ccQuadric.h 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  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_QUADRIC_PRIMITIVE_HEADER
  18. #define CC_QUADRIC_PRIMITIVE_HEADER
  19. //Local
  20. #include "ccGenericPrimitive.h"
  21. //! Quadric (primitive)
  22. /** 2D1/2 quadric primitive
  23. **/
  24. class QCC_DB_LIB_API ccQuadric : public ccGenericPrimitive
  25. {
  26. public:
  27. //! Default drawing precision
  28. /** \warning Never pass a 'constant initializer' by reference
  29. **/
  30. static const unsigned DEFAULT_DRAWING_PRECISION = 24;
  31. //! Default constructor
  32. /** Quadric orthogonal dimension is 'Z' by default
  33. \param minCorner min corner of the 'representation' base area
  34. \param maxCorner max corner of the 'representation' base area
  35. \param eq equation coefficients ( Z = a + b.X + c.Y + d.X^2 + e.X.Y + f.Y^2)
  36. \param dims optional dimension indexes
  37. \param transMat optional 3D transformation (can be set afterwards with ccDrawableObject::setGLTransformation)
  38. \param name name
  39. \param precision drawing precision
  40. **/
  41. ccQuadric( CCVector2 minCorner,
  42. CCVector2 maxCorner,
  43. const PointCoordinateType eq[6],
  44. const Tuple3ub* dims = nullptr,
  45. const ccGLMatrix* transMat = nullptr,
  46. QString name = QString("Quadric"),
  47. unsigned precision = DEFAULT_DRAWING_PRECISION);
  48. //! Simplified constructor
  49. /** For ccHObject factory only!
  50. **/
  51. ccQuadric(QString name = QString("Plane"));
  52. //! Returns class ID
  53. virtual CC_CLASS_ENUM getClassID() const override { return CC_TYPES::QUADRIC; }
  54. //inherited from ccGenericPrimitive
  55. virtual QString getTypeName() const override { return "Quadric"; }
  56. virtual bool hasDrawingPrecision() const override { return true; }
  57. virtual ccGenericPrimitive* clone() const override;
  58. //inherited from ccHObject
  59. virtual ccBBox getOwnFitBB(ccGLMatrix& trans) override;
  60. //! Returns min corner
  61. const CCVector2& getMinCorner() const { return m_minCorner; }
  62. //! Returns max corner
  63. const CCVector2& getMaxCorner() const { return m_maxCorner; }
  64. //! Returns the equation coefficients
  65. inline const PointCoordinateType* getEquationCoefs() const { return m_eq; }
  66. //! Returns the equation 'coordinate system' (X,Y,Z dimensions indexes)
  67. inline const Tuple3ub& getEquationDims() const { return m_dims; }
  68. //! Projects a 3D point in the quadric coordinate system
  69. /** \param P input 3D point
  70. \param[out] Q position of the input point in the quadric coordinate system
  71. \return elevation of the input point (in the coordinate system quadric)
  72. **/
  73. PointCoordinateType projectOnQuadric(const CCVector3& P, CCVector3& Q) const;
  74. //! Returns the equation coefficients as a string
  75. QString getEquationString() const;
  76. //! Fits a quadric primitive on a cloud
  77. /** The cloud can be any CCCoreLib::GenericIndexedCloudPersist-derived object.
  78. \param[in] cloud input cloud
  79. \param[out] rms quadric fitting rms (optional)
  80. \return quadric primitive (if successful)
  81. **/
  82. static ccQuadric* Fit(CCCoreLib::GenericIndexedCloudPersist * cloud, double* rms = nullptr);
  83. protected:
  84. //inherited from ccGenericPrimitive
  85. bool toFile_MeOnly(QFile& out, short dataVersion) const override;
  86. bool fromFile_MeOnly(QFile& in, short dataVersion, int flags, LoadedIDMap& oldToNewIDMap) override;
  87. short minimumFileVersion_MeOnly() const override;
  88. bool buildUp() override;
  89. //! Min corner
  90. CCVector2 m_minCorner;
  91. //! Max corner
  92. CCVector2 m_maxCorner;
  93. //! Equation coefficients
  94. PointCoordinateType m_eq[6];
  95. //! Dimension indexes
  96. Tuple3ub m_dims;
  97. //! Min height
  98. PointCoordinateType m_minZ;
  99. //! Max height
  100. PointCoordinateType m_maxZ;
  101. };
  102. #endif //CC_QUADRIC_PRIMITIVE_HEADER