hough_3d.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-2012, 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:$
00037  *
00038  */
00039 
00040 #ifndef PCL_RECOGNITION_HOUGH_3D_H_
00041 #define PCL_RECOGNITION_HOUGH_3D_H_
00042 
00043 #include <pcl/recognition/cg/correspondence_grouping.h>
00044 #include <pcl/recognition/boost.h>
00045 
00046 namespace pcl
00047 {
00048   namespace recognition
00049   {
00054     class PCL_EXPORTS HoughSpace3D
00055     {
00056 
00057       public:
00058       
00059         EIGEN_MAKE_ALIGNED_OPERATOR_NEW
00060       
00067         HoughSpace3D (const Eigen::Vector3d &min_coord, const Eigen::Vector3d &bin_size, const Eigen::Vector3d &max_coord);
00068 
00070         void
00071         reset ();
00072 
00080         int
00081         vote (const Eigen::Vector3d &single_vote_coord, double weight, int voter_id);
00082 
00090         int
00091         voteInt (const Eigen::Vector3d &single_vote_coord, double weight, int voter_id);
00092 
00101         double
00102         findMaxima (double min_threshold, std::vector<double> & maxima_values, std::vector<std::vector<int> > &maxima_voter_ids);
00103 
00104       protected:
00105 
00107         Eigen::Vector3d min_coord_;
00108 
00110         Eigen::Vector3d bin_size_;
00111 
00113         Eigen::Vector3i bin_count_;
00114 
00116         int partial_bin_products_[4];
00117 
00119         int total_bins_count_;
00120 
00122         std::vector<double> hough_space_;
00123         //boost::unordered_map<int, double> hough_space_;
00124 
00126         boost::unordered_map<int, std::vector<int> > voter_ids_;
00127     };
00128   }
00129 
00143   template<typename PointModelT, typename PointSceneT, typename PointModelRfT = pcl::ReferenceFrame, typename PointSceneRfT = pcl::ReferenceFrame>
00144   class Hough3DGrouping : public CorrespondenceGrouping<PointModelT, PointSceneT>
00145   {
00146     public:
00147       typedef pcl::PointCloud<PointModelRfT> ModelRfCloud;
00148       typedef typename ModelRfCloud::Ptr ModelRfCloudPtr;
00149       typedef typename ModelRfCloud::ConstPtr ModelRfCloudConstPtr;
00150 
00151       typedef pcl::PointCloud<PointSceneRfT> SceneRfCloud;
00152       typedef typename SceneRfCloud::Ptr SceneRfCloudPtr;
00153       typedef typename SceneRfCloud::ConstPtr SceneRfCloudConstPtr;
00154 
00155       typedef pcl::PointCloud<PointModelT> PointCloud;
00156       typedef typename PointCloud::Ptr PointCloudPtr;
00157       typedef typename PointCloud::ConstPtr PointCloudConstPtr;
00158 
00159       typedef typename pcl::CorrespondenceGrouping<PointModelT, PointSceneT>::SceneCloudConstPtr SceneCloudConstPtr;
00160 
00162       Hough3DGrouping () 
00163         : input_rf_ ()
00164         , scene_rf_ ()
00165         , needs_training_ (true)
00166         , model_votes_ ()
00167         , hough_threshold_ (-1)
00168         , hough_bin_size_ (1.0)
00169         , use_interpolation_ (true)
00170         , use_distance_weight_ (false)
00171         , local_rf_normals_search_radius_ (0.0f)
00172         , local_rf_search_radius_ (0.0f)
00173         , hough_space_ ()
00174         , found_transformations_ ()
00175         , hough_space_initialized_ (false)
00176       {}
00177 
00181       inline void
00182       setInputCloud (const PointCloudConstPtr &cloud)
00183       {
00184         PCLBase<PointModelT>::setInputCloud (cloud);
00185         needs_training_ = true;
00186         hough_space_initialized_ = false;
00187         input_rf_.reset();
00188       }
00189 
00196       inline void
00197       setInputRf (const ModelRfCloudConstPtr &input_rf)
00198       {
00199         input_rf_ = input_rf;
00200         needs_training_ = true;
00201         hough_space_initialized_ = false;
00202       }
00203 
00210       inline ModelRfCloudConstPtr
00211       getInputRf () const
00212       {
00213         return (input_rf_);
00214       }
00215       
00220       inline void
00221       setSceneCloud (const SceneCloudConstPtr &scene)
00222       {
00223         scene_ = scene;
00224         hough_space_initialized_ = false;
00225         scene_rf_.reset();
00226       }
00227 
00234       inline void
00235       setSceneRf (const SceneRfCloudConstPtr &scene_rf)
00236       {
00237         scene_rf_ = scene_rf;
00238         hough_space_initialized_ = false;
00239       }
00240 
00247       inline SceneRfCloudConstPtr
00248       getSceneRf () const
00249       {
00250         return (scene_rf_);
00251       }
00252 
00259       inline void
00260       setModelSceneCorrespondences (const CorrespondencesConstPtr &corrs)
00261       {
00262         model_scene_corrs_ = corrs;
00263         hough_space_initialized_ = false;
00264       }
00265 
00273       inline void
00274       setHoughThreshold (double threshold)
00275       {
00276         hough_threshold_ = threshold;
00277       }
00278 
00283       inline double
00284       getHoughThreshold () const
00285       {
00286         return (hough_threshold_);
00287       }
00288 
00293       inline void
00294       setHoughBinSize (double bin_size)
00295       {
00296         hough_bin_size_ = bin_size;
00297         hough_space_initialized_ = false;
00298       }
00299 
00304       inline double
00305       getHoughBinSize () const
00306       {
00307         return (hough_bin_size_);
00308       }
00309 
00315       inline void
00316       setUseInterpolation (bool use_interpolation)
00317       {
00318         use_interpolation_ = use_interpolation;
00319         hough_space_initialized_ = false;
00320       }
00321 
00327       inline bool
00328       getUseInterpolation () const
00329       {
00330         return (use_interpolation_);
00331       }
00332 
00337       inline void
00338       setUseDistanceWeight (bool use_distance_weight)
00339       {
00340         use_distance_weight_ = use_distance_weight;
00341         hough_space_initialized_ = false;
00342       }
00343 
00348       inline bool
00349       getUseDistanceWeight () const
00350       {
00351         return (use_distance_weight_);
00352       } 
00353 
00360       inline void
00361       setLocalRfNormalsSearchRadius (float local_rf_normals_search_radius)
00362       {
00363         local_rf_normals_search_radius_ = local_rf_normals_search_radius;
00364         needs_training_ = true;
00365         hough_space_initialized_ = false;
00366       }
00367 
00374       inline float
00375       getLocalRfNormalsSearchRadius () const
00376       {
00377         return (local_rf_normals_search_radius_);
00378       }
00379 
00387       inline void
00388       setLocalRfSearchRadius (float local_rf_search_radius)
00389       {
00390         local_rf_search_radius_ = local_rf_search_radius;
00391         needs_training_ = true;
00392         hough_space_initialized_ = false;
00393       }
00394 
00402       inline float
00403       getLocalRfSearchRadius () const
00404       {
00405         return (local_rf_search_radius_);
00406       }
00407 
00413       bool
00414       train ();
00415 
00422       bool
00423       recognize (std::vector<Eigen::Matrix4f, Eigen::aligned_allocator<Eigen::Matrix4f> > &transformations);
00424 
00432       bool
00433       recognize (std::vector<Eigen::Matrix4f, Eigen::aligned_allocator<Eigen::Matrix4f> > &transformations, std::vector<pcl::Correspondences> &clustered_corrs);
00434 
00435     protected:
00436       using CorrespondenceGrouping<PointModelT, PointSceneT>::input_;
00437       using CorrespondenceGrouping<PointModelT, PointSceneT>::scene_;
00438       using CorrespondenceGrouping<PointModelT, PointSceneT>::model_scene_corrs_;
00439 
00441       ModelRfCloudConstPtr input_rf_;
00442 
00444       SceneRfCloudConstPtr scene_rf_;
00445 
00447       bool needs_training_;
00448 
00450       std::vector<Eigen::Vector3f> model_votes_;
00451 
00453       double hough_threshold_;
00454 
00456       double hough_bin_size_;
00457 
00459       bool use_interpolation_;
00460 
00462       bool use_distance_weight_;
00463 
00465       float local_rf_normals_search_radius_;
00466 
00468       float local_rf_search_radius_;
00469 
00471       boost::shared_ptr<pcl::recognition::HoughSpace3D> hough_space_;
00472 
00474       std::vector<Eigen::Matrix4f, Eigen::aligned_allocator<Eigen::Matrix4f> > found_transformations_;
00475 
00479       bool hough_space_initialized_;
00480 
00486       void
00487       clusterCorrespondences (std::vector<Correspondences> &model_instances);
00488 
00490       //  * 
00491       //  * \param[in] the scene cloud in which the PointSceneT has been converted to PointModelT.
00492       //  * \param[in] corrs a set of correspondences.
00493       //  * \param[out] transform the transformation matrix between the input cloud and the scene cloud that aligns the found correspondences.
00494       //  * \return true if the recognition had been successful or false if errors have occurred.
00495       //  */
00496       //bool
00497       //getTransformMatrix (const PointCloudConstPtr &scene_cloud, const Correspondences &corrs, Eigen::Matrix4f &transform);
00498 
00503       bool
00504       houghVoting ();
00505 
00511       template<typename PointType, typename PointRfType> void
00512       computeRf (const boost::shared_ptr<const pcl::PointCloud<PointType> > &input, pcl::PointCloud<PointRfType> &rf);
00513   };
00514 }
00515 
00516 #ifdef PCL_NO_PRECOMPILE
00517 #include <pcl/recognition/impl/cg/hough_3d.hpp>
00518 #endif
00519 
00520 #endif // PCL_RECOGNITION_HOUGH_3D_H_


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