Point Cloud Library (PCL)  1.14.1-dev
centroid.h
Go to the documentation of this file.
1 /*
2  * Software License Agreement (BSD License)
3  *
4  * Point Cloud Library (PCL) - www.pointclouds.org
5  * Copyright (c) 2010, 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  */
38 
39 #pragma once
40 
41 #include <pcl/memory.h>
42 #include <pcl/pcl_macros.h>
43 #include <pcl/point_cloud.h>
44 #include <pcl/type_traits.h>
45 #include <pcl/PointIndices.h>
46 #include <pcl/cloud_iterator.h>
47 
48 /**
49  * \file pcl/common/centroid.h
50  * Define methods for centroid estimation and covariance matrix calculus
51  * \ingroup common
52  */
53 
54 /*@{*/
55 namespace pcl
56 {
57  /** \brief Compute the 3D (X-Y-Z) centroid of a set of points and return it as a 3D vector.
58  * \param[in] cloud_iterator an iterator over the input point cloud
59  * \param[out] centroid the output centroid
60  * \return number of valid points used to determine the centroid. In case of dense point clouds, this is the same as the size of input cloud.
61  * \note if return value is 0, the centroid is not changed, thus not valid.
62  * The last component of the vector is set to 1, this allows to transform the centroid vector with 4x4 matrices.
63  * \ingroup common
64  */
65  template <typename PointT, typename Scalar> inline unsigned int
66  compute3DCentroid (ConstCloudIterator<PointT> &cloud_iterator,
67  Eigen::Matrix<Scalar, 4, 1> &centroid);
68 
69  template <typename PointT> inline unsigned int
71  Eigen::Vector4f &centroid)
72  {
73  return (compute3DCentroid <PointT, float> (cloud_iterator, centroid));
74  }
75 
76  template <typename PointT> inline unsigned int
78  Eigen::Vector4d &centroid)
79  {
80  return (compute3DCentroid <PointT, double> (cloud_iterator, centroid));
81  }
82 
83  /** \brief Compute the 3D (X-Y-Z) centroid of a set of points and return it as a 3D vector.
84  * \param[in] cloud the input point cloud
85  * \param[out] centroid the output centroid
86  * \return number of valid points used to determine the centroid. In case of dense point clouds, this is the same as the size of input cloud.
87  * \note if return value is 0, the centroid is not changed, thus not valid.
88  * The last component of the vector is set to 1, this allows to transform the centroid vector with 4x4 matrices.
89  * \ingroup common
90  */
91  template <typename PointT, typename Scalar> inline unsigned int
93  Eigen::Matrix<Scalar, 4, 1> &centroid);
94 
95  template <typename PointT> inline unsigned int
97  Eigen::Vector4f &centroid)
98  {
99  return (compute3DCentroid <PointT, float> (cloud, centroid));
100  }
101 
102  template <typename PointT> inline unsigned int
104  Eigen::Vector4d &centroid)
105  {
106  return (compute3DCentroid <PointT, double> (cloud, centroid));
107  }
108 
109  /** \brief Compute the 3D (X-Y-Z) centroid of a set of points using their indices and
110  * return it as a 3D vector.
111  * \param[in] cloud the input point cloud
112  * \param[in] indices the point cloud indices that need to be used
113  * \param[out] centroid the output centroid
114  * \return number of valid points used to determine the centroid. In case of dense point clouds, this is the same as the size of input indices.
115  * \note if return value is 0, the centroid is not changed, thus not valid.
116  * The last component of the vector is set to 1, this allows to transform the centroid vector with 4x4 matrices.
117  * \ingroup common
118  */
119  template <typename PointT, typename Scalar> inline unsigned int
121  const Indices &indices,
122  Eigen::Matrix<Scalar, 4, 1> &centroid);
123 
124  template <typename PointT> inline unsigned int
126  const Indices &indices,
127  Eigen::Vector4f &centroid)
128  {
129  return (compute3DCentroid <PointT, float> (cloud, indices, centroid));
130  }
131 
132  template <typename PointT> inline unsigned int
134  const Indices &indices,
135  Eigen::Vector4d &centroid)
136  {
137  return (compute3DCentroid <PointT, double> (cloud, indices, centroid));
138  }
139 
140  /** \brief Compute the 3D (X-Y-Z) centroid of a set of points using their indices and
141  * return it as a 3D vector.
142  * \param[in] cloud the input point cloud
143  * \param[in] indices the point cloud indices that need to be used
144  * \param[out] centroid the output centroid
145  * \return number of valid points used to determine the centroid. In case of dense point clouds, this is the same as the size of input indices.
146  * \note if return value is 0, the centroid is not changed, thus not valid.
147  * The last component of the vector is set to 1, this allows to transform the centroid vector with 4x4 matrices.
148  * \ingroup common
149  */
150  template <typename PointT, typename Scalar> inline unsigned int
152  const pcl::PointIndices &indices,
153  Eigen::Matrix<Scalar, 4, 1> &centroid);
154 
155  template <typename PointT> inline unsigned int
157  const pcl::PointIndices &indices,
158  Eigen::Vector4f &centroid)
159  {
160  return (compute3DCentroid <PointT, float> (cloud, indices, centroid));
161  }
162 
163  template <typename PointT> inline unsigned int
165  const pcl::PointIndices &indices,
166  Eigen::Vector4d &centroid)
167  {
168  return (compute3DCentroid <PointT, double> (cloud, indices, centroid));
169  }
170 
171  /** \brief Compute the 3x3 covariance matrix of a given set of points.
172  * The result is returned as a Eigen::Matrix3f.
173  * Note: the covariance matrix is not normalized with the number of
174  * points. For a normalized covariance, please use
175  * computeCovarianceMatrixNormalized.
176  * \param[in] cloud the input point cloud
177  * \param[in] centroid the centroid of the set of points in the cloud
178  * \param[out] covariance_matrix the resultant 3x3 covariance matrix
179  * \return number of valid points used to determine the covariance matrix.
180  * In case of dense point clouds, this is the same as the size of input cloud.
181  * \note if return value is 0, the covariance matrix is not changed, thus not valid.
182  * \ingroup common
183  */
184  template <typename PointT, typename Scalar> inline unsigned int
186  const Eigen::Matrix<Scalar, 4, 1> &centroid,
187  Eigen::Matrix<Scalar, 3, 3> &covariance_matrix);
188 
189  template <typename PointT> inline unsigned int
191  const Eigen::Vector4f &centroid,
192  Eigen::Matrix3f &covariance_matrix)
193  {
194  return (computeCovarianceMatrix<PointT, float> (cloud, centroid, covariance_matrix));
195  }
196 
197  template <typename PointT> inline unsigned int
199  const Eigen::Vector4d &centroid,
200  Eigen::Matrix3d &covariance_matrix)
201  {
202  return (computeCovarianceMatrix<PointT, double> (cloud, centroid, covariance_matrix));
203  }
204 
205  /** \brief Compute normalized the 3x3 covariance matrix of a given set of points.
206  * The result is returned as a Eigen::Matrix3f.
207  * Normalized means that every entry has been divided by the number of points in the point cloud.
208  * For small number of points, or if you want explicitly the sample-variance, use computeCovarianceMatrix
209  * and scale the covariance matrix with 1 / (n-1), where n is the number of points used to calculate
210  * the covariance matrix and is returned by the computeCovarianceMatrix function.
211  * \param[in] cloud the input point cloud
212  * \param[in] centroid the centroid of the set of points in the cloud
213  * \param[out] covariance_matrix the resultant 3x3 covariance matrix
214  * \return number of valid points used to determine the covariance matrix.
215  * In case of dense point clouds, this is the same as the size of input cloud.
216  * \ingroup common
217  */
218  template <typename PointT, typename Scalar> inline unsigned int
220  const Eigen::Matrix<Scalar, 4, 1> &centroid,
221  Eigen::Matrix<Scalar, 3, 3> &covariance_matrix);
222 
223  template <typename PointT> inline unsigned int
225  const Eigen::Vector4f &centroid,
226  Eigen::Matrix3f &covariance_matrix)
227  {
228  return (computeCovarianceMatrixNormalized<PointT, float> (cloud, centroid, covariance_matrix));
229  }
230 
231  template <typename PointT> inline unsigned int
233  const Eigen::Vector4d &centroid,
234  Eigen::Matrix3d &covariance_matrix)
235  {
236  return (computeCovarianceMatrixNormalized<PointT, double> (cloud, centroid, covariance_matrix));
237  }
238 
239  /** \brief Compute the 3x3 covariance matrix of a given set of points using their indices.
240  * The result is returned as a Eigen::Matrix3f.
241  * Note: the covariance matrix is not normalized with the number of
242  * points. For a normalized covariance, please use
243  * computeCovarianceMatrixNormalized.
244  * \param[in] cloud the input point cloud
245  * \param[in] indices the point cloud indices that need to be used
246  * \param[in] centroid the centroid of the set of points in the cloud
247  * \param[out] covariance_matrix the resultant 3x3 covariance matrix
248  * \return number of valid points used to determine the covariance matrix.
249  * In case of dense point clouds, this is the same as the size of input indices.
250  * \ingroup common
251  */
252  template <typename PointT, typename Scalar> inline unsigned int
254  const Indices &indices,
255  const Eigen::Matrix<Scalar, 4, 1> &centroid,
256  Eigen::Matrix<Scalar, 3, 3> &covariance_matrix);
257 
258  template <typename PointT> inline unsigned int
260  const Indices &indices,
261  const Eigen::Vector4f &centroid,
262  Eigen::Matrix3f &covariance_matrix)
263  {
264  return (computeCovarianceMatrix<PointT, float> (cloud, indices, centroid, covariance_matrix));
265  }
266 
267  template <typename PointT> inline unsigned int
269  const Indices &indices,
270  const Eigen::Vector4d &centroid,
271  Eigen::Matrix3d &covariance_matrix)
272  {
273  return (computeCovarianceMatrix<PointT, double> (cloud, indices, centroid, covariance_matrix));
274  }
275 
276  /** \brief Compute the 3x3 covariance matrix of a given set of points using their indices.
277  * The result is returned as a Eigen::Matrix3f.
278  * Note: the covariance matrix is not normalized with the number of
279  * points. For a normalized covariance, please use
280  * computeCovarianceMatrixNormalized.
281  * \param[in] cloud the input point cloud
282  * \param[in] indices the point cloud indices that need to be used
283  * \param[in] centroid the centroid of the set of points in the cloud
284  * \param[out] covariance_matrix the resultant 3x3 covariance matrix
285  * \return number of valid points used to determine the covariance matrix.
286  * In case of dense point clouds, this is the same as the size of input indices.
287  * \ingroup common
288  */
289  template <typename PointT, typename Scalar> inline unsigned int
291  const pcl::PointIndices &indices,
292  const Eigen::Matrix<Scalar, 4, 1> &centroid,
293  Eigen::Matrix<Scalar, 3, 3> &covariance_matrix);
294 
295  template <typename PointT> inline unsigned int
297  const pcl::PointIndices &indices,
298  const Eigen::Vector4f &centroid,
299  Eigen::Matrix3f &covariance_matrix)
300  {
301  return (computeCovarianceMatrix<PointT, float> (cloud, indices, centroid, covariance_matrix));
302  }
303 
304  template <typename PointT> inline unsigned int
306  const pcl::PointIndices &indices,
307  const Eigen::Vector4d &centroid,
308  Eigen::Matrix3d &covariance_matrix)
309  {
310  return (computeCovarianceMatrix<PointT, double> (cloud, indices, centroid, covariance_matrix));
311  }
312 
313  /** \brief Compute the normalized 3x3 covariance matrix of a given set of points using
314  * their indices.
315  * The result is returned as a Eigen::Matrix3f.
316  * Normalized means that every entry has been divided by the number of entries in indices.
317  * For small number of points, or if you want explicitly the sample-variance, use computeCovarianceMatrix
318  * and scale the covariance matrix with 1 / (n-1), where n is the number of points used to calculate
319  * the covariance matrix and is returned by the computeCovarianceMatrix function.
320  * \param[in] cloud the input point cloud
321  * \param[in] indices the point cloud indices that need to be used
322  * \param[in] centroid the centroid of the set of points in the cloud
323  * \param[out] covariance_matrix the resultant 3x3 covariance matrix
324  * \return number of valid points used to determine the covariance matrix.
325  * In case of dense point clouds, this is the same as the size of input indices.
326  * \ingroup common
327  */
328  template <typename PointT, typename Scalar> inline unsigned int
330  const Indices &indices,
331  const Eigen::Matrix<Scalar, 4, 1> &centroid,
332  Eigen::Matrix<Scalar, 3, 3> &covariance_matrix);
333 
334  template <typename PointT> inline unsigned int
336  const Indices &indices,
337  const Eigen::Vector4f &centroid,
338  Eigen::Matrix3f &covariance_matrix)
339  {
340  return (computeCovarianceMatrixNormalized<PointT, float> (cloud, indices, centroid, covariance_matrix));
341  }
342 
343  template <typename PointT> inline unsigned int
345  const Indices &indices,
346  const Eigen::Vector4d &centroid,
347  Eigen::Matrix3d &covariance_matrix)
348  {
349  return (computeCovarianceMatrixNormalized<PointT, double> (cloud, indices, centroid, covariance_matrix));
350  }
351 
352  /** \brief Compute the normalized 3x3 covariance matrix of a given set of points using
353  * their indices. The result is returned as a Eigen::Matrix3f.
354  * Normalized means that every entry has been divided by the number of entries in indices.
355  * For small number of points, or if you want explicitly the sample-variance, use computeCovarianceMatrix
356  * and scale the covariance matrix with 1 / (n-1), where n is the number of points used to calculate
357  * the covariance matrix and is returned by the computeCovarianceMatrix function.
358  * \param[in] cloud the input point cloud
359  * \param[in] indices the point cloud indices that need to be used
360  * \param[in] centroid the centroid of the set of points in the cloud
361  * \param[out] covariance_matrix the resultant 3x3 covariance matrix
362  * \return number of valid points used to determine the covariance matrix.
363  * In case of dense point clouds, this is the same as the size of input indices.
364  * \ingroup common
365  */
366  template <typename PointT, typename Scalar> inline unsigned int
368  const pcl::PointIndices &indices,
369  const Eigen::Matrix<Scalar, 4, 1> &centroid,
370  Eigen::Matrix<Scalar, 3, 3> &covariance_matrix);
371 
372  template <typename PointT> inline unsigned int
374  const pcl::PointIndices &indices,
375  const Eigen::Vector4f &centroid,
376  Eigen::Matrix3f &covariance_matrix)
377  {
378  return (computeCovarianceMatrixNormalized<PointT, float> (cloud, indices, centroid, covariance_matrix));
379  }
380 
381  template <typename PointT> inline unsigned int
383  const pcl::PointIndices &indices,
384  const Eigen::Vector4d &centroid,
385  Eigen::Matrix3d &covariance_matrix)
386  {
387  return (computeCovarianceMatrixNormalized<PointT, double> (cloud, indices, centroid, covariance_matrix));
388  }
389 
390  /** \brief Compute the normalized 3x3 covariance matrix and the centroid of a given set of points in a single loop.
391  * Normalized means that every entry has been divided by the number of valid entries in the point cloud.
392  * For small number of points, or if you want explicitly the sample-variance, scale the covariance matrix
393  * with n / (n-1), where n is the number of points used to calculate the covariance matrix and is returned by this function.
394  * \note This method is theoretically exact. However using float for internal calculations reduces the accuracy but increases the efficiency.
395  * \param[in] cloud the input point cloud
396  * \param[out] covariance_matrix the resultant 3x3 covariance matrix
397  * \param[out] centroid the centroid of the set of points in the cloud
398  * \return number of valid points used to determine the covariance matrix.
399  * In case of dense point clouds, this is the same as the size of input cloud.
400  * \ingroup common
401  */
402  template <typename PointT, typename Scalar> inline unsigned int
404  Eigen::Matrix<Scalar, 3, 3> &covariance_matrix,
405  Eigen::Matrix<Scalar, 4, 1> &centroid);
406 
407  template <typename PointT> inline unsigned int
409  Eigen::Matrix3f &covariance_matrix,
410  Eigen::Vector4f &centroid)
411  {
412  return (computeMeanAndCovarianceMatrix<PointT, float> (cloud, covariance_matrix, centroid));
413  }
414 
415  template <typename PointT> inline unsigned int
417  Eigen::Matrix3d &covariance_matrix,
418  Eigen::Vector4d &centroid)
419  {
420  return (computeMeanAndCovarianceMatrix<PointT, double> (cloud, covariance_matrix, centroid));
421  }
422 
423  /** \brief Compute the normalized 3x3 covariance matrix and the centroid of a given set of points in a single loop.
424  * Normalized means that every entry has been divided by the number of entries in indices.
425  * For small number of points, or if you want explicitly the sample-variance, scale the covariance matrix
426  * with n / (n-1), where n is the number of points used to calculate the covariance matrix and is returned by this function.
427  * \note This method is theoretically exact. However using float for internal calculations reduces the accuracy but increases the efficiency.
428  * \param[in] cloud the input point cloud
429  * \param[in] indices subset of points given by their indices
430  * \param[out] covariance_matrix the resultant 3x3 covariance matrix
431  * \param[out] centroid the centroid of the set of points in the cloud
432  * \return number of valid points used to determine the covariance matrix.
433  * In case of dense point clouds, this is the same as the size of input indices.
434  * \ingroup common
435  */
436  template <typename PointT, typename Scalar> inline unsigned int
438  const Indices &indices,
439  Eigen::Matrix<Scalar, 3, 3> &covariance_matrix,
440  Eigen::Matrix<Scalar, 4, 1> &centroid);
441 
442  template <typename PointT> inline unsigned int
444  const Indices &indices,
445  Eigen::Matrix3f &covariance_matrix,
446  Eigen::Vector4f &centroid)
447  {
448  return (computeMeanAndCovarianceMatrix<PointT, float> (cloud, indices, covariance_matrix, centroid));
449  }
450 
451  template <typename PointT> inline unsigned int
453  const Indices &indices,
454  Eigen::Matrix3d &covariance_matrix,
455  Eigen::Vector4d &centroid)
456  {
457  return (computeMeanAndCovarianceMatrix<PointT, double> (cloud, indices, covariance_matrix, centroid));
458  }
459 
460  /** \brief Compute the normalized 3x3 covariance matrix and the centroid of a given set of points in a single loop.
461  * Normalized means that every entry has been divided by the number of entries in indices.
462  * For small number of points, or if you want explicitly the sample-variance, scale the covariance matrix
463  * with n / (n-1), where n is the number of points used to calculate the covariance matrix and is returned by this function.
464  * \note This method is theoretically exact. However using float for internal calculations reduces the accuracy but increases the efficiency.
465  * \param[in] cloud the input point cloud
466  * \param[in] indices subset of points given by their indices
467  * \param[out] centroid the centroid of the set of points in the cloud
468  * \param[out] covariance_matrix the resultant 3x3 covariance matrix
469  * \return number of valid points used to determine the covariance matrix.
470  * In case of dense point clouds, this is the same as the size of input indices.
471  * \ingroup common
472  */
473  template <typename PointT, typename Scalar> inline unsigned int
475  const pcl::PointIndices &indices,
476  Eigen::Matrix<Scalar, 3, 3> &covariance_matrix,
477  Eigen::Matrix<Scalar, 4, 1> &centroid);
478 
479  template <typename PointT> inline unsigned int
481  const pcl::PointIndices &indices,
482  Eigen::Matrix3f &covariance_matrix,
483  Eigen::Vector4f &centroid)
484  {
485  return (computeMeanAndCovarianceMatrix<PointT, float> (cloud, indices, covariance_matrix, centroid));
486  }
487 
488  template <typename PointT> inline unsigned int
490  const pcl::PointIndices &indices,
491  Eigen::Matrix3d &covariance_matrix,
492  Eigen::Vector4d &centroid)
493  {
494  return (computeMeanAndCovarianceMatrix<PointT, double> (cloud, indices, covariance_matrix, centroid));
495  }
496 
497  /** \brief Compute the normalized 3x3 covariance matrix for a already demeaned point cloud.
498  * Normalized means that every entry has been divided by the number of entries in the input point cloud.
499  * For small number of points, or if you want explicitly the sample-variance, scale the covariance matrix
500  * with n / (n-1), where n is the number of points used to calculate the covariance matrix and is returned by this function.
501  * \note This method is theoretically exact. However using float for internal calculations reduces the accuracy but increases the efficiency.
502  * \param[in] cloud the input point cloud
503  * \param[out] covariance_matrix the resultant 3x3 covariance matrix
504  * \return number of valid points used to determine the covariance matrix.
505  * In case of dense point clouds, this is the same as the size of input cloud.
506  * \ingroup common
507  */
508  template <typename PointT, typename Scalar> inline unsigned int
510  Eigen::Matrix<Scalar, 3, 3> &covariance_matrix);
511 
512  template <typename PointT> inline unsigned int
514  Eigen::Matrix3f &covariance_matrix)
515  {
516  return (computeCovarianceMatrix<PointT, float> (cloud, covariance_matrix));
517  }
518 
519  template <typename PointT> inline unsigned int
521  Eigen::Matrix3d &covariance_matrix)
522  {
523  return (computeCovarianceMatrix<PointT, double> (cloud, covariance_matrix));
524  }
525 
526  /** \brief Compute the normalized 3x3 covariance matrix for a already demeaned point cloud.
527  * Normalized means that every entry has been divided by the number of entries in indices.
528  * For small number of points, or if you want explicitly the sample-variance, scale the covariance matrix
529  * with n / (n-1), where n is the number of points used to calculate the covariance matrix and is returned by this function.
530  * \note This method is theoretically exact. However using float for internal calculations reduces the accuracy but increases the efficiency.
531  * \param[in] cloud the input point cloud
532  * \param[in] indices subset of points given by their indices
533  * \param[out] covariance_matrix the resultant 3x3 covariance matrix
534  * \return number of valid points used to determine the covariance matrix.
535  * In case of dense point clouds, this is the same as the size of input indices.
536  * \ingroup common
537  */
538  template <typename PointT, typename Scalar> inline unsigned int
540  const Indices &indices,
541  Eigen::Matrix<Scalar, 3, 3> &covariance_matrix);
542 
543  template <typename PointT> inline unsigned int
545  const Indices &indices,
546  Eigen::Matrix3f &covariance_matrix)
547  {
548  return (computeCovarianceMatrix<PointT, float> (cloud, indices, covariance_matrix));
549  }
550 
551  template <typename PointT> inline unsigned int
553  const Indices &indices,
554  Eigen::Matrix3d &covariance_matrix)
555  {
556  return (computeCovarianceMatrix<PointT, double> (cloud, indices, covariance_matrix));
557  }
558 
559  /** \brief Compute the normalized 3x3 covariance matrix for a already demeaned point cloud.
560  * Normalized means that every entry has been divided by the number of entries in indices.
561  * For small number of points, or if you want explicitly the sample-variance, scale the covariance matrix
562  * with n / (n-1), where n is the number of points used to calculate the covariance matrix and is returned by this function.
563  * \note This method is theoretically exact. However using float for internal calculations reduces the accuracy but increases the efficiency.
564  * \param[in] cloud the input point cloud
565  * \param[in] indices subset of points given by their indices
566  * \param[out] covariance_matrix the resultant 3x3 covariance matrix
567  * \return number of valid points used to determine the covariance matrix.
568  * In case of dense point clouds, this is the same as the size of input indices.
569  * \ingroup common
570  */
571  template <typename PointT, typename Scalar> inline unsigned int
573  const pcl::PointIndices &indices,
574  Eigen::Matrix<Scalar, 3, 3> &covariance_matrix);
575 
576  template <typename PointT> inline unsigned int
578  const pcl::PointIndices &indices,
579  Eigen::Matrix3f &covariance_matrix)
580  {
581  return (computeCovarianceMatrix<PointT, float> (cloud, indices, covariance_matrix));
582  }
583 
584  template <typename PointT> inline unsigned int
586  const pcl::PointIndices &indices,
587  Eigen::Matrix3d &covariance_matrix)
588  {
589  return (computeCovarianceMatrix<PointT, double> (cloud, indices, covariance_matrix));
590  }
591 
592 
593  /** \brief Compute centroid, OBB (Oriented Bounding Box), PCA axes of a given set of points.
594  * OBB is oriented like the three axes (major, middle and minor) with
595  * major_axis = obb_rotational_matrix.col(0)
596  * middle_axis = obb_rotational_matrix.col(1)
597  * minor_axis = obb_rotational_matrix.col(2)
598  * one way to visualize OBB when Scalar is float:
599  * Eigen::Vector3f position(obb_position(0), obb_position(1), obb_position(2));
600  * Eigen::Quaternionf quat(obb_rotational_matrix);
601  * viewer->addCube(position, quat, obb_dimensions(0), obb_dimensions(1), obb_dimensions(2), .....);
602  * \param[in] cloud the input point cloud
603  * \param[out] centroid the centroid (mean value of the XYZ coordinates) of the set of points in the cloud
604  * \param[out] obb_center position of the center of the OBB (it is the same as centroid if the cloud is centrally symmetric)
605  * \param[out] obb_dimensions (width, height and depth) of the OBB
606  * \param[out] obb_rotational_matrix rotational matrix of the OBB
607  * \return number of valid points used to determine the output.
608  * In case of dense point clouds, this is the same as the size of the input cloud.
609  * \ingroup common
610  */
611  template <typename PointT, typename Scalar> inline unsigned int
613  Eigen::Matrix<Scalar, 3, 1>& centroid,
614  Eigen::Matrix<Scalar, 3, 1>& obb_center,
615  Eigen::Matrix<Scalar, 3, 1>& obb_dimensions,
616  Eigen::Matrix<Scalar, 3, 3>& obb_rotational_matrix);
617 
618 
619  /** \brief Compute centroid, OBB (Oriented Bounding Box), PCA axes of a given set of points.
620  * OBB is oriented like the three axes (major, middle and minor) with
621  * major_axis = obb_rotational_matrix.col(0)
622  * middle_axis = obb_rotational_matrix.col(1)
623  * minor_axis = obb_rotational_matrix.col(2)
624  * one way to visualize OBB when Scalar is float:
625  * Eigen::Vector3f position(obb_position(0), obb_position(1), obb_position(2));
626  * Eigen::Quaternionf quat(obb_rotational_matrix);
627  * viewer->addCube(position, quat, obb_dimensions(0), obb_dimensions(1), obb_dimensions(2), .....);
628  * \param[in] cloud the input point cloud
629  * \param[in] indices subset of points given by their indices
630  * \param[out] centroid the centroid (mean value of the XYZ coordinates) of the set of points in the cloud
631  * \param[out] obb_center position of the center of the OBB (it is the same as centroid if the cloud is centrally symmetric)
632  * \param[out] obb_dimensions (width, height and depth) of the OBB
633  * \param[out] obb_rotational_matrix rotational matrix of the OBB
634  * \return number of valid points used to determine the output.
635  * In case of dense point clouds, this is the same as the size of the input cloud.
636  * \ingroup common
637  */
638  template <typename PointT, typename Scalar> inline unsigned int
640  const Indices &indices,
641  Eigen::Matrix<Scalar, 3, 1>& centroid,
642  Eigen::Matrix<Scalar, 3, 1>& obb_center,
643  Eigen::Matrix<Scalar, 3, 1>& obb_dimensions,
644  Eigen::Matrix<Scalar, 3, 3>& obb_rotational_matrix);
645 
646 
647  /** \brief Subtract a centroid from a point cloud and return the de-meaned representation
648  * \param[in] cloud_iterator an iterator over the input point cloud
649  * \param[in] centroid the centroid of the point cloud
650  * \param[out] cloud_out the resultant output point cloud
651  * \param[in] npts the number of samples guaranteed to be left in the input cloud, accessible by the iterator. If not given, it will be calculated.
652  * \ingroup common
653  */
654  template <typename PointT, typename Scalar> void
655  demeanPointCloud (ConstCloudIterator<PointT> &cloud_iterator,
656  const Eigen::Matrix<Scalar, 4, 1> &centroid,
657  pcl::PointCloud<PointT> &cloud_out,
658  int npts = 0);
659 
660  template <typename PointT> void
662  const Eigen::Vector4f &centroid,
663  pcl::PointCloud<PointT> &cloud_out,
664  int npts = 0)
665  {
666  return (demeanPointCloud<PointT, float> (cloud_iterator, centroid, cloud_out, npts));
667  }
668 
669  template <typename PointT> void
671  const Eigen::Vector4d &centroid,
672  pcl::PointCloud<PointT> &cloud_out,
673  int npts = 0)
674  {
675  return (demeanPointCloud<PointT, double> (cloud_iterator, centroid, cloud_out, npts));
676  }
677 
678  /** \brief Subtract a centroid from a point cloud and return the de-meaned representation
679  * \param[in] cloud_in the input point cloud
680  * \param[in] centroid the centroid of the point cloud
681  * \param[out] cloud_out the resultant output point cloud
682  * \ingroup common
683  */
684  template <typename PointT, typename Scalar> void
685  demeanPointCloud (const pcl::PointCloud<PointT> &cloud_in,
686  const Eigen::Matrix<Scalar, 4, 1> &centroid,
687  pcl::PointCloud<PointT> &cloud_out);
688 
689  template <typename PointT> void
691  const Eigen::Vector4f &centroid,
692  pcl::PointCloud<PointT> &cloud_out)
693  {
694  return (demeanPointCloud<PointT, float> (cloud_iterator, centroid, cloud_out));
695  }
696 
697  template <typename PointT> void
699  const Eigen::Vector4d &centroid,
700  pcl::PointCloud<PointT> &cloud_out)
701  {
702  return (demeanPointCloud<PointT, double> (cloud_iterator, centroid, cloud_out));
703  }
704 
705  /** \brief Subtract a centroid from a point cloud and return the de-meaned representation
706  * \param[in] cloud_in the input point cloud
707  * \param[in] indices the set of point indices to use from the input point cloud
708  * \param[out] centroid the centroid of the point cloud
709  * \param cloud_out the resultant output point cloud
710  * \ingroup common
711  */
712  template <typename PointT, typename Scalar> void
713  demeanPointCloud (const pcl::PointCloud<PointT> &cloud_in,
714  const Indices &indices,
715  const Eigen::Matrix<Scalar, 4, 1> &centroid,
716  pcl::PointCloud<PointT> &cloud_out);
717 
718  template <typename PointT> void
720  const Indices &indices,
721  const Eigen::Vector4f &centroid,
722  pcl::PointCloud<PointT> &cloud_out)
723  {
724  return (demeanPointCloud<PointT, float> (cloud_in, indices, centroid, cloud_out));
725  }
726 
727  template <typename PointT> void
729  const Indices &indices,
730  const Eigen::Vector4d &centroid,
731  pcl::PointCloud<PointT> &cloud_out)
732  {
733  return (demeanPointCloud<PointT, double> (cloud_in, indices, centroid, cloud_out));
734  }
735 
736  /** \brief Subtract a centroid from a point cloud and return the de-meaned representation
737  * \param[in] cloud_in the input point cloud
738  * \param[in] indices the set of point indices to use from the input point cloud
739  * \param[out] centroid the centroid of the point cloud
740  * \param cloud_out the resultant output point cloud
741  * \ingroup common
742  */
743  template <typename PointT, typename Scalar> void
744  demeanPointCloud (const pcl::PointCloud<PointT> &cloud_in,
745  const pcl::PointIndices& indices,
746  const Eigen::Matrix<Scalar, 4, 1> &centroid,
747  pcl::PointCloud<PointT> &cloud_out);
748 
749  template <typename PointT> void
751  const pcl::PointIndices& indices,
752  const Eigen::Vector4f &centroid,
753  pcl::PointCloud<PointT> &cloud_out)
754  {
755  return (demeanPointCloud<PointT, float> (cloud_in, indices, centroid, cloud_out));
756  }
757 
758  template <typename PointT> void
760  const pcl::PointIndices& indices,
761  const Eigen::Vector4d &centroid,
762  pcl::PointCloud<PointT> &cloud_out)
763  {
764  return (demeanPointCloud<PointT, double> (cloud_in, indices, centroid, cloud_out));
765  }
766 
767  /** \brief Subtract a centroid from a point cloud and return the de-meaned
768  * representation as an Eigen matrix
769  * \param[in] cloud_iterator an iterator over the input point cloud
770  * \param[in] centroid the centroid of the point cloud
771  * \param[out] cloud_out the resultant output XYZ0 dimensions of \a cloud_in as
772  * an Eigen matrix (4 rows, N pts columns)
773  * \param[in] npts the number of samples guaranteed to be left in the input cloud, accessible by the iterator. If not given, it will be calculated.
774  * \ingroup common
775  */
776  template <typename PointT, typename Scalar> void
777  demeanPointCloud (ConstCloudIterator<PointT> &cloud_iterator,
778  const Eigen::Matrix<Scalar, 4, 1> &centroid,
779  Eigen::Matrix<Scalar, Eigen::Dynamic, Eigen::Dynamic> &cloud_out,
780  int npts = 0);
781 
782  template <typename PointT> void
784  const Eigen::Vector4f &centroid,
785  Eigen::MatrixXf &cloud_out,
786  int npts = 0)
787  {
788  return (demeanPointCloud<PointT, float> (cloud_iterator, centroid, cloud_out, npts));
789  }
790 
791  template <typename PointT> void
793  const Eigen::Vector4d &centroid,
794  Eigen::MatrixXd &cloud_out,
795  int npts = 0)
796  {
797  return (demeanPointCloud<PointT, double> (cloud_iterator, centroid, cloud_out, npts));
798  }
799 
800  /** \brief Subtract a centroid from a point cloud and return the de-meaned
801  * representation as an Eigen matrix
802  * \param[in] cloud_in the input point cloud
803  * \param[in] centroid the centroid of the point cloud
804  * \param[out] cloud_out the resultant output XYZ0 dimensions of \a cloud_in as
805  * an Eigen matrix (4 rows, N pts columns)
806  * \ingroup common
807  */
808  template <typename PointT, typename Scalar> void
809  demeanPointCloud (const pcl::PointCloud<PointT> &cloud_in,
810  const Eigen::Matrix<Scalar, 4, 1> &centroid,
811  Eigen::Matrix<Scalar, Eigen::Dynamic, Eigen::Dynamic> &cloud_out);
812 
813  template <typename PointT> void
815  const Eigen::Vector4f &centroid,
816  Eigen::MatrixXf &cloud_out)
817  {
818  return (demeanPointCloud<PointT, float> (cloud_in, centroid, cloud_out));
819  }
820 
821  template <typename PointT> void
823  const Eigen::Vector4d &centroid,
824  Eigen::MatrixXd &cloud_out)
825  {
826  return (demeanPointCloud<PointT, double> (cloud_in, centroid, cloud_out));
827  }
828 
829  /** \brief Subtract a centroid from a point cloud and return the de-meaned
830  * representation as an Eigen matrix
831  * \param[in] cloud_in the input point cloud
832  * \param[in] indices the set of point indices to use from the input point cloud
833  * \param[in] centroid the centroid of the point cloud
834  * \param[out] cloud_out the resultant output XYZ0 dimensions of \a cloud_in as
835  * an Eigen matrix (4 rows, N pts columns)
836  * \ingroup common
837  */
838  template <typename PointT, typename Scalar> void
839  demeanPointCloud (const pcl::PointCloud<PointT> &cloud_in,
840  const Indices &indices,
841  const Eigen::Matrix<Scalar, 4, 1> &centroid,
842  Eigen::Matrix<Scalar, Eigen::Dynamic, Eigen::Dynamic> &cloud_out);
843 
844  template <typename PointT> void
846  const Indices &indices,
847  const Eigen::Vector4f &centroid,
848  Eigen::MatrixXf &cloud_out)
849  {
850  return (demeanPointCloud<PointT, float> (cloud_in, indices, centroid, cloud_out));
851  }
852 
853  template <typename PointT> void
855  const Indices &indices,
856  const Eigen::Vector4d &centroid,
857  Eigen::MatrixXd &cloud_out)
858  {
859  return (demeanPointCloud<PointT, double> (cloud_in, indices, centroid, cloud_out));
860  }
861 
862  /** \brief Subtract a centroid from a point cloud and return the de-meaned
863  * representation as an Eigen matrix
864  * \param[in] cloud_in the input point cloud
865  * \param[in] indices the set of point indices to use from the input point cloud
866  * \param[in] centroid the centroid of the point cloud
867  * \param[out] cloud_out the resultant output XYZ0 dimensions of \a cloud_in as
868  * an Eigen matrix (4 rows, N pts columns)
869  * \ingroup common
870  */
871  template <typename PointT, typename Scalar> void
872  demeanPointCloud (const pcl::PointCloud<PointT> &cloud_in,
873  const pcl::PointIndices& indices,
874  const Eigen::Matrix<Scalar, 4, 1> &centroid,
875  Eigen::Matrix<Scalar, Eigen::Dynamic, Eigen::Dynamic> &cloud_out);
876 
877  template <typename PointT> void
879  const pcl::PointIndices& indices,
880  const Eigen::Vector4f &centroid,
881  Eigen::MatrixXf &cloud_out)
882  {
883  return (demeanPointCloud<PointT, float> (cloud_in, indices, centroid, cloud_out));
884  }
885 
886  template <typename PointT> void
888  const pcl::PointIndices& indices,
889  const Eigen::Vector4d &centroid,
890  Eigen::MatrixXd &cloud_out)
891  {
892  return (demeanPointCloud<PointT, double> (cloud_in, indices, centroid, cloud_out));
893  }
894 
895  /** \brief Helper functor structure for n-D centroid estimation. */
896  template<typename PointT, typename Scalar>
898  {
899  using Pod = typename traits::POD<PointT>::type;
900 
901  NdCentroidFunctor (const PointT &p, Eigen::Matrix<Scalar, Eigen::Dynamic, 1> &centroid)
902  : centroid_ (centroid),
903  p_ (reinterpret_cast<const Pod&>(p)) { }
904 
905  template<typename Key> inline void operator() ()
906  {
907  using T = typename pcl::traits::datatype<PointT, Key>::type;
908  const std::uint8_t* raw_ptr = reinterpret_cast<const std::uint8_t*>(&p_) + pcl::traits::offset<PointT, Key>::value;
909  const T* data_ptr = reinterpret_cast<const T*>(raw_ptr);
910 
911  // Check if the value is invalid
912  if (!std::isfinite (*data_ptr))
913  {
914  f_idx_++;
915  return;
916  }
917 
918  centroid_[f_idx_++] += *data_ptr;
919  }
920 
921  private:
922  int f_idx_{0};
923  Eigen::Matrix<Scalar, Eigen::Dynamic, 1> &centroid_;
924  const Pod &p_;
925  };
926 
927  /** \brief General, all purpose nD centroid estimation for a set of points using their
928  * indices.
929  * \param cloud the input point cloud
930  * \param centroid the output centroid
931  * \ingroup common
932  */
933  template <typename PointT, typename Scalar> inline void
935  Eigen::Matrix<Scalar, Eigen::Dynamic, 1> &centroid);
936 
937  template <typename PointT> inline void
939  Eigen::VectorXf &centroid)
940  {
941  return (computeNDCentroid<PointT, float> (cloud, centroid));
942  }
943 
944  template <typename PointT> inline void
946  Eigen::VectorXd &centroid)
947  {
948  return (computeNDCentroid<PointT, double> (cloud, centroid));
949  }
950 
951  /** \brief General, all purpose nD centroid estimation for a set of points using their
952  * indices.
953  * \param cloud the input point cloud
954  * \param indices the point cloud indices that need to be used
955  * \param centroid the output centroid
956  * \ingroup common
957  */
958  template <typename PointT, typename Scalar> inline void
960  const Indices &indices,
961  Eigen::Matrix<Scalar, Eigen::Dynamic, 1> &centroid);
962 
963  template <typename PointT> inline void
965  const Indices &indices,
966  Eigen::VectorXf &centroid)
967  {
968  return (computeNDCentroid<PointT, float> (cloud, indices, centroid));
969  }
970 
971  template <typename PointT> inline void
973  const Indices &indices,
974  Eigen::VectorXd &centroid)
975  {
976  return (computeNDCentroid<PointT, double> (cloud, indices, centroid));
977  }
978 
979  /** \brief General, all purpose nD centroid estimation for a set of points using their
980  * indices.
981  * \param cloud the input point cloud
982  * \param indices the point cloud indices that need to be used
983  * \param centroid the output centroid
984  * \ingroup common
985  */
986  template <typename PointT, typename Scalar> inline void
988  const pcl::PointIndices &indices,
989  Eigen::Matrix<Scalar, Eigen::Dynamic, 1> &centroid);
990 
991  template <typename PointT> inline void
993  const pcl::PointIndices &indices,
994  Eigen::VectorXf &centroid)
995  {
996  return (computeNDCentroid<PointT, float> (cloud, indices, centroid));
997  }
998 
999  template <typename PointT> inline void
1001  const pcl::PointIndices &indices,
1002  Eigen::VectorXd &centroid)
1003  {
1004  return (computeNDCentroid<PointT, double> (cloud, indices, centroid));
1005  }
1006 
1007 }
1008 
1009 #include <pcl/common/impl/accumulators.hpp>
1010 
1011 namespace pcl
1012 {
1013 
1014  /** A generic class that computes the centroid of points fed to it.
1015  *
1016  * Here by "centroid" we denote not just the mean of 3D point coordinates,
1017  * but also mean of values in the other data fields. The general-purpose
1018  * \ref computeNDCentroid() function also implements this sort of
1019  * functionality, however it does it in a "dumb" way, i.e. regardless of the
1020  * semantics of the data inside a field it simply averages the values. In
1021  * certain cases (e.g. for \c x, \c y, \c z, \c intensity fields) this
1022  * behavior is reasonable, however in other cases (e.g. \c rgb, \c rgba,
1023  * \c label fields) this does not lead to meaningful results.
1024  *
1025  * This class is capable of computing the centroid in a "smart" way, i.e.
1026  * taking into account the meaning of the data inside fields. Currently the
1027  * following fields are supported:
1028  *
1029  * Data | Point fields | Algorithm
1030  * --------- | ------------------------------------- | -------------------------------------------------------------------------------------------
1031  * XYZ | \c x, \c y, \c z | Average (separate for each field)
1032  * Normal | \c normal_x, \c normal_y, \c normal_z | Average (separate for each field), resulting vector is normalized
1033  * Curvature | \c curvature | Average
1034  * Color | \c rgb or \c rgba | Average (separate for R, G, B, and alpha channels)
1035  * Intensity | \c intensity | Average
1036  * Label | \c label | Majority vote; if several labels have the same largest support then the smaller label wins
1037  *
1038  * The template parameter defines the type of points that may be accumulated
1039  * with this class. This may be an arbitrary PCL point type, and centroid
1040  * computation will happen only for the fields that are present in it and are
1041  * supported.
1042  *
1043  * Current centroid may be retrieved at any time using get(). Note that the
1044  * function is templated on point type, so it is possible to fetch the
1045  * centroid into a point type that differs from the type of points that are
1046  * being accumulated. All the "extra" fields for which the centroid is not
1047  * being calculated will be left untouched.
1048  *
1049  * Example usage:
1050  *
1051  * \code
1052  * // Create and accumulate points
1053  * CentroidPoint<pcl::PointXYZ> centroid;
1054  * centroid.add (pcl::PointXYZ (1, 2, 3);
1055  * centroid.add (pcl::PointXYZ (5, 6, 7);
1056  * // Fetch centroid using `get()`
1057  * pcl::PointXYZ c1;
1058  * centroid.get (c1);
1059  * // The expected result is: c1.x == 3, c1.y == 4, c1.z == 5
1060  * // It is also okay to use `get()` with a different point type
1061  * pcl::PointXYZRGB c2;
1062  * centroid.get (c2);
1063  * // The expected result is: c2.x == 3, c2.y == 4, c2.z == 5,
1064  * // and c2.rgb is left untouched
1065  * \endcode
1066  *
1067  * \note Assumes that the points being inserted are valid.
1068  *
1069  * \note This class template can be successfully instantiated for *any*
1070  * PCL point type. Of course, each of the field averages is computed only if
1071  * the point type has the corresponding field.
1072  *
1073  * \ingroup common
1074  * \author Sergey Alexandrov */
1075  template <typename PointT>
1077  {
1078 
1079  public:
1080 
1081  CentroidPoint () = default;
1082 
1083  /** Add a new point to the centroid computation.
1084  *
1085  * In this function only the accumulators and point counter are updated,
1086  * actual centroid computation does not happen until get() is called. */
1087  void
1088  add (const PointT& point);
1089 
1090  /** Retrieve the current centroid.
1091  *
1092  * Computation (division of accumulated values by the number of points
1093  * and normalization where applicable) happens here. The result is not
1094  * cached, so any subsequent call to this function will trigger
1095  * re-computation.
1096  *
1097  * If the number of accumulated points is zero, then the point will be
1098  * left untouched. */
1099  template <typename PointOutT> void
1100  get (PointOutT& point) const;
1101 
1102  /** Get the total number of points that were added. */
1103  inline std::size_t
1104  getSize () const
1105  {
1106  return (num_points_);
1107  }
1108 
1110 
1111  private:
1112 
1113  std::size_t num_points_ = 0;
1114  typename pcl::detail::Accumulators<PointT>::type accumulators_;
1115 
1116  };
1117 
1118  /** Compute the centroid of a set of points and return it as a point.
1119  *
1120  * Implementation leverages \ref CentroidPoint class and therefore behaves
1121  * differently from \ref compute3DCentroid() and \ref computeNDCentroid().
1122  * See \ref CentroidPoint documentation for explanation.
1123  *
1124  * \param[in] cloud input point cloud
1125  * \param[out] centroid output centroid
1126  *
1127  * \return number of valid points used to determine the centroid (will be the
1128  * same as the size of the cloud if it is dense)
1129  *
1130  * \note If return value is \c 0, then the centroid is not changed, thus is
1131  * not valid.
1132  *
1133  * \ingroup common */
1134  template <typename PointInT, typename PointOutT> std::size_t
1136  PointOutT& centroid);
1137 
1138  /** Compute the centroid of a set of points and return it as a point.
1139  * \param[in] cloud
1140  * \param[in] indices point cloud indices that need to be used
1141  * \param[out] centroid
1142  * This is an overloaded function provided for convenience. See the
1143  * documentation for computeCentroid().
1144  *
1145  * \ingroup common */
1146  template <typename PointInT, typename PointOutT> std::size_t
1148  const Indices& indices,
1149  PointOutT& centroid);
1150 
1151 }
1152 /*@}*/
1153 #include <pcl/common/impl/centroid.hpp>
A generic class that computes the centroid of points fed to it.
Definition: centroid.h:1077
std::size_t getSize() const
Get the total number of points that were added.
Definition: centroid.h:1104
void get(PointOutT &point) const
Retrieve the current centroid.
Definition: centroid.hpp:1173
void add(const PointT &point)
Add a new point to the centroid computation.
Definition: centroid.hpp:1164
CentroidPoint()=default
Iterator class for point clouds with or without given indices.
PointCloud represents the base class in PCL for storing collections of 3D points.
Definition: point_cloud.h:173
unsigned int computeCentroidAndOBB(const pcl::PointCloud< PointT > &cloud, Eigen::Matrix< Scalar, 3, 1 > &centroid, Eigen::Matrix< Scalar, 3, 1 > &obb_center, Eigen::Matrix< Scalar, 3, 1 > &obb_dimensions, Eigen::Matrix< Scalar, 3, 3 > &obb_rotational_matrix)
Compute centroid, OBB (Oriented Bounding Box), PCA axes of a given set of points.
Definition: centroid.hpp:663
std::size_t computeCentroid(const pcl::PointCloud< PointInT > &cloud, PointOutT &centroid)
Compute the centroid of a set of points and return it as a point.
Definition: centroid.hpp:1187
#define PCL_MAKE_ALIGNED_OPERATOR_NEW
Macro to signal a class requires a custom allocator.
Definition: memory.h:63
void computeNDCentroid(const pcl::PointCloud< PointT > &cloud, Eigen::Matrix< Scalar, Eigen::Dynamic, 1 > &centroid)
General, all purpose nD centroid estimation for a set of points using their indices.
Definition: centroid.hpp:1111
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:509
void demeanPointCloud(ConstCloudIterator< PointT > &cloud_iterator, const Eigen::Matrix< Scalar, 4, 1 > &centroid, pcl::PointCloud< PointT > &cloud_out, int npts=0)
Subtract a centroid from a point cloud and return the de-meaned representation.
Definition: centroid.hpp:933
unsigned int computeCovarianceMatrixNormalized(const pcl::PointCloud< PointT > &cloud, const Eigen::Matrix< Scalar, 4, 1 > &centroid, Eigen::Matrix< Scalar, 3, 3 > &covariance_matrix)
Compute normalized the 3x3 covariance matrix of a given set of points.
Definition: centroid.hpp:269
unsigned int computeCovarianceMatrix(const pcl::PointCloud< PointT > &cloud, const Eigen::Matrix< Scalar, 4, 1 > &centroid, Eigen::Matrix< Scalar, 3, 3 > &covariance_matrix)
Compute the 3x3 covariance matrix of a given set of points.
Definition: centroid.hpp:192
unsigned int compute3DCentroid(ConstCloudIterator< PointT > &cloud_iterator, Eigen::Matrix< Scalar, 4, 1 > &centroid)
Compute the 3D (X-Y-Z) centroid of a set of points and return it as a 3D vector.
Definition: centroid.hpp:57
Defines functions, macros and traits for allocating and using memory.
IndicesAllocator<> Indices
Type used for indices in PCL.
Definition: types.h:133
Defines all the PCL and non-PCL macros used.
Helper functor structure for n-D centroid estimation.
Definition: centroid.h:898
NdCentroidFunctor(const PointT &p, Eigen::Matrix< Scalar, Eigen::Dynamic, 1 > &centroid)
Definition: centroid.h:901
typename traits::POD< PointT >::type Pod
Definition: centroid.h:899
A point structure representing Euclidean xyz coordinates, and the RGB color.
typename boost::fusion::result_of::as_vector< typename boost::mpl::filter_view< boost::mpl::vector< AccumulatorXYZ, AccumulatorNormal, AccumulatorCurvature, AccumulatorRGBA, AccumulatorIntensity, AccumulatorLabel >, IsAccumulatorCompatible< PointT > > >::type type