ccSectionExtractionTool.h 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237
  1. #pragma once
  2. //##########################################################################
  3. //# #
  4. //# CLOUDCOMPARE #
  5. //# #
  6. //# This program is free software; you can redistribute it and/or modify #
  7. //# it under the terms of the GNU General Public License as published by #
  8. //# the Free Software Foundation; version 2 or later of the License. #
  9. //# #
  10. //# This program is distributed in the hope that it will be useful, #
  11. //# but WITHOUT ANY WARRANTY; without even the implied warranty of #
  12. //# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
  13. //# GNU General Public License for more details. #
  14. //# #
  15. //# COPYRIGHT: EDF R&D / TELECOM ParisTech (ENST-TSI) #
  16. //# #
  17. //##########################################################################
  18. //Local
  19. #include "ccEnvelopeExtractor.h"
  20. #include "ccOverlayDialog.h"
  21. //qCC_db
  22. #include <ccHObject.h>
  23. class ccGenericPointCloud;
  24. class ccPointCloud;
  25. class ccGLWindowInterface;
  26. namespace Ui
  27. {
  28. class SectionExtractionDlg;
  29. }
  30. //! Section extraction tool
  31. class ccSectionExtractionTool : public ccOverlayDialog
  32. {
  33. Q_OBJECT
  34. public:
  35. //! Default constructor
  36. explicit ccSectionExtractionTool(QWidget* parent);
  37. //! Destructor
  38. ~ccSectionExtractionTool() override;
  39. //! Adds a cloud to the 'clouds' pool
  40. bool addCloud(ccGenericPointCloud* cloud, bool alreadyInDB = true);
  41. //! Adds a polyline to the 'sections' pool
  42. /** \warning: if this method returns true, the class takes the ownership of the cloud!
  43. **/
  44. bool addPolyline(ccPolyline* poly, bool alreadyInDB = true);
  45. //! Removes all registered entities (clouds & polylines)
  46. void removeAllEntities();
  47. //inherited from ccOverlayDialog
  48. bool linkWith(ccGLWindowInterface* win) override;
  49. bool start() override;
  50. void stop(bool accepted) override;
  51. protected:
  52. void undo();
  53. bool reset(bool askForConfirmation = true);
  54. void apply();
  55. void cancel();
  56. void addPointToPolyline(int x, int y);
  57. void closePolyLine(int x=0, int y=0); //arguments for compatibility with ccGlWindow::rightButtonClicked signal
  58. void updatePolyLine(int x, int y, Qt::MouseButtons buttons);
  59. void enableSectionEditingMode(bool);
  60. void doImportPolylinesFromDB();
  61. void setVertDimension(int);
  62. void entitySelected(ccHObject*);
  63. void generateOrthoSections();
  64. void extractPoints();
  65. void unfoldPoints();
  66. void exportSections();
  67. //! To capture overridden shortcuts (pause button, etc.)
  68. void onShortcutTriggered(int);
  69. protected:
  70. //! Projects a 2D (screen) point to 3D
  71. //CCVector3 project2Dto3D(int x, int y) const;
  72. //! Cancels currently edited polyline
  73. void cancelCurrentPolyline();
  74. //! Deletes currently selected polyline
  75. void deleteSelectedPolyline();
  76. //! Adds a 'step' on the undo stack
  77. void addUndoStep();
  78. //! Convert one or several ReferenceCloud instances to a single cloud and add it to the main DB
  79. bool extractSectionCloud( const std::vector<CCCoreLib::ReferenceCloud*>& refClouds,
  80. unsigned sectionIndex,
  81. bool& cloudGenerated);
  82. //! Extract the envelope from a set of 2D points and add it to the main DB
  83. bool extractSectionEnvelope(const ccPolyline* originalSection,
  84. const ccPointCloud* originalSectionCloud,
  85. ccPointCloud* unrolledSectionCloud, //'2D' cloud with Z = 0
  86. unsigned sectionIndex,
  87. ccEnvelopeExtractor::EnvelopeType type,
  88. PointCoordinateType maxEdgeLength,
  89. bool multiPass,
  90. bool splitEnvelope,
  91. bool& envelopeGenerated,
  92. bool visualDebugMode = false);
  93. //! Creates (if necessary) and returns a group to store entities in the main DB
  94. ccHObject* getExportGroup(unsigned& defaultGroupID, const QString& defaultName);
  95. //! Imported entity
  96. template<class EntityType> struct ImportedEntity
  97. {
  98. //! Default constructor
  99. ImportedEntity()
  100. : entity(0)
  101. , originalDisplay(nullptr)
  102. , isInDB(false)
  103. , backupColorShown(false)
  104. , backupWidth(1)
  105. {}
  106. //! Copy constructor
  107. ImportedEntity(const ImportedEntity& section)
  108. : entity(section.entity)
  109. , originalDisplay(section.originalDisplay)
  110. , isInDB(section.isInDB)
  111. , backupColorShown(section.backupColorShown)
  112. , backupWidth(section.backupWidth)
  113. {
  114. backupColor = section.backupColor;
  115. }
  116. //! Constructor from an entity
  117. ImportedEntity(EntityType* e, bool alreadyInDB)
  118. : entity(e)
  119. , originalDisplay(e->getDisplay())
  120. , isInDB(alreadyInDB)
  121. , backupColorShown(false)
  122. , backupWidth(0)
  123. {
  124. //specific case: polylines
  125. if (e->isA(CC_TYPES::POLY_LINE))
  126. {
  127. ccPolyline* poly = reinterpret_cast<ccPolyline*>(e);
  128. //backup color
  129. backupColor = poly->getColor();
  130. backupColorShown = poly->colorsShown();
  131. //backup thickness
  132. backupWidth = poly->getWidth();
  133. }
  134. }
  135. bool operator ==(const ImportedEntity& ie) { return entity == ie.entity; }
  136. EntityType* entity;
  137. ccGenericGLDisplay* originalDisplay;
  138. bool isInDB;
  139. //backup info (for polylines only)
  140. ccColor::Rgb backupColor;
  141. bool backupColorShown;
  142. PointCoordinateType backupWidth;
  143. };
  144. //! Section
  145. using Section = ImportedEntity<ccPolyline>;
  146. //! Releases a polyline
  147. /** The polyline is removed from display. Then it is
  148. deleted if the polyline is not already in DB.
  149. **/
  150. void releasePolyline(Section* section);
  151. //! Cloud
  152. using Cloud = ImportedEntity<ccGenericPointCloud>;
  153. //! Type of the pool of active sections
  154. using SectionPool = QList<Section>;
  155. //! Type of the pool of clouds
  156. using CloudPool = QList<Cloud>;
  157. //! Process states
  158. enum ProcessStates
  159. {
  160. //... = 1,
  161. //... = 2,
  162. //... = 4,
  163. //... = 8,
  164. //... = 16,
  165. PAUSED = 32,
  166. STARTED = 64,
  167. RUNNING = 128,
  168. };
  169. //! Deselects the currently selected polyline
  170. void selectPolyline(Section* poly, bool autoRefreshDisplay = true);
  171. //! Updates the global clouds bounding-box
  172. void updateCloudsBox();
  173. private: //members
  174. //! Associated UI
  175. Ui::SectionExtractionDlg* m_UI;
  176. //! Pool of active sections
  177. SectionPool m_sections;
  178. //! Selected polyline (if any)
  179. Section* m_selectedPoly;
  180. //! Pool of clouds
  181. CloudPool m_clouds;
  182. //! Current process state
  183. unsigned m_state;
  184. //! Last 'undo' count
  185. std::vector<size_t> m_undoCount;
  186. //! Currently edited polyline
  187. ccPolyline* m_editedPoly;
  188. //! Segmentation polyline vertices
  189. ccPointCloud* m_editedPolyVertices;
  190. //! Global clouds bounding-box
  191. ccBBox m_cloudsBox;
  192. };