Point Cloud Library (PCL)  1.12.1-dev
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 //////////////////////////////////////////////////////////////////////////
50 template <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  // Get the values at the two points
59  pcl::Array4fMapConst p0 = (*input_)[samples[0]].getArray4fMap ();
60  pcl::Array4fMapConst p1 = (*input_)[samples[1]].getArray4fMap ();
61  pcl::Array4fMapConst p2 = (*input_)[samples[2]].getArray4fMap ();
62 
63  Eigen::Array4f p2p0 = p2 - p0;
64  Eigen::Array4f dy1dy2 = (p1-p0) / p2p0;
65 
66  return ( ((dy1dy2[0] != dy1dy2[1]) || (dy1dy2[2] != dy1dy2[1])) && (!p2p0.isZero()) );
67 }
68 
69 //////////////////////////////////////////////////////////////////////////
70 template <typename PointT> bool
72  const Indices &samples, Eigen::VectorXf &model_coefficients) const
73 {
74  // Need 3 samples
75  if (samples.size () != sample_size_)
76  {
77  PCL_ERROR ("[pcl::SampleConsensusModelPlane::computeModelCoefficients] Invalid set of samples given (%lu)!\n", samples.size ());
78  return (false);
79  }
80 
81  pcl::Array4fMapConst p0 = (*input_)[samples[0]].getArray4fMap ();
82  pcl::Array4fMapConst p1 = (*input_)[samples[1]].getArray4fMap ();
83  pcl::Array4fMapConst p2 = (*input_)[samples[2]].getArray4fMap ();
84 
85  // Compute the segment values (in 3d) between p1 and p0
86  Eigen::Array4f p1p0 = p1 - p0;
87  // Compute the segment values (in 3d) between p2 and p0
88  Eigen::Array4f p2p0 = p2 - p0;
89 
90  // Avoid some crashes by checking for collinearity here
91  Eigen::Array4f dy1dy2 = p1p0 / p2p0;
92  if ( p2p0.isZero() || ((dy1dy2[0] == dy1dy2[1]) && (dy1dy2[2] == dy1dy2[1])) ) // Check for collinearity
93  {
94  return (false);
95  }
96 
97  // Compute the plane coefficients from the 3 given points in a straightforward manner
98  // calculate the plane normal n = (p2-p1) x (p3-p1) = cross (p2-p1, p3-p1)
99  model_coefficients.resize (model_size_);
100  model_coefficients[0] = p1p0[1] * p2p0[2] - p1p0[2] * p2p0[1];
101  model_coefficients[1] = p1p0[2] * p2p0[0] - p1p0[0] * p2p0[2];
102  model_coefficients[2] = p1p0[0] * p2p0[1] - p1p0[1] * p2p0[0];
103  model_coefficients[3] = 0.0f;
104 
105  // Normalize
106  model_coefficients.normalize ();
107 
108  // ... + d = 0
109  model_coefficients[3] = -1.0f * (model_coefficients.template head<4>().dot (p0.matrix ()));
110 
111  PCL_DEBUG ("[pcl::SampleConsensusModelPlane::computeModelCoefficients] Model is (%g,%g,%g,%g).\n",
112  model_coefficients[0], model_coefficients[1], model_coefficients[2], model_coefficients[3]);
113  return (true);
114 }
115 
116 #define AT(POS) ((*input_)[(*indices_)[(POS)]])
117 
118 #ifdef __AVX__
119 // This function computes the distances of 8 points to the plane
120 template <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
121 {
122  // The andnot-function realizes an abs-operation: the sign bit is removed
123  return _mm256_andnot_ps (abs_help,
124  _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)),
125  _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))),
126  _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)),
127  d_vec))); // TODO this could be replaced by three fmadd-instructions (if available), but the speed gain would probably be minimal
128 }
129 #endif // ifdef __AVX__
130 
131 #ifdef __SSE__
132 // This function computes the distances of 4 points to the plane
133 template <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
134 {
135  // The andnot-function realizes an abs-operation: the sign bit is removed
136  return _mm_andnot_ps (abs_help,
137  _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)),
138  _mm_mul_ps (b_vec, _mm_set_ps (AT(i ).y, AT(i+1).y, AT(i+2).y, AT(i+3).y))),
139  _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)),
140  d_vec))); // TODO this could be replaced by three fmadd-instructions (if available), but the speed gain would probably be minimal
141 }
142 #endif // ifdef __SSE__
143 
144 #undef AT
145 
146 //////////////////////////////////////////////////////////////////////////
147 template <typename PointT> void
149  const Eigen::VectorXf &model_coefficients, std::vector<double> &distances) const
150 {
151  // Needs a valid set of model coefficients
152  if (!isModelValid (model_coefficients))
153  {
154  PCL_ERROR ("[pcl::SampleConsensusModelPlane::getDistancesToModel] Given model is invalid!\n");
155  return;
156  }
157 
158  distances.resize (indices_->size ());
159 
160  // Iterate through the 3d points and calculate the distances from them to the plane
161  for (std::size_t i = 0; i < indices_->size (); ++i)
162  {
163  // Calculate the distance from the point to the plane normal as the dot product
164  // D = (P-A).N/|N|
165  /*distances[i] = std::abs (model_coefficients[0] * (*input_)[(*indices_)[i]].x +
166  model_coefficients[1] * (*input_)[(*indices_)[i]].y +
167  model_coefficients[2] * (*input_)[(*indices_)[i]].z +
168  model_coefficients[3]);*/
169  Eigen::Vector4f pt ((*input_)[(*indices_)[i]].x,
170  (*input_)[(*indices_)[i]].y,
171  (*input_)[(*indices_)[i]].z,
172  1.0f);
173  distances[i] = std::abs (model_coefficients.dot (pt));
174  }
175 }
176 
177 //////////////////////////////////////////////////////////////////////////
178 template <typename PointT> void
180  const Eigen::VectorXf &model_coefficients, const double threshold, Indices &inliers)
181 {
182  // Needs a valid set of model coefficients
183  if (!isModelValid (model_coefficients))
184  {
185  PCL_ERROR ("[pcl::SampleConsensusModelPlane::selectWithinDistance] Given model is invalid!\n");
186  return;
187  }
188 
189  inliers.clear ();
190  error_sqr_dists_.clear ();
191  inliers.reserve (indices_->size ());
192  error_sqr_dists_.reserve (indices_->size ());
193 
194  // Iterate through the 3d points and calculate the distances from them to the plane
195  for (std::size_t i = 0; i < indices_->size (); ++i)
196  {
197  // Calculate the distance from the point to the plane normal as the dot product
198  // D = (P-A).N/|N|
199  Eigen::Vector4f pt ((*input_)[(*indices_)[i]].x,
200  (*input_)[(*indices_)[i]].y,
201  (*input_)[(*indices_)[i]].z,
202  1.0f);
203 
204  float distance = std::abs (model_coefficients.dot (pt));
205 
206  if (distance < threshold)
207  {
208  // Returns the indices of the points whose distances are smaller than the threshold
209  inliers.push_back ((*indices_)[i]);
210  error_sqr_dists_.push_back (static_cast<double> (distance));
211  }
212  }
213 }
214 
215 //////////////////////////////////////////////////////////////////////////
216 template <typename PointT> std::size_t
218  const Eigen::VectorXf &model_coefficients, const double threshold) const
219 {
220  // Needs a valid set of model coefficients
221  if (!isModelValid (model_coefficients))
222  {
223  PCL_ERROR ("[pcl::SampleConsensusModelPlane::countWithinDistance] Given model is invalid!\n");
224  return (0);
225  }
226 #if defined (__AVX__) && defined (__AVX2__)
227  return countWithinDistanceAVX (model_coefficients, threshold);
228 #elif defined (__SSE__) && defined (__SSE2__) && defined (__SSE4_1__)
229  return countWithinDistanceSSE (model_coefficients, threshold);
230 #else
231  return countWithinDistanceStandard (model_coefficients, threshold);
232 #endif
233 }
234 
235 //////////////////////////////////////////////////////////////////////////
236 template <typename PointT> std::size_t
238  const Eigen::VectorXf &model_coefficients, const double threshold, std::size_t i) const
239 {
240  std::size_t nr_p = 0;
241  // Iterate through the 3d points and calculate the distances from them to the plane
242  for (; i < indices_->size (); ++i)
243  {
244  // Calculate the distance from the point to the plane normal as the dot product
245  // D = (P-A).N/|N|
246  Eigen::Vector4f pt ((*input_)[(*indices_)[i]].x,
247  (*input_)[(*indices_)[i]].y,
248  (*input_)[(*indices_)[i]].z,
249  1.0f);
250  if (std::abs (model_coefficients.dot (pt)) < threshold)
251  {
252  nr_p++;
253  }
254  }
255  return (nr_p);
256 }
257 
258 //////////////////////////////////////////////////////////////////////////
259 #if defined (__SSE__) && defined (__SSE2__) && defined (__SSE4_1__)
260 template <typename PointT> std::size_t
262  const Eigen::VectorXf &model_coefficients, const double threshold, std::size_t i) const
263 {
264  std::size_t nr_p = 0;
265  const __m128 a_vec = _mm_set1_ps (model_coefficients[0]);
266  const __m128 b_vec = _mm_set1_ps (model_coefficients[1]);
267  const __m128 c_vec = _mm_set1_ps (model_coefficients[2]);
268  const __m128 d_vec = _mm_set1_ps (model_coefficients[3]);
269  const __m128 threshold_vec = _mm_set1_ps (threshold);
270  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
271  __m128i res = _mm_set1_epi32(0); // This corresponds to nr_p: 4 32bit integers that, summed together, hold the number of inliers
272  for (; (i + 4) <= indices_->size (); i += 4)
273  {
274  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
275  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
276  //const int res = _mm_movemask_ps (mask);
277  //if (res & 1) nr_p++;
278  //if (res & 2) nr_p++;
279  //if (res & 4) nr_p++;
280  //if (res & 8) nr_p++;
281  }
282  nr_p += _mm_extract_epi32 (res, 0);
283  nr_p += _mm_extract_epi32 (res, 1);
284  nr_p += _mm_extract_epi32 (res, 2);
285  nr_p += _mm_extract_epi32 (res, 3);
286 
287  // Process the remaining points (at most 3)
288  nr_p += countWithinDistanceStandard(model_coefficients, threshold, i);
289  return (nr_p);
290 }
291 #endif
292 
293 //////////////////////////////////////////////////////////////////////////
294 #if defined (__AVX__) && defined (__AVX2__)
295 template <typename PointT> std::size_t
297  const Eigen::VectorXf &model_coefficients, const double threshold, std::size_t i) const
298 {
299  std::size_t nr_p = 0;
300  const __m256 a_vec = _mm256_set1_ps (model_coefficients[0]);
301  const __m256 b_vec = _mm256_set1_ps (model_coefficients[1]);
302  const __m256 c_vec = _mm256_set1_ps (model_coefficients[2]);
303  const __m256 d_vec = _mm256_set1_ps (model_coefficients[3]);
304  const __m256 threshold_vec = _mm256_set1_ps (threshold);
305  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
306  __m256i res = _mm256_set1_epi32(0); // This corresponds to nr_p: 8 32bit integers that, summed together, hold the number of inliers
307  for (; (i + 8) <= indices_->size (); i += 8)
308  {
309  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
310  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
311  //const int res = _mm256_movemask_ps (mask);
312  //if (res & 1) nr_p++;
313  //if (res & 2) nr_p++;
314  //if (res & 4) nr_p++;
315  //if (res & 8) nr_p++;
316  //if (res & 16) nr_p++;
317  //if (res & 32) nr_p++;
318  //if (res & 64) nr_p++;
319  //if (res & 128) nr_p++;
320  }
321  nr_p += _mm256_extract_epi32 (res, 0);
322  nr_p += _mm256_extract_epi32 (res, 1);
323  nr_p += _mm256_extract_epi32 (res, 2);
324  nr_p += _mm256_extract_epi32 (res, 3);
325  nr_p += _mm256_extract_epi32 (res, 4);
326  nr_p += _mm256_extract_epi32 (res, 5);
327  nr_p += _mm256_extract_epi32 (res, 6);
328  nr_p += _mm256_extract_epi32 (res, 7);
329 
330  // Process the remaining points (at most 7)
331  nr_p += countWithinDistanceStandard(model_coefficients, threshold, i);
332  return (nr_p);
333 }
334 #endif
335 
336 //////////////////////////////////////////////////////////////////////////
337 template <typename PointT> void
339  const Indices &inliers, const Eigen::VectorXf &model_coefficients, Eigen::VectorXf &optimized_coefficients) const
340 {
341  // Needs a valid set of model coefficients
342  if (!isModelValid (model_coefficients))
343  {
344  PCL_ERROR ("[pcl::SampleConsensusModelPlane::optimizeModelCoefficients] Given model is invalid!\n");
345  optimized_coefficients = model_coefficients;
346  return;
347  }
348 
349  // Need more than the minimum sample size to make a difference
350  if (inliers.size () <= sample_size_)
351  {
352  PCL_ERROR ("[pcl::SampleConsensusModelPlane::optimizeModelCoefficients] Not enough inliers found to optimize model coefficients (%lu)! Returning the same coefficients.\n", inliers.size ());
353  optimized_coefficients = model_coefficients;
354  return;
355  }
356 
357  Eigen::Vector4f plane_parameters;
358 
359  // Use Least-Squares to fit the plane through all the given sample points and find out its coefficients
360  EIGEN_ALIGN16 Eigen::Matrix3f covariance_matrix;
361  Eigen::Vector4f xyz_centroid;
362 
363  computeMeanAndCovarianceMatrix (*input_, inliers, covariance_matrix, xyz_centroid);
364 
365  // Compute the model coefficients
366  EIGEN_ALIGN16 Eigen::Vector3f::Scalar eigen_value;
367  EIGEN_ALIGN16 Eigen::Vector3f eigen_vector;
368  pcl::eigen33 (covariance_matrix, eigen_value, eigen_vector);
369 
370  // Hessian form (D = nc . p_plane (centroid here) + p)
371  optimized_coefficients.resize (model_size_);
372  optimized_coefficients[0] = eigen_vector [0];
373  optimized_coefficients[1] = eigen_vector [1];
374  optimized_coefficients[2] = eigen_vector [2];
375  optimized_coefficients[3] = 0.0f;
376  optimized_coefficients[3] = -1.0f * optimized_coefficients.dot (xyz_centroid);
377 
378  // Make sure it results in a valid model
379  if (!isModelValid (optimized_coefficients))
380  {
381  optimized_coefficients = model_coefficients;
382  }
383 }
384 
385 //////////////////////////////////////////////////////////////////////////
386 template <typename PointT> void
388  const Indices &inliers, const Eigen::VectorXf &model_coefficients, PointCloud &projected_points, bool copy_data_fields) const
389 {
390  // Needs a valid set of model coefficients
391  if (!isModelValid (model_coefficients))
392  {
393  PCL_ERROR ("[pcl::SampleConsensusModelPlane::projectPoints] Given model is invalid!\n");
394  return;
395  }
396 
397  projected_points.header = input_->header;
398  projected_points.is_dense = input_->is_dense;
399 
400  Eigen::Vector4f mc (model_coefficients[0], model_coefficients[1], model_coefficients[2], 0.0f);
401 
402  // normalize the vector perpendicular to the plane...
403  mc.normalize ();
404  // ... and store the resulting normal as a local copy of the model coefficients
405  Eigen::Vector4f tmp_mc = model_coefficients;
406  tmp_mc[0] = mc[0];
407  tmp_mc[1] = mc[1];
408  tmp_mc[2] = mc[2];
409 
410  // Copy all the data fields from the input cloud to the projected one?
411  if (copy_data_fields)
412  {
413  // Allocate enough space and copy the basics
414  projected_points.resize (input_->size ());
415  projected_points.width = input_->width;
416  projected_points.height = input_->height;
417 
418  using FieldList = typename pcl::traits::fieldList<PointT>::type;
419  // Iterate over each point
420  for (std::size_t i = 0; i < input_->size (); ++i)
421  // Iterate over each dimension
422  pcl::for_each_type <FieldList> (NdConcatenateFunctor <PointT, PointT> ((*input_)[i], projected_points[i]));
423 
424  // Iterate through the 3d points and calculate the distances from them to the plane
425  for (const auto &inlier : inliers)
426  {
427  // Calculate the distance from the point to the plane
428  Eigen::Vector4f p ((*input_)[inlier].x,
429  (*input_)[inlier].y,
430  (*input_)[inlier].z,
431  1);
432  // use normalized coefficients to calculate the scalar projection
433  float distance_to_plane = tmp_mc.dot (p);
434 
435  pcl::Vector4fMap pp = projected_points[inlier].getVector4fMap ();
436  pp.matrix () = p - mc * distance_to_plane; // mc[3] = 0, therefore the 3rd coordinate is safe
437  }
438  }
439  else
440  {
441  // Allocate enough space and copy the basics
442  projected_points.resize (inliers.size ());
443  projected_points.width = inliers.size ();
444  projected_points.height = 1;
445 
446  using FieldList = typename pcl::traits::fieldList<PointT>::type;
447  // Iterate over each point
448  for (std::size_t i = 0; i < inliers.size (); ++i)
449  {
450  // Iterate over each dimension
451  pcl::for_each_type <FieldList> (NdConcatenateFunctor <PointT, PointT> ((*input_)[inliers[i]], projected_points[i]));
452  }
453 
454  // Iterate through the 3d points and calculate the distances from them to the plane
455  for (std::size_t i = 0; i < inliers.size (); ++i)
456  {
457  // Calculate the distance from the point to the plane
458  Eigen::Vector4f p ((*input_)[inliers[i]].x,
459  (*input_)[inliers[i]].y,
460  (*input_)[inliers[i]].z,
461  1.0f);
462  // use normalized coefficients to calculate the scalar projection
463  float distance_to_plane = tmp_mc.dot (p);
464 
465  pcl::Vector4fMap pp = projected_points[i].getVector4fMap ();
466  pp.matrix () = p - mc * distance_to_plane; // mc[3] = 0, therefore the 3rd coordinate is safe
467  }
468  }
469 }
470 
471 //////////////////////////////////////////////////////////////////////////
472 template <typename PointT> bool
474  const std::set<index_t> &indices, const Eigen::VectorXf &model_coefficients, const double threshold) const
475 {
476  // Needs a valid set of model coefficients
477  if (!isModelValid (model_coefficients))
478  {
479  PCL_ERROR ("[pcl::SampleConsensusModelPlane::doSamplesVerifyModel] Given model is invalid!\n");
480  return (false);
481  }
482 
483  for (const auto &index : indices)
484  {
485  Eigen::Vector4f pt ((*input_)[index].x,
486  (*input_)[index].y,
487  (*input_)[index].z,
488  1.0f);
489  if (std::abs (model_coefficients.dot (pt)) > threshold)
490  {
491  return (false);
492  }
493  }
494 
495  return (true);
496 }
497 
498 #define PCL_INSTANTIATE_SampleConsensusModelPlane(T) template class PCL_EXPORTS pcl::SampleConsensusModelPlane<T>;
499 
500 #endif // PCL_SAMPLE_CONSENSUS_IMPL_SAC_MODEL_PLANE_H_
501 
pcl::computeMeanAndCovarianceMatrix
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:485
pcl::PointCloud::height
std::uint32_t height
The point cloud height (if organized as an image-structure).
Definition: point_cloud.h:400
pcl::SampleConsensusModelPlane::selectWithinDistance
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.
Definition: sac_model_plane.hpp:179
pcl::SampleConsensusModelPlane::countWithinDistance
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.
Definition: sac_model_plane.hpp:217
pcl::geometry::distance
float distance(const PointT &p1, const PointT &p2)
Definition: geometry.h:60
pcl::SampleConsensusModelPlane
SampleConsensusModelPlane defines a model for 3D plane segmentation.
Definition: sac_model_plane.h:142
pcl::NdConcatenateFunctor
Helper functor structure for concatenate.
Definition: concatenate.h:49
pcl::PointCloud
PointCloud represents the base class in PCL for storing collections of 3D points.
Definition: distances.h:55
pcl::eigen33
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
pcl::SampleConsensusModelPlane::countWithinDistanceStandard
std::size_t countWithinDistanceStandard(const Eigen::VectorXf &model_coefficients, const double threshold, std::size_t i=0) const
This implementation uses no SIMD instructions.
Definition: sac_model_plane.hpp:237
pcl::SampleConsensusModelPlane::projectPoints
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.
Definition: sac_model_plane.hpp:387
pcl::PointCloud::width
std::uint32_t width
The point cloud width (if organized as an image-structure).
Definition: point_cloud.h:398
pcl::SampleConsensusModelPlane::optimizeModelCoefficients
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.
Definition: sac_model_plane.hpp:338
pcl::SampleConsensusModelPlane::computeModelCoefficients
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...
Definition: sac_model_plane.hpp:71
pcl::Array4fMapConst
const Eigen::Map< const Eigen::Array4f, Eigen::Aligned > Array4fMapConst
Definition: point_types.hpp:227
pcl::PointCloud::is_dense
bool is_dense
True if no points are invalid (e.g., have NaN or Inf values in any of their floating point fields).
Definition: point_cloud.h:403
pcl::PointCloud::resize
void resize(std::size_t count)
Resizes the container to contain count elements.
Definition: point_cloud.h:462
pcl::PointCloud::header
pcl::PCLHeader header
The point cloud header.
Definition: point_cloud.h:392
pcl::Indices
IndicesAllocator<> Indices
Type used for indices in PCL.
Definition: types.h:133
pcl::SampleConsensusModelPlane::getDistancesToModel
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.
Definition: sac_model_plane.hpp:148
pcl::SampleConsensusModelPlane::doSamplesVerifyModel
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.
Definition: sac_model_plane.hpp:473
pcl::Vector4fMap
Eigen::Map< Eigen::Vector4f, Eigen::Aligned > Vector4fMap
Definition: point_types.hpp:230
centroid.h