FIX:Elephant foot compensation simplify expoly leads to contour loss

jira: none
Change-Id: I4df620e1a0c55803499ec979fa3ea22394f32699
This commit is contained in:
zhimin.zeng 2025-02-07 17:34:57 +08:00 committed by lane.wei
parent f2d9902ff3
commit 48368ed472
2 changed files with 34 additions and 20 deletions

View File

@ -564,17 +564,16 @@ ExPolygon elephant_foot_compensation(const ExPolygon &input_expoly, double min_c
else else
{ {
EdgeGrid::Grid grid; EdgeGrid::Grid grid;
ExPolygon simplified = input_expoly.simplify(SCALED_EPSILON).front(); assert(validate_expoly_orientation(input_expoly));
assert(validate_expoly_orientation(simplified)); BoundingBox bbox = get_extents(input_expoly.contour);
BoundingBox bbox = get_extents(simplified.contour);
bbox.offset(SCALED_EPSILON); bbox.offset(SCALED_EPSILON);
grid.set_bbox(bbox); grid.set_bbox(bbox);
grid.create(simplified, coord_t(0.7 * search_radius)); grid.create(input_expoly, coord_t(0.7 * search_radius));
std::vector<std::vector<float>> deltas; std::vector<std::vector<float>> deltas;
deltas.reserve(simplified.holes.size() + 1); deltas.reserve(input_expoly.holes.size() + 1);
ExPolygon resampled(simplified); ExPolygon resampled(input_expoly);
double resample_interval = scale_(0.5); double resample_interval = scale_(0.5);
for (size_t idx_contour = 0; idx_contour <= simplified.holes.size(); ++ idx_contour) { for (size_t idx_contour = 0; idx_contour <= input_expoly.holes.size(); ++ idx_contour) {
Polygon &poly = (idx_contour == 0) ? resampled.contour : resampled.holes[idx_contour - 1]; Polygon &poly = (idx_contour == 0) ? resampled.contour : resampled.holes[idx_contour - 1];
std::vector<ResampledPoint> resampled_point_parameters; std::vector<ResampledPoint> resampled_point_parameters;
poly.points = resample_polygon(poly.points, resample_interval, resampled_point_parameters); poly.points = resample_polygon(poly.points, resample_interval, resampled_point_parameters);
@ -628,8 +627,9 @@ ExPolygon elephant_foot_compensation(const ExPolygon &input, const Flow &exter
ExPolygons elephant_foot_compensation(const ExPolygons &input, const Flow &external_perimeter_flow, const double compensation) ExPolygons elephant_foot_compensation(const ExPolygons &input, const Flow &external_perimeter_flow, const double compensation)
{ {
ExPolygons out; ExPolygons out;
out.reserve(input.size()); ExPolygons simplified_exps = expolygons_simplify(input, SCALED_EPSILON);
for (const ExPolygon &expoly : input) out.reserve(simplified_exps.size());
for (const ExPolygon &expoly : simplified_exps)
out.emplace_back(elephant_foot_compensation(expoly, external_perimeter_flow, compensation)); out.emplace_back(elephant_foot_compensation(expoly, external_perimeter_flow, compensation));
return out; return out;
} }
@ -637,8 +637,9 @@ ExPolygons elephant_foot_compensation(const ExPolygons &input, const Flow &exter
ExPolygons elephant_foot_compensation(const ExPolygons &input, double min_contour_width, const double compensation) ExPolygons elephant_foot_compensation(const ExPolygons &input, double min_contour_width, const double compensation)
{ {
ExPolygons out; ExPolygons out;
out.reserve(input.size()); ExPolygons simplified_exps = expolygons_simplify(input, SCALED_EPSILON);
for (const ExPolygon &expoly : input) out.reserve(simplified_exps.size());
for (const ExPolygon &expoly : simplified_exps)
out.emplace_back(elephant_foot_compensation(expoly, min_contour_width, compensation)); out.emplace_back(elephant_foot_compensation(expoly, min_contour_width, compensation));
return out; return out;
} }

View File

@ -407,6 +407,19 @@ void PrintObject::make_perimeters(const AutoContourHolesCompensationParams &auto
BOOST_LOG_TRIVIAL(debug) << "Generating extra perimeters for region " << region_id << " in parallel - end"; BOOST_LOG_TRIVIAL(debug) << "Generating extra perimeters for region " << region_id << " in parallel - end";
} }
#if 0
{ // for debug
for (size_t layer_idx = 0; layer_idx < m_layers.size(); ++layer_idx) {
auto regions = m_layers[layer_idx]->regions();
for (size_t region_idx = 0; region_idx < regions.size(); ++region_idx) {
LayerRegion *layer_region = regions[region_idx];
std::string name = "before_make_perimeter_layer-" + std::to_string(layer_idx) + "-region-" + std::to_string(region_idx) + ".svg";
layer_region->slices.export_to_svg(debug_out_path(name.c_str()).c_str(), true);
}
}
}
#endif
BOOST_LOG_TRIVIAL(debug) << "Generating perimeters in parallel - start"; BOOST_LOG_TRIVIAL(debug) << "Generating perimeters in parallel - start";
tbb::parallel_for( tbb::parallel_for(
tbb::blocked_range<size_t>(0, m_layers.size()), tbb::blocked_range<size_t>(0, m_layers.size()),