region_growing.hpp
/*
* Software License Agreement (BSD License)
*
* Point Cloud Library (PCL) - www.pointclouds.org
*
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following
* disclaimer in the documentation and/or other materials provided
* with the distribution.
* * Neither the name of the copyright holder(s) nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
* Author : Sergey Ushakov
* Email : mine_all_mine@bk.ru
*
*/
#ifndef PCL_SEGMENTATION_REGION_GROWING_HPP_
#define PCL_SEGMENTATION_REGION_GROWING_HPP_
#include <pcl/segmentation/region_growing.h>
#include <pcl/search/search.h>
#include <pcl/search/kdtree.h>
#include <pcl/point_cloud.h>
#include <pcl/point_types.h>
#include <queue>
#include <list>
#include <cmath>
#include <time.h>
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
template <typename PointT, typename NormalT>
pcl::RegionGrowing<PointT, NormalT>::RegionGrowing () :
min_pts_per_cluster_ (1),
max_pts_per_cluster_ (std::numeric_limits<int>::max ()),
smooth_mode_flag_ (true),
curvature_flag_ (true),
residual_flag_ (false),
theta_threshold_ (30.0f / 180.0f * static_cast<float> (M_PI)),
residual_threshold_ (0.05f),
curvature_threshold_ (0.05f),
neighbour_number_ (30),
search_ (),
normals_ (),
point_neighbours_ (0),
point_labels_ (0),
normal_flag_ (true),
num_pts_in_segment_ (0),
clusters_ (0),
number_of_segments_ (0)
{
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
template <typename PointT, typename NormalT>
pcl::RegionGrowing<PointT, NormalT>::~RegionGrowing ()
{
if (search_ != 0)
search_.reset ();
if (normals_ != 0)
normals_.reset ();
point_neighbours_.clear ();
point_labels_.clear ();
num_pts_in_segment_.clear ();
clusters_.clear ();
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
template <typename PointT, typename NormalT> int
pcl::RegionGrowing<PointT, NormalT>::getMinClusterSize ()
{
return (min_pts_per_cluster_);
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
template <typename PointT, typename NormalT> void
pcl::RegionGrowing<PointT, NormalT>::setMinClusterSize (int min_cluster_size)
{
min_pts_per_cluster_ = min_cluster_size;
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
template <typename PointT, typename NormalT> int
pcl::RegionGrowing<PointT, NormalT>::getMaxClusterSize ()
{
return (max_pts_per_cluster_);
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
template <typename PointT, typename NormalT> void
pcl::RegionGrowing<PointT, NormalT>::setMaxClusterSize (int max_cluster_size)
{
max_pts_per_cluster_ = max_cluster_size;
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
template <typename PointT, typename NormalT> bool
pcl::RegionGrowing<PointT, NormalT>::getSmoothModeFlag () const
{
return (smooth_mode_flag_);
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
template <typename PointT, typename NormalT> void
pcl::RegionGrowing<PointT, NormalT>::setSmoothModeFlag (bool value)
{
smooth_mode_flag_ = value;
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
template <typename PointT, typename NormalT> bool
pcl::RegionGrowing<PointT, NormalT>::getCurvatureTestFlag () const
{
return (curvature_flag_);
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
template <typename PointT, typename NormalT> void
pcl::RegionGrowing<PointT, NormalT>::setCurvatureTestFlag (bool value)
{
curvature_flag_ = value;
if (curvature_flag_ == false && residual_flag_ == false)
residual_flag_ = true;
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
template <typename PointT, typename NormalT> bool
pcl::RegionGrowing<PointT, NormalT>::getResidualTestFlag () const
{
return (residual_flag_);
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
template <typename PointT, typename NormalT> void
pcl::RegionGrowing<PointT, NormalT>::setResidualTestFlag (bool value)
{
residual_flag_ = value;
if (curvature_flag_ == false && residual_flag_ == false)
curvature_flag_ = true;
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
template <typename PointT, typename NormalT> float
pcl::RegionGrowing<PointT, NormalT>::getSmoothnessThreshold () const
{
return (theta_threshold_);
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
template <typename PointT, typename NormalT> void
pcl::RegionGrowing<PointT, NormalT>::setSmoothnessThreshold (float theta)
{
theta_threshold_ = theta;
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
template <typename PointT, typename NormalT> float
pcl::RegionGrowing<PointT, NormalT>::getResidualThreshold () const
{
return (residual_threshold_);
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
template <typename PointT, typename NormalT> void
pcl::RegionGrowing<PointT, NormalT>::setResidualThreshold (float residual)
{
residual_threshold_ = residual;
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
template <typename PointT, typename NormalT> float
pcl::RegionGrowing<PointT, NormalT>::getCurvatureThreshold () const
{
return (curvature_threshold_);
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
template <typename PointT, typename NormalT> void
pcl::RegionGrowing<PointT, NormalT>::setCurvatureThreshold (float curvature)
{
curvature_threshold_ = curvature;
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
template <typename PointT, typename NormalT> unsigned int
pcl::RegionGrowing<PointT, NormalT>::getNumberOfNeighbours () const
{
return (neighbour_number_);
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
template <typename PointT, typename NormalT> void
pcl::RegionGrowing<PointT, NormalT>::setNumberOfNeighbours (unsigned int neighbour_number)
{
neighbour_number_ = neighbour_number;
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
template <typename PointT, typename NormalT> typename pcl::RegionGrowing<PointT, NormalT>::KdTreePtr
pcl::RegionGrowing<PointT, NormalT>::getSearchMethod () const
{
return (search_);
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
template <typename PointT, typename NormalT> void
pcl::RegionGrowing<PointT, NormalT>::setSearchMethod (const KdTreePtr& tree)
{
if (search_ != 0)
search_.reset ();
search_ = tree;
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
template <typename PointT, typename NormalT> typename pcl::RegionGrowing<PointT, NormalT>::NormalPtr
pcl::RegionGrowing<PointT, NormalT>::getInputNormals () const
{
return (normals_);
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
template <typename PointT, typename NormalT> void
pcl::RegionGrowing<PointT, NormalT>::setInputNormals (const NormalPtr& norm)
{
if (normals_ != 0)
normals_.reset ();
normals_ = norm;
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
template <typename PointT, typename NormalT> void
pcl::RegionGrowing<PointT, NormalT>::extract (std::vector <pcl::PointIndices>& clusters)
{
clusters_.clear ();
clusters.clear ();
point_neighbours_.clear ();
point_labels_.clear ();
num_pts_in_segment_.clear ();
number_of_segments_ = 0;
bool segmentation_is_possible = initCompute ();
if ( !segmentation_is_possible )
{
deinitCompute ();
return;
}
segmentation_is_possible = prepareForSegmentation ();
if ( !segmentation_is_possible )
{
deinitCompute ();
return;
}
findPointNeighbours ();
applySmoothRegionGrowingAlgorithm ();
assembleRegions ();
clusters.resize (clusters_.size ());
std::vector<pcl::PointIndices>::iterator cluster_iter_input = clusters.begin ();
for (std::vector<pcl::PointIndices>::const_iterator cluster_iter = clusters_.begin (); cluster_iter != clusters_.end (); cluster_iter++)
{
if ((static_cast<int> (cluster_iter->indices.size ()) >= min_pts_per_cluster_) &&
(static_cast<int> (cluster_iter->indices.size ()) <= max_pts_per_cluster_))
{
*cluster_iter_input = *cluster_iter;
cluster_iter_input++;
}
}
clusters_ = std::vector<pcl::PointIndices> (clusters.begin (), cluster_iter_input);
clusters.resize(clusters_.size());
deinitCompute ();
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
template <typename PointT, typename NormalT> bool
pcl::RegionGrowing<PointT, NormalT>::prepareForSegmentation ()
{
// if user forgot to pass point cloud or if it is empty
if ( input_->points.size () == 0 )
return (false);
// if user forgot to pass normals or the sizes of point and normal cloud are different
if ( normals_ == 0 || input_->points.size () != normals_->points.size () )
return (false);
// if residual test is on then we need to check if all needed parameters were correctly initialized
if (residual_flag_)
{
if (residual_threshold_ <= 0.0f)
return (false);
}
// if curvature test is on ...
// if (curvature_flag_)
// {
// in this case we do not need to check anything that related to it
// so we simply commented it
// }
// from here we check those parameters that are always valuable
if (neighbour_number_ == 0)
return (false);
// if user didn't set search method
if (!search_)
search_.reset (new pcl::search::KdTree<PointT>);
if (indices_)
{
if (indices_->empty ())
PCL_ERROR ("[pcl::RegionGrowing::prepareForSegmentation] Empty given indices!\n");
search_->setInputCloud (input_, indices_);
}
else
search_->setInputCloud (input_);
return (true);
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
template <typename PointT, typename NormalT> void
pcl::RegionGrowing<PointT, NormalT>::findPointNeighbours ()
{
int point_number = static_cast<int> (indices_->size ());
std::vector<int> neighbours;
std::vector<float> distances;
point_neighbours_.resize (input_->points.size (), neighbours);
if (input_->is_dense)
{
for (int i_point = 0; i_point < point_number; i_point++)
{
int point_index = (*indices_)[i_point];
neighbours.clear ();
search_->nearestKSearch (i_point, neighbour_number_, neighbours, distances);
point_neighbours_[point_index].swap (neighbours);
}
}
else
{
for (int i_point = 0; i_point < point_number; i_point++)
{
neighbours.clear ();
int point_index = (*indices_)[i_point];
if (!pcl::isFinite (input_->points[point_index]))
continue;
search_->nearestKSearch (i_point, neighbour_number_, neighbours, distances);
point_neighbours_[point_index].swap (neighbours);
}
}
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
template <typename PointT, typename NormalT> void
pcl::RegionGrowing<PointT, NormalT>::applySmoothRegionGrowingAlgorithm ()
{
int num_of_pts = static_cast<int> (indices_->size ());
point_labels_.resize (input_->points.size (), -1);
std::vector< std::pair<float, int> > point_residual;
std::pair<float, int> pair;
point_residual.resize (num_of_pts, pair);
if (normal_flag_ == true)
{
for (int i_point = 0; i_point < num_of_pts; i_point++)
{
int point_index = (*indices_)[i_point];
point_residual[i_point].first = normals_->points[point_index].curvature;
point_residual[i_point].second = point_index;
}
std::sort (point_residual.begin (), point_residual.end (), comparePair);
}
else
{
for (int i_point = 0; i_point < num_of_pts; i_point++)
{
int point_index = (*indices_)[i_point];
point_residual[i_point].first = 0;
point_residual[i_point].second = point_index;
}
}
int seed_counter = 0;
int seed = point_residual[seed_counter].second;
int segmented_pts_num = 0;
int number_of_segments = 0;
while (segmented_pts_num < num_of_pts)
{
int pts_in_segment;
pts_in_segment = growRegion (seed, number_of_segments);
segmented_pts_num += pts_in_segment;
num_pts_in_segment_.push_back (pts_in_segment);
number_of_segments++;
//find next point that is not segmented yet
for (int i_seed = seed_counter + 1; i_seed < num_of_pts; i_seed++)
{
int index = point_residual[i_seed].second;
if (point_labels_[index] == -1)
{
seed = index;
seed_counter = i_seed;
break;
}
}
}
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
template <typename PointT, typename NormalT> int
pcl::RegionGrowing<PointT, NormalT>::growRegion (int initial_seed, int segment_number)
{
std::queue<int> seeds;
seeds.push (initial_seed);
point_labels_[initial_seed] = segment_number;
int num_pts_in_segment = 1;
while (!seeds.empty ())
{
int curr_seed;
curr_seed = seeds.front ();
seeds.pop ();
size_t i_nghbr = 0;
while ( i_nghbr < neighbour_number_ && i_nghbr < point_neighbours_[curr_seed].size () )
{
int index = point_neighbours_[curr_seed][i_nghbr];
if (point_labels_[index] != -1)
{
i_nghbr++;
continue;
}
bool is_a_seed = false;
bool belongs_to_segment = validatePoint (initial_seed, curr_seed, index, is_a_seed);
if (belongs_to_segment == false)
{
i_nghbr++;
continue;
}
point_labels_[index] = segment_number;
num_pts_in_segment++;
if (is_a_seed)
{
seeds.push (index);
}
i_nghbr++;
}// next neighbour
}// next seed
return (num_pts_in_segment);
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
template <typename PointT, typename NormalT> bool
pcl::RegionGrowing<PointT, NormalT>::validatePoint (int initial_seed, int point, int nghbr, bool& is_a_seed) const
{
is_a_seed = true;
float cosine_threshold = cosf (theta_threshold_);
float data[4];
data[0] = input_->points[point].data[0];
data[1] = input_->points[point].data[1];
data[2] = input_->points[point].data[2];
data[3] = input_->points[point].data[3];
Eigen::Map<Eigen::Vector3f> initial_point (static_cast<float*> (data));
Eigen::Map<Eigen::Vector3f> initial_normal (static_cast<float*> (normals_->points[point].normal));
//check the angle between normals
if (smooth_mode_flag_ == true)
{
Eigen::Map<Eigen::Vector3f> nghbr_normal (static_cast<float*> (normals_->points[nghbr].normal));
float dot_product = fabsf (nghbr_normal.dot (initial_normal));
if (dot_product < cosine_threshold)
{
return (false);
}
}
else
{
Eigen::Map<Eigen::Vector3f> nghbr_normal (static_cast<float*> (normals_->points[nghbr].normal));
Eigen::Map<Eigen::Vector3f> initial_seed_normal (static_cast<float*> (normals_->points[initial_seed].normal));
float dot_product = fabsf (nghbr_normal.dot (initial_seed_normal));
if (dot_product < cosine_threshold)
return (false);
}
// check the curvature if needed
if (curvature_flag_ && normals_->points[nghbr].curvature > curvature_threshold_)
{
is_a_seed = false;
}
// check the residual if needed
float data_1[4];
data_1[0] = input_->points[nghbr].data[0];
data_1[1] = input_->points[nghbr].data[1];
data_1[2] = input_->points[nghbr].data[2];
data_1[3] = input_->points[nghbr].data[3];
Eigen::Map<Eigen::Vector3f> nghbr_point (static_cast<float*> (data_1));
float residual = fabsf (initial_normal.dot (initial_point - nghbr_point));
if (residual_flag_ && residual > residual_threshold_)
is_a_seed = false;
return (true);
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
template <typename PointT, typename NormalT> void
pcl::RegionGrowing<PointT, NormalT>::assembleRegions ()
{
int number_of_segments = static_cast<int> (num_pts_in_segment_.size ());
int number_of_points = static_cast<int> (input_->points.size ());
pcl::PointIndices segment;
clusters_.resize (number_of_segments, segment);
for (int i_seg = 0; i_seg < number_of_segments; i_seg++)
{
clusters_[i_seg].indices.resize ( num_pts_in_segment_[i_seg], 0);
}
std::vector<int> counter;
counter.resize (number_of_segments, 0);
for (int i_point = 0; i_point < number_of_points; i_point++)
{
int segment_index = point_labels_[i_point];
if (segment_index != -1)
{
int point_index = counter[segment_index];
clusters_[segment_index].indices[point_index] = i_point;
counter[segment_index] = point_index + 1;
}
}
number_of_segments_ = number_of_segments;
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
template <typename PointT, typename NormalT> void
pcl::RegionGrowing<PointT, NormalT>::getSegmentFromPoint (int index, pcl::PointIndices& cluster)
{
cluster.indices.clear ();
bool segmentation_is_possible = initCompute ();
if ( !segmentation_is_possible )
{
deinitCompute ();
return;
}
// first of all we need to find out if this point belongs to cloud
bool point_was_found = false;
int number_of_points = static_cast <int> (indices_->size ());
for (int point = 0; point < number_of_points; point++)
if ( (*indices_)[point] == index)
{
point_was_found = true;
break;
}
if (point_was_found)
{
if (clusters_.empty ())
{
point_neighbours_.clear ();
point_labels_.clear ();
num_pts_in_segment_.clear ();
number_of_segments_ = 0;
segmentation_is_possible = prepareForSegmentation ();
if ( !segmentation_is_possible )
{
deinitCompute ();
return;
}
findPointNeighbours ();
applySmoothRegionGrowingAlgorithm ();
assembleRegions ();
}
// if we have already made the segmentation, then find the segment
// to which this point belongs
std::vector <pcl::PointIndices>::iterator i_segment;
for (i_segment = clusters_.begin (); i_segment != clusters_.end (); i_segment++)
{
bool segment_was_found = false;
for (size_t i_point = 0; i_point < i_segment->indices.size (); i_point++)
{
if (i_segment->indices[i_point] == index)
{
segment_was_found = true;
cluster.indices.clear ();
cluster.indices.reserve (i_segment->indices.size ());
std::copy (i_segment->indices.begin (), i_segment->indices.end (), std::back_inserter (cluster.indices));
break;
}
}
if (segment_was_found)
{
break;
}
}// next segment
}// end if point was found
deinitCompute ();
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
template <typename PointT, typename NormalT> pcl::PointCloud<pcl::PointXYZRGB>::Ptr
pcl::RegionGrowing<PointT, NormalT>::getColoredCloud ()
{
pcl::PointCloud<pcl::PointXYZRGB>::Ptr colored_cloud;
if (!clusters_.empty ())
{
colored_cloud = (new pcl::PointCloud<pcl::PointXYZRGB>)->makeShared ();
srand (static_cast<unsigned int> (time (0)));
std::vector<unsigned char> colors;
for (size_t i_segment = 0; i_segment < clusters_.size (); i_segment++)
{
colors.push_back (static_cast<unsigned char> (rand () % 256));
colors.push_back (static_cast<unsigned char> (rand () % 256));
colors.push_back (static_cast<unsigned char> (rand () % 256));
}
colored_cloud->width = input_->width;
colored_cloud->height = input_->height;
colored_cloud->is_dense = input_->is_dense;
for (size_t i_point = 0; i_point < input_->points.size (); i_point++)
{
pcl::PointXYZRGB point;
point.x = *(input_->points[i_point].data);
point.y = *(input_->points[i_point].data + 1);
point.z = *(input_->points[i_point].data + 2);
point.r = 255;
point.g = 0;
point.b = 0;
colored_cloud->points.push_back (point);
}
std::vector< pcl::PointIndices >::iterator i_segment;
int next_color = 0;
for (i_segment = clusters_.begin (); i_segment != clusters_.end (); i_segment++)
{
std::vector<int>::iterator i_point;
for (i_point = i_segment->indices.begin (); i_point != i_segment->indices.end (); i_point++)
{
int index;
index = *i_point;
colored_cloud->points[index].r = colors[3 * next_color];
colored_cloud->points[index].g = colors[3 * next_color + 1];
colored_cloud->points[index].b = colors[3 * next_color + 2];
}
next_color++;
}
}
return (colored_cloud);
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
template <typename PointT, typename NormalT> pcl::PointCloud<pcl::PointXYZRGBA>::Ptr
pcl::RegionGrowing<PointT, NormalT>::getColoredCloudRGBA ()
{
pcl::PointCloud<pcl::PointXYZRGBA>::Ptr colored_cloud;
if (!clusters_.empty ())
{
colored_cloud = (new pcl::PointCloud<pcl::PointXYZRGBA>)->makeShared ();
srand (static_cast<unsigned int> (time (0)));
std::vector<unsigned char> colors;
for (size_t i_segment = 0; i_segment < clusters_.size (); i_segment++)
{
colors.push_back (static_cast<unsigned char> (rand () % 256));
colors.push_back (static_cast<unsigned char> (rand () % 256));
colors.push_back (static_cast<unsigned char> (rand () % 256));
}
colored_cloud->width = input_->width;
colored_cloud->height = input_->height;
colored_cloud->is_dense = input_->is_dense;
for (size_t i_point = 0; i_point < input_->points.size (); i_point++)
{
pcl::PointXYZRGBA point;
point.x = *(input_->points[i_point].data);
point.y = *(input_->points[i_point].data + 1);
point.z = *(input_->points[i_point].data + 2);
point.r = 255;
point.g = 0;
point.b = 0;
point.a = 0;
colored_cloud->points.push_back (point);
}
std::vector< pcl::PointIndices >::iterator i_segment;
int next_color = 0;
for (i_segment = clusters_.begin (); i_segment != clusters_.end (); i_segment++)
{
std::vector<int>::iterator i_point;
for (i_point = i_segment->indices.begin (); i_point != i_segment->indices.end (); i_point++)
{
int index;
index = *i_point;
colored_cloud->points[index].r = colors[3 * next_color];
colored_cloud->points[index].g = colors[3 * next_color + 1];
colored_cloud->points[index].b = colors[3 * next_color + 2];
}
next_color++;
}
}
return (colored_cloud);
}
#define PCL_INSTANTIATE_RegionGrowing(T) template class pcl::RegionGrowing<T, pcl::Normal>;
#endif // PCL_SEGMENTATION_REGION_GROWING_HPP_
pcl::RegionGrowing::theta_threshold_
float theta_threshold_
Thershold used for testing the smoothness between points.
Definition: region_growing.h:298
pcl::RegionGrowing::residual_threshold_
float residual_threshold_
Thershold used in residual test.
Definition: region_growing.h:301
pcl::RegionGrowing::curvature_threshold_
float curvature_threshold_
Thershold used in curvature test.
Definition: region_growing.h:304
pcl::RegionGrowing::getNumberOfNeighbours
unsigned int getNumberOfNeighbours() const
Returns the number of nearest neighbours used for KNN.
Definition: region_growing.hpp:213
pcl::search::KdTree< PointT >
pcl::isFinite
bool isFinite(const PointT &pt)
Tests if the 3D components of a point are all finite param[in] pt point to be tested return true if f...
Definition: point_tests.h:54
pcl::RegionGrowing::getResidualThreshold
float getResidualThreshold() const
Returns residual threshold.
Definition: region_growing.hpp:185
pcl::PointCloud::points
std::vector< PointT, Eigen::aligned_allocator< PointT > > points
The point data.
Definition: point_cloud.h:410
pcl::RegionGrowing::setSmoothModeFlag
void setSmoothModeFlag(bool value)
This function allows to turn on/off the smoothness constraint.
Definition: region_growing.hpp:130
pcl::RegionGrowing::prepareForSegmentation
virtual bool prepareForSegmentation()
This method simply checks if it is possible to execute the segmentation algorithm with the current se...
Definition: region_growing.hpp:308
pcl::RegionGrowing::setMaxClusterSize
void setMaxClusterSize(int max_cluster_size)
Set the maximum number of points that a cluster needs to contain in order to be considered valid...
Definition: region_growing.hpp:116
pcl::RegionGrowing::setMinClusterSize
void setMinClusterSize(int min_cluster_size)
Set the minimum number of points that a cluster needs to contain in order to be considered valid...
Definition: region_growing.hpp:102
pcl::RegionGrowing::num_pts_in_segment_
std::vector< int > num_pts_in_segment_
Tells how much points each segment contains.
Definition: region_growing.h:327
pcl::RegionGrowing::neighbour_number_
unsigned int neighbour_number_
Number of neighbours to find.
Definition: region_growing.h:307
pcl::RegionGrowing::getSearchMethod
KdTreePtr getSearchMethod() const
Returns the pointer to the search method that is used for KNN.
Definition: region_growing.hpp:227
pcl::RegionGrowing::RegionGrowing
RegionGrowing()
Constructor that sets default values for member variables.
Definition: region_growing.hpp:57
pcl::RegionGrowing::extract
virtual void extract(std::vector< pcl::PointIndices > &clusters)
This method launches the segmentation algorithm and returns the clusters that were obtained during th...
Definition: region_growing.hpp:261
pcl::PCLBase::indices_
IndicesPtr indices_
A pointer to the vector of point indices to use.
Definition: pcl_base.h:153
pcl::RegionGrowing::getMinClusterSize
int getMinClusterSize()
Get the minimum number of points that a cluster needs to contain in order to be considered valid...
Definition: region_growing.hpp:95
pcl::RegionGrowing::~RegionGrowing
virtual ~RegionGrowing()
This destructor destroys the cloud, normals and search method used for finding KNN.
Definition: region_growing.hpp:80
pcl::RegionGrowing::residual_flag_
bool residual_flag_
If set to true then residual test will be done during segmentation.
Definition: region_growing.h:295
std
Definition: multi_grid_octree_data.hpp:45
pcl::RegionGrowing::setCurvatureThreshold
void setCurvatureThreshold(float curvature)
Allows to set curvature threshold used for testing the points.
Definition: region_growing.hpp:206
pcl::PointIndices::indices
std::vector< int > indices
Definition: PointIndices.h:19
pcl::RegionGrowing::min_pts_per_cluster_
int min_pts_per_cluster_
Stores the minimum number of points that a cluster needs to contain in order to be considered valid...
Definition: region_growing.h:283
pcl::RegionGrowing::growRegion
int growRegion(int initial_seed, int segment_number)
This method grows a segment for the given seed point.
Definition: region_growing.hpp:444
pcl::RegionGrowing::setNumberOfNeighbours
void setNumberOfNeighbours(unsigned int neighbour_number)
Allows to set the number of neighbours.
Definition: region_growing.hpp:220
pcl::PointXYZRGBA
A point structure representing Euclidean xyz coordinates, and the RGBA color.
Definition: point_types.hpp:539
pcl::RegionGrowing::setSmoothnessThreshold
void setSmoothnessThreshold(float theta)
Allows to set smoothness threshold used for testing the points.
Definition: region_growing.hpp:178
pcl::PointCloud::height
uint32_t height
The point cloud height (if organized as an image-structure).
Definition: point_cloud.h:415
pcl::RegionGrowing::number_of_segments_
int number_of_segments_
Stores the number of segments.
Definition: region_growing.h:333
pcl::PCLBase::initCompute
bool initCompute()
This method should get called before starting the actual computation.
Definition: pcl_base.hpp:139
pcl::RegionGrowing::normals_
NormalPtr normals_
Contains normals of the points that will be segmented.
Definition: region_growing.h:313
pcl::PointCloud::Ptr
boost::shared_ptr< PointCloud< PointT > > Ptr
Definition: point_cloud.h:428
pcl::RegionGrowing::getSmoothnessThreshold
float getSmoothnessThreshold() const
Returns smoothness threshold.
Definition: region_growing.hpp:171
pcl::RegionGrowing::max_pts_per_cluster_
int max_pts_per_cluster_
Stores the maximum number of points that a cluster needs to contain in order to be considered valid...
Definition: region_growing.h:286
pcl::PointCloud::width
uint32_t width
The point cloud width (if organized as an image-structure).
Definition: point_cloud.h:413
pcl::RegionGrowing::KdTreePtr
KdTree::Ptr KdTreePtr
Definition: region_growing.h:66
pcl::PointIndices
Definition: PointIndices.h:12
pcl::comparePair
bool comparePair(std::pair< float, int > i, std::pair< float, int > j)
This function is used as a comparator for sorting.
Definition: region_growing.h:341
pcl::RegionGrowing::setResidualTestFlag
virtual void setResidualTestFlag(bool value)
Allows to turn on/off the residual test.
Definition: region_growing.hpp:161
pcl::RegionGrowing::clusters_
std::vector< pcl::PointIndices > clusters_
After the segmentation it will contain the segments.
Definition: region_growing.h:330
point_types.h
Defines all the PCL implemented PointT point type structures.
pcl::RegionGrowing::findPointNeighbours
virtual void findPointNeighbours()
This method finds KNN for each point and saves them to the array because the algorithm needs to find ...
Definition: region_growing.hpp:354
pcl::RegionGrowing::getColoredCloud
pcl::PointCloud< pcl::PointXYZRGB >::Ptr getColoredCloud()
If the cloud was successfully segmented, then function returns colored cloud.
Definition: region_growing.hpp:652
pcl::RegionGrowing::getInputNormals
NormalPtr getInputNormals() const
Returns normals.
Definition: region_growing.hpp:244
pcl::RegionGrowing::getCurvatureThreshold
float getCurvatureThreshold() const
Returns curvature threshold.
Definition: region_growing.hpp:199
pcl::RegionGrowing::validatePoint
virtual bool validatePoint(int initial_seed, int point, int nghbr, bool &is_a_seed) const
This function is checking if the point with index &#39;nghbr&#39; belongs to the segment. ...
Definition: region_growing.hpp:494
pcl::RegionGrowing::setInputNormals
void setInputNormals(const NormalPtr &norm)
This method sets the normals.
Definition: region_growing.hpp:251
pcl::RegionGrowing::getSegmentFromPoint
virtual void getSegmentFromPoint(int index, pcl::PointIndices &cluster)
For a given point this function builds a segment to which it belongs and returns this segment...
Definition: region_growing.hpp:582
pcl::RegionGrowing::NormalPtr
Normal::Ptr NormalPtr
Definition: region_growing.h:68
pcl::PCLBase::deinitCompute
bool deinitCompute()
This method should get called after finishing the actual computation.
Definition: pcl_base.hpp:174
pcl::RegionGrowing::getResidualTestFlag
bool getResidualTestFlag() const
Returns the flag that signalize if the residual test is turned on/off.
Definition: region_growing.hpp:154
pcl::RegionGrowing::point_labels_
std::vector< int > point_labels_
Point labels that tells to which segment each point belongs.
Definition: region_growing.h:319
pcl::RegionGrowing::getColoredCloudRGBA
pcl::PointCloud< pcl::PointXYZRGBA >::Ptr getColoredCloudRGBA()
If the cloud was successfully segmented, then function returns colored cloud.
Definition: region_growing.hpp:706
pcl::PointCloud< pcl::PointXYZRGB >
pcl::RegionGrowing::getSmoothModeFlag
bool getSmoothModeFlag() const
Returns the flag value.
Definition: region_growing.hpp:123
pcl::RegionGrowing::applySmoothRegionGrowingAlgorithm
void applySmoothRegionGrowingAlgorithm()
This function implements the algorithm described in the article "Segmentation of point clouds using s...
Definition: region_growing.hpp:387
pcl::RegionGrowing::smooth_mode_flag_
bool smooth_mode_flag_
Flag that signalizes if the smoothness constraint will be used.
Definition: region_growing.h:289
pcl::RegionGrowing::getMaxClusterSize
int getMaxClusterSize()
Get the maximum number of points that a cluster needs to contain in order to be considered valid...
Definition: region_growing.hpp:109
pcl::RegionGrowing::setResidualThreshold
void setResidualThreshold(float residual)
Allows to set residual threshold used for testing the points.
Definition: region_growing.hpp:192
pcl::RegionGrowing::assembleRegions
void assembleRegions()
This function simply assembles the regions from list of point labels.
Definition: region_growing.hpp:550
pcl::PointCloud::is_dense
bool is_dense
True if no points are invalid (e.g., have NaN or Inf values).
Definition: point_cloud.h:418
pcl::RegionGrowing::normal_flag_
bool normal_flag_
If set to true then normal/smoothness test will be done during segmentation.
Definition: region_growing.h:324
pcl::RegionGrowing::search_
KdTreePtr search_
Serch method that will be used for KNN.
Definition: region_growing.h:310
pcl::PCLBase::input_
PointCloudConstPtr input_
The input point cloud dataset.
Definition: pcl_base.h:150
pcl::RegionGrowing::setCurvatureTestFlag
virtual void setCurvatureTestFlag(bool value)
Allows to turn on/off the curvature test.
Definition: region_growing.hpp:144
pcl::PointXYZRGB
A point structure representing Euclidean xyz coordinates, and the RGB color.
Definition: point_types.hpp:606
pcl::RegionGrowing::getCurvatureTestFlag
bool getCurvatureTestFlag() const
Returns the flag that signalize if the curvature test is turned on/off.
Definition: region_growing.hpp:137
pcl::RegionGrowing::setSearchMethod
void setSearchMethod(const KdTreePtr &tree)
Allows to set search method that will be used for finding KNN.
Definition: region_growing.hpp:234
pcl::RegionGrowing::curvature_flag_
bool curvature_flag_
If set to true then curvature test will be done during segmentation.
Definition: region_growing.h:292
pcl::RegionGrowing::point_neighbours_
std::vector< std::vector< int > > point_neighbours_
Contains neighbours of each point.
Definition: region_growing.h:316