Skip to content

Commit eb3fafa

Browse files
committed
Merge pull request #1071 from taketwo/sac-refactoring-1
SAC Models Refactoring: getClassName()
2 parents bd83085 + 958e9b6 commit eb3fafa

17 files changed

+123
-33
lines changed

sample_consensus/include/pcl/sample_consensus/sac_model.h

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -348,6 +348,13 @@ namespace pcl
348348
virtual SacModel
349349
getModelType () const = 0;
350350

351+
/** \brief Get a string representation of the name of this class. */
352+
inline const std::string&
353+
getClassName () const
354+
{
355+
return (model_name_);
356+
}
357+
351358
/** \brief Return the size of a sample from which a model is computed */
352359
inline unsigned int
353360
getSampleSize () const
@@ -434,7 +441,7 @@ namespace pcl
434441
return (computeVariance (error_sqr_dists_));
435442
}
436443

437-
protected:
444+
protected:
438445
/** \brief Fills a sample array with random samples from the indices_ vector
439446
* \param[out] sample the set of indices of target_ to analyze
440447
*/
@@ -505,6 +512,9 @@ namespace pcl
505512
virtual bool
506513
isSampleGood (const std::vector<int> &samples) const = 0;
507514

515+
/** \brief The model name. */
516+
std::string model_name_;
517+
508518
/** \brief A boost shared pointer to the point cloud data array. */
509519
PointCloudConstPtr input_;
510520

@@ -629,7 +639,7 @@ namespace pcl
629639
typedef Eigen::Matrix<Scalar,InputsAtCompileTime,1> InputType;
630640
typedef Eigen::Matrix<Scalar,ValuesAtCompileTime,InputsAtCompileTime> JacobianType;
631641

632-
/** \brief Empty Construtor. */
642+
/** \brief Empty Constructor. */
633643
Functor () : m_data_points_ (ValuesAtCompileTime) {}
634644

635645
/** \brief Constructor

sample_consensus/include/pcl/sample_consensus/sac_model_circle.h

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ namespace pcl
6060
class SampleConsensusModelCircle2D : public SampleConsensusModel<PointT>
6161
{
6262
public:
63+
using SampleConsensusModel<PointT>::model_name_;
6364
using SampleConsensusModel<PointT>::input_;
6465
using SampleConsensusModel<PointT>::indices_;
6566
using SampleConsensusModel<PointT>::radius_min_;
@@ -78,7 +79,9 @@ namespace pcl
7879
*/
7980
SampleConsensusModelCircle2D (const PointCloudConstPtr &cloud, bool random = false)
8081
: SampleConsensusModel<PointT> (cloud, random), tmp_inliers_ ()
81-
{};
82+
{
83+
model_name_ = "SampleConsensusModelCircle2D";
84+
}
8285

8386
/** \brief Constructor for base SampleConsensusModelCircle2D.
8487
* \param[in] cloud the input point cloud dataset
@@ -89,7 +92,9 @@ namespace pcl
8992
const std::vector<int> &indices,
9093
bool random = false)
9194
: SampleConsensusModel<PointT> (cloud, indices, random), tmp_inliers_ ()
92-
{};
95+
{
96+
model_name_ = "SampleConsensusModelCircle2D";
97+
}
9398

9499
/** \brief Copy constructor.
95100
* \param[in] source the model to copy into this
@@ -98,6 +103,7 @@ namespace pcl
98103
SampleConsensusModel<PointT> (), tmp_inliers_ ()
99104
{
100105
*this = source;
106+
model_name_ = "SampleConsensusModelCircle2D";
101107
}
102108

103109
/** \brief Empty destructor */
@@ -152,7 +158,7 @@ namespace pcl
152158
const double threshold);
153159

154160
/** \brief Recompute the 2d circle coefficients using the given inlier set and return them to the user.
155-
* @note: these are the coefficients of the 2d circle model after refinement (eg. after SVD)
161+
* @note: these are the coefficients of the 2d circle model after refinement (e.g. after SVD)
156162
* \param[in] inliers the data inliers found as supporting the model
157163
* \param[in] model_coefficients the initial guess for the optimization
158164
* \param[out] optimized_coefficients the resultant recomputed coefficients after non-linear optimization

sample_consensus/include/pcl/sample_consensus/sac_model_circle3d.h

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ namespace pcl
6161
class SampleConsensusModelCircle3D : public SampleConsensusModel<PointT>
6262
{
6363
public:
64+
using SampleConsensusModel<PointT>::model_name_;
6465
using SampleConsensusModel<PointT>::input_;
6566
using SampleConsensusModel<PointT>::indices_;
6667
using SampleConsensusModel<PointT>::radius_min_;
@@ -79,7 +80,10 @@ namespace pcl
7980
*/
8081
SampleConsensusModelCircle3D (const PointCloudConstPtr &cloud,
8182
bool random = false)
82-
: SampleConsensusModel<PointT> (cloud, random) {};
83+
: SampleConsensusModel<PointT> (cloud, random)
84+
{
85+
model_name_ = "SampleConsensusModelCircle3D";
86+
}
8387

8488
/** \brief Constructor for base SampleConsensusModelCircle3D.
8589
* \param[in] cloud the input point cloud dataset
@@ -89,7 +93,10 @@ namespace pcl
8993
SampleConsensusModelCircle3D (const PointCloudConstPtr &cloud,
9094
const std::vector<int> &indices,
9195
bool random = false)
92-
: SampleConsensusModel<PointT> (cloud, indices, random) {};
96+
: SampleConsensusModel<PointT> (cloud, indices, random)
97+
{
98+
model_name_ = "SampleConsensusModelCircle3D";
99+
}
93100

94101
/** \brief Empty destructor */
95102
virtual ~SampleConsensusModelCircle3D () {}
@@ -101,6 +108,7 @@ namespace pcl
101108
SampleConsensusModel<PointT> (), tmp_inliers_ ()
102109
{
103110
*this = source;
111+
model_name_ = "SampleConsensusModelCircle3D";
104112
}
105113

106114
/** \brief Copy constructor.
@@ -152,7 +160,7 @@ namespace pcl
152160
const double threshold);
153161

154162
/** \brief Recompute the 3d circle coefficients using the given inlier set and return them to the user.
155-
* @note: these are the coefficients of the 3d circle model after refinement (eg. after SVD)
163+
* @note: these are the coefficients of the 3d circle model after refinement (e.g. after SVD)
156164
* \param[in] inliers the data inliers found as supporting the model
157165
* \param[in] model_coefficients the initial guess for the optimization
158166
* \param[out] optimized_coefficients the resultant recomputed coefficients after non-linear optimization

sample_consensus/include/pcl/sample_consensus/sac_model_cone.h

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141

4242
#include <pcl/sample_consensus/sac_model.h>
4343
#include <pcl/sample_consensus/model_types.h>
44+
#include <pcl/pcl_macros.h>
4445
#include <pcl/common/common.h>
4546
#include <pcl/common/distances.h>
4647
#include <limits.h>
@@ -65,6 +66,7 @@ namespace pcl
6566
class SampleConsensusModelCone : public SampleConsensusModel<PointT>, public SampleConsensusModelFromNormals<PointT, PointNT>
6667
{
6768
public:
69+
using SampleConsensusModel<PointT>::model_name_;
6870
using SampleConsensusModel<PointT>::input_;
6971
using SampleConsensusModel<PointT>::indices_;
7072
using SampleConsensusModel<PointT>::radius_min_;
@@ -92,6 +94,7 @@ namespace pcl
9294
, max_angle_ (std::numeric_limits<double>::max ())
9395
, tmp_inliers_ ()
9496
{
97+
model_name_ = "SampleConsensusModelCone";
9598
}
9699

97100
/** \brief Constructor for base SampleConsensusModelCone.
@@ -110,6 +113,7 @@ namespace pcl
110113
, max_angle_ (std::numeric_limits<double>::max ())
111114
, tmp_inliers_ ()
112115
{
116+
model_name_ = "SampleConsensusModelCone";
113117
}
114118

115119
/** \brief Copy constructor.
@@ -121,6 +125,7 @@ namespace pcl
121125
axis_ (), eps_angle_ (), min_angle_ (), max_angle_ (), tmp_inliers_ ()
122126
{
123127
*this = source;
128+
model_name_ = "SampleConsensusModelCone";
124129
}
125130

126131
/** \brief Empty destructor */
@@ -163,8 +168,8 @@ namespace pcl
163168

164169
/** \brief Set the minimum and maximum allowable opening angle for a cone model
165170
* given from a user.
166-
* \param[in] min_angle the minimum allwoable opening angle of a cone model
167-
* \param[in] max_angle the maximum allwoable opening angle of a cone model
171+
* \param[in] min_angle the minimum allowable opening angle of a cone model
172+
* \param[in] max_angle the maximum allowable opening angle of a cone model
168173
*/
169174
inline void
170175
setMinMaxOpeningAngle (const double &min_angle, const double &max_angle)
@@ -173,9 +178,9 @@ namespace pcl
173178
max_angle_ = max_angle;
174179
}
175180

176-
/** \brief Get the opening angle which we need minumum to validate a cone model.
177-
* \param[out] min_angle the minimum allwoable opening angle of a cone model
178-
* \param[out] max_angle the maximum allwoable opening angle of a cone model
181+
/** \brief Get the opening angle which we need minimum to validate a cone model.
182+
* \param[out] min_angle the minimum allowable opening angle of a cone model
183+
* \param[out] max_angle the maximum allowable opening angle of a cone model
179184
*/
180185
inline void
181186
getMinMaxOpeningAngle (double &min_angle, double &max_angle) const
@@ -224,7 +229,7 @@ namespace pcl
224229

225230

226231
/** \brief Recompute the cone coefficients using the given inlier set and return them to the user.
227-
* @note: these are the coefficients of the cone model after refinement (eg. after SVD)
232+
* @note: these are the coefficients of the cone model after refinement (e.g. after SVD)
228233
* \param[in] inliers the data inliers found as supporting the model
229234
* \param[in] model_coefficients the initial guess for the optimization
230235
* \param[out] optimized_coefficients the resultant recomputed coefficients after non-linear optimization
@@ -270,8 +275,9 @@ namespace pcl
270275
pointToAxisDistance (const Eigen::Vector4f &pt, const Eigen::VectorXf &model_coefficients);
271276

272277
/** \brief Get a string representation of the name of this class. */
273-
std::string
274-
getName () const { return ("SampleConsensusModelCone"); }
278+
PCL_DEPRECATED ("[pcl::SampleConsensusModelCone::getName] getName is deprecated. Please use getClassName instead.")
279+
std::string
280+
getName () const { return (model_name_); }
275281

276282
protected:
277283
/** \brief Check whether a model is valid given the user constraints.

sample_consensus/include/pcl/sample_consensus/sac_model_cylinder.h

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343

4444
#include <pcl/sample_consensus/sac_model.h>
4545
#include <pcl/sample_consensus/model_types.h>
46+
#include <pcl/pcl_macros.h>
4647
#include <pcl/common/common.h>
4748
#include <pcl/common/distances.h>
4849

@@ -65,6 +66,7 @@ namespace pcl
6566
class SampleConsensusModelCylinder : public SampleConsensusModel<PointT>, public SampleConsensusModelFromNormals<PointT, PointNT>
6667
{
6768
public:
69+
using SampleConsensusModel<PointT>::model_name_;
6870
using SampleConsensusModel<PointT>::input_;
6971
using SampleConsensusModel<PointT>::indices_;
7072
using SampleConsensusModel<PointT>::radius_min_;
@@ -90,6 +92,7 @@ namespace pcl
9092
, eps_angle_ (0)
9193
, tmp_inliers_ ()
9294
{
95+
model_name_ = "SampleConsensusModelCylinder";
9396
}
9497

9598
/** \brief Constructor for base SampleConsensusModelCylinder.
@@ -106,6 +109,7 @@ namespace pcl
106109
, eps_angle_ (0)
107110
, tmp_inliers_ ()
108111
{
112+
model_name_ = "SampleConsensusModelCylinder";
109113
}
110114

111115
/** \brief Copy constructor.
@@ -119,6 +123,7 @@ namespace pcl
119123
tmp_inliers_ ()
120124
{
121125
*this = source;
126+
model_name_ = "SampleConsensusModelCylinder";
122127
}
123128

124129
/** \brief Empty destructor */
@@ -138,7 +143,7 @@ namespace pcl
138143
}
139144

140145
/** \brief Set the angle epsilon (delta) threshold.
141-
* \param[in] ea the maximum allowed difference between the cyilinder axis and the given axis.
146+
* \param[in] ea the maximum allowed difference between the cylinder axis and the given axis.
142147
*/
143148
inline void
144149
setEpsAngle (const double ea) { eps_angle_ = ea; }
@@ -196,7 +201,7 @@ namespace pcl
196201
const double threshold);
197202

198203
/** \brief Recompute the cylinder coefficients using the given inlier set and return them to the user.
199-
* @note: these are the coefficients of the cylinder model after refinement (eg. after SVD)
204+
* @note: these are the coefficients of the cylinder model after refinement (e.g. after SVD)
200205
* \param[in] inliers the data inliers found as supporting the model
201206
* \param[in] model_coefficients the initial guess for the optimization
202207
* \param[out] optimized_coefficients the resultant recomputed coefficients after non-linear optimization
@@ -270,8 +275,9 @@ namespace pcl
270275
Eigen::Vector4f &pt_proj);
271276

272277
/** \brief Get a string representation of the name of this class. */
273-
std::string
274-
getName () const { return ("SampleConsensusModelCylinder"); }
278+
PCL_DEPRECATED ("[pcl::SampleConsensusModelCylinder::getName] getName is deprecated. Please use getClassName instead.")
279+
std::string
280+
getName () const { return (model_name_); }
275281

276282
protected:
277283
/** \brief Check whether a model is valid given the user constraints.

sample_consensus/include/pcl/sample_consensus/sac_model_line.h

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ namespace pcl
6363
class SampleConsensusModelLine : public SampleConsensusModel<PointT>
6464
{
6565
public:
66+
using SampleConsensusModel<PointT>::model_name_;
6667
using SampleConsensusModel<PointT>::input_;
6768
using SampleConsensusModel<PointT>::indices_;
6869
using SampleConsensusModel<PointT>::error_sqr_dists_;
@@ -78,7 +79,10 @@ namespace pcl
7879
* \param[in] random if true set the random seed to the current time, else set to 12345 (default: false)
7980
*/
8081
SampleConsensusModelLine (const PointCloudConstPtr &cloud, bool random = false)
81-
: SampleConsensusModel<PointT> (cloud, random) {};
82+
: SampleConsensusModel<PointT> (cloud, random)
83+
{
84+
model_name_ = "SampleConsensusModelLine";
85+
}
8286

8387
/** \brief Constructor for base SampleConsensusModelLine.
8488
* \param[in] cloud the input point cloud dataset
@@ -88,7 +92,10 @@ namespace pcl
8892
SampleConsensusModelLine (const PointCloudConstPtr &cloud,
8993
const std::vector<int> &indices,
9094
bool random = false)
91-
: SampleConsensusModel<PointT> (cloud, indices, random) {};
95+
: SampleConsensusModel<PointT> (cloud, indices, random)
96+
{
97+
model_name_ = "SampleConsensusModelLine";
98+
}
9299

93100
/** \brief Empty destructor */
94101
virtual ~SampleConsensusModelLine () {}
@@ -132,7 +139,7 @@ namespace pcl
132139
const double threshold);
133140

134141
/** \brief Recompute the line coefficients using the given inlier set and return them to the user.
135-
* @note: these are the coefficients of the line model after refinement (eg. after SVD)
142+
* @note: these are the coefficients of the line model after refinement (e.g. after SVD)
136143
* \param[in] inliers the data inliers found as supporting the model
137144
* \param[in] model_coefficients the initial guess for the model coefficients
138145
* \param[out] optimized_coefficients the resultant recomputed coefficients after optimization

sample_consensus/include/pcl/sample_consensus/sac_model_normal_parallel_plane.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ namespace pcl
8484
class SampleConsensusModelNormalParallelPlane : public SampleConsensusModelNormalPlane<PointT, PointNT>
8585
{
8686
public:
87+
using SampleConsensusModel<PointT>::model_name_;
8788
using SampleConsensusModel<PointT>::input_;
8889
using SampleConsensusModel<PointT>::indices_;
8990
using SampleConsensusModelFromNormals<PointT, PointNT>::normals_;
@@ -112,6 +113,7 @@ namespace pcl
112113
, cos_angle_ (-1.0)
113114
, eps_dist_ (0.0)
114115
{
116+
model_name_ = "SampleConsensusModelNormalParallelPlane";
115117
}
116118

117119
/** \brief Constructor for base SampleConsensusModelNormalParallelPlane.
@@ -129,6 +131,7 @@ namespace pcl
129131
, cos_angle_ (-1.0)
130132
, eps_dist_ (0.0)
131133
{
134+
model_name_ = "SampleConsensusModelNormalParallelPlane";
132135
}
133136

134137
/** \brief Empty destructor */

sample_consensus/include/pcl/sample_consensus/sac_model_normal_plane.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ namespace pcl
7676
class SampleConsensusModelNormalPlane : public SampleConsensusModelPlane<PointT>, public SampleConsensusModelFromNormals<PointT, PointNT>
7777
{
7878
public:
79+
using SampleConsensusModel<PointT>::model_name_;
7980
using SampleConsensusModel<PointT>::input_;
8081
using SampleConsensusModel<PointT>::indices_;
8182
using SampleConsensusModelFromNormals<PointT, PointNT>::normals_;
@@ -101,6 +102,7 @@ namespace pcl
101102
: SampleConsensusModelPlane<PointT> (cloud, random)
102103
, SampleConsensusModelFromNormals<PointT, PointNT> ()
103104
{
105+
model_name_ = "SampleConsensusModelNormalPlane";
104106
}
105107

106108
/** \brief Constructor for base SampleConsensusModelNormalPlane.
@@ -114,6 +116,7 @@ namespace pcl
114116
: SampleConsensusModelPlane<PointT> (cloud, indices, random)
115117
, SampleConsensusModelFromNormals<PointT, PointNT> ()
116118
{
119+
model_name_ = "SampleConsensusModelNormalPlane";
117120
}
118121

119122
/** \brief Empty destructor */

0 commit comments

Comments
 (0)