Skip to content

Commit

Permalink
Merge cf2ceec into 21eb603
Browse files Browse the repository at this point in the history
  • Loading branch information
supermerill authored Dec 3, 2018
2 parents 21eb603 + cf2ceec commit 0ddfef6
Show file tree
Hide file tree
Showing 25 changed files with 581 additions and 76 deletions.
14 changes: 9 additions & 5 deletions lib/Slic3r/GUI/Plater/2DToolpaths.pm
Original file line number Diff line number Diff line change
Expand Up @@ -456,11 +456,15 @@ sub Render {
sub _draw {
my ($self, $object, $print_z, $path) = @_;

my @paths = $path->isa('Slic3r::ExtrusionLoop')
? @$path
: ($path);

$self->_draw_path($object, $print_z, $_) for @paths;
if ($path->isa('Slic3r::ExtrusionPath::Collection')) {
$self->_draw($object, $print_z, $_) for @{$path};
}else{
my @paths = ($path->isa('Slic3r::ExtrusionLoop') || $path->isa('Slic3r::ExtrusionMultiPath'))
? @$path
: ($path);

$self->_draw_path($object, $print_z, $_) for @paths;
}
}

sub _draw_path {
Expand Down
3 changes: 2 additions & 1 deletion lib/Slic3r/GUI/PresetEditor.pm
Original file line number Diff line number Diff line change
Expand Up @@ -473,7 +473,7 @@ sub options {
extrusion_width first_layer_extrusion_width perimeter_extrusion_width
external_perimeter_extrusion_width infill_extrusion_width solid_infill_extrusion_width
top_infill_extrusion_width support_material_extrusion_width
support_material_interface_extrusion_width infill_overlap bridge_flow_ratio
support_material_interface_extrusion_width infill_overlap bridge_flow_ratio over_bridge_flow_ratio
xy_size_compensation resolution shortcuts compatible_printers
print_settings_id
)
Expand Down Expand Up @@ -702,6 +702,7 @@ sub build {
{
my $optgroup = $page->new_optgroup('Flow');
$optgroup->append_single_option_line('bridge_flow_ratio');
$optgroup->append_single_option_line('over_bridge_flow_ratio');
}
{
my $optgroup = $page->new_optgroup('Other');
Expand Down
17 changes: 6 additions & 11 deletions lib/Slic3r/Print/GCode.pm
Original file line number Diff line number Diff line change
Expand Up @@ -632,27 +632,27 @@ sub process_layer {
}

# process infill
# $layerm->fills is a collection of ExtrusionPath::Collection objects, each one containing
# the ExtrusionPath objects of a certain infill "group" (also called "surface"
# $layerm->fills is a collection of ExtrusionEntity::Collection objects, each one containing
# the ExtrusionEntity objects of a certain infill "group" (also called "surface"
# throughout the code). We can redefine the order of such Collections but we have to
# do each one completely at once.
foreach my $fill (@{$layerm->fills}) {
next if $fill->empty; # this shouldn't happen but first_point() would fail

# init by_extruder item only if we actually use the extruder
my $extruder_id = $fill->[0]->is_solid_infill
my $extruder_id = $fill->is_solid_infill()
? $region->config->solid_infill_extruder-1
: $region->config->infill_extruder-1;

$by_extruder{$extruder_id} //= [];

# $fill is an ExtrusionPath::Collection object
# $fill is an ExtrusionEntity::Collection object (ExtrusionEntityEollection)
for my $i (0 .. $n_slices) {
if ($i == $n_slices
|| $point_inside_surface->($i, $fill->first_point)) {
$by_extruder{$extruder_id}[$i] //= { infill => {} };
$by_extruder{$extruder_id}[$i]{infill}{$region_id} //= [];
push @{ $by_extruder{$extruder_id}[$i]{infill}{$region_id} }, $fill;
push @{ $by_extruder{$extruder_id}[$i]{infill}{$region_id} }, $fill->flatten_if_sortable();
last;
}
}
Expand Down Expand Up @@ -730,12 +730,7 @@ sub _extrude_infill {

my $collection = Slic3r::ExtrusionPath::Collection->new(@{ $entities_by_region->{$region_id} });
for my $fill (@{$collection->chained_path_from($self->_gcodegen->last_pos, 0)}) {
if ($fill->isa('Slic3r::ExtrusionPath::Collection')) {
$gcode .= $self->_gcodegen->extrude($_, 'infill', -1)
for @{$fill->chained_path_from($self->_gcodegen->last_pos, 0)};
} else {
$gcode .= $self->_gcodegen->extrude($fill, 'infill', -1) ;
}
$gcode .= $self->_gcodegen->extrude($fill, 'infill', -1) ;
}
}
return $gcode;
Expand Down
1 change: 1 addition & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,7 @@ add_library(libslic3r STATIC
${LIBDIR}/libslic3r/Fill/FillPlanePath.cpp
${LIBDIR}/libslic3r/Fill/FillRectilinear.cpp
${LIBDIR}/libslic3r/Fill/FillGyroid.cpp
${LIBDIR}/libslic3r/Fill/FillSmooth.cpp
${LIBDIR}/libslic3r/Flow.cpp
${LIBDIR}/libslic3r/GCode.cpp
${LIBDIR}/libslic3r/PrintGCode.cpp
Expand Down
4 changes: 2 additions & 2 deletions xs/src/libslic3r/ExtrusionEntity.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ class ExtrusionPath : public ExtrusionEntity
|| this->role == erSolidInfill
|| this->role == erTopSolidInfill;
};
bool is_solid_infill() const {
virtual bool is_solid_infill() const {
return this->role == erBridgeInfill
|| this->role == erSolidInfill
|| this->role == erTopSolidInfill;
Expand Down Expand Up @@ -158,7 +158,7 @@ class ExtrusionLoop : public ExtrusionEntity
|| this->paths.front().role == erSolidInfill
|| this->paths.front().role == erTopSolidInfill;
};
bool is_solid_infill() const {
virtual bool is_solid_infill() const {
return this->paths.front().role == erBridgeInfill
|| this->paths.front().role == erSolidInfill
|| this->paths.front().role == erTopSolidInfill;
Expand Down
47 changes: 46 additions & 1 deletion xs/src/libslic3r/ExtrusionEntityCollection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ ExtrusionEntityCollection::reverse()
for (ExtrusionEntitiesPtr::iterator it = this->entities.begin(); it != this->entities.end(); ++it) {
// Don't reverse it if it's a loop, as it doesn't change anything in terms of elements ordering
// and caller might rely on winding order
if (!(*it)->is_loop()) (*it)->reverse();
if (!(*it)->is_loop() && (*it)->can_reverse()) (*it)->reverse();
}
std::reverse(this->entities.begin(), this->entities.end());
}
Expand Down Expand Up @@ -242,6 +242,45 @@ ExtrusionEntityCollection::flatten() const
return coll;
}

/* Returns a vector of chained (new) pointers to all non-collection items contained in this one */
void
ExtrusionEntityCollection::flatten_if_sortable(ExtrusionEntityCollection* retval) const
{
if (no_sort){
ExtrusionEntityCollection *unsortable = new ExtrusionEntityCollection(*this);
retval->append(*unsortable);
unsortable->entities.clear();
for (ExtrusionEntitiesPtr::const_iterator it = this->entities.begin(); it != this->entities.end(); ++it) {
if ((*it)->is_collection()) {
ExtrusionEntityCollection* collection = dynamic_cast<ExtrusionEntityCollection*>(*it);
collection->flatten_if_sortable(unsortable);
}
else {
unsortable->append(**it);
}
}
}
else{
for (ExtrusionEntitiesPtr::const_iterator it = this->entities.begin(); it != this->entities.end(); ++it) {
if ((*it)->is_collection()) {
ExtrusionEntityCollection* collection = dynamic_cast<ExtrusionEntityCollection*>(*it);
retval->append(collection->flatten_if_sortable().entities);
}
else {
retval->append(**it);
}
}
}
}

ExtrusionEntityCollection
ExtrusionEntityCollection::flatten_if_sortable() const
{
ExtrusionEntityCollection coll;
this->flatten_if_sortable(&coll);
return coll;
}

double
ExtrusionEntityCollection::min_mm3_per_mm() const
{
Expand All @@ -257,4 +296,10 @@ ExtrusionEntityCollection::min_mm3_per_mm() const
return min_mm3_per_mm;
}

bool
ExtrusionEntityCollection::is_solid_infill() const
{
return entities.empty()?false:entities.front()->is_solid_infill();
};

}
6 changes: 3 additions & 3 deletions xs/src/libslic3r/ExtrusionEntityCollection.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,14 +64,14 @@ class ExtrusionEntityCollection : public ExtrusionEntity
/// Returns a flattened copy of this ExtrusionEntityCollection. That is, all of the items in its entities vector are not collections.
/// You should be iterating over flatten().entities if you are interested in the underlying ExtrusionEntities (and don't care about hierarchy).
ExtrusionEntityCollection flatten() const;


void flatten_if_sortable(ExtrusionEntityCollection* retval) const;
ExtrusionEntityCollection flatten_if_sortable() const;
double min_mm3_per_mm() const;
Polyline as_polyline() const {
CONFESS("Calling as_polyline() on a ExtrusionEntityCollection");
return Polyline();
};

virtual bool is_solid_infill() const;
ExtrusionEntitiesPtr::iterator begin() { return entities.begin(); }
ExtrusionEntitiesPtr::iterator end() { return entities.end(); }
ExtrusionEntitiesPtr::const_iterator begin() const { return entities.cbegin(); }
Expand Down
50 changes: 50 additions & 0 deletions xs/src/libslic3r/Fill/Fill.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include "../Geometry.hpp"
#include "../Surface.hpp"
#include "../PrintConfig.hpp"
#include "../ExtrusionEntityCollection.hpp"

#include "Fill.hpp"
#include "FillConcentric.hpp"
Expand All @@ -14,6 +15,8 @@
#include "FillGyroid.hpp"
#include "FillPlanePath.hpp"
#include "FillRectilinear.hpp"
#include "FillSmooth.hpp"


namespace Slic3r {

Expand All @@ -29,6 +32,7 @@ Fill::new_from_type(const InfillPattern type)
case ipRectilinear: return new FillRectilinear();
case ipAlignedRectilinear: return new FillAlignedRectilinear();
case ipGrid: return new FillGrid();
case ipSmooth: return new FillSmooth();

case ipTriangles: return new FillTriangles();
case ipStars: return new FillStars();
Expand Down Expand Up @@ -110,4 +114,50 @@ Fill::_infill_direction(const Surface &surface) const
return direction_t(out_angle, out_shift);
}

void
Fill::fill_surface_extrusion(const Surface &surface, const Flow &flow, ExtrusionEntitiesPtr &out, const ExtrusionRole &role)
{
//call fill_surface
Polylines polylines = this->fill_surface(surface);
if (polylines.empty())
return;

// calculate actual flow from spacing (which might have been adjusted by the infill
// pattern generator)
Flow goodFlow = flow;
if (density == 1) {
// if we used the internal flow we're not doing a solid infill
// so we can safely ignore the slight variation that might have
// been applied to f->spacing()
} else {
goodFlow = Flow::new_from_spacing(spacing(), flow.nozzle_diameter, flow.height, flow.bridge || use_bridge_flow());
}

// Save into layer.
ExtrusionEntityCollection *eec = new ExtrusionEntityCollection();
/// pass the no_sort attribute to the extrusion path
eec->no_sort = this->no_sort();
/// add it into the collection
out.push_back(eec);
/// get the role
ExtrusionRole good_role = role;
if(good_role == erNone){
if (flow.bridge) {
good_role = erBridgeInfill;
} else if (surface.is_solid()) {
good_role = (surface.is_top()) ? erTopSolidInfill : erSolidInfill;
} else {
good_role = erInternalInfill;
}
}
/// push the path
ExtrusionPath templ(good_role);
templ.mm3_per_mm = goodFlow.mm3_per_mm();
templ.width = goodFlow.width;
templ.height = goodFlow.height;

eec->append(STDMOVE(polylines), templ);

}

} // namespace Slic3r
13 changes: 10 additions & 3 deletions xs/src/libslic3r/Fill/Fill.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include "../ExPolygon.hpp"
#include "../Polyline.hpp"
#include "../PrintConfig.hpp"
#include "../Flow.hpp"

namespace Slic3r {

Expand Down Expand Up @@ -77,7 +78,12 @@ class Fill
/// Can this pattern be used for solid infill?
virtual bool can_solid() const { return false; };

/// Perform the fill.

/// Perform the fill (call fill_surface)
virtual void fill_surface_extrusion(const Surface &surface, const Flow &flow,
ExtrusionEntitiesPtr &out, const ExtrusionRole &role);

/// perform the fill (called by fill_surface_extrusion, call _fill_surface_single)
virtual Polylines fill_surface(const Surface &surface);

coordf_t spacing() const { return this->_spacing; };
Expand All @@ -102,8 +108,9 @@ class Fill
{};

typedef std::pair<float, Point> direction_t;

/// The expolygon may be modified by the method to avoid a copy.


/// The expolygon may be modified by the method to avoid a copy. (called by fill_surface)
virtual void _fill_surface_single(
unsigned int thickness_layers,
const direction_t &direction,
Expand Down
2 changes: 1 addition & 1 deletion xs/src/libslic3r/Fill/FillRectilinear.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ FillRectilinear::_fill_single_direction(ExPolygon expolygon,
// rotate polygons so that we can work with vertical lines here
expolygon.rotate(-direction.first);

assert(this->density > 0.0001f && this->density <= 1.f);
assert(this->density > 0.0001f);
const coord_t min_spacing = scale_(this->min_spacing);
coord_t line_spacing = (double) min_spacing / this->density;

Expand Down
Loading

0 comments on commit 0ddfef6

Please sign in to comment.