From f15ea66cfb2c2e0c222092e9a07c384eba25ae49 Mon Sep 17 00:00:00 2001 From: Sergey Alexandrov Date: Sat, 24 Oct 2015 16:50:41 +0200 Subject: [PATCH] Store required sample size inside SampleConsensusModel classes --- .../pcl/sample_consensus/model_types.h | 48 +++++++++++-------- .../include/pcl/sample_consensus/sac_model.h | 16 +++---- .../pcl/sample_consensus/sac_model_circle.h | 3 ++ .../pcl/sample_consensus/sac_model_circle3d.h | 3 ++ .../pcl/sample_consensus/sac_model_cone.h | 3 ++ .../pcl/sample_consensus/sac_model_cylinder.h | 3 ++ .../pcl/sample_consensus/sac_model_line.h | 3 ++ .../sac_model_normal_parallel_plane.h | 3 ++ .../sample_consensus/sac_model_normal_plane.h | 3 ++ .../sac_model_normal_sphere.h | 3 ++ .../sac_model_parallel_line.h | 3 ++ .../sac_model_parallel_plane.h | 3 ++ .../sac_model_perpendicular_plane.h | 5 +- .../pcl/sample_consensus/sac_model_plane.h | 3 ++ .../sample_consensus/sac_model_registration.h | 3 ++ .../sac_model_registration_2d.h | 3 ++ .../pcl/sample_consensus/sac_model_sphere.h | 3 ++ .../pcl/sample_consensus/sac_model_stick.h | 3 ++ 18 files changed, 84 insertions(+), 30 deletions(-) diff --git a/sample_consensus/include/pcl/sample_consensus/model_types.h b/sample_consensus/include/pcl/sample_consensus/model_types.h index cd5855e7614..0585a1aa7d8 100644 --- a/sample_consensus/include/pcl/sample_consensus/model_types.h +++ b/sample_consensus/include/pcl/sample_consensus/model_types.h @@ -68,31 +68,37 @@ namespace pcl }; } -// Define the number of samples in SacModel needs typedef std::map::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 SAC_SAMPLE_SIZE (sample_size_pairs, sample_size_pairs - + sizeof (sample_size_pairs) / sizeof (SampleSizeModel)); + const static std::map + 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_ diff --git a/sample_consensus/include/pcl/sample_consensus/sac_model.h b/sample_consensus/include/pcl/sample_consensus/sac_model.h index ba6bac096c8..f1b80556baf 100644 --- a/sample_consensus/include/pcl/sample_consensus/sac_model.h +++ b/sample_consensus/include/pcl/sample_consensus/sac_model.h @@ -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::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. */ @@ -571,6 +568,9 @@ namespace pcl /** \brief A vector holding the distances to the computed model. Used internally. */ std::vector 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_; diff --git a/sample_consensus/include/pcl/sample_consensus/sac_model_circle.h b/sample_consensus/include/pcl/sample_consensus/sac_model_circle.h index 7927f1fbf35..5aefd7045f3 100644 --- a/sample_consensus/include/pcl/sample_consensus/sac_model_circle.h +++ b/sample_consensus/include/pcl/sample_consensus/sac_model_circle.h @@ -81,6 +81,7 @@ namespace pcl : SampleConsensusModel (cloud, random), tmp_inliers_ () { model_name_ = "SampleConsensusModelCircle2D"; + sample_size_ = 3; model_size_ = 3; } @@ -95,6 +96,7 @@ namespace pcl : SampleConsensusModel (cloud, indices, random), tmp_inliers_ () { model_name_ = "SampleConsensusModelCircle2D"; + sample_size_ = 3; model_size_ = 3; } @@ -197,6 +199,7 @@ namespace pcl getModelType () const { return (SACMODEL_CIRCLE2D); } protected: + using SampleConsensusModel::sample_size_; using SampleConsensusModel::model_size_; /** \brief Check whether a model is valid given the user constraints. diff --git a/sample_consensus/include/pcl/sample_consensus/sac_model_circle3d.h b/sample_consensus/include/pcl/sample_consensus/sac_model_circle3d.h index df621462341..54dddd5f18c 100644 --- a/sample_consensus/include/pcl/sample_consensus/sac_model_circle3d.h +++ b/sample_consensus/include/pcl/sample_consensus/sac_model_circle3d.h @@ -83,6 +83,7 @@ namespace pcl : SampleConsensusModel (cloud, random) { model_name_ = "SampleConsensusModelCircle3D"; + sample_size_ = 3; model_size_ = 7; } @@ -97,6 +98,7 @@ namespace pcl : SampleConsensusModel (cloud, indices, random) { model_name_ = "SampleConsensusModelCircle3D"; + sample_size_ = 3; model_size_ = 7; } @@ -199,6 +201,7 @@ namespace pcl getModelType () const { return (SACMODEL_CIRCLE3D); } protected: + using SampleConsensusModel::sample_size_; using SampleConsensusModel::model_size_; /** \brief Check whether a model is valid given the user constraints. diff --git a/sample_consensus/include/pcl/sample_consensus/sac_model_cone.h b/sample_consensus/include/pcl/sample_consensus/sac_model_cone.h index 97c458b7301..e4593033704 100644 --- a/sample_consensus/include/pcl/sample_consensus/sac_model_cone.h +++ b/sample_consensus/include/pcl/sample_consensus/sac_model_cone.h @@ -95,6 +95,7 @@ namespace pcl , tmp_inliers_ () { model_name_ = "SampleConsensusModelCone"; + sample_size_ = 3; model_size_ = 7; } @@ -115,6 +116,7 @@ namespace pcl , tmp_inliers_ () { model_name_ = "SampleConsensusModelCone"; + sample_size_ = 3; model_size_ = 7; } @@ -270,6 +272,7 @@ namespace pcl getModelType () const { return (SACMODEL_CONE); } protected: + using SampleConsensusModel::sample_size_; using SampleConsensusModel::model_size_; /** \brief Get the distance from a point to a line (represented by a point and a direction) diff --git a/sample_consensus/include/pcl/sample_consensus/sac_model_cylinder.h b/sample_consensus/include/pcl/sample_consensus/sac_model_cylinder.h index f95eb77c0e8..2c6b080eb3a 100644 --- a/sample_consensus/include/pcl/sample_consensus/sac_model_cylinder.h +++ b/sample_consensus/include/pcl/sample_consensus/sac_model_cylinder.h @@ -93,6 +93,7 @@ namespace pcl , tmp_inliers_ () { model_name_ = "SampleConsensusModelCylinder"; + sample_size_ = 2; model_size_ = 7; } @@ -111,6 +112,7 @@ namespace pcl , tmp_inliers_ () { model_name_ = "SampleConsensusModelCylinder"; + sample_size_ = 2; model_size_ = 7; } @@ -242,6 +244,7 @@ namespace pcl getModelType () const { return (SACMODEL_CYLINDER); } protected: + using SampleConsensusModel::sample_size_; using SampleConsensusModel::model_size_; /** \brief Get the distance from a point to a line (represented by a point and a direction) diff --git a/sample_consensus/include/pcl/sample_consensus/sac_model_line.h b/sample_consensus/include/pcl/sample_consensus/sac_model_line.h index 4f7274cc1e6..07eef59067b 100644 --- a/sample_consensus/include/pcl/sample_consensus/sac_model_line.h +++ b/sample_consensus/include/pcl/sample_consensus/sac_model_line.h @@ -83,6 +83,7 @@ namespace pcl : SampleConsensusModel (cloud, random) { model_name_ = "SampleConsensusModelLine"; + sample_size_ = 2; model_size_ = 6; } @@ -97,6 +98,7 @@ namespace pcl : SampleConsensusModel (cloud, indices, random) { model_name_ = "SampleConsensusModelLine"; + sample_size_ = 2; model_size_ = 6; } @@ -179,6 +181,7 @@ namespace pcl getModelType () const { return (SACMODEL_LINE); } protected: + using SampleConsensusModel::sample_size_; using SampleConsensusModel::model_size_; /** \brief Check if a sample of indices results in a good sample of points diff --git a/sample_consensus/include/pcl/sample_consensus/sac_model_normal_parallel_plane.h b/sample_consensus/include/pcl/sample_consensus/sac_model_normal_parallel_plane.h index 2a9f2662c46..2b29b667655 100644 --- a/sample_consensus/include/pcl/sample_consensus/sac_model_normal_parallel_plane.h +++ b/sample_consensus/include/pcl/sample_consensus/sac_model_normal_parallel_plane.h @@ -114,6 +114,7 @@ namespace pcl , eps_dist_ (0.0) { model_name_ = "SampleConsensusModelNormalParallelPlane"; + sample_size_ = 3; model_size_ = 4; } @@ -133,6 +134,7 @@ namespace pcl , eps_dist_ (0.0) { model_name_ = "SampleConsensusModelNormalParallelPlane"; + sample_size_ = 3; model_size_ = 4; } @@ -187,6 +189,7 @@ namespace pcl EIGEN_MAKE_ALIGNED_OPERATOR_NEW protected: + using SampleConsensusModel::sample_size_; using SampleConsensusModel::model_size_; /** \brief Check whether a model is valid given the user constraints. diff --git a/sample_consensus/include/pcl/sample_consensus/sac_model_normal_plane.h b/sample_consensus/include/pcl/sample_consensus/sac_model_normal_plane.h index f561ecd0d64..1e762ba3ba8 100644 --- a/sample_consensus/include/pcl/sample_consensus/sac_model_normal_plane.h +++ b/sample_consensus/include/pcl/sample_consensus/sac_model_normal_plane.h @@ -103,6 +103,7 @@ namespace pcl , SampleConsensusModelFromNormals () { model_name_ = "SampleConsensusModelNormalPlane"; + sample_size_ = 3; model_size_ = 4; } @@ -118,6 +119,7 @@ namespace pcl , SampleConsensusModelFromNormals () { model_name_ = "SampleConsensusModelNormalPlane"; + sample_size_ = 3; model_size_ = 4; } @@ -159,6 +161,7 @@ namespace pcl EIGEN_MAKE_ALIGNED_OPERATOR_NEW protected: + using SampleConsensusModel::sample_size_; using SampleConsensusModel::model_size_; }; } diff --git a/sample_consensus/include/pcl/sample_consensus/sac_model_normal_sphere.h b/sample_consensus/include/pcl/sample_consensus/sac_model_normal_sphere.h index e228109a251..9a40dbf69a1 100644 --- a/sample_consensus/include/pcl/sample_consensus/sac_model_normal_sphere.h +++ b/sample_consensus/include/pcl/sample_consensus/sac_model_normal_sphere.h @@ -97,6 +97,7 @@ namespace pcl , SampleConsensusModelFromNormals () { model_name_ = "SampleConsensusModelNormalSphere"; + sample_size_ = 4; model_size_ = 4; } @@ -112,6 +113,7 @@ namespace pcl , SampleConsensusModelFromNormals () { model_name_ = "SampleConsensusModelNormalSphere"; + sample_size_ = 4; model_size_ = 4; } @@ -152,6 +154,7 @@ namespace pcl EIGEN_MAKE_ALIGNED_OPERATOR_NEW protected: + using SampleConsensusModel::sample_size_; using SampleConsensusModel::model_size_; /** \brief Check whether a model is valid given the user constraints. diff --git a/sample_consensus/include/pcl/sample_consensus/sac_model_parallel_line.h b/sample_consensus/include/pcl/sample_consensus/sac_model_parallel_line.h index 877069ddee0..72fda46b810 100644 --- a/sample_consensus/include/pcl/sample_consensus/sac_model_parallel_line.h +++ b/sample_consensus/include/pcl/sample_consensus/sac_model_parallel_line.h @@ -85,6 +85,7 @@ namespace pcl , eps_angle_ (0.0) { model_name_ = "SampleConsensusModelParallelLine"; + sample_size_ = 2; model_size_ = 6; } @@ -101,6 +102,7 @@ namespace pcl , eps_angle_ (0.0) { model_name_ = "SampleConsensusModelParallelLine"; + sample_size_ = 2; model_size_ = 6; } @@ -159,6 +161,7 @@ namespace pcl getModelType () const { return (SACMODEL_PARALLEL_LINE); } protected: + using SampleConsensusModel::sample_size_; using SampleConsensusModel::model_size_; /** \brief Check whether a model is valid given the user constraints. diff --git a/sample_consensus/include/pcl/sample_consensus/sac_model_parallel_plane.h b/sample_consensus/include/pcl/sample_consensus/sac_model_parallel_plane.h index 28880f74225..7e681b1b9bf 100644 --- a/sample_consensus/include/pcl/sample_consensus/sac_model_parallel_plane.h +++ b/sample_consensus/include/pcl/sample_consensus/sac_model_parallel_plane.h @@ -86,6 +86,7 @@ namespace pcl , sin_angle_ (-1.0) { model_name_ = "SampleConsensusModelParallelPlane"; + sample_size_ = 3; model_size_ = 4; } @@ -103,6 +104,7 @@ namespace pcl , sin_angle_ (-1.0) { model_name_ = "SampleConsensusModelParallelPlane"; + sample_size_ = 3; model_size_ = 4; } @@ -163,6 +165,7 @@ namespace pcl getModelType () const { return (SACMODEL_PARALLEL_PLANE); } protected: + using SampleConsensusModel::sample_size_; using SampleConsensusModel::model_size_; /** \brief Check whether a model is valid given the user constraints. diff --git a/sample_consensus/include/pcl/sample_consensus/sac_model_perpendicular_plane.h b/sample_consensus/include/pcl/sample_consensus/sac_model_perpendicular_plane.h index f0a9025fec9..43e7d0e1c94 100644 --- a/sample_consensus/include/pcl/sample_consensus/sac_model_perpendicular_plane.h +++ b/sample_consensus/include/pcl/sample_consensus/sac_model_perpendicular_plane.h @@ -90,6 +90,7 @@ namespace pcl , eps_angle_ (0.0) { model_name_ = "SampleConsensusModelPerpendicularPlane"; + sample_size_ = 3; model_size_ = 4; } @@ -106,9 +107,10 @@ namespace pcl , eps_angle_ (0.0) { model_name_ = "SampleConsensusModelPerpendicularPlane"; + sample_size_ = 3; model_size_ = 4; } - + /** \brief Empty destructor */ virtual ~SampleConsensusModelPerpendicularPlane () {} @@ -166,6 +168,7 @@ namespace pcl getModelType () const { return (SACMODEL_PERPENDICULAR_PLANE); } protected: + using SampleConsensusModel::sample_size_; using SampleConsensusModel::model_size_; /** \brief Check whether a model is valid given the user constraints. diff --git a/sample_consensus/include/pcl/sample_consensus/sac_model_plane.h b/sample_consensus/include/pcl/sample_consensus/sac_model_plane.h index c09edd48880..4ec78d91b47 100644 --- a/sample_consensus/include/pcl/sample_consensus/sac_model_plane.h +++ b/sample_consensus/include/pcl/sample_consensus/sac_model_plane.h @@ -156,6 +156,7 @@ namespace pcl : SampleConsensusModel (cloud, random) { model_name_ = "SampleConsensusModelPlane"; + sample_size_ = 3; model_size_ = 4; } @@ -170,6 +171,7 @@ namespace pcl : SampleConsensusModel (cloud, indices, random) { model_name_ = "SampleConsensusModelPlane"; + sample_size_ = 3; model_size_ = 4; } @@ -252,6 +254,7 @@ namespace pcl getModelType () const { return (SACMODEL_PLANE); } protected: + using SampleConsensusModel::sample_size_; using SampleConsensusModel::model_size_; private: diff --git a/sample_consensus/include/pcl/sample_consensus/sac_model_registration.h b/sample_consensus/include/pcl/sample_consensus/sac_model_registration.h index 93862dcef66..6da4d57725f 100644 --- a/sample_consensus/include/pcl/sample_consensus/sac_model_registration.h +++ b/sample_consensus/include/pcl/sample_consensus/sac_model_registration.h @@ -85,6 +85,7 @@ namespace pcl // Call our own setInputCloud setInputCloud (cloud); model_name_ = "SampleConsensusModelRegistration"; + sample_size_ = 3; model_size_ = 16; } @@ -105,6 +106,7 @@ namespace pcl computeOriginalIndexMapping (); computeSampleDistanceThreshold (cloud, indices); model_name_ = "SampleConsensusModelRegistration"; + sample_size_ = 3; model_size_ = 16; } @@ -217,6 +219,7 @@ namespace pcl getModelType () const { return (SACMODEL_REGISTRATION); } protected: + using SampleConsensusModel::sample_size_; using SampleConsensusModel::model_size_; /** \brief Check if a sample of indices results in a good sample of points diff --git a/sample_consensus/include/pcl/sample_consensus/sac_model_registration_2d.h b/sample_consensus/include/pcl/sample_consensus/sac_model_registration_2d.h index a058e61cd80..c64a5483520 100644 --- a/sample_consensus/include/pcl/sample_consensus/sac_model_registration_2d.h +++ b/sample_consensus/include/pcl/sample_consensus/sac_model_registration_2d.h @@ -81,6 +81,7 @@ namespace pcl // Call our own setInputCloud setInputCloud (cloud); model_name_ = "SampleConsensusModelRegistration2D"; + sample_size_ = 3; model_size_ = 16; } @@ -98,6 +99,7 @@ namespace pcl computeOriginalIndexMapping (); computeSampleDistanceThreshold (cloud, indices); model_name_ = "SampleConsensusModelRegistration2D"; + sample_size_ = 3; model_size_ = 16; } @@ -145,6 +147,7 @@ namespace pcl { return (projection_matrix_); } protected: + using SampleConsensusModel::sample_size_; using SampleConsensusModel::model_size_; /** \brief Check if a sample of indices results in a good sample of points diff --git a/sample_consensus/include/pcl/sample_consensus/sac_model_sphere.h b/sample_consensus/include/pcl/sample_consensus/sac_model_sphere.h index 3f72618a851..9b6eb734613 100644 --- a/sample_consensus/include/pcl/sample_consensus/sac_model_sphere.h +++ b/sample_consensus/include/pcl/sample_consensus/sac_model_sphere.h @@ -82,6 +82,7 @@ namespace pcl : SampleConsensusModel (cloud, random), tmp_inliers_ () { model_name_ = "SampleConsensusModelSphere"; + sample_size_ = 4; model_size_ = 4; } @@ -96,6 +97,7 @@ namespace pcl : SampleConsensusModel (cloud, indices, random), tmp_inliers_ () { model_name_ = "SampleConsensusModelSphere"; + sample_size_ = 4; model_size_ = 4; } @@ -199,6 +201,7 @@ namespace pcl inline pcl::SacModel getModelType () const { return (SACMODEL_SPHERE); } protected: + using SampleConsensusModel::sample_size_; using SampleConsensusModel::model_size_; /** \brief Check whether a model is valid given the user constraints. diff --git a/sample_consensus/include/pcl/sample_consensus/sac_model_stick.h b/sample_consensus/include/pcl/sample_consensus/sac_model_stick.h index 05c159e4e6e..5c307ff6b32 100644 --- a/sample_consensus/include/pcl/sample_consensus/sac_model_stick.h +++ b/sample_consensus/include/pcl/sample_consensus/sac_model_stick.h @@ -87,6 +87,7 @@ namespace pcl : SampleConsensusModel (cloud, random) { model_name_ = "SampleConsensusModelStick"; + sample_size_ = 2; model_size_ = 7; } @@ -101,6 +102,7 @@ namespace pcl : SampleConsensusModel (cloud, indices, random) { model_name_ = "SampleConsensusModelStick"; + sample_size_ = 2; model_size_ = 7; } @@ -183,6 +185,7 @@ namespace pcl getModelType () const { return (SACMODEL_STICK); } protected: + using SampleConsensusModel::sample_size_; using SampleConsensusModel::model_size_; /** \brief Check if a sample of indices results in a good sample of points