From 2dbc2f938a32e712f47646659d68ea9e9ca31b93 Mon Sep 17 00:00:00 2001 From: Filip Sykala - NTB T15p Date: Tue, 17 Dec 2024 13:34:44 +0100 Subject: [PATCH] Iteractive tune of point density --- src/libslic3r/SLAPrint.hpp | 4 +++ src/libslic3r/SLAPrintSteps.cpp | 30 +++++++++++++++----- src/libslic3r/SLAPrintSteps.hpp | 2 ++ src/slic3r/GUI/Gizmos/GLGizmoSlaSupports.cpp | 1 + 4 files changed, 30 insertions(+), 7 deletions(-) diff --git a/src/libslic3r/SLAPrint.hpp b/src/libslic3r/SLAPrint.hpp index abb76b6b7c..c931fa4105 100644 --- a/src/libslic3r/SLAPrint.hpp +++ b/src/libslic3r/SLAPrint.hpp @@ -26,6 +26,7 @@ #include "PrintBase.hpp" #include "SLA/SupportTree.hpp" +#include "SLA/SupportPointGenerator.hpp" // SupportPointGeneratorData #include "Point.hpp" #include "Format/SLAArchiveWriter.hpp" #include "libslic3r/GCode/ThumbnailData.hpp" @@ -367,6 +368,9 @@ private: std::vector m_model_height_levels; + // Precalculated data needed for interactive automatic support placement. + sla::SupportPointGeneratorData m_support_point_generator_data; + struct SupportData { sla::SupportableMesh input; // the input diff --git a/src/libslic3r/SLAPrintSteps.cpp b/src/libslic3r/SLAPrintSteps.cpp index 14e2cfacbd..84c6132c3c 100644 --- a/src/libslic3r/SLAPrintSteps.cpp +++ b/src/libslic3r/SLAPrintSteps.cpp @@ -469,6 +469,26 @@ template BoundingBoxf3 csgmesh_positive_bb(const Cont &csg) return bb3d; } +void SLAPrint::Steps::prepare_for_generate_supports(SLAPrintObject &po) { + using namespace sla; + std::vector slices = po.get_model_slices(); // copy + const std::vector &heights = po.m_model_height_levels; + const PrepareSupportConfig &prepare_cfg = SampleConfigFactory::get_sample_config().prepare_config; + ThrowOnCancel cancel = [this]() { throw_if_canceled(); }; + + // scaling for the sub operations + double d = objectstep_scale * OBJ_STEP_LEVELS[slaposSupportPoints] / 200.0; + double init = current_status(); + StatusFunction status = [this, d, init](unsigned st) { + double current = init + st * d; + if (std::round(current_status()) < std::round(current)) + report_status(current, OBJ_STEP_LABELS(slaposSupportPoints)); + }; + + po.m_support_point_generator_data = + prepare_generator_data(std::move(slices), heights, prepare_cfg, cancel, status); +} + // The slicing will be performed on an imaginary 1D grid which starts from // the bottom of the bounding box created around the supported model. So // the first layer which is usually thicker will be part of the supports @@ -543,6 +563,8 @@ void SLAPrint::Steps::slice_model(SLAPrintObject &po) // We apply the printer correction offset here. apply_printer_corrections(po, soModel); + // We need to prepare data in previous step to create interactive support point generation + prepare_for_generate_supports(po); // po.m_preview_meshes[slaposObjectSlice] = po.get_mesh_to_print(); // report_status(-2, "", SlicingStatus::RELOAD_SLA_PREVIEW); } @@ -677,17 +699,11 @@ void SLAPrint::Steps::support_points(SLAPrintObject &po) // TODO: filter small unprintable islands in slices // (Island with area smaller than 1 pixel was skipped in support generator) - std::vector slices = po.get_model_slices(); // copy - const std::vector& heights = po.m_model_height_levels; ThrowOnCancel cancel = [this]() { throw_if_canceled(); }; StatusFunction status = statuscb; - const PrepareSupportConfig &prepare_cfg = config.island_configuration.prepare_config; - SupportPointGeneratorData data = - prepare_generator_data(std::move(slices), heights, prepare_cfg, cancel, status); - LayerSupportPoints layer_support_points = - generate_support_points(data, config, cancel, status); + generate_support_points(po.m_support_point_generator_data, config, cancel, status); const AABBMesh& emesh = po.m_supportdata->input.emesh; // Maximal move of support point to mesh surface, diff --git a/src/libslic3r/SLAPrintSteps.hpp b/src/libslic3r/SLAPrintSteps.hpp index a1e50842c7..de1f256f5e 100644 --- a/src/libslic3r/SLAPrintSteps.hpp +++ b/src/libslic3r/SLAPrintSteps.hpp @@ -56,6 +56,8 @@ private: void generate_preview(SLAPrintObject &po, SLAPrintObjectStep step); indexed_triangle_set generate_preview_vdb(SLAPrintObject &po, SLAPrintObjectStep step); + void prepare_for_generate_supports(SLAPrintObject &po); + public: explicit Steps(SLAPrint *print); diff --git a/src/slic3r/GUI/Gizmos/GLGizmoSlaSupports.cpp b/src/slic3r/GUI/Gizmos/GLGizmoSlaSupports.cpp index 65a2c9563f..3db393d502 100644 --- a/src/slic3r/GUI/Gizmos/GLGizmoSlaSupports.cpp +++ b/src/slic3r/GUI/Gizmos/GLGizmoSlaSupports.cpp @@ -709,6 +709,7 @@ RENDER_AGAIN: Plater::TakeSnapshot snapshot(wxGetApp().plater(), _L("Support parameter change")); mo->config.set(support_points_density, (int) density); wxGetApp().obj_list()->update_and_show_object_settings_item(); + auto_generate(); } const sla::SupportPoints &supports = m_normal_cache;