ACloudViewer  3.9.4
A Modern Library for 3D Data Processing
ecvNormalComputationDlg.cpp
Go to the documentation of this file.
1 // ----------------------------------------------------------------------------
2 // - CloudViewer: www.cloudViewer.org -
3 // ----------------------------------------------------------------------------
4 // Copyright (c) 2018-2024 www.cloudViewer.org
5 // SPDX-License-Identifier: MIT
6 // ----------------------------------------------------------------------------
7 
9 
10 // CV_DB_LIB
11 #include <ecvOctree.h>
12 #include <ecvPointCloud.h>
13 #include <ecvProgressDialog.h>
14 
15 // Qt
16 #include <QComboBox>
17 
18 // system
19 #include <assert.h>
20 
22  bool withSensor,
23  QWidget* parent /*=nullptr*/)
24  : QDialog(parent, Qt::Tool), Ui::NormalComputationDlg(), m_cloud(nullptr) {
25  setupUi(this);
26 
27  // by default, the 'auto' button is hidden (as long as setCloud is not
28  // called)
29  autoRadiusToolButton->setVisible(false);
30 
31  connect(localModelComboBox,
32  static_cast<void (QComboBox::*)(int)>(
33  &QComboBox::currentIndexChanged),
35  connect(autoRadiusToolButton, &QToolButton::clicked, this,
37 
38  if (withScanGrid) {
39  useScanGridCheckBox->setChecked(true);
40  scanGridsOrientCheckBox->setChecked(true);
41  } else {
42  // disable 'scan grid' options
43  useScanGridCheckBox->setChecked(false);
44  useScanGridCheckBox->setEnabled(false);
45  gridAngleFrame->setEnabled(false);
46 
47  scanGridsOrientCheckBox->setChecked(false);
48  scanGridsOrientCheckBox->setEnabled(false);
49  }
50 
51  if (withSensor) {
52  sensorOrientCheckBox->setChecked(true);
53  } else {
54  // disable 'sensor' options
55  sensorOrientCheckBox->setChecked(false);
56  sensorOrientCheckBox->setEnabled(false);
57  }
58 }
59 
61  int index = -1;
62  switch (model) {
63  case LS:
64  index = 0;
65  break;
66  case QUADRIC:
67  index = 1;
68  break;
69  case TRI:
70  index = 2;
71  break;
72  default:
73  assert(false);
74  break;
75  }
76  localModelComboBox->setCurrentIndex(index);
77 }
78 
80  switch (localModelComboBox->currentIndex()) {
81  case 0:
82  return LS;
83  case 1:
84  return QUADRIC;
85  case 2:
86  return TRI;
87  }
88 
89  assert(false);
90  return LS;
91 }
92 
94  // DGM: we don't disable the parent frame anymore as it is used by the
95  // octree/grid toggling
96  radiusDoubleSpinBox->setEnabled(index != 2);
97  autoRadiusToolButton->setEnabled(index != 2);
98 }
99 
101  radiusDoubleSpinBox->setValue(static_cast<double>(radius));
102 }
103 
105  m_cloud = cloud;
106 
107  autoRadiusToolButton->setVisible(m_cloud != 0);
108 }
109 
111  return static_cast<PointCoordinateType>(radiusDoubleSpinBox->value());
112 }
113 
115  ccNormalVectors::Orientation orientation) {
116  if (orientation == ccNormalVectors::UNDEFINED) {
117  preferredOrientRadioButton->setChecked(false);
118  } else {
119  preferredOrientRadioButton->setChecked(true);
120  preferredOrientationComboBox->setCurrentIndex(orientation);
121  }
122 }
123 
125  return useScanGridCheckBox->isChecked();
126 }
127 
129  return gridAngleDoubleSpinBox->value();
130 }
131 
133  gridAngleDoubleSpinBox->setValue(value);
134 }
135 
137  return normalsOrientGroupBox->isChecked();
138 }
139 
141  return scanGridsOrientCheckBox->isChecked();
142 }
143 
145  return sensorOrientCheckBox->isChecked();
146 }
147 
149  return preferredOrientRadioButton->isChecked();
150 }
151 
153  return mstOrientRadioButton->isChecked();
154 }
155 
157  mstNeighborsSpinBox->setValue(n);
158 }
159 
161  return mstNeighborsSpinBox->value();
162 }
163 
165  const {
166  int index = preferredOrientRadioButton->isChecked()
167  ? preferredOrientationComboBox->currentIndex()
168  : -1;
169 
170  return (index >= 0 && index <= ccNormalVectors::PREVIOUS
171  ? static_cast<ccNormalVectors::Orientation>(index)
173 }
174 
176  if (!m_cloud) {
177  assert(false);
178  return;
179  }
180 
181  if (!m_cloud->getOctree()) {
182  ecvProgressDialog pDlg(true, this);
183  if (!m_cloud->computeOctree(&pDlg)) {
184  CVLog::Error(QString("Could not compute octree for cloud '%1'")
185  .arg(m_cloud->getName()));
186  autoRadiusToolButton->setVisible(false);
187  return;
188  }
189  }
190 
192  m_cloud, m_cloud->getOctree().data());
193  if (radius > 0) {
194  radiusDoubleSpinBox->setValue(radius);
195  }
196 }
CV_LOCAL_MODEL_TYPES
Definition: CVConst.h:121
@ LS
Definition: CVConst.h:123
@ TRI
Definition: CVConst.h:124
@ QUADRIC
Definition: CVConst.h:125
float PointCoordinateType
Type of the coordinates of a (N-D) point.
Definition: CVTypes.h:16
static bool Error(const char *format,...)
Display an error dialog with formatted message.
Definition: CVLog.cpp:143
virtual void setVisible(bool state)
Sets entity visibility.
virtual ccOctree::Shared computeOctree(cloudViewer::GenericProgressCallback *progressCb=nullptr, bool autoAddChild=true)
Computes the cloud octree.
virtual ccOctree::Shared getOctree() const
Returns the associated octree (if any)
bool useScanGridsForComputation() const
Returns whether scan grids should be used for computation.
ccNormalComputationDlg(bool withScanGrid, bool withSensor, QWidget *parent=nullptr)
Default constructor.
bool usePreferredOrientation() const
Returns whether a preferred orientation should be used.
int getMSTNeighborCount() const
Returns the number of neighbors for Minimum Spanning Tree (MST)
bool orientNormals() const
Returns whether normals should be oriented or not.
void setMSTNeighborCount(int n)
Sets the number of neighbors for Minimum Spanning Tree (MST)
ccNormalVectors::Orientation getPreferredOrientation() const
Returns the preferred orientation (if any)
double getMinGridAngle_deg() const
Returns the min angle for grid triangles.
bool useScanGridsForOrientation() const
Returns whether scan grids should be used for normals orientation.
void setMinGridAngle_deg(double value)
Sets the min angle for grid triangles.
CV_LOCAL_MODEL_TYPES getLocalModel() const
Returns the local model chosen for normal computation.
void setCloud(ccPointCloud *cloud)
Sets the currently selected cloud (required for 'auto' feature)
bool useSensorsForOrientation() const
Returns whether scan grids should be used for normals computation.
void setRadius(PointCoordinateType radius)
Sets default value for local neighbourhood radius.
void autoEstimateRadius()
Automatically estimate the local surface radius.
void setPreferredOrientation(ccNormalVectors::Orientation orientation)
Sets the preferred orientation.
ccPointCloud * m_cloud
Selected cloud.
void localModelChanged(int index)
On local model change.
void setLocalModel(CV_LOCAL_MODEL_TYPES model)
Sets the local model chosen for normal computation.
PointCoordinateType getRadius() const
Returns local neighbourhood radius.
static PointCoordinateType GuessBestRadius(ccGenericPointCloud *cloud, cloudViewer::DgmOctree *cloudOctree=nullptr, cloudViewer::GenericProgressCallback *progressCb=nullptr)
Orientation
'Default' orientations
@ PREVIOUS
Re-use previous normal (if any)
@ UNDEFINED
Undefined (no orientation is required)
virtual QString getName() const
Returns object name.
Definition: ecvObject.h:72
A 3D cloud and its associated features (color, normals, scalar fields, etc.)
Graphical progress indicator (thread-safe)