40 #ifndef PCL_REGISTRATION_IMPL_CORRESPONDENCE_REJECTION_SAMPLE_CONSENSUS_HPP_
41 #define PCL_REGISTRATION_IMPL_CORRESPONDENCE_REJECTION_SAMPLE_CONSENSUS_HPP_
43 #include <boost/unordered_map.hpp>
46 template <
typename Po
intT>
void
48 const typename pcl::registration::CorrespondenceRejectorSampleConsensus<PointT>::PointCloudConstPtr &cloud)
50 setInputSource (cloud);
54 template <
typename Po
intT>
typename pcl::registration::CorrespondenceRejectorSampleConsensus<PointT>::PointCloudConstPtr
const
57 return (getInputSource ());
61 template <
typename Po
intT>
void
63 const typename pcl::registration::CorrespondenceRejectorSampleConsensus<PointT>::PointCloudConstPtr &cloud)
65 setInputTarget (cloud);
69 template <
typename Po
intT>
void
73 setMaximumIterations (max_iterations);
77 template <
typename Po
intT>
int
80 return (getMaximumIterations ());
84 template <
typename Po
intT>
void
91 PCL_ERROR (
"[pcl::registration::%s::getRemainingCorrespondences] No input cloud dataset was given!\n", getClassName ().c_str ());
97 PCL_ERROR (
"[pcl::registration::%s::getRemainingCorrespondences] No input target dataset was given!\n", getClassName ().c_str ());
101 int nr_correspondences =
static_cast<int> (original_correspondences.size ());
102 std::vector<int> source_indices (nr_correspondences);
103 std::vector<int> target_indices (nr_correspondences);
106 for (
size_t i = 0; i < original_correspondences.size (); ++i)
108 source_indices[i] = original_correspondences[i].index_query;
109 target_indices[i] = original_correspondences[i].index_match;
113 std::vector<int> source_indices_good;
114 std::vector<int> target_indices_good;
119 SampleConsensusModelRegistrationPtr model;
122 model->setInputTarget (target_, target_indices);
130 remaining_correspondences = original_correspondences;
131 best_transformation_.setIdentity ();
138 PCL_ERROR (
"[pcl::registration::CorrespondenceRejectorSampleConsensus::getRemainingCorrespondences] Could not refine the model! Returning an empty solution.\n");
142 std::vector<int> inliers;
145 if (inliers.size () < 3)
147 remaining_correspondences = original_correspondences;
148 best_transformation_.setIdentity ();
151 boost::unordered_map<int, int> index_to_correspondence;
152 for (
int i = 0; i < nr_correspondences; ++i)
153 index_to_correspondence[original_correspondences[i].index_query] = i;
155 remaining_correspondences.resize (inliers.size ());
156 for (
size_t i = 0; i < inliers.size (); ++i)
157 remaining_correspondences[i] = original_correspondences[index_to_correspondence[inliers[i]]];
161 inlier_indices_.reserve (inliers.size ());
162 for (
size_t i = 0; i < inliers.size (); ++i)
163 inlier_indices_.push_back (index_to_correspondence[inliers[i]]);
167 Eigen::VectorXf model_coefficients;
169 best_transformation_.row (0) = model_coefficients.segment<4>(0);
170 best_transformation_.row (1) = model_coefficients.segment<4>(4);
171 best_transformation_.row (2) = model_coefficients.segment<4>(8);
172 best_transformation_.row (3) = model_coefficients.segment<4>(12);
177 #endif // PCL_REGISTRATION_IMPL_CORRESPONDENCE_REJECTION_SAMPLE_CONSENSUS_HPP_
std::vector< pcl::Correspondence, Eigen::aligned_allocator< pcl::Correspondence > > Correspondences
SampleConsensusModelRegistration defines a model for Point-To-Point registration outlier rejection...
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.
CorrespondenceRejectorSampleConsensus implements a correspondence rejection using Random Sample Conse...
void getRemainingCorrespondences(const pcl::Correspondences &original_correspondences, pcl::Correspondences &remaining_correspondences)
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 getInliers(std::vector< int > &inliers)
Return the best set of inliers found so far for this model.
boost::shared_ptr< SampleConsensusModelRegistration > Ptr
void getModelCoefficients(Eigen::VectorXf &model_coefficients)
Return the model coefficients of the best model found so far.
bool computeModel(int debug_verbosity_level=0)
Compute the actual model and find the inliers.