85 const auto ix = std::min (binsx_ - 1,
static_cast<unsigned> (std::max (0.0f, std::floor (0.5f * (binsx_) * (normal[0] + 1.f)))));
86 const auto iy = std::min (binsy_ - 1,
static_cast<unsigned> (std::max (0.0f, std::floor (0.5f * (binsy_) * (normal[1] + 1.f)))));
87 const auto iz = std::min (binsz_ - 1,
static_cast<unsigned> (std::max (0.0f, std::floor (0.5f * (binsz_) * (normal[2] + 1.f)))));
101 unsigned int max_values = (std::min) (sample_,
static_cast<unsigned int> (input_normals_->size ()));
103 indices.resize (max_values);
104 removed_indices_->resize (max_values);
107 unsigned int n_bins = binsx_ * binsy_ * binsz_;
110 std::vector<std::list <int> > normals_hg;
111 normals_hg.reserve (n_bins);
112 for (
unsigned int i = 0; i < n_bins; i++)
113 normals_hg.emplace_back();
115 for (
const auto index : *indices_)
117 unsigned int bin_number = findBin ((*input_normals_)[index].normal);
118 normals_hg[bin_number].push_back (index);
124 std::vector<std::vector<std::list<int>::iterator> > random_access (normals_hg.size ());
125 for (std::size_t i = 0; i < normals_hg.size (); i++)
127 random_access.emplace_back();
128 random_access[i].resize (normals_hg[i].size ());
131 for (
auto itr = normals_hg[i].begin (); itr != normals_hg[i].end (); ++itr, ++j)
132 random_access[i][j] = itr;
134 std::vector<std::size_t> start_index (normals_hg.size ());
136 std::size_t prev_index = 0;
137 for (std::size_t i = 1; i < normals_hg.size (); i++)
139 start_index[i] = prev_index + normals_hg[i-1].size ();
140 prev_index = start_index[i];
144 boost::dynamic_bitset<> is_sampled_flag (input_normals_->size ());
146 boost::dynamic_bitset<> bin_empty_flag (normals_hg.size ());
151 for (std::size_t j = 0; j < normals_hg.size (); j++)
153 auto M =
static_cast<unsigned int> (normals_hg[j].size ());
154 if (M == 0 || bin_empty_flag.test (j))
157 unsigned int pos = 0;
158 unsigned int random_index = 0;
159 std::uniform_int_distribution<unsigned> rng_uniform_distribution (0u, M - 1u);
164 random_index = rng_uniform_distribution (rng_);
165 pos = start_index[j] + random_index;
166 }
while (is_sampled_flag.test (pos));
168 is_sampled_flag.flip (start_index[j] + random_index);
171 if (isEntireBinSampled (is_sampled_flag, start_index[j],
static_cast<unsigned int> (normals_hg[j].size ())))
172 bin_empty_flag.flip (j);
174 unsigned int index = *(random_access[j][random_index]);
183 if (extract_removed_indices_)
185 Indices indices_temp = indices;
186 std::sort (indices_temp.begin (), indices_temp.end ());
188 Indices all_indices_temp = *indices_;
189 std::sort (all_indices_temp.begin (), all_indices_temp.end ());
190 set_difference (all_indices_temp.begin (), all_indices_temp.end (),
191 indices_temp.begin (), indices_temp.end (),
192 inserter (*removed_indices_, removed_indices_->begin ()));