Point Cloud Library (PCL)
1.9.1dev

A generic class that computes the centroid of points fed to it. More...
#include <pcl/common/centroid.h>
Public Member Functions  
CentroidPoint ()=default  
void  add (const PointT &point) 
Add a new point to the centroid computation. More...  
template<typename PointOutT >  
void  get (PointOutT &point) const 
Retrieve the current centroid. More...  
std::size_t  getSize () const 
Get the total number of points that were added. More...  
A generic class that computes the centroid of points fed to it.
Here by "centroid" we denote not just the mean of 3D point coordinates, but also mean of values in the other data fields. The generalpurpose computeNDCentroid() function also implements this sort of functionality, however it does it in a "dumb" way, i.e. regardless of the semantics of the data inside a field it simply averages the values. In certain cases (e.g. for x
, y
, z
, intensity
fields) this behavior is reasonable, however in other cases (e.g. rgb
, rgba
, label
fields) this does not lead to meaningful results.
This class is capable of computing the centroid in a "smart" way, i.e. taking into account the meaning of the data inside fields. Currently the following fields are supported:
Data  Point fields  Algorithm 

XYZ  x , y , z  Average (separate for each field) 
Normal  normal_x , normal_y , normal_z  Average (separate for each field), resulting vector is normalized 
Curvature  curvature  Average 
Color  rgb or rgba  Average (separate for R, G, B, and alpha channels) 
Intensity  intensity  Average 
Label  label  Majority vote; if several labels have the same largest support then the smaller label wins 
The template parameter defines the type of points that may be accumulated with this class. This may be an arbitrary PCL point type, and centroid computation will happen only for the fields that are present in it and are supported.
Current centroid may be retrieved at any time using get(). Note that the function is templated on point type, so it is possible to fetch the centroid into a point type that differs from the type of points that are being accumulated. All the "extra" fields for which the centroid is not being calculated will be left untouched.
Example usage:
Definition at line 1021 of file centroid.h.

default 
void pcl::CentroidPoint< PointT >::add  (  const PointT &  point  ) 
Add a new point to the centroid computation.
In this function only the accumulators and point counter are updated, actual centroid computation does not happen until get() is called.
Definition at line 856 of file centroid.hpp.
Referenced by pcl::VoxelGrid< pcl::PointXYZRGBL >::applyFilter(), and pcl::computeCentroid().
void pcl::CentroidPoint< PointT >::get  (  PointOutT &  point  )  const 
Retrieve the current centroid.
Computation (division of accumulated values by the number of points and normalization where applicable) happens here. The result is not cached, so any subsequent call to this function will trigger recomputation.
If the number of accumulated points is zero, then the point will be left untouched.
Definition at line 865 of file centroid.hpp.
Referenced by pcl::VoxelGrid< pcl::PointXYZRGBL >::applyFilter(), and pcl::computeCentroid().

inline 
Get the total number of points that were added.
Definition at line 1049 of file centroid.h.
References pcl::computeCentroid(), and PCL_MAKE_ALIGNED_OPERATOR_NEW.
Referenced by pcl::computeCentroid().