From b3183cb27768670a8410e8ce83af1cf2e599fbb3 Mon Sep 17 00:00:00 2001 From: Lukas Matena Date: Wed, 9 Nov 2022 15:00:46 +0100 Subject: [PATCH] Measurement: Fixed a bug in circles detection (failing assert) --- src/libslic3r/Measure.cpp | 35 ++++++++++------------------------- 1 file changed, 10 insertions(+), 25 deletions(-) diff --git a/src/libslic3r/Measure.cpp b/src/libslic3r/Measure.cpp index 6965357c37..43b9782a83 100644 --- a/src/libslic3r/Measure.cpp +++ b/src/libslic3r/Measure.cpp @@ -339,32 +339,9 @@ void MeasuringImpl::extract_features() } circles_lengths.clear(); // no longer needed, make it obvious - // Some of the "circles" may actually be polygons (5-8 vertices). We want them - // detected as edges, but also to remember the center and save it into those edges. - // We will add all such edges manually and delete the detected circles, leaving it - // in circles_idxs so they are not picked again. - assert(circles.size() == circles_idxs.size()); - for (int i=circles.size()-1; i>=0; --i) { - if (circles_idxs[i].first == 0 && circles_idxs[i].second == border.size()-1) { - int N = circles_idxs[i].second - circles_idxs[i].first; - if (N <= 8) { - if (N >= 5) { // polygon = 5,6,7,8 vertices - const Vec3d center = std::get<0>(circles[i].get_circle()); - for (int j=(int)circles_idxs[i].first + 1; j<=(int)circles_idxs[i].second; ++j) - edges.emplace_back(SurfaceFeature(SurfaceFeatureType::Edge, - border[j - 1], border[j], std::make_optional(center))); - } else { - // This will be handled just like a regular edge (squares, triangles). - circles_idxs.erase(circles_idxs.begin() + i); - } - circles.erase(circles.begin() + i); - } - } - } - // Anything under 5 vertices shall not be considered a circle. assert(circles_idxs.size() == circles.size()); - for (int i=0; i=0; --i) { const auto& [start, end] = circles_idxs[i]; int N = start >= 0 ? end - start + (start == 0 && end == border.size()-1 ? 0 : 1) // last point is the same as first @@ -372,7 +349,15 @@ void MeasuringImpl::extract_features() if (N < 5) { circles.erase(circles.begin() + i); circles_idxs.erase(circles_idxs.begin() + i); - --i; + } else if (N <= 8 && start == 0 && end == border.size()-1) { + // This is a regular 5-8 polygon. Add the edges as edges with a special + // point and remove the circle. Leave the indices in circles_idxs, so + // the edges are not picked up again later. + const Vec3d center = std::get<0>(circles[i].get_circle()); + for (int j=1; j<=end; ++j) + edges.emplace_back(SurfaceFeature(SurfaceFeatureType::Edge, + border[j - 1], border[j], std::make_optional(center))); + circles.erase(circles.begin() + i); } }