Point Cloud Library (PCL)  1.5.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
pfh.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: pfh.h 4702 2012-02-23 09:39:33Z gedikli $
00037  *
00038  */
00039 
00040 #ifndef PCL_PFH_H_
00041 #define PCL_PFH_H_
00042 
00043 #include <pcl/point_types.h>
00044 #include <pcl/features/feature.h>
00045 #include <map>
00046 
00047 namespace pcl
00048 {
00065   PCL_EXPORTS bool 
00066   computePairFeatures (const Eigen::Vector4f &p1, const Eigen::Vector4f &n1, 
00067                        const Eigen::Vector4f &p2, const Eigen::Vector4f &n2, 
00068                        float &f1, float &f2, float &f3, float &f4);
00069 
00100   template <typename PointInT, typename PointNT, typename PointOutT = pcl::PFHSignature125>
00101   class PFHEstimation : public FeatureFromNormals<PointInT, PointNT, PointOutT>
00102   {
00103     public:
00104       using Feature<PointInT, PointOutT>::feature_name_;
00105       using Feature<PointInT, PointOutT>::getClassName;
00106       using Feature<PointInT, PointOutT>::indices_;
00107       using Feature<PointInT, PointOutT>::k_;
00108       using Feature<PointInT, PointOutT>::search_parameter_;
00109       using Feature<PointInT, PointOutT>::surface_;
00110       using Feature<PointInT, PointOutT>::input_;
00111       using FeatureFromNormals<PointInT, PointNT, PointOutT>::normals_;
00112 
00113       typedef typename Feature<PointInT, PointOutT>::PointCloudOut PointCloudOut;
00114       typedef typename Feature<PointInT, PointOutT>::PointCloudIn  PointCloudIn;
00115 
00119       PFHEstimation () : nr_subdiv_ (5), d_pi_ (1.0 / (2.0 * M_PI)), use_cache_ (false)
00120       {
00121         feature_name_ = "PFHEstimation";
00122 
00123         // Default 1GB memory size. Need to set it to something more conservative.
00124         max_cache_size_ = (1ul*1024ul*1024ul*1024ul) / sizeof (std::pair<std::pair<int, int>, Eigen::Vector4f>);
00125       };
00126 
00130       inline void
00131       setMaximumCacheSize (unsigned int cache_size)
00132       {
00133         max_cache_size_ = cache_size;
00134       }
00135 
00137       inline unsigned int 
00138       getMaximumCacheSize ()
00139       {
00140         return (max_cache_size_);
00141       }
00142 
00154       inline void
00155       setUseInternalCache (bool use_cache)
00156       {
00157         use_cache_ = use_cache;
00158       }
00159 
00161       inline bool
00162       getUseInternalCache ()
00163       {
00164         return (use_cache_);
00165       }
00166 
00181       bool 
00182       computePairFeatures (const pcl::PointCloud<PointInT> &cloud, const pcl::PointCloud<PointNT> &normals, 
00183                            int p_idx, int q_idx, float &f1, float &f2, float &f3, float &f4);
00184 
00193       void 
00194       computePointPFHSignature (const pcl::PointCloud<PointInT> &cloud, const pcl::PointCloud<PointNT> &normals, 
00195                                 const std::vector<int> &indices, int nr_split, Eigen::VectorXf &pfh_histogram);
00196 
00197     protected:
00203       void 
00204       computeFeature (PointCloudOut &output);
00205 
00207       int nr_subdiv_;
00208 
00210       Eigen::VectorXf pfh_histogram_;
00211 
00213       Eigen::Vector4f pfh_tuple_;
00214 
00216       int f_index_[3];
00217 
00219       float d_pi_; 
00220 
00222       std::map<std::pair<int, int>, Eigen::Vector4f, std::less<std::pair<int, int> >, Eigen::aligned_allocator<Eigen::Vector4f> > feature_map_;
00223 
00225       std::queue<std::pair<int, int> > key_list_;
00226 
00228       unsigned int max_cache_size_;
00229 
00231       bool use_cache_;
00232     private:
00236       void 
00237       computeFeatureEigen (pcl::PointCloud<Eigen::MatrixXf> &output) {}
00238   };
00239 
00268   template <typename PointInT, typename PointNT>
00269   class PFHEstimation<PointInT, PointNT, Eigen::MatrixXf> : public PFHEstimation<PointInT, PointNT, pcl::PFHSignature125>
00270   {
00271     public:
00272       using PFHEstimation<PointInT, PointNT, pcl::PFHSignature125>::pfh_histogram_;
00273       using PFHEstimation<PointInT, PointNT, pcl::PFHSignature125>::nr_subdiv_;
00274       using PFHEstimation<PointInT, PointNT, pcl::PFHSignature125>::k_;
00275       using PFHEstimation<PointInT, PointNT, pcl::PFHSignature125>::indices_;
00276       using PFHEstimation<PointInT, PointNT, pcl::PFHSignature125>::search_parameter_;
00277       using PFHEstimation<PointInT, PointNT, pcl::PFHSignature125>::surface_;
00278       using PFHEstimation<PointInT, PointNT, pcl::PFHSignature125>::input_;
00279       using PFHEstimation<PointInT, PointNT, pcl::PFHSignature125>::normals_;
00280       using PFHEstimation<PointInT, PointNT, pcl::PFHSignature125>::computePointPFHSignature;
00281       using PFHEstimation<PointInT, PointNT, pcl::PFHSignature125>::compute;
00282       using PFHEstimation<PointInT, PointNT, pcl::PFHSignature125>::feature_map_;
00283       using PFHEstimation<PointInT, PointNT, pcl::PFHSignature125>::key_list_;
00284 
00285     private:
00291       void 
00292       computeFeatureEigen (pcl::PointCloud<Eigen::MatrixXf> &output);
00293 
00297       void 
00298       compute (pcl::PointCloud<pcl::PFHSignature125> &output) {}
00299    };
00300 }
00301 
00302 #endif  //#ifndef PCL_PFH_H_
00303 
00304