ccPointPairRegistrationDlg.h 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  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 "ccMainAppInterface.h"
  20. #include "ccOverlayDialog.h"
  21. #include "ccPickingListener.h"
  22. //CCCoreLib
  23. #include <PointProjectionTools.h>
  24. //qCC_db
  25. #include <ccPointCloud.h>
  26. //Qt generated dialog
  27. #include <ui_pointPairRegistrationDlg.h>
  28. class ccGenericPointCloud;
  29. class ccGenericGLDisplay;
  30. class ccGLWindowInterface;
  31. class cc2DLabel;
  32. class ccPickingHub;
  33. class QStringList;
  34. //Dialog for the point-pair registration algorithm (Horn)
  35. class ccPointPairRegistrationDlg : public ccOverlayDialog, public ccPickingListener, Ui::pointPairRegistrationDlg
  36. {
  37. Q_OBJECT
  38. public:
  39. //! Default constructor
  40. explicit ccPointPairRegistrationDlg(ccPickingHub* pickingHub, ccMainAppInterface* app, QWidget* parent = nullptr);
  41. //inherited from ccOverlayDialog
  42. bool linkWith(ccGLWindowInterface* win) override;
  43. bool start() override;
  44. void stop(bool state) override;
  45. //! Inits dialog
  46. bool init( ccGLWindowInterface* win,
  47. const ccHObject::Container& alignedEntities,
  48. const ccHObject::Container* referenceEntities = nullptr);
  49. //! Clears dialog
  50. void clear();
  51. //! Pauses the dialog
  52. void pause(bool state);
  53. //! Adds a point to the 'align' set
  54. bool addAlignedPoint(CCVector3d& P, ccHObject* entity = nullptr, bool shifted = true);
  55. //! Adds a point to the 'reference' set
  56. bool addReferencePoint(CCVector3d& P, ccHObject* entity = nullptr, bool shifted = true);
  57. //! Removes a point from the 'align' set
  58. void removeAlignedPoint(int index, bool autoRemoveDualPoint = true);
  59. //! Removes a point from the 'reference' set
  60. void removeRefPoint(int index, bool autoRemoveDualPoint = true);
  61. //! Inherited from ccPickingListener
  62. void onItemPicked(const PickedItem& pi) override;
  63. protected:
  64. //! Slot called to change to-be-aligned entities visibility
  65. void showAlignedEntities(bool);
  66. //! Slot called to change reference entities visibility
  67. void showReferenceEntities(bool);
  68. //! Slot called to add a manual point to the 'align' set
  69. void addManualAlignedPoint();
  70. //! Slot called to add a manual point to the 'reference' set
  71. void addManualRefPoint();
  72. //! Slot called to remove the last point on the 'align' stack
  73. void unstackAligned();
  74. //! Slot called to remove the last point on the 'reference' stack
  75. void unstackRef();
  76. //! Slot called when a "delete" button is pushed
  77. void onDelButtonPushed();
  78. //! Updates the registration info and buttons states
  79. void updateAlignInfo();
  80. void apply();
  81. void align();
  82. void reset();
  83. void cancel();
  84. protected:
  85. //! Enables (or not) buttons depending on the number of points in both lists
  86. void onPointCountChanged();
  87. //! Calls the registration routine
  88. bool callRegistration( CCCoreLib::PointProjectionTools::Transformation& trans,
  89. double& rms,
  90. bool autoUpdateTab,
  91. bool& withUmeyama,
  92. QStringList* report = nullptr );
  93. //! Clears the RMS rows
  94. void clearRMSColumns();
  95. //! Adds a point to one of the table (ref./to-be-aligned)
  96. void addPointToTable( QTableWidget* tableWidget,
  97. int rowIndex,
  98. const CCVector3d& P,
  99. QString pointLabel );
  100. //! Converts a picked point to a sphere center (if necessary)
  101. /** \param P input point (may be converted to a sphere center)
  102. \param entity associated entity
  103. \param sphereRadius the detected spherer radius (or -1 if no sphere)
  104. \return whether the point can be used or not
  105. **/
  106. bool convertToSphereCenter(CCVector3d& P, ccHObject* entity, PointCoordinateType& sphereRadius);
  107. //! Resets the displayed title (3D view)
  108. void resetTitle();
  109. //! Entity original context
  110. struct EntityContext
  111. {
  112. //! Default constructor
  113. explicit EntityContext(ccHObject* ent);
  114. //! Restores cloud original state
  115. void restore();
  116. ccHObject* entity;
  117. ccGenericGLDisplay* originalDisplay;
  118. bool wasVisible;
  119. bool wasEnabled;
  120. bool wasSelected;
  121. };
  122. //! Set of contexts
  123. struct EntityContexts : public QMap< ccHObject*, EntityContext >
  124. {
  125. void fill(const ccHObject::Container& entities);
  126. void restoreAll()
  127. {
  128. for (EntityContext& ctx : *this)
  129. ctx.restore();
  130. }
  131. bool isShifted;
  132. CCVector3d shift;
  133. double scale = 1.0;
  134. };
  135. //! Removes a label (and restore its associated label if any)
  136. void removeLabel( ccPointCloud& points,
  137. unsigned childIndex,
  138. const EntityContexts& entities);
  139. protected: //members
  140. //! To-be-aligned entities
  141. EntityContexts m_alignedEntities;
  142. //! to-be-aligned points set
  143. ccPointCloud m_alignedPoints;
  144. //! Reference entities (if any)
  145. EntityContexts m_referenceEntities;
  146. //! Reference points set
  147. ccPointCloud m_refPoints;
  148. //! Whether the dialog is paused or not
  149. bool m_paused;
  150. //! Picking hub
  151. ccPickingHub* m_pickingHub;
  152. //! Main application interface
  153. ccMainAppInterface* m_app;
  154. };