Point Cloud Library (PCL)  1.3.1
pyramid_feature_matching.h
Go to the documentation of this file.
00001 /*
00002  * Software License Agreement (BSD License)
00003  *
00004  *  Copyright (c) 2011, Alexandru-Eugen Ichim
00005  *                      Willow Garage, Inc
00006  *  All rights reserved.
00007  *
00008  *  Redistribution and use in source and binary forms, with or without
00009  *  modification, are permitted provided that the following conditions
00010  *  are met:
00011  *
00012  *   * Redistributions of source code must retain the above copyright
00013  *     notice, this list of conditions and the following disclaimer.
00014  *   * Redistributions in binary form must reproduce the above
00015  *     copyright notice, this list of conditions and the following
00016  *     disclaimer in the documentation and/or other materials provided
00017  *     with the distribution.
00018  *   * Neither the name of Willow Garage, Inc. nor the names of its
00019  *     contributors may be used to endorse or promote products derived
00020  *     from this software without specific prior written permission.
00021  *
00022  *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
00023  *  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
00024  *  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
00025  *  FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
00026  *  COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
00027  *  INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
00028  *  BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
00029  *  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
00030  *  CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
00031  *  LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
00032  *  ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
00033  *  POSSIBILITY OF SUCH DAMAGE.
00034  *
00035  * $Id: pyramid_feature_matching.h 2505 2011-09-19 03:18:54Z rusu $
00036  */
00037 
00038 #ifndef PCL_PYRAMID_FEATURE_MATCHING_H_
00039 #define PCL_PYRAMID_FEATURE_MATCHING_H_
00040 
00041 #include <pcl/pcl_base.h>
00042 #include <pcl/point_representation.h>
00043 
00044 namespace pcl
00045 {
00064   template <typename PointFeature>
00065   class PyramidFeatureHistogram : public PCLBase<PointFeature>
00066   {
00067     public:
00068       using PCLBase<PointFeature>::input_;
00069 
00070       typedef boost::shared_ptr<PyramidFeatureHistogram<PointFeature> > Ptr;
00071       typedef Ptr PyramidFeatureHistogramPtr;
00072       typedef boost::shared_ptr<const pcl::PointRepresentation<PointFeature> > FeatureRepresentationConstPtr;
00073 
00074 
00076       PyramidFeatureHistogram ();
00077 
00081       inline void
00082       setInputDimensionRange (std::vector<std::pair<float, float> > &dimension_range_input)
00083       { dimension_range_input_ = dimension_range_input; }
00084 
00086       inline std::vector<std::pair<float, float> >
00087       getInputDimensionRange () { return dimension_range_input_; }
00088 
00092       inline void
00093       setTargetDimensionRange (std::vector<std::pair<float, float> > &dimension_range_target)
00094       { dimension_range_target_ = dimension_range_target; }
00095 
00097       inline std::vector<std::pair<float, float> >
00098       getTargetDimensionRange () { return dimension_range_target_; }
00099 
00103       inline void
00104       setPointRepresentation (const FeatureRepresentationConstPtr& feature_representation) { feature_representation_ = feature_representation; }
00105 
00107       inline FeatureRepresentationConstPtr const
00108       getPointRepresentation () { return feature_representation_; }
00109 
00111       void
00112       compute ();
00113 
00115       inline bool
00116       isComputed () { return is_computed_; }
00117 
00123       static float
00124       comparePyramidFeatureHistograms (const PyramidFeatureHistogramPtr &pyramid_a,
00125                                        const PyramidFeatureHistogramPtr &pyramid_b);
00126 
00127 
00128     private:
00129       size_t nr_dimensions, nr_levels, nr_features;
00130       std::vector<std::pair<float, float> > dimension_range_input_, dimension_range_target_;
00131       FeatureRepresentationConstPtr feature_representation_;
00132       bool is_computed_;
00133 
00135       bool
00136       initializeHistogram ();
00137 
00141       void
00142       convertFeatureToVector (const PointFeature &feature,
00143                               std::vector<float> &feature_vector);
00144 
00146       void
00147       addFeature (std::vector<float> &feature);
00148 
00154       inline unsigned int&
00155       at (std::vector<size_t> &access,
00156           size_t &level);
00157 
00162       inline unsigned int&
00163       at (std::vector<float> &feature,
00164           size_t &level);
00165 
00167       struct PyramidFeatureHistogramLevel
00168       {
00169         PyramidFeatureHistogramLevel () {}
00170         PyramidFeatureHistogramLevel (std::vector<size_t> &a_bins_per_dimension,
00171                                std::vector<float> &a_bin_step)
00172         : bins_per_dimension (a_bins_per_dimension),
00173           bin_step (a_bin_step)
00174         {
00175           initializeHistogramLevel ();
00176         }
00177 
00178         void
00179         initializeHistogramLevel ();
00180 
00181         std::vector<unsigned int> hist;
00182         std::vector<size_t> bins_per_dimension;
00183         std::vector<float> bin_step;
00184       };
00185       std::vector<PyramidFeatureHistogramLevel> hist_levels;
00186   };
00187 }
00188 
00189 #endif /* PCL_PYRAMID_FEATURE_MATCHING_H_ */
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines