Point Cloud Library (PCL)  1.14.0-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 ()=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...
 

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:

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:

// 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
A point structure representing Euclidean xyz coordinates.
A point structure representing Euclidean xyz coordinates, and the RGB color.
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 1076 of file centroid.h.

Constructor & Destructor Documentation

◆ CentroidPoint()

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

Member Function Documentation

◆ add()

template<typename PointT >
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 1164 of file centroid.hpp.

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

◆ get()

template<typename PointT >
template<typename PointOutT >
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 re-computation.

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

Definition at line 1173 of file centroid.hpp.

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

◆ getSize()

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

Get the total number of points that were added.

Definition at line 1104 of file centroid.h.


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