Point Cloud Library (PCL)  1.7.1
our_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: cvfh.h 4936 2012-03-07 11:12:45Z aaldoma $
38  *
39  */
40 
41 #ifndef PCL_FEATURES_OURCVFH_H_
42 #define PCL_FEATURES_OURCVFH_H_
43 
44 #include <pcl/features/feature.h>
45 #include <pcl/search/pcl_search.h>
46 #include <pcl/common/common.h>
47 
48 namespace pcl
49 {
50  /** \brief OURCVFHEstimation estimates the Oriented, Unique and Repetable Clustered Viewpoint Feature Histogram (CVFH) descriptor for a given
51  * point cloud dataset given XYZ data and normals, as presented in:
52  * - OUR-CVFH – Oriented, Unique and Repeatable Clustered Viewpoint Feature Histogram for Object Recognition and 6DOF Pose Estimation
53  * A. Aldoma, F. Tombari, R.B. Rusu and M. Vincze
54  * DAGM-OAGM 2012
55  * Graz, Austria
56  * The suggested PointOutT is pcl::VFHSignature308.
57  *
58  * \author Aitor Aldoma
59  * \ingroup features
60  */
61  template<typename PointInT, typename PointNT, typename PointOutT = pcl::VFHSignature308>
62  class OURCVFHEstimation : public FeatureFromNormals<PointInT, PointNT, PointOutT>
63  {
64  public:
65  typedef boost::shared_ptr<OURCVFHEstimation<PointInT, PointNT, PointOutT> > Ptr;
66  typedef boost::shared_ptr<const OURCVFHEstimation<PointInT, PointNT, PointOutT> > ConstPtr;
74 
78  /** \brief Empty constructor. */
80  vpx_ (0), vpy_ (0), vpz_ (0), leaf_size_ (0.005f), normalize_bins_ (false), curv_threshold_ (0.03f), cluster_tolerance_ (leaf_size_ * 3),
81  eps_angle_threshold_ (0.125f), min_points_ (50), radius_normals_ (leaf_size_ * 3), centroids_dominant_orientations_ (),
83  {
84  search_radius_ = 0;
85  k_ = 1;
86  feature_name_ = "OURCVFHEstimation";
87  refine_clusters_ = 1.f;
88  min_axis_value_ = 0.925f;
89  axis_ratio_ = 0.8f;
90  }
91  ;
92 
93  /** \brief Creates an affine transformation from the RF axes
94  * \param[in] evx the x-axis
95  * \param[in] evy the z-axis
96  * \param[in] evz the z-axis
97  * \param[out] transformPC the resulting transformation
98  * \param[in] center_mat 4x4 matrix concatenated to the resulting transformation
99  */
100  inline Eigen::Matrix4f
101  createTransFromAxes (Eigen::Vector3f & evx, Eigen::Vector3f & evy, Eigen::Vector3f & evz, Eigen::Affine3f & transformPC,
102  Eigen::Matrix4f & center_mat)
103  {
104  Eigen::Matrix4f trans;
105  trans.setIdentity (4, 4);
106  trans (0, 0) = evx (0, 0);
107  trans (1, 0) = evx (1, 0);
108  trans (2, 0) = evx (2, 0);
109  trans (0, 1) = evy (0, 0);
110  trans (1, 1) = evy (1, 0);
111  trans (2, 1) = evy (2, 0);
112  trans (0, 2) = evz (0, 0);
113  trans (1, 2) = evz (1, 0);
114  trans (2, 2) = evz (2, 0);
115 
116  Eigen::Matrix4f homMatrix = Eigen::Matrix4f ();
117  homMatrix.setIdentity (4, 4);
118  homMatrix = transformPC.matrix ();
119 
120  Eigen::Matrix4f trans_copy = trans.inverse ();
121  trans = trans_copy * center_mat * homMatrix;
122  return trans;
123  }
124 
125  /** \brief Computes SGURF and the shape distribution based on the selected SGURF
126  * \param[in] processed the input cloud
127  * \param[out] output the resulting signature
128  * \param[in] cluster_indices the indices of the stable cluster
129  */
130  void
131  computeRFAndShapeDistribution (PointInTPtr & processed, PointCloudOut &output, std::vector<pcl::PointIndices> & cluster_indices);
132 
133  /** \brief Computes SGURF
134  * \param[in] centroid the centroid of the cluster
135  * \param[in] normal_centroid the average of the normals
136  * \param[in] processed the input cloud
137  * \param[out] transformations the transformations aligning the cloud to the SGURF axes
138  * \param[out] grid the cloud transformed internally
139  * \param[in] indices the indices of the stable cluster
140  */
141  bool
142  sgurf (Eigen::Vector3f & centroid, Eigen::Vector3f & normal_centroid, PointInTPtr & processed, std::vector<Eigen::Matrix4f, Eigen::aligned_allocator<Eigen::Matrix4f> > & transformations,
143  PointInTPtr & grid, pcl::PointIndices & indices);
144 
145  /** \brief Removes normals with high curvature caused by real edges or noisy data
146  * \param[in] cloud pointcloud to be filtered
147  * \param[out] indices_out the indices of the points with higher curvature than threshold
148  * \param[out] indices_in the indices of the remaining points after filtering
149  * \param[in] threshold threshold value for curvature
150  */
151  void
152  filterNormalsWithHighCurvature (const pcl::PointCloud<PointNT> & cloud, std::vector<int> & indices_to_use, std::vector<int> &indices_out,
153  std::vector<int> &indices_in, float threshold);
154 
155  /** \brief Set the viewpoint.
156  * \param[in] vpx the X coordinate of the viewpoint
157  * \param[in] vpy the Y coordinate of the viewpoint
158  * \param[in] vpz the Z coordinate of the viewpoint
159  */
160  inline void
161  setViewPoint (float vpx, float vpy, float vpz)
162  {
163  vpx_ = vpx;
164  vpy_ = vpy;
165  vpz_ = vpz;
166  }
167 
168  /** \brief Set the radius used to compute normals
169  * \param[in] radius_normals the radius
170  */
171  inline void
172  setRadiusNormals (float radius_normals)
173  {
174  radius_normals_ = radius_normals;
175  }
176 
177  /** \brief Get the viewpoint.
178  * \param[out] vpx the X coordinate of the viewpoint
179  * \param[out] vpy the Y coordinate of the viewpoint
180  * \param[out] vpz the Z coordinate of the viewpoint
181  */
182  inline void
183  getViewPoint (float &vpx, float &vpy, float &vpz)
184  {
185  vpx = vpx_;
186  vpy = vpy_;
187  vpz = vpz_;
188  }
189 
190  /** \brief Get the centroids used to compute different CVFH descriptors
191  * \param[out] centroids vector to hold the centroids
192  */
193  inline void
194  getCentroidClusters (std::vector<Eigen::Vector3f> & centroids)
195  {
196  for (size_t i = 0; i < centroids_dominant_orientations_.size (); ++i)
197  centroids.push_back (centroids_dominant_orientations_[i]);
198  }
199 
200  /** \brief Get the normal centroids used to compute different CVFH descriptors
201  * \param[out] centroids vector to hold the normal centroids
202  */
203  inline void
204  getCentroidNormalClusters (std::vector<Eigen::Vector3f> & centroids)
205  {
206  for (size_t i = 0; i < dominant_normals_.size (); ++i)
207  centroids.push_back (dominant_normals_[i]);
208  }
209 
210  /** \brief Sets max. Euclidean distance between points to be added to the cluster
211  * \param[in] d the maximum Euclidean distance
212  */
213 
214  inline void
216  {
217  cluster_tolerance_ = d;
218  }
219 
220  /** \brief Sets max. deviation of the normals between two points so they can be clustered together
221  * \param[in] d the maximum deviation
222  */
223  inline void
225  {
226  eps_angle_threshold_ = d;
227  }
228 
229  /** \brief Sets curvature threshold for removing normals
230  * \param[in] d the curvature threshold
231  */
232  inline void
234  {
235  curv_threshold_ = d;
236  }
237 
238  /** \brief Set minimum amount of points for a cluster to be considered
239  * \param[in] min the minimum amount of points to be set
240  */
241  inline void
242  setMinPoints (size_t min)
243  {
244  min_points_ = min;
245  }
246 
247  /** \brief Sets wether if the signatures should be normalized or not
248  * \param[in] normalize true if normalization is required, false otherwise
249  */
250  inline void
251  setNormalizeBins (bool normalize)
252  {
253  normalize_bins_ = normalize;
254  }
255 
256  /** \brief Gets the indices of the original point cloud used to compute the signatures
257  * \param[out] indices vector of point indices
258  */
259  inline void
260  getClusterIndices (std::vector<pcl::PointIndices> & indices)
261  {
262  indices = clusters_;
263  }
264 
265  /** \brief Sets the refinement factor for the clusters
266  * \param[in] rc the factor used to decide if a point is used to estimate a stable cluster
267  */
268  void
269  setRefineClusters (float rc)
270  {
271  refine_clusters_ = rc;
272  }
273 
274  /** \brief Returns the transformations aligning the point cloud to the corresponding SGURF
275  * \param[out] trans vector of transformations
276  */
277  void
278  getTransforms (std::vector<Eigen::Matrix4f, Eigen::aligned_allocator<Eigen::Matrix4f> > & trans)
279  {
280  trans = transforms_;
281  }
282 
283  /** \brief Returns a boolean vector indicating of the transformation obtained by getTransforms() represents
284  * a valid SGURF
285  * \param[out] valid vector of booleans
286  */
287  void
288  getValidTransformsVec (std::vector<bool> & valid)
289  {
290  valid = valid_transforms_;
291  }
292 
293  /** \brief Sets the min axis ratio between the SGURF axes to decide if disambiguition is feasible
294  * \param[in] f the ratio between axes
295  */
296  void
297  setAxisRatio (float f)
298  {
299  axis_ratio_ = f;
300  }
301 
302  /** \brief Sets the min disambiguition axis value to generate several SGURFs for the cluster when disambiguition is difficult
303  * \param[in] f the min axis value
304  */
305  void
306  setMinAxisValue (float f)
307  {
308  min_axis_value_ = f;
309  }
310 
311  /** \brief Overloaded computed method from pcl::Feature.
312  * \param[out] output the resultant point cloud model dataset containing the estimated features
313  */
314  void
315  compute (PointCloudOut &output);
316 
317  private:
318  /** \brief Values describing the viewpoint ("pinhole" camera model assumed).
319  * By default, the viewpoint is set to 0,0,0.
320  */
321  float vpx_, vpy_, vpz_;
322 
323  /** \brief Size of the voxels after voxel gridding. IMPORTANT: Must match the voxel
324  * size of the training data or the normalize_bins_ flag must be set to true.
325  */
326  float leaf_size_;
327 
328  /** \brief Wether to normalize the signatures or not. Default: false. */
329  bool normalize_bins_;
330 
331  /** \brief Curvature threshold for removing normals. */
332  float curv_threshold_;
333 
334  /** \brief allowed Euclidean distance between points to be added to the cluster. */
335  float cluster_tolerance_;
336 
337  /** \brief deviation of the normals between two points so they can be clustered together. */
338  float eps_angle_threshold_;
339 
340  /** \brief Minimum amount of points in a clustered region to be considered stable for CVFH
341  * computation.
342  */
343  size_t min_points_;
344 
345  /** \brief Radius for the normals computation. */
346  float radius_normals_;
347 
348  /** \brief Factor for the cluster refinement */
349  float refine_clusters_;
350 
351  std::vector<Eigen::Matrix4f, Eigen::aligned_allocator<Eigen::Matrix4f> > transforms_;
352  std::vector<bool> valid_transforms_;
353 
354  float axis_ratio_;
355  float min_axis_value_;
356 
357  /** \brief Estimate the OUR-CVFH descriptors at
358  * a set of points given by <setInputCloud (), setIndices ()> using the surface in
359  * setSearchSurface ()
360  *
361  * \param[out] output the resultant point cloud model dataset that contains the OUR-CVFH
362  * feature estimates
363  */
364  void
365  computeFeature (PointCloudOut &output);
366 
367  /** \brief Region growing method using Euclidean distances and neighbors normals to
368  * add points to a region.
369  * \param[in] cloud point cloud to split into regions
370  * \param[in] normals are the normals of cloud
371  * \param[in] tolerance is the allowed Euclidean distance between points to be added to
372  * the cluster
373  * \param[in] tree is the spatial search structure for nearest neighbour search
374  * \param[out] clusters vector of indices representing the clustered regions
375  * \param[in] eps_angle deviation of the normals between two points so they can be
376  * clustered together
377  * \param[in] min_pts_per_cluster minimum cluster size. (default: 1 point)
378  * \param[in] max_pts_per_cluster maximum cluster size. (default: all the points)
379  */
380  void
381  extractEuclideanClustersSmooth (const pcl::PointCloud<pcl::PointNormal> &cloud, const pcl::PointCloud<pcl::PointNormal> &normals,
382  float tolerance, const pcl::search::Search<pcl::PointNormal>::Ptr &tree,
383  std::vector<pcl::PointIndices> &clusters, double eps_angle, unsigned int min_pts_per_cluster = 1,
384  unsigned int max_pts_per_cluster = (std::numeric_limits<int>::max) ());
385 
386  protected:
387  /** \brief Centroids that were used to compute different OUR-CVFH descriptors */
388  std::vector<Eigen::Vector3f> centroids_dominant_orientations_;
389  /** \brief Normal centroids that were used to compute different OUR-CVFH descriptors */
390  std::vector<Eigen::Vector3f> dominant_normals_;
391  /** \brief Indices to the points representing the stable clusters */
392  std::vector<pcl::PointIndices> clusters_;
393  };
394 }
395 
396 #ifdef PCL_NO_PRECOMPILE
397 #include <pcl/features/impl/our_cvfh.hpp>
398 #endif
399 
400 #endif //#ifndef PCL_FEATURES_VFH_H_
int k_
The number of K nearest neighbors to use for each point.
Definition: feature.h:242
void setNormalizeBins(bool normalize)
Sets wether if the signatures should be normalized or not.
Definition: our_cvfh.h:251
void compute(PointCloudOut &output)
Overloaded computed method from pcl::Feature.
Definition: our_cvfh.hpp:52
void getViewPoint(float &vpx, float &vpy, float &vpz)
Get the viewpoint.
Definition: our_cvfh.h:183
boost::shared_ptr< pcl::search::Search< PointT > > Ptr
Definition: search.h:80
boost::shared_ptr< const OURCVFHEstimation< PointInT, PointNT, PointOutT > > ConstPtr
Definition: our_cvfh.h:66
Feature< PointInT, PointOutT >::PointCloudOut PointCloudOut
Definition: our_cvfh.h:75
std::vector< Eigen::Vector3f > centroids_dominant_orientations_
Centroids that were used to compute different OUR-CVFH descriptors.
Definition: our_cvfh.h:388
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: our_cvfh.hpp:161
std::string feature_name_
The feature name.
Definition: feature.h:222
boost::shared_ptr< OURCVFHEstimation< PointInT, PointNT, PointOutT > > Ptr
Definition: our_cvfh.h:65
void setRadiusNormals(float radius_normals)
Set the radius used to compute normals.
Definition: our_cvfh.h:172
void setViewPoint(float vpx, float vpy, float vpz)
Set the viewpoint.
Definition: our_cvfh.h:161
void getCentroidNormalClusters(std::vector< Eigen::Vector3f > &centroids)
Get the normal centroids used to compute different CVFH descriptors.
Definition: our_cvfh.h:204
void setMinPoints(size_t min)
Set minimum amount of points for a cluster to be considered.
Definition: our_cvfh.h:242
void setMinAxisValue(float f)
Sets the min disambiguition axis value to generate several SGURFs for the cluster when disambiguition...
Definition: our_cvfh.h:306
OURCVFHEstimation estimates the Oriented, Unique and Repetable Clustered Viewpoint Feature Histogram ...
Definition: our_cvfh.h:62
OURCVFHEstimation()
Empty constructor.
Definition: our_cvfh.h:79
void setCurvatureThreshold(float d)
Sets curvature threshold for removing normals.
Definition: our_cvfh.h:233
void setEPSAngleThreshold(float d)
Sets max.
Definition: our_cvfh.h:224
std::vector< Eigen::Vector3f > dominant_normals_
Normal centroids that were used to compute different OUR-CVFH descriptors.
Definition: our_cvfh.h:390
std::vector< pcl::PointIndices > clusters_
Indices to the points representing the stable clusters.
Definition: our_cvfh.h:392
double search_radius_
The nearest neighbors search radius for each point.
Definition: feature.h:239
void setClusterTolerance(float d)
Sets max.
Definition: our_cvfh.h:215
bool sgurf(Eigen::Vector3f &centroid, Eigen::Vector3f &normal_centroid, PointInTPtr &processed, std::vector< Eigen::Matrix4f, Eigen::aligned_allocator< Eigen::Matrix4f > > &transformations, PointInTPtr &grid, pcl::PointIndices &indices)
Computes SGURF.
Definition: our_cvfh.hpp:191
void setAxisRatio(float f)
Sets the min axis ratio between the SGURF axes to decide if disambiguition is feasible.
Definition: our_cvfh.h:297
void getCentroidClusters(std::vector< Eigen::Vector3f > &centroids)
Get the centroids used to compute different CVFH descriptors.
Definition: our_cvfh.h:194
Feature represents the base feature class.
Definition: feature.h:105
void getClusterIndices(std::vector< pcl::PointIndices > &indices)
Gets the indices of the original point cloud used to compute the signatures.
Definition: our_cvfh.h:260
Eigen::Matrix4f createTransFromAxes(Eigen::Vector3f &evx, Eigen::Vector3f &evy, Eigen::Vector3f &evz, Eigen::Affine3f &transformPC, Eigen::Matrix4f &center_mat)
Creates an affine transformation from the RF axes.
Definition: our_cvfh.h:101
boost::shared_ptr< PointCloud< PointT > > Ptr
Definition: point_cloud.h:428
pcl::search::Search< PointNormal >::Ptr KdTreePtr
Definition: our_cvfh.h:76
void getValidTransformsVec(std::vector< bool > &valid)
Returns a boolean vector indicating of the transformation obtained by getTransforms() represents a va...
Definition: our_cvfh.h:288
PointCloud represents the base class in PCL for storing collections of 3D points. ...
void setRefineClusters(float rc)
Sets the refinement factor for the clusters.
Definition: our_cvfh.h:269
pcl::PointCloud< PointInT >::Ptr PointInTPtr
Definition: our_cvfh.h:77
void computeRFAndShapeDistribution(PointInTPtr &processed, PointCloudOut &output, std::vector< pcl::PointIndices > &cluster_indices)
Computes SGURF and the shape distribution based on the selected SGURF.
Definition: our_cvfh.hpp:375
void getTransforms(std::vector< Eigen::Matrix4f, Eigen::aligned_allocator< Eigen::Matrix4f > > &trans)
Returns the transformations aligning the point cloud to the corresponding SGURF.
Definition: our_cvfh.h:278