@@ -79,66 +79,12 @@ pcl::NormalSpaceSampling<PointT, NormalT>::isEntireBinSampled (boost::dynamic_bi
7979
8080// /////////////////////////////////////////////////////////////////////////////
8181template <typename PointT, typename NormalT> unsigned int
82- pcl::NormalSpaceSampling<PointT, NormalT>::findBin (const float *normal, unsigned int )
82+ pcl::NormalSpaceSampling<PointT, NormalT>::findBin (const float *normal)
8383{
84- unsigned int bin_number = 0 ;
85- // Holds the bin numbers for direction cosines in x,y,z directions
86- unsigned int t[3 ] = {0 ,0 ,0 };
87-
88- // dcos is the direction cosine.
89- float dcos = 0.0 ;
90- float bin_size = 0.0 ;
91- // max_cos and min_cos are the maximum and minimum values of std::cos(theta) respectively
92- float max_cos = 1.0 ;
93- float min_cos = -1.0 ;
94-
95- // dcos = std::cos (normal[0]);
96- dcos = normal[0 ];
97- bin_size = (max_cos - min_cos) / static_cast <float > (binsx_);
98-
99- // Finding bin number for direction cosine in x direction
100- unsigned int k = 0 ;
101- for (float i = min_cos; (i + bin_size) < (max_cos - bin_size); i += bin_size , k++)
102- {
103- if (dcos >= i && dcos <= (i+bin_size))
104- {
105- break ;
106- }
107- }
108- t[0 ] = k;
109-
110- // dcos = std::cos (normal[1]);
111- dcos = normal[1 ];
112- bin_size = (max_cos - min_cos) / static_cast <float > (binsy_);
113-
114- // Finding bin number for direction cosine in y direction
115- k = 0 ;
116- for (float i = min_cos; (i + bin_size) < (max_cos - bin_size); i += bin_size , k++)
117- {
118- if (dcos >= i && dcos <= (i+bin_size))
119- {
120- break ;
121- }
122- }
123- t[1 ] = k;
124-
125- // dcos = std::cos (normal[2]);
126- dcos = normal[2 ];
127- bin_size = (max_cos - min_cos) / static_cast <float > (binsz_);
128-
129- // Finding bin number for direction cosine in z direction
130- k = 0 ;
131- for (float i = min_cos; (i + bin_size) < (max_cos - bin_size); i += bin_size , k++)
132- {
133- if (dcos >= i && dcos <= (i+bin_size))
134- {
135- break ;
136- }
137- }
138- t[2 ] = k;
139-
140- bin_number = t[0 ] * (binsy_*binsz_) + t[1 ] * binsz_ + t[2 ];
141- 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;
14288}
14389
14490// /////////////////////////////////////////////////////////////////////////////
@@ -165,10 +111,10 @@ pcl::NormalSpaceSampling<PointT, NormalT>::applyFilter (std::vector<int> &indice
165111 for (unsigned int i = 0 ; i < n_bins; i++)
166112 normals_hg.emplace_back ();
167113
168- for (std::vector< int >::const_iterator it = indices_-> begin (); it != indices_-> end (); ++it )
114+ for (const auto index : * indices_)
169115 {
170- unsigned int bin_number = findBin (input_normals_-> points [*it ].normal , n_bins );
171- 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 );
172118 }
173119
174120
0 commit comments