ccGeomFeaturesDlg.cpp 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  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 "ccGeomFeaturesDlg.h"
  18. //Qt
  19. #include <QPushButton>
  20. #include <QDialogButtonBox>
  21. ccGeomFeaturesDlg::ccGeomFeaturesDlg(QWidget* parent/*=nullptr*/)
  22. : QDialog(parent, Qt::Tool)
  23. , Ui::GeomFeaturesDialog()
  24. {
  25. setupUi(this);
  26. connect(buttonBox->button(QDialogButtonBox::Reset), &QPushButton::clicked, this, &ccGeomFeaturesDlg::reset);
  27. try
  28. {
  29. m_options.reserve(22);
  30. m_options.push_back(Option(roughnessCheckBox, CCCoreLib::GeometricalAnalysisTools::Roughness, 0));
  31. m_options.push_back(Option(firstOrderMomentCheckBox, CCCoreLib::GeometricalAnalysisTools::MomentOrder1, 0));
  32. m_options.push_back(Option(curvMeanCheckBox, CCCoreLib::GeometricalAnalysisTools::Curvature, CCCoreLib::Neighbourhood::MEAN_CURV));
  33. m_options.push_back(Option(curvGaussCheckBox, CCCoreLib::GeometricalAnalysisTools::Curvature, CCCoreLib::Neighbourhood::GAUSSIAN_CURV));
  34. m_options.push_back(Option(curvNCRCheckBox, CCCoreLib::GeometricalAnalysisTools::Curvature, CCCoreLib::Neighbourhood::NORMAL_CHANGE_RATE));
  35. m_options.push_back(Option(densityKnnCheckBox, CCCoreLib::GeometricalAnalysisTools::LocalDensity, CCCoreLib::GeometricalAnalysisTools::DENSITY_KNN));
  36. m_options.push_back(Option(densitySurfCheckBox, CCCoreLib::GeometricalAnalysisTools::LocalDensity, CCCoreLib::GeometricalAnalysisTools::DENSITY_2D));
  37. m_options.push_back(Option(densityVolCheckBox, CCCoreLib::GeometricalAnalysisTools::LocalDensity, CCCoreLib::GeometricalAnalysisTools::DENSITY_3D));
  38. m_options.push_back(Option(eigSumCheckBox, CCCoreLib::GeometricalAnalysisTools::Feature, CCCoreLib::Neighbourhood::EigenValuesSum));
  39. m_options.push_back(Option(eigOmnivarianceCheckBox, CCCoreLib::GeometricalAnalysisTools::Feature, CCCoreLib::Neighbourhood::Omnivariance));
  40. m_options.push_back(Option(eigenentropyCheckBox, CCCoreLib::GeometricalAnalysisTools::Feature, CCCoreLib::Neighbourhood::EigenEntropy));
  41. m_options.push_back(Option(eigAnisotropyCheckBox, CCCoreLib::GeometricalAnalysisTools::Feature, CCCoreLib::Neighbourhood::Anisotropy));
  42. m_options.push_back(Option(eigPlanarityBox, CCCoreLib::GeometricalAnalysisTools::Feature, CCCoreLib::Neighbourhood::Planarity));
  43. m_options.push_back(Option(eigLinearityCheckBox, CCCoreLib::GeometricalAnalysisTools::Feature, CCCoreLib::Neighbourhood::Linearity));
  44. m_options.push_back(Option(eigPCA1CheckBox, CCCoreLib::GeometricalAnalysisTools::Feature, CCCoreLib::Neighbourhood::PCA1));
  45. m_options.push_back(Option(eigPCA2CheckBox, CCCoreLib::GeometricalAnalysisTools::Feature, CCCoreLib::Neighbourhood::PCA2));
  46. m_options.push_back(Option(eigSurfaceVarCheckBox, CCCoreLib::GeometricalAnalysisTools::Feature, CCCoreLib::Neighbourhood::SurfaceVariation));
  47. m_options.push_back(Option(eigSphericityCheckBox, CCCoreLib::GeometricalAnalysisTools::Feature, CCCoreLib::Neighbourhood::Sphericity));
  48. m_options.push_back(Option(eigVerticalityCheckBox, CCCoreLib::GeometricalAnalysisTools::Feature, CCCoreLib::Neighbourhood::Verticality));
  49. m_options.push_back(Option(eigenvalue1CheckBox, CCCoreLib::GeometricalAnalysisTools::Feature, CCCoreLib::Neighbourhood::EigenValue1));
  50. m_options.push_back(Option(eigenvalue2CheckBox, CCCoreLib::GeometricalAnalysisTools::Feature, CCCoreLib::Neighbourhood::EigenValue2));
  51. m_options.push_back(Option(eigenvalue3CheckBox, CCCoreLib::GeometricalAnalysisTools::Feature, CCCoreLib::Neighbourhood::EigenValue3));
  52. }
  53. catch (std::bad_alloc)
  54. {
  55. ccLog::Warning("[ccGeomFeaturesDlg] Not enough memory");
  56. }
  57. }
  58. void ccGeomFeaturesDlg::setUpDirection(const CCVector3& upDir)
  59. {
  60. upDirXDoubleSpinBox->setValue(upDir.x);
  61. upDirYDoubleSpinBox->setValue(upDir.y);
  62. upDirZDoubleSpinBox->setValue(upDir.z);
  63. upDirGroupBox->setChecked(true);
  64. }
  65. CCVector3* ccGeomFeaturesDlg::getUpDirection() const
  66. {
  67. if (roughnessCheckBox->isChecked() && upDirGroupBox->isChecked())
  68. {
  69. static CCVector3 UpDirection(0, 0, 1);
  70. UpDirection.x = static_cast<PointCoordinateType>(upDirXDoubleSpinBox->value());
  71. UpDirection.y = static_cast<PointCoordinateType>(upDirYDoubleSpinBox->value());
  72. UpDirection.z = static_cast<PointCoordinateType>(upDirZDoubleSpinBox->value());
  73. return &UpDirection;
  74. }
  75. else
  76. {
  77. return nullptr;
  78. }
  79. }
  80. void ccGeomFeaturesDlg::setSelectedFeatures(const ccLibAlgorithms::GeomCharacteristicSet& features)
  81. {
  82. reset();
  83. for (const ccLibAlgorithms::GeomCharacteristic& f : features)
  84. {
  85. //find the corresponding checkbox
  86. for (const Option& opt : m_options)
  87. {
  88. if (opt.charac == f.charac && opt.subOption == f.subOption)
  89. {
  90. opt.checkBox->setChecked(true);
  91. break;
  92. }
  93. }
  94. }
  95. }
  96. bool ccGeomFeaturesDlg::getSelectedFeatures(ccLibAlgorithms::GeomCharacteristicSet& features) const
  97. {
  98. features.clear();
  99. try
  100. {
  101. //test each check-box and add the corresponding feature descriptor if necessary
  102. for (const Option& opt : m_options)
  103. {
  104. assert(opt.checkBox);
  105. if (opt.checkBox && opt.checkBox->isChecked())
  106. features.push_back(opt);
  107. }
  108. }
  109. catch (const std::bad_alloc&)
  110. {
  111. return false;
  112. }
  113. return true;
  114. }
  115. double ccGeomFeaturesDlg::getRadius() const
  116. {
  117. return radiusDoubleSpinBox->value();
  118. }
  119. void ccGeomFeaturesDlg::setRadius(double r)
  120. {
  121. radiusDoubleSpinBox->setValue(r);
  122. }
  123. void ccGeomFeaturesDlg::reset()
  124. {
  125. for (const Option& opt : m_options)
  126. opt.checkBox->setChecked(false);
  127. }