Cubic infill.

This commit is contained in:
bubnikv 2016-10-21 18:56:55 +02:00
parent 1fb57e439e
commit 20cd34a3a5
6 changed files with 43 additions and 11 deletions

View File

@ -25,6 +25,7 @@ Fill* Fill::new_from_type(const InfillPattern type)
case ipLine: return new FillLine(); case ipLine: return new FillLine();
case ipGrid: return new FillGrid2(); case ipGrid: return new FillGrid2();
case ipTriangles: return new FillTriangles(); case ipTriangles: return new FillTriangles();
case ipCubic: return new FillCubic();
// case ipGrid: return new FillGrid(); // case ipGrid: return new FillGrid();
case ipArchimedeanChords: return new FillArchimedeanChords(); case ipArchimedeanChords: return new FillArchimedeanChords();
case ipHilbertCurve: return new FillHilbertCurve(); case ipHilbertCurve: return new FillHilbertCurve();

View File

@ -39,7 +39,7 @@ class Fill
public: public:
// Index of the layer. // Index of the layer.
size_t layer_id; size_t layer_id;
// Height of the layer, in unscaled coordinates // Z coordinate of the top print surface, in unscaled coordinates
coordf_t z; coordf_t z;
// in unscaled coordinates // in unscaled coordinates
coordf_t spacing; coordf_t spacing;

View File

@ -751,7 +751,7 @@ enum DirectionMask
DIR_BACKWARD = 2 DIR_BACKWARD = 2
}; };
bool FillRectilinear2::fill_surface_by_lines(const Surface *surface, const FillParams &params, float angleBase, Polylines &polylines_out) bool FillRectilinear2::fill_surface_by_lines(const Surface *surface, const FillParams &params, float angleBase, float pattern_shift, Polylines &polylines_out)
{ {
// At the end, only the new polylines will be rotated back. // At the end, only the new polylines will be rotated back.
size_t n_polylines_out_initial = polylines_out.size(); 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 { } else {
// extend bounding box so that our pattern will be aligned with other layers // extend bounding box so that our pattern will be aligned with other layers
// Transform the reference point to the rotated coordinate system. // 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.merge(_align_to_grid(
bounding_box.min, bounding_box.min,
Point(this->_line_spacing, this->_line_spacing), 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. // 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 &params) Polylines FillRectilinear2::fill_surface(const Surface *surface, const FillParams &params)
{ {
Polylines polylines_out; 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"); printf("FillRectilinear2::fill_surface() failed to fill a region.\n");
} }
return polylines_out; 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 &params) Polylines FillGrid2::fill_surface(const Surface *surface, const FillParams &params)
{ {
Polylines polylines_out; 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) ||
! fill_surface_by_lines(surface, params, float(M_PI / 2.), 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"); printf("FillGrid2::fill_surface() failed to fill a region.\n");
} }
return polylines_out; return polylines_out;
@ -1457,12 +1461,24 @@ Polylines FillGrid2::fill_surface(const Surface *surface, const FillParams &para
Polylines FillTriangles::fill_surface(const Surface *surface, const FillParams &params) Polylines FillTriangles::fill_surface(const Surface *surface, const FillParams &params)
{ {
Polylines polylines_out; Polylines polylines_out;
if (! fill_surface_by_lines(surface, params, 0.f, polylines_out) || if (! fill_surface_by_lines(surface, params, 0.f, 0., polylines_out) ||
! fill_surface_by_lines(surface, params, float(M_PI / 3.), 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.), 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"); printf("FillTriangles::fill_surface() failed to fill a region.\n");
} }
return polylines_out; return polylines_out;
} }
Polylines FillCubic::fill_surface(const Surface *surface, const FillParams &params)
{
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 } // namespace Slic3r

View File

@ -16,7 +16,7 @@ public:
virtual Polylines fill_surface(const Surface *surface, const FillParams &params); virtual Polylines fill_surface(const Surface *surface, const FillParams &params);
protected: protected:
bool fill_surface_by_lines(const Surface *surface, const FillParams &params, float angleBase, Polylines &polylines_out); bool fill_surface_by_lines(const Surface *surface, const FillParams &params, float angleBase, float pattern_shift, Polylines &polylines_out);
coord_t _min_spacing; coord_t _min_spacing;
coord_t _line_spacing; coord_t _line_spacing;
@ -46,6 +46,18 @@ protected:
virtual float _layer_angle(size_t idx) const { return 0.f; } 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 &params);
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 }; // namespace Slic3r
#endif // slic3r_FillRectilinear2_hpp_ #endif // slic3r_FillRectilinear2_hpp_

View File

@ -372,6 +372,7 @@ PrintConfigDef::PrintConfigDef()
def->enum_values.push_back("rectilinear"); def->enum_values.push_back("rectilinear");
def->enum_values.push_back("grid"); def->enum_values.push_back("grid");
def->enum_values.push_back("triangles"); def->enum_values.push_back("triangles");
def->enum_values.push_back("cubic");
def->enum_values.push_back("line"); def->enum_values.push_back("line");
def->enum_values.push_back("concentric"); def->enum_values.push_back("concentric");
def->enum_values.push_back("honeycomb"); def->enum_values.push_back("honeycomb");
@ -382,6 +383,7 @@ PrintConfigDef::PrintConfigDef()
def->enum_labels.push_back("Rectilinear"); def->enum_labels.push_back("Rectilinear");
def->enum_labels.push_back("Grid"); def->enum_labels.push_back("Grid");
def->enum_labels.push_back("Triangles"); def->enum_labels.push_back("Triangles");
def->enum_labels.push_back("Cubic");
def->enum_labels.push_back("Line"); def->enum_labels.push_back("Line");
def->enum_labels.push_back("Concentric"); def->enum_labels.push_back("Concentric");
def->enum_labels.push_back("Honeycomb"); def->enum_labels.push_back("Honeycomb");

View File

@ -30,7 +30,7 @@ enum GCodeFlavor {
}; };
enum InfillPattern { enum InfillPattern {
ipRectilinear, ipGrid, ipTriangles, ipLine, ipConcentric, ipHoneycomb, ip3DHoneycomb, ipRectilinear, ipGrid, ipTriangles, ipCubic, ipLine, ipConcentric, ipHoneycomb, ip3DHoneycomb,
ipHilbertCurve, ipArchimedeanChords, ipOctagramSpiral, ipHilbertCurve, ipArchimedeanChords, ipOctagramSpiral,
}; };
@ -59,6 +59,7 @@ template<> inline t_config_enum_values ConfigOptionEnum<InfillPattern>::get_enum
keys_map["rectilinear"] = ipRectilinear; keys_map["rectilinear"] = ipRectilinear;
keys_map["grid"] = ipGrid; keys_map["grid"] = ipGrid;
keys_map["triangles"] = ipTriangles; keys_map["triangles"] = ipTriangles;
keys_map["cubic"] = ipCubic;
keys_map["line"] = ipLine; keys_map["line"] = ipLine;
keys_map["concentric"] = ipConcentric; keys_map["concentric"] = ipConcentric;
keys_map["honeycomb"] = ipHoneycomb; keys_map["honeycomb"] = ipHoneycomb;