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_IMPL_CORRESPONDENCE_REJECTION_SAMPLE_CONSENSUS_HPP_
00039 #define PCL_REGISTRATION_IMPL_CORRESPONDENCE_REJECTION_SAMPLE_CONSENSUS_HPP_
00040
00041 #include <boost/unordered_map.hpp>
00042
00044 template <typename PointT> void
00045 pcl::registration::CorrespondenceRejectorSampleConsensus<PointT>::getRemainingCorrespondences (
00046 const pcl::Correspondences& original_correspondences,
00047 pcl::Correspondences& remaining_correspondences)
00048 {
00049 int nr_correspondences = static_cast<int> (original_correspondences.size ());
00050 std::vector<int> source_indices (nr_correspondences);
00051 std::vector<int> target_indices (nr_correspondences);
00052
00053
00054 for (size_t i = 0; i < original_correspondences.size (); ++i)
00055 {
00056 source_indices[i] = original_correspondences[i].index_query;
00057 target_indices[i] = original_correspondences[i].index_match;
00058 }
00059
00060
00061 std::vector<int> source_indices_good;
00062 std::vector<int> target_indices_good;
00063 {
00064
00065
00066 typedef typename pcl::SampleConsensusModelRegistration<PointT>::Ptr SampleConsensusModelRegistrationPtr;
00067 SampleConsensusModelRegistrationPtr model;
00068 model.reset (new pcl::SampleConsensusModelRegistration<PointT> (input_, source_indices));
00069
00070 model->setInputTarget (target_, target_indices);
00071
00072 pcl::RandomSampleConsensus<PointT> sac (model, inlier_threshold_);
00073 sac.setMaxIterations (max_iterations_);
00074
00075
00076 if (!sac.computeModel ())
00077 {
00078 remaining_correspondences = original_correspondences;
00079 best_transformation_.setIdentity ();
00080 return;
00081 }
00082 else
00083 {
00084 std::vector<int> inliers;
00085 sac.getInliers (inliers);
00086
00087 if (inliers.size () < 3)
00088 {
00089 remaining_correspondences = original_correspondences;
00090 best_transformation_.setIdentity ();
00091 return;
00092 }
00093 boost::unordered_map<int, int> index_to_correspondence;
00094 for (int i = 0; i < nr_correspondences; ++i)
00095 index_to_correspondence[original_correspondences[i].index_query] = i;
00096
00097 remaining_correspondences.resize (inliers.size ());
00098 for (size_t i = 0; i < inliers.size (); ++i)
00099 remaining_correspondences[i] = original_correspondences[index_to_correspondence[inliers[i]]];
00100
00101
00102 Eigen::VectorXf model_coefficients;
00103 sac.getModelCoefficients (model_coefficients);
00104 best_transformation_.row (0) = model_coefficients.segment<4>(0);
00105 best_transformation_.row (1) = model_coefficients.segment<4>(4);
00106 best_transformation_.row (2) = model_coefficients.segment<4>(8);
00107 best_transformation_.row (3) = model_coefficients.segment<4>(12);
00108 }
00109 }
00110 }
00111
00112 #endif