ccFacet.h 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. //##########################################################################
  2. //# #
  3. //# CLOUDCOMPARE #
  4. //# #
  5. //# This program is free software; you can redistribute it and/or modify #
  6. //# it under the terms of the GNU General Public License as published by #
  7. //# the Free Software Foundation; version 2 or later of the License. #
  8. //# #
  9. //# This program is distributed in the hope that it will be useful, #
  10. //# but WITHOUT ANY WARRANTY; without even the implied warranty of #
  11. //# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
  12. //# GNU General Public License for more details. #
  13. //# #
  14. //# COPYRIGHT: EDF R&D / TELECOM ParisTech (ENST-TSI) #
  15. //# #
  16. //##########################################################################
  17. #ifndef CC_FACET_HEADER
  18. #define CC_FACET_HEADER
  19. //Local
  20. #include "ccHObject.h"
  21. #include "ccPlanarEntityInterface.h"
  22. namespace CCCoreLib
  23. {
  24. class GenericIndexedCloudPersist;
  25. }
  26. class ccMesh;
  27. class ccPolyline;
  28. class ccPointCloud;
  29. //! Facet
  30. /** Composite object: point cloud + 2D1/2 contour polyline + 2D1/2 surface mesh
  31. **/
  32. class QCC_DB_LIB_API ccFacet : public ccHObject, public ccPlanarEntityInterface
  33. {
  34. public:
  35. //! Default constructor
  36. /** \param maxEdgeLength max edge length (if possible - ignored if 0)
  37. \param name name
  38. **/
  39. ccFacet(PointCoordinateType maxEdgeLength = 0,
  40. const QString& name = QString("Facet"));
  41. //! Destructor
  42. ~ccFacet() override = default;
  43. //! Creates a facet from a set of points
  44. /** The facet boundary can either be the convex hull (maxEdgeLength = 0)
  45. or the concave hull (maxEdgeLength > 0).
  46. \param cloud cloud from which to create the facet
  47. \param maxEdgeLength max edge length (if possible - ignored if 0)
  48. \param transferOwnership if true and the input cloud is a ccPointCloud, it will be 'kept' as 'origin points'
  49. \param planeEquation to input a custom plane equation
  50. \return a facet (or 0 if an error occurred)
  51. **/
  52. static ccFacet* Create( CCCoreLib::GenericIndexedCloudPersist* cloud,
  53. PointCoordinateType maxEdgeLength = 0,
  54. bool transferOwnership = false,
  55. const PointCoordinateType* planeEquation = nullptr);
  56. //! Returns class ID
  57. CC_CLASS_ENUM getClassID() const override { return CC_TYPES::FACET; }
  58. bool isSerializable() const override { return true; }
  59. //! Sets the facet unique color
  60. /** \param rgb RGB color
  61. **/
  62. void setColor(const ccColor::Rgb& rgb);
  63. //inherited from ccPlanarEntityInterface
  64. inline CCVector3 getNormal() const override { return CCVector3(m_planeEquation); }
  65. //! Returns associated RMS
  66. inline double getRMS() const { return m_rms; }
  67. //! Returns associated surface
  68. inline double getSurface() const { return m_surface; }
  69. //! Returns plane equation
  70. inline const PointCoordinateType* getPlaneEquation() const { return m_planeEquation; }
  71. //! Inverts the facet normal
  72. void invertNormal();
  73. //! Returns the facet center
  74. inline const CCVector3& getCenter() const { return m_center; }
  75. //! Returns polygon mesh (if any)
  76. inline ccMesh* getPolygon() { return m_polygonMesh; }
  77. //! Returns polygon mesh (if any)
  78. inline const ccMesh* getPolygon() const { return m_polygonMesh; }
  79. //! Returns contour polyline (if any)
  80. inline ccPolyline* getContour() { return m_contourPolyline; }
  81. //! Returns contour polyline (if any)
  82. inline const ccPolyline* getContour() const { return m_contourPolyline; }
  83. //! Returns contour vertices (if any)
  84. inline ccPointCloud* getContourVertices() { return m_contourVertices; }
  85. //! Returns contour vertices (if any)
  86. inline const ccPointCloud* getContourVertices() const { return m_contourVertices; }
  87. //! Returns origin points (if any)
  88. inline ccPointCloud* getOriginPoints() { return m_originPoints; }
  89. //! Returns origin points (if any)
  90. inline const ccPointCloud* getOriginPoints() const { return m_originPoints; }
  91. //! Sets polygon mesh
  92. inline void setPolygon(ccMesh* mesh) { m_polygonMesh = mesh; }
  93. //! Sets contour polyline
  94. inline void setContour(ccPolyline* poly) { m_contourPolyline = poly; }
  95. //! Sets contour vertices
  96. inline void setContourVertices(ccPointCloud* cloud) { m_contourVertices = cloud; }
  97. //! Sets origin points
  98. inline void setOriginPoints(ccPointCloud* cloud) { m_originPoints = cloud; }
  99. //! Clones this facet
  100. ccFacet* clone() const;
  101. protected:
  102. //inherited from ccDrawable
  103. void drawMeOnly(CC_DRAW_CONTEXT& context) override;
  104. //! Creates internal representation (polygon, polyline, etc.)
  105. bool createInternalRepresentation( CCCoreLib::GenericIndexedCloudPersist* points,
  106. const PointCoordinateType* planeEquation = nullptr);
  107. //! Facet
  108. ccMesh* m_polygonMesh;
  109. //! Facet contour
  110. ccPolyline* m_contourPolyline;
  111. //! Shared vertices (between polygon and contour)
  112. ccPointCloud* m_contourVertices;
  113. //! Origin points
  114. ccPointCloud* m_originPoints;
  115. //! Plane equation - as usual in CC plane equation is ax + by + cz = d
  116. PointCoordinateType m_planeEquation[4];
  117. //! Facet centroid
  118. CCVector3 m_center;
  119. //! RMS (relatively to m_associatedPoints)
  120. double m_rms;
  121. //! Surface (m_polygon)
  122. double m_surface;
  123. //! Max length
  124. PointCoordinateType m_maxEdgeLength;
  125. //inherited from ccHObject
  126. bool toFile_MeOnly(QFile& out, short dataVersion) const override;
  127. bool fromFile_MeOnly(QFile& in, short dataVersion, int flags, LoadedIDMap& oldToNewIDMap) override;
  128. short minimumFileVersion_MeOnly() const override;
  129. // ccHObject interface
  130. void applyGLTransformation(const ccGLMatrix &trans) override;
  131. };
  132. #endif //CC_FACET_PRIMITIVE_HEADER