Point Cloud Library (PCL)  1.4.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
fpfh.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: fpfh.h 3755 2011-12-31 23:45:30Z rusu $
00037  *
00038  */
00039 
00040 #ifndef PCL_FPFH_H_
00041 #define PCL_FPFH_H_
00042 
00043 #include <pcl/features/feature.h>
00044 #include <set>
00045 
00046 namespace pcl
00047 {
00076   template <typename PointInT, typename PointNT, typename PointOutT>
00077   class FPFHEstimation : public FeatureFromNormals<PointInT, PointNT, PointOutT>
00078   {
00079     public:
00080       using Feature<PointInT, PointOutT>::feature_name_;
00081       using Feature<PointInT, PointOutT>::getClassName;
00082       using Feature<PointInT, PointOutT>::indices_;
00083       using Feature<PointInT, PointOutT>::k_;
00084       using Feature<PointInT, PointOutT>::search_parameter_;
00085       using Feature<PointInT, PointOutT>::input_;
00086       using Feature<PointInT, PointOutT>::surface_;
00087       using FeatureFromNormals<PointInT, PointNT, PointOutT>::normals_;
00088 
00089       typedef typename Feature<PointInT, PointOutT>::PointCloudOut PointCloudOut;
00090 
00092       FPFHEstimation () : nr_bins_f1_ (11), nr_bins_f2_ (11), nr_bins_f3_ (11), d_pi_ ((float)(1.0 / (2.0 * M_PI)))
00093       {
00094         feature_name_ = "FPFHEstimation";
00095       };
00096 
00110       bool 
00111       computePairFeatures (const pcl::PointCloud<PointInT> &cloud, const pcl::PointCloud<PointNT> &normals, 
00112                            int p_idx, int q_idx, float &f1, float &f2, float &f3, float &f4);
00113 
00125       void 
00126       computePointSPFHSignature (const pcl::PointCloud<PointInT> &cloud, 
00127                                  const pcl::PointCloud<PointNT> &normals, int p_idx, int row, 
00128                                  const std::vector<int> &indices, 
00129                                  Eigen::MatrixXf &hist_f1, Eigen::MatrixXf &hist_f2, Eigen::MatrixXf &hist_f3);
00130 
00140       void 
00141       weightPointSPFHSignature (const Eigen::MatrixXf &hist_f1, 
00142                                 const Eigen::MatrixXf &hist_f2, 
00143                                 const Eigen::MatrixXf &hist_f3, 
00144                                 const std::vector<int> &indices, 
00145                                 const std::vector<float> &dists, 
00146                                 Eigen::VectorXf &fpfh_histogram);
00147 
00153       inline void
00154       setNrSubdivisions (int nr_bins_f1, int nr_bins_f2, int nr_bins_f3)
00155       {
00156         nr_bins_f1_ = nr_bins_f1;
00157         nr_bins_f2_ = nr_bins_f2;
00158         nr_bins_f3_ = nr_bins_f3;
00159       }
00160 
00166       inline void
00167       getNrSubdivisions (int &nr_bins_f1, int &nr_bins_f2, int &nr_bins_f3)
00168       {
00169         nr_bins_f1 = nr_bins_f1_;
00170         nr_bins_f2 = nr_bins_f2_;
00171         nr_bins_f3 = nr_bins_f3_;
00172       }
00173 
00174     protected:
00175 
00182       void 
00183       computeSPFHSignatures (std::vector<int> &spf_hist_lookup, 
00184                              Eigen::MatrixXf &hist_f1, Eigen::MatrixXf &hist_f2, Eigen::MatrixXf &hist_f3);
00185 
00191       void 
00192       computeFeature (PointCloudOut &output);
00193 
00195       int nr_bins_f1_, nr_bins_f2_, nr_bins_f3_;
00196 
00198       Eigen::MatrixXf hist_f1_;
00199 
00201       Eigen::MatrixXf hist_f2_;
00202 
00204       Eigen::MatrixXf hist_f3_;
00205 
00207       Eigen::VectorXf fpfh_histogram_;
00208 
00210       float d_pi_; 
00211 
00212     private:
00216       void 
00217       computeFeature (pcl::PointCloud<Eigen::MatrixXf> &output) {}
00218   };
00219 
00248   template <typename PointInT, typename PointNT>
00249   class FPFHEstimation<PointInT, PointNT, Eigen::MatrixXf> : public FPFHEstimation<PointInT, PointNT, pcl::FPFHSignature33>
00250   {
00251     public:
00252       using FPFHEstimation<PointInT, PointNT, pcl::FPFHSignature33>::k_;
00253       using FPFHEstimation<PointInT, PointNT, pcl::FPFHSignature33>::nr_bins_f1_;
00254       using FPFHEstimation<PointInT, PointNT, pcl::FPFHSignature33>::nr_bins_f2_;
00255       using FPFHEstimation<PointInT, PointNT, pcl::FPFHSignature33>::nr_bins_f3_;
00256       using FPFHEstimation<PointInT, PointNT, pcl::FPFHSignature33>::hist_f1_;
00257       using FPFHEstimation<PointInT, PointNT, pcl::FPFHSignature33>::hist_f2_;
00258       using FPFHEstimation<PointInT, PointNT, pcl::FPFHSignature33>::hist_f3_;
00259       using FPFHEstimation<PointInT, PointNT, pcl::FPFHSignature33>::indices_;
00260       using FPFHEstimation<PointInT, PointNT, pcl::FPFHSignature33>::search_parameter_;
00261       using FPFHEstimation<PointInT, PointNT, pcl::FPFHSignature33>::input_;
00262       using FPFHEstimation<PointInT, PointNT, pcl::FPFHSignature33>::compute;
00263       using FPFHEstimation<PointInT, PointNT, pcl::FPFHSignature33>::fpfh_histogram_;
00264 
00265     private:
00271       void 
00272       computeFeature (pcl::PointCloud<Eigen::MatrixXf> &output);
00273 
00277       void 
00278       compute (pcl::PointCloud<pcl::FPFHSignature33> &output) {}
00279   };
00280 }
00281 
00282 #endif  //#ifndef PCL_FPFH_H_
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines