Point Cloud Library (PCL)  1.12.1-dev
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 #pragma once
42 
43 #include <pcl/features/feature.h>
44 
45 namespace pcl
46 {
47  /** \brief @b GFPFHEstimation estimates the Global Fast Point Feature Histogram (GFPFH) descriptor for a given point
48  * cloud dataset containing points and labels.
49  *
50  * @note If you use this code in any academic work, please cite:
51  *
52  * <ul>
53  * <li> R.B. Rusu, A. Holzbach, M. Beetz.
54  * Detecting and Segmenting Objects for Mobile Manipulation.
55  * In the S3DV Workshop of the 12th International Conference on Computer Vision (ICCV),
56  * 2009.
57  * </li>
58  * </ul>
59  *
60  * \author Radu B. Rusu
61  * \ingroup features
62  * \tparam PointOutT Suggested type is `pcl::GFPFHSignature16`
63  */
64  template <typename PointInT, typename PointLT, typename PointOutT>
65  class GFPFHEstimation : public FeatureFromLabels<PointInT, PointLT, PointOutT>
66  {
67  public:
68  using Ptr = shared_ptr<GFPFHEstimation<PointInT, PointLT, PointOutT> >;
69  using ConstPtr = shared_ptr<const GFPFHEstimation<PointInT, PointLT, PointOutT> >;
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 std::uint32_t
103  emptyLabel () const { return 0; }
104 
105  /** \brief Return the number of different classes. */
106  inline std::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 (std::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) override;
134 
135  /** \brief Return the dominant label of a set of points. */
136  std::uint32_t
137  getDominantLabel (const pcl::Indices& 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  std::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
shared_ptr< Feature< PointInT, PointOutT > > Ptr
Definition: feature.h:114
std::string feature_name_
The feature name.
Definition: feature.h:223
shared_ptr< const Feature< PointInT, PointOutT > > ConstPtr
Definition: feature.h:115
GFPFHEstimation estimates the Global Fast Point Feature Histogram (GFPFH) descriptor for a given poin...
Definition: gfpfh.h:66
int descriptorSize() const
Return the size of the descriptor.
Definition: gfpfh.h:117
void computeDistancesToMean(const std::vector< std::vector< int > > &transition_histograms, std::vector< float > &distances)
Compute the distance of each transition histogram to the mean.
Definition: gfpfh.hpp:179
typename Feature< PointInT, PointOutT >::PointCloudOut PointCloudOut
Definition: gfpfh.h:80
std::uint32_t getNumberOfClasses() const
Return the number of different classes.
Definition: gfpfh.h:107
void computeTransitionHistograms(const std::vector< std::vector< int > > &label_histograms, std::vector< std::vector< int > > &transition_histograms)
Compute the fixed-length histograms of transitions.
Definition: gfpfh.hpp:138
std::uint32_t getDominantLabel(const pcl::Indices &indices)
Return the dominant label of a set of points.
Definition: gfpfh.hpp:254
std::uint32_t emptyLabel() const
Return the empty label value.
Definition: gfpfh.h:103
void setNumberOfClasses(std::uint32_t n)
Set the number of different classes.
Definition: gfpfh.h:113
void compute(PointCloudOut &output)
Overloaded computed method from pcl::Feature.
Definition: gfpfh.hpp:53
void computeMeanHistogram(const std::vector< std::vector< int > > &histograms, std::vector< float > &mean_histogram)
Compute the mean histogram of the given set of histograms.
Definition: gfpfh.hpp:223
float computeHIKDistance(const std::vector< int > &histogram, const std::vector< float > &mean_histogram)
Return the Intersection Kernel distance between two histograms.
Definition: gfpfh.hpp:239
GFPFHEstimation()
Empty constructor.
Definition: gfpfh.h:84
void computeDistanceHistogram(const std::vector< float > &distances, std::vector< float > &histogram)
Compute the binned histogram of distance values.
Definition: gfpfh.hpp:196
void computeFeature(PointCloudOut &output) override
Estimate the Point Feature Histograms (PFH) descriptors at a set of points given by <setInputCloud ()...
Definition: gfpfh.hpp:80
void setOctreeLeafSize(double size)
Set the size of the octree leaves.
Definition: gfpfh.h:95
double getOctreeLeafSize()
Get the sphere radius used for determining the neighbors.
Definition: gfpfh.h:99
IndicesAllocator<> Indices
Type used for indices in PCL.
Definition: types.h:133