Fixed short edge collapse algortihm, so that it does not decimate all triangles on very high detailed models

Relevant issue 8834 Access Error when slicing
This commit is contained in:
PavelMikus 2022-09-09 12:50:10 +02:00
parent ec2f533e3a
commit 59fa918828
3 changed files with 8 additions and 3 deletions

View File

@ -663,8 +663,8 @@ void compute_global_occlusion(GlobalModelInfo &result, const PrintObject *po,
BOOST_LOG_TRIVIAL(debug) BOOST_LOG_TRIVIAL(debug)
<< "SeamPlacer: decimate: start"; << "SeamPlacer: decimate: start";
its_short_edge_collpase(triangle_set, 25000); its_short_edge_collpase(triangle_set, SeamPlacer::fast_decimation_triangle_count_target);
its_short_edge_collpase(negative_volumes_set, 25000); its_short_edge_collpase(negative_volumes_set, SeamPlacer::fast_decimation_triangle_count_target);
size_t negative_volumes_start_index = triangle_set.indices.size(); size_t negative_volumes_start_index = triangle_set.indices.size();
its_merge(triangle_set, negative_volumes_set); its_merge(triangle_set, negative_volumes_set);

View File

@ -123,6 +123,7 @@ class SeamPlacer {
public: 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 // 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; static constexpr size_t raycasting_visibility_samples_count = 30000;
static constexpr size_t fast_decimation_triangle_count_target = 16000;
//square of number of rays per sample point //square of number of rays per sample point
static constexpr size_t sqr_rays_per_sample_point = 5; static constexpr size_t sqr_rays_per_sample_point = 5;

View File

@ -98,6 +98,7 @@ 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 //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); 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) { for (const size_t &face_idx : face_indices) {
if (face_removal_flags[face_idx]) { if (face_removal_flags[face_idx]) {
// if face already removed from previous collapses, skip (each collapse removes two triangles [at least] ) // 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 faces
remove_face(face_idx, neighbor_to_remove_face_idx); remove_face(face_idx, neighbor_to_remove_face_idx);
remove_face(neighbor_to_remove_face_idx, face_idx); remove_face(neighbor_to_remove_face_idx, face_idx);
allowed_face_removals-=2;
// break. this triangle is done // break. this triangle is done
break; break;
} }
if (allowed_face_removals <= 0) { break; }
} }
// filter face_indices, remove those that have been collapsed // filter face_indices, remove those that have been collapsed