Point Cloud Library (PCL)  1.4.0
 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 3755 2011-12-31 23:45:30Z rusu $
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 
00098   template <typename PointInT, typename PointNT, typename PointOutT>
00099   class PFHEstimation : public FeatureFromNormals<PointInT, PointNT, PointOutT>
00100   {
00101     public:
00102       using Feature<PointInT, PointOutT>::feature_name_;
00103       using Feature<PointInT, PointOutT>::getClassName;
00104       using Feature<PointInT, PointOutT>::indices_;
00105       using Feature<PointInT, PointOutT>::k_;
00106       using Feature<PointInT, PointOutT>::search_parameter_;
00107       using Feature<PointInT, PointOutT>::surface_;
00108       using Feature<PointInT, PointOutT>::input_;
00109       using FeatureFromNormals<PointInT, PointNT, PointOutT>::normals_;
00110 
00111       typedef typename Feature<PointInT, PointOutT>::PointCloudOut PointCloudOut;
00112       typedef typename Feature<PointInT, PointOutT>::PointCloudIn  PointCloudIn;
00113 
00117       PFHEstimation () : nr_subdiv_ (5), d_pi_ (1.0 / (2.0 * M_PI)), use_cache_ (false)
00118       {
00119         feature_name_ = "PFHEstimation";
00120 
00121         // Default 1GB memory size. Need to set it to something more conservative.
00122         max_cache_size_ = (1ul*1024ul*1024ul*1024ul) / sizeof (std::pair<std::pair<int, int>, Eigen::Vector4f>);
00123       };
00124 
00128       inline void
00129       setMaximumCacheSize (unsigned int cache_size)
00130       {
00131         max_cache_size_ = cache_size;
00132       }
00133 
00135       inline unsigned int 
00136       getMaximumCacheSize ()
00137       {
00138         return (max_cache_size_);
00139       }
00140 
00152       inline void
00153       setUseInternalCache (bool use_cache)
00154       {
00155         use_cache_ = use_cache;
00156       }
00157 
00159       inline bool
00160       getUseInternalCache ()
00161       {
00162         return (use_cache_);
00163       }
00164 
00179       bool 
00180       computePairFeatures (const pcl::PointCloud<PointInT> &cloud, const pcl::PointCloud<PointNT> &normals, 
00181                            int p_idx, int q_idx, float &f1, float &f2, float &f3, float &f4);
00182 
00191       void 
00192       computePointPFHSignature (const pcl::PointCloud<PointInT> &cloud, const pcl::PointCloud<PointNT> &normals, 
00193                                 const std::vector<int> &indices, int nr_split, Eigen::VectorXf &pfh_histogram);
00194 
00195     protected:
00201       void 
00202       computeFeature (PointCloudOut &output);
00203 
00205       int nr_subdiv_;
00206 
00208       Eigen::VectorXf pfh_histogram_;
00209 
00211       Eigen::Vector4f pfh_tuple_;
00212 
00214       int f_index_[3];
00215 
00217       float d_pi_; 
00218 
00220       std::map<std::pair<int, int>, Eigen::Vector4f, std::less<std::pair<int, int> >, Eigen::aligned_allocator<Eigen::Vector4f> > feature_map_;
00221 
00223       std::queue<std::pair<int, int> > key_list_;
00224 
00226       unsigned int max_cache_size_;
00227 
00229       bool use_cache_;
00230     private:
00234       void 
00235       computeFeature (pcl::PointCloud<Eigen::MatrixXf> &output) {}
00236   };
00237 
00266   template <typename PointInT, typename PointNT>
00267   class PFHEstimation<PointInT, PointNT, Eigen::MatrixXf> : public PFHEstimation<PointInT, PointNT, pcl::PFHSignature125>
00268   {
00269     public:
00270       using PFHEstimation<PointInT, PointNT, pcl::PFHSignature125>::pfh_histogram_;
00271       using PFHEstimation<PointInT, PointNT, pcl::PFHSignature125>::nr_subdiv_;
00272       using PFHEstimation<PointInT, PointNT, pcl::PFHSignature125>::k_;
00273       using PFHEstimation<PointInT, PointNT, pcl::PFHSignature125>::indices_;
00274       using PFHEstimation<PointInT, PointNT, pcl::PFHSignature125>::search_parameter_;
00275       using PFHEstimation<PointInT, PointNT, pcl::PFHSignature125>::surface_;
00276       using PFHEstimation<PointInT, PointNT, pcl::PFHSignature125>::input_;
00277       using PFHEstimation<PointInT, PointNT, pcl::PFHSignature125>::normals_;
00278       using PFHEstimation<PointInT, PointNT, pcl::PFHSignature125>::computePointPFHSignature;
00279       using PFHEstimation<PointInT, PointNT, pcl::PFHSignature125>::compute;
00280       using PFHEstimation<PointInT, PointNT, pcl::PFHSignature125>::feature_map_;
00281       using PFHEstimation<PointInT, PointNT, pcl::PFHSignature125>::key_list_;
00282 
00283     private:
00289       void 
00290       computeFeature (pcl::PointCloud<Eigen::MatrixXf> &output);
00291 
00295       void 
00296       compute (pcl::PointCloud<pcl::PFHSignature125> &output) {}
00297    };
00298 }
00299 
00300 #endif  //#ifndef PCL_PFH_H_
00301 
00302 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines