41 #ifndef PCL_REGISTRATION_IMPL_CORRESPONDENCE_REJECTION_SAMPLE_CONSENSUS_HPP_
42 #define PCL_REGISTRATION_IMPL_CORRESPONDENCE_REJECTION_SAMPLE_CONSENSUS_HPP_
44 #include <pcl/sample_consensus/ransac.h>
45 #include <pcl/sample_consensus/sac_model_registration.h>
47 #include <unordered_map>
51 namespace registration {
53 template <
typename Po
intT>
60 PCL_ERROR(
"[pcl::registration::%s::getRemainingCorrespondences] No input cloud "
61 "dataset was given!\n",
62 getClassName().c_str());
67 PCL_ERROR(
"[pcl::registration::%s::getRemainingCorrespondences] No input target "
68 "dataset was given!\n",
69 getClassName().c_str());
74 inlier_indices_.clear();
76 int nr_correspondences =
static_cast<int>(original_correspondences.size());
81 for (std::size_t i = 0; i < original_correspondences.size(); ++i) {
82 source_indices[i] = original_correspondences[i].index_query;
83 target_indices[i] = original_correspondences[i].index_match;
89 using SampleConsensusModelRegistrationPtr =
91 SampleConsensusModelRegistrationPtr model;
95 model->setInputTarget(target_, target_indices);
102 remaining_correspondences = original_correspondences;
103 best_transformation_.setIdentity();
107 PCL_ERROR(
"[pcl::registration::CorrespondenceRejectorSampleConsensus::"
108 "getRemainingCorrespondences] Could not refine the model! Returning an "
109 "empty solution.\n");
116 if (inliers.size() < 3) {
117 remaining_correspondences = original_correspondences;
118 best_transformation_.setIdentity();
121 std::unordered_map<int, int> index_to_correspondence;
122 for (
int i = 0; i < nr_correspondences; ++i)
123 index_to_correspondence[original_correspondences[i].index_query] = i;
125 remaining_correspondences.resize(inliers.size());
126 for (std::size_t i = 0; i < inliers.size(); ++i)
127 remaining_correspondences[i] =
128 original_correspondences[index_to_correspondence[inliers[i]]];
131 inlier_indices_.reserve(inliers.size());
132 for (
const auto& inlier : inliers)
133 inlier_indices_.push_back(index_to_correspondence[inlier]);
137 Eigen::VectorXf model_coefficients;
139 best_transformation_.row(0) = model_coefficients.segment<4>(0);
140 best_transformation_.row(1) = model_coefficients.segment<4>(4);
141 best_transformation_.row(2) = model_coefficients.segment<4>(8);
142 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
IndicesAllocator<> Indices
Type used for indices in PCL.