38#ifndef PCL_SAMPLE_CONSENSUS_IMPL_SAC_MODEL_REGISTRATION_2D_HPP_
39#define PCL_SAMPLE_CONSENSUS_IMPL_SAC_MODEL_REGISTRATION_2D_HPP_
41#include <pcl/sample_consensus/sac_model_registration_2d.h>
44template <
typename Po
intT>
bool
49 PCL_ERROR (
"[pcl::SampleConsensusModelRegistration2D::isSampleGood] Wrong number of samples (is %lu, should be %lu)!\n", samples.size (),
sample_size_);
66template <
typename Po
intT>
void
69 PCL_INFO (
"[pcl::SampleConsensusModelRegistration2D<PointT>::getDistancesToModel]\n");
72 PCL_ERROR (
"[pcl::SampleConsensusModelRegistration2D::getDistancesToModel] Number of source indices (%lu) differs than number of target indices (%lu)!\n",
indices_->size (),
indices_tgt_->size ());
78 PCL_ERROR (
"[pcl::SampleConsensusModelRegistration2D::getDistanceToModel] No target dataset given!\n");
85 Eigen::Matrix4f transform;
86 transform.row (0).matrix () = model_coefficients.segment<4>(0);
87 transform.row (1).matrix () = model_coefficients.segment<4>(4);
88 transform.row (2).matrix () = model_coefficients.segment<4>(8);
89 transform.row (3).matrix () = model_coefficients.segment<4>(12);
91 for (std::size_t i = 0; i <
indices_->size (); ++i)
97 Eigen::Vector4f p_tr (transform * pt_src);
100 Eigen::Vector3f p_tr3 (p_tr[0], p_tr[1], p_tr[2]);
101 Eigen::Vector3f uv (projection_matrix_ * p_tr3);
120template <
typename Po
intT>
void
125 PCL_ERROR (
"[pcl::SampleConsensusModelRegistration2D::selectWithinDistance] Number of source indices (%lu) differs than number of target indices (%lu)!\n",
indices_->size (),
indices_tgt_->size ());
131 PCL_ERROR (
"[pcl::SampleConsensusModelRegistration2D::selectWithinDistance] No target dataset given!\n");
135 double thresh = threshold * threshold;
139 inliers.reserve (
indices_->size ());
142 Eigen::Matrix4f transform;
143 transform.row (0).matrix () = model_coefficients.segment<4>(0);
144 transform.row (1).matrix () = model_coefficients.segment<4>(4);
145 transform.row (2).matrix () = model_coefficients.segment<4>(8);
146 transform.row (3).matrix () = model_coefficients.segment<4>(12);
148 for (std::size_t i = 0; i <
indices_->size (); ++i)
154 Eigen::Vector4f p_tr (transform * pt_src);
157 Eigen::Vector3f p_tr3 (p_tr[0], p_tr[1], p_tr[2]);
158 Eigen::Vector3f uv (projection_matrix_ * p_tr3);
165 double distance = ((uv[0] - (*target_)[(*indices_tgt_)[i]].u) *
166 (uv[0] - (*target_)[(*indices_tgt_)[i]].u) +
167 (uv[1] - (*target_)[(*indices_tgt_)[i]].v) *
168 (uv[1] - (*target_)[(*indices_tgt_)[i]].v));
171 if (distance < thresh)
180template <
typename Po
intT> std::size_t
182 const Eigen::VectorXf &model_coefficients,
const double threshold)
const
186 PCL_ERROR (
"[pcl::SampleConsensusModelRegistration2D::countWithinDistance] Number of source indices (%lu) differs than number of target indices (%lu)!\n",
indices_->size (),
indices_tgt_->size ());
191 PCL_ERROR (
"[pcl::SampleConsensusModelRegistration2D::countWithinDistance] No target dataset given!\n");
195 double thresh = threshold * threshold;
197 Eigen::Matrix4f transform;
198 transform.row (0).matrix () = model_coefficients.segment<4>(0);
199 transform.row (1).matrix () = model_coefficients.segment<4>(4);
200 transform.row (2).matrix () = model_coefficients.segment<4>(8);
201 transform.row (3).matrix () = model_coefficients.segment<4>(12);
203 std::size_t nr_p = 0;
205 for (std::size_t i = 0; i <
indices_->size (); ++i)
211 Eigen::Vector4f p_tr (transform * pt_src);
214 Eigen::Vector3f p_tr3 (p_tr[0], p_tr[1], p_tr[2]);
215 Eigen::Vector3f uv (projection_matrix_ * p_tr3);
unsigned int sample_size_
The size of a sample from which the model is computed.
IndicesPtr indices_
A pointer to the vector of point indices to use.
PointCloudConstPtr input_
A boost shared pointer to the point cloud data array.
std::vector< double > error_sqr_dists_
A vector holding the distances to the computed model.
void selectWithinDistance(const Eigen::VectorXf &model_coefficients, const double threshold, Indices &inliers)
Select all the points which respect the given model coefficients as inliers.
virtual std::size_t countWithinDistance(const Eigen::VectorXf &model_coefficients, const double threshold) const
Count all the points which respect the given model coefficients as inliers.
bool isSampleGood(const Indices &samples) const
Check if a sample of indices results in a good sample of points indices.
void getDistancesToModel(const Eigen::VectorXf &model_coefficients, std::vector< double > &distances) const
Compute all distances from the transformed points to their correspondences.
IndicesPtr indices_tgt_
A pointer to the vector of target point indices to use.
PointCloudConstPtr target_
A boost shared pointer to the target point cloud data array.
IndicesAllocator<> Indices
Type used for indices in PCL.