ccClipBox.h 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  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_CLIP_BOX_HEADER
  18. #define CC_CLIP_BOX_HEADER
  19. //Local
  20. #include "ccBBox.h"
  21. #include "ccGenericPointCloud.h"
  22. #include "ccHObject.h"
  23. #include "ccInteractor.h"
  24. //Qt
  25. #include <QObject>
  26. class ccClipBoxPart;
  27. //! Clipping box
  28. class QCC_DB_LIB_API ccClipBox : public QObject, public ccHObject, public ccInteractor
  29. {
  30. Q_OBJECT
  31. public:
  32. //! Default constructor
  33. /** \param name entity name (optional)
  34. \param uniqueID unique ID (handle with care)
  35. **/
  36. ccClipBox(QString name = QString("Clipping box"), unsigned uniqueID = ccUniqueIDGenerator::InvalidUniqueID);
  37. //! Destructor
  38. ~ccClipBox() override;
  39. //! Adds an associated entity
  40. /** Warning: resets the current clipping box
  41. **/
  42. bool addAssociatedEntity(ccHObject* associatedEntity);
  43. //! Releases all associated entities
  44. /** Warning: resets the current clipping box
  45. **/
  46. void releaseAssociatedEntities();
  47. //inherited from ccHObject
  48. ccBBox getOwnBB(bool withGLFeatures = false) override;
  49. //inherited from ccInteractor
  50. //bool move2D(int x, int y, int dx, int dy, int screenWidth, int screenHeight) override;
  51. bool move3D(const CCVector3d& u) override;
  52. //! Sets last clicked point (on screen)
  53. void setClickedPoint(int x, int y, int screenWidth, int screenHeight, const ccGLMatrixd& viewMatrix);
  54. //! Components
  55. enum Components { NONE = 0,
  56. X_MINUS_ARROW,
  57. X_PLUS_ARROW,
  58. Y_MINUS_ARROW,
  59. Y_PLUS_ARROW,
  60. Z_MINUS_ARROW,
  61. Z_PLUS_ARROW,
  62. CROSS,
  63. X_MINUS_TORUS,
  64. Y_MINUS_TORUS,
  65. Z_MINUS_TORUS,
  66. X_PLUS_TORUS,
  67. Y_PLUS_TORUS,
  68. Z_PLUS_TORUS
  69. };
  70. //! Sets currently active component
  71. /** \param id component ID (see Components)
  72. **/
  73. void setActiveComponent(Components id);
  74. //inherited from ccHObject
  75. inline CC_CLASS_ENUM getClassID() const override { return CC_TYPES::CLIPPING_BOX; }
  76. //! Returns the box extents
  77. inline const ccBBox& getBox() const { return m_box; }
  78. //! Whether to show the box or not
  79. inline void showBox(bool state) { m_showBox = state; }
  80. //! Sets the box extents
  81. void setBox(const ccBBox& box);
  82. //! Shifts the current box
  83. void shift(const CCVector3& v);
  84. //! Flags the points of a given cloud depending on whether they are inside or outside of this clipping box
  85. /** \param cloud point cloud
  86. \param visTable visibility flags
  87. \param shrink Whether the box is shrinking (faster) or not
  88. **/
  89. void flagPointsInside( ccGenericPointCloud* cloud,
  90. ccGenericPointCloud::VisibilityTableType* visTable,
  91. bool shrink = false) const;
  92. //! Resets box
  93. void reset();
  94. //! Manually sets the box parameters
  95. void set(const ccBBox& extents, const ccGLMatrix& transformation);
  96. //! Returns the box parameters
  97. void get(ccBBox& extents, ccGLMatrix& transformation);
  98. //! Associated entity container
  99. inline const ccHObject& getContainer() const { return m_entityContainer; }
  100. Q_SIGNALS:
  101. //! Signal sent each time the box is modified
  102. void boxModified(const ccBBox* box);
  103. protected: //methods
  104. //! Updates the associated entity clipping planes
  105. void update();
  106. //inherited from ccHObject
  107. void drawMeOnly(CC_DRAW_CONTEXT& context) override;
  108. //! Computes arrows display scale
  109. PointCoordinateType computeArrowsScale() const;
  110. protected: //members
  111. //! Associated entities container
  112. ccHObject m_entityContainer;
  113. //! Clipping box
  114. ccBBox m_box;
  115. //! Show box
  116. bool m_showBox;
  117. //! Active component
  118. Components m_activeComponent;
  119. //! Last "orientation" vector (corresponding to last clicked point)
  120. CCVector3d m_lastOrientation;
  121. //! View matrix
  122. ccGLMatrixd m_viewMatrix;
  123. //! Sub-parts (proxies)
  124. QMap<int, ccClipBoxPart*> m_parts;
  125. };
  126. //! Part of the clipping box (for picking)
  127. class QCC_DB_LIB_API ccClipBoxPart : public ccHObject
  128. {
  129. public:
  130. //! Default constructor
  131. /** \param color picking color
  132. \param partID part ID
  133. **/
  134. ccClipBoxPart(ccClipBox* clipBox, ccClipBox::Components partID)
  135. : m_clipBox(clipBox)
  136. , m_partID(partID)
  137. {}
  138. //inherited from ccHObject
  139. inline CC_CLASS_ENUM getClassID() const override { return CC_TYPES::CLIPPING_BOX_PART; }
  140. //! Returns the corresponding part ID
  141. inline ccClipBox::Components partID() const { return m_partID; }
  142. //! Returns the associated clipping box
  143. ccClipBox* clipBox() { return m_clipBox; }
  144. protected:
  145. //! Associated clipping box
  146. ccClipBox* m_clipBox;
  147. //! Part number
  148. ccClipBox::Components m_partID;
  149. };
  150. #endif //CC_CLIP_BOX_HEADER