10 #include <Utils/cc2sm.h>
11 #include <Utils/sm2cc.h>
13 #include "PclUtils/PCLModules.h"
14 #include "Tools/Common/ecvTools.h"
24 #include <QMainWindow>
33 tr(
"DoN Segmentation"),
34 tr(
"DoN Segmentation from clouds"),
35 ":/toolbar/PclAlgorithms/icons/DoN.png")),
37 m_comparisonField(
"curvature"),
38 m_comparisonTypes(
"GT"),
41 m_minDonMagnitude(0.3f),
42 m_maxDonMagnitude(1.3f),
43 m_clusterTolerance(0.02f),
44 m_minClusterSize(100),
45 m_maxClusterSize(25000),
46 m_randomClusterColor(false) {}
56 if (have_cloud != 1)
return -11;
79 static_cast<float>(
m_dialog->minDonMagnitudeSpinBox->value());
81 static_cast<float>(
m_dialog->maxDonMagnitudeSpinBox->value());
87 static_cast<float>(
m_dialog->clusterToleranceSpinBox->value());
103 if (!cloud)
return -1;
106 PointCloudT::Ptr xyzCloud = cc2smReader(cloud).getXYZ2();
107 if (!xyzCloud)
return -1;
109 std::vector<int> dummy;
110 PCLModules::RemoveNaN<PointT>(xyzCloud, xyzCloud, dummy);
113 double cloudReolution =
114 PCLModules::ComputeCloudResolution<PointT>(xyzCloud);
122 PointCloudNormal::Ptr normals_small_scale(
new PointCloudNormal);
123 PointCloudNormal::Ptr normals_large_scale(
new PointCloudNormal);
125 if (!PCLModules::ComputeNormals<PointT, PointNT>(
126 xyzCloud, normals_small_scale,
m_smallScale,
false,
true)) {
130 if (!PCLModules::ComputeNormals<PointT, PointNT>(
131 xyzCloud, normals_large_scale,
m_largeScale,
false,
true)) {
137 PointCloudNormal::Ptr doncloud(
new PointCloudNormal);
138 pcl::copyPointCloud<PointT, PointNT>(*xyzCloud, *doncloud);
139 if (!PCLModules::DONEstimation<PointT, PointNT, PointNT>(
140 xyzCloud, normals_small_scale, normals_large_scale, doncloud)) {
147 PCLModules::ConditionParameters param;
150 param.condition_type_ = PCLModules::ConditionParameters::
151 ConditionType::CONDITION_OR;
153 param.condition_type_ = PCLModules::ConditionParameters::
154 ConditionType::CONDITION_AND;
157 PCLModules::ConditionParameters::ComparisonParam comparison;
159 comparison.comparison_type_ =
160 PCLModules::ConditionParameters::ComparisonType::GT;
161 }
else if (
type ==
"GE") {
162 comparison.comparison_type_ =
163 PCLModules::ConditionParameters::ComparisonType::GE;
164 }
else if (
type ==
"LT") {
165 comparison.comparison_type_ =
166 PCLModules::ConditionParameters::ComparisonType::LT;
167 }
else if (
type ==
"LE") {
168 comparison.comparison_type_ =
169 PCLModules::ConditionParameters::ComparisonType::LE;
170 }
else if (
type ==
"EQ") {
171 comparison.comparison_type_ =
172 PCLModules::ConditionParameters::ComparisonType::EQ;
177 param.condition_params_.push_back(comparison);
180 PointCloudNormal::Ptr doncloud_filtered(
new PointCloudNormal);
181 if (!PCLModules::ConditionalRemovalFilter<PointNT>(
182 doncloud, param, doncloud_filtered,
false)) {
185 doncloud = doncloud_filtered;
186 if (doncloud->width * doncloud->height == 0) {
192 std::vector<pcl::PointIndices> cluster_indices;
193 if (!PCLModules::EuclideanCluster<PointNT>(
199 if (cluster_indices.size() == 0 || cluster_indices.size() > 300) {
204 std::vector<std::vector<size_t>> clusterIndices;
205 for (
auto& cluster : cluster_indices) {
206 std::vector<size_t> cs;
207 cs.resize(cluster.indices.size());
208 for (
size_t i = 0; i < cluster.indices.size(); ++i) {
209 cs[i] = (
static_cast<size_t>(cluster.indices[i]));
212 clusterIndices.push_back(cs);
222 tr(
"-Tolerance(%1)-ClusterSize(%2-%3)")
235 "of clusters! Result may be incomplete"),
259 "Selected entity does not have any suitable scalar field "
263 "Wrong Parameters. One or more parameters cannot be "
267 "Difference of Normals Segmentation could not get any "
269 "the clusters are more than 300 for the given dataset. Try "
270 "relaxing your parameters");
272 return tr(
"An error occurred during the generation of clusters!");
Base abstract class for each implemented PCL filter.
int isFirstSelectedCcPointCloud()
Returns 1 if the first selected object is a ccPointCloud.
void newEntity(ccHObject *)
Signal emitted when a new entity is created by the filter.
ecvMainAppInterface * m_app
Associated application interface.
virtual QString getErrorMessage(int errorCode)
Returns the error message corresponding to a given error code.
ccPointCloud * getSelectedEntityAsCCPointCloud() const
Returns the first selected entity as a ccPointCloud.
void getComparisonTypes(QStringList &types)
const QString getComparisonField()
DONSegmentationDlg * m_dialog
virtual QString getErrorMessage(int errorCode)
Returns the error message corresponding to a given error code.
virtual ~DONSegmentation()
bool m_randomClusterColor
virtual void getParametersFromDialog()
Collects parameters from the filter dialog (if openDialog is successful)
virtual int compute()
Performs the actual filter job.
virtual int checkSelected()
Checks if current selection is compliant with the filter.
virtual int openInputDialog()
QString m_comparisonField
virtual int checkParameters()
QStringList m_comparisonTypes
Hierarchical CLOUDVIEWER Object.
unsigned getChildrenNumber() const
Returns the number of children.
virtual bool addChild(ccHObject *child, int dependencyFlags=DP_PARENT_OF_OTHER, int insertIndex=-1)
Adds a child.
ccHObject * getParent() const
Returns parent object.
virtual QString getName() const
Returns object name.
virtual void setName(const QString &name)
Sets object name.
virtual void setEnabled(bool state)
Sets the "enabled" property.
A 3D cloud and its associated features (color, normals, scalar fields, etc.)
virtual QWidget * getActiveWindow()=0
virtual void dispToConsole(QString message, ConsoleMessageLevel level=STD_CONSOLE_MESSAGE)=0
static void error(char *msg)