41 #ifndef PCL_REGISTRATION_IMPL_CORRESPONDENCE_REJECTION_SAMPLE_CONSENSUS_HPP_ 42 #define PCL_REGISTRATION_IMPL_CORRESPONDENCE_REJECTION_SAMPLE_CONSENSUS_HPP_ 44 #include <unordered_map> 45 #include <pcl/sample_consensus/ransac.h> 46 #include <pcl/sample_consensus/sac_model_registration.h> 52 namespace registration
55 template <
typename Po
intT>
void 62 PCL_ERROR (
"[pcl::registration::%s::getRemainingCorrespondences] No input cloud dataset was given!\n", getClassName ().c_str ());
68 PCL_ERROR (
"[pcl::registration::%s::getRemainingCorrespondences] No input target dataset was given!\n", getClassName ().c_str ());
73 inlier_indices_.clear ();
75 int nr_correspondences =
static_cast<int> (original_correspondences.size ());
76 std::vector<int> source_indices (nr_correspondences);
77 std::vector<int> target_indices (nr_correspondences);
80 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;
90 SampleConsensusModelRegistrationPtr model;
93 model->setInputTarget (target_, target_indices);
101 remaining_correspondences = original_correspondences;
102 best_transformation_.setIdentity ();
107 PCL_ERROR (
"[pcl::registration::CorrespondenceRejectorSampleConsensus::getRemainingCorrespondences] Could not refine the model! Returning an empty solution.\n");
111 std::vector<int> inliers;
114 if (inliers.size () < 3)
116 remaining_correspondences = original_correspondences;
117 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]]];
130 inlier_indices_.reserve (inliers.size ());
131 for (
const int &inlier : inliers)
132 inlier_indices_.push_back (index_to_correspondence[inlier]);
136 Eigen::VectorXf model_coefficients;
138 best_transformation_.row (0) = model_coefficients.segment<4>(0);
139 best_transformation_.row (1) = model_coefficients.segment<4>(4);
140 best_transformation_.row (2) = model_coefficients.segment<4>(8);
141 best_transformation_.row (3) = model_coefficients.segment<4>(12);
148 #endif // PCL_REGISTRATION_IMPL_CORRESPONDENCE_REJECTION_SAMPLE_CONSENSUS_HPP_ SampleConsensusModelRegistration defines a model for Point-To-Point registration outlier rejection...
void getInliers(Indices &inliers) const
Return the best set of inliers found so far for this model.
shared_ptr< SampleConsensusModelRegistration< PointT > > Ptr
void setMaxIterations(int max_iterations)
Set the maximum number of iterations.
virtual bool refineModel(const double sigma=3.0, const unsigned int max_iterations=1000)
Refine the model found.
bool computeModel(int debug_verbosity_level=0) override
Compute the actual model and find the inliers.
std::vector< pcl::Correspondence, Eigen::aligned_allocator< pcl::Correspondence > > Correspondences
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.
RandomSampleConsensus represents an implementation of the RANSAC (RANdom SAmple Consensus) algorithm...
void getModelCoefficients(Eigen::VectorXf &model_coefficients) const
Return the model coefficients of the best model found so far.