Skip to content

Commit 4105d6f

Browse files
committed
Update the displayed mesh after each part instance
1 parent aa2a372 commit 4105d6f

File tree

3 files changed

+11
-9
lines changed

3 files changed

+11
-9
lines changed

src/pstack/calc/stacker.cpp

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ struct stack_state {
2424
util::mdarray<Bool, 3> space;
2525
std::vector<std::shared_ptr<const part>> ordered_parts;
2626
stack_result result;
27+
std::size_t total_parts;
28+
std::size_t total_placed;
2729
};
2830

2931
void place(const util::mdspan<Bool, 3> space, const int index, const util::mdspan<const int, 3> obj, const int x, const int y, const int z) {
@@ -100,6 +102,9 @@ std::size_t try_place(const stack_parameters& params, stack_state& state, const
100102
new_piece.translation += translation;
101103
place(state.space, bit_index, state.voxels[part_index], x, y, z); // Mark voxels as occupied
102104
++placed;
105+
++state.total_placed;
106+
params.set_progress(state.total_placed, state.total_parts);
107+
params.display_mesh(state.result.mesh, max);
103108
if (to_place == placed) { // All instances of this part placed, move to next part
104109
return placed;
105110
} else { // Move to next instance of part
@@ -125,10 +130,11 @@ std::optional<stack_result> stack_impl(const stack_parameters& params, const std
125130

126131
double triangles = 0;
127132
const double scale_factor = 1 / params.resolution;
128-
int total_parts = 0;
133+
state.total_parts = 0;
134+
state.total_placed = 0;
129135
for (const std::shared_ptr<const part> part : state.ordered_parts) {
130136
triangles += part->triangle_count * rotation_sets[part->rotation_index].size();
131-
total_parts += part->quantity;
137+
state.total_parts += part->quantity;
132138
}
133139

134140
double progress = 0;
@@ -232,7 +238,6 @@ std::optional<stack_result> stack_impl(const stack_parameters& params, const std
232238

233239
params.set_progress(0, 1);
234240

235-
std::size_t total_placed = 0;
236241
for (std::size_t part_index = 0; part_index != state.ordered_parts.size(); ++part_index) {
237242
std::size_t to_place = state.ordered_parts[part_index]->quantity;
238243
while (to_place > 0) {
@@ -241,9 +246,6 @@ std::optional<stack_result> stack_impl(const stack_parameters& params, const std
241246
}
242247
const std::size_t placed = try_place(params, state, part_index, to_place, { max_x, max_y, max_z });
243248
to_place -= placed;
244-
total_placed += placed;
245-
params.set_progress(total_placed, total_parts);
246-
params.display_mesh(state.result.mesh, max_x, max_y, max_z);
247249

248250
// If we have not placed a part, it means there are no more ways to place an instance of the current part in the box: it must be enlarged
249251
if (placed == 0) {

src/pstack/calc/stacker.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ struct stack_parameters {
3030
std::vector<std::shared_ptr<const part>> parts;
3131

3232
std::function<void(double, double)> set_progress;
33-
std::function<void(const mesh&, int, int, int)> display_mesh;
33+
std::function<void(const mesh&, const geo::point3<int>)> display_mesh;
3434
std::function<void(stack_result, std::chrono::system_clock::duration)> on_success;
3535
std::function<void()> on_failure;
3636
std::function<void()> on_finish;

src/pstack/gui/main_window.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -190,10 +190,10 @@ void main_window::on_stacking_start() {
190190
_controls.progress_bar->SetValue(static_cast<int>(100 * progress / total));
191191
});
192192
},
193-
.display_mesh = [this](const calc::mesh& mesh, int max_x, int max_y, int max_z) {
193+
.display_mesh = [this](const calc::mesh& mesh, const geo::point3<int> max) {
194194
CallAfter([=] {
195195
// Make a copy of `mesh`, otherwise we encounter a data race
196-
_viewport->set_mesh(mesh, { max_x / 2.0f, max_y / 2.0f, max_z / 2.0f });
196+
_viewport->set_mesh(mesh, { max.x / 2.0f, max.y / 2.0f, max.z / 2.0f });
197197
});
198198
},
199199
.on_success = [this](calc::stack_result result, const std::chrono::system_clock::duration elapsed) {

0 commit comments

Comments
 (0)