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