FIX: short edge collapse algortihm

so that it does not decimate all triangles on very high detailed models
Relevant issue 8834 Access Error when slicing
Github: #2283

Change-Id: I047361c88c561962ef4d3cf67bc0126402c41941
(cherry picked from commit f8aaa5c69d59c5fced4b7bb112376e4df94b5ddc)
This commit is contained in:
PavelMikus 2022-09-09 12:50:10 +02:00 committed by Lane.Wei
parent 731035b8b6
commit a15700e5de
3 changed files with 11 additions and 5 deletions

View file

@ -590,9 +590,10 @@ void compute_global_occlusion(GlobalModelInfo &result, const PrintObject *po, st
BOOST_LOG_TRIVIAL(debug) << "SeamPlacer: gather occlusion meshes: end";
BOOST_LOG_TRIVIAL(debug) << "SeamPlacer: decimate: start";
its_short_edge_collpase(triangle_set, 25000);
its_short_edge_collpase(negative_volumes_set, 25000);
BOOST_LOG_TRIVIAL(debug)
<< "SeamPlacer: decimate: start";
its_short_edge_collpase(triangle_set, SeamPlacer::fast_decimation_triangle_count_target);
its_short_edge_collpase(negative_volumes_set, SeamPlacer::fast_decimation_triangle_count_target);
size_t negative_volumes_start_index = triangle_set.indices.size();
its_merge(triangle_set, negative_volumes_set);

View file

@ -115,7 +115,8 @@ class SeamPlacer
public:
// Number of samples generated on the mesh. There are sqr_rays_per_sample_point*sqr_rays_per_sample_point rays casted from each samples
static constexpr size_t raycasting_visibility_samples_count = 30000;
// square of number of rays per sample point
static constexpr size_t fast_decimation_triangle_count_target = 16000;
//square of number of rays per sample point
static constexpr size_t sqr_rays_per_sample_point = 5;
// snapping angle - angles larger than this value will be snapped to during seam painting

View file

@ -97,7 +97,8 @@ void its_short_edge_collpase(indexed_triangle_set &mesh, size_t target_triangle_
//shuffle the faces and traverse in random order, this MASSIVELY improves the quality of the result
std::shuffle(face_indices.begin(), face_indices.end(), generator);
int allowed_face_removals = int(face_indices.size()) - int(target_triangle_count);
for (const size_t &face_idx : face_indices) {
if (face_removal_flags[face_idx]) {
// if face already removed from previous collapses, skip (each collapse removes two triangles [at least] )
@ -130,10 +131,13 @@ void its_short_edge_collpase(indexed_triangle_set &mesh, size_t target_triangle_
// remove faces
remove_face(face_idx, neighbor_to_remove_face_idx);
remove_face(neighbor_to_remove_face_idx, face_idx);
allowed_face_removals-=2;
// break. this triangle is done
break;
}
if (allowed_face_removals <= 0) { break; }
}
// filter face_indices, remove those that have been collapsed