Point Cloud Library (PCL)  1.7.2
fpfh.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  * 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$
38  *
39  */
40 
41 #ifndef PCL_FPFH_H_
42 #define PCL_FPFH_H_
43 
44 #include <pcl/features/feature.h>
45 #include <set>
46 
47 namespace pcl
48 {
49  /** \brief FPFHEstimation estimates the <b>Fast Point Feature Histogram (FPFH)</b> descriptor for a given point
50  * cloud dataset containing points and normals.
51  *
52  * A commonly used type for PointOutT is pcl::FPFHSignature33.
53  *
54  * \note If you use this code in any academic work, please cite:
55  *
56  * - R.B. Rusu, N. Blodow, M. Beetz.
57  * Fast Point Feature Histograms (FPFH) for 3D Registration.
58  * In Proceedings of the IEEE International Conference on Robotics and Automation (ICRA),
59  * Kobe, Japan, May 12-17 2009.
60  * - R.B. Rusu, A. Holzbach, N. Blodow, M. Beetz.
61  * Fast Geometric Point Labeling using Conditional Random Fields.
62  * In Proceedings of the 22nd IEEE/RSJ International Conference on Intelligent Robots and Systems (IROS),
63  * St. Louis, MO, USA, October 11-15 2009.
64  *
65  * \attention
66  * The convention for FPFH features is:
67  * - if a query point's nearest neighbors cannot be estimated, the FPFH feature will be set to NaN
68  * (not a number)
69  * - it is impossible to estimate a FPFH descriptor for a point that
70  * doesn't have finite 3D coordinates. Therefore, any point that contains
71  * NaN data on x, y, or z, will have its FPFH feature property set to NaN.
72  *
73  * \note The code is stateful as we do not expect this class to be multicore parallelized. Please look at
74  * \ref FPFHEstimationOMP for examples on parallel implementations of the FPFH (Fast Point Feature Histogram).
75  *
76  * \author Radu B. Rusu
77  * \ingroup features
78  */
79  template <typename PointInT, typename PointNT, typename PointOutT = pcl::FPFHSignature33>
80  class FPFHEstimation : public FeatureFromNormals<PointInT, PointNT, PointOutT>
81  {
82  public:
83  typedef boost::shared_ptr<FPFHEstimation<PointInT, PointNT, PointOutT> > Ptr;
84  typedef boost::shared_ptr<const FPFHEstimation<PointInT, PointNT, PointOutT> > ConstPtr;
93 
95 
96  /** \brief Empty constructor. */
98  nr_bins_f1_ (11), nr_bins_f2_ (11), nr_bins_f3_ (11),
100  d_pi_ (1.0f / (2.0f * static_cast<float> (M_PI)))
101  {
102  feature_name_ = "FPFHEstimation";
103  };
104 
105  /** \brief Compute the 4-tuple representation containing the three angles and one distance between two points
106  * represented by Cartesian coordinates and normals.
107  * \note For explanations about the features, please see the literature mentioned above (the order of the
108  * features might be different).
109  * \param[in] cloud the dataset containing the XYZ Cartesian coordinates of the two points
110  * \param[in] normals the dataset containing the surface normals (assuming normalized vectors) at each point in cloud
111  * \param[in] p_idx the index of the first point (source)
112  * \param[in] q_idx the index of the second point (target)
113  * \param[out] f1 the first angular feature (angle between the projection of nq_idx and u)
114  * \param[out] f2 the second angular feature (angle between nq_idx and v)
115  * \param[out] f3 the third angular feature (angle between np_idx and |p_idx - q_idx|)
116  * \param[out] f4 the distance feature (p_idx - q_idx)
117  */
118  bool
120  int p_idx, int q_idx, float &f1, float &f2, float &f3, float &f4);
121 
122  /** \brief Estimate the SPFH (Simple Point Feature Histograms) individual signatures of the three angular
123  * (f1, f2, f3) features for a given point based on its spatial neighborhood of 3D points with normals
124  * \param[in] cloud the dataset containing the XYZ Cartesian coordinates of the two points
125  * \param[in] normals the dataset containing the surface normals at each point in \a cloud
126  * \param[in] p_idx the index of the query point (source)
127  * \param[in] row the index row in feature histogramms
128  * \param[in] indices the k-neighborhood point indices in the dataset
129  * \param[out] hist_f1 the resultant SPFH histogram for feature f1
130  * \param[out] hist_f2 the resultant SPFH histogram for feature f2
131  * \param[out] hist_f3 the resultant SPFH histogram for feature f3
132  */
133  void
135  const pcl::PointCloud<PointNT> &normals, int p_idx, int row,
136  const std::vector<int> &indices,
137  Eigen::MatrixXf &hist_f1, Eigen::MatrixXf &hist_f2, Eigen::MatrixXf &hist_f3);
138 
139  /** \brief Weight the SPFH (Simple Point Feature Histograms) individual histograms to create the final FPFH
140  * (Fast Point Feature Histogram) for a given point based on its 3D spatial neighborhood
141  * \param[in] hist_f1 the histogram feature vector of \a f1 values over the given patch
142  * \param[in] hist_f2 the histogram feature vector of \a f2 values over the given patch
143  * \param[in] hist_f3 the histogram feature vector of \a f3 values over the given patch
144  * \param[in] indices the point indices of p_idx's k-neighborhood in the point cloud
145  * \param[in] dists the distances from p_idx to all its k-neighbors
146  * \param[out] fpfh_histogram the resultant FPFH histogram representing the feature at the query point
147  */
148  void
149  weightPointSPFHSignature (const Eigen::MatrixXf &hist_f1,
150  const Eigen::MatrixXf &hist_f2,
151  const Eigen::MatrixXf &hist_f3,
152  const std::vector<int> &indices,
153  const std::vector<float> &dists,
154  Eigen::VectorXf &fpfh_histogram);
155 
156  /** \brief Set the number of subdivisions for each angular feature interval.
157  * \param[in] nr_bins_f1 number of subdivisions for the first angular feature
158  * \param[in] nr_bins_f2 number of subdivisions for the second angular feature
159  * \param[in] nr_bins_f3 number of subdivisions for the third angular feature
160  */
161  inline void
162  setNrSubdivisions (int nr_bins_f1, int nr_bins_f2, int nr_bins_f3)
163  {
164  nr_bins_f1_ = nr_bins_f1;
165  nr_bins_f2_ = nr_bins_f2;
166  nr_bins_f3_ = nr_bins_f3;
167  }
168 
169  /** \brief Get the number of subdivisions for each angular feature interval.
170  * \param[out] nr_bins_f1 number of subdivisions for the first angular feature
171  * \param[out] nr_bins_f2 number of subdivisions for the second angular feature
172  * \param[out] nr_bins_f3 number of subdivisions for the third angular feature
173  */
174  inline void
175  getNrSubdivisions (int &nr_bins_f1, int &nr_bins_f2, int &nr_bins_f3)
176  {
177  nr_bins_f1 = nr_bins_f1_;
178  nr_bins_f2 = nr_bins_f2_;
179  nr_bins_f3 = nr_bins_f3_;
180  }
181 
182  protected:
183 
184  /** \brief Estimate the set of all SPFH (Simple Point Feature Histograms) signatures for the input cloud
185  * \param[out] spf_hist_lookup a lookup table for all the SPF feature indices
186  * \param[out] hist_f1 the resultant SPFH histogram for feature f1
187  * \param[out] hist_f2 the resultant SPFH histogram for feature f2
188  * \param[out] hist_f3 the resultant SPFH histogram for feature f3
189  */
190  void
191  computeSPFHSignatures (std::vector<int> &spf_hist_lookup,
192  Eigen::MatrixXf &hist_f1, Eigen::MatrixXf &hist_f2, Eigen::MatrixXf &hist_f3);
193 
194  /** \brief Estimate the Fast Point Feature Histograms (FPFH) descriptors at a set of points given by
195  * <setInputCloud (), setIndices ()> using the surface in setSearchSurface () and the spatial locator in
196  * setSearchMethod ()
197  * \param[out] output the resultant point cloud model dataset that contains the FPFH feature estimates
198  */
199  void
200  computeFeature (PointCloudOut &output);
201 
202  /** \brief The number of subdivisions for each angular feature interval. */
204 
205  /** \brief Placeholder for the f1 histogram. */
206  Eigen::MatrixXf hist_f1_;
207 
208  /** \brief Placeholder for the f2 histogram. */
209  Eigen::MatrixXf hist_f2_;
210 
211  /** \brief Placeholder for the f3 histogram. */
212  Eigen::MatrixXf hist_f3_;
213 
214  /** \brief Placeholder for a point's FPFH signature. */
215  Eigen::VectorXf fpfh_histogram_;
216 
217  /** \brief Float constant = 1.0 / (2.0 * M_PI) */
218  float d_pi_;
219  };
220 }
221 
222 #ifdef PCL_NO_PRECOMPILE
223 #include <pcl/features/impl/fpfh.hpp>
224 #endif
225 
226 #endif //#ifndef PCL_FPFH_H_
Eigen::MatrixXf hist_f1_
Placeholder for the f1 histogram.
Definition: fpfh.h:206
void computeSPFHSignatures(std::vector< int > &spf_hist_lookup, Eigen::MatrixXf &hist_f1, Eigen::MatrixXf &hist_f2, Eigen::MatrixXf &hist_f3)
Estimate the set of all SPFH (Simple Point Feature Histograms) signatures for the input cloud...
Definition: fpfh.hpp:174
float d_pi_
Float constant = 1.0 / (2.0 * M_PI)
Definition: fpfh.h:218
int nr_bins_f1_
The number of subdivisions for each angular feature interval.
Definition: fpfh.h:203
void getNrSubdivisions(int &nr_bins_f1, int &nr_bins_f2, int &nr_bins_f3)
Get the number of subdivisions for each angular feature interval.
Definition: fpfh.h:175
std::string feature_name_
The feature name.
Definition: feature.h:222
void computeFeature(PointCloudOut &output)
Estimate the Fast Point Feature Histograms (FPFH) descriptors at a set of points given by <setInputCl...
Definition: fpfh.hpp:234
void setNrSubdivisions(int nr_bins_f1, int nr_bins_f2, int nr_bins_f3)
Set the number of subdivisions for each angular feature interval.
Definition: fpfh.h:162
Feature< PointInT, PointOutT >::PointCloudOut PointCloudOut
Definition: fpfh.h:94
boost::shared_ptr< FPFHEstimation< PointInT, PointNT, PointOutT > > Ptr
Definition: fpfh.h:83
void weightPointSPFHSignature(const Eigen::MatrixXf &hist_f1, const Eigen::MatrixXf &hist_f2, const Eigen::MatrixXf &hist_f3, const std::vector< int > &indices, const std::vector< float > &dists, Eigen::VectorXf &fpfh_histogram)
Weight the SPFH (Simple Point Feature Histograms) individual histograms to create the final FPFH (Fas...
Definition: fpfh.hpp:106
Eigen::MatrixXf hist_f2_
Placeholder for the f2 histogram.
Definition: fpfh.h:209
FPFHEstimation estimates the Fast Point Feature Histogram (FPFH) descriptor for a given point cloud d...
Definition: fpfh.h:80
Eigen::VectorXf fpfh_histogram_
Placeholder for a point&#39;s FPFH signature.
Definition: fpfh.h:215
PointCloud represents the base class in PCL for storing collections of 3D points. ...
bool computePairFeatures(const pcl::PointCloud< PointInT > &cloud, const pcl::PointCloud< PointNT > &normals, int p_idx, int q_idx, float &f1, float &f2, float &f3, float &f4)
Compute the 4-tuple representation containing the three angles and one distance between two points re...
Definition: fpfh.hpp:49
Eigen::MatrixXf hist_f3_
Placeholder for the f3 histogram.
Definition: fpfh.h:212
FPFHEstimation()
Empty constructor.
Definition: fpfh.h:97
void computePointSPFHSignature(const pcl::PointCloud< PointInT > &cloud, const pcl::PointCloud< PointNT > &normals, int p_idx, int row, const std::vector< int > &indices, Eigen::MatrixXf &hist_f1, Eigen::MatrixXf &hist_f2, Eigen::MatrixXf &hist_f3)
Estimate the SPFH (Simple Point Feature Histograms) individual signatures of the three angular (f1...
Definition: fpfh.hpp:61
boost::shared_ptr< const FPFHEstimation< PointInT, PointNT, PointOutT > > ConstPtr
Definition: fpfh.h:84
Feature represents the base feature class.
Definition: feature.h:105