Point Cloud Library (PCL)
1.9.1
|
41 #ifndef PCL_SAMPLE_CONSENSUS_MODEL_H_
42 #define PCL_SAMPLE_CONSENSUS_MODEL_H_
49 #include <pcl/console/print.h>
50 #include <pcl/point_cloud.h>
51 #include <pcl/sample_consensus/boost.h>
52 #include <pcl/sample_consensus/model_types.h>
54 #include <pcl/search/search.h>
58 template<
class T>
class ProgressiveSampleConsensus;
65 template <
typename Po
intT>
74 typedef boost::shared_ptr<SampleConsensusModel>
Ptr;
75 typedef boost::shared_ptr<const SampleConsensusModel>
ConstPtr;
96 rng_alg_.seed (
static_cast<unsigned> (std::time(0)));
122 rng_alg_.seed (
static_cast<unsigned> (std::time (0)));
139 const std::vector<int> &indices,
154 rng_alg_.seed (
static_cast<unsigned> (std::time(0)));
160 PCL_ERROR (
"[pcl::SampleConsensusModel] Invalid index vector given with size %lu while the input PointCloud has size %lu!\n",
indices_->size (),
input_->points.size ());
183 PCL_ERROR (
"[pcl::SampleConsensusModel::getSamples] Can not select %lu unique points out of %lu!\n",
184 samples.size (),
indices_->size ());
187 iterations = INT_MAX - 1;
204 PCL_DEBUG (
"[pcl::SampleConsensusModel::getSamples] Selected %lu samples.\n", samples.size ());
208 PCL_DEBUG (
"[pcl::SampleConsensusModel::getSamples] WARNING: Could not select %d sample points in %d iterations!\n",
getSampleSize (),
max_sample_checks_);
221 Eigen::VectorXf &model_coefficients)
const = 0;
235 const Eigen::VectorXf &model_coefficients,
236 Eigen::VectorXf &optimized_coefficients)
const = 0;
245 std::vector<double> &distances)
const = 0;
257 const double threshold,
258 std::vector<int> &inliers) = 0;
271 const double threshold)
const = 0;
283 const Eigen::VectorXf &model_coefficients,
285 bool copy_data_fields =
true)
const = 0;
297 const Eigen::VectorXf &model_coefficients,
298 const double threshold)
const = 0;
308 indices_.reset (
new std::vector<int> ());
312 indices_->resize (cloud->points.size ());
313 for (
size_t i = 0; i < cloud->points.size (); ++i)
314 (*
indices_)[i] =
static_cast<int> (i);
320 inline PointCloudConstPtr
327 setIndices (
const boost::shared_ptr <std::vector<int> > &indices)
339 indices_.reset (
new std::vector<int> (indices));
344 inline boost::shared_ptr <std::vector<int> >
352 inline const std::string&
427 std::vector<double> dists (error_sqr_dists);
428 const size_t medIdx = dists.size () >> 1;
429 std::nth_element (dists.begin (), dists.begin () + medIdx, dists.end ());
430 double median_error_sqr = dists[medIdx];
431 return (2.1981 * median_error_sqr);
443 PCL_ERROR (
"[pcl::SampleConsensusModel::computeVariance] The variance of the Sample Consensus model distances cannot be estimated, as the model has not been computed yet. Please compute the model first or at least run selectWithinDistance before continuing. Returning NAN!\n");
444 return (std::numeric_limits<double>::quiet_NaN ());
457 size_t sample_size = sample.size ();
459 for (
unsigned int i = 0; i < sample_size; ++i)
474 size_t sample_size = sample.size ();
480 std::vector<int> indices;
481 std::vector<float> sqr_dists;
491 if (indices.size () < sample_size - 1)
494 for(
unsigned int i = 1; i < sample_size; ++i)
499 for (
unsigned int i = 0; i < sample_size-1; ++i)
500 std::swap (indices[i], indices[i + (
rnd () % (indices.size () - i))]);
501 for (
unsigned int i = 1; i < sample_size; ++i)
520 PCL_ERROR (
"[pcl::%s::isModelValid] Invalid number of model coefficients given (%lu)!\n",
getClassName ().c_str (), model_coefficients.size ());
531 isSampleGood (
const std::vector<int> &samples)
const = 0;
566 boost::shared_ptr<boost::variate_generator< boost::mt19937&, boost::uniform_int<> > >
rng_gen_;
584 EIGEN_MAKE_ALIGNED_OPERATOR_NEW
590 template <
typename Po
intT,
typename Po
intNT>
597 typedef boost::shared_ptr<SampleConsensusModelFromNormals>
Ptr;
598 typedef boost::shared_ptr<const SampleConsensusModelFromNormals>
ConstPtr;
652 template<
typename _Scalar,
int NX=Eigen::Dynamic,
int NY=Eigen::Dynamic>
662 typedef Eigen::Matrix<Scalar,ValuesAtCompileTime,1>
ValueType;
663 typedef Eigen::Matrix<Scalar,InputsAtCompileTime,1>
InputType;
664 typedef Eigen::Matrix<Scalar,ValuesAtCompileTime,InputsAtCompileTime>
JacobianType;
672 Functor (
int m_data_points) : m_data_points_ (m_data_points) {}
678 values ()
const {
return (m_data_points_); }
681 const int m_data_points_;
685 #endif //#ifndef PCL_SAMPLE_CONSENSUS_MODEL_H_
virtual bool computeModelCoefficients(const std::vector< int > &samples, Eigen::VectorXf &model_coefficients) const =0
Check whether the given index samples can form a valid model, compute the model coefficients from the...
boost::shared_ptr< std::vector< int > > indices_
A pointer to the vector of point indices to use.
virtual ~SampleConsensusModel()
Destructor for base SampleConsensusModel.
This file defines compatibility wrappers for low level I/O functions.
void setIndices(const boost::shared_ptr< std::vector< int > > &indices)
Provide a pointer to the vector of indices that represents the input data.
boost::shared_ptr< PointCloud< PointT > > Ptr
boost::shared_ptr< SampleConsensusModel > Ptr
pcl::PointCloud< PointT >::Ptr PointCloudPtr
SearchPtr samples_radius_search_
The search object for picking subsequent samples using radius search.
void drawIndexSampleRadius(std::vector< int > &sample)
Fills a sample array with one random sample from the indices_ vector and other random samples that ar...
void setSamplesMaxDist(const double &radius, SearchPtr search)
Set the maximum distance allowed when drawing random samples.
boost::shared_ptr< pcl::search::Search< PointT > > Ptr
const std::string & getClassName() const
Get a string representation of the name of this class.
void setInputNormals(const PointCloudNConstPtr &normals)
Provide a pointer to the input dataset that contains the point normals of the XYZ dataset.
SampleConsensusModelFromNormals represents the base model class for models that require the use of su...
boost::shared_ptr< std::vector< int > > getIndices() const
Get a pointer to the vector of indices used.
boost::shared_ptr< boost::variate_generator< boost::mt19937 &, boost::uniform_int<> > > rng_gen_
Boost-based random number generator.
PointCloudConstPtr getInputCloud() const
Get a pointer to the input point cloud dataset.
pcl::PointCloud< PointT > PointCloud
virtual void optimizeModelCoefficients(const std::vector< int > &inliers, const Eigen::VectorXf &model_coefficients, Eigen::VectorXf &optimized_coefficients) const =0
Recompute the model coefficients using the given inlier set and return them to the user.
unsigned int sample_size_
The size of a sample from which the model is computed.
virtual void projectPoints(const std::vector< int > &inliers, const Eigen::VectorXf &model_coefficients, PointCloud &projected_points, bool copy_data_fields=true) const =0
Create a new point cloud with inliers projected onto the model.
void getRadiusLimits(double &min_radius, double &max_radius) const
Get the minimum and maximum allowable radius limits for the model as set by the user.
unsigned int model_size_
The number of coefficients in the model.
RandomSampleConsensus represents an implementation of the RANSAC (RAndom SAmple Consensus) algorithm,...
void getSamplesMaxDist(double &radius) const
Get maximum distance allowed when drawing random samples.
boost::shared_ptr< SampleConsensusModelFromNormals > Ptr
PointCloud represents the base class in PCL for storing collections of 3D points.
boost::shared_ptr< boost::uniform_int<> > rng_dist_
Boost-based random number generator distribution.
A point structure representing Euclidean xyz coordinates, and the RGB color.
virtual ~SampleConsensusModelFromNormals()
Destructor.
PointCloudNConstPtr getInputNormals()
Get a pointer to the normals of the input XYZ point cloud dataset.
int values() const
Get the number of values.
virtual int countWithinDistance(const Eigen::VectorXf &model_coefficients, const double threshold) const =0
Count all the points which respect the given model coefficients as inliers.
virtual void selectWithinDistance(const Eigen::VectorXf &model_coefficients, const double threshold, std::vector< int > &inliers)=0
Select all the points which respect the given model coefficients as inliers.
PointCloudNConstPtr normals_
A pointer to the input dataset that contains the point normals of the XYZ dataset.
pcl::PointCloud< PointT >::ConstPtr PointCloudConstPtr
Eigen::Matrix< Scalar, InputsAtCompileTime, 1 > InputType
Functor(int m_data_points)
Constructor.
double getNormalDistanceWeight()
Get the normal angular distance weight.
virtual SacModel getModelType() const =0
Return an unique id for each type of model employed.
static const unsigned int max_sample_checks_
The maximum number of samples to try until we get a good one.
SampleConsensusModel(const PointCloudConstPtr &cloud, const std::vector< int > &indices, bool random=false)
Constructor for base SampleConsensusModel.
virtual void getSamples(int &iterations, std::vector< int > &samples)
Get a set of random data samples and return them as point indices.
virtual void getDistancesToModel(const Eigen::VectorXf &model_coefficients, std::vector< double > &distances) const =0
Compute all distances from the cloud data to a given model.
Base functor all the models that need non linear optimization must define their own one and implement...
unsigned int getModelSize() const
Return the number of coefficients in the model.
virtual bool isModelValid(const Eigen::VectorXf &model_coefficients) const
Check whether a model is valid given the user constraints.
void setNormalDistanceWeight(const double w)
Set the normal angular distance weight.
double samples_radius_
The maximum distance of subsequent samples from the first (radius search)
Eigen::Matrix< Scalar, ValuesAtCompileTime, 1 > ValueType
void setRadiusLimits(const double &min_radius, const double &max_radius)
Set the minimum and maximum allowable radius limits for the model (applicable to models that estimate...
SampleConsensusModelFromNormals()
Empty constructor for base SampleConsensusModelFromNormals.
virtual void setInputCloud(const PointCloudConstPtr &cloud)
Provide a pointer to the input dataset.
double radius_min_
The minimum and maximum radius limits for the model.
virtual bool isSampleGood(const std::vector< int > &samples) const =0
Check if a sample of indices results in a good sample of points indices.
Eigen::Matrix< Scalar, ValuesAtCompileTime, InputsAtCompileTime > JacobianType
int rnd()
Boost-based random number generator.
std::string model_name_
The model name.
unsigned int getSampleSize() const
Return the size of a sample from which the model is computed.
void drawIndexSample(std::vector< int > &sample)
Fills a sample array with random samples from the indices_ vector.
SampleConsensusModel(bool random=false)
Empty constructor for base SampleConsensusModel.
boost::shared_ptr< const SampleConsensusModelFromNormals > ConstPtr
std::vector< double > error_sqr_dists_
A vector holding the distances to the computed model.
boost::shared_ptr< const PointCloud< PointT > > ConstPtr
boost::shared_ptr< const SampleConsensusModel > ConstPtr
virtual bool doSamplesVerifyModel(const std::set< int > &indices, const Eigen::VectorXf &model_coefficients, const double threshold) const =0
Verify whether a subset of indices verifies a given set of model coefficients.
Functor()
Empty Constructor.
double computeVariance(const std::vector< double > &error_sqr_dists) const
Compute the variance of the errors to the model.
double computeVariance() const
Compute the variance of the errors to the model from the internally estimated vector of distances.
SampleConsensusModel represents the base model class.
std::vector< int > shuffled_indices_
Data containing a shuffled version of the indices.
pcl::PointCloud< PointNT >::ConstPtr PointCloudNConstPtr
pcl::search::Search< PointT >::Ptr SearchPtr
SampleConsensusModel(const PointCloudConstPtr &cloud, bool random=false)
Constructor for base SampleConsensusModel.
PointCloudConstPtr input_
A boost shared pointer to the point cloud data array.
double normal_distance_weight_
The relative weight (between 0 and 1) to give to the angular distance (0 to pi/2) between point norma...
boost::mt19937 rng_alg_
Boost-based random number generator algorithm.
pcl::PointCloud< PointNT >::Ptr PointCloudNPtr
void setIndices(const std::vector< int > &indices)
Provide the vector of indices that represents the input data.