ccGraphicalSegmentationTool.h 5.3 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_GRAPHICAL_SEGMENTATION_TOOLS_HEADER
  18. #define CC_GRAPHICAL_SEGMENTATION_TOOLS_HEADER
  19. //Local
  20. #include <ccOverlayDialog.h>
  21. //qCC_db
  22. #include <ccHObject.h>
  23. //Qt
  24. #include <QSet>
  25. //GUI
  26. #include <ui_graphicalSegmentationDlg.h>
  27. #include <set>
  28. class ccPolyline;
  29. class ccPointCloud;
  30. class ccGLWindowInterface;
  31. class ccMainAppInterface;
  32. //! Graphical segmentation mechanism (with polyline)
  33. class ccGraphicalSegmentationTool : public ccOverlayDialog, public Ui::GraphicalSegmentationDlg
  34. {
  35. Q_OBJECT
  36. public:
  37. //! Default constructor
  38. explicit ccGraphicalSegmentationTool(QWidget* parent);
  39. //! Destructor
  40. virtual ~ccGraphicalSegmentationTool();
  41. //! Adds an entity (and/or its children) to the 'to be segmented' pool
  42. /** Warning: some entities may be rejected if they are
  43. locked, or can't be segmented this way.
  44. \return whether entity has been added to the pool or not
  45. **/
  46. bool addEntity(ccHObject* anObject, bool silent = false);
  47. //! Returns the number of entites currently in the the 'to be segmented' pool
  48. unsigned getNumberOfValidEntities() const;
  49. //! Get a pointer to the polyline that has been segmented
  50. const ccPolyline* getPolyLine() const { return m_segmentationPoly; }
  51. //! Returns the active 'to be segmented' set
  52. QSet<ccHObject*>& entities() { return m_toSegment; }
  53. //! Returns the active 'to be segmented' set (const version)
  54. const QSet<ccHObject*>& entities() const { return m_toSegment; }
  55. //inherited from ccOverlayDialog
  56. virtual bool linkWith(ccGLWindowInterface* win) override;
  57. virtual bool start() override;
  58. virtual void stop(bool accepted) override;
  59. //! Returns whether hidden parts should be delete after segmentation
  60. bool deleteHiddenParts() const { return m_deleteHiddenParts; }
  61. //! Remove entities from the 'to be segmented' pool
  62. /** \warning 'unallocateVisibilityArray' will be called on all point clouds
  63. prior to be removed from the pool.
  64. **/
  65. void removeAllEntities();
  66. //! Apply segmentation and update the database (helper)
  67. bool applySegmentation(ccMainAppInterface* app, ccHObject::Container& newEntities);
  68. protected:
  69. void segmentIn();
  70. void segmentOut();
  71. void exportSelection();
  72. void segment(bool keepPointsInside, ScalarType classificationValue = CCCoreLib::NAN_VALUE, bool exportSelection = false);
  73. void reset();
  74. void options();
  75. void apply();
  76. void applyAndDelete();
  77. void cancel();
  78. inline void addPointToPolyline(int x, int y) { return addPointToPolylineExt(x, y, false); }
  79. void addPointToPolylineExt(int x, int y, bool allowClicksOutside);
  80. void closePolyLine(int x = 0, int y = 0); //arguments for compatibility with ccGlWindow::rightButtonClicked signal
  81. void closeRectangle();
  82. void updatePolyLine(int x, int y, Qt::MouseButtons buttons);
  83. void run();
  84. void stopRunning();
  85. void pauseSegmentationMode(bool);
  86. void setClassificationValue();
  87. void doSetPolylineSelection();
  88. void doSetRectangularSelection();
  89. void doActionUseExistingPolyline();
  90. void doExportSegmentationPolyline();
  91. //! To capture overridden shortcuts (pause button, etc.)
  92. void onShortcutTriggered(int);
  93. //! Prepare entity before removal
  94. void prepareEntityForRemoval(ccHObject* entity, bool unallocateVisibilityArrays);
  95. //! Whether to allow or not to exort the current segmentation polyline
  96. void allowPolylineExport(bool state);
  97. protected:
  98. //! Set of entities to be segmented
  99. QSet<ccHObject*> m_toSegment;
  100. //! Whether something has changed or not (for proper 'cancel')
  101. bool m_somethingHasChanged;
  102. //! Process states
  103. enum ProcessStates
  104. {
  105. POLYLINE = 1,
  106. RECTANGLE = 2,
  107. //... = 4,
  108. //... = 8,
  109. //... = 16,
  110. PAUSED = 32,
  111. STARTED = 64,
  112. RUNNING = 128,
  113. };
  114. //! Current process state
  115. unsigned m_state;
  116. //! Segmentation polyline
  117. ccPolyline* m_segmentationPoly;
  118. //! Segmentation polyline vertices
  119. ccPointCloud* m_polyVertices;
  120. //! Selection mode
  121. bool m_rectangularSelection;
  122. //! Whether to delete hidden parts after segmentation
  123. bool m_deleteHiddenParts;
  124. //! In export mode, entities in this set will be enabled/visible
  125. std::set<ccHObject*> m_enableOnClose;
  126. //! In export mode, entities in this set will be disabled/invisible
  127. std::set<ccHObject*> m_disableOnClose;
  128. };
  129. #endif //CC_GRAPHICAL_SEGMENTATION_TOOLS_HEADER