Point Cloud Library (PCL)  1.9.1
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 #ifndef PCL_GPU_SEEDED_HUE_SEGMENTATION_H_
41 #define PCL_GPU_SEEDED_HUE_SEGMENTATION_H_
42 
43 #include <pcl/point_types.h>
44 #include <pcl/point_cloud.h>
45 #include <pcl/PointIndices.h>
46 #include <pcl/pcl_macros.h>
47 #include <pcl/gpu/octree/octree.hpp>
48 #include <pcl/gpu/containers/device_array.hpp>
49 
50 namespace pcl
51 {
52  namespace gpu
53  {
54  void
55  seededHueSegmentation (const boost::shared_ptr<pcl::PointCloud<pcl::PointXYZRGB> > &host_cloud_,
56  const pcl::gpu::Octree::Ptr &tree,
57  float tolerance,
58  PointIndices &clusters_in,
59  PointIndices &clusters_out,
60  float delta_hue = 0.0);
61 
63  {
64  public:
69 
72 
75 
77 
78  //////////////////////////////////////////////////////////////////////////////////////////////////////////////////
79  /** \brief Empty constructor. */
81  {};
82 
83  /** \brief Provide a pointer to the search object.
84  * \param tree a pointer to the spatial search object.
85  */
86  inline void setSearchMethod (const GPUTreePtr &tree) { tree_ = tree; }
87 
88  /** \brief Get a pointer to the search method used.
89  * @todo fix this for a generic search tree
90  */
91  inline GPUTreePtr getSearchMethod () { return (tree_); }
92 
93  /** \brief Set the spatial cluster tolerance as a measure in the L2 Euclidean space
94  * \param tolerance the spatial cluster tolerance as a measure in the L2 Euclidean space
95  */
96  inline void setClusterTolerance (double tolerance) { cluster_tolerance_ = tolerance; }
97 
98  /** \brief Get the spatial cluster tolerance as a measure in the L2 Euclidean space. */
99  inline double getClusterTolerance () { return (cluster_tolerance_); }
100 
101  inline void setInput (CloudDevice input) {input_ = input;}
102 
103  inline void setHostCloud (PointCloudHostPtr host_cloud) {host_cloud_ = host_cloud;}
104 
105  /** \brief Set the tollerance on the hue
106  * \param[in] delta_hue the new delta hue
107  */
108  inline void
109  setDeltaHue (float delta_hue) { delta_hue_ = delta_hue; }
110 
111  /** \brief Get the tolerance on the hue */
112  inline float
113  getDeltaHue () { return (delta_hue_); }
114 
115  /** \brief Cluster extraction in a PointCloud given by <setInputCloud (), setIndices ()>
116  * \param indices_in
117  * \param indices_out
118  */
119  void segment (PointIndices &indices_in, PointIndices &indices_out);
120 
121  protected:
122  /** \brief the input cloud on the GPU */
124 
125  /** \brief the original cloud the Host */
127 
128  /** \brief A pointer to the spatial search object. */
130 
131  /** \brief The spatial cluster tolerance as a measure in the L2 Euclidean space. */
133 
134  /** \brief The allowed difference on the hue*/
135  float delta_hue_;
136 
137  /** \brief Class getName method. */
138  virtual std::string getClassName () const { return ("gpu::SeededHueSegmentation"); }
139  };
140  /** \brief Sort clusters method (for std::sort).
141  * \ingroup segmentation
142  */
143  inline bool
145  {
146  return (a.indices.size () < b.indices.size ());
147  }
148  }
149 }
150 
151 #endif //PCL_GPU_SEEDED_HUE_SEGMENTATION_H_
152 
153 
154 
155 
void setClusterTolerance(double tolerance)
Set the spatial cluster tolerance as a measure in the L2 Euclidean space.
void setDeltaHue(float delta_hue)
Set the tollerance on the hue.
PointCloudHostPtr host_cloud_
the original cloud the Host
This file defines compatibility wrappers for low level I/O functions.
Definition: convolution.h:45
boost::shared_ptr< Octree > Ptr
Types.
Definition: octree.hpp:67
std::vector< int > indices
Definition: PointIndices.h:19
GPUTreePtr getSearchMethod()
Get a pointer to the search method used.
Octree implementation on GPU.
Definition: octree.hpp:56
bool comparePointClusters(const pcl::PointIndices &a, const pcl::PointIndices &b)
Sort clusters method (for std::sort).
GPUTreePtr tree_
A pointer to the spatial search object.
boost::shared_ptr< PointCloud< pcl::PointXYZ > > Ptr
Definition: point_cloud.h:428
virtual std::string getClassName() const
Class getName method.
Defines all the PCL implemented PointT point type structures.
A point structure representing Euclidean xyz coordinates.
pcl::gpu::Octree::PointCloud CloudDevice
void setSearchMethod(const GPUTreePtr &tree)
Provide a pointer to the search object.
boost::shared_ptr< const PointCloud< pcl::PointXYZ > > ConstPtr
Definition: point_cloud.h:429
float delta_hue_
The allowed difference on the hue.
PointCloudHost::ConstPtr PointCloudHostConstPtr
void segment(PointIndices &indices_in, PointIndices &indices_out)
Cluster extraction in a PointCloud given by <setInputCloud (), setIndices ()>
boost::shared_ptr< ::pcl::PointIndices > Ptr
Definition: PointIndices.h:22
CloudDevice input_
the input cloud on the GPU
float getDeltaHue()
Get the tolerance on the hue.
void seededHueSegmentation(const boost::shared_ptr< pcl::PointCloud< pcl::PointXYZRGB > > &host_cloud_, const pcl::gpu::Octree::Ptr &tree, float tolerance, PointIndices &clusters_in, PointIndices &clusters_out, float delta_hue=0.0)
pcl::PointCloud< pcl::PointXYZ > PointCloudHost
void setHostCloud(PointCloudHostPtr host_cloud)
double getClusterTolerance()
Get the spatial cluster tolerance as a measure in the L2 Euclidean space.
boost::shared_ptr< ::pcl::PointIndices const > ConstPtr
Definition: PointIndices.h:23
double cluster_tolerance_
The spatial cluster tolerance as a measure in the L2 Euclidean space.