39 #ifndef PCL_REGISTRATION_IMPL_CORRESPONDENCE_REJECTION_SAMPLE_CONSENSUS_2D_HPP_
40 #define PCL_REGISTRATION_IMPL_CORRESPONDENCE_REJECTION_SAMPLE_CONSENSUS_2D_HPP_
42 #include <pcl/sample_consensus/sac_model_registration_2d.h>
43 #include <pcl/sample_consensus/ransac.h>
45 #include <unordered_map>
51 namespace registration
54 template <
typename Po
intT>
void
61 PCL_ERROR (
"[pcl::registration::%s::getRemainingCorrespondences] No input cloud dataset was given!\n", getClassName ().c_str ());
67 PCL_ERROR (
"[pcl::registration::%s::getRemainingCorrespondences] No input target dataset was given!\n", getClassName ().c_str ());
71 if (projection_matrix_ == Eigen::Matrix3f::Identity ())
73 PCL_ERROR (
"[pcl::registration::%s::getRemainingCorrespondences] Intrinsic camera parameters not given!\n", getClassName ().c_str ());
77 int nr_correspondences =
static_cast<int> (original_correspondences.size ());
78 std::vector<int> source_indices (nr_correspondences);
79 std::vector<int> target_indices (nr_correspondences);
82 for (std::size_t i = 0; i < original_correspondences.size (); ++i)
84 source_indices[i] = original_correspondences[i].index_query;
85 target_indices[i] = original_correspondences[i].index_match;
101 PCL_ERROR (
"[pcl::registration::%s::getRemainingCorrespondences] Error computing model! Returning the original correspondences...\n", getClassName ().c_str ());
102 remaining_correspondences = original_correspondences;
103 best_transformation_.setIdentity ();
107 PCL_WARN (
"[pcl::registration::%s::getRemainingCorrespondences] Error refining model!\n", getClassName ().c_str ());
109 std::vector<int> inliers;
112 if (inliers.size () < 3)
114 PCL_ERROR (
"[pcl::registration::%s::getRemainingCorrespondences] Less than 3 correspondences found!\n", getClassName ().c_str ());
115 remaining_correspondences = original_correspondences;
116 best_transformation_.setIdentity ();
120 std::unordered_map<int, int> index_to_correspondence;
121 for (
int i = 0; i < nr_correspondences; ++i)
122 index_to_correspondence[original_correspondences[i].index_query] = i;
124 remaining_correspondences.resize (inliers.size ());
125 for (std::size_t i = 0; i < inliers.size (); ++i)
126 remaining_correspondences[i] = original_correspondences[index_to_correspondence[inliers[i]]];
129 Eigen::VectorXf model_coefficients;
131 best_transformation_.row (0) = model_coefficients.segment<4>(0);
132 best_transformation_.row (1) = model_coefficients.segment<4>(4);
133 best_transformation_.row (2) = model_coefficients.segment<4>(8);
134 best_transformation_.row (3) = model_coefficients.segment<4>(12);
140 #endif // PCL_REGISTRATION_IMPL_CORRESPONDENCE_REJECTION_SAMPLE_CONSENSUS_2D_HPP_