Point Cloud Library (PCL)  1.12.0
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/point_types.h>
43 #include <pcl/point_cloud.h>
44 #include <pcl/PointIndices.h>
45 #include <pcl/pcl_macros.h>
46 
47 namespace pcl
48 {
49  namespace gpu
50  {
51  void
53  const pcl::gpu::Octree::Ptr &tree,
54  float tolerance,
55  PointIndices &clusters_in,
56  PointIndices &clusters_out,
57  float delta_hue = 0.0);
58 
60  {
61  public:
66 
69 
72 
74 
75  //////////////////////////////////////////////////////////////////////////////////////////////////////////////////
76  /** \brief Empty constructor. */
77  SeededHueSegmentation () = default;
78 
79  /** \brief Provide a pointer to the search object.
80  * \param tree a pointer to the spatial search object.
81  */
82  inline void setSearchMethod (const GPUTreePtr &tree) { tree_ = tree; }
83 
84  /** \brief Get a pointer to the search method used.
85  * @todo fix this for a generic search tree
86  */
87  inline GPUTreePtr getSearchMethod () { return (tree_); }
88 
89  /** \brief Set the spatial cluster tolerance as a measure in the L2 Euclidean space
90  * \param tolerance the spatial cluster tolerance as a measure in the L2 Euclidean space
91  */
92  inline void setClusterTolerance (double tolerance) { cluster_tolerance_ = tolerance; }
93 
94  /** \brief Get the spatial cluster tolerance as a measure in the L2 Euclidean space. */
95  inline double getClusterTolerance () { return (cluster_tolerance_); }
96 
97  inline void setInput (CloudDevice input) {input_ = input;}
98 
99  inline void setHostCloud (PointCloudHostPtr host_cloud) {host_cloud_ = host_cloud;}
100 
101  /** \brief Set the tollerance on the hue
102  * \param[in] delta_hue the new delta hue
103  */
104  inline void
105  setDeltaHue (float delta_hue) { delta_hue_ = delta_hue; }
106 
107  /** \brief Get the tolerance on the hue */
108  inline float
109  getDeltaHue () { return (delta_hue_); }
110 
111  /** \brief Cluster extraction in a PointCloud given by <setInputCloud (), setIndices ()>
112  * \param indices_in
113  * \param indices_out
114  */
115  void segment (PointIndices &indices_in, PointIndices &indices_out);
116 
117  protected:
118  /** \brief the input cloud on the GPU */
120 
121  /** \brief the original cloud the Host */
123 
124  /** \brief A pointer to the spatial search object. */
126 
127  /** \brief The spatial cluster tolerance as a measure in the L2 Euclidean space. */
128  double cluster_tolerance_ {0};
129 
130  /** \brief The allowed difference on the hue*/
131  float delta_hue_ {0.0};
132 
133  /** \brief Class getName method. */
134  virtual std::string getClassName () const { return ("gpu::SeededHueSegmentation"); }
135  };
136  /** \brief Sort clusters method (for std::sort).
137  * \ingroup segmentation
138  */
139  inline bool
141  {
142  return (a.indices.size () < b.indices.size ());
143  }
144  }
145 }
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:58
shared_ptr< Octree > Ptr
Types.
Definition: octree.hpp:68
DeviceArray< PointType > PointCloud
Point cloud supported.
Definition: octree.hpp:75
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)
Cluster extraction in 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.