ccPolyline.h 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237
  1. #pragma once
  2. //##########################################################################
  3. //# #
  4. //# CLOUDCOMPARE #
  5. //# #
  6. //# This program is free software; you can redistribute it and/or modify #
  7. //# it under the terms of the GNU General Public License as published by #
  8. //# the Free Software Foundation; version 2 or later of the License. #
  9. //# #
  10. //# This program is distributed in the hope that it will be useful, #
  11. //# but WITHOUT ANY WARRANTY; without even the implied warranty of #
  12. //# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
  13. //# GNU General Public License for more details. #
  14. //# #
  15. //# COPYRIGHT: EDF R&D / TELECOM ParisTech (ENST-TSI) #
  16. //# #
  17. //##########################################################################
  18. //CCCoreLib
  19. #include <Polyline.h>
  20. //Local
  21. #include "ccShiftedObject.h"
  22. class ccPointCloud;
  23. class ccGenericPointCloud;
  24. //! Colored polyline
  25. /** Extends the CCCoreLib::Polyline class
  26. **/
  27. class QCC_DB_LIB_API ccPolyline : public CCCoreLib::Polyline, public ccShiftedObject
  28. {
  29. public:
  30. //! Default constructor
  31. /** \param associatedCloud the associated point cloud (i.e. the vertices)
  32. \param uniqueID unique ID (handle with care)
  33. **/
  34. explicit ccPolyline(GenericIndexedCloudPersist* associatedCloud, unsigned uniqueID = ccUniqueIDGenerator::InvalidUniqueID);
  35. //! Copy constructor
  36. /** \param poly polyline to copy/clone
  37. **/
  38. ccPolyline(const ccPolyline& poly);
  39. //! Destructor
  40. virtual ~ccPolyline() override = default;
  41. //! Returns class ID
  42. CC_CLASS_ENUM getClassID() const override { return CC_TYPES::POLY_LINE; }
  43. //inherited methods (ccHObject)
  44. bool isSerializable() const override { return true; }
  45. bool hasColors() const override;
  46. void applyGLTransformation(const ccGLMatrix& trans) override;
  47. //inherited methods (ccShiftedObject)
  48. void setGlobalShift(const CCVector3d& shift) override;
  49. void setGlobalScale(double scale) override;
  50. const CCVector3d& getGlobalShift() const override;
  51. double getGlobalScale() const override;
  52. //! Removes unused capacity
  53. inline void shrinkToFit() { if (size() < capacity()) resize(size()); }
  54. //! Clones this polyline
  55. ccPolyline* clone() const;
  56. //! Defines if the polyline is considered as 2D or 3D
  57. /** \param state if true, the polyline is 2D
  58. **/
  59. void set2DMode(bool state);
  60. //! Returns whether the polyline is considered as 2D or 3D
  61. inline bool is2DMode() const { return m_mode2D; }
  62. //! Defines if the polyline is drawn in background or foreground
  63. /** \param state if true, the polyline is drawn in foreground
  64. **/
  65. void setForeground(bool state);
  66. //! Sets the polyline color
  67. /** \param col RGB color
  68. **/
  69. inline void setColor(const ccColor::Rgb& col) { m_rgbColor = col; }
  70. //! Sets the width of the line
  71. /** \param width the desired width
  72. **/
  73. void setWidth(PointCoordinateType width);
  74. //! Returns the width of the line
  75. /** \return the width of the line in pixels
  76. **/
  77. inline PointCoordinateType getWidth() const { return m_width; }
  78. //! Returns the polyline color
  79. /** \return a pointer to the polyline RGB color
  80. **/
  81. inline const ccColor::Rgb& getColor() const { return m_rgbColor; }
  82. //inherited methods (ccHObject)
  83. virtual ccBBox getOwnBB(bool withGLFeatures = false) override;
  84. inline virtual void drawBB(CC_DRAW_CONTEXT& context, const ccColor::Rgb& col) override
  85. {
  86. //DGM: only for 3D polylines!
  87. if (!is2DMode())
  88. {
  89. ccShiftedObject::drawBB(context, col);
  90. }
  91. }
  92. //! Splits the polyline into several parts based on a maximum edge length
  93. /** \warning output polylines set (parts) may be empty if all the vertices are too far from each other!
  94. \param[in] maxEdgeLength maximum edge length
  95. \param[out] parts output polyline parts
  96. \return success
  97. **/
  98. bool split( PointCoordinateType maxEdgeLength, std::vector<ccPolyline*>& parts );
  99. //! Computes the polyline length
  100. PointCoordinateType computeLength() const;
  101. //! Sets whether to display or hide the polyline vertices
  102. void showVertices(bool state) { m_showVertices = state; }
  103. //! Whether the polyline vertices should be displayed or not
  104. bool verticesShown() const { return m_showVertices; }
  105. //! Sets the width of vertex markers
  106. void setVertexMarkerWidth(int width) { m_vertMarkWidth = width; }
  107. //! Returns the width of vertex markers
  108. int getVertexMarkerWidth() const { return m_vertMarkWidth; }
  109. //! Initializes the polyline with a given set of vertices and the parameters of another polyline
  110. /** \warning Even the 'closed' state is copied as is!
  111. \param vertices set of vertices (can be null, in which case the polyline vertices will be cloned)
  112. \param poly polyline
  113. \return success
  114. **/
  115. bool initWith(ccPointCloud*& vertices, const ccPolyline& poly);
  116. //! Copy the parameters from another polyline
  117. void importParametersFrom(const ccPolyline& poly);
  118. //! Shows an arrow in place of a given vertex
  119. void showArrow(bool state, unsigned vertIndex, PointCoordinateType length);
  120. //! Returns the number of segments
  121. unsigned segmentCount() const;
  122. //! Samples points on the polyline
  123. ccPointCloud* samplePoints( bool densityBased,
  124. double samplingParameter,
  125. bool withRGB);
  126. //! Smoothes the polyline (Chaikin algorithm)
  127. /** \param ratio between 0 and 0.5 (excluded)
  128. \param iterationCount of iteration
  129. \return smoothed polyline
  130. **/
  131. ccPolyline* smoothChaikin( PointCoordinateType ratio,
  132. unsigned iterationCount) const;
  133. //! Creates a polyline mesh with the selected vertices only
  134. /** This method is called after a graphical segmentation.
  135. It creates one or several new polylines with the segments having both
  136. vertices tagged as "visible" (see ccGenericPointCloud::visibilityArray).
  137. **/
  138. bool createNewPolylinesFromSelection(std::vector<ccPolyline*>& output);
  139. //! Helper to determine if the input cloud acts as vertices of a polyline
  140. static bool IsCloudVerticesOfPolyline(ccGenericPointCloud* cloud, ccPolyline** polyline = nullptr);
  141. //! Creates a circle as a polyline
  142. static ccPolyline* Circle(const CCVector3& center, PointCoordinateType radius, unsigned resolution = 48);
  143. public: //meta-data keys
  144. //! Meta data key: vertical direction (for 2D polylines, contour plots, etc.)
  145. /** Expected value: 0(=X), 1(=Y) or 2(=Z) as int
  146. **/
  147. static QString MetaKeyUpDir() { return "up.dir"; }
  148. //! Meta data key: contour plot constant altitude (for contour plots, etc.)
  149. /** Expected value: altitude as double
  150. **/
  151. static QString MetaKeyConstAltitude() { return "contour.altitude"; }
  152. //! Meta data key: profile abscissa along generatrix
  153. static QString MetaKeyAbscissa() { return "profile.abscissa"; }
  154. //! Meta data key (prefix): intersection point between profile and its generatrix
  155. /** Expected value: 3D vector
  156. \warning must be followed by '.x', '.y' or '.z'
  157. **/
  158. static QString MetaKeyPrefixCenter() { return "profile.center"; }
  159. //! Meta data key (prefix): generatrix orientation at the point of intersection with the profile
  160. /** Expected value: 3D vector
  161. \warning must be followed by '.x', '.y' or '.z'
  162. **/
  163. static QString MetaKeyPrefixDirection() { return "profile.direction"; }
  164. protected:
  165. //inherited from ccHObject
  166. bool toFile_MeOnly(QFile& out, short dataVersion) const override;
  167. bool fromFile_MeOnly(QFile& in, short dataVersion, int flags, LoadedIDMap& oldToNewIDMap) override;
  168. short minimumFileVersion_MeOnly() const override;
  169. //inherited methods (ccHObject)
  170. void drawMeOnly(CC_DRAW_CONTEXT& context) override;
  171. //! Unique RGB color
  172. ccColor::Rgb m_rgbColor;
  173. //! Width of the line
  174. PointCoordinateType m_width;
  175. //! Whether polyline should be considered as 2D (true) or 3D (false)
  176. bool m_mode2D;
  177. //! Whether polyline should draws itself in background (false) or foreground (true)
  178. bool m_foreground;
  179. //! Whether vertices should be displayed or not
  180. bool m_showVertices;
  181. //! Vertex marker width
  182. int m_vertMarkWidth;
  183. //! Whether to show an arrow or not
  184. bool m_showArrow;
  185. //! Arrow length
  186. PointCoordinateType m_arrowLength;
  187. //! Arrow index
  188. unsigned m_arrowIndex;
  189. };