Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Store required sample size inside SampleConsensusModel classes #1396

Merged
merged 1 commit into from
Oct 24, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 27 additions & 21 deletions sample_consensus/include/pcl/sample_consensus/model_types.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,31 +68,37 @@ namespace pcl
};
}

// Define the number of samples in SacModel needs
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),
SampleSizeModel (pcl::SACMODEL_CIRCLE2D, 3),
SampleSizeModel (pcl::SACMODEL_CIRCLE3D, 3),
SampleSizeModel (pcl::SACMODEL_SPHERE, 4),
SampleSizeModel (pcl::SACMODEL_CYLINDER, 2),
SampleSizeModel (pcl::SACMODEL_CONE, 3),
//SampleSizeModel (pcl::SACMODEL_TORUS, 2),
SampleSizeModel (pcl::SACMODEL_PARALLEL_LINE, 2),
SampleSizeModel (pcl::SACMODEL_PERPENDICULAR_PLANE, 3),
//SampleSizeModel (pcl::PARALLEL_LINES, 2),
SampleSizeModel (pcl::SACMODEL_NORMAL_PLANE, 3),
SampleSizeModel (pcl::SACMODEL_NORMAL_SPHERE, 4),
SampleSizeModel (pcl::SACMODEL_REGISTRATION, 3),
SampleSizeModel (pcl::SACMODEL_REGISTRATION_2D, 3),
SampleSizeModel (pcl::SACMODEL_PARALLEL_PLANE, 3),
SampleSizeModel (pcl::SACMODEL_NORMAL_PARALLEL_PLANE, 3),
SampleSizeModel (pcl::SACMODEL_STICK, 2)};
const static SampleSizeModel
PCL_DEPRECATED("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")
sample_size_pairs[] = {SampleSizeModel (pcl::SACMODEL_PLANE, 3),
SampleSizeModel (pcl::SACMODEL_LINE, 2),
SampleSizeModel (pcl::SACMODEL_CIRCLE2D, 3),
SampleSizeModel (pcl::SACMODEL_CIRCLE3D, 3),
SampleSizeModel (pcl::SACMODEL_SPHERE, 4),
SampleSizeModel (pcl::SACMODEL_CYLINDER, 2),
SampleSizeModel (pcl::SACMODEL_CONE, 3),
//SampleSizeModel (pcl::SACMODEL_TORUS, 2),
SampleSizeModel (pcl::SACMODEL_PARALLEL_LINE, 2),
SampleSizeModel (pcl::SACMODEL_PERPENDICULAR_PLANE, 3),
//SampleSizeModel (pcl::PARALLEL_LINES, 2),
SampleSizeModel (pcl::SACMODEL_NORMAL_PLANE, 3),
SampleSizeModel (pcl::SACMODEL_NORMAL_SPHERE, 4),
SampleSizeModel (pcl::SACMODEL_REGISTRATION, 3),
SampleSizeModel (pcl::SACMODEL_REGISTRATION_2D, 3),
SampleSizeModel (pcl::SACMODEL_PARALLEL_PLANE, 3),
SampleSizeModel (pcl::SACMODEL_NORMAL_PARALLEL_PLANE, 3),
SampleSizeModel (pcl::SACMODEL_STICK, 2)};

namespace pcl
{
const static std::map<pcl::SacModel, unsigned int> SAC_SAMPLE_SIZE (sample_size_pairs, sample_size_pairs
+ sizeof (sample_size_pairs) / sizeof (SampleSizeModel));
const static std::map<pcl::SacModel, unsigned int>
PCL_DEPRECATED("This map 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")
SAC_SAMPLE_SIZE (sample_size_pairs, sample_size_pairs + sizeof (sample_size_pairs) / sizeof (SampleSizeModel));
}

#endif //#ifndef PCL_SAMPLE_CONSENSUS_MODEL_TYPES_H_
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
Loading