41 #ifndef PCL_REGISTRATION_IMPL_CORRESPONDENCE_REJECTION_SAMPLE_CONSENSUS_HPP_
42 #define PCL_REGISTRATION_IMPL_CORRESPONDENCE_REJECTION_SAMPLE_CONSENSUS_HPP_
44 #include <unordered_map>
50 namespace registration
53 template <
typename Po
intT>
void
60 PCL_ERROR (
"[pcl::registration::%s::getRemainingCorrespondences] No input cloud dataset was given!\n", getClassName ().c_str ());
66 PCL_ERROR (
"[pcl::registration::%s::getRemainingCorrespondences] No input target dataset was given!\n", getClassName ().c_str ());
71 inlier_indices_.clear ();
73 int nr_correspondences =
static_cast<int> (original_correspondences.size ());
74 std::vector<int> source_indices (nr_correspondences);
75 std::vector<int> target_indices (nr_correspondences);
78 for (std::size_t i = 0; i < original_correspondences.size (); ++i)
80 source_indices[i] = original_correspondences[i].index_query;
81 target_indices[i] = original_correspondences[i].index_match;
88 SampleConsensusModelRegistrationPtr model;
91 model->setInputTarget (target_, target_indices);
99 remaining_correspondences = original_correspondences;
100 best_transformation_.setIdentity ();
105 PCL_ERROR (
"[pcl::registration::CorrespondenceRejectorSampleConsensus::getRemainingCorrespondences] Could not refine the model! Returning an empty solution.\n");
109 std::vector<int> inliers;
112 if (inliers.size () < 3)
114 remaining_correspondences = original_correspondences;
115 best_transformation_.setIdentity ();
118 std::unordered_map<int, int> index_to_correspondence;
119 for (
int i = 0; i < nr_correspondences; ++i)
120 index_to_correspondence[original_correspondences[i].index_query] = i;
122 remaining_correspondences.resize (inliers.size ());
123 for (std::size_t i = 0; i < inliers.size (); ++i)
124 remaining_correspondences[i] = original_correspondences[index_to_correspondence[inliers[i]]];
128 inlier_indices_.reserve (inliers.size ());
129 for (
const int &inlier : inliers)
130 inlier_indices_.push_back (index_to_correspondence[inlier]);
134 Eigen::VectorXf model_coefficients;
136 best_transformation_.row (0) = model_coefficients.segment<4>(0);
137 best_transformation_.row (1) = model_coefficients.segment<4>(4);
138 best_transformation_.row (2) = model_coefficients.segment<4>(8);
139 best_transformation_.row (3) = model_coefficients.segment<4>(12);
RandomSampleConsensus represents an implementation of the RANSAC (RANdom SAmple Consensus) algorithm,...
bool computeModel(int debug_verbosity_level=0) override
Compute the actual model and find the inliers.
void getInliers(Indices &inliers) const
Return the best set of inliers found so far for this model.
void getModelCoefficients(Eigen::VectorXf &model_coefficients) const
Return the model coefficients of the best model found so far.
virtual bool refineModel(const double sigma=3.0, const unsigned int max_iterations=1000)
Refine the model found.
void setMaxIterations(int max_iterations)
Set the maximum number of iterations.
SampleConsensusModelRegistration defines a model for Point-To-Point registration outlier rejection.
shared_ptr< SampleConsensusModelRegistration< PointT > > Ptr
void getRemainingCorrespondences(const pcl::Correspondences &original_correspondences, pcl::Correspondences &remaining_correspondences) override
Get a list of valid correspondences after rejection from the original set of correspondences.
std::vector< pcl::Correspondence, Eigen::aligned_allocator< pcl::Correspondence > > Correspondences