Skip to content

Commit

Permalink
sorting perimeters (experimental, to improve path planning)
Browse files Browse the repository at this point in the history
fix seam notch with spiral vase
some gui stuff for scripted settings.
  • Loading branch information
supermerill committed Dec 14, 2023
2 parents 69c3980 + 3c97b61 commit 4c9edde
Show file tree
Hide file tree
Showing 20 changed files with 312 additions and 145 deletions.
2 changes: 2 additions & 0 deletions resources/ui_layout/Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,8 @@ These functions can only be called in a `set` or `reset` function. If you need t
### others
* void **ask_for_refresh**()
ask for a OPTNAME_set() after the current OPTNAME_get(), to be able to set settings.
* bool **is_enabled**(string setting_key)
Experimental. Ask if this setting is currently enabled. Dangerous, as it will be true if it's not constructed.

### to get/set the value of a custom variable
The first argument is the index of the tab setting: 0 for print settings, 1 for filament settings and 2 for printer settings.
Expand Down
5 changes: 5 additions & 0 deletions resources/ui_layout/default/print.as
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,11 @@ void s_seam_position_set(string &in set_val, int idx)
}
}

bool s_seam_position_is_enabled()
{
return get_int("perimeters") > 0;
}

// s_wall_thickness
// set the perimeter_spacing & external_perimeter_spacing
// as m * 2 perimeter_spacing + n * 2 * external_perimeter_spacing = o * s_wall_thickness
Expand Down
13 changes: 9 additions & 4 deletions src/libslic3r/GCode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4787,7 +4787,7 @@ std::string GCode::extrude_entity(const ExtrusionEntity &entity, const std::stri
}

void GCode::use(const ExtrusionEntityCollection &collection) {
if (!collection.can_sort() || collection.role() == erMixed || collection.entities().size() <= 1) {
if (!collection.can_sort() /*|| collection.role() == erMixed*/ || collection.entities().size() <= 1) {
for (const ExtrusionEntity* next_entity : collection.entities()) {
next_entity->visit(*this);
}
Expand Down Expand Up @@ -4912,10 +4912,15 @@ std::string GCode::extrude_perimeters(const Print &print, const std::vector<Obje
gcode += m_writer.set_temperature(m_config.print_temperature.value, false, m_writer.tool()->id());
else if (m_layer != nullptr && m_layer->bottom_z() < EPSILON && m_config.first_layer_temperature.get_at(m_writer.tool()->id()) > 0)
gcode += m_writer.set_temperature(m_config.first_layer_temperature.get_at(m_writer.tool()->id()), false, m_writer.tool()->id());
else if (m_config.temperature.get_at(m_writer.tool()->id()) > 0) // don't set it if disabled
gcode += m_writer.set_temperature(m_config.temperature.get_at(m_writer.tool()->id()), false, m_writer.tool()->id());
for (const ExtrusionEntity *ee : region.perimeters)
else if (m_config.temperature.get_at(m_writer.tool()->id()) > 0) { // don't set it if disabled
gcode += m_writer.set_temperature(m_config.temperature.get_at(m_writer.tool()->id()), false,
m_writer.tool()->id());
}
ExtrusionEntitiesPtr extrusions{region.perimeters};
chain_and_reorder_extrusion_entities(extrusions, &m_last_pos);
for (const ExtrusionEntity *ee : extrusions) {
gcode += this->extrude_entity(*ee, "perimeter", -1.);
}
}
m_seam_perimeters = false;
return gcode;
Expand Down
39 changes: 9 additions & 30 deletions src/libslic3r/GCode/SeamPlacer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -429,7 +429,7 @@ Polygons extract_perimeter_polygons(const Layer *layer, const SeamPosition confi
class PerimeterCopy : public ExtrusionVisitorConst {
Polygons* polygons;
std::vector<const LayerRegion*>* corresponding_regions_out;
LayerRegion* current_layer_region;
const LayerRegion* current_layer_region;
SeamPosition configured_seam_preference;
public:
PerimeterCopy(std::vector<const LayerRegion*>* regions_out, Polygons* polys, SeamPosition configured_seam)
Expand Down Expand Up @@ -457,41 +457,20 @@ Polygons extract_perimeter_polygons(const Layer *layer, const SeamPosition confi
entity->visit(*this);
}
}
void set_current_layer_region(const LayerRegion *set) { current_layer_region = set; }
} visitor(&corresponding_regions_out, &polygons, configured_seam_preference);

for (const LayerRegion *layer_region : layer->regions()) {
for (const ExtrusionEntity *ex_entity : layer_region->perimeters.entities()) {
if (ex_entity->is_collection()) { //collection of inner, outer, and overhang perimeters
//ex_entity->visit(visitor);
for (const ExtrusionEntity *perimeter : static_cast<const ExtrusionEntityCollection*>(ex_entity)->entities()) {
ExtrusionRole role = perimeter->role();
if (perimeter->is_loop()) {
for (const ExtrusionPath &path : static_cast<const ExtrusionLoop*>(perimeter)->paths) {
if (path.role() == ExtrusionRole::erExternalPerimeter) {
role = ExtrusionRole::erExternalPerimeter;
}
}
}

if (role == ExtrusionRole::erExternalPerimeter
|| (is_perimeter(role) && (configured_seam_preference == spAllRandom) )) { //for random seam alignment, extract all perimeters
Points p;
perimeter->collect_points(p);
polygons.emplace_back(std::move(p));
corresponding_regions_out.push_back(layer_region);
}
}
if (polygons.empty()) {
Points p;
ex_entity->collect_points(p);
polygons.emplace_back(std::move(p));
corresponding_regions_out.push_back(layer_region);
}
} else {
visitor.set_current_layer_region(layer_region);
ex_entity->visit(visitor);
if (polygons.empty()) {
Points p;
ex_entity->collect_points(p);
polygons.emplace_back(std::move(p));
corresponding_regions_out.push_back(layer_region);
//shouldn't happen
assert(false);
}
}
}
Expand Down Expand Up @@ -814,8 +793,8 @@ struct SeamComparator {

// Standard comparator, must respect the requirements of comparators (e.g. give same result on same inputs) for sorting usage
// should return if a is better seamCandidate than b
bool is_first_better(const SeamCandidate &a, const SeamCandidate &b, const Vec2f &preffered_location = Vec2f { 0.0f,
0.0f }) const {
bool is_first_better(const SeamCandidate &a, const SeamCandidate &b, const Vec2f &preffered_location = Vec2f { 0.0f, 0.0f}) const
{
if ((setup == SeamPosition::spAligned || setup == SeamPosition::spExtremlyAligned) && a.central_enforcer != b.central_enforcer) {
return a.central_enforcer;
}
Expand Down
39 changes: 32 additions & 7 deletions src/libslic3r/PerimeterGenerator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -354,8 +354,10 @@ ProcessSurfaceResult PerimeterGenerator::process_arachne(int& loop_number, const
}
}

if (ExtrusionEntityCollection extrusion_coll = _traverse_extrusions(ordered_extrusions); !extrusion_coll.empty())
if (ExtrusionEntityCollection extrusion_coll = _traverse_extrusions(ordered_extrusions); !extrusion_coll.empty()) {
extrusion_coll.set_can_sort_reverse(false, false);
this->loops->append(extrusion_coll);
}

ExPolygons infill_contour = union_ex(wallToolPaths.getInnerContour());
const coord_t spacing = (perimeters.size() == 1) ? ext_perimeter_spacing2 : perimeter_spacing;
Expand Down Expand Up @@ -2562,23 +2564,46 @@ ExtrusionEntityCollection PerimeterGenerator::_traverse_loops(
}
assert(thin_walls.empty());
ExtrusionEntityCollection children = this->_traverse_loops(loop.children, thin_walls, has_overhang ? 1 : count_since_overhang < 0 ? -1 : (count_since_overhang+1));
coll_out.set_entities().reserve(coll_out.entities().size() + children.entities().size() + 1);
coll[idx.first] = nullptr;
if (loop.is_contour) {
//note: this->layer->id() % 2 == 1 already taken into account in the is_steep_overhang compute (to save time).
if (loop.is_steep_overhang && this->layer->id() % 2 == 1)
eloop->make_clockwise();
else
eloop->make_counter_clockwise();
coll_out.append(std::move(children.entities()));
coll_out.append(*eloop);
//ensure that our children are printed before us
if (!children.empty()) {
ExtrusionEntityCollection print_child_beforeplz;
print_child_beforeplz.set_can_sort_reverse(false, false);
if (children.entities().size() > 1) {
print_child_beforeplz.append(children);
} else {
print_child_beforeplz.append(std::move(children.entities()));
}
print_child_beforeplz.append(*eloop);
coll_out.append(std::move(print_child_beforeplz));
} else {
coll_out.append(*eloop);
}
} else {
if (loop.is_steep_overhang && this->layer->id() % 2 == 1)
eloop->make_counter_clockwise();
else
eloop->make_clockwise();
coll_out.append(*eloop);
coll_out.append(std::move(children.entities()));
// ensure that our children are printed after us
if (!children.empty()) {
ExtrusionEntityCollection print_child_beforeplz;
print_child_beforeplz.set_can_sort_reverse(false, false);
print_child_beforeplz.append(*eloop);
if (children.entities().size() > 1) {
print_child_beforeplz.append(children);
} else {
print_child_beforeplz.append(std::move(children.entities()));
}
coll_out.append(std::move(print_child_beforeplz));
} else {
coll_out.append(*eloop);
}
}
}
}
Expand Down Expand Up @@ -2974,7 +2999,7 @@ PerimeterGenerator::_get_nearest_point(const PerimeterGeneratorLoops &children,

if ((myPolylines.paths[idx_poly].role() == erExternalPerimeter || child.is_external() )
&& (this->object_config->seam_position.value != SeamPosition::spRandom && this->object_config->seam_position.value != SeamPosition::spAllRandom)) {
//first, try to find 2 point near enough
//first, try to find 2 point near enough //TODO: use seam placer or at least an equivalent.
for (size_t idx_point = 0; idx_point < myPolylines.paths[idx_poly].polyline.size(); idx_point++) {
const Point &p = myPolylines.paths[idx_poly].polyline.get_points()[idx_point];
const Point &nearest_p = *child.polygon.closest_point(p);
Expand Down
13 changes: 12 additions & 1 deletion src/libslic3r/Preset.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -126,10 +126,21 @@ class Preset
TYPE_SLA_MATERIAL = TYPE_SLA | TYPE_MATERIAL,
TYPE_TECHNOLOGY = TYPE_FFF | TYPE_SLA,

TYPE_FREQUENT = 1 << 5,
TYPE_FREQUENT_FFF = TYPE_FFF | TYPE_FREQUENT,
TYPE_FREQUENT_SLA = TYPE_SLA | TYPE_FREQUENT,
// This type is here to support PresetConfigSubstitutions for physical printers, however it does not belong to the Preset class,
// PhysicalPrinter class is used instead.
TYPE_PHYSICAL_PRINTER = 1 << 5,
TYPE_PHYSICAL_PRINTER = 1 << 6,
};
static inline PrinterTechnology get_tech(Type type)
{
if ((type & TYPE_FFF) == TYPE_FFF)
return PrinterTechnology::ptFFF;
if ((type & TYPE_FFF) == TYPE_SLA)
return PrinterTechnology::ptSLA;
return PrinterTechnology::ptUnknown;
}
static std::string type_name(Type t);

Type type = TYPE_INVALID;
Expand Down
22 changes: 20 additions & 2 deletions src/slic3r/GUI/ConfigManipulation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,9 @@ void ConfigManipulation::update_print_fff_config(DynamicPrintConfig* config, con
&& config->opt_bool("overhangs_reverse") == false
&& config->opt_bool("gap_fill_last") == false
&& config->opt_int("solid_over_perimeters") == 0
&& config->option("seam_notch_all")->getFloat() == 0
&& config->option("seam_notch_inner")->getFloat() == 0
&& config->option("seam_notch_outer")->getFloat() == 0
)) {
wxString msg_text = _(L("The Spiral Vase mode requires:\n"
"- no top solid layers\n"
Expand All @@ -98,7 +101,8 @@ void ConfigManipulation::update_print_fff_config(DynamicPrintConfig* config, con
"- unchecked 'dense infill'\n"
"- unchecked 'extra perimeters'"
"- unchecked 'gap fill after last perimeter'"
"- disabled 'no solid fill over X perimeters'"));
"- disabled 'no solid fill over X perimeters'"
"- disabled 'seam notch'"));
if (is_global_config)
msg_text += "\n\n" + _(L("Shall I adjust those settings in order to enable Spiral Vase?"));
MessageDialog dialog(m_msg_dlg_parent, msg_text, _(L("Spiral Vase")),
Expand Down Expand Up @@ -137,6 +141,12 @@ void ConfigManipulation::update_print_fff_config(DynamicPrintConfig* config, con
new_conf.set_key_value("gap_fill_last", new ConfigOptionBool(false));
else if (this->local_config->get().optptr("solid_over_perimeters"))
new_conf.set_key_value("solid_over_perimeters", new ConfigOptionInt(0));
else if (this->local_config->get().optptr("seam_notch_all"))
new_conf.set_key_value("seam_notch_all", new ConfigOptionFloatOrPercent(0, false));
else if (this->local_config->get().optptr("seam_notch_inner"))
new_conf.set_key_value("seam_notch_all", new ConfigOptionFloatOrPercent(0, false));
else if (this->local_config->get().optptr("seam_notch_outer"))
new_conf.set_key_value("seam_notch_all", new ConfigOptionFloatOrPercent(0, false));
this->local_config->apply_only(new_conf, this->local_config->keys(), true);
} else if (answer == wxID_YES) {
new_conf.set_key_value("top_solid_layers", new ConfigOptionInt(0));
Expand All @@ -153,6 +163,9 @@ void ConfigManipulation::update_print_fff_config(DynamicPrintConfig* config, con
new_conf.set_key_value("overhangs_reverse", new ConfigOptionBool(false));
new_conf.set_key_value("gap_fill_last", new ConfigOptionBool(false));
new_conf.set_key_value("solid_over_perimeters", new ConfigOptionInt(0));
new_conf.set_key_value("seam_notch_all", new ConfigOptionFloatOrPercent(0, false));
new_conf.set_key_value("seam_notch_inner", new ConfigOptionFloatOrPercent(0, false));
new_conf.set_key_value("seam_notch_outer", new ConfigOptionFloatOrPercent(0, false));
fill_density = 0;
support = false;
} else {
Expand Down Expand Up @@ -327,7 +340,7 @@ void ConfigManipulation::toggle_print_fff_options(DynamicPrintConfig* config)
"external_perimeters_first", "external_perimeter_extrusion_width", "external_perimeter_extrusion_spacing","external_perimeter_extrusion_change_odd_layers",
"overhangs","perimeter_speed",
"seam_position", "small_perimeter_speed", "small_perimeter_min_length", " small_perimeter_max_length", "spiral_vase",
"perimeter_generator"})
"perimeter_generator", "seam_notch_all", "seam_notch_inner", "seam_notch_outer"})
toggle_field(el, have_perimeters);

bool has_spiral_vase = have_perimeters && config->opt_bool("spiral_vase");
Expand Down Expand Up @@ -361,6 +374,11 @@ void ConfigManipulation::toggle_print_fff_options(DynamicPrintConfig* config)

toggle_field("perimeter_loop_seam", config->opt_bool("perimeter_loop"));

bool have_notch = have_perimeters && (config->option("seam_notch_all")->getFloat() != 0 ||
config->option("seam_notch_inner")->getFloat() != 0 ||
config->option("seam_notch_outer")->getFloat() != 0);
toggle_field("seam_notch_angle", have_notch);

bool have_gap_fill = !have_arachne;
toggle_field("gap_fill_enabled", have_gap_fill);
for (auto el : { "gap_fill_extension", "gap_fill_last", "gap_fill_max_width", "gap_fill_min_area", "gap_fill_min_length", "gap_fill_min_width" })
Expand Down
36 changes: 18 additions & 18 deletions src/slic3r/GUI/CreateMMUTiledCanvas.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1113,31 +1113,31 @@ void CreateMMUTiledCanvas::create_main_tab(wxPanel* tab)
//group_size->append_single_option_line(option);

//line = { L("Size"), "" };
group_size->append_single_option_line(group_size->get_option("size"));
group_size->append_single_option_line(group_size->create_option_from_def("size"));
//line.append_option(Option(def, "size"));

group_size->append_single_option_line(group_size->get_option("size_px"));
group_size->append_single_option_line(group_size->create_option_from_def("size_px"));
//line.append_option(Option(def, "size_px"));

//group_size->append_line(line);

group_size->append_single_option_line(group_size->get_option("height"));
group_size->append_single_option_line(group_size->create_option_from_def("height"));

group_size->append_single_option_line(group_size->get_option("offset"));
group_size->append_single_option_line(group_size->create_option_from_def("offset"));

line = { L("Gap"), "" };

line.append_option(group_size->get_option("separation_xy"));
line.append_option(group_size->create_option_from_def("separation_xy"));

line.append_option(group_size->get_option("separation_z"));
line.append_option(group_size->create_option_from_def("separation_z"));

group_size->append_line(line);

group_size->append_single_option_line(group_size->get_option("bezel"));
group_size->append_single_option_line(group_size->get_option("border"));
group_size->append_single_option_line(group_size->create_option_from_def("bezel"));
group_size->append_single_option_line(group_size->create_option_from_def("border"));


//group_size->append_single_option_line(group_size->get_option("bump"));
//group_size->append_single_option_line(group_size->create_option_from_def("bump"));

group_size->activate([]() {}, wxALIGN_RIGHT);
group_size->reload_config();
Expand All @@ -1156,23 +1156,23 @@ void CreateMMUTiledCanvas::create_main_tab(wxPanel* tab)
};
group_colors->title_width = 15;

group_colors->append_single_option_line(group_colors->get_option("spool_colors"));
group_colors->append_single_option_line(group_colors->create_option_from_def("spool_colors"));

//line = { L("Separation"), "" };
//line.append_option(group_colors->get_option("near_color"));
//line.append_option(group_colors->get_option("color_comp"));
//line.append_option(group_colors->create_option_from_def("near_color"));
//line.append_option(group_colors->create_option_from_def("color_comp"));
//group_colors->append_line(line);
group_colors->append_single_option_line(group_colors->get_option("near_color"));
group_colors->append_single_option_line(group_colors->create_option_from_def("near_color"));

group_colors->append_single_option_line(group_colors->get_option("color_comp"));
group_colors->append_single_option_line(group_colors->create_option_from_def("color_comp"));

group_colors->append_single_option_line(group_colors->get_option("order_dark"));
group_colors->append_single_option_line(group_colors->create_option_from_def("order_dark"));

group_colors->append_single_option_line(group_colors->get_option("original"));
group_colors->append_single_option_line(group_colors->create_option_from_def("original"));

group_colors->append_single_option_line(group_colors->get_option("extruders"));
group_colors->append_single_option_line(group_colors->create_option_from_def("extruders"));

group_colors->append_single_option_line(group_colors->get_option("background_color"));
group_colors->append_single_option_line(group_colors->create_option_from_def("background_color"));

//line = { "", "" };
//line.full_width = 1;
Expand Down
Loading

0 comments on commit 4c9edde

Please sign in to comment.