Point Cloud Library (PCL)  1.4.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
vfh.h
Go to the documentation of this file.
00001 /*
00002  * Software License Agreement (BSD License)
00003  *
00004  *  Point Cloud Library (PCL) - www.pointclouds.org
00005  *  Copyright (c) 2010-2011, Willow Garage, Inc.
00006  *
00007  *  All rights reserved.
00008  *
00009  *  Redistribution and use in source and binary forms, with or without
00010  *  modification, are permitted provided that the following conditions
00011  *  are met:
00012  *
00013  *   * Redistributions of source code must retain the above copyright
00014  *     notice, this list of conditions and the following disclaimer.
00015  *   * Redistributions in binary form must reproduce the above
00016  *     copyright notice, this list of conditions and the following
00017  *     disclaimer in the documentation and/or other materials provided
00018  *     with the distribution.
00019  *   * Neither the name of Willow Garage, Inc. nor the names of its
00020  *     contributors may be used to endorse or promote products derived
00021  *     from this software without specific prior written permission.
00022  *
00023  *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
00024  *  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
00025  *  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
00026  *  FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
00027  *  COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
00028  *  INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
00029  *  BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
00030  *  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
00031  *  CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
00032  *  LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
00033  *  ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
00034  *  POSSIBILITY OF SUCH DAMAGE.
00035  *
00036  * $Id: vfh.h 3755 2011-12-31 23:45:30Z rusu $
00037  *
00038  */
00039 
00040 #ifndef PCL_FEATURES_VFH_H_
00041 #define PCL_FEATURES_VFH_H_
00042 
00043 #include <pcl/point_types.h>
00044 #include <pcl/features/feature.h>
00045 
00046 namespace pcl
00047 {
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 (const 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 (const 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 
00209       float vpx_, vpy_, vpz_;
00210 
00216       void
00217       computeFeature (PointCloudOut &output);
00218 
00219     protected:
00221       Eigen::VectorXf hist_f1_;
00223       Eigen::VectorXf hist_f2_;
00225       Eigen::VectorXf hist_f3_;
00227       Eigen::VectorXf hist_f4_;
00229       Eigen::VectorXf hist_vp_;
00230 
00232       Eigen::Vector4f normal_to_use_;
00234       Eigen::Vector4f centroid_to_use_;
00235 
00236       // VFH configuration parameters because CVFH instantiates it. See constructor for default values.
00237 
00239       bool use_given_normal_;
00241       bool use_given_centroid_;
00243       bool normalize_bins_;
00245       bool normalize_distances_;
00247       bool size_component_;
00248 
00249     private:
00251       float d_pi_;
00252 
00256       void 
00257       computeFeature (pcl::PointCloud<Eigen::MatrixXf> &output) {}
00258   };
00259 
00275 //  template<typename PointInT, typename PointNT>
00276 //  class VFHEstimation<PointInT, PointNT, Eigen::MatrixXf> : public VFHEstimation<PointInT, PointNT, pcl::VFHSignature263>
00277 //  {
00278 //    public:
00286 //
00287 //    private:
00288 //      /** \brief Estimate the Viewpoint Feature Histograms (VFH) descriptors at a set of points given by
00289 //        * <setInputCloud (), setIndices ()> using the surface in setSearchSurface () and the spatial locator in
00290 //        * setSearchMethod ()
00291 //        * \param[out] output the resultant point cloud model dataset that contains the VFH feature estimates
00292 //        */
00293 //      void
00294 //      computeFeature (pcl::PointCloud<Eigen::MatrixXf> &output);
00295 //
00296 //      /** \brief Make the compute (&PointCloudOut); inaccessible from outside the class
00297 //        * \param[out] output the output point cloud 
00298 //        */
00299 //      void 
00300 //      compute (pcl::PointCloud<pcl::Normal> &output) {}
00301 //  };
00302 }
00303 
00304 #endif  //#ifndef PCL_FEATURES_VFH_H_
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines