diff options
author | Lukáš Hejl <hejl.lukas@gmail.com> | 2020-08-26 23:18:51 +0300 |
---|---|---|
committer | Lukáš Hejl <hejl.lukas@gmail.com> | 2020-08-26 23:18:51 +0300 |
commit | eaaff4e707e8321b7bc1b9e9151fb94a4befc3bd (patch) | |
tree | 1bb195479bee299481d8cee074674252384abfe0 /src/libslic3r/Fill | |
parent | 3ac16d9c9cd2d796db45c266964c507c423a7992 (diff) |
Generating polylines from octree
Diffstat (limited to 'src/libslic3r/Fill')
-rw-r--r-- | src/libslic3r/Fill/FillAdaptive.cpp | 57 | ||||
-rw-r--r-- | src/libslic3r/Fill/FillAdaptive.hpp | 7 |
2 files changed, 64 insertions, 0 deletions
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, |