ACloudViewer  3.9.4
A Modern Library for 3D Data Processing
ecvPolyline.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 // CV_CORE_LIB
11 #include <Polyline.h>
12 
13 // Local
14 #include "CV_db.h"
15 #include "ecvShiftedObject.h"
16 
17 class ccPointCloud;
19 
21 
24  public ccShiftedObject {
25 public:
27 
29  explicit ccPolyline(GenericIndexedCloudPersist* associatedCloud);
30  explicit ccPolyline(ccPointCloud& associatedCloud);
31 
33 
35  ccPolyline(const ccPolyline& poly);
36 
38  virtual ~ccPolyline() override = default;
39 
41  virtual CV_CLASS_ENUM getClassID() const override {
42  return CV_TYPES::POLY_LINE;
43  }
44 
45  // inherited methods (ccHObject)
46  virtual bool isSerializable() const override { return true; }
47  virtual void applyGLTransformation(const ccGLMatrix& trans) override;
48  virtual unsigned getUniqueIDForDisplay() const override;
49 
50  // inherited methods (ccDrawableObject)
51  virtual bool hasColors() const override;
52 
53  // inherited methods (ccShiftedObject)
54  virtual void setGlobalShift(const CCVector3d& shift) override;
55  virtual void setGlobalScale(double scale) override;
56 
58 
60  void set2DMode(bool state);
61 
63  inline bool is2DMode() const { return m_mode2D; }
64 
66 
68  void setTransformFlag(bool state) { m_needTransform = state; };
69 
71  inline bool needTransform() const { return m_needTransform; }
72 
74 
76  void setForeground(bool state);
77 
79 
81  inline void setColor(const ecvColor::Rgb& col) {
82  enableTempColor(false);
83  m_rgbColor = col;
84  }
85 
87 
90 
92 
94  inline PointCoordinateType getWidth() const { return m_width; }
95 
97 
99  inline const ecvColor::Rgb& getColor() const { return m_rgbColor; }
100 
101  // inherited methods (ccHObject)
102  virtual ccBBox getOwnBB(bool withGLFeatures = false) override;
103  inline virtual void drawBB(CC_DRAW_CONTEXT& context,
104  const ecvColor::Rgb& col) override {
105  // DGM: only for 3D polylines!
106  if (!is2DMode()) ccShiftedObject::drawBB(context, col);
107  }
108 
110 
115  bool split(PointCoordinateType maxEdgeLength,
116  std::vector<ccPolyline*>& parts);
117 
119 
123  bool add(const ccPointCloud& cloud);
124 
127 
129  void showVertices(bool state) { m_showVertices = state; }
131  bool verticesShown() const { return m_showVertices; }
132  bool arrowShown() const { return m_showArrow; }
133  unsigned getArrowIndex() const { return m_arrowIndex; }
134  PointCoordinateType getArrowLength() const { return m_arrowLength; }
135 
137  void setVertexMarkerWidth(int width) { m_vertMarkWidth = width; }
139  int getVertexMarkerWidth() const { return m_vertMarkWidth; }
140 
143 
147  bool initWith(ccPointCloud* vertices, const ccPolyline& poly);
148 
150  void importParametersFrom(const ccPolyline& poly);
151 
153  void showArrow(bool state, unsigned vertIndex, PointCoordinateType length);
154 
156  unsigned segmentCount() const;
157 
159  ccPointCloud* samplePoints(bool densityBased,
160  double samplingParameter,
161  bool withRGB);
162 
164 
169  unsigned iterationCount) const;
170 
172 
177  bool createNewPolylinesFromSelection(std::vector<ccPolyline*>& output);
178 
181  ccPolyline** polyline = nullptr);
182 
184  static ccPolyline* Circle(const CCVector3& center,
185  PointCoordinateType radius,
186  unsigned resolution = 48);
187 
188  inline virtual bool IsEmpty() const override { return !hasPoints(); }
189  virtual Eigen::Vector3d GetMinBound() const override;
190  virtual Eigen::Vector3d GetMaxBound() const override;
191  virtual Eigen::Vector3d GetCenter() const override;
192  virtual ccBBox GetAxisAlignedBoundingBox() const override;
193  virtual ecvOrientedBBox GetOrientedBoundingBox() const override;
195  const Eigen::Matrix4d& transformation) override;
196  virtual ccPolyline& Translate(const Eigen::Vector3d& translation,
197  bool relative = true) override;
198  virtual ccPolyline& Scale(const double s,
199  const Eigen::Vector3d& center) override;
200  virtual ccPolyline& Rotate(const Eigen::Matrix3d& R,
201  const Eigen::Vector3d& center) override;
202 
203  ccPolyline& operator+=(const ccPolyline& polyline);
204  ccPolyline& operator=(const ccPolyline& polyline);
205  ccPolyline operator+(const ccPolyline& polyline) const;
206 
210  ccPolyline& PaintUniformColor(const Eigen::Vector3d& color) {
212  return *this;
213  }
214 
215 public: // meta-data keys
218 
220  static QString MetaKeyUpDir() { return "up.dir"; }
222 
224  static QString MetaKeyConstAltitude() { return "contour.altitude"; }
226  static QString MetaKeyAbscissa() { return "profile.abscissa"; }
229 
232  static QString MetaKeyPrefixCenter() { return "profile.center"; }
235 
238  static QString MetaKeyPrefixDirection() { return "profile.direction"; }
239 
240 protected:
241  // inherited from ccHObject
242  bool toFile_MeOnly(QFile& out, short dataVersion) const override;
243  short minimumFileVersion_MeOnly() const override;
244  bool fromFile_MeOnly(QFile& in,
245  short dataVersion,
246  int flags,
247  LoadedIDMap& oldToNewIDMap) override;
248 
249  // inherited methods (ccHObject)
250  virtual void drawMeOnly(CC_DRAW_CONTEXT& context) override;
251 
254 
257 
259  bool m_mode2D;
260 
263 
267 
270 
273 
279  unsigned m_arrowIndex;
280 };
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
int width
math::float4 color
Bounding box structure.
Definition: ecvBBox.h:25
virtual void enableTempColor(bool state)
Set temporary color activation state.
Float version of ccGLMatrixTpl.
Definition: ecvGLMatrix.h:19
A 3D cloud interface with associated features (color, normals, octree, etc.)
virtual void drawBB(CC_DRAW_CONTEXT &context, const ecvColor::Rgb &col)
Draws the entity (and its children) bounding-box.
A 3D cloud and its associated features (color, normals, scalar fields, etc.)
Colored polyline.
Definition: ecvPolyline.h:24
ccPolyline operator+(const ccPolyline &polyline) const
void setTransformFlag(bool state)
Defines if the polyline is considered as processed polyline.
Definition: ecvPolyline.h:68
ccPolyline & PaintUniformColor(const Eigen::Vector3d &color)
Assigns each line in the LineSet the same color.
Definition: ecvPolyline.h:210
PointCoordinateType computeLength() const
Computes the polyline length.
short minimumFileVersion_MeOnly() const override
PointCoordinateType getArrowLength() const
Definition: ecvPolyline.h:134
void setForeground(bool state)
Defines if the polyline is drawn in background or foreground.
bool m_needTransform
Whether polyline should be considered as processed polyline.
Definition: ecvPolyline.h:262
virtual void setGlobalShift(const CCVector3d &shift) override
Sets shift applied to original coordinates (information storage only)
virtual ~ccPolyline() override=default
Destructor.
virtual Eigen::Vector3d GetMaxBound() const override
Returns max bounds for geometry coordinates.
bool toFile_MeOnly(QFile &out, short dataVersion) const override
Save own object data.
bool fromFile_MeOnly(QFile &in, short dataVersion, int flags, LoadedIDMap &oldToNewIDMap) override
Loads own object data.
virtual ccPolyline & Translate(const Eigen::Vector3d &translation, bool relative=true) override
Apply translation to the geometry coordinates.
bool verticesShown() const
Whether the polyline vertices should be displayed or not.
Definition: ecvPolyline.h:131
virtual ccPolyline & Transform(const Eigen::Matrix4d &transformation) override
Apply transformation (4x4 matrix) to the geometry coordinates.
unsigned m_arrowIndex
Arrow index.
Definition: ecvPolyline.h:279
virtual Eigen::Vector3d GetCenter() const override
Returns the center of the geometry coordinates.
bool createNewPolylinesFromSelection(std::vector< ccPolyline * > &output)
Creates a polyline mesh with the selected vertices only.
void set2DMode(bool state)
Defines if the polyline is considered as 2D or 3D.
ccPolyline & operator=(const ccPolyline &polyline)
PointCoordinateType m_width
Width of the line.
Definition: ecvPolyline.h:256
bool needTransform() const
Returns whether the polyline is considered as 2D or 3D.
Definition: ecvPolyline.h:71
ccPointCloud * samplePoints(bool densityBased, double samplingParameter, bool withRGB)
Samples points on the polyline.
static QString MetaKeyPrefixDirection()
Definition: ecvPolyline.h:238
static QString MetaKeyUpDir()
Definition: ecvPolyline.h:220
bool is2DMode() const
Returns whether the polyline is considered as 2D or 3D.
Definition: ecvPolyline.h:63
bool m_showArrow
Whether to show an arrow or not.
Definition: ecvPolyline.h:275
ecvColor::Rgb m_rgbColor
Unique RGB color.
Definition: ecvPolyline.h:253
ccPolyline(const ccPolyline &poly)
Copy constructor.
ccPolyline * smoothChaikin(PointCoordinateType ratio, unsigned iterationCount) const
Smoothes the polyline (Chaikin algorithm)
void showArrow(bool state, unsigned vertIndex, PointCoordinateType length)
Shows an arrow in place of a given vertex.
static bool IsCloudVerticesOfPolyline(ccGenericPointCloud *cloud, ccPolyline **polyline=nullptr)
Helper to determine if the input cloud acts as vertices of a polyline.
virtual void drawMeOnly(CC_DRAW_CONTEXT &context) override
Draws the entity only (not its children)
virtual Eigen::Vector3d GetMinBound() const override
Returns min bounds for geometry coordinates.
const ecvColor::Rgb & getColor() const
Returns the polyline color.
Definition: ecvPolyline.h:99
virtual ccPolyline & Scale(const double s, const Eigen::Vector3d &center) override
Apply scaling to the geometry coordinates. Given a scaling factor , and center , a given point is tr...
ccPolyline(GenericIndexedCloudPersist *associatedCloud)
Default constructor.
bool m_foreground
Definition: ecvPolyline.h:266
void setVertexMarkerWidth(int width)
Sets the width of vertex markers.
Definition: ecvPolyline.h:137
void importParametersFrom(const ccPolyline &poly)
Copy the parameters from another polyline.
unsigned getArrowIndex() const
Definition: ecvPolyline.h:133
virtual ccBBox getOwnBB(bool withGLFeatures=false) override
Returns the entity's own bounding-box.
virtual ccPolyline & Rotate(const Eigen::Matrix3d &R, const Eigen::Vector3d &center) override
Apply rotation to the geometry coordinates and normals. Given a rotation matrix , and center ,...
virtual CV_CLASS_ENUM getClassID() const override
Returns class ID.
Definition: ecvPolyline.h:41
virtual bool isSerializable() const override
Returns whether object is serializable of not.
Definition: ecvPolyline.h:46
static QString MetaKeyConstAltitude()
Meta data key: contour plot constant altitude (for contour plots, etc.)
Definition: ecvPolyline.h:224
static QString MetaKeyAbscissa()
Meta data key: profile abscissa along generatrix.
Definition: ecvPolyline.h:226
void showVertices(bool state)
Sets whether to display or hide the polyline vertices.
Definition: ecvPolyline.h:129
bool add(const ccPointCloud &cloud)
Add another reference cloud.
static QString MetaKeyPrefixCenter()
Definition: ecvPolyline.h:232
unsigned segmentCount() const
Returns the number of segments.
virtual ecvOrientedBBox GetOrientedBoundingBox() const override
virtual bool IsEmpty() const override
Definition: ecvPolyline.h:188
PointCoordinateType m_arrowLength
Arrow length.
Definition: ecvPolyline.h:277
int m_vertMarkWidth
Vertex marker width.
Definition: ecvPolyline.h:272
bool m_showVertices
Whether vertices should be displayed or not.
Definition: ecvPolyline.h:269
virtual bool hasColors() const override
Returns whether colors are enabled or not.
PointCoordinateType getWidth() const
Returns the width of the line.
Definition: ecvPolyline.h:94
bool initWith(ccPointCloud *vertices, const ccPolyline &poly)
bool arrowShown() const
Definition: ecvPolyline.h:132
virtual ccBBox GetAxisAlignedBoundingBox() const override
Returns an axis-aligned bounding box of the geometry.
virtual void applyGLTransformation(const ccGLMatrix &trans) override
Applies a GL transformation to the entity.
ccPolyline(ccPointCloud &associatedCloud)
int getVertexMarkerWidth() const
Returns the width of vertex markers.
Definition: ecvPolyline.h:139
bool m_mode2D
Whether polyline should be considered as 2D (true) or 3D (false)
Definition: ecvPolyline.h:259
ccPolyline & operator+=(const ccPolyline &polyline)
bool split(PointCoordinateType maxEdgeLength, std::vector< ccPolyline * > &parts)
Splits the polyline into several parts based on a maximum edge length.
virtual void drawBB(CC_DRAW_CONTEXT &context, const ecvColor::Rgb &col) override
Draws the entity (and its children) bounding-box.
Definition: ecvPolyline.h:103
virtual void setGlobalScale(double scale) override
static ccPolyline * Circle(const CCVector3 &center, PointCoordinateType radius, unsigned resolution=48)
Creates a circle as a polyline.
void setColor(const ecvColor::Rgb &col)
Sets the polyline color.
Definition: ecvPolyline.h:81
void setWidth(PointCoordinateType width)
Sets the width of the line.
virtual unsigned getUniqueIDForDisplay() const override
Returns object unqiue ID used for display.
QMultiMap< unsigned, unsigned > LoadedIDMap
Map of loaded unique IDs (old ID --> new ID)
Shifted entity interface.
virtual bool hasPoints() const
Definition: GenericCloud.h:37
A simple polyline class.
Definition: Polyline.h:20
RGB color structure.
Definition: ecvColorTypes.h:49
constexpr static RgbTpl FromEigen(const Eigen::Vector3d &t)
Definition: ecvColorTypes.h:86
__host__ __device__ float length(float2 v)
Definition: cutil_math.h:1162
ImGuiContext * context
Definition: Window.cpp:76
@ POLY_LINE
Definition: CVTypes.h:112
bool setColor(ccHObject::Container selectedEntities, bool colorize, QWidget *parent)
Display context.