Point Cloud Library (PCL)  1.3.1
vfh.h
Go to the documentation of this file.
00001 /*
00002  * Software License Agreement (BSD License)
00003  *
00004  *  Copyright (c) 2009, Willow Garage, Inc.
00005  *  All rights reserved.
00006  *
00007  *  Redistribution and use in source and binary forms, with or without
00008  *  modification, are permitted provided that the following conditions
00009  *  are met:
00010  *
00011  *   * Redistributions of source code must retain the above copyright
00012  *     notice, this list of conditions and the following disclaimer.
00013  *   * Redistributions in binary form must reproduce the above
00014  *     copyright notice, this list of conditions and the following
00015  *     disclaimer in the documentation and/or other materials provided
00016  *     with the distribution.
00017  *   * Neither the name of Willow Garage, Inc. nor the names of its
00018  *     contributors may be used to endorse or promote products derived
00019  *     from this software without specific prior written permission.
00020  *
00021  *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
00022  *  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
00023  *  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
00024  *  FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
00025  *  COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
00026  *  INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
00027  *  BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
00028  *  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
00029  *  CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
00030  *  LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
00031  *  ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
00032  *  POSSIBILITY OF SUCH DAMAGE.
00033  *
00034  * $Id: vfh.h 1370 2011-06-19 01:06:01Z jspricke $
00035  *
00036  */
00037 
00038 #ifndef PCL_FEATURES_VFH_H_
00039 #define PCL_FEATURES_VFH_H_
00040 
00041 #include <pcl/features/feature.h>
00042 
00043 namespace pcl
00044 {
00063   template<typename PointInT, typename PointNT, typename PointOutT>
00064   class VFHEstimation : public FeatureFromNormals<PointInT, PointNT, PointOutT>
00065   {
00066   public:
00067     using Feature<PointInT, PointOutT>::feature_name_;
00068     using Feature<PointInT, PointOutT>::getClassName;
00069     using Feature<PointInT, PointOutT>::indices_;
00070     using Feature<PointInT, PointOutT>::k_;
00071     using Feature<PointInT, PointOutT>::search_radius_;
00072     using Feature<PointInT, PointOutT>::surface_;
00073     using FeatureFromNormals<PointInT, PointNT, PointOutT>::normals_;
00074 
00075     typedef typename Feature<PointInT, PointOutT>::PointCloudOut PointCloudOut;
00076 
00078     VFHEstimation () :
00079       nr_bins_f1_ (45), nr_bins_f2_ (45), nr_bins_f3_ (45), nr_bins_f4_ (45), nr_bins_vp_ (128), vpx_ (0), vpy_ (0),
00080           vpz_ (0), d_pi_ (1.0 / (2.0 * M_PI))
00081     {
00082       hist_f1_.setZero (nr_bins_f1_);
00083       hist_f2_.setZero (nr_bins_f2_);
00084       hist_f3_.setZero (nr_bins_f3_);
00085       hist_f4_.setZero (nr_bins_f4_);
00086       search_radius_ = 0;
00087       k_ = 1;
00088       feature_name_ = "VFHEstimation";
00089 
00090       //default parameters to compute VFH
00091       use_given_normal_ = false;
00092       use_given_centroid_ = false;
00093       normalize_bins_ = true;
00094       normalize_distances_ = false;
00095       size_component_ = false;
00096     }
00097     ;
00098 
00107     void
00108     computePointSPFHSignature (const Eigen::Vector4f &centroid_p, const Eigen::Vector4f &centroid_n,
00109                                const pcl::PointCloud<PointInT> &cloud, const pcl::PointCloud<PointNT> &normals,
00110                                const std::vector<int> &indices);
00111 
00117     inline void
00118     setViewPoint (float vpx, float vpy, float vpz)
00119     {
00120       vpx_ = vpx;
00121       vpy_ = vpy;
00122       vpz_ = vpz;
00123     }
00124 
00126     inline void
00127     getViewPoint (float &vpx, float &vpy, float &vpz)
00128     {
00129       vpx = vpx_;
00130       vpy = vpy_;
00131       vpz = vpz_;
00132     }
00133 
00137     inline void
00138     setUseGivenNormal (bool use)
00139     {
00140       use_given_normal_ = use;
00141     }
00142 
00147     inline void
00148     setNormalToUse (Eigen::Vector3f normal)
00149     {
00150       normal_to_use_ = Eigen::Vector4f (normal[0], normal[1], normal[2], 0);
00151     }
00152 
00156     inline void
00157     setUseGivenCentroid (bool use)
00158     {
00159       use_given_centroid_ = use;
00160     }
00161 
00166     inline void
00167     setCentroidToUse (Eigen::Vector3f centroid)
00168     {
00169       centroid_to_use_ = Eigen::Vector4f (centroid[0], centroid[1], centroid[2], 0);
00170     }
00171 
00175     inline void
00176     setNormalizeBins (bool normalize)
00177     {
00178       normalize_bins_ = normalize;
00179     }
00180 
00185     inline void
00186     setNormalizeDistance (bool normalize)
00187     {
00188       normalize_distances_ = normalize;
00189     }
00190 
00195     inline void
00196     setFillSizeComponent (bool fill_size)
00197     {
00198       size_component_ = fill_size;
00199     }
00200 
00201   private:
00202 
00204     int nr_bins_f1_, nr_bins_f2_, nr_bins_f3_, nr_bins_f4_, nr_bins_vp_;
00205 
00208     float vpx_, vpy_, vpz_;
00209 
00215     void
00216     computeFeature (PointCloudOut &output);
00217 
00218   protected:
00220     Eigen::VectorXf hist_f1_;
00222     Eigen::VectorXf hist_f2_;
00224     Eigen::VectorXf hist_f3_;
00226     Eigen::VectorXf hist_f4_;
00228     Eigen::VectorXf hist_vp_;
00229 
00231     Eigen::Vector4f normal_to_use_;
00233     Eigen::Vector4f centroid_to_use_;
00234 
00235     // VFH configuration parameters because CVFH instantiates it. See constructor for default values.
00236 
00238     bool use_given_normal_;
00240     bool use_given_centroid_;
00242     bool normalize_bins_;
00244     bool normalize_distances_;
00246     bool size_component_;
00247 
00248   private:
00250     float d_pi_;
00251   };
00252 }
00253 
00254 #endif  //#ifndef PCL_FEATURES_VFH_H_
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines