41#ifndef PCL_SAMPLE_CONSENSUS_IMPL_SAC_MODEL_LINE_H_
42#define PCL_SAMPLE_CONSENSUS_IMPL_SAC_MODEL_LINE_H_
44#include <pcl/sample_consensus/sac_model_line.h>
46#include <pcl/common/concatenate.h>
47#include <pcl/common/eigen.h>
50template <
typename Po
intT>
bool
55 PCL_ERROR (
"[pcl::SampleConsensusModelLine::isSampleGood] Wrong number of samples (is %lu, should be %lu)!\n",
samples.
size (), sample_size_);
73template <
typename Po
intT>
bool
80 PCL_ERROR (
"[pcl::SampleConsensusModelLine::computeModelCoefficients] Invalid set of samples given (%lu)!\n",
samples.
size ());
84 if (std::abs ((*input_)[
samples[0]].x - (*input_)[
samples[1]].x) <= std::numeric_limits<float>::epsilon () &&
85 std::abs ((*input_)[
samples[0]].y - (*input_)[
samples[1]].y) <= std::numeric_limits<float>::epsilon () &&
86 std::abs ((*input_)[
samples[0]].z - (*input_)[
samples[1]].z) <= std::numeric_limits<float>::epsilon ())
101 PCL_DEBUG (
"[pcl::SampleConsensusModelLine::computeModelCoefficients] Model is (%g,%g,%g,%g,%g,%g).\n",
108template <
typename Po
intT>
void
118 distances.resize (indices_->size ());
126 for (std::size_t i = 0; i < indices_->size (); ++i)
136template <
typename Po
intT>
void
147 error_sqr_dists_.clear ();
148 inliers.reserve (indices_->size ());
149 error_sqr_dists_.reserve (indices_->size ());
157 for (std::size_t i = 0; i < indices_->size (); ++i)
166 inliers.push_back ((*indices_)[i]);
173template <
typename Po
intT> std::size_t
183 std::size_t
nr_p = 0;
191 for (std::size_t i = 0; i < indices_->size (); ++i)
204template <
typename Po
intT>
void
218 PCL_ERROR (
"[pcl::SampleConsensusModelLine::optimizeModelCoefficients] Not enough inliers to refine/optimize the model's coefficients (%lu)! Returning the same coefficients.\n",
inliers.
size ());
226 Eigen::Vector4f centroid;
229 PCL_WARN (
"[pcl::SampleConsensusModelLine::optimizeModelCoefficients] compute3DCentroid failed (returned 0) because there are no valid inliers.\n");
250template <
typename Po
intT>
void
273 using FieldList =
typename pcl::traits::fieldList<PointT>::type;
300 using FieldList =
typename pcl::traits::fieldList<PointT>::type;
323template <
typename Po
intT>
bool
325 const std::set<index_t> &indices,
const Eigen::VectorXf &
model_coefficients,
const double threshold)
const
338 for (
const auto &index : indices)
349#define PCL_INSTANTIATE_SampleConsensusModelLine(T) template class PCL_EXPORTS pcl::SampleConsensusModelLine<T>;
Define methods for centroid estimation and covariance matrix calculus.
Iterator class for point clouds with or without given indices.
std::size_t size() const
Size of the range the iterator is going through.
bool computeModelCoefficients(const Indices &samples, Eigen::VectorXf &model_coefficients) const override
Check whether the given index samples can form a valid line model, compute the model coefficients fro...
std::size_t countWithinDistance(const Eigen::VectorXf &model_coefficients, const double threshold) const override
Count all the points which respect the given model coefficients as inliers.
void getDistancesToModel(const Eigen::VectorXf &model_coefficients, std::vector< double > &distances) const override
Compute all squared distances from the cloud data to a given line model.
bool isSampleGood(const Indices &samples) const override
Check if a sample of indices results in a good sample of points indices.
bool doSamplesVerifyModel(const std::set< index_t > &indices, const Eigen::VectorXf &model_coefficients, const double threshold) const override
Verify whether a subset of indices verifies the given line model coefficients.
void optimizeModelCoefficients(const Indices &inliers, const Eigen::VectorXf &model_coefficients, Eigen::VectorXf &optimized_coefficients) const override
Recompute the line coefficients using the given inlier set and return them to the user.
void projectPoints(const Indices &inliers, const Eigen::VectorXf &model_coefficients, PointCloud &projected_points, bool copy_data_fields=true) const override
Create a new point cloud with inliers projected onto the line model.
typename SampleConsensusModel< PointT >::PointCloud PointCloud
void selectWithinDistance(const Eigen::VectorXf &model_coefficients, const double threshold, Indices &inliers) override
Select all the points which respect the given model coefficients as inliers.
void computeCorrespondingEigenVector(const Matrix &mat, const typename Matrix::Scalar &eigenvalue, Vector &eigenvector)
determines the corresponding eigenvector to the given eigenvalue of the symmetric positive semi defin...
unsigned int computeCovarianceMatrix(const pcl::PointCloud< PointT > &cloud, const Eigen::Matrix< Scalar, 4, 1 > ¢roid, Eigen::Matrix< Scalar, 3, 3 > &covariance_matrix)
Compute the 3x3 covariance matrix of a given set of points.
void eigen33(const Matrix &mat, typename Matrix::Scalar &eigenvalue, Vector &eigenvector)
determines the eigenvector and eigenvalue of the smallest eigenvalue of the symmetric positive semi d...
unsigned int compute3DCentroid(ConstCloudIterator< PointT > &cloud_iterator, Eigen::Matrix< Scalar, 4, 1 > ¢roid)
Compute the 3D (X-Y-Z) centroid of a set of points and return it as a 3D vector.
IndicesAllocator<> Indices
Type used for indices in PCL.