Point Cloud Library (PCL) 1.13.0
Loading...
Searching...
No Matches
sac_model_plane.hpp
1/*
2 * Software License Agreement (BSD License)
3 *
4 * Point Cloud Library (PCL) - www.pointclouds.org
5 * Copyright (c) 2009, Willow Garage, Inc.
6 * Copyright (c) 2012-, Open Perception, Inc.
7 *
8 * All rights reserved.
9 *
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
12 * are met:
13 *
14 * * Redistributions of source code must retain the above copyright
15 * notice, this list of conditions and the following disclaimer.
16 * * Redistributions in binary form must reproduce the above
17 * copyright notice, this list of conditions and the following
18 * disclaimer in the documentation and/or other materials provided
19 * with the distribution.
20 * * Neither the name of the copyright holder(s) nor the names of its
21 * contributors may be used to endorse or promote products derived
22 * from this software without specific prior written permission.
23 *
24 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
25 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
26 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
27 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
28 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
29 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
30 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
31 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
32 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
33 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
34 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
35 * POSSIBILITY OF SUCH DAMAGE.
36 *
37 * $Id$
38 *
39 */
40
41#ifndef PCL_SAMPLE_CONSENSUS_IMPL_SAC_MODEL_PLANE_H_
42#define PCL_SAMPLE_CONSENSUS_IMPL_SAC_MODEL_PLANE_H_
43
44#include <pcl/sample_consensus/sac_model_plane.h>
45#include <pcl/common/centroid.h>
46#include <pcl/common/eigen.h>
47#include <pcl/common/concatenate.h>
48
49//////////////////////////////////////////////////////////////////////////
50template <typename PointT> bool
52{
53 if (samples.size () != sample_size_)
54 {
55 PCL_ERROR ("[pcl::SampleConsensusModelPlane::isSampleGood] Wrong number of samples (is %lu, should be %lu)!\n", samples.size (), sample_size_);
56 return (false);
57 }
58
59 // Check if the sample points are collinear
60 // Similar checks are implemented as precaution in computeModelCoefficients,
61 // so if you find the need to fix something in here, look there, too.
62 pcl::Vector3fMapConst p0 = (*input_)[samples[0]].getVector3fMap ();
63 pcl::Vector3fMapConst p1 = (*input_)[samples[1]].getVector3fMap ();
64 pcl::Vector3fMapConst p2 = (*input_)[samples[2]].getVector3fMap ();
65
66 // Check if the norm of the cross-product would be non-zero, otherwise
67 // normalization will fail. One could also interpret this as kind of check
68 // if the triangle spanned by those three points would have an area greater
69 // than zero.
70 if ((p1 - p0).cross(p2 - p0).stableNorm() < Eigen::NumTraits<float>::dummy_precision ())
71 {
72 PCL_ERROR ("[pcl::SampleConsensusModelPlane::isSampleGood] Sample points too similar or collinear!\n");
73 return (false);
74 }
75
76 return (true);
77}
78
79//////////////////////////////////////////////////////////////////////////
80template <typename PointT> bool
82 const Indices &samples, Eigen::VectorXf &model_coefficients) const
83{
84 // The checks are redundant with isSampleGood above, but since most of the
85 // computed values are also used to compute the model coefficients, this might
86 // be a situation where this duplication is acceptable.
87 if (samples.size () != sample_size_)
88 {
89 PCL_ERROR ("[pcl::SampleConsensusModelPlane::computeModelCoefficients] Invalid set of samples given (%lu)!\n", samples.size ());
90 return (false);
91 }
92
93 pcl::Vector3fMapConst p0 = (*input_)[samples[0]].getVector3fMap ();
94 pcl::Vector3fMapConst p1 = (*input_)[samples[1]].getVector3fMap ();
95 pcl::Vector3fMapConst p2 = (*input_)[samples[2]].getVector3fMap ();
96
97 const Eigen::Vector3f cross = (p1 - p0).cross(p2 - p0);
98 const float crossNorm = cross.stableNorm();
99
100 // Checking for collinearity here
101 if (crossNorm < Eigen::NumTraits<float>::dummy_precision ())
102 {
103 PCL_ERROR ("[pcl::SampleConsensusModelPlane::computeModelCoefficients] Chosen samples are collinear!\n");
104 return (false);
105 }
106
107 // Compute the plane coefficients from the 3 given points in a straightforward manner
108 // calculate the plane normal n = (p2-p1) x (p3-p1) = cross (p2-p1, p3-p1)
109 model_coefficients.resize (model_size_);
110 model_coefficients.template head<3>() = cross / crossNorm;
111
112 // ... + d = 0
113 model_coefficients[3] = -1.0f * (model_coefficients.template head<3>().dot (p0));
114
115 PCL_DEBUG ("[pcl::SampleConsensusModelPlane::computeModelCoefficients] Model is (%g,%g,%g,%g).\n",
116 model_coefficients[0], model_coefficients[1], model_coefficients[2], model_coefficients[3]);
117 return (true);
118}
119
120#define AT(POS) ((*input_)[(*indices_)[(POS)]])
121
122#ifdef __AVX__
123// This function computes the distances of 8 points to the plane
124template <typename PointT> inline __m256 pcl::SampleConsensusModelPlane<PointT>::dist8 (const std::size_t i, const __m256 &a_vec, const __m256 &b_vec, const __m256 &c_vec, const __m256 &d_vec, const __m256 &abs_help) const
125{
126 // The andnot-function realizes an abs-operation: the sign bit is removed
127 return _mm256_andnot_ps (abs_help,
128 _mm256_add_ps (_mm256_add_ps (_mm256_mul_ps (a_vec, _mm256_set_ps (AT(i ).x, AT(i+1).x, AT(i+2).x, AT(i+3).x, AT(i+4).x, AT(i+5).x, AT(i+6).x, AT(i+7).x)),
129 _mm256_mul_ps (b_vec, _mm256_set_ps (AT(i ).y, AT(i+1).y, AT(i+2).y, AT(i+3).y, AT(i+4).y, AT(i+5).y, AT(i+6).y, AT(i+7).y))),
130 _mm256_add_ps (_mm256_mul_ps (c_vec, _mm256_set_ps (AT(i ).z, AT(i+1).z, AT(i+2).z, AT(i+3).z, AT(i+4).z, AT(i+5).z, AT(i+6).z, AT(i+7).z)),
131 d_vec))); // TODO this could be replaced by three fmadd-instructions (if available), but the speed gain would probably be minimal
132}
133#endif // ifdef __AVX__
134
135#ifdef __SSE__
136// This function computes the distances of 4 points to the plane
137template <typename PointT> inline __m128 pcl::SampleConsensusModelPlane<PointT>::dist4 (const std::size_t i, const __m128 &a_vec, const __m128 &b_vec, const __m128 &c_vec, const __m128 &d_vec, const __m128 &abs_help) const
138{
139 // The andnot-function realizes an abs-operation: the sign bit is removed
140 return _mm_andnot_ps (abs_help,
141 _mm_add_ps (_mm_add_ps (_mm_mul_ps (a_vec, _mm_set_ps (AT(i ).x, AT(i+1).x, AT(i+2).x, AT(i+3).x)),
142 _mm_mul_ps (b_vec, _mm_set_ps (AT(i ).y, AT(i+1).y, AT(i+2).y, AT(i+3).y))),
143 _mm_add_ps (_mm_mul_ps (c_vec, _mm_set_ps (AT(i ).z, AT(i+1).z, AT(i+2).z, AT(i+3).z)),
144 d_vec))); // TODO this could be replaced by three fmadd-instructions (if available), but the speed gain would probably be minimal
145}
146#endif // ifdef __SSE__
147
148#undef AT
149
150//////////////////////////////////////////////////////////////////////////
151template <typename PointT> void
153 const Eigen::VectorXf &model_coefficients, std::vector<double> &distances) const
154{
155 // Needs a valid set of model coefficients
156 if (!isModelValid (model_coefficients))
157 {
158 PCL_ERROR ("[pcl::SampleConsensusModelPlane::getDistancesToModel] Given model is invalid!\n");
159 return;
160 }
161
162 distances.resize (indices_->size ());
163
164 // Iterate through the 3d points and calculate the distances from them to the plane
165 for (std::size_t i = 0; i < indices_->size (); ++i)
166 {
167 // Calculate the distance from the point to the plane normal as the dot product
168 // D = (P-A).N/|N|
169 /*distances[i] = std::abs (model_coefficients[0] * (*input_)[(*indices_)[i]].x +
170 model_coefficients[1] * (*input_)[(*indices_)[i]].y +
171 model_coefficients[2] * (*input_)[(*indices_)[i]].z +
172 model_coefficients[3]);*/
173 Eigen::Vector4f pt ((*input_)[(*indices_)[i]].x,
174 (*input_)[(*indices_)[i]].y,
175 (*input_)[(*indices_)[i]].z,
176 1.0f);
177 distances[i] = std::abs (model_coefficients.dot (pt));
178 }
179}
180
181//////////////////////////////////////////////////////////////////////////
182template <typename PointT> void
184 const Eigen::VectorXf &model_coefficients, const double threshold, Indices &inliers)
185{
186 // Needs a valid set of model coefficients
187 if (!isModelValid (model_coefficients))
188 {
189 PCL_ERROR ("[pcl::SampleConsensusModelPlane::selectWithinDistance] Given model is invalid!\n");
190 return;
191 }
192
193 inliers.clear ();
194 error_sqr_dists_.clear ();
195 inliers.reserve (indices_->size ());
196 error_sqr_dists_.reserve (indices_->size ());
197
198 // Iterate through the 3d points and calculate the distances from them to the plane
199 for (std::size_t i = 0; i < indices_->size (); ++i)
200 {
201 // Calculate the distance from the point to the plane normal as the dot product
202 // D = (P-A).N/|N|
203 Eigen::Vector4f pt ((*input_)[(*indices_)[i]].x,
204 (*input_)[(*indices_)[i]].y,
205 (*input_)[(*indices_)[i]].z,
206 1.0f);
207
208 float distance = std::abs (model_coefficients.dot (pt));
209
210 if (distance < threshold)
211 {
212 // Returns the indices of the points whose distances are smaller than the threshold
213 inliers.push_back ((*indices_)[i]);
214 error_sqr_dists_.push_back (static_cast<double> (distance));
215 }
216 }
217}
218
219//////////////////////////////////////////////////////////////////////////
220template <typename PointT> std::size_t
222 const Eigen::VectorXf &model_coefficients, const double threshold) const
223{
224 // Needs a valid set of model coefficients
225 if (!isModelValid (model_coefficients))
226 {
227 PCL_ERROR ("[pcl::SampleConsensusModelPlane::countWithinDistance] Given model is invalid!\n");
228 return (0);
229 }
230#if defined (__AVX__) && defined (__AVX2__)
231 return countWithinDistanceAVX (model_coefficients, threshold);
232#elif defined (__SSE__) && defined (__SSE2__) && defined (__SSE4_1__)
233 return countWithinDistanceSSE (model_coefficients, threshold);
234#else
235 return countWithinDistanceStandard (model_coefficients, threshold);
236#endif
237}
238
239//////////////////////////////////////////////////////////////////////////
240template <typename PointT> std::size_t
242 const Eigen::VectorXf &model_coefficients, const double threshold, std::size_t i) const
243{
244 std::size_t nr_p = 0;
245 // Iterate through the 3d points and calculate the distances from them to the plane
246 for (; i < indices_->size (); ++i)
247 {
248 // Calculate the distance from the point to the plane normal as the dot product
249 // D = (P-A).N/|N|
250 Eigen::Vector4f pt ((*input_)[(*indices_)[i]].x,
251 (*input_)[(*indices_)[i]].y,
252 (*input_)[(*indices_)[i]].z,
253 1.0f);
254 if (std::abs (model_coefficients.dot (pt)) < threshold)
255 {
256 nr_p++;
257 }
258 }
259 return (nr_p);
260}
261
262//////////////////////////////////////////////////////////////////////////
263#if defined (__SSE__) && defined (__SSE2__) && defined (__SSE4_1__)
264template <typename PointT> std::size_t
266 const Eigen::VectorXf &model_coefficients, const double threshold, std::size_t i) const
267{
268 std::size_t nr_p = 0;
269 const __m128 a_vec = _mm_set1_ps (model_coefficients[0]);
270 const __m128 b_vec = _mm_set1_ps (model_coefficients[1]);
271 const __m128 c_vec = _mm_set1_ps (model_coefficients[2]);
272 const __m128 d_vec = _mm_set1_ps (model_coefficients[3]);
273 const __m128 threshold_vec = _mm_set1_ps (threshold);
274 const __m128 abs_help = _mm_set1_ps (-0.0F); // -0.0F (negative zero) means that all bits are 0, only the sign bit is 1
275 __m128i res = _mm_set1_epi32(0); // This corresponds to nr_p: 4 32bit integers that, summed together, hold the number of inliers
276 for (; (i + 4) <= indices_->size (); i += 4)
277 {
278 const __m128 mask = _mm_cmplt_ps (dist4 (i, a_vec, b_vec, c_vec, d_vec, abs_help), threshold_vec); // The mask contains 1 bits if the corresponding points are inliers, else 0 bits
279 res = _mm_add_epi32 (res, _mm_and_si128 (_mm_set1_epi32 (1), _mm_castps_si128 (mask))); // The latter part creates a vector with ones (as 32bit integers) where the points are inliers
280 //const int res = _mm_movemask_ps (mask);
281 //if (res & 1) nr_p++;
282 //if (res & 2) nr_p++;
283 //if (res & 4) nr_p++;
284 //if (res & 8) nr_p++;
285 }
286 nr_p += _mm_extract_epi32 (res, 0);
287 nr_p += _mm_extract_epi32 (res, 1);
288 nr_p += _mm_extract_epi32 (res, 2);
289 nr_p += _mm_extract_epi32 (res, 3);
290
291 // Process the remaining points (at most 3)
292 nr_p += countWithinDistanceStandard(model_coefficients, threshold, i);
293 return (nr_p);
294}
295#endif
296
297//////////////////////////////////////////////////////////////////////////
298#if defined (__AVX__) && defined (__AVX2__)
299template <typename PointT> std::size_t
301 const Eigen::VectorXf &model_coefficients, const double threshold, std::size_t i) const
302{
303 std::size_t nr_p = 0;
304 const __m256 a_vec = _mm256_set1_ps (model_coefficients[0]);
305 const __m256 b_vec = _mm256_set1_ps (model_coefficients[1]);
306 const __m256 c_vec = _mm256_set1_ps (model_coefficients[2]);
307 const __m256 d_vec = _mm256_set1_ps (model_coefficients[3]);
308 const __m256 threshold_vec = _mm256_set1_ps (threshold);
309 const __m256 abs_help = _mm256_set1_ps (-0.0F); // -0.0F (negative zero) means that all bits are 0, only the sign bit is 1
310 __m256i res = _mm256_set1_epi32(0); // This corresponds to nr_p: 8 32bit integers that, summed together, hold the number of inliers
311 for (; (i + 8) <= indices_->size (); i += 8)
312 {
313 const __m256 mask = _mm256_cmp_ps (dist8 (i, a_vec, b_vec, c_vec, d_vec, abs_help), threshold_vec, _CMP_LT_OQ); // The mask contains 1 bits if the corresponding points are inliers, else 0 bits
314 res = _mm256_add_epi32 (res, _mm256_and_si256 (_mm256_set1_epi32 (1), _mm256_castps_si256 (mask))); // The latter part creates a vector with ones (as 32bit integers) where the points are inliers
315 //const int res = _mm256_movemask_ps (mask);
316 //if (res & 1) nr_p++;
317 //if (res & 2) nr_p++;
318 //if (res & 4) nr_p++;
319 //if (res & 8) nr_p++;
320 //if (res & 16) nr_p++;
321 //if (res & 32) nr_p++;
322 //if (res & 64) nr_p++;
323 //if (res & 128) nr_p++;
324 }
325 nr_p += _mm256_extract_epi32 (res, 0);
326 nr_p += _mm256_extract_epi32 (res, 1);
327 nr_p += _mm256_extract_epi32 (res, 2);
328 nr_p += _mm256_extract_epi32 (res, 3);
329 nr_p += _mm256_extract_epi32 (res, 4);
330 nr_p += _mm256_extract_epi32 (res, 5);
331 nr_p += _mm256_extract_epi32 (res, 6);
332 nr_p += _mm256_extract_epi32 (res, 7);
333
334 // Process the remaining points (at most 7)
335 nr_p += countWithinDistanceStandard(model_coefficients, threshold, i);
336 return (nr_p);
337}
338#endif
339
340//////////////////////////////////////////////////////////////////////////
341template <typename PointT> void
343 const Indices &inliers, const Eigen::VectorXf &model_coefficients, Eigen::VectorXf &optimized_coefficients) const
344{
345 // Needs a valid set of model coefficients
346 if (!isModelValid (model_coefficients))
347 {
348 PCL_ERROR ("[pcl::SampleConsensusModelPlane::optimizeModelCoefficients] Given model is invalid!\n");
349 optimized_coefficients = model_coefficients;
350 return;
351 }
352
353 // Need more than the minimum sample size to make a difference
354 if (inliers.size () <= sample_size_)
355 {
356 PCL_ERROR ("[pcl::SampleConsensusModelPlane::optimizeModelCoefficients] Not enough inliers found to optimize model coefficients (%lu)! Returning the same coefficients.\n", inliers.size ());
357 optimized_coefficients = model_coefficients;
358 return;
359 }
360
361 Eigen::Vector4f plane_parameters;
362
363 // Use Least-Squares to fit the plane through all the given sample points and find out its coefficients
364 EIGEN_ALIGN16 Eigen::Matrix3f covariance_matrix;
365 Eigen::Vector4f xyz_centroid;
366
367 if (0 == computeMeanAndCovarianceMatrix (*input_, inliers, covariance_matrix, xyz_centroid))
368 {
369 PCL_ERROR ("[pcl::SampleConsensusModelPlane::optimizeModelCoefficients] computeMeanAndCovarianceMatrix failed (returned 0) because there are no valid inliers.\n");
370 optimized_coefficients = model_coefficients;
371 return;
372 }
373
374 // Compute the model coefficients
375 EIGEN_ALIGN16 Eigen::Vector3f::Scalar eigen_value;
376 EIGEN_ALIGN16 Eigen::Vector3f eigen_vector;
377 pcl::eigen33 (covariance_matrix, eigen_value, eigen_vector);
378
379 // Hessian form (D = nc . p_plane (centroid here) + p)
380 optimized_coefficients.resize (model_size_);
381 optimized_coefficients[0] = eigen_vector [0];
382 optimized_coefficients[1] = eigen_vector [1];
383 optimized_coefficients[2] = eigen_vector [2];
384 optimized_coefficients[3] = 0.0f;
385 optimized_coefficients[3] = -1.0f * optimized_coefficients.dot (xyz_centroid);
386
387 // Make sure it results in a valid model
388 if (!isModelValid (optimized_coefficients))
389 {
390 optimized_coefficients = model_coefficients;
391 }
392}
393
394//////////////////////////////////////////////////////////////////////////
395template <typename PointT> void
397 const Indices &inliers, const Eigen::VectorXf &model_coefficients, PointCloud &projected_points, bool copy_data_fields) const
398{
399 // Needs a valid set of model coefficients
400 if (!isModelValid (model_coefficients))
401 {
402 PCL_ERROR ("[pcl::SampleConsensusModelPlane::projectPoints] Given model is invalid!\n");
403 return;
404 }
405
406 projected_points.header = input_->header;
407 projected_points.is_dense = input_->is_dense;
408
409 Eigen::Vector4f mc (model_coefficients[0], model_coefficients[1], model_coefficients[2], 0.0f);
410
411 // normalize the vector perpendicular to the plane...
412 mc.normalize ();
413 // ... and store the resulting normal as a local copy of the model coefficients
414 Eigen::Vector4f tmp_mc = model_coefficients;
415 tmp_mc[0] = mc[0];
416 tmp_mc[1] = mc[1];
417 tmp_mc[2] = mc[2];
418
419 // Copy all the data fields from the input cloud to the projected one?
420 if (copy_data_fields)
421 {
422 // Allocate enough space and copy the basics
423 projected_points.resize (input_->size ());
424 projected_points.width = input_->width;
425 projected_points.height = input_->height;
426
427 using FieldList = typename pcl::traits::fieldList<PointT>::type;
428 // Iterate over each point
429 for (std::size_t i = 0; i < input_->size (); ++i)
430 // Iterate over each dimension
431 pcl::for_each_type <FieldList> (NdConcatenateFunctor <PointT, PointT> ((*input_)[i], projected_points[i]));
432
433 // Iterate through the 3d points and calculate the distances from them to the plane
434 for (const auto &inlier : inliers)
435 {
436 // Calculate the distance from the point to the plane
437 Eigen::Vector4f p ((*input_)[inlier].x,
438 (*input_)[inlier].y,
439 (*input_)[inlier].z,
440 1);
441 // use normalized coefficients to calculate the scalar projection
442 float distance_to_plane = tmp_mc.dot (p);
443
444 pcl::Vector4fMap pp = projected_points[inlier].getVector4fMap ();
445 pp.matrix () = p - mc * distance_to_plane; // mc[3] = 0, therefore the 3rd coordinate is safe
446 }
447 }
448 else
449 {
450 // Allocate enough space and copy the basics
451 projected_points.resize (inliers.size ());
452 projected_points.width = inliers.size ();
453 projected_points.height = 1;
454
455 using FieldList = typename pcl::traits::fieldList<PointT>::type;
456 // Iterate over each point
457 for (std::size_t i = 0; i < inliers.size (); ++i)
458 {
459 // Iterate over each dimension
460 pcl::for_each_type <FieldList> (NdConcatenateFunctor <PointT, PointT> ((*input_)[inliers[i]], projected_points[i]));
461 }
462
463 // Iterate through the 3d points and calculate the distances from them to the plane
464 for (std::size_t i = 0; i < inliers.size (); ++i)
465 {
466 // Calculate the distance from the point to the plane
467 Eigen::Vector4f p ((*input_)[inliers[i]].x,
468 (*input_)[inliers[i]].y,
469 (*input_)[inliers[i]].z,
470 1.0f);
471 // use normalized coefficients to calculate the scalar projection
472 float distance_to_plane = tmp_mc.dot (p);
473
474 pcl::Vector4fMap pp = projected_points[i].getVector4fMap ();
475 pp.matrix () = p - mc * distance_to_plane; // mc[3] = 0, therefore the 3rd coordinate is safe
476 }
477 }
478}
479
480//////////////////////////////////////////////////////////////////////////
481template <typename PointT> bool
483 const std::set<index_t> &indices, const Eigen::VectorXf &model_coefficients, const double threshold) const
484{
485 // Needs a valid set of model coefficients
486 if (!isModelValid (model_coefficients))
487 {
488 PCL_ERROR ("[pcl::SampleConsensusModelPlane::doSamplesVerifyModel] Given model is invalid!\n");
489 return (false);
490 }
491
492 for (const auto &index : indices)
493 {
494 Eigen::Vector4f pt ((*input_)[index].x,
495 (*input_)[index].y,
496 (*input_)[index].z,
497 1.0f);
498 if (std::abs (model_coefficients.dot (pt)) > threshold)
499 {
500 return (false);
501 }
502 }
503
504 return (true);
505}
506
507#define PCL_INSTANTIATE_SampleConsensusModelPlane(T) template class PCL_EXPORTS pcl::SampleConsensusModelPlane<T>;
508
509#endif // PCL_SAMPLE_CONSENSUS_IMPL_SAC_MODEL_PLANE_H_
510
Define methods for centroid estimation and covariance matrix calculus.
SampleConsensusModelPlane defines a model for 3D plane segmentation.
typename SampleConsensusModel< PointT >::PointCloud PointCloud
void optimizeModelCoefficients(const Indices &inliers, const Eigen::VectorXf &model_coefficients, Eigen::VectorXf &optimized_coefficients) const override
Recompute the plane coefficients using the given inlier set and return them to the user.
void getDistancesToModel(const Eigen::VectorXf &model_coefficients, std::vector< double > &distances) const override
Compute all distances from the cloud data to a given plane model.
bool doSamplesVerifyModel(const std::set< index_t > &indices, const Eigen::VectorXf &model_coefficients, const double threshold) const override
Verify whether a subset of indices verifies the given plane model coefficients.
void selectWithinDistance(const Eigen::VectorXf &model_coefficients, const double threshold, Indices &inliers) override
Select all the points which respect the given model coefficients as inliers.
void projectPoints(const Indices &inliers, const Eigen::VectorXf &model_coefficients, PointCloud &projected_points, bool copy_data_fields=true) const override
Create a new point cloud with inliers projected onto the plane model.
bool computeModelCoefficients(const Indices &samples, Eigen::VectorXf &model_coefficients) const override
Check whether the given index samples can form a valid plane model, compute the model coefficients fr...
std::size_t countWithinDistanceStandard(const Eigen::VectorXf &model_coefficients, const double threshold, std::size_t i=0) const
This implementation uses no SIMD instructions.
std::size_t countWithinDistance(const Eigen::VectorXf &model_coefficients, const double threshold) const override
Count all the points which respect the given model coefficients as inliers.
unsigned int computeMeanAndCovarianceMatrix(const pcl::PointCloud< PointT > &cloud, Eigen::Matrix< Scalar, 3, 3 > &covariance_matrix, Eigen::Matrix< Scalar, 4, 1 > &centroid)
Compute the normalized 3x3 covariance matrix and the centroid of a given set of points in a single lo...
Definition centroid.hpp:508
void eigen33(const Matrix &mat, typename Matrix::Scalar &eigenvalue, Vector &eigenvector)
determines the eigenvector and eigenvalue of the smallest eigenvalue of the symmetric positive semi d...
Definition eigen.hpp:296
__device__ __host__ __forceinline__ float3 cross(const float3 &v1, const float3 &v2)
Definition utils.hpp:107
Eigen::Map< Eigen::Vector4f, Eigen::Aligned > Vector4fMap
const Eigen::Map< const Eigen::Vector3f > Vector3fMapConst
IndicesAllocator<> Indices
Type used for indices in PCL.
Definition types.h:133