ACloudViewer  3.9.4
A Modern Library for 3D Data Processing
Annotaion.h
Go to the documentation of this file.
1 // ----------------------------------------------------------------------------
2 // - CloudViewer: www.cloudViewer.org -
3 // ----------------------------------------------------------------------------
4 // Copyright (c) 2018-2024 www.cloudViewer.org
5 // SPDX-License-Identifier: MIT
6 // ----------------------------------------------------------------------------
7 
8 #pragma once
9 
10 #include <Utils/PCLCloud.h>
11 #include <vtkSmartPointer.h>
12 
13 #include <vector>
14 
15 struct BoxLabel {
17  type = "unknown";
18  this->detail.center_x = this->detail.center_y = this->detail.center_z =
19  0;
20  this->detail.yaw = 2;
21  this->detail.length = this->detail.width = this->detail.height = 1;
22  }
23  BoxLabel(const double p1[3],
24  const double p2[3],
25  std::string type_ = "unknown") {
26  type = type_;
27  this->detail.center_x = (p1[0] + p2[0]) / 2;
28  this->detail.center_y = (p1[1] + p2[1]) / 2;
29  this->detail.center_z = (p1[2] + p2[2]) / 2;
30  this->detail.yaw = 0;
31  this->detail.length = p2[0] - p1[0];
32  this->detail.width = p2[1] - p1[1];
33  this->detail.height = p2[2] - p1[2];
34  }
35  std::string type;
36  union {
37  double data[7];
38  struct {
39  double center_x;
40  double center_y;
41  double center_z;
42  double length;
43  double width;
44  double height;
45  double yaw;
46  } detail;
47  };
48 
49  std::string toString() {
50  char buffer[200];
51  sprintf(buffer, "%s %f %f %f %f %f %f %f", type.c_str(), data[0],
52  data[1], data[2], data[3], data[4], data[5], data[6]);
53  return std::string(buffer);
54  }
55 };
56 
57 class vtkBalloonWidget;
62 
63 class vtkTransform;
64 class vtkRenderWindowInteractor;
65 class vtkActor;
66 class vtkPolyDataMapper;
67 
68 class Annotation {
69  friend class Annotaions;
70 
71 public:
77  Annotation(const std::vector<int>& slice, std::string type_);
78 
85  Annotation(const BoxLabel& label, bool visible_ = true, bool lock_ = false);
86 
93  Annotation(const PointCloudI::Ptr cloud,
94  std::vector<int>& slice,
95  std::string type_);
96 
97  ~Annotation();
98 
104 
110 
116  void picked(vtkRenderWindowInteractor* interactor);
117 
121  void unpicked();
122 
127  void adjustToAnchor();
128 
133  void setType(const std::string value);
135  std::string getType() const;
136 
137  const std::vector<int>& getSlice() const;
138 
139 protected:
140  void initial();
141 
148  void colorAnnotation(int color_index = -1);
149 
155  void setAnchorPoint(const PointCloudI::Ptr cloud,
156  const std::vector<int>& slice);
157 
164  double computeScaleAndCenterShift(double o[3], double scs[2]);
165 
166 private:
167  std::string type;
172 
174  vtkSmartPointer<vtkBoxWidgetCallback0> boxWidgetCallback0;
175  vtkSmartPointer<vtkBoxWidgetCallback1> boxWidgetCallback1;
176 
177  std::vector<double*> anchorPoints;
178 
179  std::vector<int> m_slice;
180 
181  double center[3];
182 
183  // NOTE not used
184  bool visible;
185  bool lock;
186 
187 public:
192  static std::vector<std::string>* GetTypes();
193 
199  static std::size_t GetTypeIndex(std::string type_);
200 
206  static std::string GetTypeByIndex(size_t index);
207 
215  static void ComputeOBB(const PointCloudI::Ptr cloud,
216  std::vector<int>& slice,
217  double p1[3],
218  double p2[3]);
219 
220 protected:
224  static std::vector<std::string>* types;
225 };
226 
227 class Annotaions {
228 public:
229  explicit Annotaions(vtkRenderWindowInteractor* interactor = nullptr);
230 
231  void preserve(size_t num = 0);
232  void release();
233 
234  void add(Annotation* anno);
235  void remove(Annotation* anno);
236  void clear();
237  std::size_t getSize();
238 
239  void updateLabels(Annotation* anno, bool resetFlag = false);
240 
245  void loadAnnotations(std::string filename, int mode);
246 
251  void saveAnnotations(std::string filename, int mode);
252 
253  bool getAnnotations(std::vector<int>& annos) const;
254 
260  Annotation* getAnnotation(vtkActor* actor);
261  Annotation* getAnnotation(std::size_t index);
262  void getAnnotations(const std::string& type,
263  std::vector<Annotation*>& annotations);
264  int getAnnotationIndex(Annotation* anno);
265  std::vector<Annotation*>& getAnnotations();
266 
267  inline int getLabelByIndex(std::size_t index) {
268  if (index >= m_capacity) {
269  return -1;
270  }
271  return m_labeledCloudIndex[index];
272  }
273 
274  void updateBalloonByIndex(std::size_t index);
275  void updateBalloonByAnno(Annotation* anno);
276 
277 protected:
281  std::vector<Annotation*> m_annotations;
282 
283  vtkRenderWindowInteractor* m_interactor;
285 
286  int* m_labeledCloudIndex = nullptr;
287  size_t m_capacity = 0;
288 };
vtkAnnotationBoxSource.h
Annotaions::add
void add(Annotation *anno)
Definition: Annotaion.cpp:445
vtkBoxWidgetCallback0
Definition: vtkBoxWidgetAnnotationCallback.h:14
BoxLabel::center_z
double center_z
Definition: Annotaion.h:41
Annotation::colorAnnotation
void colorAnnotation(int color_index=-1)
color the annotation with given color
Definition: Annotaion.cpp:123
filename
std::string filename
Definition: PointCloudIO.cpp:47
Annotaions::Annotaions
Annotaions(vtkRenderWindowInteractor *interactor=nullptr)
Definition: Annotaion.cpp:406
Annotation::setType
void setType(const std::string value)
change the type of annotation, and color too
Definition: Annotaion.cpp:324
AnnotationMap
map< size_t, std::vector< int > > AnnotationMap
Definition: Annotaion.cpp:516
x
normal_z x
Definition: my_point_types.h:165
Annotaions::clear
void clear()
Definition: Annotaion.cpp:469
ecvColorTypes.h
Pi
const float Pi
Definition: utils.cpp:15
BoxLabel::yaw
double yaw
Definition: Annotaion.h:45
Annotaions::remove
void remove(Annotation *anno)
Definition: Annotaion.cpp:458
CVTools::QMappingReader
static bool QMappingReader(const std::string &filename, std::vector< size_t > &indices)
Definition: CVTools.cpp:280
Annotaions::m_annotations
std::vector< Annotation * > m_annotations
keep all annotation from current cloud
Definition: Annotaion.h:281
BoxLabel::center_y
double center_y
Definition: Annotaion.h:40
Annotation::applyTransform
void applyTransform(vtkSmartPointer< vtkTransform > t)
apply transform to annotation
Definition: Annotaion.cpp:231
Annotaions
Definition: Annotaion.h:227
CVLog::Print
static bool Print(const char *format,...)
Prints out a formatted message in console.
Definition: CVLog.cpp:113
BoxLabel::BoxLabel
BoxLabel(const double p1[3], const double p2[3], std::string type_="unknown")
Definition: Annotaion.h:23
BoxLabel::length
double length
Definition: Annotaion.h:42
CVLog.h
Annotation::initial
void initial()
Definition: Annotaion.cpp:112
color_index
long color_index
Definition: FileIOFactory.cpp:51
PCLCloud.h
BoxLabel::center_x
double center_x
Definition: Annotaion.h:39
BoxLabel::data
double data[7]
Definition: Annotaion.h:37
vtkSmartPointer< vtkTransform >
Annotaions::preserve
void preserve(size_t num=0)
Definition: Annotaion.cpp:420
ecvColor::RgbTpl::r
Type r
Definition: ecvColorTypes.h:54
Annotation::types
static std::vector< std::string > * types
types all annotation type here
Definition: Annotaion.h:224
BoxLabel
Definition: Annotaion.h:15
Annotaions::release
void release()
Definition: Annotaion.cpp:428
Annotaions::updateLabels
void updateLabels(Annotation *anno, bool resetFlag=false)
Definition: Annotaion.cpp:482
Annotaions::updateBalloonByAnno
void updateBalloonByAnno(Annotation *anno)
Definition: Annotaion.cpp:717
CVLog::Error
static bool Error(const char *format,...)
Display an error dialog with formatted message.
Definition: CVLog.cpp:143
BoxLabel::type
std::string type
Definition: Annotaion.h:35
vtkAnnotationBoxSource
Definition: vtkAnnotationBoxSource.h:14
y
normal_z y
Definition: my_point_types.h:168
ecvColor::LookUpTable::at
Rgb at(size_t color_id)
Definition: ecvColorTypes.cpp:77
Annotation::getBoxLabel
BoxLabel getBoxLabel()
getBoxLabel get boxLabel from annotaion tranformation
Definition: Annotaion.cpp:215
BoxLabel::toString
std::string toString()
Definition: Annotaion.h:49
Annotaions::getAnnotations
std::vector< Annotation * > & getAnnotations()
Definition: Annotaion.cpp:667
Annotation::~Annotation
~Annotation()
Definition: Annotaion.cpp:104
CVTools::TimeOff
static QString TimeOff()
Definition: CVTools.cpp:39
Annotaions::m_labeledCloudIndex
int * m_labeledCloudIndex
Definition: Annotaion.h:286
Annotation::getActor
vtkSmartPointer< vtkActor > getActor() const
Definition: Annotaion.cpp:333
BoxLabel::detail
struct BoxLabel::@52::@54 detail
Annotation::GetTypeIndex
static std::size_t GetTypeIndex(std::string type_)
GetTypeIndex auto add to vector map if has not.
Definition: Annotaion.cpp:362
Annotaions::getLabelByIndex
int getLabelByIndex(std::size_t index)
Definition: Annotaion.h:267
ecvColor::RgbTpl::g
Type g
Definition: ecvColorTypes.h:54
CVTools::TimeStart
static void TimeStart()
Definition: CVTools.cpp:37
Annotaions::saveAnnotations
void saveAnnotations(std::string filename, int mode)
save annotations to file
Definition: Annotaion.cpp:577
Annotation::getSlice
const std::vector< int > & getSlice() const
Definition: Annotaion.cpp:322
Annotation::computeScaleAndCenterShift
double computeScaleAndCenterShift(double o[3], double scs[2])
computeScaleAndCenterShift
Definition: Annotaion.cpp:335
a
a[190]
Definition: essential_matrix_poly.h:19
cloudViewer::ml::contrib::Cross
CLOUDVIEWER_HOST_DEVICE float Cross(const Point &a, const Point &b)
Definition: IoUImpl.h:39
Annotaions::getSize
std::size_t getSize()
Definition: Annotaion.cpp:480
Annotation::GetTypeByIndex
static std::string GetTypeByIndex(size_t index)
GetTypeByIndex auto add to vector map if has not.
Definition: Annotaion.cpp:372
ecvColor::RgbTpl::b
Type b
Definition: ecvColorTypes.h:54
Annotation::adjustToAnchor
void adjustToAnchor()
keep current orientation, re-compute the center and scale to make annotation fit to selected point we...
Definition: Annotaion.cpp:283
vtkBoxWidgetCallback1
Definition: vtkBoxWidgetAnnotationCallback.h:29
Annotation::Annotation
Annotation(const std::vector< int > &slice, std::string type_)
Annotation construct from slice which load from label file.
Definition: Annotaion.cpp:43
CVTools.h
CVLog::Warning
static bool Warning(const char *format,...)
Prints out a formatted warning message in console.
Definition: CVLog.cpp:133
Annotation::ComputeOBB
static void ComputeOBB(const PointCloudI::Ptr cloud, std::vector< int > &slice, double p1[3], double p2[3])
ComputeOBB compute max,min [x,y,z] aligned to xyz axis.
Definition: Annotaion.cpp:381
BoxLabel::height
double height
Definition: Annotaion.h:44
ecvColor::RgbTpl
RGB color structure.
Definition: ecvColorTypes.h:49
std
Definition: Eigen.h:85
Annotaions::getAnnotation
Annotation * getAnnotation(vtkActor *actor)
from annotatin box actor to find annotation itself
Definition: Annotaion.cpp:669
Annotaions::loadAnnotations
void loadAnnotations(std::string filename, int mode)
load annotations from file
Definition: Annotaion.cpp:518
vtkBoxWidgetAnnotationCallback.h
vtkBoxWidgetRestricted.h
Annotation::GetTypes
static std::vector< std::string > * GetTypes()
get types vector pointer
Definition: Annotaion.cpp:354
Annotaions::m_capacity
size_t m_capacity
Definition: Annotaion.h:287
z
normal_z z
Definition: my_point_types.h:165
Annotaions::m_interactor
vtkRenderWindowInteractor * m_interactor
Definition: Annotaion.h:283
Annotation::unpicked
void unpicked()
disable boxWidget
Definition: Annotaion.cpp:277
Annotaions::updateBalloonByIndex
void updateBalloonByIndex(std::size_t index)
Definition: Annotaion.cpp:705
Annotation
Definition: Annotaion.h:68
Annotaion.h
Annotaions::getAnnotationIndex
int getAnnotationIndex(Annotation *anno)
Definition: Annotaion.cpp:678
vtkBoxWidgetRestricted
The vtkBoxWidgetRestricted class vtkBoxWidgetRestricted restricts the rotation with Z axis.
Definition: vtkBoxWidgetRestricted.h:21
Annotation::setAnchorPoint
void setAnchorPoint(const PointCloudI::Ptr cloud, const std::vector< int > &slice)
copy selected points as anchor to current annotation
Definition: Annotaion.cpp:167
CVTools::QMappingWriter
static bool QMappingWriter(const std::string &filename, const void *data, std::size_t length)
Definition: CVTools.cpp:331
patch::to_string
std::string to_string(const T &n)
Definition: Common.h:20
Annotation::picked
void picked(vtkRenderWindowInteractor *interactor)
enter picked state, show boxwidget which allow to adjust annotation
Definition: Annotaion.cpp:240
Annotation::getType
std::string getType() const
Definition: Annotaion.cpp:320
type
char type
Definition: FileIOFactory.cpp:131
Annotaions::m_balloonWidget
vtkSmartPointer< vtkBalloonWidget > m_balloonWidget
Definition: Annotaion.h:284
BoxLabel::width
double width
Definition: Annotaion.h:43
BoxLabel::BoxLabel
BoxLabel()
Definition: Annotaion.h:16