ccPlane.h 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  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_PLANE_PRIMITIVE_HEADER
  18. #define CC_PLANE_PRIMITIVE_HEADER
  19. //Local
  20. #include "ccGenericPrimitive.h"
  21. #include "ccPlanarEntityInterface.h"
  22. //! Plane (primitive)
  23. /** 3D plane primitive
  24. **/
  25. class QCC_DB_LIB_API ccPlane : public ccGenericPrimitive, public ccPlanarEntityInterface
  26. {
  27. public:
  28. //! Default constructor
  29. /** Plane normal corresponds to 'Z' dimension
  30. \param xWidth plane width along 'X' dimension
  31. \param yWidth plane width along 'Y' dimension
  32. \param transMat optional 3D transformation (can be set afterwards with ccDrawableObject::setGLTransformation)
  33. \param name name
  34. **/
  35. ccPlane(PointCoordinateType xWidth,
  36. PointCoordinateType yWidth,
  37. const ccGLMatrix* transMat = nullptr,
  38. QString name = QString("Plane"));
  39. //! Simplified constructor
  40. /** For ccHObject factory only!
  41. **/
  42. ccPlane(QString name = QString("Plane"));
  43. //! Returns class ID
  44. virtual CC_CLASS_ENUM getClassID() const override { return CC_TYPES::PLANE; }
  45. //inherited from ccGenericPrimitive
  46. virtual QString getTypeName() const override { return "Plane"; }
  47. virtual ccGenericPrimitive* clone() const override;
  48. //inherited from ccHObject
  49. virtual ccBBox getOwnFitBB(ccGLMatrix& trans) override;
  50. //! Returns 'X' width
  51. PointCoordinateType getXWidth() const { return m_xWidth; }
  52. //! Returns 'Y' width
  53. PointCoordinateType getYWidth() const { return m_yWidth; }
  54. //! Returns the center
  55. CCVector3 getCenter() const { return m_transformation.getTranslationAsVec3D(); }
  56. //! Sets 'X' width
  57. void setXWidth(PointCoordinateType w, bool autoUpdate = true) { m_xWidth = w; if (autoUpdate) updateRepresentation(); }
  58. //! Sets 'Y' width
  59. void setYWidth(PointCoordinateType h, bool autoUpdate = true) { m_yWidth = h; if (autoUpdate) updateRepresentation(); }
  60. //inherited from ccPlanarEntityInterface
  61. CCVector3 getNormal() const override { return m_transformation.getColumnAsVec3D(2); }
  62. //! Sets an image as texture
  63. /** \return The created material (if successful)
  64. **/
  65. ccMaterial::Shared setAsTexture(QImage image, QString imageFilename = QString());
  66. //! Sets an image as texture for a quad mesh
  67. /** \return The created material (if successful)
  68. **/
  69. static ccMaterial::Shared SetQuadTexture(ccMesh* quadMesh, QImage image, QString imageFilename = QString());
  70. //! Fits a plane primitive on a cloud
  71. /** The cloud can be any CCCoreLib::GenericIndexedCloudPersist-derived object,
  72. i.e. even a ccPolyline object for instance.
  73. \param[in] cloud input cloud
  74. \param[out] rms plane fitting rms (optional)
  75. \return plane primitive (if successful)
  76. **/
  77. static ccPlane* Fit(CCCoreLib::GenericIndexedCloudPersist * cloud, double* rms = nullptr);
  78. //! Returns the equation of the plane
  79. /** Equation:
  80. N.P + constVal = 0
  81. i.e. Nx.x + Ny.y + Nz.z + constVal = 0
  82. **/
  83. void getEquation(CCVector3& N, PointCoordinateType& constVal) const;
  84. //! Returns the equation of the plane
  85. /** Equation:
  86. planeEquation plane equation : [a, b, c, d] as 'ax+by+cz=d'
  87. Same equation used in Neighbourhood and DistanceComputationTools
  88. **/
  89. const PointCoordinateType* getEquation();
  90. //! Flips the plane
  91. void flip();
  92. protected:
  93. //inherited from ccDrawable
  94. void drawMeOnly(CC_DRAW_CONTEXT& context) override;
  95. //inherited from ccGenericPrimitive
  96. bool toFile_MeOnly(QFile& out, short dataVersion) const override;
  97. bool fromFile_MeOnly(QFile& in, short dataVersion, int flags, LoadedIDMap& oldToNewIDMap) override;
  98. short minimumFileVersion_MeOnly() const override;
  99. bool buildUp() override;
  100. //! Width along 'X' dimension
  101. PointCoordinateType m_xWidth;
  102. //! Width along 'Y' dimension
  103. PointCoordinateType m_yWidth;
  104. // Array [a,b,c,d] such that ax+by+cz = d
  105. PointCoordinateType m_PlaneEquation[4];
  106. };
  107. #endif //CC_PLANE_PRIMITIVE_HEADER