Skip to content

Commit

Permalink
Store required sample size inside SampleConsensusModel classes
Browse files Browse the repository at this point in the history
  • Loading branch information
taketwo committed Oct 22, 2015
1 parent c316542 commit a819bd3
Show file tree
Hide file tree
Showing 18 changed files with 61 additions and 10 deletions.
5 changes: 4 additions & 1 deletion sample_consensus/include/pcl/sample_consensus/model_types.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,9 @@ namespace pcl
};
}

// Define the number of samples in SacModel needs
// Warning: this array is deprecated and is kept only to prevent breaking
// existing user code. Starting from PCL 1.8.0 model sample size is a protected
// member of the SampleConsensusModel class
typedef std::map<pcl::SacModel, unsigned int>::value_type SampleSizeModel;
const static SampleSizeModel sample_size_pairs[] = {SampleSizeModel (pcl::SACMODEL_PLANE, 3),
SampleSizeModel (pcl::SACMODEL_LINE, 2),
Expand All @@ -91,6 +93,7 @@ const static SampleSizeModel sample_size_pairs[] = {SampleSizeModel (pcl::SACMOD

namespace pcl
{
// Warning: this map is deprecated, see the note above
const static std::map<pcl::SacModel, unsigned int> SAC_SAMPLE_SIZE (sample_size_pairs, sample_size_pairs
+ sizeof (sample_size_pairs) / sizeof (SampleSizeModel));
}
Expand Down
16 changes: 8 additions & 8 deletions sample_consensus/include/pcl/sample_consensus/sac_model.h
Original file line number Diff line number Diff line change
Expand Up @@ -355,14 +355,11 @@ namespace pcl
return (model_name_);
}

/** \brief Return the size of a sample from which a model is computed */
inline unsigned int
getSampleSize () const
{
std::map<pcl::SacModel, unsigned int>::const_iterator it = SAC_SAMPLE_SIZE.find (getModelType ());
if (it == SAC_SAMPLE_SIZE.end ())
throw InvalidSACModelTypeException ("No sample size defined for given model type!\n");
return (it->second);
/** \brief Return the size of a sample from which the model is computed. */
inline unsigned int
getSampleSize () const
{
return sample_size_;
}

/** \brief Return the number of coefficients in the model. */
Expand Down Expand Up @@ -571,6 +568,9 @@ namespace pcl
/** \brief A vector holding the distances to the computed model. Used internally. */
std::vector<double> error_sqr_dists_;

/** \brief The size of a sample from which the model is computed. Every subclass should initialize this appropriately. */
unsigned int sample_size_;

/** \brief The number of coefficients in the model. Every subclass should initialize this appropriately. */
unsigned int model_size_;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ namespace pcl
: SampleConsensusModel<PointT> (cloud, random), tmp_inliers_ ()
{
model_name_ = "SampleConsensusModelCircle2D";
sample_size_ = 3;
model_size_ = 3;
}

Expand All @@ -95,6 +96,7 @@ namespace pcl
: SampleConsensusModel<PointT> (cloud, indices, random), tmp_inliers_ ()
{
model_name_ = "SampleConsensusModelCircle2D";
sample_size_ = 3;
model_size_ = 3;
}

Expand Down Expand Up @@ -197,6 +199,7 @@ namespace pcl
getModelType () const { return (SACMODEL_CIRCLE2D); }

protected:
using SampleConsensusModel<PointT>::sample_size_;
using SampleConsensusModel<PointT>::model_size_;

/** \brief Check whether a model is valid given the user constraints.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ namespace pcl
: SampleConsensusModel<PointT> (cloud, random)
{
model_name_ = "SampleConsensusModelCircle3D";
sample_size_ = 3;
model_size_ = 7;
}

Expand All @@ -97,6 +98,7 @@ namespace pcl
: SampleConsensusModel<PointT> (cloud, indices, random)
{
model_name_ = "SampleConsensusModelCircle3D";
sample_size_ = 3;
model_size_ = 7;
}

Expand Down Expand Up @@ -199,6 +201,7 @@ namespace pcl
getModelType () const { return (SACMODEL_CIRCLE3D); }

protected:
using SampleConsensusModel<PointT>::sample_size_;
using SampleConsensusModel<PointT>::model_size_;

/** \brief Check whether a model is valid given the user constraints.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ namespace pcl
, tmp_inliers_ ()
{
model_name_ = "SampleConsensusModelCone";
sample_size_ = 3;
model_size_ = 7;
}

Expand All @@ -115,6 +116,7 @@ namespace pcl
, tmp_inliers_ ()
{
model_name_ = "SampleConsensusModelCone";
sample_size_ = 3;
model_size_ = 7;
}

Expand Down Expand Up @@ -270,6 +272,7 @@ namespace pcl
getModelType () const { return (SACMODEL_CONE); }

protected:
using SampleConsensusModel<PointT>::sample_size_;
using SampleConsensusModel<PointT>::model_size_;

/** \brief Get the distance from a point to a line (represented by a point and a direction)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ namespace pcl
, tmp_inliers_ ()
{
model_name_ = "SampleConsensusModelCylinder";
sample_size_ = 2;
model_size_ = 7;
}

Expand All @@ -111,6 +112,7 @@ namespace pcl
, tmp_inliers_ ()
{
model_name_ = "SampleConsensusModelCylinder";
sample_size_ = 2;
model_size_ = 7;
}

Expand Down Expand Up @@ -242,6 +244,7 @@ namespace pcl
getModelType () const { return (SACMODEL_CYLINDER); }

protected:
using SampleConsensusModel<PointT>::sample_size_;
using SampleConsensusModel<PointT>::model_size_;

/** \brief Get the distance from a point to a line (represented by a point and a direction)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ namespace pcl
: SampleConsensusModel<PointT> (cloud, random)
{
model_name_ = "SampleConsensusModelLine";
sample_size_ = 2;
model_size_ = 6;
}

Expand All @@ -97,6 +98,7 @@ namespace pcl
: SampleConsensusModel<PointT> (cloud, indices, random)
{
model_name_ = "SampleConsensusModelLine";
sample_size_ = 2;
model_size_ = 6;
}

Expand Down Expand Up @@ -179,6 +181,7 @@ namespace pcl
getModelType () const { return (SACMODEL_LINE); }

protected:
using SampleConsensusModel<PointT>::sample_size_;
using SampleConsensusModel<PointT>::model_size_;

/** \brief Check if a sample of indices results in a good sample of points
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ namespace pcl
, eps_dist_ (0.0)
{
model_name_ = "SampleConsensusModelNormalParallelPlane";
sample_size_ = 3;
model_size_ = 4;
}

Expand All @@ -133,6 +134,7 @@ namespace pcl
, eps_dist_ (0.0)
{
model_name_ = "SampleConsensusModelNormalParallelPlane";
sample_size_ = 3;
model_size_ = 4;
}

Expand Down Expand Up @@ -187,6 +189,7 @@ namespace pcl
EIGEN_MAKE_ALIGNED_OPERATOR_NEW

protected:
using SampleConsensusModel<PointT>::sample_size_;
using SampleConsensusModel<PointT>::model_size_;

/** \brief Check whether a model is valid given the user constraints.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ namespace pcl
, SampleConsensusModelFromNormals<PointT, PointNT> ()
{
model_name_ = "SampleConsensusModelNormalPlane";
sample_size_ = 3;
model_size_ = 4;
}

Expand All @@ -118,6 +119,7 @@ namespace pcl
, SampleConsensusModelFromNormals<PointT, PointNT> ()
{
model_name_ = "SampleConsensusModelNormalPlane";
sample_size_ = 3;
model_size_ = 4;
}

Expand Down Expand Up @@ -159,6 +161,7 @@ namespace pcl
EIGEN_MAKE_ALIGNED_OPERATOR_NEW

protected:
using SampleConsensusModel<PointT>::sample_size_;
using SampleConsensusModel<PointT>::model_size_;
};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ namespace pcl
, SampleConsensusModelFromNormals<PointT, PointNT> ()
{
model_name_ = "SampleConsensusModelNormalSphere";
sample_size_ = 4;
model_size_ = 4;
}

Expand All @@ -112,6 +113,7 @@ namespace pcl
, SampleConsensusModelFromNormals<PointT, PointNT> ()
{
model_name_ = "SampleConsensusModelNormalSphere";
sample_size_ = 4;
model_size_ = 4;
}

Expand Down Expand Up @@ -152,6 +154,7 @@ namespace pcl
EIGEN_MAKE_ALIGNED_OPERATOR_NEW

protected:
using SampleConsensusModel<PointT>::sample_size_;
using SampleConsensusModel<PointT>::model_size_;

/** \brief Check whether a model is valid given the user constraints.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ namespace pcl
, eps_angle_ (0.0)
{
model_name_ = "SampleConsensusModelParallelLine";
sample_size_ = 2;
model_size_ = 6;
}

Expand All @@ -101,6 +102,7 @@ namespace pcl
, eps_angle_ (0.0)
{
model_name_ = "SampleConsensusModelParallelLine";
sample_size_ = 2;
model_size_ = 6;
}

Expand Down Expand Up @@ -159,6 +161,7 @@ namespace pcl
getModelType () const { return (SACMODEL_PARALLEL_LINE); }

protected:
using SampleConsensusModel<PointT>::sample_size_;
using SampleConsensusModel<PointT>::model_size_;

/** \brief Check whether a model is valid given the user constraints.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ namespace pcl
, sin_angle_ (-1.0)
{
model_name_ = "SampleConsensusModelParallelPlane";
sample_size_ = 3;
model_size_ = 4;
}

Expand All @@ -103,6 +104,7 @@ namespace pcl
, sin_angle_ (-1.0)
{
model_name_ = "SampleConsensusModelParallelPlane";
sample_size_ = 3;
model_size_ = 4;
}

Expand Down Expand Up @@ -163,6 +165,7 @@ namespace pcl
getModelType () const { return (SACMODEL_PARALLEL_PLANE); }

protected:
using SampleConsensusModel<PointT>::sample_size_;
using SampleConsensusModel<PointT>::model_size_;

/** \brief Check whether a model is valid given the user constraints.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ namespace pcl
, eps_angle_ (0.0)
{
model_name_ = "SampleConsensusModelPerpendicularPlane";
sample_size_ = 3;
model_size_ = 4;
}

Expand All @@ -106,9 +107,10 @@ namespace pcl
, eps_angle_ (0.0)
{
model_name_ = "SampleConsensusModelPerpendicularPlane";
sample_size_ = 3;
model_size_ = 4;
}

/** \brief Empty destructor */
virtual ~SampleConsensusModelPerpendicularPlane () {}

Expand Down Expand Up @@ -166,6 +168,7 @@ namespace pcl
getModelType () const { return (SACMODEL_PERPENDICULAR_PLANE); }

protected:
using SampleConsensusModel<PointT>::sample_size_;
using SampleConsensusModel<PointT>::model_size_;

/** \brief Check whether a model is valid given the user constraints.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@ namespace pcl
: SampleConsensusModel<PointT> (cloud, random)
{
model_name_ = "SampleConsensusModelPlane";
sample_size_ = 3;
model_size_ = 4;
}

Expand All @@ -170,6 +171,7 @@ namespace pcl
: SampleConsensusModel<PointT> (cloud, indices, random)
{
model_name_ = "SampleConsensusModelPlane";
sample_size_ = 3;
model_size_ = 4;
}

Expand Down Expand Up @@ -252,6 +254,7 @@ namespace pcl
getModelType () const { return (SACMODEL_PLANE); }

protected:
using SampleConsensusModel<PointT>::sample_size_;
using SampleConsensusModel<PointT>::model_size_;

private:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ namespace pcl
// Call our own setInputCloud
setInputCloud (cloud);
model_name_ = "SampleConsensusModelRegistration";
sample_size_ = 3;
model_size_ = 16;
}

Expand All @@ -105,6 +106,7 @@ namespace pcl
computeOriginalIndexMapping ();
computeSampleDistanceThreshold (cloud, indices);
model_name_ = "SampleConsensusModelRegistration";
sample_size_ = 3;
model_size_ = 16;
}

Expand Down Expand Up @@ -217,6 +219,7 @@ namespace pcl
getModelType () const { return (SACMODEL_REGISTRATION); }

protected:
using SampleConsensusModel<PointT>::sample_size_;
using SampleConsensusModel<PointT>::model_size_;

/** \brief Check if a sample of indices results in a good sample of points
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ namespace pcl
// Call our own setInputCloud
setInputCloud (cloud);
model_name_ = "SampleConsensusModelRegistration2D";
sample_size_ = 3;
model_size_ = 16;
}

Expand All @@ -98,6 +99,7 @@ namespace pcl
computeOriginalIndexMapping ();
computeSampleDistanceThreshold (cloud, indices);
model_name_ = "SampleConsensusModelRegistration2D";
sample_size_ = 3;
model_size_ = 16;
}

Expand Down Expand Up @@ -145,6 +147,7 @@ namespace pcl
{ return (projection_matrix_); }

protected:
using SampleConsensusModel<PointT>::sample_size_;
using SampleConsensusModel<PointT>::model_size_;

/** \brief Check if a sample of indices results in a good sample of points
Expand Down
Loading

0 comments on commit a819bd3

Please sign in to comment.