Skip to content

Commit d178ebf

Browse files
Remove use of raw pointer from NormalSpaceSampling.
1 parent 8d7033e commit d178ebf

File tree

2 files changed

+8
-14
lines changed

2 files changed

+8
-14
lines changed

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

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -59,11 +59,10 @@ pcl::NormalSpaceSampling<PointT, NormalT>::initCompute ()
5959
return false;
6060
}
6161

62-
boost::mt19937 rng (static_cast<unsigned int> (seed_));
63-
boost::uniform_int<unsigned int> uniform_distrib (0, unsigned (input_->size ()));
64-
delete rng_uniform_distribution_;
65-
rng_uniform_distribution_ = new boost::variate_generator<boost::mt19937, boost::uniform_int<unsigned int> > (rng, uniform_distrib);
66-
62+
rng_uniform_distribution_ = std::bind (
63+
boost::uniform_int<unsigned> (0, static_cast<unsigned> (input_->size ())),
64+
boost::mt19937 (seed_)
65+
);
6766
return (true);
6867
}
6968

@@ -217,7 +216,7 @@ pcl::NormalSpaceSampling<PointT, NormalT>::applyFilter (std::vector<int> &indice
217216
// Picking up a sample at random from jth bin
218217
do
219218
{
220-
random_index = static_cast<unsigned int> ((*rng_uniform_distribution_) () % M);
219+
random_index = rng_uniform_distribution_ () % M;
221220
pos = start_index[j] + random_index;
222221
} while (is_sampled_flag.test (pos));
223222

filters/include/pcl/filters/normal_space.h

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,10 @@
3939

4040
#include <pcl/filters/boost.h>
4141
#include <pcl/filters/filter_indices.h>
42+
4243
#include <ctime>
4344
#include <climits>
45+
#include <functional>
4446

4547
namespace pcl
4648
{
@@ -77,17 +79,10 @@ namespace pcl
7779
, binsy_ ()
7880
, binsz_ ()
7981
, input_normals_ ()
80-
, rng_uniform_distribution_ (nullptr)
8182
{
8283
filter_name_ = "NormalSpaceSampling";
8384
}
8485

85-
/** \brief Destructor. */
86-
~NormalSpaceSampling ()
87-
{
88-
delete rng_uniform_distribution_;
89-
}
90-
9186
/** \brief Set number of indices to be sampled.
9287
* \param[in] sample the number of sample indices
9388
*/
@@ -190,7 +185,7 @@ namespace pcl
190185
isEntireBinSampled (boost::dynamic_bitset<> &array, unsigned int start_index, unsigned int length);
191186

192187
/** \brief Uniform random distribution. */
193-
boost::variate_generator<boost::mt19937, boost::uniform_int<std::uint32_t> > *rng_uniform_distribution_;
188+
std::function<unsigned ()> rng_uniform_distribution_;
194189
};
195190
}
196191

0 commit comments

Comments
 (0)