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 
86  unsigned pointIndex,
87  bool entityCenter = false);
88 
90 
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 
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 
311  void clear2Dviews();
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 };
float PointCoordinateType
Type of the coordinates of a (N-D) point.
Definition: CVTypes.h:16
int64_t CV_CLASS_ENUM
Type of object type flags (64 bits)
Definition: CVTypes.h:97
#define CV_DB_LIB_API
Definition: CV_db.h:15
double normal[3]
std::string name
math::float2 uv
2D label (typically attached to points)
Definition: ecv2DLabel.h:22
bool addPickedPoint(ccGenericPointCloud *cloud, unsigned pointIndex, bool entityCenter=false)
Adds a point to this label.
const PickedPoint & getPickedPoint(unsigned index) const
Returns a given point.
Definition: ecv2DLabel.h:194
QString m_sphereIdfix
Definition: ecv2DLabel.h:355
virtual CV_CLASS_ENUM getClassID() const override
Returns class ID.
Definition: ecv2DLabel.h:30
cc2DLabel(QString name=QString("label"))
Default constructor.
QRect m_labelROI
label ROI
Definition: ecv2DLabel.h:333
virtual bool acceptClick(int x, int y, Qt::MouseButton button) override
Called on mouse click.
bool m_dispIn2D
Whether to display the label in 2D.
Definition: ecv2DLabel.h:350
virtual void drawMeOnly(CC_DRAW_CONTEXT &context) override
Draws the entity only (not its children)
float m_relMarkerScale
Relative marker scale.
Definition: ecv2DLabel.h:353
QString getTitle(int precision) const
Returns the (3D) label title.
bool toFile_MeOnly(QFile &out, short dataVersion) const override
Save own object data.
QString m_surfaceIdfix
Definition: ecv2DLabel.h:356
void clear3Dviews()
QString m_lineID
Definition: ecv2DLabel.h:358
void getLabelInfo2(LabelInfo2 &info) const
Gets two-points label info.
bool isCollapsed() const
Returns whether the label is collapsed or not.
Definition: ecv2DLabel.h:105
QString getRawName() const
Returns 'raw' name (no replacement of default keywords)
Definition: ecv2DLabel.h:36
void clear(bool ignoreDependencies=false, bool ignoreCaption=true)
Clears label.
short minimumFileVersion_MeOnly() const override
void setRelativeMarkerScale(float scale)
Sets marker (relative) scale.
Definition: ecv2DLabel.h:205
virtual bool move2D(int x, int y, int dx, int dy, int screenWidth, int screenHeight) override
Called on mouse move (for 2D interactors)
const float * getPosition() const
Returns relative position.
Definition: ecv2DLabel.h:63
PickedPoint & getPickedPoint(unsigned index)
Returns a given point.
Definition: ecv2DLabel.h:198
void updateLabel()
void setCollapsed(bool state)
Whether to collapse label or not.
Definition: ecv2DLabel.h:102
bool isPointLegendDisplayed() const
Returns whether the point(s) legend is displayed.
Definition: ecv2DLabel.h:111
void setDisplayedIn2D(bool state)
Whether to display the label in 2D.
Definition: ecv2DLabel.h:114
bool fromFile_MeOnly(QFile &in, short dataVersion, int flags, LoadedIDMap &oldToNewIDMap) override
Loads own object data.
unsigned size() const
Returns current size.
Definition: ecv2DLabel.h:74
std::vector< PickedPoint > m_pickedPoints
Picked points.
Definition: ecv2DLabel.h:318
virtual QString getName() const override
Returns object name.
static QString GetSFValueAsString(const LabelInfo1 &info, int precision)
Returns the SF value as a string.
QString m_contourIdfix
Definition: ecv2DLabel.h:357
void drawMeOnly2D(CC_DRAW_CONTEXT &context)
Draws the entity only (not its children) - 2D version.
bool addPickedPoint(ccGenericMesh *mesh, unsigned triangleIndex, const CCVector2d &uv, bool entityCenter=false)
Adds a point to this label.
void updateName()
Updates the label 'name'.
QStringList getLabelContent(int precision) const
Gets label content (as it will be displayed)
void getLabelInfo3(LabelInfo3 &info) const
Gets three-points label info.
void setPosition(float x, float y)
Sets relative position.
virtual void onDeletionOf(const ccHObject *obj) override
This method is called when another object is deleted.
bool m_dispPointsLegend
Whether to display the point(s) legend.
Definition: ecv2DLabel.h:347
void clear2Dviews()
bool pointPicking(const CCVector2d &clickPos, const ccGLCameraParameters &camera, int &nearestPointIndex, double &nearestSquareDist) const
Point (marker) picking.
void update2DLabelView(CC_DRAW_CONTEXT &context, bool updateScreen=true)
void clearLabel(bool ignoreCaption=true)
void update3DLabelView(CC_DRAW_CONTEXT &context, bool updateScreen=true)
virtual bool isSerializable() const override
Returns whether object is serializable of not.
Definition: ecv2DLabel.h:33
bool isDisplayedIn2D() const
Returns whether the label is displayed in 2D.
Definition: ecv2DLabel.h:117
void getLabelInfo1(LabelInfo1 &info) const
Returns one-point label info.
void drawMeOnly3D(CC_DRAW_CONTEXT &context)
Draws the entity only (not its children) - 3D version.
QStringList m_historyMessage
Definition: ecv2DLabel.h:335
bool m_showFullBody
Whether to show full label body or not.
Definition: ecv2DLabel.h:324
bool addPickedPoint(const PickedPoint &pp)
Adds a point to this label (direct - handle with care)
void displayPointLegend(bool state)
Whether to display the point(s) legend (title only)
Definition: ecv2DLabel.h:108
Generic mesh interface.
A 3D cloud interface with associated features (color, normals, octree, etc.)
Hierarchical CLOUDVIEWER Object.
Definition: ecvHObject.h:25
Interactor interface (entity that can be dragged or clicked in a 3D view)
Definition: ecvInteractor.h:20
QString m_name
Object name.
Definition: ecvObject.h:219
QMultiMap< unsigned, unsigned > LoadedIDMap
Map of loaded unique IDs (old ID --> new ID)
RGB color structure.
Definition: ecvColorTypes.h:49
ImGuiContext * context
Definition: Window.cpp:76
@ LABEL_2D
Definition: CVTypes.h:140
One-point label info.
Definition: ecv2DLabel.h:217
ccGenericPointCloud * cloud
Definition: ecv2DLabel.h:219
ecvColor::Rgb rgb
Definition: ecv2DLabel.h:223
LabelInfo1()
Default constructor.
Definition: ecv2DLabel.h:230
Two-points label info.
Definition: ecv2DLabel.h:254
LabelInfo2()
Default constructor.
Definition: ecv2DLabel.h:261
ccGenericPointCloud * cloud1
Definition: ecv2DLabel.h:256
ccGenericPointCloud * cloud2
Definition: ecv2DLabel.h:258
Three-points label info.
Definition: ecv2DLabel.h:272
LabelInfo3()
Default constructor.
Definition: ecv2DLabel.h:284
PointCoordinateType area
Definition: ecv2DLabel.h:280
ccGenericPointCloud * cloud1
Definition: ecv2DLabel.h:274
ccGenericPointCloud * cloud2
Definition: ecv2DLabel.h:276
ccGenericPointCloud * cloud3
Definition: ecv2DLabel.h:278
Picked point descriptor.
Definition: ecv2DLabel.h:122
CCVector2d uv
Barycentric coordinates (for triangles)
Definition: ecv2DLabel.h:136
CCVector3 getPointPosition() const
Returns the point position (3D)
PickedPoint()
Default constructor.
Definition: ecv2DLabel.h:155
unsigned index
Point/triangle index.
Definition: ecv2DLabel.h:128
QString itemTitle() const
PickedPoint(ccGenericPointCloud *_cloud, unsigned pointIndex, bool centerPoint=false)
Constructor from a point and its index.
Definition: ecv2DLabel.h:165
ccGenericPointCloud * cloudOrVertices() const
Returns the cloud or the mesh vertices.
ccGenericMesh * mesh
Mesh.
Definition: ecv2DLabel.h:126
ccHObject * entity() const
Returns the associated entity (cloud or mesh)
bool entityCenterPoint
Entity center mode (index will be invalid)
Definition: ecv2DLabel.h:138
float markerScale
Last known marker scale.
Definition: ecv2DLabel.h:134
CCVector3d pos2D
Last known '2D' position (i.e. in screen space)
Definition: ecv2DLabel.h:132
ccGenericPointCloud * cloud
Cloud.
Definition: ecv2DLabel.h:124
QString prefix(const char *pointTag) const
Returns the point prefix ('Point' or 'Point@Tri' or 'IDXX Center')
PickedPoint(ccGenericMesh *_mesh, unsigned triIindex, const CCVector2d &_uv, bool centerPoint=false)
Constructor from a triangle, its index and barycentric coordinates.
Definition: ecv2DLabel.h:177
unsigned getUniqueID() const
Returns the cloud or the mesh unique ID.
OpenGL camera parameters.
Display context.