11 template <
typename external_space_po
int_t>
13 std::size_t n_low, std::size_t n_high) {
14 m_max_size_high = n_high;
15 m_max_size_low = n_low;
19 if (n_high == std::numeric_limits<std::size_t>::max() or
20 n_low == std::numeric_limits<std::size_t>::max()) {
25 m_storage.reserve(n_low + n_high);
26 m_indices_high.reserve(n_high);
27 m_indices_low.reserve(n_low);
30 template <
typename external_space_po
int_t>
32 std::vector<std::size_t>& indices, std::size_t& current_size) {
40 std::swap(indices[0], indices[current_size - 1]);
41 bubbledw(indices, 0, --current_size);
44 template <
typename external_space_po
int_t>
46 const std::size_t
n,
const std::size_t max_size)
const {
52 template <
typename external_space_po
int_t>
54 const std::vector<std::size_t>& indices, std::size_t
n)
const {
56 return m_storage[indices[
n]].weight;
59 template <
typename external_space_po
int_t>
67 m_indices_high.clear();
68 m_indices_low.clear();
71 template <
typename external_space_po
int_t>
73 external_space_point_t& SpB, external_space_point_t& SpM,
74 external_space_point_t& SpT,
float weight,
float zOrigin,
bool isQuality) {
78 return push(m_indices_high, m_n_high, m_max_size_high, SpB, SpM, SpT,
79 weight, zOrigin, isQuality);
81 return push(m_indices_low, m_n_low, m_max_size_low, SpB, SpM, SpT, weight,
85 template <
typename external_space_po
int_t>
87 std::vector<std::size_t>& indices, std::size_t&
n,
const std::size_t n_max,
88 external_space_point_t& SpB, external_space_point_t& SpM,
89 external_space_point_t& SpT,
float weight,
float zOrigin,
bool isQuality) {
97 addToCollection(indices, n, n_max,
98 value_type(SpB, SpM, SpT, weight, zOrigin, isQuality));
104 const auto& lowest_weight = this->weight(indices, 0);
105 if (weight <= lowest_weight) {
111 addToCollection(indices, n, n_max,
112 value_type(SpB, SpM, SpT, weight, zOrigin, isQuality));
116 template <
typename external_space_po
int_t>
118 std::vector<std::size_t>& indices, std::size_t&
n,
const std::size_t n_max,
121 if (indices.size() == n_max) {
125 indices.push_back(m_storage.size() - 1);
128 bubbleup(indices, n++);
131 template <
typename external_space_po
int_t>
133 std::vector<std::size_t>& indices, std::size_t
n, std::size_t actual_size) {
134 while (n < actual_size) {
138 float current = weight(indices, n);
139 std::size_t left_child = 2 * n + 1;
140 std::size_t right_child = 2 * n + 2;
153 if (not
exists(left_child, actual_size)) {
161 float weight_left_child = weight(indices, left_child);
163 std::size_t selected_child = left_child;
164 float selected_weight = weight_left_child;
167 if (
exists(right_child, actual_size)) {
168 float weight_right_child = weight(indices, right_child);
169 if (weight_right_child <= weight_left_child) {
170 selected_child = right_child;
171 selected_weight = weight_right_child;
178 if (selected_weight >= current) {
183 std::swap(indices[n], indices[selected_child]);
188 template <
typename external_space_po
int_t>
190 std::vector<std::size_t>& indices, std::size_t
n) {
195 std::size_t parent_idx = (n - 1) / 2;
197 float weight_current = weight(indices, n);
198 float weight_parent = weight(indices, parent_idx);
201 if (weight_parent <= weight_current) {
206 std::swap(indices[n], indices[parent_idx]);
211 template <
typename external_space_po
int_t>
216 std::vector<value_type>
output(m_n_high + m_n_low);
217 std::size_t out_idx = output.size() - 1;
222 while (m_n_high != 0 or m_n_low != 0) {
225 std::size_t
idx = m_n_low;
226 for (std::size_t
i(0);
i <
idx;
i++) {
227 output[out_idx--] =
std::move(m_storage[m_indices_low[0]]);
228 pop(m_indices_low, m_n_low);
235 std::size_t
idx = m_n_high;
236 for (std::size_t
i(0);
i <
idx;
i++) {
237 output[out_idx--] =
std::move(m_storage[m_indices_high[0]]);
238 pop(m_indices_high, m_n_high);
244 if (descendingByQuality(m_storage[m_indices_low[0]],
245 m_storage[m_indices_high[0]])) {
246 output[out_idx--] =
std::move(m_storage[m_indices_high[0]]);
247 pop(m_indices_high, m_n_high);
249 output[out_idx--] =
std::move(m_storage[m_indices_low[0]]);
250 pop(m_indices_low, m_n_low);
259 template <
typename external_space_po
int_t>
269 const auto& bottom_l1 = i1.
bottom;
270 const auto& middle_l1 = i1.
middle;
271 const auto& top_l1 = i1.
top;
273 const auto& bottom_l2 = i2.
bottom;
274 const auto& middle_l2 = i2.
middle;
275 const auto& top_l2 = i2.
top;
277 float seed1_sum = 0.;
278 float seed2_sum = 0.;
281 bottom_l1->y() * bottom_l1->y() + bottom_l1->z() * bottom_l1->z();
283 middle_l1->y() * middle_l1->y() + middle_l1->z() * middle_l1->z();
284 seed1_sum += top_l1->y() * top_l1->y() + top_l1->z() * top_l1->z();
287 bottom_l2->y() * bottom_l2->y() + bottom_l2->z() * bottom_l2->z();
289 middle_l2->y() * middle_l2->y() + middle_l2->z() * middle_l2->z();
290 seed2_sum += top_l2->y() * top_l2->y() + top_l2->z() * top_l2->z();
292 return seed1_sum > seed2_sum;
295 template <
typename external_space_po
int_t>
298 return not descendingByQuality(i1, i2);