Skip to content

Commit a09c4c8

Browse files
authored
Fix SampleConsensusModel constructor to not use a virtual function (#6305)
* Fix SampleConsensusModel constructor to not use a virtual function * add numeric for iota * fix default constructors --------- Co-authored-by: jmackay2 <jmackay2>
1 parent 20a06e0 commit a09c4c8

File tree

1 file changed

+18
-30
lines changed
  • sample_consensus/include/pcl/sample_consensus

1 file changed

+18
-30
lines changed

sample_consensus/include/pcl/sample_consensus/sac_model.h

Lines changed: 18 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848
#include <boost/random/uniform_int.hpp> // for uniform_int
4949
#include <boost/random/variate_generator.hpp> // for variate_generator
5050
#include <random>
51+
#include <numeric> // for iota
5152

5253
#include <pcl/memory.h>
5354
#include <pcl/console/print.h>
@@ -101,41 +102,14 @@ namespace pcl
101102
}
102103

103104
public:
104-
/** \brief Constructor for base SampleConsensusModel.
105-
* \param[in] cloud the input point cloud dataset
106-
* \param[in] random if true set the random seed to the current time, else set to 12345 (default: false)
107-
*/
108-
SampleConsensusModel (const PointCloudConstPtr &cloud, bool random = false)
109-
: input_ ()
110-
, radius_min_ (-std::numeric_limits<double>::max ())
111-
, radius_max_ (std::numeric_limits<double>::max ())
112-
, samples_radius_ (0.)
113-
, samples_radius_search_ ()
114-
, rng_dist_ (new boost::uniform_int<> (0, std::numeric_limits<int>::max ()))
115-
, custom_model_constraints_ ([](auto){return true;})
116-
{
117-
if (random)
118-
rng_alg_.seed (std::random_device()());
119-
else
120-
rng_alg_.seed (12345u);
121-
122-
// Sets the input cloud and creates a vector of "fake" indices
123-
setInputCloud (cloud);
124-
125-
// Create a random number generator object
126-
rng_gen_.reset (new boost::variate_generator<boost::mt19937&, boost::uniform_int<> > (rng_alg_, *rng_dist_));
127-
}
128-
129105
/** \brief Constructor for base SampleConsensusModel.
130106
* \param[in] cloud the input point cloud dataset
131107
* \param[in] indices a vector of point indices to be used from \a cloud
132108
* \param[in] random if true set the random seed to the current time, else set to 12345 (default: false)
133109
*/
134-
SampleConsensusModel (const PointCloudConstPtr &cloud,
135-
const Indices &indices,
136-
bool random = false)
110+
SampleConsensusModel (const PointCloudConstPtr &cloud, const Indices &indices, const bool random = false)
137111
: input_ (cloud)
138-
, indices_ (new Indices (indices))
112+
, indices_(new Indices(indices))
139113
, radius_min_ (-std::numeric_limits<double>::max ())
140114
, radius_max_ (std::numeric_limits<double>::max ())
141115
, samples_radius_ (0.)
@@ -148,6 +122,13 @@ namespace pcl
148122
else
149123
rng_alg_.seed (12345u);
150124

125+
// If no indices are provided, use all points
126+
if (indices_->empty())
127+
{
128+
indices_->resize(cloud->size());
129+
std::iota(indices_->begin(), indices_->end(), 0);
130+
}
131+
151132
if (indices_->size () > input_->size ())
152133
{
153134
PCL_ERROR("[pcl::SampleConsensusModel] Invalid index vector given with size "
@@ -160,7 +141,14 @@ namespace pcl
160141

161142
// Create a random number generator object
162143
rng_gen_.reset (new boost::variate_generator<boost::mt19937&, boost::uniform_int<> > (rng_alg_, *rng_dist_));
163-
};
144+
}
145+
146+
/** \brief Constructor for base SampleConsensusModel.
147+
* \param[in] cloud the input point cloud dataset
148+
* \param[in] random if true set the random seed to the current time, else set to 12345 (default: false)
149+
*/
150+
SampleConsensusModel (const PointCloudConstPtr &cloud, const bool random = false)
151+
: SampleConsensusModel(cloud, Indices(), random) {};
164152

165153
/** \brief Destructor for base SampleConsensusModel. */
166154
virtual ~SampleConsensusModel () = default;

0 commit comments

Comments
 (0)