Point Cloud Library (PCL)  1.12.1-dev
gpu_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 Willow Garage, Inc. 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 
40 #pragma once
41 
42 #include <pcl/PointIndices.h>
43 #include <pcl/pcl_macros.h>
44 #include <pcl/point_cloud.h>
45 #include <pcl/point_types.h>
46 
47 namespace pcl {
48 namespace gpu {
49 void
51  const pcl::gpu::Octree::Ptr& tree,
52  float tolerance,
53  PointIndices& clusters_in,
54  PointIndices& clusters_out,
55  float delta_hue = 0.0);
56 
58 public:
63 
66 
69 
71 
72  //////////////////////////////////////////////////////////////////////////////////////////////////////////////////
73  /** \brief Empty constructor. */
74  SeededHueSegmentation() = default;
75 
76  /** \brief Provide a pointer to the search object.
77  * \param tree a pointer to the spatial search object.
78  */
79  inline void
81  {
82  tree_ = tree;
83  }
84 
85  /** \brief Get a pointer to the search method used.
86  * @todo fix this for a generic search tree
87  */
88  inline GPUTreePtr
90  {
91  return (tree_);
92  }
93 
94  /** \brief Set the spatial cluster tolerance as a measure in the L2 Euclidean space
95  * \param tolerance the spatial cluster tolerance as a measure in the L2 Euclidean
96  * space
97  */
98  inline void
99  setClusterTolerance(double tolerance)
100  {
101  cluster_tolerance_ = tolerance;
102  }
103 
104  /** \brief Get the spatial cluster tolerance as a measure in the L2 Euclidean space.
105  */
106  inline double
108  {
109  return (cluster_tolerance_);
110  }
111 
112  inline void
114  {
115  input_ = input;
116  }
117 
118  inline void
120  {
121  host_cloud_ = host_cloud;
122  }
123 
124  /** \brief Set the tollerance on the hue
125  * \param[in] delta_hue the new delta hue
126  */
127  inline void
128  setDeltaHue(float delta_hue)
129  {
130  delta_hue_ = delta_hue;
131  }
132 
133  /** \brief Get the tolerance on the hue */
134  inline float
136  {
137  return (delta_hue_);
138  }
139 
140  /** \brief extract clusters of a PointCloud given by <setInputCloud(), setIndices()>
141  * \param indices_in
142  * \param indices_out
143  */
144  void
145  segment(PointIndices& indices_in, PointIndices& indices_out);
146 
147 protected:
148  /** \brief the input cloud on the GPU */
150 
151  /** \brief the original cloud the Host */
153 
154  /** \brief A pointer to the spatial search object. */
156 
157  /** \brief The spatial cluster tolerance as a measure in the L2 Euclidean space. */
159 
160  /** \brief The allowed difference on the hue*/
161  float delta_hue_{0.0};
162 
163  /** \brief Class getName method. */
164  virtual std::string
165  getClassName() const
166  {
167  return ("gpu::SeededHueSegmentation");
168  }
169 };
170 /** \brief Sort clusters method (for std::sort).
171  * \ingroup segmentation
172  */
173 inline bool
175 {
176  return (a.indices.size() < b.indices.size());
177 }
178 } // namespace gpu
179 } // namespace pcl
shared_ptr< PointCloud< PointT > > Ptr
Definition: point_cloud.h:413
shared_ptr< const PointCloud< pcl::PointXYZ > > ConstPtr
Definition: point_cloud.h:414
Octree implementation on GPU.
Definition: octree.hpp:59
shared_ptr< Octree > Ptr
Types.
Definition: octree.hpp:69
DeviceArray< PointType > PointCloud
Point cloud supported.
Definition: octree.hpp:76
PointCloudHostPtr host_cloud_
the original cloud the Host
SeededHueSegmentation()=default
Empty constructor.
virtual std::string getClassName() const
Class getName method.
CloudDevice input_
the input cloud on the GPU
GPUTreePtr getSearchMethod()
Get a pointer to the search method used.
float getDeltaHue()
Get the tolerance on the hue.
float delta_hue_
The allowed difference on the hue.
void setDeltaHue(float delta_hue)
Set the tollerance on the hue.
double cluster_tolerance_
The spatial cluster tolerance as a measure in the L2 Euclidean space.
PointCloudHost::ConstPtr PointCloudHostConstPtr
void setSearchMethod(const GPUTreePtr &tree)
Provide a pointer to the search object.
double getClusterTolerance()
Get the spatial cluster tolerance as a measure in the L2 Euclidean space.
void segment(PointIndices &indices_in, PointIndices &indices_out)
extract clusters of a PointCloud given by <setInputCloud(), setIndices()>
void setHostCloud(PointCloudHostPtr host_cloud)
void setClusterTolerance(double tolerance)
Set the spatial cluster tolerance as a measure in the L2 Euclidean space.
GPUTreePtr tree_
A pointer to the spatial search object.
Defines all the PCL implemented PointT point type structures.
bool comparePointClusters(const pcl::PointIndices &a, const pcl::PointIndices &b)
Sort clusters method (for std::sort).
void seededHueSegmentation(const pcl::PointCloud< pcl::PointXYZRGB >::Ptr &host_cloud_, const pcl::gpu::Octree::Ptr &tree, float tolerance, PointIndices &clusters_in, PointIndices &clusters_out, float delta_hue=0.0)
Defines all the PCL and non-PCL macros used.
shared_ptr< ::pcl::PointIndices > Ptr
Definition: PointIndices.h:13
shared_ptr< const ::pcl::PointIndices > ConstPtr
Definition: PointIndices.h:14
A point structure representing Euclidean xyz coordinates.