Skip to content

Commit 2da82a8

Browse files
committed
geometry
1 parent c49285a commit 2da82a8

File tree

1 file changed

+44
-24
lines changed

1 file changed

+44
-24
lines changed

src/geometry/accelerators/tree.cpp

Lines changed: 44 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ void insert_child_box_indices(const Objects& objects, const std::vector<int>& bo
143143
}
144144

145145
template <typename Box, typename Objects>
146-
void extend(
146+
bool extend_iteration(
147147
const Objects& objects,
148148
const unsigned max_depth,
149149
const unsigned min_objects,
@@ -153,37 +153,57 @@ void extend(
153153
ThreadTaskManager<Task<Box>>* const task_manager,
154154
progress::Ratio* const progress)
155155
{
156-
while (true)
156+
const auto task = task_manager->get();
157+
if (!task)
157158
{
158-
const auto task = task_manager->get();
159-
if (!task)
160-
{
161-
break;
162-
}
159+
return false;
160+
}
161+
162+
if (task->depth >= max_depth || task->box->object_indices.size() <= min_objects)
163+
{
164+
task->box->childs[0] = -1;
165+
return true;
166+
}
163167

164-
if (task->depth >= max_depth || task->box->object_indices.size() <= min_objects)
168+
const std::array child_boxes = create_child_boxes(task->box->parallelotope, boxes_lock, boxes);
169+
for (std::size_t i = 0; i < child_boxes.size(); ++i)
170+
{
171+
if ((child_boxes[i].index & 0xfff) == 0xfff)
165172
{
166-
task->box->childs[0] = -1;
167-
continue;
173+
progress->set(child_boxes[i].index, max_boxes);
168174
}
169175

170-
const std::array child_boxes = create_child_boxes(task->box->parallelotope, boxes_lock, boxes);
171-
for (std::size_t i = 0; i < child_boxes.size(); ++i)
172-
{
173-
if ((child_boxes[i].index & 0xfff) == 0xfff)
174-
{
175-
progress->set(child_boxes[i].index, max_boxes);
176-
}
176+
task->box->childs[i] = child_boxes[i].index;
177177

178-
task->box->childs[i] = child_boxes[i].index;
178+
Box* const child_box = child_boxes[i].box;
179+
insert_child_box_indices(objects, task->box->object_indices, child_box);
180+
task_manager->emplace(child_box, task->depth + 1);
181+
}
179182

180-
Box* const child_box = child_boxes[i].box;
181-
insert_child_box_indices(objects, task->box->object_indices, child_box);
182-
task_manager->emplace(child_box, task->depth + 1);
183-
}
183+
task->box->object_indices.clear();
184+
task->box->object_indices.shrink_to_fit();
184185

185-
task->box->object_indices.clear();
186-
task->box->object_indices.shrink_to_fit();
186+
return true;
187+
}
188+
189+
template <typename Box, typename Objects>
190+
void extend(
191+
const Objects& objects,
192+
const unsigned max_depth,
193+
const unsigned min_objects,
194+
const unsigned max_boxes,
195+
std::mutex* const boxes_lock,
196+
std::deque<Box>* const boxes,
197+
ThreadTaskManager<Task<Box>>* const task_manager,
198+
progress::Ratio* const progress)
199+
{
200+
while (true)
201+
{
202+
if (!extend_iteration(
203+
objects, max_depth, min_objects, max_boxes, boxes_lock, boxes, task_manager, progress))
204+
{
205+
return;
206+
}
187207
}
188208
}
189209

0 commit comments

Comments
 (0)