Point Cloud Library (PCL)  1.14.1
seeded_hue_segmentation.h
1 /*
2  * Software License Agreement (BSD License)
3  *
4  * Point Cloud Library (PCL) - www.pointclouds.org
5  * Copyright (c) 2010-2011, Willow Garage, Inc.
6  *
7  * All rights reserved.
8  *
9  * Redistribution and use in source and binary forms, with or without
10  * modification, are permitted provided that the following conditions
11  * are met:
12  *
13  * * Redistributions of source code must retain the above copyright
14  * notice, this list of conditions and the following disclaimer.
15  * * Redistributions in binary form must reproduce the above
16  * copyright notice, this list of conditions and the following
17  * disclaimer in the documentation and/or other materials provided
18  * with the distribution.
19  * * Neither the name of the copyright holder(s) nor the names of its
20  * contributors may be used to endorse or promote products derived
21  * from this software without specific prior written permission.
22  *
23  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
24  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
25  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
26  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
27  * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
28  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
29  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
30  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
31  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
33  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
34  * POSSIBILITY OF SUCH DAMAGE.
35  *
36  * $id: $
37  */
38 
39 #pragma once
40 
41 #include <pcl/pcl_base.h>
42 #include <pcl/point_types_conversion.h>
43 #include <pcl/search/search.h> // for Search
44 
45 namespace pcl
46 {
47  //////////////////////////////////////////////////////////////////////////////////////////////////////////////////
48  /** \brief Decompose a region of space into clusters based on the Euclidean distance between points
49  * \param[in] cloud the point cloud message
50  * \param[in] tree the spatial locator (e.g., kd-tree) used for nearest neighbors searching
51  * \note the tree has to be created as a spatial locator on \a cloud
52  * \param[in] tolerance the spatial cluster tolerance as a measure in L2 Euclidean space
53  * \param[in] indices_in the cluster containing the seed point indices (as a vector of PointIndices)
54  * \param[out] indices_out
55  * \param[in] delta_hue
56  * \todo look how to make this templated!
57  * \ingroup segmentation
58  */
59  void
62  float tolerance,
63  PointIndices &indices_in,
64  PointIndices &indices_out,
65  float delta_hue = 0.0);
66 
67  /** \brief Decompose a region of space into clusters based on the Euclidean distance between points
68  * \param[in] cloud the point cloud message
69  * \param[in] tree the spatial locator (e.g., kd-tree) used for nearest neighbors searching
70  * \note the tree has to be created as a spatial locator on \a cloud
71  * \param[in] tolerance the spatial cluster tolerance as a measure in L2 Euclidean space
72  * \param[in] indices_in the cluster containing the seed point indices (as a vector of PointIndices)
73  * \param[out] indices_out
74  * \param[in] delta_hue
75  * \todo look how to make this templated!
76  * \ingroup segmentation
77  */
78  void
80  const search::Search<PointXYZRGBL>::Ptr &tree,
81  float tolerance,
82  PointIndices &indices_in,
83  PointIndices &indices_out,
84  float delta_hue = 0.0);
85 
86  //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
87  //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
88  //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
89  /** \brief SeededHueSegmentation
90  * \author Koen Buys
91  * \ingroup segmentation
92  */
93  class SeededHueSegmentation: public PCLBase<PointXYZRGB>
94  {
96 
97  public:
101 
104 
107 
108  //////////////////////////////////////////////////////////////////////////////////////////////////////////////////
109  /** \brief Empty constructor. */
110  SeededHueSegmentation () = default;
111 
112  /** \brief Provide a pointer to the search object.
113  * \param[in] tree a pointer to the spatial search object.
114  */
115  inline void
116  setSearchMethod (const KdTreePtr &tree) { tree_ = tree; }
117 
118  /** \brief Get a pointer to the search method used. */
119  inline KdTreePtr
120  getSearchMethod () const { return (tree_); }
121 
122  /** \brief Set the spatial cluster tolerance as a measure in the L2 Euclidean space
123  * \param[in] tolerance the spatial cluster tolerance as a measure in the L2 Euclidean space
124  */
125  inline void
126  setClusterTolerance (double tolerance) { cluster_tolerance_ = tolerance; }
127 
128  /** \brief Get the spatial cluster tolerance as a measure in the L2 Euclidean space. */
129  inline double
131 
132  /** \brief Set the tolerance on the hue
133  * \param[in] delta_hue the new delta hue
134  */
135  inline void
136  setDeltaHue (float delta_hue) { delta_hue_ = delta_hue; }
137 
138  /** \brief Get the tolerance on the hue */
139  inline float
140  getDeltaHue () const { return (delta_hue_); }
141 
142  /** \brief Cluster extraction in a PointCloud given by <setInputCloud (), setIndices ()>
143  * \param[in] indices_in
144  * \param[out] indices_out
145  */
146  void
147  segment (PointIndices &indices_in, PointIndices &indices_out);
148 
149  protected:
150  // Members derived from the base class
151  using BasePCLBase::input_;
152  using BasePCLBase::indices_;
155 
156  /** \brief A pointer to the spatial search object. */
157  KdTreePtr tree_{nullptr};
158 
159  /** \brief The spatial cluster tolerance as a measure in the L2 Euclidean space. */
160  double cluster_tolerance_{0.0};
161 
162  /** \brief The allowed difference on the hue*/
163  float delta_hue_{0.0f};
164 
165  /** \brief Class getName method. */
166  virtual std::string getClassName () const { return ("seededHueSegmentation"); }
167  };
168 }
169 
170 #ifdef PCL_NO_PRECOMPILE
171 #include <pcl/segmentation/impl/seeded_hue_segmentation.hpp>
172 #endif
float delta_hue_
The allowed difference on the hue.
virtual std::string getClassName() const
Class getName method.
SeededHueSegmentation()=default
Empty constructor.
PointIndices::ConstPtr PointIndicesConstPtr
pcl::search::Search< PointXYZRGB >::Ptr KdTreePtr
shared_ptr< PointCloud< PointT > > Ptr
Definition: point_cloud.h:413
KdTreePtr getSearchMethod() const
Get a pointer to the search method used.
void setClusterTolerance(double tolerance)
Set the spatial cluster tolerance as a measure in the L2 Euclidean space.
void setSearchMethod(const KdTreePtr &tree)
Provide a pointer to the search object.
IndicesPtr indices_
A pointer to the vector of point indices to use.
Definition: pcl_base.h:150
float getDeltaHue() const
Get the tolerance on the hue.
void setDeltaHue(float delta_hue)
Set the tolerance on the hue.
bool initCompute()
This method should get called before starting the actual computation.
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...
void segment(PointIndices &indices_in, PointIndices &indices_out)
Cluster extraction in a PointCloud given by
shared_ptr< ::pcl::PointIndices > Ptr
Definition: PointIndices.h:13
PCL base class.
Definition: pcl_base.h:69
KdTreePtr tree_
A pointer to the spatial search object.
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. ...
Definition: distances.h:55
PointCloud::ConstPtr PointCloudConstPtr
shared_ptr< const ::pcl::PointIndices > ConstPtr
Definition: PointIndices.h:14
shared_ptr< const PointCloud< PointT > > ConstPtr
Definition: point_cloud.h:414
PointCloudConstPtr input_
The input point cloud dataset.
Definition: pcl_base.h:147
shared_ptr< pcl::search::Search< PointXYZRGB > > Ptr
Definition: search.h:81
double cluster_tolerance_
The spatial cluster tolerance as a measure in the L2 Euclidean space.
double getClusterTolerance() const
Get the spatial cluster tolerance as a measure in the L2 Euclidean space.