From d28b61f8a305fcf1ecf3a779b303dde1bf8ea35a Mon Sep 17 00:00:00 2001 From: tamasmeszaros Date: Thu, 22 Nov 2018 18:02:05 +0100 Subject: [PATCH] Adding checkbox for disabling support generation (still having pad generation) --- src/libslic3r/MTUtils.hpp | 2 - src/libslic3r/PrintConfig.cpp | 8 ++++ src/libslic3r/PrintConfig.hpp | 14 +++++++ src/libslic3r/SLA/SLASupportTree.cpp | 5 +++ src/libslic3r/SLA/SLASupportTree.hpp | 7 +--- src/libslic3r/SLAPrint.cpp | 56 +++++++++++++++++++--------- src/slic3r/GUI/Preset.cpp | 1 + src/slic3r/GUI/Tab.cpp | 3 ++ 8 files changed, 72 insertions(+), 24 deletions(-) diff --git a/src/libslic3r/MTUtils.hpp b/src/libslic3r/MTUtils.hpp index 3001c27ff..1e0fb426a 100644 --- a/src/libslic3r/MTUtils.hpp +++ b/src/libslic3r/MTUtils.hpp @@ -8,8 +8,6 @@ namespace Slic3r { -// TODO: these classes are untested - /// Handy little spin mutex for the cached meshes. /// Implements the "Lockable" concept class SpinMutex { diff --git a/src/libslic3r/PrintConfig.cpp b/src/libslic3r/PrintConfig.cpp index 739b7ee22..3bbdf9246 100644 --- a/src/libslic3r/PrintConfig.cpp +++ b/src/libslic3r/PrintConfig.cpp @@ -2445,6 +2445,14 @@ void PrintConfigDef::init_sla_params() def = this->add("sla_print_settings_id", coString); def->default_value = new ConfigOptionString(""); + def = this->add("supports_enable", coBool); + def->label = L("Generate supports"); + def->category = L("Supports"); + def->tooltip = L("Generate supports for the models"); + def->sidetext = L(""); + def->cli = ""; + def->default_value = new ConfigOptionBool(true); + def = this->add("support_head_front_radius", coFloat); def->label = L("Support head front radius"); def->category = L("Supports"); diff --git a/src/libslic3r/PrintConfig.hpp b/src/libslic3r/PrintConfig.hpp index a3c79f4a4..b3d0c33be 100644 --- a/src/libslic3r/PrintConfig.hpp +++ b/src/libslic3r/PrintConfig.hpp @@ -904,6 +904,9 @@ class SLAPrintObjectConfig : public StaticPrintConfig public: ConfigOptionFloat layer_height; + // Enabling or disabling support creation + ConfigOptionBool supports_enable; + // Radius in mm of the pointing side of the head. ConfigOptionFloat support_head_front_radius /*= 0.2*/; @@ -942,16 +945,27 @@ public: // Now for the base pool (pad) ///////////////////////////////////////////// + // Enabling or disabling support creation ConfigOptionBool pad_enable; + + // The thickness of the pad walls ConfigOptionFloat pad_wall_thickness /*= 2*/; + + // The height of the pad from the bottom to the top not considering the pit ConfigOptionFloat pad_wall_height /*= 5*/; + + // The greatest distance where two individual pads are merged into one. The + // distance is measured roughly from the centroids of the pads. ConfigOptionFloat pad_max_merge_distance /*= 50*/; + + // The smoothing radius of the pad edges ConfigOptionFloat pad_edge_radius /*= 1*/; protected: void initialize(StaticCacheBase &cache, const char *base_ptr) { OPT_PTR(layer_height); + OPT_PTR(supports_enable); OPT_PTR(support_head_front_radius); OPT_PTR(support_head_penetration); OPT_PTR(support_head_back_radius); diff --git a/src/libslic3r/SLA/SLASupportTree.cpp b/src/libslic3r/SLA/SLASupportTree.cpp index e08eaec74..27fa53236 100644 --- a/src/libslic3r/SLA/SLASupportTree.cpp +++ b/src/libslic3r/SLA/SLASupportTree.cpp @@ -1619,6 +1619,11 @@ bool SLASupportTree::generate(const PointSet &points, return pc == ABORT; } +SLASupportTree::SLASupportTree(): m_impl(new Impl()) +{ + +} + const TriangleMesh &SLASupportTree::merged_mesh() const { return get().merged_mesh(); diff --git a/src/libslic3r/SLA/SLASupportTree.hpp b/src/libslic3r/SLA/SLASupportTree.hpp index 163cacbde..a24601de1 100644 --- a/src/libslic3r/SLA/SLASupportTree.hpp +++ b/src/libslic3r/SLA/SLASupportTree.hpp @@ -132,6 +132,8 @@ class SLASupportTree { const Controller& ctl = {}); public: + SLASupportTree(); + SLASupportTree(const PointSet& pts, const EigenMesh3D& em, const SupportConfig& cfg = {}, @@ -161,11 +163,6 @@ public: /// Get the pad geometry const TriangleMesh& get_pad() const; - /// The Z offset to raise the model and the supports to the ground level. - /// This is the elevation given in the support config and the height of the - /// pad (if requested). - double get_elevation() const; - }; } diff --git a/src/libslic3r/SLAPrint.cpp b/src/libslic3r/SLAPrint.cpp index 7a5b9053a..567401d44 100644 --- a/src/libslic3r/SLAPrint.cpp +++ b/src/libslic3r/SLAPrint.cpp @@ -381,8 +381,11 @@ void SLAPrint::process() auto ilh = float(ilhd); const size_t objcount = m_objects.size(); - const unsigned min_objstatus = 0; - const unsigned max_objstatus = 80; + const unsigned min_objstatus = 0; // where the per object operations start + const unsigned max_objstatus = 80; // where the per object operations end + + // the coefficient that multiplies the per object status values which + // are set up for <0, 100>. They need to be scaled into the whole process const double ostepd = (max_objstatus - min_objstatus) / (objcount * 100.0); // The slicing will be performed on an imaginary 1D grid which starts from @@ -410,6 +413,7 @@ void SLAPrint::process() auto flh = float(lh); auto gnd = float(bb3d.min(Z)); + // The 1D grid heights std::vector heights; // The first layer (the one before the initial height) is added only @@ -423,26 +427,29 @@ void SLAPrint::process() slicer.slice(heights, &layers, [this](){ throw_if_canceled(); }); }; + // this procedure simply converts the points and copies them into + // the support data cache auto support_points = [](SLAPrintObject& po) { ModelObject& mo = *po.m_model_object; - if(!mo.sla_support_points.empty()) { - po.m_supportdata.reset(new SLAPrintObject::SupportData()); - po.m_supportdata->emesh = sla::to_eigenmesh(po.transformed_mesh()); + po.m_supportdata.reset(new SLAPrintObject::SupportData()); + if(!mo.sla_support_points.empty()) { + po.m_supportdata->emesh = sla::to_eigenmesh(po.transformed_mesh()); po.m_supportdata->support_points = sla::to_point_set(po.transformed_support_points()); } - - // for(SLAPrintObject *po : pobjects) { - // TODO: calculate automatic support points - // po->m_supportdata->slice_cache contains the slices at this point - //} }; // In this step we create the supports auto support_tree = [this, objcount, ostepd](SLAPrintObject& po) { if(!po.m_supportdata) return; + if(!po.m_config.supports_enable.getBool()) { + // Generate empty support tree. It can still host a pad + po.m_supportdata->support_tree_ptr.reset(new SLASupportTree()); + return; + } + auto& emesh = po.m_supportdata->emesh; auto& pts = po.m_supportdata->support_points; // nowhere filled yet try { @@ -460,10 +467,15 @@ void SLAPrint::process() sla::Controller ctl; + // some magic to scale the status values coming from the support + // tree creation into the whole print process auto stfirst = OBJ_STEP_LEVELS.begin(); auto stthis = stfirst + slaposSupportTree; + // we need to add up the status portions until this operation unsigned init = std::accumulate(stfirst, stthis, 0); - init = unsigned(init * ostepd); + init = unsigned(init * ostepd); // scale the init portion + + // scaling for the sub operations double d = *stthis / (objcount * 100.0); ctl.statuscb = [this, init, d](unsigned st, const std::string& msg){ @@ -472,7 +484,7 @@ void SLAPrint::process() ctl.stopcondition = [this](){ return canceled(); }; ctl.cancelfn = [this]() { throw_if_canceled(); }; - po.m_supportdata->support_tree_ptr.reset( + po.m_supportdata->support_tree_ptr.reset( new SLASupportTree(pts, emesh, scfg, ctl)); } catch(sla::SLASupportsStoppedException&) { @@ -487,8 +499,7 @@ void SLAPrint::process() // and before the supports had been sliced. (or the slicing has to be // repeated) - if(/*po.is_step_done(slaposSupportTree) &&*/ - po.m_config.pad_enable.getBool() && + if(po.m_config.pad_enable.getBool() && po.m_supportdata && po.m_supportdata->support_tree_ptr) { @@ -498,13 +509,22 @@ void SLAPrint::process() double er = po.m_config.pad_edge_radius.getFloat(); double lh = po.m_config.layer_height.getFloat(); double elevation = po.m_config.support_object_elevation.getFloat(); + if(!po.m_config.supports_enable.getBool()) elevation = 0; sla::PoolConfig pcfg(wt, h, md, er); sla::ExPolygons bp; double pad_h = sla::get_pad_elevation(pcfg); - if(elevation < pad_h) sla::base_plate(po.transformed_mesh(), bp, + auto&& trmesh = po.transformed_mesh(); + + // This call can get pretty time consuming + if(elevation < pad_h) sla::base_plate(trmesh, bp, float(pad_h), float(lh)); + std::cout << "Mesh is empty: " << trmesh.empty() << std::endl; + std::cout << "Pad height: " << pad_h << std::endl; + std::cout << "Elevation " << elevation << std::endl; + std::cout << "Pad plate vertices: " << bp.size() << std::endl; + po.m_supportdata->support_tree_ptr->add_pad(bp, wt, h, md, er); } }; @@ -914,7 +934,8 @@ bool SLAPrintObject::invalidate_all_steps() } double SLAPrintObject::get_elevation() const { - double ret = m_config.support_object_elevation.getFloat(); + bool se = m_config.supports_enable.getBool(); + double ret = se? m_config.support_object_elevation.getFloat() : 0; // if the pad is enabled, then half of the pad height is its base plate if(m_config.pad_enable.getBool()) { @@ -935,11 +956,12 @@ double SLAPrintObject::get_elevation() const { double SLAPrintObject::get_current_elevation() const { + bool se = m_config.supports_enable.getBool(); bool has_supports = is_step_done(slaposSupportTree); bool has_pad = is_step_done(slaposBasePool); if(!has_supports && !has_pad) return 0; else if(has_supports && !has_pad) - return m_config.support_object_elevation.getFloat(); + return se ? m_config.support_object_elevation.getFloat() : 0; else return get_elevation(); return 0; diff --git a/src/slic3r/GUI/Preset.cpp b/src/slic3r/GUI/Preset.cpp index 4ed00e834..96191e0ff 100644 --- a/src/slic3r/GUI/Preset.cpp +++ b/src/slic3r/GUI/Preset.cpp @@ -402,6 +402,7 @@ const std::vector& Preset::sla_print_options() if (s_opts.empty()) { s_opts = { "layer_height", + "supports_enable", "support_head_front_radius", "support_head_penetration", "support_head_back_radius", diff --git a/src/slic3r/GUI/Tab.cpp b/src/slic3r/GUI/Tab.cpp index 1cc7c5844..7258ce003 100644 --- a/src/slic3r/GUI/Tab.cpp +++ b/src/slic3r/GUI/Tab.cpp @@ -2997,6 +2997,9 @@ void TabSLAPrint::build() optgroup->append_single_option_line("layer_height"); page = add_options_page(_(L("Supports")), "building.png"); + optgroup = page->new_optgroup(_(L("Supports"))); + optgroup->append_single_option_line("supports_enable"); + optgroup = page->new_optgroup(_(L("Support head"))); optgroup->append_single_option_line("support_head_front_radius"); optgroup->append_single_option_line("support_head_back_radius");