Point Cloud Library (PCL)  1.14.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 
86  descriptor_size_ (PointOutT::descriptorSize ())
87  {
88  feature_name_ = "GFPFHEstimation";
89  }
90 
91  /** \brief Set the size of the octree leaves.
92  */
93  inline void
94  setOctreeLeafSize (double size) { octree_leaf_size_ = size; }
95 
96  /** \brief Get the sphere radius used for determining the neighbors. */
97  inline double
98  getOctreeLeafSize () { return (octree_leaf_size_); }
99 
100  /** \brief Return the empty label value. */
101  inline std::uint32_t
102  emptyLabel () const { return 0; }
103 
104  /** \brief Return the number of different classes. */
105  inline std::uint32_t
106  getNumberOfClasses () const { return number_of_classes_; }
107 
108  /** \brief Set the number of different classes.
109  * \param n number of different classes.
110  */
111  inline void
112  setNumberOfClasses (std::uint32_t n) { number_of_classes_ = n; }
113 
114  /** \brief Return the size of the descriptor. */
115  inline int
116  descriptorSize () const { return descriptor_size_; }
117 
118  /** \brief Overloaded computed method from pcl::Feature.
119  * \param[out] output the resultant point cloud model dataset containing the estimated features
120  */
121  void
122  compute (PointCloudOut &output);
123 
124  protected:
125 
126  /** \brief Estimate the Point Feature Histograms (PFH) descriptors at a set of points given by
127  * <setInputCloud (), setIndices ()> using the surface in setSearchSurface () and the spatial locator in
128  * setSearchMethod ()
129  * \param output the resultant point cloud model dataset that contains the PFH feature estimates
130  */
131  void
132  computeFeature (PointCloudOut &output) override;
133 
134  /** \brief Return the dominant label of a set of points. */
135  std::uint32_t
136  getDominantLabel (const pcl::Indices& indices);
137 
138  /** \brief Compute the fixed-length histograms of transitions. */
139  void computeTransitionHistograms (const std::vector< std::vector<int> >& label_histograms,
140  std::vector< std::vector<int> >& transition_histograms);
141 
142  /** \brief Compute the distance of each transition histogram to the mean. */
143  void
144  computeDistancesToMean (const std::vector< std::vector<int> >& transition_histograms,
145  std::vector<float>& distances);
146 
147  /** \brief Return the Intersection Kernel distance between two histograms. */
148  float
149  computeHIKDistance (const std::vector<int>& histogram,
150  const std::vector<float>& mean_histogram);
151 
152  /** \brief Compute the binned histogram of distance values. */
153  void
154  computeDistanceHistogram (const std::vector<float>& distances,
155  std::vector<float>& histogram);
156 
157  /** \brief Compute the mean histogram of the given set of histograms. */
158  void
159  computeMeanHistogram (const std::vector< std::vector<int> >& histograms,
160  std::vector<float>& mean_histogram);
161 
162  private:
163  /** \brief Size of octree leaves. */
164  double octree_leaf_size_{0.01};
165 
166  /** \brief Number of possible classes/labels. */
167  std::uint32_t number_of_classes_{16};
168 
169  /** \brief Dimension of the descriptors. */
170  int descriptor_size_;
171  };
172 }
173 
174 #ifdef PCL_NO_PRECOMPILE
175 #include <pcl/features/impl/gfpfh.hpp>
176 #endif
shared_ptr< Feature< PointInT, PointOutT > > Ptr
Definition: feature.h:114
std::string feature_name_
The feature name.
Definition: feature.h:220
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:116
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:106
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:102
void setNumberOfClasses(std::uint32_t n)
Set the number of different classes.
Definition: gfpfh.h:112
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:94
double getOctreeLeafSize()
Get the sphere radius used for determining the neighbors.
Definition: gfpfh.h:98
IndicesAllocator<> Indices
Type used for indices in PCL.
Definition: types.h:133