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