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 ());
102 inlier_indices_.clear ();
104 int nr_correspondences =
static_cast<int> (original_correspondences.size ());
105 std::vector<int> source_indices (nr_correspondences);
106 std::vector<int> target_indices (nr_correspondences);
109 for (
size_t i = 0; i < original_correspondences.size (); ++i)
111 source_indices[i] = original_correspondences[i].index_query;
112 target_indices[i] = original_correspondences[i].index_match;
116 std::vector<int> source_indices_good;
117 std::vector<int> target_indices_good;
122 SampleConsensusModelRegistrationPtr model;
125 model->setInputTarget (target_, target_indices);
133 remaining_correspondences = original_correspondences;
134 best_transformation_.setIdentity ();
141 PCL_ERROR (
"[pcl::registration::CorrespondenceRejectorSampleConsensus::getRemainingCorrespondences] Could not refine the model! Returning an empty solution.\n");
145 std::vector<int> inliers;
148 if (inliers.size () < 3)
150 remaining_correspondences = original_correspondences;
151 best_transformation_.setIdentity ();
154 boost::unordered_map<int, int> index_to_correspondence;
155 for (
int i = 0; i < nr_correspondences; ++i)
156 index_to_correspondence[original_correspondences[i].index_query] = i;
158 remaining_correspondences.resize (inliers.size ());
159 for (
size_t i = 0; i < inliers.size (); ++i)
160 remaining_correspondences[i] = original_correspondences[index_to_correspondence[inliers[i]]];
164 inlier_indices_.reserve (inliers.size ());
165 for (
size_t i = 0; i < inliers.size (); ++i)
166 inlier_indices_.push_back (index_to_correspondence[inliers[i]]);
170 Eigen::VectorXf model_coefficients;
172 best_transformation_.row (0) = model_coefficients.segment<4>(0);
173 best_transformation_.row (1) = model_coefficients.segment<4>(4);
174 best_transformation_.row (2) = model_coefficients.segment<4>(8);
175 best_transformation_.row (3) = model_coefficients.segment<4>(12);
180 #endif // PCL_REGISTRATION_IMPL_CORRESPONDENCE_REJECTION_SAMPLE_CONSENSUS_HPP_ boost::shared_ptr< SampleConsensusModelRegistration > Ptr
SampleConsensusModelRegistration defines a model for Point-To-Point registration outlier rejection...
virtual void setTargetCloud(const PointCloudConstPtr &cloud)
Provide a target point cloud dataset (must contain XYZ data!)
bool computeModel(int debug_verbosity_level=0)
Compute the actual model and find the inliers.
PointCloudConstPtr const getInputCloud()
Get a pointer to the input point cloud dataset target.
void setMaxIterations(int max_iterations)
Set the maximum number of iterations.
int getMaxIterations()
Get the maximum number of iterations.
void getInliers(std::vector< int > &inliers)
Return the best set of inliers found so far for this model.
std::vector< pcl::Correspondence, Eigen::aligned_allocator< pcl::Correspondence > > Correspondences
void getModelCoefficients(Eigen::VectorXf &model_coefficients)
Return the model coefficients of the best model found so far.
virtual void setInputCloud(const PointCloudConstPtr &cloud)
Provide a source point cloud dataset (must contain XYZ data!)
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.
RandomSampleConsensus represents an implementation of the RANSAC (RAndom SAmple Consensus) algorithm...
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.