ACloudViewer  3.9.4
A Modern Library for 3D Data Processing
StatisticalOutliersRemover.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 // 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 
28  tr("Statistical Outlier Removal"),
29  tr("Filter outlier data based on point neighborhood statistics"),
30  tr("Filter the points that are farther of their neighbors than "
31  "the average (plus a number of times the standard deviation)"),
32  ":/toolbar/PclAlgorithms/icons/sor_outlier_remover.png")),
33  m_dialog(nullptr),
34  m_k(0),
35  m_std(0.0f) {}
36 
38  // we must delete parent-less dialogs ourselves!
39  if (m_dialog && m_dialog->parent() == nullptr) delete m_dialog;
40 }
41 
43  if (!m_dialog) {
44  m_dialog = new SORDialog(m_app ? m_app->getMainWindow() : nullptr);
45  }
46 
47  return m_dialog->exec() ? 1 : 0;
48 }
49 
51  // get values from dialog
52  if (m_dialog) {
53  m_k = m_dialog->spinK->value();
54  m_std = static_cast<float>(m_dialog->spinStd->value());
55  }
56 }
57 
59  // get selected as pointcloud
61  if (!cloud) return -1;
62 
63  // now as sensor message
64  PCLCloud::Ptr tmp_cloud = cc2smReader(cloud).getAsSM();
65  if (!tmp_cloud) return -1;
66 
67  PCLCloud::Ptr outcloud(new PCLCloud);
69  tmp_cloud, outcloud, m_k, m_std);
70  if (result < 0) return -1;
71 
72  // get back outcloud as a ccPointCloud
73  ccPointCloud* final_cloud = pcl2cc::Convert(*outcloud);
74  if (!final_cloud) return -1;
75 
76  // create a suitable name for the entity
77  final_cloud->setName(
78  QString("%1_k%2_std%3").arg(cloud->getName()).arg(m_k).arg(m_std));
79  // final_cloud->setDisplay(cloud->getDisplay());
80  // copy global shift & scale
81  final_cloud->setGlobalScale(cloud->getGlobalScale());
82  final_cloud->setGlobalShift(cloud->getGlobalShift());
83 
84  // disable original cloud
85  cloud->setEnabled(false);
86  if (cloud->getParent()) cloud->getParent()->addChild(final_cloud);
87 
88  emit newEntity(final_cloud);
89 
90  return 1;
91 }
pcl::PCLPointCloud2 PCLCloud
Definition: PCLCloud.h:34
core::Tensor result
Definition: VtkUtils.cpp:76
Base abstract class for each implemented PCL filter.
Definition: BasePclModule.h:53
void newEntity(ccHObject *)
Signal emitted when a new entity is created by the filter.
ecvMainAppInterface * m_app
Associated application interface.
ccPointCloud * getSelectedEntityAsCCPointCloud() const
Returns the first selected entity as a ccPointCloud.
void getParametersFromDialog()
Collects parameters from the filter dialog (if openDialog is successful)
int compute()
Performs the actual filter job.
CC to PCL cloud converter.
Definition: cc2sm.h:43
PCLCloud::Ptr getAsSM(std::list< std::string > &requested_fields) const
Definition: cc2sm.cpp:607
ccHObject * getParent() const
Returns parent object.
Definition: ecvHObject.h:245
virtual bool addChild(ccHObject *child, int dependencyFlags=DP_PARENT_OF_OTHER, int insertIndex=-1)
Adds a child.
Definition: ecvHObject.cpp:534
virtual QString getName() const
Returns object name.
Definition: ecvObject.h:72
virtual void setName(const QString &name)
Sets object name.
Definition: ecvObject.h:75
virtual void setEnabled(bool state)
Sets the "enabled" property.
Definition: ecvObject.h:102
A 3D cloud and its associated features (color, normals, scalar fields, etc.)
virtual void setGlobalShift(double x, double y, double z)
Sets shift applied to original coordinates (information storage only)
virtual const CCVector3d & getGlobalShift() const
Returns the shift applied to original coordinates.
virtual void setGlobalScale(double scale)
virtual double getGlobalScale() const
Returns the scale applied to original coordinates.
virtual QMainWindow * getMainWindow()=0
Returns main window.
static ccMesh * Convert(PCLTextureMesh::ConstPtr textureMesh)
Converts a PCL point cloud to a ccPointCloud.
template int RemoveOutliersStatistical< PCLCloud >(const PCLCloud::ConstPtr inCloud, PCLCloud::Ptr outCloud, int knn, double nSigma)
PCL filter description.
Definition: BasePclModule.h:26