Point Cloud Library (PCL)  1.7.0
gfpfh.h
1 /*
2  * Software License Agreement (BSD License)
3  *
4  * Point Cloud Library (PCL) - www.pointclouds.org
5  * Copyright (c) 2009, Willow Garage, Inc.
6  * Copyright (c) 2012-, Open Perception, Inc.
7  *
8  * All rights reserved.
9  *
10  * Redistribution and use in source and binary forms, with or without
11  * modification, are permitted provided that the following conditions
12  * are met:
13  *
14  * * Redistributions of source code must retain the above copyright
15  * notice, this list of conditions and the following disclaimer.
16  * * Redistributions in binary form must reproduce the above
17  * copyright notice, this list of conditions and the following
18  * disclaimer in the documentation and/or other materials provided
19  * with the distribution.
20  * * Neither the name of the copyright holder(s) nor the names of its
21  * contributors may be used to endorse or promote products derived
22  * from this software without specific prior written permission.
23  *
24  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
25  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
26  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
27  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
28  * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
29  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
30  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
31  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
32  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
33  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
34  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
35  * POSSIBILITY OF SUCH DAMAGE.
36  *
37  * $Id: gfpfh.h 1423 2011-06-21 09:51:32Z bouffa $
38  *
39  */
40 
41 #ifndef PCL_GFPFH_H_
42 #define PCL_GFPFH_H_
43 
44 #include <pcl/features/feature.h>
45 
46 namespace pcl
47 {
48  /** \brief @b GFPFHEstimation estimates the Global Fast Point Feature Histogram (GFPFH) descriptor for a given point
49  * cloud dataset containing points and labels.
50  *
51  * @note If you use this code in any academic work, please cite:
52  *
53  * <ul>
54  * <li> R.B. Rusu, A. Holzbach, M. Beetz.
55  * Detecting and Segmenting Objects for Mobile Manipulation.
56  * In the S3DV Workshop of the 12th International Conference on Computer Vision (ICCV),
57  * 2009.
58  * </li>
59  * </ul>
60  *
61  * \author Radu B. Rusu
62  * \ingroup features
63  */
64  template <typename PointInT, typename PointLT, typename PointOutT>
65  class GFPFHEstimation : public FeatureFromLabels<PointInT, PointLT, PointOutT>
66  {
67  public:
68  typedef boost::shared_ptr<GFPFHEstimation<PointInT, PointLT, PointOutT> > Ptr;
69  typedef boost::shared_ptr<const GFPFHEstimation<PointInT, PointLT, PointOutT> > ConstPtr;
76 
79 
82 
83  /** \brief Empty constructor. */
85  octree_leaf_size_ (0.01),
86  number_of_classes_ (16),
87  descriptor_size_ (PointOutT::descriptorSize ())
88  {
89  feature_name_ = "GFPFHEstimation";
90  }
91 
92  /** \brief Set the size of the octree leaves.
93  */
94  inline void
95  setOctreeLeafSize (double size) { octree_leaf_size_ = size; }
96 
97  /** \brief Get the sphere radius used for determining the neighbors. */
98  inline double
99  getOctreeLeafSize () { return (octree_leaf_size_); }
100 
101  /** \brief Return the empty label value. */
102  inline uint32_t
103  emptyLabel () const { return 0; }
104 
105  /** \brief Return the number of different classes. */
106  inline uint32_t
107  getNumberOfClasses () const { return number_of_classes_; }
108 
109  /** \brief Set the number of different classes.
110  * \param n number of different classes.
111  */
112  inline void
113  setNumberOfClasses (uint32_t n) { number_of_classes_ = n; }
114 
115  /** \brief Return the size of the descriptor. */
116  inline int
117  descriptorSize () const { return descriptor_size_; }
118 
119  /** \brief Overloaded computed method from pcl::Feature.
120  * \param[out] output the resultant point cloud model dataset containing the estimated features
121  */
122  void
123  compute (PointCloudOut &output);
124 
125  protected:
126 
127  /** \brief Estimate the Point Feature Histograms (PFH) descriptors at a set of points given by
128  * <setInputCloud (), setIndices ()> using the surface in setSearchSurface () and the spatial locator in
129  * setSearchMethod ()
130  * \param output the resultant point cloud model dataset that contains the PFH feature estimates
131  */
132  void
133  computeFeature (PointCloudOut &output);
134 
135  /** \brief Return the dominant label of a set of points. */
136  uint32_t
137  getDominantLabel (const std::vector<int>& indices);
138 
139  /** \brief Compute the fixed-length histograms of transitions. */
140  void computeTransitionHistograms (const std::vector< std::vector<int> >& label_histograms,
141  std::vector< std::vector<int> >& transition_histograms);
142 
143  /** \brief Compute the distance of each transition histogram to the mean. */
144  void
145  computeDistancesToMean (const std::vector< std::vector<int> >& transition_histograms,
146  std::vector<float>& distances);
147 
148  /** \brief Return the Intersection Kernel distance between two histograms. */
149  float
150  computeHIKDistance (const std::vector<int>& histogram,
151  const std::vector<float>& mean_histogram);
152 
153  /** \brief Compute the binned histogram of distance values. */
154  void
155  computeDistanceHistogram (const std::vector<float>& distances,
156  std::vector<float>& histogram);
157 
158  /** \brief Compute the mean histogram of the given set of histograms. */
159  void
160  computeMeanHistogram (const std::vector< std::vector<int> >& histograms,
161  std::vector<float>& mean_histogram);
162 
163  private:
164  /** \brief Size of octree leaves. */
165  double octree_leaf_size_;
166 
167  /** \brief Number of possible classes/labels. */
168  uint32_t number_of_classes_;
169 
170  /** \brief Dimension of the descriptors. */
171  int descriptor_size_;
172  };
173 }
174 
175 #ifdef PCL_NO_PRECOMPILE
176 #include <pcl/features/impl/gfpfh.hpp>
177 #endif
178 
179 #endif //#ifndef PCL_GFPFH_H_