39 #ifndef PCL_SEGMENTATION_IMPL_SEEDED_HUE_SEGMENTATION_H_
40 #define PCL_SEGMENTATION_IMPL_SEEDED_HUE_SEGMENTATION_H_
42 #include <pcl/segmentation/seeded_hue_segmentation.h>
43 #include <pcl/console/print.h>
44 #include <pcl/search/auto.h>
57 PCL_ERROR(
"[pcl::seededHueSegmentation] Tree built for a different point cloud "
58 "dataset (%zu) than the input cloud (%zu)!\n",
60 static_cast<std::size_t
>(cloud.
size()));
66 std::vector<bool> processed (cloud.
size (),
false);
69 std::vector<float> nn_distances;
72 for (
const auto &i : indices_in.
indices)
81 seed_queue.push_back (i);
88 while (sq_idx <
static_cast<int> (seed_queue.size ()))
90 int ret = tree->
radiusSearch (seed_queue[sq_idx], tolerance, nn_indices, nn_distances, std::numeric_limits<int>::max());
92 PCL_ERROR(
"[pcl::seededHueSegmentation] radiusSearch returned error code -1\n");
100 for (std::size_t j = nn_start_idx; j < nn_indices.size (); ++j)
102 if (processed[nn_indices[j]])
106 p_l = cloud[nn_indices[j]];
110 if (std::fabs(h_l.
h - h.
h) < delta_hue)
112 seed_queue.push_back (nn_indices[j]);
113 processed[nn_indices[j]] =
true;
120 for (
const auto &l : seed_queue)
121 indices_out.
indices.push_back(l);
124 std::sort (indices_out.
indices.begin (), indices_out.
indices.end ());
137 PCL_ERROR(
"[pcl::seededHueSegmentation] Tree built for a different point cloud "
138 "dataset (%zu) than the input cloud (%zu)!\n",
140 static_cast<std::size_t
>(cloud.
size()));
146 std::vector<bool> processed (cloud.
size (),
false);
149 std::vector<float> nn_distances;
152 for (
const auto &i : indices_in.
indices)
161 seed_queue.push_back (i);
168 while (sq_idx <
static_cast<int> (seed_queue.size ()))
170 int ret = tree->
radiusSearch (seed_queue[sq_idx], tolerance, nn_indices, nn_distances, std::numeric_limits<int>::max());
172 PCL_ERROR(
"[pcl::seededHueSegmentation] radiusSearch returned error code -1\n");
179 for (std::size_t j = nn_start_idx; j < nn_indices.size (); ++j)
181 if (processed[nn_indices[j]])
185 p_l = cloud[nn_indices[j]];
189 if (std::fabs(h_l.
h - h.
h) < delta_hue)
191 seed_queue.push_back (nn_indices[j]);
192 processed[nn_indices[j]] =
true;
199 for (
const auto &l : seed_queue)
200 indices_out.
indices.push_back(l);
203 std::sort (indices_out.
indices.begin (), indices_out.
indices.end ());
PointCloudConstPtr input_
The input point cloud dataset.
IndicesPtr indices_
A pointer to the vector of point indices to use.
bool initCompute()
This method should get called before starting the actual computation.
bool deinitCompute()
This method should get called after finishing the actual computation.
PointCloud represents the base class in PCL for storing collections of 3D points.
KdTreePtr tree_
A pointer to the spatial search object.
float delta_hue_
The allowed difference on the hue.
double cluster_tolerance_
The spatial cluster tolerance as a measure in the L2 Euclidean space.
void segment(PointIndices &indices_in, PointIndices &indices_out)
Cluster extraction in a PointCloud given by <setInputCloud (), setIndices ()>
virtual bool getSortedResults()
Gets whether the results should be sorted (ascending in the distance) or not Otherwise the results ma...
shared_ptr< pcl::search::Search< PointT > > Ptr
virtual PointCloudConstPtr getInputCloud() const
Get a pointer to the input point cloud dataset.
virtual int radiusSearch(const PointT &point, double radius, Indices &k_indices, std::vector< float > &k_sqr_distances, unsigned int max_nn=0) const =0
Search for all the nearest neighbors of the query point in a given radius.
void seededHueSegmentation(const PointCloud< PointXYZRGB > &cloud, const search::Search< PointXYZRGB >::Ptr &tree, float tolerance, PointIndices &indices_in, PointIndices &indices_out, float delta_hue=0.0)
Decompose a region of space into clusters based on the Euclidean distance between points.
@ radius_search
The search method will mainly be used for radiusSearch.
void PointXYZRGBtoXYZHSV(const PointXYZRGB &in, PointXYZHSV &out)
Convert a XYZRGB point type to a XYZHSV.
IndicesAllocator<> Indices
Type used for indices in PCL.
A point structure representing Euclidean xyz coordinates, and the RGB color.