Point Cloud Library (PCL)  1.7.1
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[out] indices_out the indices of the points with higher curvature than threshold
104  * \param[out] indices_in the indices of the remaining points after filtering
105  * \param[in] threshold threshold value for curvature
106  */
107  void
108  filterNormalsWithHighCurvature (const pcl::PointCloud<PointNT> & cloud, std::vector<int> & indices_to_use, std::vector<int> &indices_out,
109  std::vector<int> &indices_in, float threshold);
110 
111  /** \brief Set the viewpoint.
112  * \param[in] vpx the X coordinate of the viewpoint
113  * \param[in] vpy the Y coordinate of the viewpoint
114  * \param[in] vpz the Z coordinate of the viewpoint
115  */
116  inline void
117  setViewPoint (float vpx, float vpy, float vpz)
118  {
119  vpx_ = vpx;
120  vpy_ = vpy;
121  vpz_ = vpz;
122  }
123 
124  /** \brief Set the radius used to compute normals
125  * \param[in] radius_normals the radius
126  */
127  inline void
128  setRadiusNormals (float radius_normals)
129  {
130  radius_normals_ = radius_normals;
131  }
132 
133  /** \brief Get the viewpoint.
134  * \param[out] vpx the X coordinate of the viewpoint
135  * \param[out] vpy the Y coordinate of the viewpoint
136  * \param[out] vpz the Z coordinate of the viewpoint
137  */
138  inline void
139  getViewPoint (float &vpx, float &vpy, float &vpz)
140  {
141  vpx = vpx_;
142  vpy = vpy_;
143  vpz = vpz_;
144  }
145 
146  /** \brief Get the centroids used to compute different CVFH descriptors
147  * \param[out] centroids vector to hold the centroids
148  */
149  inline void
150  getCentroidClusters (std::vector<Eigen::Vector3f> & centroids)
151  {
152  for (size_t i = 0; i < centroids_dominant_orientations_.size (); ++i)
153  centroids.push_back (centroids_dominant_orientations_[i]);
154  }
155 
156  /** \brief Get the normal centroids used to compute different CVFH descriptors
157  * \param[out] centroids vector to hold the normal centroids
158  */
159  inline void
160  getCentroidNormalClusters (std::vector<Eigen::Vector3f> & centroids)
161  {
162  for (size_t i = 0; i < dominant_normals_.size (); ++i)
163  centroids.push_back (dominant_normals_[i]);
164  }
165 
166  /** \brief Sets max. Euclidean distance between points to be added to the cluster
167  * \param[in] d the maximum Euclidean distance
168  */
169 
170  inline void
172  {
173  cluster_tolerance_ = d;
174  }
175 
176  /** \brief Sets max. deviation of the normals between two points so they can be clustered together
177  * \param[in] d the maximum deviation
178  */
179  inline void
181  {
182  eps_angle_threshold_ = d;
183  }
184 
185  /** \brief Sets curvature threshold for removing normals
186  * \param[in] d the curvature threshold
187  */
188  inline void
190  {
191  curv_threshold_ = d;
192  }
193 
194  /** \brief Set minimum amount of points for a cluster to be considered
195  * \param[in] min the minimum amount of points to be set
196  */
197  inline void
198  setMinPoints (size_t min)
199  {
200  min_points_ = min;
201  }
202 
203  /** \brief Sets wether if the CVFH signatures should be normalized or not
204  * \param[in] normalize true if normalization is required, false otherwise
205  */
206  inline void
207  setNormalizeBins (bool normalize)
208  {
209  normalize_bins_ = normalize;
210  }
211 
212  /** \brief Overloaded computed method from pcl::Feature.
213  * \param[out] output the resultant point cloud model dataset containing the estimated features
214  */
215  void
216  compute (PointCloudOut &output);
217 
218  private:
219  /** \brief Values describing the viewpoint ("pinhole" camera model assumed).
220  * By default, the viewpoint is set to 0,0,0.
221  */
222  float vpx_, vpy_, vpz_;
223 
224  /** \brief Size of the voxels after voxel gridding. IMPORTANT: Must match the voxel
225  * size of the training data or the normalize_bins_ flag must be set to true.
226  */
227  float leaf_size_;
228 
229  /** \brief Wether to normalize the signatures or not. Default: false. */
230  bool normalize_bins_;
231 
232  /** \brief Curvature threshold for removing normals. */
233  float curv_threshold_;
234 
235  /** \brief allowed Euclidean distance between points to be added to the cluster. */
236  float cluster_tolerance_;
237 
238  /** \brief deviation of the normals between two points so they can be clustered together. */
239  float eps_angle_threshold_;
240 
241  /** \brief Minimum amount of points in a clustered region to be considered stable for CVFH
242  * computation.
243  */
244  size_t min_points_;
245 
246  /** \brief Radius for the normals computation. */
247  float radius_normals_;
248 
249  /** \brief Estimate the Clustered Viewpoint Feature Histograms (CVFH) descriptors at
250  * a set of points given by <setInputCloud (), setIndices ()> using the surface in
251  * setSearchSurface ()
252  *
253  * \param[out] output the resultant point cloud model dataset that contains the CVFH
254  * feature estimates
255  */
256  void
257  computeFeature (PointCloudOut &output);
258 
259  /** \brief Region growing method using Euclidean distances and neighbors normals to
260  * add points to a region.
261  * \param[in] cloud point cloud to split into regions
262  * \param[in] normals are the normals of cloud
263  * \param[in] tolerance is the allowed Euclidean distance between points to be added to
264  * the cluster
265  * \param[in] tree is the spatial search structure for nearest neighbour search
266  * \param[out] clusters vector of indices representing the clustered regions
267  * \param[in] eps_angle deviation of the normals between two points so they can be
268  * clustered together
269  * \param[in] min_pts_per_cluster minimum cluster size. (default: 1 point)
270  * \param[in] max_pts_per_cluster maximum cluster size. (default: all the points)
271  */
272  void
273  extractEuclideanClustersSmooth (const pcl::PointCloud<pcl::PointNormal> &cloud,
274  const pcl::PointCloud<pcl::PointNormal> &normals, float tolerance,
276  std::vector<pcl::PointIndices> &clusters, double eps_angle,
277  unsigned int min_pts_per_cluster = 1,
278  unsigned int max_pts_per_cluster = (std::numeric_limits<int>::max) ());
279 
280  protected:
281  /** \brief Centroids that were used to compute different CVFH descriptors */
282  std::vector<Eigen::Vector3f> centroids_dominant_orientations_;
283  /** \brief Normal centroids that were used to compute different CVFH descriptors */
284  std::vector<Eigen::Vector3f> dominant_normals_;
285  };
286 }
287 
288 #ifdef PCL_NO_PRECOMPILE
289 #include <pcl/features/impl/cvfh.hpp>
290 #endif
291 
292 #endif //#ifndef PCL_FEATURES_CVFH_H_