Point Cloud Library (PCL)  1.9.1-dev
List of all members | Public Member Functions
pcl::CentroidPoint< PointT > Class Template Reference

A generic class that computes the centroid of points fed to it. More...

#include <pcl/common/centroid.h>

Public Member Functions

 CentroidPoint ()
 
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...
 
size_t getSize () const
 Get the total number of points that were added. More...
 

Detailed Description

template<typename PointT>
class pcl::CentroidPoint< PointT >

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 general-purpose 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:

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:

// Create and accumulate points
CentroidPoint<pcl::PointXYZ> centroid;
centroid.add (pcl::PointXYZ (1, 2, 3);
centroid.add (pcl::PointXYZ (5, 6, 7);
// Fetch centroid using `get()`
centroid.get (c1);
// The expected result is: c1.x == 3, c1.y == 4, c1.z == 5
// It is also okay to use `get()` with a different point type
centroid.get (c2);
// The expected result is: c2.x == 3, c2.y == 4, c2.z == 5,
// and c2.rgb is left untouched
Note
Assumes that the points being inserted are valid.
This class template can be successfully instantiated for any PCL point type. Of course, each of the field averages is computed only if the point type has the corresponding field.
Author
Sergey Alexandrov

Definition at line 1036 of file centroid.h.

Constructor & Destructor Documentation

template<typename PointT>
pcl::CentroidPoint< PointT >::CentroidPoint ( )
inline

Definition at line 1041 of file centroid.h.

Member Function Documentation

template<typename PointT>
void pcl::CentroidPoint< PointT >::add ( const PointT point)
inline

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 1051 of file centroid.h.

Referenced by pcl::VoxelGrid< PointT >::applyFilter(), and pcl::computeCentroid().

template<typename PointT>
template<typename PointOutT >
void pcl::CentroidPoint< PointT >::get ( PointOutT &  point) const
inline

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 re-computation.

If the number of accumulated points is zero, then the point will be left untouched.

Definition at line 1068 of file centroid.h.

Referenced by pcl::VoxelGrid< PointT >::applyFilter(), and pcl::computeCentroid().

template<typename PointT>
size_t pcl::CentroidPoint< PointT >::getSize ( ) const
inline

Get the total number of points that were added.

Definition at line 1082 of file centroid.h.

References pcl::computeCentroid().

Referenced by pcl::computeCentroid().


The documentation for this class was generated from the following file: