Point Cloud Library (PCL)  1.5.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
shot.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  *
00037  */
00038 
00039 #ifndef PCL_SHOT_H_
00040 #define PCL_SHOT_H_
00041 
00042 #include <pcl/point_types.h>
00043 #include <pcl/features/feature.h>
00044 
00045 namespace pcl
00046 {
00066   template <typename PointInT, typename PointNT, typename PointOutT = pcl::SHOT> 
00067   class SHOTEstimationBase : public FeatureFromNormals<PointInT, PointNT, PointOutT>
00068   {
00069     public:
00070       using Feature<PointInT, PointOutT>::feature_name_;
00071       using Feature<PointInT, PointOutT>::getClassName;
00072       using Feature<PointInT, PointOutT>::input_;
00073       using Feature<PointInT, PointOutT>::indices_;
00074       using Feature<PointInT, PointOutT>::k_;
00075       using Feature<PointInT, PointOutT>::search_parameter_;
00076       using Feature<PointInT, PointOutT>::search_radius_;
00077       using Feature<PointInT, PointOutT>::surface_;
00078       using FeatureFromNormals<PointInT, PointNT, PointOutT>::normals_;
00079 
00080       typedef typename Feature<PointInT, PointOutT>::PointCloudIn PointCloudIn;
00081 
00082     protected:
00086       SHOTEstimationBase (int nr_shape_bins = 10) :
00087         nr_shape_bins_ (nr_shape_bins),
00088         rf_ (3),                    // Initialize the placeholder for the point's RF
00089         nr_grid_sector_ (32),
00090         maxAngularSectors_ (28),
00091         descLength_ (0)
00092       {
00093         feature_name_ = "SHOTEstimation";
00094       };
00095 
00096     public:
00104       virtual void 
00105       computePointSHOT (const int index, 
00106                         const std::vector<int> &indices, 
00107                         const std::vector<float> &sqr_dists, 
00108                         Eigen::VectorXf &shot,
00109                         std::vector<Eigen::Vector4f, Eigen::aligned_allocator<Eigen::Vector4f> > &rf) = 0;
00110 
00111     protected:
00112 
00118       void 
00119       computeFeature (pcl::PointCloud<PointOutT> &output);
00120 
00131       void 
00132       interpolateSingleChannel (const std::vector<int> &indices,
00133                                 const std::vector<float> &sqr_dists, 
00134                                 const Eigen::Vector4f &centralPoint, 
00135                                 const std::vector<Eigen::Vector4f, Eigen::aligned_allocator<Eigen::Vector4f> > &rf,
00136                                 std::vector<double> &binDistance, 
00137                                 const int nr_bins,
00138                                 Eigen::VectorXf &shot);
00139 
00144       void
00145       normalizeHistogram (Eigen::VectorXf &shot, int desc_length);
00146 
00147 
00159       void
00160       createBinDistanceShape (int index, const std::vector<int> &indices, const std::vector<float> &sqr_dists,
00161                               const pcl::PointCloud<PointInT> &input,
00162                               const pcl::PointCloud<PointNT> &normals,
00163                               const pcl::PointCloud<PointInT> &surface,
00164                               double search_radius,
00165                               std::vector<double> &bin_distance_shape,
00166                               std::vector<Eigen::Vector4f, Eigen::aligned_allocator<Eigen::Vector4f> > &rf);
00167 
00169       const int nr_shape_bins_;
00170 
00172       Eigen::VectorXf shot_;
00173 
00175       std::vector<Eigen::Vector4f, Eigen::aligned_allocator<Eigen::Vector4f> > rf_;
00176 
00178       double sqradius_;
00179 
00181       double radius3_4_;
00182 
00184       double radius1_4_;
00185 
00187       double radius1_2_;
00188 
00190       const int nr_grid_sector_;
00191 
00193       const int maxAngularSectors_;
00194 
00196       int descLength_;
00197 
00201       void 
00202       computeFeatureEigen (pcl::PointCloud<Eigen::MatrixXf> &output) {}
00203   };
00204 
00222   template <typename PointInT, typename PointNT> 
00223   class SHOTEstimationBase<PointInT, PointNT, Eigen::MatrixXf> : public SHOTEstimationBase<PointInT, PointNT, pcl::SHOT>
00224   {
00225     public:
00226       using SHOTEstimationBase<PointInT, PointNT, pcl::SHOT>::input_;
00227       using SHOTEstimationBase<PointInT, PointNT, pcl::SHOT>::indices_;
00228       using SHOTEstimationBase<PointInT, PointNT, pcl::SHOT>::k_;
00229       using SHOTEstimationBase<PointInT, PointNT, pcl::SHOT>::search_parameter_;
00230       using SHOTEstimationBase<PointInT, PointNT, pcl::SHOT>::search_radius_;
00231       using SHOTEstimationBase<PointInT, PointNT, pcl::SHOT>::surface_;
00232       using SHOTEstimationBase<PointInT, PointNT, pcl::SHOT>::rf_;
00233       using SHOTEstimationBase<PointInT, PointNT, pcl::SHOT>::descLength_;
00234       using SHOTEstimationBase<PointInT, PointNT, pcl::SHOT>::nr_grid_sector_;
00235       using SHOTEstimationBase<PointInT, PointNT, pcl::SHOT>::nr_shape_bins_;
00236       using SHOTEstimationBase<PointInT, PointNT, pcl::SHOT>::sqradius_;
00237       using SHOTEstimationBase<PointInT, PointNT, pcl::SHOT>::radius3_4_;
00238       using SHOTEstimationBase<PointInT, PointNT, pcl::SHOT>::radius1_4_;
00239       using SHOTEstimationBase<PointInT, PointNT, pcl::SHOT>::radius1_2_;
00240       using SHOTEstimationBase<PointInT, PointNT, pcl::SHOT>::shot_;
00241 
00245       SHOTEstimationBase (int nr_shape_bins = 10) : SHOTEstimationBase<PointInT, PointNT, pcl::SHOT> (nr_shape_bins) {};
00246 
00252       void 
00253       computeFeatureEigen (pcl::PointCloud<Eigen::MatrixXf> &output);
00254 
00260       void 
00261       computeEigen (pcl::PointCloud<Eigen::MatrixXf> &output) 
00262       { 
00263         pcl::SHOTEstimationBase<PointInT, PointNT, pcl::SHOT>::computeEigen (output); 
00264       }
00265 
00269       void 
00270       compute (pcl::PointCloud<pcl::SHOT> &output) {}
00271   };
00272 
00290   template <typename PointInT, typename PointNT, typename PointOutT> 
00291   class SHOTEstimation : public SHOTEstimationBase<PointInT, PointNT, PointOutT>
00292   {
00293     public:
00294       using SHOTEstimationBase<PointInT, PointNT, PointOutT>::feature_name_;
00295       using SHOTEstimationBase<PointInT, PointNT, PointOutT>::getClassName;
00296       using SHOTEstimationBase<PointInT, PointNT, PointOutT>::indices_;
00297       using SHOTEstimationBase<PointInT, PointNT, PointOutT>::k_;
00298       using SHOTEstimationBase<PointInT, PointNT, PointOutT>::search_parameter_;
00299       using SHOTEstimationBase<PointInT, PointNT, PointOutT>::search_radius_;
00300       using SHOTEstimationBase<PointInT, PointNT, PointOutT>::surface_;
00301       using SHOTEstimationBase<PointInT, PointNT, PointOutT>::input_;
00302       using SHOTEstimationBase<PointInT, PointNT, PointOutT>::normals_;
00303       using SHOTEstimationBase<PointInT, PointNT, PointOutT>::descLength_;
00304       using SHOTEstimationBase<PointInT, PointNT, PointOutT>::nr_grid_sector_;
00305       using SHOTEstimationBase<PointInT, PointNT, PointOutT>::nr_shape_bins_;
00306       using SHOTEstimationBase<PointInT, PointNT, PointOutT>::sqradius_;
00307       using SHOTEstimationBase<PointInT, PointNT, PointOutT>::radius3_4_;
00308       using SHOTEstimationBase<PointInT, PointNT, PointOutT>::radius1_4_;
00309       using SHOTEstimationBase<PointInT, PointNT, PointOutT>::radius1_2_;
00310       using SHOTEstimationBase<PointInT, PointNT, PointOutT>::rf_;
00311       using SHOTEstimationBase<PointInT, PointNT, PointOutT>::maxAngularSectors_;
00312       using SHOTEstimationBase<PointInT, PointNT, PointOutT>::interpolateSingleChannel;
00313       using SHOTEstimationBase<PointInT, PointNT, PointOutT>::shot_;
00314 
00315       typedef typename Feature<PointInT, PointOutT>::PointCloudIn PointCloudIn;
00316 
00320       SHOTEstimation (int nr_shape_bins = 10) : SHOTEstimationBase<PointInT, PointNT, PointOutT> (nr_shape_bins)
00321       {
00322         feature_name_ = "SHOTEstimation";
00323       };
00324 
00332       void 
00333       computePointSHOT (const int index, 
00334                         const std::vector<int> &indices, 
00335                         const std::vector<float> &sqr_dists, 
00336                         Eigen::VectorXf &shot,
00337                         std::vector<Eigen::Vector4f, Eigen::aligned_allocator<Eigen::Vector4f> > &rf);
00338 
00339    };
00340 
00358   template <typename PointInT, typename PointNT> 
00359   class SHOTEstimation<PointInT, PointNT, Eigen::MatrixXf> : public SHOTEstimationBase<PointInT, PointNT, Eigen::MatrixXf>
00360   {
00361     public:
00362       using SHOTEstimationBase<PointInT, PointNT, Eigen::MatrixXf>::feature_name_;
00363       using SHOTEstimationBase<PointInT, PointNT, Eigen::MatrixXf>::getClassName;
00364       using SHOTEstimationBase<PointInT, PointNT, Eigen::MatrixXf>::indices_;
00365       using SHOTEstimationBase<PointInT, PointNT, Eigen::MatrixXf>::k_;
00366       using SHOTEstimationBase<PointInT, PointNT, Eigen::MatrixXf>::search_parameter_;
00367       using SHOTEstimationBase<PointInT, PointNT, Eigen::MatrixXf>::search_radius_;
00368       using SHOTEstimationBase<PointInT, PointNT, Eigen::MatrixXf>::surface_;
00369       using SHOTEstimationBase<PointInT, PointNT, Eigen::MatrixXf>::input_;
00370       using SHOTEstimationBase<PointInT, PointNT, Eigen::MatrixXf>::normals_;
00371       using SHOTEstimationBase<PointInT, PointNT, Eigen::MatrixXf>::descLength_;
00372       using SHOTEstimationBase<PointInT, PointNT, Eigen::MatrixXf>::nr_grid_sector_;
00373       using SHOTEstimationBase<PointInT, PointNT, Eigen::MatrixXf>::nr_shape_bins_;
00374       using SHOTEstimationBase<PointInT, PointNT, Eigen::MatrixXf>::sqradius_;
00375       using SHOTEstimationBase<PointInT, PointNT, Eigen::MatrixXf>::radius3_4_;
00376       using SHOTEstimationBase<PointInT, PointNT, Eigen::MatrixXf>::radius1_4_;
00377       using SHOTEstimationBase<PointInT, PointNT, Eigen::MatrixXf>::radius1_2_;
00378       using SHOTEstimationBase<PointInT, PointNT, Eigen::MatrixXf>::rf_;
00379       using SHOTEstimationBase<PointInT, PointNT, Eigen::MatrixXf>::maxAngularSectors_;
00380       using SHOTEstimationBase<PointInT, PointNT, Eigen::MatrixXf>::interpolateSingleChannel;
00381       using SHOTEstimationBase<PointInT, PointNT, Eigen::MatrixXf>::shot_;
00382 
00386       SHOTEstimation (int nr_shape_bins = 10) : SHOTEstimationBase<PointInT, PointNT, Eigen::MatrixXf> (nr_shape_bins)
00387       {
00388         feature_name_ = "SHOTEstimation";
00389       };
00390 
00398       void 
00399       computePointSHOT (const int index, 
00400                         const std::vector<int> &indices, 
00401                         const std::vector<float> &sqr_dists, 
00402                         Eigen::VectorXf &shot,
00403                         std::vector<Eigen::Vector4f, Eigen::aligned_allocator<Eigen::Vector4f> > &rf);
00404    };
00405 
00423   template <typename PointNT, typename PointOutT> 
00424   class SHOTEstimation<pcl::PointXYZRGBA, PointNT, PointOutT> : public SHOTEstimationBase<pcl::PointXYZRGBA, PointNT, PointOutT>
00425   {
00426     public:
00427       using Feature<pcl::PointXYZRGBA, PointOutT>::feature_name_;
00428       using Feature<pcl::PointXYZRGBA, PointOutT>::getClassName;
00429       using Feature<pcl::PointXYZRGBA, PointOutT>::indices_;
00430       using Feature<pcl::PointXYZRGBA, PointOutT>::k_;
00431       using Feature<pcl::PointXYZRGBA, PointOutT>::search_parameter_;
00432       using Feature<pcl::PointXYZRGBA, PointOutT>::search_radius_;
00433       using Feature<pcl::PointXYZRGBA, PointOutT>::surface_;
00434       using Feature<pcl::PointXYZRGBA, PointOutT>::input_;
00435       using FeatureFromNormals<pcl::PointXYZRGBA, PointNT, PointOutT>::normals_;
00436       using SHOTEstimationBase<pcl::PointXYZRGBA, PointNT, PointOutT>::descLength_;
00437       using SHOTEstimationBase<pcl::PointXYZRGBA, PointNT, PointOutT>::nr_grid_sector_;
00438       using SHOTEstimationBase<pcl::PointXYZRGBA, PointNT, PointOutT>::nr_shape_bins_;
00439       using SHOTEstimationBase<pcl::PointXYZRGBA, PointNT, PointOutT>::sqradius_;
00440       using SHOTEstimationBase<pcl::PointXYZRGBA, PointNT, PointOutT>::radius3_4_;
00441       using SHOTEstimationBase<pcl::PointXYZRGBA, PointNT, PointOutT>::radius1_4_;
00442       using SHOTEstimationBase<pcl::PointXYZRGBA, PointNT, PointOutT>::radius1_2_;
00443       using SHOTEstimationBase<pcl::PointXYZRGBA, PointNT, PointOutT>::rf_;
00444       using SHOTEstimationBase<pcl::PointXYZRGBA, PointNT, PointOutT>::maxAngularSectors_;
00445       using SHOTEstimationBase<pcl::PointXYZRGBA, PointNT, PointOutT>::interpolateSingleChannel;
00446       using SHOTEstimationBase<pcl::PointXYZRGBA, PointNT, PointOutT>::shot_;
00447 
00448       typedef typename Feature<pcl::PointXYZRGBA, PointOutT>::PointCloudOut PointCloudOut;
00449       typedef typename Feature<pcl::PointXYZRGBA, PointOutT>::PointCloudIn PointCloudIn;
00450 
00457       SHOTEstimation (bool describe_shape = true, 
00458                       bool describe_color = false, 
00459                       const int nr_shape_bins = 10, 
00460                       const int nr_color_bins = 30) 
00461         : SHOTEstimationBase<pcl::PointXYZRGBA, PointNT, PointOutT> (nr_shape_bins),
00462           b_describe_shape_ (describe_shape),
00463           b_describe_color_ (describe_color),
00464           nr_color_bins_ (nr_color_bins)
00465       {
00466         feature_name_ = "SHOTEstimation";
00467       };
00468 
00476       void 
00477       computePointSHOT (const int index, 
00478                         const std::vector<int> &indices, 
00479                         const std::vector<float> &sqr_dists, 
00480                         Eigen::VectorXf &shot,
00481                         std::vector<Eigen::Vector4f, Eigen::aligned_allocator<Eigen::Vector4f> > &rf);
00482 
00483     protected:
00484 
00490       void 
00491       computeFeature (PointCloudOut &output);
00492 
00504       void 
00505       interpolateDoubleChannel (const std::vector<int> &indices,
00506                                 const std::vector<float> &sqr_dists, 
00507                                 const Eigen::Vector4f &centralPoint, 
00508                                 const std::vector<Eigen::Vector4f, Eigen::aligned_allocator<Eigen::Vector4f> > &rf,
00509                                 std::vector<double> &binDistanceShape, 
00510                                 std::vector<double> &binDistanceColor, 
00511                                 const int nr_bins_shape,
00512                                 const int nr_bins_color,
00513                                 Eigen::VectorXf &shot);
00514 
00523       static void 
00524       RGB2CIELAB (unsigned char R, unsigned char G, unsigned char B, float &L, float &A, float &B2);
00525 
00527       bool b_describe_shape_;
00528 
00530       bool b_describe_color_;
00531 
00533       int nr_color_bins_;
00534 
00535     public:
00536       static float sRGB_LUT[256];
00537       static float sXYZ_LUT[4000];
00538   };
00539 
00557   template <typename PointNT> 
00558   class SHOTEstimation<pcl::PointXYZRGBA, PointNT, Eigen::MatrixXf> : public SHOTEstimation<pcl::PointXYZRGBA, PointNT, pcl::SHOT>
00559   {
00560     public:
00561       using SHOTEstimation<pcl::PointXYZRGBA, PointNT, pcl::SHOT>::feature_name_;
00562       using SHOTEstimation<pcl::PointXYZRGBA, PointNT, pcl::SHOT>::getClassName;
00563       using SHOTEstimation<pcl::PointXYZRGBA, PointNT, pcl::SHOT>::indices_;
00564       using SHOTEstimation<pcl::PointXYZRGBA, PointNT, pcl::SHOT>::k_;
00565       using SHOTEstimation<pcl::PointXYZRGBA, PointNT, pcl::SHOT>::search_parameter_;
00566       using SHOTEstimation<pcl::PointXYZRGBA, PointNT, pcl::SHOT>::search_radius_;
00567       using SHOTEstimation<pcl::PointXYZRGBA, PointNT, pcl::SHOT>::surface_;
00568       using SHOTEstimation<pcl::PointXYZRGBA, PointNT, pcl::SHOT>::input_;
00569       using SHOTEstimation<pcl::PointXYZRGBA, PointNT, pcl::SHOT>::rf_;
00570       using SHOTEstimation<pcl::PointXYZRGBA, PointNT, pcl::SHOT>::descLength_;
00571       using SHOTEstimation<pcl::PointXYZRGBA, PointNT, pcl::SHOT>::nr_grid_sector_;
00572       using SHOTEstimation<pcl::PointXYZRGBA, PointNT, pcl::SHOT>::nr_shape_bins_;
00573       using SHOTEstimation<pcl::PointXYZRGBA, PointNT, pcl::SHOT>::sqradius_;
00574       using SHOTEstimation<pcl::PointXYZRGBA, PointNT, pcl::SHOT>::radius3_4_;
00575       using SHOTEstimation<pcl::PointXYZRGBA, PointNT, pcl::SHOT>::radius1_4_;
00576       using SHOTEstimation<pcl::PointXYZRGBA, PointNT, pcl::SHOT>::radius1_2_;
00577       using SHOTEstimation<pcl::PointXYZRGBA, PointNT, pcl::SHOT>::maxAngularSectors_;
00578       using SHOTEstimation<pcl::PointXYZRGBA, PointNT, pcl::SHOT>::interpolateSingleChannel;
00579       using SHOTEstimation<pcl::PointXYZRGBA, PointNT, pcl::SHOT>::shot_;
00580       using SHOTEstimation<pcl::PointXYZRGBA, PointNT, pcl::SHOT>::b_describe_shape_;
00581       using SHOTEstimation<pcl::PointXYZRGBA, PointNT, pcl::SHOT>::b_describe_color_;
00582       using SHOTEstimation<pcl::PointXYZRGBA, PointNT, pcl::SHOT>::nr_color_bins_;
00583 
00590       SHOTEstimation (bool describe_shape = true, 
00591                       bool describe_color = false, 
00592                       const int nr_shape_bins = 10, 
00593                       const int nr_color_bins = 30) 
00594         : SHOTEstimation<pcl::PointXYZRGBA, PointNT, pcl::SHOT> (describe_shape, describe_color, nr_shape_bins, nr_color_bins) {};
00595 
00596    protected:
00602       void 
00603       computeFeatureEigen (pcl::PointCloud<Eigen::MatrixXf> &output);
00604   };
00605 }
00606 
00607 #endif  //#ifndef PCL_SHOT_H_
00608 
00609