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>
44 template <
typename Po
intT>
bool
47 if (samples.size () != sample_size_)
49 PCL_ERROR (
"[pcl::SampleConsensusModelRegistration2D::isSampleGood] Wrong number of samples (is %lu, should be %lu)!\n", samples.size (), sample_size_);
66 template <
typename Po
intT>
void
69 PCL_INFO (
"[pcl::SampleConsensusModelRegistration2D<PointT>::getDistancesToModel]\n");
70 if (indices_->size () != indices_tgt_->size ())
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");
82 distances.resize (indices_->size ());
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)
93 Eigen::Vector4f pt_src ((*input_)[(*indices_)[i]].x,
94 (*input_)[(*indices_)[i]].y,
95 (*input_)[(*indices_)[i]].z, 1.0f);
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);
112 distances[i] = std::sqrt ((uv[0] - (*target_)[(*indices_tgt_)[i]].u) *
113 (uv[0] - (*target_)[(*indices_tgt_)[i]].u) +
114 (uv[1] - (*target_)[(*indices_tgt_)[i]].v) *
115 (uv[1] - (*target_)[(*indices_tgt_)[i]].v));
120 template <
typename Po
intT>
void
123 if (indices_->size () != indices_tgt_->size ())
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;
138 error_sqr_dists_.clear ();
139 inliers.reserve (indices_->size ());
140 error_sqr_dists_.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)
150 Eigen::Vector4f pt_src ((*input_)[(*indices_)[i]].x,
151 (*input_)[(*indices_)[i]].y,
152 (*input_)[(*indices_)[i]].z, 1.0f);
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));
173 inliers.push_back ((*indices_)[i]);
174 error_sqr_dists_.push_back (
distance);
180 template <
typename Po
intT> std::size_t
182 const Eigen::VectorXf &model_coefficients,
const double threshold)
const
184 if (indices_->size () != indices_tgt_->size ())
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)
207 Eigen::Vector4f pt_src ((*input_)[(*indices_)[i]].x,
208 (*input_)[(*indices_)[i]].y,
209 (*input_)[(*indices_)[i]].z, 1.0f);
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);
225 if (((uv[0] - (*target_)[(*indices_tgt_)[i]].u) *
226 (uv[0] - (*target_)[(*indices_tgt_)[i]].u) +
227 (uv[1] - (*target_)[(*indices_tgt_)[i]].v) *
228 (uv[1] - (*target_)[(*indices_tgt_)[i]].v)) < thresh)
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.
float distance(const PointT &p1, const PointT &p2)
IndicesAllocator<> Indices
Type used for indices in PCL.