Dense sparse infill

(also a bit of cleaning)
This commit is contained in:
supermerilll 2018-07-01 18:58:24 +02:00 committed by supermerill
parent d21c33e9b5
commit 3de81fc960
8 changed files with 217 additions and 132 deletions

View File

@ -164,8 +164,15 @@ void make_fill(LayerRegion &layerm, ExtrusionEntityCollection &out)
fill_pattern = (surface.is_external() && ! is_bridge) ?
(surface.is_top() ? layerm.region()->config.top_fill_pattern.value : layerm.region()->config.bottom_fill_pattern.value) :
ipRectilinear;
} else if (density <= 0)
} else {
if (layerm.region()->config.infill_dense_layers.getInt() > 0
&& surface.maxNbLayersOnTop < layerm.region()->config.infill_dense_layers.getInt() + layerm.region()->config.top_solid_layers.getInt()
&& surface.maxNbLayersOnTop >= layerm.region()->config.top_solid_layers.getInt()){
density = layerm.region()->config.infill_dense_density.getFloat();
}
if (density <= 0)
continue;
}
// get filler object
std::unique_ptr<Fill> f = std::unique_ptr<Fill>(Fill::new_from_type(fill_pattern));
@ -230,7 +237,6 @@ void make_fill(LayerRegion &layerm, ExtrusionEntityCollection &out)
params.dont_adjust = false;
params.fill_exactly = layerm.region()->config.enforce_full_fill_volume.getBool();
// calculate actual flow from spacing (which might have been adjusted by the infill
// pattern generator)
if (using_internal_flow) {

View File

@ -205,6 +205,7 @@ public:
void _make_perimeters();
void _infill();
void clip_fill_surfaces();
void count_distance_top();
void discover_horizontal_shells();
void combine_infill();
void _generate_support_material();

View File

@ -827,6 +827,53 @@ PrintConfigDef::PrintConfigDef()
def->min = 1;
def->default_value = new ConfigOptionInt(1);
def = this->add("infill_dense_layers", coInt);
def->label = L("Number of dense layers");
def->category = L("Infill");
def->tooltip = L("Set the number of denser infill layer you want between the normal sparse infill and the top layers. 0 to disable");
def->sidetext = L("layers");
def->cli = "infill-dense-layers=i";
def->min = 0;
def->default_value = new ConfigOptionInt(0);
def = this->add("infill_dense_density", coPercent);
def->gui_type = "f_enum_open";
def->gui_flags = "show_value";
def->label = L("Dense fill density");
def->category = L("Infill");
def->tooltip = L("Density of the dense internal infill, expressed in the range 0% - 100%.");
def->sidetext = L("%");
def->cli = "infill-dense-density=s";
def->min = 0;
def->max = 100;
def->enum_values.push_back("0");
def->enum_values.push_back("4");
def->enum_values.push_back("5.5");
def->enum_values.push_back("7.5");
def->enum_values.push_back("10");
def->enum_values.push_back("13");
def->enum_values.push_back("18");
def->enum_values.push_back("23");
def->enum_values.push_back("31");
def->enum_values.push_back("42");
def->enum_values.push_back("55");
def->enum_values.push_back("75");
def->enum_values.push_back("100");
def->enum_labels.push_back("0");
def->enum_labels.push_back("4");
def->enum_labels.push_back("5.5");
def->enum_labels.push_back("7.5");
def->enum_labels.push_back("10");
def->enum_labels.push_back("13");
def->enum_labels.push_back("18");
def->enum_labels.push_back("23");
def->enum_labels.push_back("31");
def->enum_labels.push_back("42");
def->enum_labels.push_back("55");
def->enum_labels.push_back("75");
def->enum_labels.push_back("100");
def->default_value = new ConfigOptionPercent(42);
def = this->add("infill_extruder", coInt);
def->label = L("Infill extruder");
def->category = L("Extruders");

View File

@ -407,6 +407,8 @@ public:
ConfigOptionInt infill_every_layers;
ConfigOptionFloatOrPercent infill_overlap;
ConfigOptionFloat infill_speed;
ConfigOptionInt infill_dense_layers;
ConfigOptionPercent infill_dense_density;
ConfigOptionBool overhangs;
ConfigOptionInt perimeter_extruder;
ConfigOptionFloatOrPercent perimeter_extrusion_width;
@ -450,6 +452,8 @@ protected:
OPT_PTR(infill_every_layers);
OPT_PTR(infill_overlap);
OPT_PTR(infill_speed);
OPT_PTR(infill_dense_layers);
OPT_PTR(infill_dense_density);
OPT_PTR(overhangs);
OPT_PTR(perimeter_extruder);
OPT_PTR(perimeter_extrusion_width);

View File

@ -189,6 +189,8 @@ bool PrintObject::invalidate_state_by_config_options(const std::vector<t_config_
|| opt_key == "infill_only_where_needed"
|| opt_key == "infill_every_layers"
|| opt_key == "solid_infill_every_layers"
|| opt_key == "infill_dense_layers"
|| opt_key == "infill_dense_density"
|| opt_key == "bottom_solid_layers"
|| opt_key == "top_solid_layers"
|| opt_key == "solid_infill_below_area"
@ -374,6 +376,9 @@ void PrintObject::_prepare_infill()
// combine fill surfaces to honor the "infill every N layers" option
this->combine_infill();
// count the distance from the nearest top surface, to allow to use denser infill
// if neded and if infill_dense_layers is positive.
this->count_distance_top();
#ifdef SLIC3R_DEBUG_SLICE_PROCESSING
for (size_t region_id = 0; region_id < this->print()->regions.size(); ++ region_id) {
@ -390,6 +395,38 @@ void PrintObject::_prepare_infill()
#endif /* SLIC3R_DEBUG_SLICE_PROCESSING */
}
void PrintObject::count_distance_top(){
for (int idx_region = 0; idx_region < this->_print->regions.size(); ++idx_region) {
//count how many surface there are on each one
LayerRegion *previousOne = NULL;
if (this->layers.size() > 1) previousOne = this->layers[this->layers.size() - 1]->get_region(idx_region);
if (previousOne != NULL && previousOne->region()->config.infill_dense_layers.getInt() > 0){
for (int idx_layer = this->layers.size() - 2; idx_layer >= 0; --idx_layer){
LayerRegion *layerm = this->layers[idx_layer]->get_region(idx_region);
for (Surface &surf : layerm->fill_surfaces.surfaces){
if (!surf.is_top()){
surf.maxNbLayersOnTop = 65000;
//find the surface which intersect with the smalle maxNb possible
for (Surface &upp : previousOne->fill_surfaces.surfaces){
// i'm using that because the result is better & different than
// upp.expolygon.overlaps(surf.expolygon), surf.expolygon.overlaps(upp.expolygon)
if (intersection_ex(surf, upp).size() > 0){
surf.maxNbLayersOnTop = std::min(surf.maxNbLayersOnTop, (unsigned short)(upp.maxNbLayersOnTop + 1));
}
}
}else{
surf.maxNbLayersOnTop = 0;
}
}
previousOne = layerm;
}
}
}
}
// This function analyzes slices of a region (SurfaceCollection slices).
// Each region slice (instance of Surface) is analyzed, whether it is supported or whether it is the top surface.
// Initially all slices are of type stInternal.
@ -487,7 +524,6 @@ void PrintObject::detect_surfaces_type()
diff(layerm_slices_surfaces, to_polygons(lower_layer->slices), true),
-offset, offset),
surface_type_bottom_other);
// if user requested internal shells, we need to identify surfaces
// lying on other slices not belonging to this region
if (interface_shells) {
@ -504,7 +540,6 @@ void PrintObject::detect_surfaces_type()
stBottom);
}
#endif
} else {
// if no lower layer, all surfaces of this one are solid
// we clone surfaces because we're going to clear the slices collection
@ -513,22 +548,6 @@ void PrintObject::detect_surfaces_type()
surface.surface_type = surface_type_bottom_1st;
}
// Any surface lying on the void is a true bottom bridge (an overhang)
// and we have to conpensate if we are over that
// Surfaces bottomOverBridge;
// if(under_lower_layer){
// surfaces_append(
// bottomOverBridge,
// offset2_ex(
// diff(layerm_slices_surfaces, to_polygons(under_lower_layer->slices), true),
// -offset, offset),
// stInternalOverBridge);
// std::cout<<idx_layer<<" under_lower_layer "<<under_lower_layer->slices.expolygons.size()<<" > "<<bottomOverBridge.size()<<", bot="<<bottom.size()<<"\n";
// for(int i=0;i<under_lower_layer->slices.expolygons.size();i++) std::cout<<" area of under_lower_layer "<<under_lower_layer->slices.expolygons[i].area()<<"\n";
// for(int i=0;i<bottom.size();i++) std::cout<<" area of bottom "<<bottom[i].area()<<"\n";
// for(int i=0;i<bottomOverBridge.size();i++) std::cout<<" area of overbridge "<<bottomOverBridge[i].area()<<"\n";
// }
// now, if the object contained a thin membrane, we could have overlapping bottom
// and top surfaces; let's do an intersection to discover them and consider them
// as bottom surfaces (to allow for bridge detection)
@ -563,12 +582,6 @@ void PrintObject::detect_surfaces_type()
{
Polygons topbottom = to_polygons(top);
polygons_append(topbottom, to_polygons(bottom));
// ExPolygons overExPolygons = diff_ex(to_polygons(bottomOverBridge), topbottom, false);
// surfaces_append(surfaces_out,
// overExPolygons,
// stInternalOverBridge);
// for(int i=0;i<overExPolygons.size();i++) std::cout<<" area of overExPolygons "<<overExPolygons[i].area()<<"\n";
// polygons_append(topbottom, to_polygons(bottomOverBridge));
surfaces_append(surfaces_out,
diff_ex(layerm_slices_surfaces, topbottom, false),
stInternal);

View File

@ -41,35 +41,42 @@ public:
unsigned short thickness_layers; // in layers
double bridge_angle; // in radians, ccw, 0 = East, only 0+ (negative means undefined)
unsigned short extra_perimeters;
unsigned short maxNbLayersOnTop;
Surface(const Slic3r::Surface &rhs)
: surface_type(rhs.surface_type), expolygon(rhs.expolygon),
thickness(rhs.thickness), thickness_layers(rhs.thickness_layers),
bridge_angle(rhs.bridge_angle), extra_perimeters(rhs.extra_perimeters)
bridge_angle(rhs.bridge_angle), extra_perimeters(rhs.extra_perimeters),
maxNbLayersOnTop(rhs.maxNbLayersOnTop)
{};
Surface(SurfaceType _surface_type, const ExPolygon &_expolygon)
: surface_type(_surface_type), expolygon(_expolygon),
thickness(-1), thickness_layers(1), bridge_angle(-1), extra_perimeters(0)
thickness(-1), thickness_layers(1), bridge_angle(-1), extra_perimeters(0),
maxNbLayersOnTop(0)
{};
Surface(const Surface &other, const ExPolygon &_expolygon)
: surface_type(other.surface_type), expolygon(_expolygon),
thickness(other.thickness), thickness_layers(other.thickness_layers),
bridge_angle(other.bridge_angle), extra_perimeters(other.extra_perimeters)
bridge_angle(other.bridge_angle), extra_perimeters(other.extra_perimeters),
maxNbLayersOnTop(other.maxNbLayersOnTop)
{};
Surface(Surface &&rhs)
: surface_type(rhs.surface_type), expolygon(std::move(rhs.expolygon)),
thickness(rhs.thickness), thickness_layers(rhs.thickness_layers),
bridge_angle(rhs.bridge_angle), extra_perimeters(rhs.extra_perimeters)
bridge_angle(rhs.bridge_angle), extra_perimeters(rhs.extra_perimeters),
maxNbLayersOnTop(rhs.maxNbLayersOnTop)
{};
Surface(SurfaceType _surface_type, const ExPolygon &&_expolygon)
: surface_type(_surface_type), expolygon(std::move(_expolygon)),
thickness(-1), thickness_layers(1), bridge_angle(-1), extra_perimeters(0)
thickness(-1), thickness_layers(1), bridge_angle(-1), extra_perimeters(0),
maxNbLayersOnTop(0)
{};
Surface(const Surface &other, const ExPolygon &&_expolygon)
: surface_type(other.surface_type), expolygon(std::move(_expolygon)),
thickness(other.thickness), thickness_layers(other.thickness_layers),
bridge_angle(other.bridge_angle), extra_perimeters(other.extra_perimeters)
bridge_angle(other.bridge_angle), extra_perimeters(other.extra_perimeters),
maxNbLayersOnTop(other.maxNbLayersOnTop)
{};
Surface& operator=(const Surface &rhs)
@ -80,6 +87,7 @@ public:
thickness_layers = rhs.thickness_layers;
bridge_angle = rhs.bridge_angle;
extra_perimeters = rhs.extra_perimeters;
maxNbLayersOnTop = rhs.maxNbLayersOnTop;
return *this;
}
@ -91,6 +99,7 @@ public:
thickness_layers = rhs.thickness_layers;
bridge_angle = rhs.bridge_angle;
extra_perimeters = rhs.extra_perimeters;
maxNbLayersOnTop = rhs.maxNbLayersOnTop;
return *this;
}

View File

@ -299,7 +299,8 @@ const std::vector<std::string>& Preset::print_options()
"top_infill_extrusion_width", "support_material_extrusion_width", "infill_overlap", "bridge_flow_ratio",
"over_bridge_flow_ratio", "clip_multipart_objects", "enforce_full_fill_volume", "external_infill_margin",
"elefant_foot_compensation", "xy_size_compensation", "threads", "resolution", "wipe_tower", "wipe_tower_x", "wipe_tower_y",
"wipe_tower_width", "wipe_tower_rotation_angle", "wipe_tower_bridging", "only_one_perimeter_top", "compatible_printers", "compatible_printers_condition","inherits"
"wipe_tower_width", "wipe_tower_rotation_angle", "wipe_tower_bridging", "only_one_perimeter_top", "compatible_printers",
"compatible_printers_condition", "inherits", "infill_dense_layers", "infill_dense_density"
};
return s_opts;
}

View File

@ -856,6 +856,10 @@ void TabPrint::build()
optgroup = page->new_optgroup(_(L("Reducing printing time")));
optgroup->append_single_option_line("infill_every_layers");
optgroup->append_single_option_line("infill_only_where_needed");
line = { _(L("Use denser infill below top layers")), "" };
line.append_option(optgroup->get_option("infill_dense_layers"));
line.append_option(optgroup->get_option("infill_dense_density"));
optgroup->append_line(line);
optgroup = page->new_optgroup(_(L("Advanced")));
optgroup->append_single_option_line("solid_infill_every_layers");