From 20cd34a3a5ec3bf039876dfb6306740b65d4e236 Mon Sep 17 00:00:00 2001 From: bubnikv Date: Fri, 21 Oct 2016 18:56:55 +0200 Subject: [PATCH] Cubic infill. --- xs/src/libslic3r/Fill/FillBase.cpp | 1 + xs/src/libslic3r/Fill/FillBase.hpp | 2 +- xs/src/libslic3r/Fill/FillRectilinear2.cpp | 32 ++++++++++++++++------ xs/src/libslic3r/Fill/FillRectilinear2.hpp | 14 +++++++++- xs/src/libslic3r/PrintConfig.cpp | 2 ++ xs/src/libslic3r/PrintConfig.hpp | 3 +- 6 files changed, 43 insertions(+), 11 deletions(-) diff --git a/xs/src/libslic3r/Fill/FillBase.cpp b/xs/src/libslic3r/Fill/FillBase.cpp index ba3a5ee47..9043bcd83 100644 --- a/xs/src/libslic3r/Fill/FillBase.cpp +++ b/xs/src/libslic3r/Fill/FillBase.cpp @@ -25,6 +25,7 @@ Fill* Fill::new_from_type(const InfillPattern type) case ipLine: return new FillLine(); case ipGrid: return new FillGrid2(); case ipTriangles: return new FillTriangles(); + case ipCubic: return new FillCubic(); // case ipGrid: return new FillGrid(); case ipArchimedeanChords: return new FillArchimedeanChords(); case ipHilbertCurve: return new FillHilbertCurve(); diff --git a/xs/src/libslic3r/Fill/FillBase.hpp b/xs/src/libslic3r/Fill/FillBase.hpp index 8952c2c75..820a77814 100644 --- a/xs/src/libslic3r/Fill/FillBase.hpp +++ b/xs/src/libslic3r/Fill/FillBase.hpp @@ -39,7 +39,7 @@ class Fill public: // Index of the layer. size_t layer_id; - // Height of the layer, in unscaled coordinates + // Z coordinate of the top print surface, in unscaled coordinates coordf_t z; // in unscaled coordinates coordf_t spacing; diff --git a/xs/src/libslic3r/Fill/FillRectilinear2.cpp b/xs/src/libslic3r/Fill/FillRectilinear2.cpp index 5b37ddf84..bcebc5a00 100644 --- a/xs/src/libslic3r/Fill/FillRectilinear2.cpp +++ b/xs/src/libslic3r/Fill/FillRectilinear2.cpp @@ -751,7 +751,7 @@ enum DirectionMask DIR_BACKWARD = 2 }; -bool FillRectilinear2::fill_surface_by_lines(const Surface *surface, const FillParams ¶ms, float angleBase, Polylines &polylines_out) +bool FillRectilinear2::fill_surface_by_lines(const Surface *surface, const FillParams ¶ms, float angleBase, float pattern_shift, Polylines &polylines_out) { // At the end, only the new polylines will be rotated back. size_t n_polylines_out_initial = polylines_out.size(); @@ -791,10 +791,14 @@ bool FillRectilinear2::fill_surface_by_lines(const Surface *surface, const FillP } else { // extend bounding box so that our pattern will be aligned with other layers // Transform the reference point to the rotated coordinate system. + Point refpt = rotate_vector.second.rotated(- rotate_vector.first); + // _align_to_grid will not work correctly with positive pattern_shift. + coord_t pattern_shift_scaled = coord_t(scale_(pattern_shift)) % this->_line_spacing; + refpt.x -= (pattern_shift_scaled > 0) ? pattern_shift_scaled : (this->_line_spacing + pattern_shift_scaled); bounding_box.merge(_align_to_grid( bounding_box.min, Point(this->_line_spacing, this->_line_spacing), - rotate_vector.second.rotated(- rotate_vector.first))); + refpt)); } // Intersect a set of euqally spaced vertical lines wiht expolygon. @@ -1438,7 +1442,7 @@ bool FillRectilinear2::fill_surface_by_lines(const Surface *surface, const FillP Polylines FillRectilinear2::fill_surface(const Surface *surface, const FillParams ¶ms) { Polylines polylines_out; - if (! fill_surface_by_lines(surface, params, 0.f, polylines_out)) { + if (! fill_surface_by_lines(surface, params, 0.f, 0.f, polylines_out)) { printf("FillRectilinear2::fill_surface() failed to fill a region.\n"); } return polylines_out; @@ -1447,8 +1451,8 @@ Polylines FillRectilinear2::fill_surface(const Surface *surface, const FillParam Polylines FillGrid2::fill_surface(const Surface *surface, const FillParams ¶ms) { Polylines polylines_out; - if (! fill_surface_by_lines(surface, params, 0.f, polylines_out) || - ! fill_surface_by_lines(surface, params, float(M_PI / 2.), polylines_out)) { + if (! fill_surface_by_lines(surface, params, 0.f, 0.f, polylines_out) || + ! fill_surface_by_lines(surface, params, float(M_PI / 2.), 0.f, polylines_out)) { printf("FillGrid2::fill_surface() failed to fill a region.\n"); } return polylines_out; @@ -1457,12 +1461,24 @@ Polylines FillGrid2::fill_surface(const Surface *surface, const FillParams ¶ Polylines FillTriangles::fill_surface(const Surface *surface, const FillParams ¶ms) { Polylines polylines_out; - if (! fill_surface_by_lines(surface, params, 0.f, polylines_out) || - ! fill_surface_by_lines(surface, params, float(M_PI / 3.), polylines_out) || - ! fill_surface_by_lines(surface, params, float(2. * M_PI / 3.), polylines_out)) { + if (! fill_surface_by_lines(surface, params, 0.f, 0., polylines_out) || + ! fill_surface_by_lines(surface, params, float(M_PI / 3.), 0., polylines_out) || + ! fill_surface_by_lines(surface, params, float(2. * M_PI / 3.), 0., polylines_out)) { printf("FillTriangles::fill_surface() failed to fill a region.\n"); } return polylines_out; } +Polylines FillCubic::fill_surface(const Surface *surface, const FillParams ¶ms) +{ + Polylines polylines_out; + if (! fill_surface_by_lines(surface, params, 0.f, z, polylines_out) || + ! fill_surface_by_lines(surface, params, float(M_PI / 3.), -z, polylines_out) || + // Rotated by PI*2/3 + PI to achieve reverse sloping wall. + ! fill_surface_by_lines(surface, params, float(M_PI * 2. / 3.), z, polylines_out)) { + printf("FillCubic::fill_surface() failed to fill a region.\n"); + } + return polylines_out; +} + } // namespace Slic3r diff --git a/xs/src/libslic3r/Fill/FillRectilinear2.hpp b/xs/src/libslic3r/Fill/FillRectilinear2.hpp index dffa8921c..a82717bbe 100644 --- a/xs/src/libslic3r/Fill/FillRectilinear2.hpp +++ b/xs/src/libslic3r/Fill/FillRectilinear2.hpp @@ -16,7 +16,7 @@ public: virtual Polylines fill_surface(const Surface *surface, const FillParams ¶ms); protected: - bool fill_surface_by_lines(const Surface *surface, const FillParams ¶ms, float angleBase, Polylines &polylines_out); + bool fill_surface_by_lines(const Surface *surface, const FillParams ¶ms, float angleBase, float pattern_shift, Polylines &polylines_out); coord_t _min_spacing; coord_t _line_spacing; @@ -46,6 +46,18 @@ protected: virtual float _layer_angle(size_t idx) const { return 0.f; } }; +class FillCubic : public FillRectilinear2 +{ +public: + virtual ~FillCubic() {} + virtual Polylines fill_surface(const Surface *surface, const FillParams ¶ms); + +protected: + // The grid fill will keep the angle constant between the layers, see the implementation of Slic3r::Fill::Base. + virtual float _layer_angle(size_t idx) const { return 0.f; } +}; + + }; // namespace Slic3r #endif // slic3r_FillRectilinear2_hpp_ diff --git a/xs/src/libslic3r/PrintConfig.cpp b/xs/src/libslic3r/PrintConfig.cpp index bbbe52123..21a441a49 100644 --- a/xs/src/libslic3r/PrintConfig.cpp +++ b/xs/src/libslic3r/PrintConfig.cpp @@ -372,6 +372,7 @@ PrintConfigDef::PrintConfigDef() def->enum_values.push_back("rectilinear"); def->enum_values.push_back("grid"); def->enum_values.push_back("triangles"); + def->enum_values.push_back("cubic"); def->enum_values.push_back("line"); def->enum_values.push_back("concentric"); def->enum_values.push_back("honeycomb"); @@ -382,6 +383,7 @@ PrintConfigDef::PrintConfigDef() def->enum_labels.push_back("Rectilinear"); def->enum_labels.push_back("Grid"); def->enum_labels.push_back("Triangles"); + def->enum_labels.push_back("Cubic"); def->enum_labels.push_back("Line"); def->enum_labels.push_back("Concentric"); def->enum_labels.push_back("Honeycomb"); diff --git a/xs/src/libslic3r/PrintConfig.hpp b/xs/src/libslic3r/PrintConfig.hpp index 34dbe3645..55d34368d 100644 --- a/xs/src/libslic3r/PrintConfig.hpp +++ b/xs/src/libslic3r/PrintConfig.hpp @@ -30,7 +30,7 @@ enum GCodeFlavor { }; enum InfillPattern { - ipRectilinear, ipGrid, ipTriangles, ipLine, ipConcentric, ipHoneycomb, ip3DHoneycomb, + ipRectilinear, ipGrid, ipTriangles, ipCubic, ipLine, ipConcentric, ipHoneycomb, ip3DHoneycomb, ipHilbertCurve, ipArchimedeanChords, ipOctagramSpiral, }; @@ -59,6 +59,7 @@ template<> inline t_config_enum_values ConfigOptionEnum::get_enum keys_map["rectilinear"] = ipRectilinear; keys_map["grid"] = ipGrid; keys_map["triangles"] = ipTriangles; + keys_map["cubic"] = ipCubic; keys_map["line"] = ipLine; keys_map["concentric"] = ipConcentric; keys_map["honeycomb"] = ipHoneycomb;