From 508ba0444cc4af83c34214325a4d6cad83b8be3d Mon Sep 17 00:00:00 2001 From: sunsets <845944018@qq.com> Date: Wed, 8 May 2024 13:37:23 +0800 Subject: [PATCH] Optimized exclusion region --- src/libslic3r/BoundingBox.hpp | 24 ++++++++++++++++++++++- src/libslic3r/BuildVolume.cpp | 36 ++++++++++++++++++----------------- 2 files changed, 42 insertions(+), 18 deletions(-) diff --git a/src/libslic3r/BoundingBox.hpp b/src/libslic3r/BoundingBox.hpp index db5c6fe..b0bb997 100644 --- a/src/libslic3r/BoundingBox.hpp +++ b/src/libslic3r/BoundingBox.hpp @@ -31,7 +31,29 @@ public: : BoundingBoxBase(points.begin(), points.end()) {} - void reset() { this->defined = false; this->min = PointType::Zero(); this->max = PointType::Zero(); } + void reset() + { + this->defined = false; + this->min = PointType::Zero(); + this->max = PointType::Zero(); + } + // B66 + Polygon polygon(bool is_scaled = false) const + { + Polygon polygon; + polygon.points.clear(); + polygon.points.resize(4); + double scale_factor = 1 / (is_scaled ? SCALING_FACTOR : 1); + polygon.points[0](0) = this->min(0) * scale_factor; + polygon.points[0](1) = this->min(1) * scale_factor; + polygon.points[1](0) = this->max(0) * scale_factor; + polygon.points[1](1) = this->min(1) * scale_factor; + polygon.points[2](0) = this->max(0) * scale_factor; + polygon.points[2](1) = this->max(1) * scale_factor; + polygon.points[3](0) = this->min(0) * scale_factor; + polygon.points[3](1) = this->max(1) * scale_factor; + return polygon; + }; void merge(const PointType &point); void merge(const PointsType &points); void merge(const BoundingBoxBase &bb); diff --git a/src/libslic3r/BuildVolume.cpp b/src/libslic3r/BuildVolume.cpp index 397f4b5..946c698 100644 --- a/src/libslic3r/BuildVolume.cpp +++ b/src/libslic3r/BuildVolume.cpp @@ -339,6 +339,7 @@ BuildVolume::ObjectState BuildVolume::volume_state_bbox(const BoundingBoxf3& vol else if (tem_build_volume.intersects(volume_bbox)) { is_contain = false; is_intersect = true; + break; } } if (m_max_print_height == 0.0) @@ -369,32 +370,33 @@ bool BuildVolume::all_paths_inside(const GCodeProcessorResult& paths, const Boun build_volume.max.z() = std::numeric_limits::max(); if (ignore_bottom) build_volume.min.z() = -std::numeric_limits::max(); - std::vector> exclude_build_volume; + // B66 + Points pts; + for (const GCodeProcessorResult::MoveVertex &move : paths.moves) { + if (move.type == EMoveType::Extrude && move.extrusion_role != GCodeExtrusionRole::Custom && move.width != 0.0f && + move.height != 0.0f) + pts.emplace_back(Point(scale_(move.position.x()), scale_(move.position.y()))); + } + + if ((build_volume.contains(paths_bbox))) { + if (m_exclude_bed_shape.size() > 0) { + Slic3r::Polygon convex_hull_2d = Slic3r::Geometry::convex_hull(std::move(pts)); for (int i = 1; i < m_exclude_bed_shape.size(); i += 7) { std::vector tem_exclude_bed_shap; - for (int j = 1; j < 5; j++) + for (int j = 1; j < 6; j++) tem_exclude_bed_shap.push_back(m_exclude_bed_shape[i + j]); BoundingBoxf tem_bboxf = get_extents(tem_exclude_bed_shap); auto tem_exclude_bboxf = BoundingBoxf3{to_3d(tem_bboxf.min, 0.), to_3d(tem_bboxf.max, m_max_print_height)}; - BoundingBox3Base tem_build_volume = tem_exclude_bboxf.inflated(SceneEpsilon); - exclude_build_volume.push_back(tem_build_volume); - } - - bool is_contain = false; - bool is_intersect = false; - - for (const auto &tem_build_volume : exclude_build_volume) { - if (tem_build_volume.contains(paths_bbox)) { - is_contain = true; - is_intersect = false; + Slic3r::Polygon p = tem_exclude_bboxf.polygon(true); // instance convex hull is scaled, so we need to scale here + if (intersection({p}, {convex_hull_2d}).empty() == false) { + return false; break; - } else if (tem_build_volume.intersects(paths_bbox)) { - is_contain = false; - is_intersect = true; + } + } } } - return (build_volume.contains(paths_bbox) && !is_contain && !is_intersect); + return build_volume.contains(paths_bbox); } case Type::Circle: {