ACloudViewer  3.9.4
A Modern Library for 3D Data Processing
ecv2DLabel.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 // Local
11 #include "ecvGenericDisplayTools.h"
12 #include "ecvHObject.h"
13 #include "ecvInteractor.h"
14 
15 // Qt
16 #include <QRect>
17 
18 class ccGenericMesh;
20 
23 public:
25  cc2DLabel(QString name = QString("label"));
26 
27  // inherited from ccObject
28  virtual QString getName() const override;
29  // inherited from ccHObject
30  inline virtual CV_CLASS_ENUM getClassID() const override {
31  return CV_TYPES::LABEL_2D;
32  }
33  inline virtual bool isSerializable() const override { return true; }
34 
36  inline QString getRawName() const { return m_name; }
37 
39 
42  QStringList getLabelContent(int precision) const;
43 
45 
48  QString getTitle(int precision) const;
49 
50  // inherited from ccInteractor
51  virtual bool acceptClick(int x, int y, Qt::MouseButton button) override;
52  virtual bool move2D(int x,
53  int y,
54  int dx,
55  int dy,
56  int screenWidth,
57  int screenHeight) override;
58 
60  void setPosition(float x, float y);
61 
63  inline const float* getPosition() const { return m_screenPos; }
64 
66  void clear(bool ignoreDependencies = false, bool ignoreCaption = true);
67 
68  void clearLabel(bool ignoreCaption = true);
69  void updateLabel();
70  void update3DLabelView(CC_DRAW_CONTEXT& context, bool updateScreen = true);
71  void update2DLabelView(CC_DRAW_CONTEXT& context, bool updateScreen = true);
72 
74  inline unsigned size() const {
75  return static_cast<unsigned>(m_pickedPoints.size());
76  }
77 
79 
85  bool addPickedPoint(ccGenericPointCloud* cloud,
86  unsigned pointIndex,
87  bool entityCenter = false);
88 
90 
96  bool addPickedPoint(ccGenericMesh* mesh,
97  unsigned triangleIndex,
98  const CCVector2d& uv,
99  bool entityCenter = false);
100 
102  inline void setCollapsed(bool state) { m_showFullBody = !state; }
103 
105  inline bool isCollapsed() const { return !m_showFullBody; }
106 
108  inline void displayPointLegend(bool state) { m_dispPointsLegend = state; }
109 
111  inline bool isPointLegendDisplayed() const { return m_dispPointsLegend; }
112 
114  inline void setDisplayedIn2D(bool state) { m_dispIn2D = state; }
115 
117  inline bool isDisplayedIn2D() const { return m_dispIn2D; }
118 
120 
128  unsigned index;
130 
134  float markerScale;
139 
141  CCVector3 getPointPosition() const;
143  ccGenericPointCloud* cloudOrVertices() const;
145  unsigned getUniqueID() const;
147  ccHObject* entity() const;
150  QString itemTitle() const;
152  QString prefix(const char* pointTag) const;
153 
156  : cloud(nullptr),
157  mesh(nullptr),
158  index(0),
159  pos2D(0, 0, 0),
160  markerScale(0),
161  uv(0, 0),
162  entityCenterPoint(false) {}
163 
166  unsigned pointIndex,
167  bool centerPoint = false)
168  : cloud(_cloud),
169  mesh(nullptr),
170  index(pointIndex),
171  pos2D(0, 0, 0),
172  markerScale(0),
173  uv(0, 0),
174  entityCenterPoint(centerPoint) {}
175 
178  unsigned triIindex,
179  const CCVector2d& _uv,
180  bool centerPoint = false)
181  : cloud(nullptr),
182  mesh(_mesh),
183  index(triIindex),
184  pos2D(0, 0, 0),
185  markerScale(0),
186  uv(_uv),
187  entityCenterPoint(centerPoint) {}
188  };
189 
191  bool addPickedPoint(const PickedPoint& pp);
192 
194  inline const PickedPoint& getPickedPoint(unsigned index) const {
195  return m_pickedPoints[index];
196  }
198  inline PickedPoint& getPickedPoint(unsigned index) {
199  return m_pickedPoints[index];
200  }
201 
203 
205  inline void setRelativeMarkerScale(float scale) {
206  m_relMarkerScale = scale;
207  }
208 
210  bool pointPicking(const CCVector2d& clickPos,
211  const ccGLCameraParameters& camera,
212  int& nearestPointIndex,
213  double& nearestSquareDist) const;
214 
215 protected:
217  struct LabelInfo1 {
218  unsigned pointIndex;
220  bool hasNormal;
222  bool hasRGB;
224  bool hasSF;
225  ScalarType sfValue;
228  QString sfName;
231  : pointIndex(0),
232  cloud(0),
233  hasNormal(false),
234  normal(0, 0, 0),
235  hasRGB(false),
236  rgb(0, 0, 0),
237  hasSF(false),
238  sfValue(0),
239  sfShiftedValue(0),
240  sfValueIsShifted(false) {}
241  };
242 
244  void getLabelInfo1(LabelInfo1& info) const;
245 
247 
251  static QString GetSFValueAsString(const LabelInfo1& info, int precision);
252 
254  struct LabelInfo2 {
255  unsigned point1Index;
257  unsigned point2Index;
262  : point1Index(0),
263  cloud1(0),
264  point2Index(0),
265  cloud2(0),
266  diff(0, 0, 0) {}
267  };
269  void getLabelInfo2(LabelInfo2& info) const;
270 
272  struct LabelInfo3 {
273  unsigned point1Index;
275  unsigned point2Index;
277  unsigned point3Index;
285  : point1Index(0),
286  cloud1(0),
287  point2Index(0),
288  cloud2(0),
289  point3Index(0),
290  cloud3(0),
291  normal(0, 0, 0),
292  area(0),
293  angles(0, 0, 0),
294  edges(0, 0, 0) {}
295  };
297  void getLabelInfo3(LabelInfo3& info) const;
298 
299  // inherited from ccHObject
300  bool toFile_MeOnly(QFile& out, short dataVersion) const override;
301  short minimumFileVersion_MeOnly() const override;
302  bool fromFile_MeOnly(QFile& in,
303  short dataVersion,
304  int flags,
305  LoadedIDMap& oldToNewIDMap) override;
306  virtual void drawMeOnly(CC_DRAW_CONTEXT& context) override;
307  virtual void onDeletionOf(const ccHObject* obj) override;
308 
310  void drawMeOnly2D(CC_DRAW_CONTEXT& context);
311  void clear2Dviews();
313  void drawMeOnly3D(CC_DRAW_CONTEXT& context);
314 
315  void clear3Dviews();
316 
318  std::vector<PickedPoint> m_pickedPoints;
319 
321  void updateName();
322 
325 
327 
333  QRect m_labelROI;
334 
335  QStringList m_historyMessage;
336 
338  // int m_closeButtonROI[4];
339 
341  float m_screenPos[2];
342 
344  int m_lastScreenPos[2];
345 
348 
351 
354 
355  QString m_sphereIdfix;
356  QString m_surfaceIdfix;
357  QString m_contourIdfix;
358  QString m_lineID;
359 };
cc2DLabel::LabelInfo3::point1Index
unsigned point1Index
Definition: ecv2DLabel.h:273
cc2DLabel::LabelInfo3::area
PointCoordinateType area
Definition: ecv2DLabel.h:280
cc2DLabel::LabelInfo3::cloud2
ccGenericPointCloud * cloud2
Definition: ecv2DLabel.h:276
rgb
normal_z rgb
Definition: my_point_types.h:168
cc2DLabel::setDisplayedIn2D
void setDisplayedIn2D(bool state)
Whether to display the label in 2D.
Definition: ecv2DLabel.h:114
cc2DLabel::PickedPoint::markerScale
float markerScale
Last known marker scale.
Definition: ecv2DLabel.h:134
x
normal_z x
Definition: my_point_types.h:165
cc2DLabel::displayPointLegend
void displayPointLegend(bool state)
Whether to display the point(s) legend (title only)
Definition: ecv2DLabel.h:108
cc2DLabel::LabelInfo3::cloud3
ccGenericPointCloud * cloud3
Definition: ecv2DLabel.h:278
normal
double normal[3]
Definition: FileIOFactory.cpp:53
cc2DLabel::LabelInfo3
Three-points label info.
Definition: ecv2DLabel.h:272
cc2DLabel::isCollapsed
bool isCollapsed() const
Returns whether the label is collapsed or not.
Definition: ecv2DLabel.h:105
cc2DLabel::LabelInfo1::cloud
ccGenericPointCloud * cloud
Definition: ecv2DLabel.h:219
cc2DLabel::PickedPoint::uv
CCVector2d uv
Barycentric coordinates (for triangles)
Definition: ecv2DLabel.h:136
cc2DLabel::m_surfaceIdfix
QString m_surfaceIdfix
Definition: ecv2DLabel.h:356
cc2DLabel::setRelativeMarkerScale
void setRelativeMarkerScale(float scale)
Sets marker (relative) scale.
Definition: ecv2DLabel.h:205
ccInteractor::move2D
virtual bool move2D(int x, int y, int dx, int dy, int screenWidth, int screenHeight)
Called on mouse move (for 2D interactors)
Definition: ecvInteractor.h:32
cc2DLabel::LabelInfo1::sfValue
ScalarType sfValue
Definition: ecv2DLabel.h:225
cc2DLabel::LabelInfo2::cloud2
ccGenericPointCloud * cloud2
Definition: ecv2DLabel.h:258
cc2DLabel::m_contourIdfix
QString m_contourIdfix
Definition: ecv2DLabel.h:357
cc2DLabel::PickedPoint::mesh
ccGenericMesh * mesh
Mesh.
Definition: ecv2DLabel.h:126
ccInteractor::acceptClick
virtual bool acceptClick(int x, int y, Qt::MouseButton button)
Called on mouse click.
Definition: ecvInteractor.h:25
cc2DLabel
2D label (typically attached to points)
Definition: ecv2DLabel.h:22
cloudViewer::visualization::gui::MouseButton
MouseButton
Definition: Events.h:26
cc2DLabel::getPickedPoint
const PickedPoint & getPickedPoint(unsigned index) const
Returns a given point.
Definition: ecv2DLabel.h:194
cc2DLabel::m_sphereIdfix
QString m_sphereIdfix
Definition: ecv2DLabel.h:355
ccObject::m_name
QString m_name
Object name.
Definition: ecvObject.h:219
cc2DLabel::m_lineID
QString m_lineID
Definition: ecv2DLabel.h:358
ccGLCameraParameters
OpenGL camera parameters.
Definition: ecvGenericDisplayTools.h:554
ccInteractor
Interactor interface (entity that can be dragged or clicked in a 3D view)
Definition: ecvInteractor.h:20
cc2DLabel::LabelInfo2::cloud1
ccGenericPointCloud * cloud1
Definition: ecv2DLabel.h:256
cc2DLabel::PickedPoint::entityCenterPoint
bool entityCenterPoint
Entity center mode (index will be invalid)
Definition: ecv2DLabel.h:138
cc2DLabel::getPickedPoint
PickedPoint & getPickedPoint(unsigned index)
Returns a given point.
Definition: ecv2DLabel.h:198
CV_CLASS_ENUM
int64_t CV_CLASS_ENUM
Type of object type flags (64 bits)
Definition: CVTypes.h:97
Vector2Tpl< double >
cc2DLabel::LabelInfo3::LabelInfo3
LabelInfo3()
Default constructor.
Definition: ecv2DLabel.h:284
cc2DLabel::isSerializable
virtual bool isSerializable() const override
Returns whether object is serializable of not.
Definition: ecv2DLabel.h:33
context
ImGuiContext * context
Definition: Window.cpp:76
cc2DLabel::getRawName
QString getRawName() const
Returns 'raw' name (no replacement of default keywords)
Definition: ecv2DLabel.h:36
y
normal_z y
Definition: my_point_types.h:168
ccGenericPointCloud
A 3D cloud interface with associated features (color, normals, octree, etc.)
Definition: ecvGenericPointCloud.h:45
cc2DLabel::PickedPoint::pos2D
CCVector3d pos2D
Last known '2D' position (i.e. in screen space)
Definition: ecv2DLabel.h:132
cc2DLabel::LabelInfo1::rgb
ecvColor::Rgb rgb
Definition: ecv2DLabel.h:223
Vector3Tpl< double >
cc2DLabel::m_labelROI
QRect m_labelROI
label ROI
Definition: ecv2DLabel.h:333
cc2DLabel::LabelInfo1
One-point label info.
Definition: ecv2DLabel.h:217
cc2DLabel::isDisplayedIn2D
bool isDisplayedIn2D() const
Returns whether the label is displayed in 2D.
Definition: ecv2DLabel.h:117
cc2DLabel::setCollapsed
void setCollapsed(bool state)
Whether to collapse label or not.
Definition: ecv2DLabel.h:102
cc2DLabel::LabelInfo1::hasNormal
bool hasNormal
Definition: ecv2DLabel.h:220
cc2DLabel::LabelInfo2::point1Index
unsigned point1Index
Definition: ecv2DLabel.h:255
cc2DLabel::LabelInfo3::point3Index
unsigned point3Index
Definition: ecv2DLabel.h:277
cc2DLabel::PickedPoint::PickedPoint
PickedPoint(ccGenericMesh *_mesh, unsigned triIindex, const CCVector2d &_uv, bool centerPoint=false)
Constructor from a triangle, its index and barycentric coordinates.
Definition: ecv2DLabel.h:177
cc2DLabel::LabelInfo2::point2Index
unsigned point2Index
Definition: ecv2DLabel.h:257
cc2DLabel::size
unsigned size() const
Returns current size.
Definition: ecv2DLabel.h:74
CV_TYPES::LABEL_2D
@ LABEL_2D
Definition: CVTypes.h:140
cc2DLabel::PickedPoint::index
unsigned index
Point/triangle index.
Definition: ecv2DLabel.h:128
ccGenericMesh
Generic mesh interface.
Definition: ecvGenericMesh.h:28
ecvInteractor.h
cc2DLabel::LabelInfo3::cloud1
ccGenericPointCloud * cloud1
Definition: ecv2DLabel.h:274
cc2DLabel::LabelInfo2::LabelInfo2
LabelInfo2()
Default constructor.
Definition: ecv2DLabel.h:261
cc2DLabel::LabelInfo1::pointIndex
unsigned pointIndex
Definition: ecv2DLabel.h:218
cc2DLabel::LabelInfo2
Two-points label info.
Definition: ecv2DLabel.h:254
cc2DLabel::LabelInfo1::LabelInfo1
LabelInfo1()
Default constructor.
Definition: ecv2DLabel.h:230
cc2DLabel::m_historyMessage
QStringList m_historyMessage
Definition: ecv2DLabel.h:335
cc2DLabel::LabelInfo1::normal
CCVector3 normal
Definition: ecv2DLabel.h:221
cc2DLabel::LabelInfo1::sfShiftedValue
double sfShiftedValue
Definition: ecv2DLabel.h:226
cc2DLabel::LabelInfo1::hasSF
bool hasSF
Definition: ecv2DLabel.h:224
cc2DLabel::PickedPoint
Picked point descriptor.
Definition: ecv2DLabel.h:122
cc2DLabel::LabelInfo3::edges
CCVector3d edges
Definition: ecv2DLabel.h:282
cc2DLabel::LabelInfo2::diff
CCVector3 diff
Definition: ecv2DLabel.h:259
cc2DLabel::LabelInfo3::angles
CCVector3d angles
Definition: ecv2DLabel.h:281
cc2DLabel::m_pickedPoints
std::vector< PickedPoint > m_pickedPoints
Picked points.
Definition: ecv2DLabel.h:318
cc2DLabel::m_relMarkerScale
float m_relMarkerScale
Relative marker scale.
Definition: ecv2DLabel.h:353
uv
math::float2 uv
Definition: PointCloudBuffers.cpp:51
ecvColor::RgbTpl
RGB color structure.
Definition: ecvColorTypes.h:49
ccHObject
Hierarchical CLOUDVIEWER Object.
Definition: ecvHObject.h:25
cc2DLabel::m_dispPointsLegend
bool m_dispPointsLegend
Whether to display the point(s) legend.
Definition: ecv2DLabel.h:347
ccObject::getName
virtual QString getName() const
Returns object name.
Definition: ecvObject.h:72
cc2DLabel::getClassID
virtual CV_CLASS_ENUM getClassID() const override
Returns class ID.
Definition: ecv2DLabel.h:30
cc2DLabel::isPointLegendDisplayed
bool isPointLegendDisplayed() const
Returns whether the point(s) legend is displayed.
Definition: ecv2DLabel.h:111
cc2DLabel::PickedPoint::PickedPoint
PickedPoint()
Default constructor.
Definition: ecv2DLabel.h:155
CV_DB_LIB_API
#define CV_DB_LIB_API
Definition: CV_db.h:15
ccGLDrawContext
Display context.
Definition: ecvDrawContext.h:365
cc2DLabel::PickedPoint::PickedPoint
PickedPoint(ccGenericPointCloud *_cloud, unsigned pointIndex, bool centerPoint=false)
Constructor from a point and its index.
Definition: ecv2DLabel.h:165
PointCoordinateType
float PointCoordinateType
Type of the coordinates of a (N-D) point.
Definition: CVTypes.h:16
cc2DLabel::PickedPoint::cloud
ccGenericPointCloud * cloud
Cloud.
Definition: ecv2DLabel.h:124
ecvGenericDisplayTools.h
cc2DLabel::LabelInfo3::point2Index
unsigned point2Index
Definition: ecv2DLabel.h:275
cc2DLabel::m_showFullBody
bool m_showFullBody
Whether to show full label body or not.
Definition: ecv2DLabel.h:324
ecvHObject.h
cc2DLabel::LabelInfo3::normal
CCVector3 normal
Definition: ecv2DLabel.h:279
cc2DLabel::LabelInfo1::sfValueIsShifted
bool sfValueIsShifted
Definition: ecv2DLabel.h:227
cc2DLabel::LabelInfo1::hasRGB
bool hasRGB
Definition: ecv2DLabel.h:222
cc2DLabel::LabelInfo1::sfName
QString sfName
Definition: ecv2DLabel.h:228
cc2DLabel::m_dispIn2D
bool m_dispIn2D
Whether to display the label in 2D.
Definition: ecv2DLabel.h:350
cc2DLabel::getPosition
const float * getPosition() const
Returns relative position.
Definition: ecv2DLabel.h:63
name
std::string name
Definition: FileIOFactory.cpp:129