Point Cloud Library (PCL)  1.7.2
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 #ifndef PCL_SEEDED_HUE_SEGMENTATION_H_
40 #define PCL_SEEDED_HUE_SEGMENTATION_H_
41 
42 #include <pcl/pcl_base.h>
43 #include <pcl/point_types_conversion.h>
44 #include <pcl/search/pcl_search.h>
45 
46 namespace pcl
47 {
48  //////////////////////////////////////////////////////////////////////////////////////////////////////////////////
49  /** \brief Decompose a region of space into clusters based on the Euclidean distance between points
50  * \param[in] cloud the point cloud message
51  * \param[in] tree the spatial locator (e.g., kd-tree) used for nearest neighbors searching
52  * \note the tree has to be created as a spatial locator on \a cloud
53  * \param[in] tolerance the spatial cluster tolerance as a measure in L2 Euclidean space
54  * \param[in] indices_in the cluster containing the seed point indices (as a vector of PointIndices)
55  * \param[out] indices_out
56  * \param[in] delta_hue
57  * \todo look how to make this templated!
58  * \ingroup segmentation
59  */
60  void
62  const boost::shared_ptr<search::Search<PointXYZRGB> > &tree,
63  float tolerance,
64  PointIndices &indices_in,
65  PointIndices &indices_out,
66  float delta_hue = 0.0);
67 
68  /** \brief Decompose a region of space into clusters based on the Euclidean distance between points
69  * \param[in] cloud the point cloud message
70  * \param[in] tree the spatial locator (e.g., kd-tree) used for nearest neighbors searching
71  * \note the tree has to be created as a spatial locator on \a cloud
72  * \param[in] tolerance the spatial cluster tolerance as a measure in L2 Euclidean space
73  * \param[in] indices_in the cluster containing the seed point indices (as a vector of PointIndices)
74  * \param[out] indices_out
75  * \param[in] delta_hue
76  * \todo look how to make this templated!
77  * \ingroup segmentation
78  */
79  void
81  const boost::shared_ptr<search::Search<PointXYZRGBL> > &tree,
82  float tolerance,
83  PointIndices &indices_in,
84  PointIndices &indices_out,
85  float delta_hue = 0.0);
86 
87  //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
88  //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
89  //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
90  /** \brief SeededHueSegmentation
91  * \author Koen Buys
92  * \ingroup segmentation
93  */
94  class SeededHueSegmentation: public PCLBase<PointXYZRGB>
95  {
97 
98  public:
102 
105 
108 
109  //////////////////////////////////////////////////////////////////////////////////////////////////////////////////
110  /** \brief Empty constructor. */
112  {};
113 
114  /** \brief Provide a pointer to the search object.
115  * \param[in] tree a pointer to the spatial search object.
116  */
117  inline void
118  setSearchMethod (const KdTreePtr &tree) { tree_ = tree; }
119 
120  /** \brief Get a pointer to the search method used. */
121  inline KdTreePtr
122  getSearchMethod () const { return (tree_); }
123 
124  /** \brief Set the spatial cluster tolerance as a measure in the L2 Euclidean space
125  * \param[in] tolerance the spatial cluster tolerance as a measure in the L2 Euclidean space
126  */
127  inline void
128  setClusterTolerance (double tolerance) { cluster_tolerance_ = tolerance; }
129 
130  /** \brief Get the spatial cluster tolerance as a measure in the L2 Euclidean space. */
131  inline double
133 
134  /** \brief Set the tollerance on the hue
135  * \param[in] delta_hue the new delta hue
136  */
137  inline void
138  setDeltaHue (float delta_hue) { delta_hue_ = delta_hue; }
139 
140  /** \brief Get the tolerance on the hue */
141  inline float
142  getDeltaHue () const { return (delta_hue_); }
143 
144  /** \brief Cluster extraction in a PointCloud given by <setInputCloud (), setIndices ()>
145  * \param[in] indices_in
146  * \param[out] indices_out
147  */
148  void
149  segment (PointIndices &indices_in, PointIndices &indices_out);
150 
151  protected:
152  // Members derived from the base class
153  using BasePCLBase::input_;
154  using BasePCLBase::indices_;
157 
158  /** \brief A pointer to the spatial search object. */
159  KdTreePtr tree_;
160 
161  /** \brief The spatial cluster tolerance as a measure in the L2 Euclidean space. */
163 
164  /** \brief The allowed difference on the hue*/
165  float delta_hue_;
166 
167  /** \brief Class getName method. */
168  virtual std::string getClassName () const { return ("seededHueSegmentation"); }
169  };
170 }
171 
172 #ifdef PCL_NO_PRECOMPILE
173 #include <pcl/segmentation/impl/seeded_hue_segmentation.hpp>
174 #endif
175 
176 #endif //#ifndef PCL_SEEDED_HUE_SEGMENTATION_H_
float delta_hue_
The allowed difference on the hue.
virtual std::string getClassName() const
Class getName method.
boost::shared_ptr< PointCloud< PointT > > Ptr
Definition: point_cloud.h:428
pcl::search::Search< PointXYZRGB >::Ptr KdTreePtr
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.
pcl::PointCloud< PointXYZRGB > PointCloud
IndicesPtr indices_
A pointer to the vector of point indices to use.
Definition: pcl_base.h:153
float getDeltaHue() const
Get the tolerance on the hue.
PointCloud::ConstPtr PointCloudConstPtr
void seededHueSegmentation(const PointCloud< PointXYZRGB > &cloud, const boost::shared_ptr< search::Search< PointXYZRGB > > &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 setDeltaHue(float delta_hue)
Set the tollerance on the hue.
bool initCompute()
This method should get called before starting the actual computation.
void segment(PointIndices &indices_in, PointIndices &indices_out)
Cluster extraction in a PointCloud given by
boost::shared_ptr< const PointCloud< PointT > > ConstPtr
Definition: point_cloud.h:429
boost::shared_ptr< pcl::search::Search< PointT > > Ptr
Definition: search.h:81
PCL base class.
Definition: pcl_base.h:68
KdTreePtr tree_
A pointer to the spatial search object.
SeededHueSegmentation()
Empty constructor.
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. ...
boost::shared_ptr< ::pcl::PointIndices > Ptr
Definition: PointIndices.h:22
PointIndices::ConstPtr PointIndicesConstPtr
pcl::search::Search< PointXYZRGB > KdTree
PointCloudConstPtr input_
The input point cloud dataset.
Definition: pcl_base.h:150
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.
boost::shared_ptr< ::pcl::PointIndices const > ConstPtr
Definition: PointIndices.h:23