fixing bridging angle, avoiding too small areas, fixing final area rotation

This commit is contained in:
PavelMikus 2023-02-14 13:08:24 +01:00
parent df20302eef
commit 9f5f03099e

View File

@ -1597,6 +1597,12 @@ void PrintObject::bridge_over_infill()
for (size_t region_idx : regions_to_check) {
const LayerRegion *region = layer->get_region(region_idx);
auto region_internal_solids = region->fill_surfaces().filter_by_type(stInternalSolid);
//remove very small solid infills, usually not worth it and many of them may not even contain extrusions in the end.
void(std::remove_if(region_internal_solids.begin(), region_internal_solids.end(), [region](const Surface *s) {
float min_width = float(region->bridging_flow(frSolidInfill).scaled_width()) * 3.f;
return opening_ex({s->expolygon}, min_width).empty();
}));
if (!region_internal_solids.empty()) {
max_bridge_flow_height[&slice] = std::max(max_bridge_flow_height[&slice],
region->bridging_flow(frSolidInfill).height());
@ -1726,8 +1732,12 @@ void PrintObject::bridge_over_infill()
for (int i = 0; i < lines_count; ++i) {
Point a = (start + v * (i * step_size)).cast<coord_t>();
auto [distance, index, p] = lines_tree.distance_from_lines_extra<false>(a);
const Line &l = lines_tree.get_line(index);
directions_with_distances.emplace_back(PI - l.direction(), distance);
double angle = lines_tree.get_line(index).orientation();
if (angle > PI) {
angle -= PI;
}
angle += PI;
directions_with_distances.emplace_back(angle, distance);
}
}
}
@ -1770,9 +1780,10 @@ void PrintObject::bridge_over_infill()
};
Polygons expanded_bridged_area{};
double aligning_angle = -bridging_angle + PI;
{
polygons_rotate(bridged_area, bridging_angle);
lines_rotate(anchors_and_walls, cos(bridging_angle), sin(bridging_angle));
polygons_rotate(bridged_area, aligning_angle);
lines_rotate(anchors_and_walls, cos(aligning_angle), sin(aligning_angle));
BoundingBox bb_x = get_extents(bridged_area);
BoundingBox bb_y = get_extents(anchors_and_walls);
@ -1903,15 +1914,22 @@ void PrintObject::bridge_over_infill()
for (const auto &s : polygon_sections) {
l.insert(l.end(), s.begin(), s.end());
}
debug_draw("reconstructed" + std::to_string(lidx), l, anchors_and_walls_tree.get_lines(), to_lines(expanded_bridged_area),
bridged_area_tree.get_lines());
debug_draw("reconstructed" + std::to_string(lidx), l, anchors_and_walls_tree.get_lines(),
to_lines(expanded_bridged_area), bridged_area_tree.get_lines());
#endif
}
polygons_rotate(expanded_bridged_area, -aligning_angle);
expanded_bridged_area = intersection(expanded_bridged_area, max_area);
expand_area = diff(expand_area, expanded_bridged_area);
expanded_briding_surfaces[candidates.first].emplace_back(candidate, expanded_bridged_area, surface_to_region[candidate],
bridging_angle);
#ifdef DEBUG_BRIDGE_OVER_INFILL
debug_draw("cadidate_added" + std::to_string(lidx), to_lines(expanded_bridged_area), to_lines(bridged_area),
to_lines(max_area), to_lines(expand_area));
#endif
}
}
}
@ -1919,8 +1937,8 @@ void PrintObject::bridge_over_infill()
BOOST_LOG_TRIVIAL(info) << "Bridge over infill - Directions and expanded surfaces computed" << log_memory_info();
tbb::parallel_for(tbb::blocked_range<size_t>(0, this->layers().size()),
[po = this, &expanded_briding_surfaces](tbb::blocked_range<size_t> r) {
tbb::parallel_for(tbb::blocked_range<size_t>(0, this->layers().size()), [po = this,
&expanded_briding_surfaces](tbb::blocked_range<size_t> r) {
for (size_t lidx = r.begin(); lidx < r.end(); lidx++) {
Layer *layer = po->get_layer(lidx);
@ -1963,8 +1981,8 @@ void PrintObject::bridge_over_infill()
}
}
}
region->m_fill_surfaces.surfaces.insert(region->m_fill_surfaces.surfaces.end(),
new_surfaces.begin(), new_surfaces.end());
region->m_fill_surfaces.surfaces.insert(region->m_fill_surfaces.surfaces.end(), new_surfaces.begin(),
new_surfaces.end());
std::remove_if(region->m_fill_surfaces.begin(), region->m_fill_surfaces.end(),
[](const Surface &s) { return s.empty(); });
}