From eaaff4e707e8321b7bc1b9e9151fb94a4befc3bd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luk=C3=A1=C5=A1=20Hejl?= Date: Wed, 26 Aug 2020 22:18:51 +0200 Subject: [PATCH] Generating polylines from octree --- src/libslic3r/Fill/FillAdaptive.cpp | 57 +++++++++++++++++++++++++++++ src/libslic3r/Fill/FillAdaptive.hpp | 7 ++++ 2 files changed, 64 insertions(+) diff --git a/src/libslic3r/Fill/FillAdaptive.cpp b/src/libslic3r/Fill/FillAdaptive.cpp index ce779ad00..cac9c1c3b 100644 --- a/src/libslic3r/Fill/FillAdaptive.cpp +++ b/src/libslic3r/Fill/FillAdaptive.cpp @@ -15,7 +15,64 @@ void FillAdaptive::_fill_surface_single( ExPolygon &expolygon, Polylines &polylines_out) { + Polylines infill_polylines; + this->generate_polylines(this->adapt_fill_octree->root_cube, this->z, this->adapt_fill_octree->origin, infill_polylines); + // Crop all polylines + polylines_out = intersection_pl(infill_polylines, to_polygons(expolygon)); +} + +void FillAdaptive::generate_polylines( + FillAdaptive_Internal::Cube *cube, + double z_position, + const Vec3d &origin, + Polylines &polylines_out) +{ + using namespace FillAdaptive_Internal; + + if(cube == nullptr) + { + return; + } + + double z_diff = std::abs(z_position - cube->center.z()); + + if (z_diff > cube->properties.height / 2) + { + return; + } + + if (z_diff < cube->properties.line_z_distance) + { + Point from( + scale_((cube->properties.diagonal_length / 2) * (cube->properties.line_z_distance - z_diff) / cube->properties.line_z_distance), + scale_(cube->properties.line_xy_distance - ((z_position - (cube->center.z() - cube->properties.line_z_distance)) / sqrt(2)))); + Point to(-from.x(), from.y()); + // Relative to cube center + + float rotation_angle = Geometry::deg2rad(120.0); + + for (int dir_idx = 0; dir_idx < 3; dir_idx++) + { + Vec3d offset = cube->center - origin; + Point from_abs(from), to_abs(to); + + from_abs.x() += scale_(offset.x()); + from_abs.y() += scale_(offset.y()); + to_abs.x() += scale_(offset.x()); + to_abs.y() += scale_(offset.y()); + + polylines_out.push_back(Polyline(from_abs, to_abs)); + + from.rotate(rotation_angle); + to.rotate(rotation_angle); + } + } + + for(Cube *child : cube->children) + { + generate_polylines(child, z_position, origin, polylines_out); + } } FillAdaptive_Internal::Octree* FillAdaptive::build_octree( diff --git a/src/libslic3r/Fill/FillAdaptive.hpp b/src/libslic3r/Fill/FillAdaptive.hpp index 49c5276a9..9e1a196af 100644 --- a/src/libslic3r/Fill/FillAdaptive.hpp +++ b/src/libslic3r/Fill/FillAdaptive.hpp @@ -33,6 +33,11 @@ namespace FillAdaptive_Internal }; }; // namespace FillAdaptive_Internal +// +// Some of the algorithms used by class FillAdaptive were inspired by +// Cura Engine's class SubDivCube +// https://github.com/Ultimaker/CuraEngine/blob/master/src/infill/SubDivCube.h +// class FillAdaptive : public Fill { public: @@ -49,6 +54,8 @@ protected: virtual bool no_sort() const { return true; } + void generate_polylines(FillAdaptive_Internal::Cube *cube, double z_position, const Vec3d &origin, Polylines &polylines_out); + public: static FillAdaptive_Internal::Octree* build_octree( TriangleMesh &triangleMesh,