ACloudViewer  3.9.4
A Modern Library for 3D Data Processing
NormalEstimation.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 
8 #include "NormalEstimation.h"
9 
10 // LOCAL
11 #include <Utils/cc2sm.h>
12 #include <Utils/sm2cc.h>
13 
14 #include "PclUtils/PCLModules.h"
16 
17 // ECV_PLUGINS
18 #include <ecvMainAppInterface.h>
19 
20 // CV_DB_LIB
21 #include <ecvPointCloud.h>
22 
23 // QT
24 #include <QMainWindow>
25 #include <QThread>
26 
29  tr("Estimate Normals"),
30  tr("Estimate Normals and Curvature"),
31  tr("Estimate Normals and Curvature for the selected entity"),
32  ":/toolbar/PclAlgorithms/icons/normal_curvature.png")),
33  m_dialog(nullptr),
34  m_knn_radius(10),
35  m_radius(0),
36  m_useKnn(false),
37  m_overwrite_curvature(false) {
38  m_overwrite_curvature = true;
39 }
40 
42  // we must delete parent-less dialogs ourselves!
43  if (m_dialog && m_dialog->parent() == nullptr) delete m_dialog;
44 }
45 
47  if (!m_dialog) {
49  : 0);
50 
51  // initially these are invisible
52  m_dialog->surfaceComboBox->setVisible(false);
53  m_dialog->searchSurfaceCheckBox->setVisible(false);
54  }
55 
57  if (cloud) {
58  ccBBox bBox = cloud->getOwnBB();
59  if (bBox.isValid())
60  m_dialog->radiusDoubleSpinBox->setValue(bBox.getDiagNorm() * 0.005);
61  }
62 
63  return m_dialog->exec() ? 1 : 0;
64 }
65 
67  assert(m_dialog);
68  if (!m_dialog) return;
69 
70  // fill in parameters from dialog
71  m_useKnn = m_dialog->useKnnCheckBox->isChecked();
72  m_overwrite_curvature = m_dialog->curvatureCheckBox->isChecked();
73  m_knn_radius = m_dialog->knnSpinBox->value();
74  m_radius = static_cast<float>(m_dialog->radiusDoubleSpinBox->value());
75 }
76 
78  // pointer to selected cloud
80  if (!cloud) return -1;
81 
82  // if we have normals delete them!
83  if (cloud->hasNormals()) cloud->unallocateNorms();
84 
85  // get xyz as pcl point cloud
86  PointCloudT::Ptr pcl_cloud = cc2smReader(cloud).getXYZ2();
87  if (!pcl_cloud) return -1;
88 
89  // create storage for normals
90  PointCloudNormal::Ptr normals(new PointCloudNormal);
91 
92  // now compute
93  int result = PCLModules::ComputeNormals<PointT, pcl::PointNormal>(
94  pcl_cloud, normals, m_useKnn ? m_knn_radius : m_radius, m_useKnn);
95  if (result < 0) return -1;
96 
97  PCLCloud::Ptr sm_normals(new PCLCloud);
98  TO_PCL_CLOUD(*normals, *sm_normals);
99 
100  pcl2cc::CopyNormals(*sm_normals, *cloud);
101  pcl2cc::CopyScalarField(*sm_normals, "curvature", *cloud,
103 
104  emit entityHasChanged(cloud);
105 
106  return 1;
107 }
core::Tensor result
Definition: VtkUtils.cpp:76
Base abstract class for each implemented PCL filter.
Definition: BasePclModule.h:53
ecvMainAppInterface * m_app
Associated application interface.
ccPointCloud * getSelectedEntityAsCCPointCloud() const
Returns the first selected entity as a ccPointCloud.
void entityHasChanged(ccHObject *)
Signal emitted when an entity is (visually) modified.
virtual int compute()
Performs the actual filter job.
virtual int openInputDialog()
NormalEstimationDialog * m_dialog
virtual void getParametersFromDialog()
Collects parameters from the filter dialog (if openDialog is successful)
virtual ~NormalEstimation()
Bounding box structure.
Definition: ecvBBox.h:25
ccBBox getOwnBB(bool withGLFeatures=false) override
Returns the entity's own bounding-box.
A 3D cloud and its associated features (color, normals, scalar fields, etc.)
bool hasNormals() const override
Returns whether normals are enabled or not.
void unallocateNorms()
Erases the cloud normals.
T getDiagNorm() const
Returns diagonal length.
Definition: BoundingBox.h:172
bool isValid() const
Returns whether bounding box is valid or not.
Definition: BoundingBox.h:203
virtual QWidget * getActiveWindow()=0
double normals[3]
PCL filter description.
Definition: BasePclModule.h:26