MeVisLab Toolbox Reference
mlPCLStatisticalClusterInfo.h
Go to the documentation of this file.
1// Copyright (c) Fraunhofer MEVIS, Germany. All rights reserved.
2// **InsertLicense** code author="Wolf Spindler"
3//----------------------------------------------------------------------------------
6
14//----------------------------------------------------------------------------------
15#pragma once
16
18#include <mlPCLSupportTools.h>
20#include <mlLine.h>
21#include <mlPlane.h>
23#include <pcl/common/pca.h>
24#include <pcl/common/io.h>
25#include <pcl/common/common.h>
27
28ML_START_NAMESPACE
29
30//----------------------------------------------------------------------------------
32//----------------------------------------------------------------------------------
36 clear();
37 }
38
40 inline void clear()
41 {
42 numPoints = 0;
43
44 indices.clear();
45
46 magnitudeSum = 0.;
47 magnitudeSumAbsolute = 0.;
48 magnitudeAverage = 0.;
49 magnitudeAverageAbsolute = 0.;
50 magnitudeMedian = 0.;
51
52 phaseSum = 0.;
53 phaseSumAbsolute = 0.;
54 phaseAverage = 0.;
55 phaseAverageAbsolute = 0.;
56 phaseMedian = 0.;
57
58 centreOfGravity.assign(0.,0.,0.);
59 eigenValues.assign(0.,0.,0.);
60 eigenVectors[0].assign(0.,0.,0.);
61 eigenVectors[1].assign(0.,0.,0.);
62 eigenVectors[2].assign(0.,0.,0.);
63 orientedExtentsMin.assign(0.,0.,0.);
64 orientedExtentsMax.assign(0.,0.,0.);
65
66 planeIntersection.assign(0.,0.,0.);
67 planeIntersectionOk = false;
68 }
69
71 inline void insert(int index, double magnitude, double phase)
72 {
73 numPoints++;
74
75 indices.push_back(index);
76
77 magnitudeSum += magnitude;
78 magnitudeSumAbsolute += fabs(magnitude);
79
80 phaseSum += phase;
81 phaseSumAbsolute += fabs(phase);
82 }
83
85 inline void finalize(const MLPointCloudXYZINormal &inputPointCloud,
86 const Vector3 &planeNormal,
87 const Vector3 &planePoint,
88 const std::string &magnitudeFloatMemberName,
89 const std::string &phaseFloatMemberName)
90 {
91 if (numPoints > 0){
92 const double numPointsDbl = static_cast<double>(numPoints);
93
94 // Compute magnitude results.
95 magnitudeAverage = magnitudeSum / numPointsDbl;
96 magnitudeAverageAbsolute = magnitudeSumAbsolute / numPointsDbl;
97
98 // Compute phase results.
99 phaseAverage = phaseSum / numPointsDbl;
100 phaseAverageAbsolute = phaseSumAbsolute / numPointsDbl;
101
102 // Compute Eigenvectors, -values, and centre of gravity.
103 MLPointCloudXYZINormal clusterCloud;
104 pcl::copyPointCloud(inputPointCloud, indices, clusterCloud);
105
106 // Calculate the two median values.
108 stats = PCLSupportTools::getStatistics(clusterCloud, magnitudeFloatMemberName, true);
109 magnitudeMedian = stats.median;
110 stats = PCLSupportTools::getStatistics(clusterCloud, phaseFloatMemberName, true);
111 phaseMedian = stats.median;
112
113 // Finally calculate the principle components, eigenvalues etc.
114 if (clusterCloud.points.size() >=3 ){
115 // Compute principle component analysis only if there are more
116 // than 3 points, because otherwise crashes may appear.
117 pcl::PCA<MLPointCloudXYZINormal::PointType> PCAFilter;
118 PCAFilter.setInputCloud(PCLMakeLocalNonDeletingSharedConstPtr(clusterCloud));
119 const Eigen::Vector4f meanTmp = PCAFilter.getMean();
120 const Eigen::Vector3f eigenValuesTmp = PCAFilter.getEigenValues();
121 const Eigen::Vector3f eigenVector0Tmp = PCAFilter.getEigenVectors().col(0);
122 const Eigen::Vector3f eigenVector1Tmp = PCAFilter.getEigenVectors().col(1);
123 const Eigen::Vector3f eigenVector2Tmp = PCAFilter.getEigenVectors().col(2);
124
125 centreOfGravity.assign( meanTmp[0], meanTmp[1], meanTmp[2] /*, meanTmp[3]*/ );
126 eigenValues.assign( eigenValuesTmp[0], eigenValuesTmp[1], eigenValuesTmp[2] );
127 eigenVectors[0].assign( eigenVector0Tmp[0], eigenVector0Tmp[1], eigenVector0Tmp[2] );
128 eigenVectors[1].assign( eigenVector1Tmp[0], eigenVector1Tmp[1], eigenVector1Tmp[2] );
129 eigenVectors[2].assign( eigenVector2Tmp[0], eigenVector2Tmp[1], eigenVector2Tmp[2] );
130
131 // Create a point cloud projected to x/y/z-axis.
132 MLPointCloudXYZINormal tmpCloud;
133 PCAFilter.project(clusterCloud, tmpCloud);
134 pcl::PointXYZINormal minPoint, maxPoint;
135 pcl::getMinMax3D(tmpCloud, minPoint, maxPoint);
136
137 // Determine extent of point cloud along the three eigen vectors.
138 orientedExtentsMin[0] = minPoint.x;
139 orientedExtentsMin[1] = minPoint.y;
140 orientedExtentsMin[2] = minPoint.z;
141 orientedExtentsMax[0] = maxPoint.x;
142 orientedExtentsMax[1] = maxPoint.y;
143 orientedExtentsMax[2] = maxPoint.z;
144
145 // Cut line of (centreOfGravity,centreOfGravity+eigenVectors[0]) with user plane;
146 // eigenVectors[0] is the one with largest eigenValue.
147 Plane plane(planeNormal, planePoint);
148 Line line(centreOfGravity, centreOfGravity+eigenVectors[0]);
149 planeIntersectionOk = plane.intersect(line, planeIntersection);
150 }
151 }
152 }
153
156
158 std::vector<int> indices;
159
160 // Magnitude:
163
166
169
172
175
176
177 // Phase:
179 double phaseSum;
180
183
186
189
192
193
196
199
201 Vector3 eigenVectors[3];
202
205
208
211
214};
215
216ML_END_NAMESPACE
217
Project global and OS specific declarations.
Disables warnings from PCL headers which otherwise cannot be avoided.
Restores disabled warnings from PCL headers which otherwise cannot be avoided.
Class to define the geometry primitive "Line" consisting of a position and a direction.
Definition mlLine.h:28
Class defining a plane in 3D.
Definition mlPlane.h:30
bool intersect(const Line &l, Vector3 &intersection) const
Intersects this plane with line l and returns the intersection point in intersection.
A collection of statistical tool functions used in MLPCLSupport.
A collection of tool functions used in MLPCLSupport.
MLint64 MLint
A signed ML integer type with at least 64 bits used for index calculations on very large images even ...
Definition mlTypeDefs.h:490
std::shared_ptr< const POINT_CLOUD_TYPE > PCLMakeLocalNonDeletingSharedConstPtr(const POINT_CLOUD_TYPE &pntCloud)
Many pcl filters and classes require a boost shared pointer to the point cloud to be processed,...
pcl::PointCloud< pcl::PointXYZINormal > MLPointCloudXYZINormal
The basic point cloud type used in the PCL MeVisLab binding.
Definition mlPCLTypes.h:104
Container for statistical point cloud parameters.
double median
Value of NumPoints/2 entry of all values after sorting or 0 if no values, empty point cloud or not ca...
Small helper container managing some information about a cluster.
Vector3 eigenValues
Eigenvalues of the cluster.
double phaseSum
The sum of all point phases in the cluster.
Vector3 planeIntersection
Intersection of main axes of cluster with user plane.
Vector3 orientedExtentsMin
Minimum extents according to the eigen vectors.
double magnitudeSum
The sum of all point magnitudes in the cluster.
MLint numPoints
Number of points in the cluster.
double phaseSumAbsolute
The sum of all absolute point phases in the cluster.
StatisticalClusterInfo()
Constructor defaulting everything to an empty cluster.
double phaseMedian
The median of all point phases in the cluster.
double magnitudeMedian
The median of all point magnitudes in the cluster.
double phaseAverage
The average of all point phases in the cluster.
double phaseAverageAbsolute
The average of all point phases in the cluster.
double magnitudeSumAbsolute
The sum of all absolute point magnitudes in the cluster.
Vector3 centreOfGravity
Centre of gravity of the cluster.
std::vector< int > indices
List of point indices of the cluster.
bool planeIntersectionOk
True if intersection of main axes of cluster with user plane is valid, otherwise false.
double magnitudeAverageAbsolute
The average of all point magnitudes in the cluster.
void finalize(const MLPointCloudXYZINormal &inputPointCloud, const Vector3 &planeNormal, const Vector3 &planePoint, const std::string &magnitudeFloatMemberName, const std::string &phaseFloatMemberName)
To be called after last insert to finalise cluster calculations.
void clear()
Setting default values corresponding to an empty cluster.
Vector3 orientedExtentsMax
Minimum extents according to the eigen vectors.
double magnitudeAverage
The average of all point magnitudes in the cluster.
void insert(int index, double magnitude, double phase)
Inserting a new magnitude,phase pair updating statistics.