ppf_registration.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  *  Copyright (c) 2012-, Open Perception, Inc.
00007  *
00008  *  All rights reserved.
00009  *
00010  *  Redistribution and use in source and binary forms, with or without
00011  *  modification, are permitted provided that the following conditions
00012  *  are met:
00013  *
00014  *   * Redistributions of source code must retain the above copyright
00015  *     notice, this list of conditions and the following disclaimer.
00016  *   * Redistributions in binary form must reproduce the above
00017  *     copyright notice, this list of conditions and the following
00018  *     disclaimer in the documentation and/or other materials provided
00019  *     with the distribution.
00020  *   * Neither the name of the copyright holder(s) nor the names of its
00021  *     contributors may be used to endorse or promote products derived
00022  *     from this software without specific prior written permission.
00023  *
00024  *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
00025  *  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
00026  *  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
00027  *  FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
00028  *  COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
00029  *  INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
00030  *  BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
00031  *  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
00032  *  CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
00033  *  LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
00034  *  ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
00035  *  POSSIBILITY OF SUCH DAMAGE.
00036  *
00037  * $Id$
00038  *
00039  */
00040 
00041 
00042 #ifndef PCL_PPF_REGISTRATION_H_
00043 #define PCL_PPF_REGISTRATION_H_
00044 
00045 #include <pcl/registration/boost.h>
00046 #include <pcl/registration/registration.h>
00047 #include <pcl/features/ppf.h>
00048 
00049 namespace pcl
00050 {
00051   class PCL_EXPORTS PPFHashMapSearch
00052   {
00053     public:
00059       struct HashKeyStruct : public std::pair <int, std::pair <int, std::pair <int, int> > >
00060       {
00061         HashKeyStruct(int a, int b, int c, int d)
00062         {
00063           this->first = a;
00064           this->second.first = b;
00065           this->second.second.first = c;
00066           this->second.second.second = d;
00067         }
00068       };
00069       typedef boost::unordered_multimap<HashKeyStruct, std::pair<size_t, size_t> > FeatureHashMapType;
00070       typedef boost::shared_ptr<FeatureHashMapType> FeatureHashMapTypePtr;
00071       typedef boost::shared_ptr<PPFHashMapSearch> Ptr;
00072 
00073 
00078       PPFHashMapSearch (float angle_discretization_step = 12.0f / 180.0f * static_cast<float> (M_PI),
00079                         float distance_discretization_step = 0.01f)
00080         : alpha_m_ ()
00081         , feature_hash_map_ (new FeatureHashMapType)
00082         , internals_initialized_ (false)
00083         , angle_discretization_step_ (angle_discretization_step)
00084         , distance_discretization_step_ (distance_discretization_step)
00085         , max_dist_ (-1.0f)
00086       {
00087       }
00088 
00092       void
00093       setInputFeatureCloud (PointCloud<PPFSignature>::ConstPtr feature_cloud);
00094 
00103       void
00104       nearestNeighborSearch (float &f1, float &f2, float &f3, float &f4,
00105                              std::vector<std::pair<size_t, size_t> > &indices);
00106 
00108       Ptr
00109       makeShared() { return Ptr (new PPFHashMapSearch (*this)); }
00110 
00112       inline float
00113       getAngleDiscretizationStep () { return angle_discretization_step_; }
00114 
00116       inline float
00117       getDistanceDiscretizationStep () { return distance_discretization_step_; }
00118 
00120       inline float
00121       getModelDiameter () { return max_dist_; }
00122 
00123       std::vector <std::vector <float> > alpha_m_;
00124     private:
00125       FeatureHashMapTypePtr feature_hash_map_;
00126       bool internals_initialized_;
00127 
00128       float angle_discretization_step_, distance_discretization_step_;
00129       float max_dist_;
00130   };
00131 
00143   template <typename PointSource, typename PointTarget>
00144   class PPFRegistration : public Registration<PointSource, PointTarget>
00145   {
00146     public:
00151       struct PoseWithVotes
00152       {
00153         PoseWithVotes(Eigen::Affine3f &a_pose, unsigned int &a_votes)
00154         : pose (a_pose),
00155           votes (a_votes)
00156         {}
00157 
00158         Eigen::Affine3f pose;
00159         unsigned int votes;
00160       };
00161       typedef std::vector<PoseWithVotes, Eigen::aligned_allocator<PoseWithVotes> > PoseWithVotesList;
00162 
00164       using Registration<PointSource, PointTarget>::input_;
00166       using Registration<PointSource, PointTarget>::target_;
00167       using Registration<PointSource, PointTarget>::converged_;
00168       using Registration<PointSource, PointTarget>::final_transformation_;
00169       using Registration<PointSource, PointTarget>::transformation_;
00170 
00171       typedef pcl::PointCloud<PointSource> PointCloudSource;
00172       typedef typename PointCloudSource::Ptr PointCloudSourcePtr;
00173       typedef typename PointCloudSource::ConstPtr PointCloudSourceConstPtr;
00174 
00175       typedef pcl::PointCloud<PointTarget> PointCloudTarget;
00176       typedef typename PointCloudTarget::Ptr PointCloudTargetPtr;
00177       typedef typename PointCloudTarget::ConstPtr PointCloudTargetConstPtr;
00178 
00179 
00181       PPFRegistration ()
00182       :  Registration<PointSource, PointTarget> (),
00183          search_method_ (),
00184          scene_reference_point_sampling_rate_ (5),
00185          clustering_position_diff_threshold_ (0.01f),
00186          clustering_rotation_diff_threshold_ (20.0f / 180.0f * static_cast<float> (M_PI))
00187       {}
00188 
00193       inline void
00194       setPositionClusteringThreshold (float clustering_position_diff_threshold) { clustering_position_diff_threshold_ = clustering_position_diff_threshold; }
00195 
00200       inline float
00201       getPositionClusteringThreshold () { return clustering_position_diff_threshold_; }
00202 
00207       inline void
00208       setRotationClusteringThreshold (float clustering_rotation_diff_threshold) { clustering_rotation_diff_threshold_ = clustering_rotation_diff_threshold; }
00209 
00212       inline float
00213       getRotationClusteringThreshold () { return clustering_rotation_diff_threshold_; }
00214 
00218       inline void
00219       setSceneReferencePointSamplingRate (unsigned int scene_reference_point_sampling_rate) { scene_reference_point_sampling_rate_ = scene_reference_point_sampling_rate; }
00220 
00222       inline unsigned int
00223       getSceneReferencePointSamplingRate () { return scene_reference_point_sampling_rate_; }
00224 
00230       inline void
00231       setSearchMethod (PPFHashMapSearch::Ptr search_method) { search_method_ = search_method; }
00232 
00234       inline PPFHashMapSearch::Ptr
00235       getSearchMethod () { return search_method_; }
00236 
00240       void
00241       setInputTarget (const PointCloudTargetConstPtr &cloud);
00242 
00243 
00244     private:
00246       void
00247       computeTransformation (PointCloudSource &output, const Eigen::Matrix4f& guess);
00248 
00249 
00251       PPFHashMapSearch::Ptr search_method_;
00252 
00254       unsigned int scene_reference_point_sampling_rate_;
00255 
00258       float clustering_position_diff_threshold_, clustering_rotation_diff_threshold_;
00259 
00261       typename pcl::KdTreeFLANN<PointTarget>::Ptr scene_search_tree_;
00262 
00265       static bool
00266       poseWithVotesCompareFunction (const PoseWithVotes &a,
00267                                     const PoseWithVotes &b);
00268 
00271       static bool
00272       clusterVotesCompareFunction (const std::pair<size_t, unsigned int> &a,
00273                                    const std::pair<size_t, unsigned int> &b);
00274 
00277       void
00278       clusterPoses (PoseWithVotesList &poses,
00279                     PoseWithVotesList &result);
00280 
00283       bool
00284       posesWithinErrorBounds (Eigen::Affine3f &pose1,
00285                               Eigen::Affine3f &pose2);
00286   };
00287 }
00288 
00289 #include <pcl/registration/impl/ppf_registration.hpp>
00290 
00291 #endif // PCL_PPF_REGISTRATION_H_


pcl
Author(s): Open Perception
autogenerated on Wed Aug 26 2015 15:31:15