Skip to content

Commit

Permalink
Remove use of raw pointer from NormalSpaceSampling.
Browse files Browse the repository at this point in the history
  • Loading branch information
SergioRAgostinho committed Apr 3, 2020
1 parent 8d7033e commit d178ebf
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 14 deletions.
11 changes: 5 additions & 6 deletions filters/include/pcl/filters/impl/normal_space.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,10 @@ pcl::NormalSpaceSampling<PointT, NormalT>::initCompute ()
return false;
}

boost::mt19937 rng (static_cast<unsigned int> (seed_));
boost::uniform_int<unsigned int> uniform_distrib (0, unsigned (input_->size ()));
delete rng_uniform_distribution_;
rng_uniform_distribution_ = new boost::variate_generator<boost::mt19937, boost::uniform_int<unsigned int> > (rng, uniform_distrib);

rng_uniform_distribution_ = std::bind (
boost::uniform_int<unsigned> (0, static_cast<unsigned> (input_->size ())),
boost::mt19937 (seed_)
);
return (true);
}

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

Expand Down
11 changes: 3 additions & 8 deletions filters/include/pcl/filters/normal_space.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,10 @@

#include <pcl/filters/boost.h>
#include <pcl/filters/filter_indices.h>

#include <ctime>
#include <climits>
#include <functional>

namespace pcl
{
Expand Down Expand Up @@ -77,17 +79,10 @@ namespace pcl
, binsy_ ()
, binsz_ ()
, input_normals_ ()
, rng_uniform_distribution_ (nullptr)
{
filter_name_ = "NormalSpaceSampling";
}

/** \brief Destructor. */
~NormalSpaceSampling ()
{
delete rng_uniform_distribution_;
}

/** \brief Set number of indices to be sampled.
* \param[in] sample the number of sample indices
*/
Expand Down Expand Up @@ -190,7 +185,7 @@ namespace pcl
isEntireBinSampled (boost::dynamic_bitset<> &array, unsigned int start_index, unsigned int length);

/** \brief Uniform random distribution. */
boost::variate_generator<boost::mt19937, boost::uniform_int<std::uint32_t> > *rng_uniform_distribution_;
std::function<unsigned ()> rng_uniform_distribution_;
};
}

Expand Down

0 comments on commit d178ebf

Please sign in to comment.