ccNormalComputationDlg.cpp 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227
  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. #include "ccNormalComputationDlg.h"
  18. //qCC_db
  19. #include <ccPointCloud.h>
  20. #include <ccOctree.h>
  21. #include <ccProgressDialog.h>
  22. //Qt
  23. #include <QComboBox>
  24. //system
  25. #include <assert.h>
  26. ccNormalComputationDlg::ccNormalComputationDlg(bool withScanGrid, bool withSensor, QWidget* parent/*=nullptr*/)
  27. : QDialog(parent, Qt::Tool)
  28. , Ui::NormalComputationDlg()
  29. , m_cloud(nullptr)
  30. {
  31. setupUi(this);
  32. //by default, the 'auto' button is hidden (as long as setCloud is not called)
  33. autoRadiusToolButton->setVisible(false);
  34. connect(localModelComboBox, qOverload<int>(&QComboBox::currentIndexChanged), this, &ccNormalComputationDlg::localModelChanged);
  35. connect(autoRadiusToolButton, &QToolButton::clicked, this, &ccNormalComputationDlg::autoEstimateRadius);
  36. if (withScanGrid)
  37. {
  38. useScanGridCheckBox->setChecked(true);
  39. scanGridsOrientCheckBox->setChecked(true);
  40. }
  41. else
  42. {
  43. //disable 'scan grid' options
  44. useScanGridCheckBox->setChecked(false);
  45. useScanGridCheckBox->setEnabled(false);
  46. gridAngleFrame->setEnabled(false);
  47. scanGridsOrientCheckBox->setChecked(false);
  48. scanGridsOrientCheckBox->setEnabled(false);
  49. }
  50. if (withSensor)
  51. {
  52. sensorOrientCheckBox->setChecked(true);
  53. }
  54. else
  55. {
  56. //disable 'sensor' options
  57. sensorOrientCheckBox->setChecked(false);
  58. sensorOrientCheckBox->setEnabled(false);
  59. }
  60. }
  61. void ccNormalComputationDlg::setLocalModel(CCCoreLib::LOCAL_MODEL_TYPES model)
  62. {
  63. int index = -1;
  64. switch (model)
  65. {
  66. case CCCoreLib::LS:
  67. index = 0;
  68. break;
  69. case CCCoreLib::QUADRIC:
  70. index = 1;
  71. break;
  72. case CCCoreLib::TRI:
  73. index = 2;
  74. break;
  75. default:
  76. assert(false);
  77. break;
  78. }
  79. localModelComboBox->setCurrentIndex(index);
  80. }
  81. CCCoreLib::LOCAL_MODEL_TYPES ccNormalComputationDlg::getLocalModel() const
  82. {
  83. switch (localModelComboBox->currentIndex())
  84. {
  85. case 0:
  86. return CCCoreLib::LS;
  87. case 1:
  88. return CCCoreLib::QUADRIC;
  89. case 2:
  90. return CCCoreLib::TRI;
  91. }
  92. assert(false);
  93. return CCCoreLib::LS;
  94. }
  95. void ccNormalComputationDlg::localModelChanged(int index)
  96. {
  97. //DGM: we don't disable the parent frame anymore as it is used by the octree/grid toggling
  98. radiusDoubleSpinBox->setEnabled(index != 2);
  99. autoRadiusToolButton->setEnabled(index != 2);
  100. }
  101. void ccNormalComputationDlg::setRadius(PointCoordinateType radius)
  102. {
  103. radiusDoubleSpinBox->setValue(static_cast<double>(radius));
  104. }
  105. void ccNormalComputationDlg::setCloud(ccPointCloud* cloud)
  106. {
  107. m_cloud = cloud;
  108. autoRadiusToolButton->setVisible(m_cloud != nullptr);
  109. }
  110. PointCoordinateType ccNormalComputationDlg::getRadius() const
  111. {
  112. return static_cast<PointCoordinateType>(radiusDoubleSpinBox->value());
  113. }
  114. void ccNormalComputationDlg::setPreferredOrientation(ccNormalVectors::Orientation orientation)
  115. {
  116. if (orientation == ccNormalVectors::UNDEFINED)
  117. {
  118. preferredOrientRadioButton->setChecked(false);
  119. }
  120. else
  121. {
  122. preferredOrientRadioButton->setChecked(true);
  123. preferredOrientationComboBox->setCurrentIndex(orientation);
  124. }
  125. }
  126. bool ccNormalComputationDlg::useScanGridsForComputation() const
  127. {
  128. return useScanGridCheckBox->isChecked();
  129. }
  130. double ccNormalComputationDlg::getMinGridAngle_deg() const
  131. {
  132. return gridAngleDoubleSpinBox->value();
  133. }
  134. void ccNormalComputationDlg::setMinGridAngle_deg(double value)
  135. {
  136. gridAngleDoubleSpinBox->setValue(value);
  137. }
  138. bool ccNormalComputationDlg::orientNormals() const
  139. {
  140. return normalsOrientGroupBox->isChecked();
  141. }
  142. void ccNormalComputationDlg::setOrientNormals(bool state)
  143. {
  144. normalsOrientGroupBox->setChecked(state);
  145. }
  146. bool ccNormalComputationDlg::useScanGridsForOrientation() const
  147. {
  148. return scanGridsOrientCheckBox->isChecked();
  149. }
  150. bool ccNormalComputationDlg::useSensorsForOrientation() const
  151. {
  152. return sensorOrientCheckBox->isChecked();
  153. }
  154. bool ccNormalComputationDlg::usePreferredOrientation() const
  155. {
  156. return preferredOrientRadioButton->isChecked();
  157. }
  158. bool ccNormalComputationDlg::useMSTOrientation() const
  159. {
  160. return mstOrientRadioButton->isChecked();
  161. }
  162. void ccNormalComputationDlg::setMSTNeighborCount(int n)
  163. {
  164. mstNeighborsSpinBox->setValue(n);
  165. }
  166. int ccNormalComputationDlg::getMSTNeighborCount() const
  167. {
  168. return mstNeighborsSpinBox->value();
  169. }
  170. ccNormalVectors::Orientation ccNormalComputationDlg::getPreferredOrientation() const
  171. {
  172. int index = preferredOrientRadioButton->isChecked() ? preferredOrientationComboBox->currentIndex() : -1;
  173. return (index >= 0 && index <= ccNormalVectors::MINUS_SENSOR_ORIGIN ? static_cast<ccNormalVectors::Orientation>(index) : ccNormalVectors::UNDEFINED);
  174. }
  175. void ccNormalComputationDlg::autoEstimateRadius()
  176. {
  177. ccOctree::BestRadiusParams params;
  178. {
  179. params.aimedPopulationPerCell = 16;
  180. params.aimedPopulationRange = 4;
  181. params.minCellPopulation = 6;
  182. params.minAboveMinRatio = 0.97;
  183. }
  184. PointCoordinateType radius = ccOctree::GuessBestRadiusAutoComputeOctree(m_cloud, params, this);
  185. if (radius > 0)
  186. {
  187. radiusDoubleSpinBox->setValue(radius);
  188. }
  189. else
  190. {
  191. ccLog::Error("Failed to estimate the radius");
  192. }
  193. }