Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
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
00238 if (!feature_representation_)
00239 feature_representation_.reset (new DefaultFeatureRepresentation<FeatureT>);
00240
00241
00242 const FeatureT &feat_src = source_features_->points[index];
00243 const FeatureT &feat_tgt = target_features_->points[index];
00244
00245
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
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
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