|
Point Cloud Library (PCL)
1.6.0
|
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 #ifndef PCL_REGISTRATION_CORRESPONDENCE_REJECTION_FEATURES_H_ 00039 #define PCL_REGISTRATION_CORRESPONDENCE_REJECTION_FEATURES_H_ 00040 00041 #include <boost/function.hpp> 00042 #include <boost/unordered_map.hpp> 00043 #include <pcl/registration/correspondence_rejection.h> 00044 #include <pcl/point_cloud.h> 00045 #include <pcl/point_representation.h> 00046 00047 namespace pcl 00048 { 00049 namespace registration 00050 { 00060 class CorrespondenceRejectorFeatures: public CorrespondenceRejector 00061 { 00062 using CorrespondenceRejector::input_correspondences_; 00063 using CorrespondenceRejector::rejection_name_; 00064 using CorrespondenceRejector::getClassName; 00065 00066 public: 00068 CorrespondenceRejectorFeatures () : max_distance_ (std::numeric_limits<float>::max ()) 00069 { 00070 rejection_name_ = "CorrespondenceRejectorFeatures"; 00071 } 00072 00077 void 00078 getRemainingCorrespondences (const pcl::Correspondences& original_correspondences, 00079 pcl::Correspondences& remaining_correspondences); 00080 00085 template <typename FeatureT> inline void 00086 setSourceFeature (const typename pcl::PointCloud<FeatureT>::ConstPtr &source_feature, 00087 const std::string &key); 00088 00092 template <typename FeatureT> inline typename pcl::PointCloud<FeatureT>::ConstPtr 00093 getSourceFeature (const std::string &key); 00094 00099 template <typename FeatureT> inline void 00100 setTargetFeature (const typename pcl::PointCloud<FeatureT>::ConstPtr &target_feature, 00101 const std::string &key); 00102 00106 template <typename FeatureT> inline typename pcl::PointCloud<FeatureT>::ConstPtr 00107 getTargetFeature (const std::string &key); 00108 00115 template <typename FeatureT> inline void 00116 setDistanceThreshold (double thresh, const std::string &key); 00117 00121 inline bool 00122 hasValidFeatures (); 00123 00128 template <typename FeatureT> inline void 00129 setFeatureRepresentation (const typename pcl::PointRepresentation<FeatureT>::ConstPtr &fr, 00130 const std::string &key); 00131 00132 protected: 00133 00137 inline void 00138 applyRejection (pcl::Correspondences &correspondences) 00139 { 00140 getRemainingCorrespondences (*input_correspondences_, correspondences); 00141 } 00142 00146 float max_distance_; 00147 00148 class FeatureContainerInterface 00149 { 00150 public: 00151 virtual bool isValid () = 0; 00152 virtual double getCorrespondenceScore (int index) = 0; 00153 virtual bool isCorrespondenceValid (int index) = 0; 00154 }; 00155 00156 typedef boost::unordered_map<std::string, boost::shared_ptr<FeatureContainerInterface> > FeaturesMap; 00157 00159 FeaturesMap features_map_; 00160 00167 template <typename FeatureT> 00168 class FeatureContainer : public pcl::registration::CorrespondenceRejectorFeatures::FeatureContainerInterface 00169 { 00170 public: 00171 typedef typename pcl::PointCloud<FeatureT>::ConstPtr FeatureCloudConstPtr; 00172 typedef boost::function<int (const pcl::PointCloud<FeatureT> &, int, std::vector<int> &, 00173 std::vector<float> &)> SearchMethod; 00174 00175 typedef typename pcl::PointRepresentation<FeatureT>::ConstPtr PointRepresentationConstPtr; 00176 00177 FeatureContainer () : thresh_(std::numeric_limits<double>::max ()), feature_representation_() 00178 { 00179 } 00180 00181 inline void 00182 setSourceFeature (const FeatureCloudConstPtr &source_features) 00183 { 00184 source_features_ = source_features; 00185 } 00186 00187 inline FeatureCloudConstPtr 00188 getSourceFeature () 00189 { 00190 return (source_features_); 00191 } 00192 00193 inline void 00194 setTargetFeature (const FeatureCloudConstPtr &target_features) 00195 { 00196 target_features_ = target_features; 00197 } 00198 00199 inline FeatureCloudConstPtr 00200 getTargetFeature () 00201 { 00202 return (target_features_); 00203 } 00204 00205 inline void 00206 setDistanceThreshold (double thresh) 00207 { 00208 thresh_ = thresh; 00209 } 00210 00211 virtual inline bool 00212 isValid () 00213 { 00214 if (!source_features_ || !target_features_) 00215 return (false); 00216 else 00217 return (source_features_->points.size () > 0 && 00218 target_features_->points.size () > 0); 00219 } 00220 00224 inline void 00225 setFeatureRepresentation (const PointRepresentationConstPtr &fr) 00226 { 00227 feature_representation_ = fr; 00228 } 00229 00234 virtual inline double 00235 getCorrespondenceScore (int index) 00236 { 00237 // If no feature representation was given, reset to the default implementation for FeatureT 00238 if (!feature_representation_) 00239 feature_representation_.reset (new DefaultFeatureRepresentation<FeatureT>); 00240 00241 // Get the source and the target feature from the list 00242 const FeatureT &feat_src = source_features_->points[index]; 00243 const FeatureT &feat_tgt = target_features_->points[index]; 00244 00245 // Check if the representations are valid 00246 if (!feature_representation_->isValid (feat_src) || !feature_representation_->isValid (feat_tgt)) 00247 { 00248 PCL_ERROR ("[pcl::registration::CorrespondenceRejectorFeatures::getCorrespondenceScore] Invalid feature representation given!\n"); 00249 return (std::numeric_limits<double>::max ()); 00250 } 00251 00252 // Set the internal feature point representation of choice 00253 Eigen::VectorXf feat_src_ptr = Eigen::VectorXf::Zero (feature_representation_->getNumberOfDimensions ()); 00254 feature_representation_->vectorize (FeatureT (feat_src), feat_src_ptr); 00255 Eigen::VectorXf feat_tgt_ptr = Eigen::VectorXf::Zero (feature_representation_->getNumberOfDimensions ()); 00256 feature_representation_->vectorize (FeatureT (feat_tgt), feat_tgt_ptr); 00257 00258 // Compute the L2 norm 00259 return ((feat_src_ptr - feat_tgt_ptr).squaredNorm ()); 00260 } 00261 00267 virtual inline bool 00268 isCorrespondenceValid (int index) 00269 { 00270 if (getCorrespondenceScore (index) < thresh_ * thresh_) 00271 return (true); 00272 else 00273 return (false); 00274 } 00275 00276 private: 00277 FeatureCloudConstPtr source_features_, target_features_; 00278 SearchMethod search_method_; 00279 00281 double thresh_; 00282 00284 PointRepresentationConstPtr feature_representation_; 00285 }; 00286 }; 00287 } 00288 } 00289 00290 #include <pcl/registration/impl/correspondence_rejection_features.hpp> 00291 00292 #endif /* PCL_REGISTRATION_CORRESPONDENCE_REJECTION_FEATURES_H_ */
1.7.6.1