Skip to content

Commit 77c99fd

Browse files
author
Heiko Thiel
committed
Use random generator from C++11 instead of from Boost in module filters
1 parent d009887 commit 77c99fd

File tree

4 files changed

+12
-25
lines changed

4 files changed

+12
-25
lines changed

filters/include/pcl/filters/boost.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,6 @@
4545
#endif
4646

4747
// Marking all Boost headers as system headers to remove warnings
48-
#include <boost/random.hpp>
49-
#include <boost/random/normal_distribution.hpp>
5048
#include <boost/shared_ptr.hpp>
5149
#include <boost/make_shared.hpp>
5250
#include <boost/dynamic_bitset.hpp>

filters/include/pcl/filters/impl/normal_space.hpp

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,9 @@
4141
#include <pcl/filters/normal_space.h>
4242
#include <pcl/common/io.h>
4343

44-
#include <vector>
4544
#include <list>
45+
#include <random>
46+
#include <vector>
4647

4748
///////////////////////////////////////////////////////////////////////////////
4849
template<typename PointT, typename NormalT> bool
@@ -59,12 +60,6 @@ pcl::NormalSpaceSampling<PointT, NormalT>::initCompute ()
5960
return false;
6061
}
6162

62-
boost::mt19937 rng (static_cast<unsigned int> (seed_));
63-
boost::uniform_int<unsigned int> uniform_distrib (0, unsigned (input_->size ()));
64-
if (rng_uniform_distribution_ != NULL)
65-
delete rng_uniform_distribution_;
66-
rng_uniform_distribution_ = new boost::variate_generator<boost::mt19937, boost::uniform_int<unsigned int> > (rng, uniform_distrib);
67-
6863
return (true);
6964
}
7065

@@ -228,6 +223,10 @@ pcl::NormalSpaceSampling<PointT, NormalT>::applyFilter (std::vector<int> &indice
228223
boost::dynamic_bitset<> is_sampled_flag (input_normals_->points.size ());
229224
// Maintaining flags to check if all points in the bin are sampled
230225
boost::dynamic_bitset<> bin_empty_flag (normals_hg.size ());
226+
227+
std::mt19937 rng (static_cast<unsigned int> (seed_));
228+
std::uniform_int_distribution<unsigned int> uniform_distrib (0, unsigned (input_->size ()));
229+
231230
unsigned int i = 0;
232231
while (i < sample_)
233232
{
@@ -244,7 +243,7 @@ pcl::NormalSpaceSampling<PointT, NormalT>::applyFilter (std::vector<int> &indice
244243
// Picking up a sample at random from jth bin
245244
do
246245
{
247-
random_index = static_cast<unsigned int> ((*rng_uniform_distribution_) () % M);
246+
random_index = static_cast<unsigned int> (uniform_distrib (rng) % M);
248247
pos = start_index[j] + random_index;
249248
} while (is_sampled_flag.test (pos));
250249

filters/include/pcl/filters/impl/voxel_grid_covariance.hpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@
3838
#ifndef PCL_VOXEL_GRID_COVARIANCE_IMPL_H_
3939
#define PCL_VOXEL_GRID_COVARIANCE_IMPL_H_
4040

41+
#include <random>
42+
4143
#include <pcl/common/common.h>
4244
#include <pcl/filters/boost.h>
4345
#include <pcl/filters/voxel_grid_covariance.h>
@@ -411,9 +413,8 @@ pcl::VoxelGridCovariance<PointT>::getDisplayCloud (pcl::PointCloud<PointXYZ>& ce
411413
cell_cloud.clear ();
412414

413415
int pnt_per_cell = 1000;
414-
boost::mt19937 rng;
415-
boost::normal_distribution<> nd (0.0, leaf_size_.head (3).norm ());
416-
boost::variate_generator<boost::mt19937&, boost::normal_distribution<> > var_nor (rng, nd);
416+
std::mt19937 rng;
417+
std::normal_distribution<> nd (0.0, leaf_size_.head (3).norm ());
417418

418419
Eigen::LLT<Eigen::Matrix3d> llt_of_cov;
419420
Eigen::Matrix3d cholesky_decomp;
@@ -435,7 +436,7 @@ pcl::VoxelGridCovariance<PointT>::getDisplayCloud (pcl::PointCloud<PointXYZ>& ce
435436
// Random points generated by sampling the normal distribution given by voxel mean and covariance matrix
436437
for (int i = 0; i < pnt_per_cell; i++)
437438
{
438-
rand_point = Eigen::Vector3d (var_nor (), var_nor (), var_nor ());
439+
rand_point = Eigen::Vector3d (nd (rng), nd (rng), nd (rng));
439440
dist_point = cell_mean + cholesky_decomp * rand_point;
440441
cell_cloud.push_back (PointXYZ (static_cast<float> (dist_point (0)), static_cast<float> (dist_point (1)), static_cast<float> (dist_point (2))));
441442
}

filters/include/pcl/filters/normal_space.h

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -77,18 +77,10 @@ namespace pcl
7777
, binsy_ ()
7878
, binsz_ ()
7979
, input_normals_ ()
80-
, rng_uniform_distribution_ (NULL)
8180
{
8281
filter_name_ = "NormalSpaceSampling";
8382
}
8483

85-
/** \brief Destructor. */
86-
~NormalSpaceSampling ()
87-
{
88-
if (rng_uniform_distribution_ != NULL)
89-
delete rng_uniform_distribution_;
90-
}
91-
9284
/** \brief Set number of indices to be sampled.
9385
* \param[in] sample the number of sample indices
9486
*/
@@ -195,9 +187,6 @@ namespace pcl
195187
*/
196188
bool
197189
isEntireBinSampled (boost::dynamic_bitset<> &array, unsigned int start_index, unsigned int length);
198-
199-
/** \brief Uniform random distribution. */
200-
boost::variate_generator<boost::mt19937, boost::uniform_int<uint32_t> > *rng_uniform_distribution_;
201190
};
202191
}
203192

0 commit comments

Comments
 (0)