Point Cloud Library (PCL)  1.9.1
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Modules Pages
cvfh.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_FEATURES_CVFH_H_
42 #define PCL_FEATURES_CVFH_H_
43 
44 #include <pcl/features/feature.h>
45 #include <pcl/features/vfh.h>
46 #include <pcl/search/pcl_search.h>
47 #include <pcl/common/common.h>
48 
49 namespace pcl
50 {
51  /** \brief CVFHEstimation estimates the Clustered Viewpoint Feature Histogram (CVFH) descriptor for a given
52  * point cloud dataset containing XYZ data and normals, as presented in:
53  * - CAD-Model Recognition and 6 DOF Pose Estimation
54  * A. Aldoma, N. Blodow, D. Gossow, S. Gedikli, R.B. Rusu, M. Vincze and G. Bradski
55  * ICCV 2011, 3D Representation and Recognition (3dRR11) workshop
56  * Barcelona, Spain, (2011)
57  *
58  * The suggested PointOutT is pcl::VFHSignature308.
59  *
60  * \author Aitor Aldoma
61  * \ingroup features
62  */
63  template<typename PointInT, typename PointNT, typename PointOutT = pcl::VFHSignature308>
64  class CVFHEstimation : public FeatureFromNormals<PointInT, PointNT, PointOutT>
65  {
66  public:
67  typedef boost::shared_ptr<CVFHEstimation<PointInT, PointNT, PointOutT> > Ptr;
68  typedef boost::shared_ptr<const CVFHEstimation<PointInT, PointNT, PointOutT> > ConstPtr;
69 
77 
81 
82  /** \brief Empty constructor. */
84  vpx_ (0), vpy_ (0), vpz_ (0),
85  leaf_size_ (0.005f),
86  normalize_bins_ (false),
87  curv_threshold_ (0.03f),
88  cluster_tolerance_ (leaf_size_ * 3),
89  eps_angle_threshold_ (0.125f),
90  min_points_ (50),
91  radius_normals_ (leaf_size_ * 3),
94  {
95  search_radius_ = 0;
96  k_ = 1;
97  feature_name_ = "CVFHEstimation";
98  }
99  ;
100 
101  /** \brief Removes normals with high curvature caused by real edges or noisy data
102  * \param[in] cloud pointcloud to be filtered
103  * \param[in] indices_to_use the indices to use
104  * \param[out] indices_out the indices of the points with higher curvature than threshold
105  * \param[out] indices_in the indices of the remaining points after filtering
106  * \param[in] threshold threshold value for curvature
107  */
108  void
109  filterNormalsWithHighCurvature (const pcl::PointCloud<PointNT> & cloud, std::vector<int> & indices_to_use, std::vector<int> &indices_out,
110  std::vector<int> &indices_in, float threshold);
111 
112  /** \brief Set the viewpoint.
113  * \param[in] vpx the X coordinate of the viewpoint
114  * \param[in] vpy the Y coordinate of the viewpoint
115  * \param[in] vpz the Z coordinate of the viewpoint
116  */
117  inline void
118  setViewPoint (float vpx, float vpy, float vpz)
119  {
120  vpx_ = vpx;
121  vpy_ = vpy;
122  vpz_ = vpz;
123  }
124 
125  /** \brief Set the radius used to compute normals
126  * \param[in] radius_normals the radius
127  */
128  inline void
129  setRadiusNormals (float radius_normals)
130  {
131  radius_normals_ = radius_normals;
132  }
133 
134  /** \brief Get the viewpoint.
135  * \param[out] vpx the X coordinate of the viewpoint
136  * \param[out] vpy the Y coordinate of the viewpoint
137  * \param[out] vpz the Z coordinate of the viewpoint
138  */
139  inline void
140  getViewPoint (float &vpx, float &vpy, float &vpz)
141  {
142  vpx = vpx_;
143  vpy = vpy_;
144  vpz = vpz_;
145  }
146 
147  /** \brief Get the centroids used to compute different CVFH descriptors
148  * \param[out] centroids vector to hold the centroids
149  */
150  inline void
151  getCentroidClusters (std::vector<Eigen::Vector3f, Eigen::aligned_allocator<Eigen::Vector3f> > & centroids)
152  {
153  for (size_t i = 0; i < centroids_dominant_orientations_.size (); ++i)
154  centroids.push_back (centroids_dominant_orientations_[i]);
155  }
156 
157  /** \brief Get the normal centroids used to compute different CVFH descriptors
158  * \param[out] centroids vector to hold the normal centroids
159  */
160  inline void
161  getCentroidNormalClusters (std::vector<Eigen::Vector3f, Eigen::aligned_allocator<Eigen::Vector3f> > & centroids)
162  {
163  for (size_t i = 0; i < dominant_normals_.size (); ++i)
164  centroids.push_back (dominant_normals_[i]);
165  }
166 
167  /** \brief Sets max. Euclidean distance between points to be added to the cluster
168  * \param[in] d the maximum Euclidean distance
169  */
170 
171  inline void
173  {
174  cluster_tolerance_ = d;
175  }
176 
177  /** \brief Sets max. deviation of the normals between two points so they can be clustered together
178  * \param[in] d the maximum deviation
179  */
180  inline void
182  {
183  eps_angle_threshold_ = d;
184  }
185 
186  /** \brief Sets curvature threshold for removing normals
187  * \param[in] d the curvature threshold
188  */
189  inline void
191  {
192  curv_threshold_ = d;
193  }
194 
195  /** \brief Set minimum amount of points for a cluster to be considered
196  * \param[in] min the minimum amount of points to be set
197  */
198  inline void
199  setMinPoints (size_t min)
200  {
201  min_points_ = min;
202  }
203 
204  /** \brief Sets whether if the CVFH signatures should be normalized or not
205  * \param[in] normalize true if normalization is required, false otherwise
206  */
207  inline void
208  setNormalizeBins (bool normalize)
209  {
210  normalize_bins_ = normalize;
211  }
212 
213  /** \brief Overloaded computed method from pcl::Feature.
214  * \param[out] output the resultant point cloud model dataset containing the estimated features
215  */
216  void
217  compute (PointCloudOut &output);
218 
219  private:
220  /** \brief Values describing the viewpoint ("pinhole" camera model assumed).
221  * By default, the viewpoint is set to 0,0,0.
222  */
223  float vpx_, vpy_, vpz_;
224 
225  /** \brief Size of the voxels after voxel gridding. IMPORTANT: Must match the voxel
226  * size of the training data or the normalize_bins_ flag must be set to true.
227  */
228  float leaf_size_;
229 
230  /** \brief Whether to normalize the signatures or not. Default: false. */
231  bool normalize_bins_;
232 
233  /** \brief Curvature threshold for removing normals. */
234  float curv_threshold_;
235 
236  /** \brief allowed Euclidean distance between points to be added to the cluster. */
237  float cluster_tolerance_;
238 
239  /** \brief deviation of the normals between two points so they can be clustered together. */
240  float eps_angle_threshold_;
241 
242  /** \brief Minimum amount of points in a clustered region to be considered stable for CVFH
243  * computation.
244  */
245  size_t min_points_;
246 
247  /** \brief Radius for the normals computation. */
248  float radius_normals_;
249 
250  /** \brief Estimate the Clustered Viewpoint Feature Histograms (CVFH) descriptors at
251  * a set of points given by <setInputCloud (), setIndices ()> using the surface in
252  * setSearchSurface ()
253  *
254  * \param[out] output the resultant point cloud model dataset that contains the CVFH
255  * feature estimates
256  */
257  void
258  computeFeature (PointCloudOut &output);
259 
260  /** \brief Region growing method using Euclidean distances and neighbors normals to
261  * add points to a region.
262  * \param[in] cloud point cloud to split into regions
263  * \param[in] normals are the normals of cloud
264  * \param[in] tolerance is the allowed Euclidean distance between points to be added to
265  * the cluster
266  * \param[in] tree is the spatial search structure for nearest neighbour search
267  * \param[out] clusters vector of indices representing the clustered regions
268  * \param[in] eps_angle deviation of the normals between two points so they can be
269  * clustered together
270  * \param[in] min_pts_per_cluster minimum cluster size. (default: 1 point)
271  * \param[in] max_pts_per_cluster maximum cluster size. (default: all the points)
272  */
273  void
274  extractEuclideanClustersSmooth (const pcl::PointCloud<pcl::PointNormal> &cloud,
275  const pcl::PointCloud<pcl::PointNormal> &normals, float tolerance,
277  std::vector<pcl::PointIndices> &clusters, double eps_angle,
278  unsigned int min_pts_per_cluster = 1,
279  unsigned int max_pts_per_cluster = (std::numeric_limits<int>::max) ());
280 
281  protected:
282  /** \brief Centroids that were used to compute different CVFH descriptors */
283  std::vector<Eigen::Vector3f, Eigen::aligned_allocator<Eigen::Vector3f> > centroids_dominant_orientations_;
284  /** \brief Normal centroids that were used to compute different CVFH descriptors */
285  std::vector<Eigen::Vector3f, Eigen::aligned_allocator<Eigen::Vector3f> > dominant_normals_;
286  };
287 }
288 
289 #ifdef PCL_NO_PRECOMPILE
290 #include <pcl/features/impl/cvfh.hpp>
291 #endif
292 
293 #endif //#ifndef PCL_FEATURES_CVFH_H_
void getCentroidNormalClusters(std::vector< Eigen::Vector3f, Eigen::aligned_allocator< Eigen::Vector3f > > &centroids)
Get the normal centroids used to compute different CVFH descriptors.
Definition: cvfh.h:161
void setRadiusNormals(float radius_normals)
Set the radius used to compute normals.
Definition: cvfh.h:129
CVFHEstimation estimates the Clustered Viewpoint Feature Histogram (CVFH) descriptor for a given poin...
Definition: cvfh.h:64
pcl::VFHEstimation< PointInT, PointNT, pcl::VFHSignature308 > VFHEstimator
Definition: cvfh.h:80
std::string feature_name_
The feature name.
Definition: feature.h:222
This file defines compatibility wrappers for low level I/O functions.
Definition: convolution.h:45
CVFHEstimation()
Empty constructor.
Definition: cvfh.h:83
Feature< PointInT, PointOutT >::PointCloudOut PointCloudOut
Definition: cvfh.h:78
int k_
The number of K nearest neighbors to use for each point.
Definition: feature.h:242
void filterNormalsWithHighCurvature(const pcl::PointCloud< PointNT > &cloud, std::vector< int > &indices_to_use, std::vector< int > &indices_out, std::vector< int > &indices_in, float threshold)
Removes normals with high curvature caused by real edges or noisy data.
Definition: cvfh.hpp:162
void setEPSAngleThreshold(float d)
Sets max.
Definition: cvfh.h:181
boost::shared_ptr< const CVFHEstimation< PointInT, PointNT, PointOutT > > ConstPtr
Definition: cvfh.h:68
void setCurvatureThreshold(float d)
Sets curvature threshold for removing normals.
Definition: cvfh.h:190
std::vector< Eigen::Vector3f, Eigen::aligned_allocator< Eigen::Vector3f > > centroids_dominant_orientations_
Centroids that were used to compute different CVFH descriptors.
Definition: cvfh.h:283
boost::shared_ptr< CVFHEstimation< PointInT, PointNT, PointOutT > > Ptr
Definition: cvfh.h:67
void setNormalizeBins(bool normalize)
Sets whether if the CVFH signatures should be normalized or not.
Definition: cvfh.h:208
boost::shared_ptr< pcl::search::Search< PointT > > Ptr
Definition: search.h:81
void getCentroidClusters(std::vector< Eigen::Vector3f, Eigen::aligned_allocator< Eigen::Vector3f > > &centroids)
Get the centroids used to compute different CVFH descriptors.
Definition: cvfh.h:151
VFHEstimation estimates the Viewpoint Feature Histogram (VFH) descriptor for a given point cloud data...
Definition: vfh.h:71
void getViewPoint(float &vpx, float &vpy, float &vpz)
Get the viewpoint.
Definition: cvfh.h:140
PointCloud represents the base class in PCL for storing collections of 3D points. ...
pcl::search::Search< PointNormal >::Ptr KdTreePtr
Definition: cvfh.h:79
void compute(PointCloudOut &output)
Overloaded computed method from pcl::Feature.
Definition: cvfh.hpp:51
Feature represents the base feature class.
Definition: feature.h:105
void setMinPoints(size_t min)
Set minimum amount of points for a cluster to be considered.
Definition: cvfh.h:199
void setViewPoint(float vpx, float vpy, float vpz)
Set the viewpoint.
Definition: cvfh.h:118
double search_radius_
The nearest neighbors search radius for each point.
Definition: feature.h:239
void setClusterTolerance(float d)
Sets max.
Definition: cvfh.h:172
std::vector< Eigen::Vector3f, Eigen::aligned_allocator< Eigen::Vector3f > > dominant_normals_
Normal centroids that were used to compute different CVFH descriptors.
Definition: cvfh.h:285