Point Cloud Library (PCL)  1.6.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
vfh.h
Go to the documentation of this file.
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: vfh.h 6144 2012-07-04 22:06:28Z rusu $
38  *
39  */
40 
41 #ifndef PCL_FEATURES_VFH_H_
42 #define PCL_FEATURES_VFH_H_
43 
44 #include <pcl/point_types.h>
45 #include <pcl/features/feature.h>
46 
47 namespace pcl
48 {
70  template<typename PointInT, typename PointNT, typename PointOutT = pcl::VFHSignature308>
71  class VFHEstimation : public FeatureFromNormals<PointInT, PointNT, PointOutT>
72  {
73  public:
82 
84  typedef typename boost::shared_ptr<VFHEstimation<PointInT, PointNT, PointOutT> > Ptr;
85  typedef typename boost::shared_ptr<const VFHEstimation<PointInT, PointNT, PointOutT> > ConstPtr;
86 
87 
90  nr_bins_f1_ (45), nr_bins_f2_ (45), nr_bins_f3_ (45), nr_bins_f4_ (45), nr_bins_vp_ (128),
91  vpx_ (0), vpy_ (0), vpz_ (0),
92  hist_f1_ (), hist_f2_ (), hist_f3_ (), hist_f4_ (), hist_vp_ (),
93  normal_to_use_ (), centroid_to_use_ (), use_given_normal_ (false), use_given_centroid_ (false),
94  normalize_bins_ (true), normalize_distances_ (false), size_component_ (false),
95  d_pi_ (1.0f / (2.0f * static_cast<float> (M_PI)))
96  {
97  hist_f1_.setZero (nr_bins_f1_);
98  hist_f2_.setZero (nr_bins_f2_);
99  hist_f3_.setZero (nr_bins_f3_);
100  hist_f4_.setZero (nr_bins_f4_);
101  search_radius_ = 0;
102  k_ = 0;
103  feature_name_ = "VFHEstimation";
104  }
105 
114  void
115  computePointSPFHSignature (const Eigen::Vector4f &centroid_p, const Eigen::Vector4f &centroid_n,
116  const pcl::PointCloud<PointInT> &cloud, const pcl::PointCloud<PointNT> &normals,
117  const std::vector<int> &indices);
118 
124  inline void
125  setViewPoint (float vpx, float vpy, float vpz)
126  {
127  vpx_ = vpx;
128  vpy_ = vpy;
129  vpz_ = vpz;
130  }
131 
133  inline void
134  getViewPoint (float &vpx, float &vpy, float &vpz)
135  {
136  vpx = vpx_;
137  vpy = vpy_;
138  vpz = vpz_;
139  }
140 
144  inline void
145  setUseGivenNormal (bool use)
146  {
147  use_given_normal_ = use;
148  }
149 
154  inline void
155  setNormalToUse (const Eigen::Vector3f &normal)
156  {
157  normal_to_use_ = Eigen::Vector4f (normal[0], normal[1], normal[2], 0);
158  }
159 
163  inline void
165  {
166  use_given_centroid_ = use;
167  }
168 
173  inline void
174  setCentroidToUse (const Eigen::Vector3f &centroid)
175  {
176  centroid_to_use_ = Eigen::Vector4f (centroid[0], centroid[1], centroid[2], 0);
177  }
178 
182  inline void
183  setNormalizeBins (bool normalize)
184  {
185  normalize_bins_ = normalize;
186  }
187 
192  inline void
193  setNormalizeDistance (bool normalize)
194  {
195  normalize_distances_ = normalize;
196  }
197 
202  inline void
203  setFillSizeComponent (bool fill_size)
204  {
205  size_component_ = fill_size;
206  }
207 
211  void
212  compute (PointCloudOut &output);
213 
214  private:
215 
217  int nr_bins_f1_, nr_bins_f2_, nr_bins_f3_, nr_bins_f4_, nr_bins_vp_;
218 
222  float vpx_, vpy_, vpz_;
223 
229  void
230  computeFeature (PointCloudOut &output);
231 
232  protected:
234  bool
235  initCompute ();
236 
238  Eigen::VectorXf hist_f1_;
240  Eigen::VectorXf hist_f2_;
242  Eigen::VectorXf hist_f3_;
244  Eigen::VectorXf hist_f4_;
246  Eigen::VectorXf hist_vp_;
247 
249  Eigen::Vector4f normal_to_use_;
251  Eigen::Vector4f centroid_to_use_;
252 
253  // VFH configuration parameters because CVFH instantiates it. See constructor for default values.
254 
256  bool use_given_normal_;
258  bool use_given_centroid_;
260  bool normalize_bins_;
262  bool normalize_distances_;
264  bool size_component_;
265 
266  private:
268  float d_pi_;
269 
273  void
274  computeFeatureEigen (pcl::PointCloud<Eigen::MatrixXf> &) {}
275  };
276 
292 // template<typename PointInT, typename PointNT>
293 // class VFHEstimation<PointInT, PointNT, Eigen::MatrixXf> : public VFHEstimation<PointInT, PointNT, pcl::VFHSignature263>
294 // {
295 // public:
303 //
304 // private:
305 // /** \brief Estimate the Viewpoint Feature Histograms (VFH) descriptors at a set of points given by
306 // * <setInputCloud (), setIndices ()> using the surface in setSearchSurface () and the spatial locator in
307 // * setSearchMethod ()
308 // * \param[out] output the resultant point cloud model dataset that contains the VFH feature estimates
309 // */
310 // void
311 // computeFeature (pcl::PointCloud<Eigen::MatrixXf> &output);
312 //
313 // /** \brief Make the compute (&PointCloudOut); inaccessible from outside the class
314 // * \param[out] output the output point cloud
315 // */
316 // void
317 // compute (pcl::PointCloud<pcl::Normal> &output) {}
318 // };
319 }
320 
321 #endif //#ifndef PCL_FEATURES_VFH_H_