Point Cloud Library (PCL)  1.11.0
sac_model.h
1 /*
2  * Software License Agreement (BSD License)
3  *
4  * Point Cloud Library (PCL) - www.pointclouds.org
5  * Copyright (c) 2010-2011, Willow Garage, Inc.
6  * Copyright (c) 2012-, Open Perception, Inc.
7  *
8  * All rights reserved.
9  *
10  * Redistribution and use in source and binary forms, with or without
11  * modification, are permitted provided that the following conditions
12  * are met:
13  *
14  * * Redistributions of source code must retain the above copyright
15  * notice, this list of conditions and the following disclaimer.
16  * * Redistributions in binary form must reproduce the above
17  * copyright notice, this list of conditions and the following
18  * disclaimer in the documentation and/or other materials provided
19  * with the distribution.
20  * * Neither the name of the copyright holder(s) nor the names of its
21  * contributors may be used to endorse or promote products derived
22  * from this software without specific prior written permission.
23  *
24  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
25  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
26  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
27  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
28  * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
29  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
30  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
31  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
32  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
33  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
34  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
35  * POSSIBILITY OF SUCH DAMAGE.
36  *
37  * $Id$
38  *
39  */
40 
41 #pragma once
42 
43 #include <cfloat>
44 #include <ctime>
45 #include <climits>
46 #include <memory>
47 #include <set>
48 
49 #include <pcl/memory.h>
50 #include <pcl/pcl_macros.h>
51 #include <pcl/pcl_base.h>
52 #include <pcl/console/print.h>
53 #include <pcl/point_cloud.h>
54 #include <pcl/types.h> // for index_t, Indices
55 #include <pcl/sample_consensus/boost.h>
56 #include <pcl/sample_consensus/model_types.h>
57 
58 #include <pcl/search/search.h>
59 
60 namespace pcl
61 {
62  template<class T> class ProgressiveSampleConsensus;
63 
64  /** \brief @b SampleConsensusModel represents the base model class. All sample consensus models must inherit
65  * from this class.
66  * \author Radu B. Rusu
67  * \ingroup sample_consensus
68  */
69  template <typename PointT>
71  {
72  public:
75  using PointCloudPtr = typename PointCloud::Ptr;
77 
78  using Ptr = shared_ptr<SampleConsensusModel<PointT> >;
79  using ConstPtr = shared_ptr<const SampleConsensusModel<PointT> >;
80 
81  protected:
82  /** \brief Empty constructor for base SampleConsensusModel.
83  * \param[in] random if true set the random seed to the current time, else set to 12345 (default: false)
84  */
85  SampleConsensusModel (bool random = false)
86  : input_ ()
87  , radius_min_ (-std::numeric_limits<double>::max ())
88  , radius_max_ (std::numeric_limits<double>::max ())
89  , samples_radius_ (0.)
91  , rng_dist_ (new boost::uniform_int<> (0, std::numeric_limits<int>::max ()))
92  {
93  // Create a random number generator object
94  if (random)
95  rng_alg_.seed (static_cast<unsigned> (std::time(nullptr)));
96  else
97  rng_alg_.seed (12345u);
98 
99  rng_gen_.reset (new boost::variate_generator<boost::mt19937&, boost::uniform_int<> > (rng_alg_, *rng_dist_));
100  }
101 
102  public:
103  /** \brief Constructor for base SampleConsensusModel.
104  * \param[in] cloud the input point cloud dataset
105  * \param[in] random if true set the random seed to the current time, else set to 12345 (default: false)
106  */
107  SampleConsensusModel (const PointCloudConstPtr &cloud, bool random = false)
108  : input_ ()
109  , radius_min_ (-std::numeric_limits<double>::max ())
110  , radius_max_ (std::numeric_limits<double>::max ())
111  , samples_radius_ (0.)
113  , rng_dist_ (new boost::uniform_int<> (0, std::numeric_limits<int>::max ()))
114  {
115  if (random)
116  rng_alg_.seed (static_cast<unsigned> (std::time (nullptr)));
117  else
118  rng_alg_.seed (12345u);
119 
120  // Sets the input cloud and creates a vector of "fake" indices
121  setInputCloud (cloud);
122 
123  // Create a random number generator object
124  rng_gen_.reset (new boost::variate_generator<boost::mt19937&, boost::uniform_int<> > (rng_alg_, *rng_dist_));
125  }
126 
127  /** \brief Constructor for base SampleConsensusModel.
128  * \param[in] cloud the input point cloud dataset
129  * \param[in] indices a vector of point indices to be used from \a cloud
130  * \param[in] random if true set the random seed to the current time, else set to 12345 (default: false)
131  */
133  const Indices &indices,
134  bool random = false)
135  : input_ (cloud)
136  , indices_ (new Indices (indices))
137  , radius_min_ (-std::numeric_limits<double>::max ())
138  , radius_max_ (std::numeric_limits<double>::max ())
139  , samples_radius_ (0.)
141  , rng_dist_ (new boost::uniform_int<> (0, std::numeric_limits<int>::max ()))
142  {
143  if (random)
144  rng_alg_.seed (static_cast<unsigned> (std::time(nullptr)));
145  else
146  rng_alg_.seed (12345u);
147 
148  if (indices_->size () > input_->points.size ())
149  {
150  PCL_ERROR ("[pcl::SampleConsensusModel] Invalid index vector given with size %lu while the input PointCloud has size %lu!\n", indices_->size (), input_->points.size ());
151  indices_->clear ();
152  }
154 
155  // Create a random number generator object
156  rng_gen_.reset (new boost::variate_generator<boost::mt19937&, boost::uniform_int<> > (rng_alg_, *rng_dist_));
157  };
158 
159  /** \brief Destructor for base SampleConsensusModel. */
160  virtual ~SampleConsensusModel () {};
161 
162  /** \brief Get a set of random data samples and return them as point
163  * indices.
164  * \param[out] iterations the internal number of iterations used by SAC methods
165  * \param[out] samples the resultant model samples
166  */
167  virtual void
168  getSamples (int &iterations, Indices &samples)
169  {
170  // We're assuming that indices_ have already been set in the constructor
171  if (indices_->size () < getSampleSize ())
172  {
173  PCL_ERROR ("[pcl::SampleConsensusModel::getSamples] Can not select %lu unique points out of %lu!\n",
174  samples.size (), indices_->size ());
175  // one of these will make it stop :)
176  samples.clear ();
177  iterations = INT_MAX - 1;
178  return;
179  }
180 
181  // Get a second point which is different than the first
182  samples.resize (getSampleSize ());
183  for (unsigned int iter = 0; iter < max_sample_checks_; ++iter)
184  {
185  // Choose the random indices
186  if (samples_radius_ < std::numeric_limits<double>::epsilon ())
188  else
190 
191  // If it's a good sample, stop here
192  if (isSampleGood (samples))
193  {
194  PCL_DEBUG ("[pcl::SampleConsensusModel::getSamples] Selected %lu samples.\n", samples.size ());
195  return;
196  }
197  }
198  PCL_DEBUG ("[pcl::SampleConsensusModel::getSamples] WARNING: Could not select %d sample points in %d iterations!\n", getSampleSize (), max_sample_checks_);
199  samples.clear ();
200  }
201 
202  /** \brief Check whether the given index samples can form a valid model,
203  * compute the model coefficients from these samples and store them
204  * in model_coefficients. Pure virtual.
205  * Implementations of this function must be thread-safe.
206  * \param[in] samples the point indices found as possible good candidates
207  * for creating a valid model
208  * \param[out] model_coefficients the computed model coefficients
209  */
210  virtual bool
211  computeModelCoefficients (const Indices &samples,
212  Eigen::VectorXf &model_coefficients) const = 0;
213 
214  /** \brief Recompute the model coefficients using the given inlier set
215  * and return them to the user. Pure virtual.
216  *
217  * @note: these are the coefficients of the model after refinement
218  * (e.g., after a least-squares optimization)
219  *
220  * \param[in] inliers the data inliers supporting the model
221  * \param[in] model_coefficients the initial guess for the model coefficients
222  * \param[out] optimized_coefficients the resultant recomputed coefficients after non-linear optimization
223  */
224  virtual void
225  optimizeModelCoefficients (const Indices &inliers,
226  const Eigen::VectorXf &model_coefficients,
227  Eigen::VectorXf &optimized_coefficients) const = 0;
228 
229  /** \brief Compute all distances from the cloud data to a given model. Pure virtual.
230  *
231  * \param[in] model_coefficients the coefficients of a model that we need to compute distances to
232  * \param[out] distances the resultant estimated distances
233  */
234  virtual void
235  getDistancesToModel (const Eigen::VectorXf &model_coefficients,
236  std::vector<double> &distances) const = 0;
237 
238  /** \brief Select all the points which respect the given model
239  * coefficients as inliers. Pure virtual.
240  *
241  * \param[in] model_coefficients the coefficients of a model that we need to compute distances to
242  * \param[in] threshold a maximum admissible distance threshold for determining the inliers from
243  * the outliers
244  * \param[out] inliers the resultant model inliers
245  */
246  virtual void
247  selectWithinDistance (const Eigen::VectorXf &model_coefficients,
248  const double threshold,
249  Indices &inliers) = 0;
250 
251  /** \brief Count all the points which respect the given model
252  * coefficients as inliers. Pure virtual.
253  * Implementations of this function must be thread-safe.
254  * \param[in] model_coefficients the coefficients of a model that we need to
255  * compute distances to
256  * \param[in] threshold a maximum admissible distance threshold for
257  * determining the inliers from the outliers
258  * \return the resultant number of inliers
259  */
260  virtual std::size_t
261  countWithinDistance (const Eigen::VectorXf &model_coefficients,
262  const double threshold) const = 0;
263 
264  /** \brief Create a new point cloud with inliers projected onto the model. Pure virtual.
265  * \param[in] inliers the data inliers that we want to project on the model
266  * \param[in] model_coefficients the coefficients of a model
267  * \param[out] projected_points the resultant projected points
268  * \param[in] copy_data_fields set to true (default) if we want the \a
269  * projected_points cloud to be an exact copy of the input dataset minus
270  * the point projections on the plane model
271  */
272  virtual void
273  projectPoints (const Indices &inliers,
274  const Eigen::VectorXf &model_coefficients,
275  PointCloud &projected_points,
276  bool copy_data_fields = true) const = 0;
277 
278  /** \brief Verify whether a subset of indices verifies a given set of
279  * model coefficients. Pure virtual.
280  *
281  * \param[in] indices the data indices that need to be tested against the model
282  * \param[in] model_coefficients the set of model coefficients
283  * \param[in] threshold a maximum admissible distance threshold for
284  * determining the inliers from the outliers
285  */
286  virtual bool
287  doSamplesVerifyModel (const std::set<index_t> &indices,
288  const Eigen::VectorXf &model_coefficients,
289  const double threshold) const = 0;
290 
291  /** \brief Provide a pointer to the input dataset
292  * \param[in] cloud the const boost shared pointer to a PointCloud message
293  */
294  inline virtual void
296  {
297  input_ = cloud;
298  if (!indices_)
299  indices_.reset (new Indices ());
300  if (indices_->empty ())
301  {
302  // Prepare a set of indices to be used (entire cloud)
303  indices_->resize (cloud->points.size ());
304  for (std::size_t i = 0; i < cloud->points.size (); ++i)
305  (*indices_)[i] = static_cast<index_t> (i);
306  }
308  }
309 
310  /** \brief Get a pointer to the input point cloud dataset. */
311  inline PointCloudConstPtr
312  getInputCloud () const { return (input_); }
313 
314  /** \brief Provide a pointer to the vector of indices that represents the input data.
315  * \param[in] indices a pointer to the vector of indices that represents the input data.
316  */
317  inline void
318  setIndices (const IndicesPtr &indices)
319  {
320  indices_ = indices;
322  }
323 
324  /** \brief Provide the vector of indices that represents the input data.
325  * \param[out] indices the vector of indices that represents the input data.
326  */
327  inline void
328  setIndices (const Indices &indices)
329  {
330  indices_.reset (new Indices (indices));
331  shuffled_indices_ = indices;
332  }
333 
334  /** \brief Get a pointer to the vector of indices used. */
335  inline IndicesPtr
336  getIndices () const { return (indices_); }
337 
338  /** \brief Return a unique id for each type of model employed. */
339  virtual SacModel
340  getModelType () const = 0;
341 
342  /** \brief Get a string representation of the name of this class. */
343  inline const std::string&
344  getClassName () const
345  {
346  return (model_name_);
347  }
348 
349  /** \brief Return the size of a sample from which the model is computed. */
350  inline unsigned int
351  getSampleSize () const
352  {
353  return sample_size_;
354  }
355 
356  /** \brief Return the number of coefficients in the model. */
357  inline unsigned int
358  getModelSize () const
359  {
360  return model_size_;
361  }
362 
363  /** \brief Set the minimum and maximum allowable radius limits for the
364  * model (applicable to models that estimate a radius)
365  * \param[in] min_radius the minimum radius model
366  * \param[in] max_radius the maximum radius model
367  * \todo change this to set limits on the entire model
368  */
369  inline void
370  setRadiusLimits (const double &min_radius, const double &max_radius)
371  {
372  radius_min_ = min_radius;
373  radius_max_ = max_radius;
374  }
375 
376  /** \brief Get the minimum and maximum allowable radius limits for the
377  * model as set by the user.
378  *
379  * \param[out] min_radius the resultant minimum radius model
380  * \param[out] max_radius the resultant maximum radius model
381  */
382  inline void
383  getRadiusLimits (double &min_radius, double &max_radius) const
384  {
385  min_radius = radius_min_;
386  max_radius = radius_max_;
387  }
388 
389  /** \brief Set the maximum distance allowed when drawing random samples
390  * \param[in] radius the maximum distance (L2 norm)
391  * \param search
392  */
393  inline void
394  setSamplesMaxDist (const double &radius, SearchPtr search)
395  {
396  samples_radius_ = radius;
397  samples_radius_search_ = search;
398  }
399 
400  /** \brief Get maximum distance allowed when drawing random samples
401  *
402  * \param[out] radius the maximum distance (L2 norm)
403  */
404  inline void
405  getSamplesMaxDist (double &radius) const
406  {
407  radius = samples_radius_;
408  }
409 
411 
412  /** \brief Compute the variance of the errors to the model.
413  * \param[in] error_sqr_dists a vector holding the distances
414  */
415  inline double
416  computeVariance (const std::vector<double> &error_sqr_dists) const
417  {
418  std::vector<double> dists (error_sqr_dists);
419  const std::size_t medIdx = dists.size () >> 1;
420  std::nth_element (dists.begin (), dists.begin () + medIdx, dists.end ());
421  double median_error_sqr = dists[medIdx];
422  return (2.1981 * median_error_sqr);
423  }
424 
425  /** \brief Compute the variance of the errors to the model from the internally
426  * estimated vector of distances. The model must be computed first (or at least
427  * selectWithinDistance must be called).
428  */
429  inline double
431  {
432  if (error_sqr_dists_.empty ())
433  {
434  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");
435  return (std::numeric_limits<double>::quiet_NaN ());
436  }
438  }
439 
440  protected:
441 
442  /** \brief Fills a sample array with random samples from the indices_ vector
443  * \param[out] sample the set of indices of target_ to analyze
444  */
445  inline void
447  {
448  std::size_t sample_size = sample.size ();
449  std::size_t index_size = shuffled_indices_.size ();
450  for (std::size_t i = 0; i < sample_size; ++i)
451  // The 1/(RAND_MAX+1.0) trick is when the random numbers are not uniformly distributed and for small modulo
452  // elements, that does not matter (and nowadays, random number generators are good)
453  //std::swap (shuffled_indices_[i], shuffled_indices_[i + (rand () % (index_size - i))]);
454  std::swap (shuffled_indices_[i], shuffled_indices_[i + (rnd () % (index_size - i))]);
455  std::copy (shuffled_indices_.begin (), shuffled_indices_.begin () + sample_size, sample.begin ());
456  }
457 
458  /** \brief Fills a sample array with one random sample from the indices_ vector
459  * and other random samples that are closer than samples_radius_
460  * \param[out] sample the set of indices of target_ to analyze
461  */
462  inline void
464  {
465  std::size_t sample_size = sample.size ();
466  std::size_t index_size = shuffled_indices_.size ();
467 
468  std::swap (shuffled_indices_[0], shuffled_indices_[0 + (rnd () % (index_size - 0))]);
469  //const PointT& pt0 = (*input_)[shuffled_indices_[0]];
470 
471  Indices indices;
472  std::vector<float> sqr_dists;
473 
474  // If indices have been set when the search object was constructed,
475  // radiusSearch() expects an index into the indices vector as its
476  // first parameter. This can't be determined efficiently, so we use
477  // the point instead of the index.
478  // Returned indices are converted automatically.
479  samples_radius_search_->radiusSearch (input_->at(shuffled_indices_[0]),
480  samples_radius_, indices, sqr_dists );
481 
482  if (indices.size () < sample_size - 1)
483  {
484  // radius search failed, make an invalid model
485  for(std::size_t i = 1; i < sample_size; ++i)
487  }
488  else
489  {
490  for (std::size_t i = 0; i < sample_size-1; ++i)
491  std::swap (indices[i], indices[i + (rnd () % (indices.size () - i))]);
492  for (std::size_t i = 1; i < sample_size; ++i)
493  shuffled_indices_[i] = indices[i-1];
494  }
495 
496  std::copy (shuffled_indices_.begin (), shuffled_indices_.begin () + sample_size, sample.begin ());
497  }
498 
499  /** \brief Check whether a model is valid given the user constraints.
500  *
501  * Default implementation verifies that the number of coefficients in the supplied model is as expected for this
502  * SAC model type. Specific SAC models should extend this function by checking the user constraints (if any).
503  *
504  * \param[in] model_coefficients the set of model coefficients
505  */
506  virtual bool
507  isModelValid (const Eigen::VectorXf &model_coefficients) const
508  {
509  if (model_coefficients.size () != model_size_)
510  {
511  PCL_ERROR ("[pcl::%s::isModelValid] Invalid number of model coefficients given (is %lu, should be %lu)!\n", getClassName ().c_str (), model_coefficients.size (), model_size_);
512  return (false);
513  }
514  return (true);
515  }
516 
517  /** \brief Check if a sample of indices results in a good sample of points
518  * indices. Pure virtual.
519  * \param[in] samples the resultant index samples
520  */
521  virtual bool
522  isSampleGood (const Indices &samples) const = 0;
523 
524  /** \brief The model name. */
525  std::string model_name_;
526 
527  /** \brief A boost shared pointer to the point cloud data array. */
529 
530  /** \brief A pointer to the vector of point indices to use. */
532 
533  /** The maximum number of samples to try until we get a good one */
534  static const unsigned int max_sample_checks_ = 1000;
535 
536  /** \brief The minimum and maximum radius limits for the model.
537  * Applicable to all models that estimate a radius.
538  */
540 
541  /** \brief The maximum distance of subsequent samples from the first (radius search) */
543 
544  /** \brief The search object for picking subsequent samples using radius search */
546 
547  /** Data containing a shuffled version of the indices. This is used and modified when drawing samples. */
549 
550  /** \brief Boost-based random number generator algorithm. */
551  boost::mt19937 rng_alg_;
552 
553  /** \brief Boost-based random number generator distribution. */
554  std::shared_ptr<boost::uniform_int<> > rng_dist_;
555 
556  /** \brief Boost-based random number generator. */
557  std::shared_ptr<boost::variate_generator< boost::mt19937&, boost::uniform_int<> > > rng_gen_;
558 
559  /** \brief A vector holding the distances to the computed model. Used internally. */
560  std::vector<double> error_sqr_dists_;
561 
562  /** \brief The size of a sample from which the model is computed. Every subclass should initialize this appropriately. */
563  unsigned int sample_size_;
564 
565  /** \brief The number of coefficients in the model. Every subclass should initialize this appropriately. */
566  unsigned int model_size_;
567 
568  /** \brief Boost-based random number generator. */
569  inline int
570  rnd ()
571  {
572  return ((*rng_gen_) ());
573  }
574  public:
576  };
577 
578  /** \brief @b SampleConsensusModelFromNormals represents the base model class
579  * for models that require the use of surface normals for estimation.
580  */
581  template <typename PointT, typename PointNT>
582  class SampleConsensusModelFromNormals //: public SampleConsensusModel<PointT>
583  {
584  public:
587 
588  using Ptr = shared_ptr<SampleConsensusModelFromNormals<PointT, PointNT> >;
589  using ConstPtr = shared_ptr<const SampleConsensusModelFromNormals<PointT, PointNT> >;
590 
591  /** \brief Empty constructor for base SampleConsensusModelFromNormals. */
593 
594  /** \brief Destructor. */
596 
597  /** \brief Set the normal angular distance weight.
598  * \param[in] w the relative weight (between 0 and 1) to give to the angular
599  * distance (0 to pi/2) between point normals and the plane normal.
600  * (The Euclidean distance will have weight 1-w.)
601  */
602  inline void
603  setNormalDistanceWeight (const double w)
604  {
606  }
607 
608  /** \brief Get the normal angular distance weight. */
609  inline double
611 
612  /** \brief Provide a pointer to the input dataset that contains the point
613  * normals of the XYZ dataset.
614  *
615  * \param[in] normals the const boost shared pointer to a PointCloud message
616  */
617  inline void
619  {
620  normals_ = normals;
621  }
622 
623  /** \brief Get a pointer to the normals of the input XYZ point cloud dataset. */
624  inline PointCloudNConstPtr
625  getInputNormals () const { return (normals_); }
626 
627  protected:
628  /** \brief The relative weight (between 0 and 1) to give to the angular
629  * distance (0 to pi/2) between point normals and the plane normal.
630  */
632 
633  /** \brief A pointer to the input dataset that contains the point normals
634  * of the XYZ dataset.
635  */
637  };
638 
639  /** Base functor all the models that need non linear optimization must
640  * define their own one and implement operator() (const Eigen::VectorXd& x, Eigen::VectorXd& fvec)
641  * or operator() (const Eigen::VectorXf& x, Eigen::VectorXf& fvec) depending on the chosen _Scalar
642  */
643  template<typename _Scalar, int NX=Eigen::Dynamic, int NY=Eigen::Dynamic>
644  struct Functor
645  {
646  using Scalar = _Scalar;
647  enum
648  {
651  };
652 
653  using ValueType = Eigen::Matrix<Scalar,ValuesAtCompileTime,1>;
654  using InputType = Eigen::Matrix<Scalar,InputsAtCompileTime,1>;
655  using JacobianType = Eigen::Matrix<Scalar,ValuesAtCompileTime,InputsAtCompileTime>;
656 
657  /** \brief Empty Constructor. */
658  Functor () : m_data_points_ (ValuesAtCompileTime) {}
659 
660  /** \brief Constructor
661  * \param[in] m_data_points number of data points to evaluate.
662  */
663  Functor (int m_data_points) : m_data_points_ (m_data_points) {}
664 
665  virtual ~Functor () {}
666 
667  /** \brief Get the number of values. */
668  int
669  values () const { return (m_data_points_); }
670 
671  private:
672  const int m_data_points_;
673  };
674 }
pcl::SampleConsensusModel::projectPoints
virtual void projectPoints(const Indices &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.
pcl_macros.h
Defines all the PCL and non-PCL macros used.
pcl::SampleConsensusModel::~SampleConsensusModel
virtual ~SampleConsensusModel()
Destructor for base SampleConsensusModel.
Definition: sac_model.h:160
pcl
Definition: convolution.h:46
pcl::SampleConsensusModel::SampleConsensusModel
SampleConsensusModel(const PointCloudConstPtr &cloud, const Indices &indices, bool random=false)
Constructor for base SampleConsensusModel.
Definition: sac_model.h:132
pcl::Functor< float >::JacobianType
Eigen::Matrix< Scalar, ValuesAtCompileTime, InputsAtCompileTime > JacobianType
Definition: sac_model.h:655
pcl::IndicesPtr
shared_ptr< Indices > IndicesPtr
Definition: pcl_base.h:61
pcl::Indices
std::vector< index_t > Indices
Type used for indices in PCL.
Definition: types.h:142
pcl::SampleConsensusModel::rng_gen_
std::shared_ptr< boost::variate_generator< boost::mt19937 &, boost::uniform_int<> > > rng_gen_
Boost-based random number generator.
Definition: sac_model.h:557
pcl::SampleConsensusModel::samples_radius_search_
SearchPtr samples_radius_search_
The search object for picking subsequent samples using radius search.
Definition: sac_model.h:545
pcl::SampleConsensusModel::isSampleGood
virtual bool isSampleGood(const Indices &samples) const =0
Check if a sample of indices results in a good sample of points indices.
pcl::SampleConsensusModel::setSamplesMaxDist
void setSamplesMaxDist(const double &radius, SearchPtr search)
Set the maximum distance allowed when drawing random samples.
Definition: sac_model.h:394
pcl::SampleConsensusModel::getClassName
const std::string & getClassName() const
Get a string representation of the name of this class.
Definition: sac_model.h:344
types.h
Defines basic non-point types used by PCL.
pcl::SampleConsensusModel::rng_dist_
std::shared_ptr< boost::uniform_int<> > rng_dist_
Boost-based random number generator distribution.
Definition: sac_model.h:554
pcl::SampleConsensusModelFromNormals::setInputNormals
void setInputNormals(const PointCloudNConstPtr &normals)
Provide a pointer to the input dataset that contains the point normals of the XYZ dataset.
Definition: sac_model.h:618
pcl::SampleConsensusModelFromNormals
SampleConsensusModelFromNormals represents the base model class for models that require the use of su...
Definition: sac_model.h:582
pcl::SampleConsensusModel::getSamples
virtual void getSamples(int &iterations, Indices &samples)
Get a set of random data samples and return them as point indices.
Definition: sac_model.h:168
pcl::SampleConsensusModelFromNormals::getInputNormals
PointCloudNConstPtr getInputNormals() const
Get a pointer to the normals of the input XYZ point cloud dataset.
Definition: sac_model.h:625
pcl::SampleConsensusModel::getInputCloud
PointCloudConstPtr getInputCloud() const
Get a pointer to the input point cloud dataset.
Definition: sac_model.h:312
pcl::Functor< float >::InputType
Eigen::Matrix< Scalar, InputsAtCompileTime, 1 > InputType
Definition: sac_model.h:654
pcl::SampleConsensusModelFromNormals::getNormalDistanceWeight
double getNormalDistanceWeight() const
Get the normal angular distance weight.
Definition: sac_model.h:610
pcl::SampleConsensusModel::selectWithinDistance
virtual void selectWithinDistance(const Eigen::VectorXf &model_coefficients, const double threshold, Indices &inliers)=0
Select all the points which respect the given model coefficients as inliers.
pcl::SampleConsensusModel::sample_size_
unsigned int sample_size_
The size of a sample from which the model is computed.
Definition: sac_model.h:563
boost
Definition: boost_graph.h:46
pcl::SampleConsensusModel::getRadiusLimits
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.
Definition: sac_model.h:383
pcl::SampleConsensusModel::model_size_
unsigned int model_size_
The number of coefficients in the model.
Definition: sac_model.h:566
pcl::ProgressiveSampleConsensus
RandomSampleConsensus represents an implementation of the RANSAC (RAndom SAmple Consensus) algorithm,...
Definition: prosac.h:55
pcl::SampleConsensusModel::getSamplesMaxDist
void getSamplesMaxDist(double &radius) const
Get maximum distance allowed when drawing random samples.
Definition: sac_model.h:405
pcl::PointCloud
PointCloud represents the base class in PCL for storing collections of 3D points.
Definition: projection_matrix.h:52
pcl::SampleConsensusModel::setIndices
void setIndices(const Indices &indices)
Provide the vector of indices that represents the input data.
Definition: sac_model.h:328
pcl::index_t
detail::int_type_t< detail::index_type_size, detail::index_type_signed > index_t
Type used for an index in PCL.
Definition: types.h:136
pcl::SampleConsensusModel< WeightSACPointType >::SearchPtr
typename pcl::search::Search< WeightSACPointType >::Ptr SearchPtr
Definition: sac_model.h:76
pcl::PointXYZRGB
A point structure representing Euclidean xyz coordinates, and the RGB color.
Definition: point_types.hpp:628
pcl::SampleConsensusModelFromNormals::~SampleConsensusModelFromNormals
virtual ~SampleConsensusModelFromNormals()
Destructor.
Definition: sac_model.h:595
pcl::SampleConsensusModel::countWithinDistance
virtual std::size_t countWithinDistance(const Eigen::VectorXf &model_coefficients, const double threshold) const =0
Count all the points which respect the given model coefficients as inliers.
pcl::Functor::values
int values() const
Get the number of values.
Definition: sac_model.h:669
pcl::SampleConsensusModel::optimizeModelCoefficients
virtual void optimizeModelCoefficients(const Indices &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.
pcl::SampleConsensusModelFromNormals::normals_
PointCloudNConstPtr normals_
A pointer to the input dataset that contains the point normals of the XYZ dataset.
Definition: sac_model.h:636
pcl::Functor::Functor
Functor(int m_data_points)
Constructor.
Definition: sac_model.h:663
pcl::SampleConsensusModel::getModelType
virtual SacModel getModelType() const =0
Return a unique id for each type of model employed.
pcl::SampleConsensusModel::max_sample_checks_
static const unsigned int max_sample_checks_
The maximum number of samples to try until we get a good one.
Definition: sac_model.h:534
pcl::Functor::InputsAtCompileTime
@ InputsAtCompileTime
Definition: sac_model.h:649
pcl::SampleConsensusModel::getDistancesToModel
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.
pcl::Functor
Base functor all the models that need non linear optimization must define their own one and implement...
Definition: sac_model.h:644
pcl::SampleConsensusModel::getModelSize
unsigned int getModelSize() const
Return the number of coefficients in the model.
Definition: sac_model.h:358
pcl::SampleConsensusModel::isModelValid
virtual bool isModelValid(const Eigen::VectorXf &model_coefficients) const
Check whether a model is valid given the user constraints.
Definition: sac_model.h:507
pcl::SampleConsensusModelFromNormals::setNormalDistanceWeight
void setNormalDistanceWeight(const double w)
Set the normal angular distance weight.
Definition: sac_model.h:603
pcl::SampleConsensusModel::samples_radius_
double samples_radius_
The maximum distance of subsequent samples from the first (radius search)
Definition: sac_model.h:542
pcl::SacModel
SacModel
Definition: model_types.h:45
pcl::Functor::~Functor
virtual ~Functor()
Definition: sac_model.h:665
pcl::SampleConsensusModel::setIndices
void setIndices(const IndicesPtr &indices)
Provide a pointer to the vector of indices that represents the input data.
Definition: sac_model.h:318
pcl::SampleConsensusModel::indices_
IndicesPtr indices_
A pointer to the vector of point indices to use.
Definition: sac_model.h:531
pcl::SampleConsensusModel< WeightSACPointType >::ConstPtr
shared_ptr< const SampleConsensusModel< WeightSACPointType > > ConstPtr
Definition: sac_model.h:79
pcl::SampleConsensusModelFromNormals< pcl::PointXYZRGB, PointNT >::PointCloudNPtr
typename pcl::PointCloud< PointNT >::Ptr PointCloudNPtr
Definition: sac_model.h:586
pcl::SampleConsensusModel::setRadiusLimits
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...
Definition: sac_model.h:370
pcl::SampleConsensusModelFromNormals::SampleConsensusModelFromNormals
SampleConsensusModelFromNormals()
Empty constructor for base SampleConsensusModelFromNormals.
Definition: sac_model.h:592
pcl::SampleConsensusModel::setInputCloud
virtual void setInputCloud(const PointCloudConstPtr &cloud)
Provide a pointer to the input dataset.
Definition: sac_model.h:295
pcl::SampleConsensusModelFromNormals< pcl::PointXYZRGB, PointNT >::PointCloudNConstPtr
typename pcl::PointCloud< PointNT >::ConstPtr PointCloudNConstPtr
Definition: sac_model.h:585
pcl::SampleConsensusModel::radius_min_
double radius_min_
The minimum and maximum radius limits for the model.
Definition: sac_model.h:539
pcl::search::Search::Ptr
shared_ptr< pcl::search::Search< PointT > > Ptr
Definition: search.h:81
pcl::Functor< float >::ValueType
Eigen::Matrix< Scalar, ValuesAtCompileTime, 1 > ValueType
Definition: sac_model.h:653
PCL_MAKE_ALIGNED_OPERATOR_NEW
#define PCL_MAKE_ALIGNED_OPERATOR_NEW
Macro to signal a class requires a custom allocator.
Definition: memory.h:63
pcl::SampleConsensusModel::drawIndexSample
void drawIndexSample(Indices &sample)
Fills a sample array with random samples from the indices_ vector.
Definition: sac_model.h:446
pcl::SampleConsensusModel::rnd
int rnd()
Boost-based random number generator.
Definition: sac_model.h:570
pcl::SampleConsensusModel< WeightSACPointType >::Ptr
shared_ptr< SampleConsensusModel< WeightSACPointType > > Ptr
Definition: sac_model.h:78
pcl::SampleConsensusModelFromNormals< pcl::PointXYZRGB, PointNT >::ConstPtr
shared_ptr< const SampleConsensusModelFromNormals< pcl::PointXYZRGB, PointNT > > ConstPtr
Definition: sac_model.h:589
pcl::SampleConsensusModel::computeModelCoefficients
virtual bool computeModelCoefficients(const Indices &samples, Eigen::VectorXf &model_coefficients) const =0
Check whether the given index samples can form a valid model, compute the model coefficients from the...
pcl::SampleConsensusModel::model_name_
std::string model_name_
The model name.
Definition: sac_model.h:525
pcl::SampleConsensusModel::radius_max_
double radius_max_
Definition: sac_model.h:539
pcl::SampleConsensusModel::getSampleSize
unsigned int getSampleSize() const
Return the size of a sample from which the model is computed.
Definition: sac_model.h:351
pcl::SampleConsensusModel< WeightSACPointType >::PointCloudConstPtr
typename PointCloud::ConstPtr PointCloudConstPtr
Definition: sac_model.h:74
pcl::SampleConsensusModel::doSamplesVerifyModel
virtual bool doSamplesVerifyModel(const std::set< index_t > &indices, const Eigen::VectorXf &model_coefficients, const double threshold) const =0
Verify whether a subset of indices verifies a given set of model coefficients.
pcl::SampleConsensusModel::SampleConsensusModel
SampleConsensusModel(bool random=false)
Empty constructor for base SampleConsensusModel.
Definition: sac_model.h:85
pcl::SampleConsensusModel::error_sqr_dists_
std::vector< double > error_sqr_dists_
A vector holding the distances to the computed model.
Definition: sac_model.h:560
pcl::PointCloud::Ptr
shared_ptr< PointCloud< PointT > > Ptr
Definition: point_cloud.h:428
pcl::SampleConsensusModel::shuffled_indices_
Indices shuffled_indices_
Data containing a shuffled version of the indices.
Definition: sac_model.h:548
pcl::PointCloud::ConstPtr
shared_ptr< const PointCloud< PointT > > ConstPtr
Definition: point_cloud.h:429
pcl::SampleConsensusModel::drawIndexSampleRadius
void drawIndexSampleRadius(Indices &sample)
Fills a sample array with one random sample from the indices_ vector and other random samples that ar...
Definition: sac_model.h:463
pcl::Functor::Functor
Functor()
Empty Constructor.
Definition: sac_model.h:658
pcl::SampleConsensusModel::computeVariance
double computeVariance(const std::vector< double > &error_sqr_dists) const
Compute the variance of the errors to the model.
Definition: sac_model.h:416
pcl::SampleConsensusModel< WeightSACPointType >::PointCloudPtr
typename PointCloud::Ptr PointCloudPtr
Definition: sac_model.h:75
pcl::SampleConsensusModel::computeVariance
double computeVariance() const
Compute the variance of the errors to the model from the internally estimated vector of distances.
Definition: sac_model.h:430
pcl::SampleConsensusModel
SampleConsensusModel represents the base model class.
Definition: sac_model.h:70
pcl::Functor< float >::Scalar
float Scalar
Definition: sac_model.h:646
pcl::SampleConsensusModel::SampleConsensusModel
SampleConsensusModel(const PointCloudConstPtr &cloud, bool random=false)
Constructor for base SampleConsensusModel.
Definition: sac_model.h:107
pcl::SampleConsensusModel::input_
PointCloudConstPtr input_
A boost shared pointer to the point cloud data array.
Definition: sac_model.h:528
pcl::Functor::ValuesAtCompileTime
@ ValuesAtCompileTime
Definition: sac_model.h:650
pcl::SampleConsensusModelFromNormals::normal_distance_weight_
double normal_distance_weight_
The relative weight (between 0 and 1) to give to the angular distance (0 to pi/2) between point norma...
Definition: sac_model.h:631
pcl::SampleConsensusModel::rng_alg_
boost::mt19937 rng_alg_
Boost-based random number generator algorithm.
Definition: sac_model.h:551
memory.h
Defines functions, macros and traits for allocating and using memory.
pcl::SampleConsensusModel::getIndices
IndicesPtr getIndices() const
Get a pointer to the vector of indices used.
Definition: sac_model.h:336
pcl::SampleConsensusModelFromNormals< pcl::PointXYZRGB, PointNT >::Ptr
shared_ptr< SampleConsensusModelFromNormals< pcl::PointXYZRGB, PointNT > > Ptr
Definition: sac_model.h:588