@@ -59,11 +59,7 @@ 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_.seed (seed_);
6763 return (true );
6864}
6965
@@ -83,66 +79,12 @@ pcl::NormalSpaceSampling<PointT, NormalT>::isEntireBinSampled (boost::dynamic_bi
8379
8480// /////////////////////////////////////////////////////////////////////////////
8581template <typename PointT, typename NormalT> unsigned int
86- pcl::NormalSpaceSampling<PointT, NormalT>::findBin (const float *normal, unsigned int )
82+ pcl::NormalSpaceSampling<PointT, NormalT>::findBin (const float *normal)
8783{
88- unsigned int bin_number = 0 ;
89- // Holds the bin numbers for direction cosines in x,y,z directions
90- unsigned int t[3 ] = {0 ,0 ,0 };
91-
92- // dcos is the direction cosine.
93- float dcos = 0.0 ;
94- float bin_size = 0.0 ;
95- // max_cos and min_cos are the maximum and minimum values of std::cos(theta) respectively
96- float max_cos = 1.0 ;
97- float min_cos = -1.0 ;
98-
99- // dcos = std::cos (normal[0]);
100- dcos = normal[0 ];
101- bin_size = (max_cos - min_cos) / static_cast <float > (binsx_);
102-
103- // Finding bin number for direction cosine in x direction
104- unsigned int k = 0 ;
105- for (float i = min_cos; (i + bin_size) < (max_cos - bin_size); i += bin_size , k++)
106- {
107- if (dcos >= i && dcos <= (i+bin_size))
108- {
109- break ;
110- }
111- }
112- t[0 ] = k;
113-
114- // dcos = std::cos (normal[1]);
115- dcos = normal[1 ];
116- bin_size = (max_cos - min_cos) / static_cast <float > (binsy_);
117-
118- // Finding bin number for direction cosine in y direction
119- k = 0 ;
120- for (float i = min_cos; (i + bin_size) < (max_cos - bin_size); i += bin_size , k++)
121- {
122- if (dcos >= i && dcos <= (i+bin_size))
123- {
124- break ;
125- }
126- }
127- t[1 ] = k;
128-
129- // dcos = std::cos (normal[2]);
130- dcos = normal[2 ];
131- bin_size = (max_cos - min_cos) / static_cast <float > (binsz_);
132-
133- // Finding bin number for direction cosine in z direction
134- k = 0 ;
135- for (float i = min_cos; (i + bin_size) < (max_cos - bin_size); i += bin_size , k++)
136- {
137- if (dcos >= i && dcos <= (i+bin_size))
138- {
139- break ;
140- }
141- }
142- t[2 ] = k;
143-
144- bin_number = t[0 ] * (binsy_*binsz_) + t[1 ] * binsz_ + t[2 ];
145- return bin_number;
84+ const unsigned ix = static_cast <unsigned > (std::round (0 .5f * (binsx_ - 1 .f ) * (normal[0 ] + 1 .f )));
85+ const unsigned iy = static_cast <unsigned > (std::round (0 .5f * (binsy_ - 1 .f ) * (normal[1 ] + 1 .f )));
86+ const unsigned iz = static_cast <unsigned > (std::round (0 .5f * (binsz_ - 1 .f ) * (normal[2 ] + 1 .f )));
87+ return ix * (binsy_*binsz_) + iy * binsz_ + iz;
14688}
14789
14890// /////////////////////////////////////////////////////////////////////////////
@@ -169,10 +111,10 @@ pcl::NormalSpaceSampling<PointT, NormalT>::applyFilter (std::vector<int> &indice
169111 for (unsigned int i = 0 ; i < n_bins; i++)
170112 normals_hg.emplace_back ();
171113
172- for (std::vector< int >::const_iterator it = indices_-> begin (); it != indices_-> end (); ++it )
114+ for (const auto index : * indices_)
173115 {
174- unsigned int bin_number = findBin (input_normals_-> points [*it ].normal , n_bins );
175- normals_hg[bin_number].push_back (*it );
116+ unsigned int bin_number = findBin ((* input_normals_)[index ].normal );
117+ normals_hg[bin_number].push_back (index );
176118 }
177119
178120
@@ -213,11 +155,12 @@ pcl::NormalSpaceSampling<PointT, NormalT>::applyFilter (std::vector<int> &indice
213155
214156 unsigned int pos = 0 ;
215157 unsigned int random_index = 0 ;
158+ std::uniform_int_distribution<unsigned > rng_uniform_distribution (0u , M - 1u );
216159
217160 // Picking up a sample at random from jth bin
218161 do
219162 {
220- random_index = static_cast < unsigned int > ((*rng_uniform_distribution_) () % M );
163+ random_index = rng_uniform_distribution (rng_ );
221164 pos = start_index[j] + random_index;
222165 } while (is_sampled_flag.test (pos));
223166
0 commit comments