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
00039
00040 #ifndef PCL_REGISTRATION_CORRESPONDENCE_REJECTION_FEATURES_H_
00041 #define PCL_REGISTRATION_CORRESPONDENCE_REJECTION_FEATURES_H_
00042
00043 #include <pcl/registration/correspondence_rejection.h>
00044 #include <pcl/point_cloud.h>
00045 #include <pcl/point_representation.h>
00046 #include <pcl/registration/boost.h>
00047
00048 namespace pcl
00049 {
00050 namespace registration
00051 {
00060 class PCL_EXPORTS CorrespondenceRejectorFeatures: public CorrespondenceRejector
00061 {
00062 using CorrespondenceRejector::input_correspondences_;
00063 using CorrespondenceRejector::rejection_name_;
00064 using CorrespondenceRejector::getClassName;
00065
00066 public:
00067 typedef boost::shared_ptr<CorrespondenceRejectorFeatures> Ptr;
00068 typedef boost::shared_ptr<const CorrespondenceRejectorFeatures> ConstPtr;
00069
00071 CorrespondenceRejectorFeatures () : max_distance_ (std::numeric_limits<float>::max ()), features_map_ ()
00072 {
00073 rejection_name_ = "CorrespondenceRejectorFeatures";
00074 }
00075
00077 virtual ~CorrespondenceRejectorFeatures () {}
00078
00083 void
00084 getRemainingCorrespondences (const pcl::Correspondences& original_correspondences,
00085 pcl::Correspondences& remaining_correspondences);
00086
00091 template <typename FeatureT> inline void
00092 setSourceFeature (const typename pcl::PointCloud<FeatureT>::ConstPtr &source_feature,
00093 const std::string &key);
00094
00098 template <typename FeatureT> inline typename pcl::PointCloud<FeatureT>::ConstPtr
00099 getSourceFeature (const std::string &key);
00100
00105 template <typename FeatureT> inline void
00106 setTargetFeature (const typename pcl::PointCloud<FeatureT>::ConstPtr &target_feature,
00107 const std::string &key);
00108
00112 template <typename FeatureT> inline typename pcl::PointCloud<FeatureT>::ConstPtr
00113 getTargetFeature (const std::string &key);
00114
00121 template <typename FeatureT> inline void
00122 setDistanceThreshold (double thresh, const std::string &key);
00123
00127 inline bool
00128 hasValidFeatures ();
00129
00134 template <typename FeatureT> inline void
00135 setFeatureRepresentation (const typename pcl::PointRepresentation<FeatureT>::ConstPtr &fr,
00136 const std::string &key);
00137
00138 protected:
00139
00143 inline void
00144 applyRejection (pcl::Correspondences &correspondences)
00145 {
00146 getRemainingCorrespondences (*input_correspondences_, correspondences);
00147 }
00148
00152 float max_distance_;
00153
00154 class FeatureContainerInterface
00155 {
00156 public:
00158 virtual ~FeatureContainerInterface () {}
00159 virtual bool isValid () = 0;
00160 virtual double getCorrespondenceScore (int index) = 0;
00161 virtual bool isCorrespondenceValid (int index) = 0;
00162 };
00163
00164 typedef boost::unordered_map<std::string, boost::shared_ptr<FeatureContainerInterface> > FeaturesMap;
00165
00167 FeaturesMap features_map_;
00168
00175 template <typename FeatureT>
00176 class FeatureContainer : public pcl::registration::CorrespondenceRejectorFeatures::FeatureContainerInterface
00177 {
00178 public:
00179 typedef typename pcl::PointCloud<FeatureT>::ConstPtr FeatureCloudConstPtr;
00180 typedef boost::function<int (const pcl::PointCloud<FeatureT> &, int, std::vector<int> &,
00181 std::vector<float> &)> SearchMethod;
00182
00183 typedef typename pcl::PointRepresentation<FeatureT>::ConstPtr PointRepresentationConstPtr;
00184
00185 FeatureContainer () : thresh_(std::numeric_limits<double>::max ()), feature_representation_()
00186 {
00187 }
00188
00190 virtual ~FeatureContainer () {}
00191
00192 inline void
00193 setSourceFeature (const FeatureCloudConstPtr &source_features)
00194 {
00195 source_features_ = source_features;
00196 }
00197
00198 inline FeatureCloudConstPtr
00199 getSourceFeature ()
00200 {
00201 return (source_features_);
00202 }
00203
00204 inline void
00205 setTargetFeature (const FeatureCloudConstPtr &target_features)
00206 {
00207 target_features_ = target_features;
00208 }
00209
00210 inline FeatureCloudConstPtr
00211 getTargetFeature ()
00212 {
00213 return (target_features_);
00214 }
00215
00216 inline void
00217 setDistanceThreshold (double thresh)
00218 {
00219 thresh_ = thresh;
00220 }
00221
00222 virtual inline bool
00223 isValid ()
00224 {
00225 if (!source_features_ || !target_features_)
00226 return (false);
00227 else
00228 return (source_features_->points.size () > 0 &&
00229 target_features_->points.size () > 0);
00230 }
00231
00235 inline void
00236 setFeatureRepresentation (const PointRepresentationConstPtr &fr)
00237 {
00238 feature_representation_ = fr;
00239 }
00240
00245 virtual inline double
00246 getCorrespondenceScore (int index)
00247 {
00248
00249 if (!feature_representation_)
00250 feature_representation_.reset (new DefaultFeatureRepresentation<FeatureT>);
00251
00252
00253 const FeatureT &feat_src = source_features_->points[index];
00254 const FeatureT &feat_tgt = target_features_->points[index];
00255
00256
00257 if (!feature_representation_->isValid (feat_src) || !feature_representation_->isValid (feat_tgt))
00258 {
00259 PCL_ERROR ("[pcl::registration::%s::getCorrespondenceScore] Invalid feature representation given!\n", this->getClassName ().c_str ());
00260 return (std::numeric_limits<double>::max ());
00261 }
00262
00263
00264 Eigen::VectorXf feat_src_ptr = Eigen::VectorXf::Zero (feature_representation_->getNumberOfDimensions ());
00265 feature_representation_->vectorize (FeatureT (feat_src), feat_src_ptr);
00266 Eigen::VectorXf feat_tgt_ptr = Eigen::VectorXf::Zero (feature_representation_->getNumberOfDimensions ());
00267 feature_representation_->vectorize (FeatureT (feat_tgt), feat_tgt_ptr);
00268
00269
00270 return ((feat_src_ptr - feat_tgt_ptr).squaredNorm ());
00271 }
00272
00278 virtual inline bool
00279 isCorrespondenceValid (int index)
00280 {
00281 if (getCorrespondenceScore (index) < thresh_ * thresh_)
00282 return (true);
00283 else
00284 return (false);
00285 }
00286
00287 private:
00288 FeatureCloudConstPtr source_features_, target_features_;
00289 SearchMethod search_method_;
00290
00292 double thresh_;
00293
00295 PointRepresentationConstPtr feature_representation_;
00296 };
00297 };
00298 }
00299 }
00300
00301 #include <pcl/registration/impl/correspondence_rejection_features.hpp>
00302
00303 #endif