Use support headDiameter from config

(generate support config when diameter is known)
+ overhangs sample curve is static inside of code(do not use svg config file more)
+ Move island configuration behinde macro
This commit is contained in:
Filip Sykala - NTB T15p 2025-02-20 15:11:27 +01:00 committed by Lukas Matena
parent 974bfbdfbd
commit 63ea165f00
5 changed files with 63 additions and 35 deletions

View File

@ -52,8 +52,7 @@ bool SampleConfigFactory::verify(SampleConfig &cfg) {
return res; return res;
} }
SampleConfig SampleConfigFactory::create(float support_head_diameter_in_mm) SampleConfig SampleConfigFactory::create(float support_head_diameter_in_mm) {
{
SampleConfig result; SampleConfig result;
result.head_radius = static_cast<coord_t>(scale_(support_head_diameter_in_mm/2)); result.head_radius = static_cast<coord_t>(scale_(support_head_diameter_in_mm/2));
@ -99,6 +98,30 @@ SampleConfig SampleConfigFactory::create(float support_head_diameter_in_mm)
return result; return result;
} }
SampleConfig SampleConfigFactory::apply_density(const SampleConfig &current, float density) {
if (is_approx(density, 1.f))
return current;
if (density < .1f)
density = .1f; // minimal 10%
SampleConfig result = current; // copy
result.thin_max_distance = static_cast<coord_t>(current.thin_max_distance / density); // linear
result.thick_inner_max_distance = static_cast<coord_t>( // controll radius - quadratic
std::sqrt(sqr((double) current.thick_inner_max_distance) / density)
);
result.thick_outline_max_distance = static_cast<coord_t>(
current.thick_outline_max_distance / density
); // linear
// result.head_radius .. no change
// result.minimal_distance_from_outline .. no change
// result.maximal_distance_from_outline .. no change
// result.max_length_for_one_support_point .. no change
// result.max_length_for_two_support_points .. no change
verify(result);
return result;
}
#ifdef USE_ISLAND_GUI_FOR_SETTINGS
std::optional<SampleConfig> SampleConfigFactory::gui_sample_config_opt; std::optional<SampleConfig> SampleConfigFactory::gui_sample_config_opt;
SampleConfig &SampleConfigFactory::get_sample_config() { SampleConfig &SampleConfigFactory::get_sample_config() {
// init config // init config
@ -109,22 +132,6 @@ SampleConfig &SampleConfigFactory::get_sample_config() {
} }
SampleConfig SampleConfigFactory::get_sample_config(float density) { SampleConfig SampleConfigFactory::get_sample_config(float density) {
const SampleConfig &current = get_sample_config(); return apply_density(get_sample_config(), density);
if (is_approx(density, 1.f))
return current;
if (density < .1f)
density = .1f; // minimal 10%
SampleConfig result = current; // copy
result.thin_max_distance = static_cast<coord_t>(current.thin_max_distance / density); // linear
result.thick_inner_max_distance = static_cast<coord_t>( // controll radius - quadratic
std::sqrt(sqr((double)current.thick_inner_max_distance) / density));
result.thick_outline_max_distance = static_cast<coord_t>(current.thick_outline_max_distance / density); // linear
// result.head_radius .. no change
// result.minimal_distance_from_outline .. no change
// result.maximal_distance_from_outline .. no change
// result.max_length_for_one_support_point .. no change
// result.max_length_for_two_support_points .. no change
verify(result);
return result;
} }
#endif // USE_ISLAND_GUI_FOR_SETTINGS

View File

@ -5,6 +5,8 @@
#include "SampleConfig.hpp" #include "SampleConfig.hpp"
#include "libslic3r/PrintConfig.hpp" #include "libslic3r/PrintConfig.hpp"
//#define USE_ISLAND_GUI_FOR_SETTINGS
namespace Slic3r::sla { namespace Slic3r::sla {
/// <summary> /// <summary>
@ -17,7 +19,8 @@ public:
static bool verify(SampleConfig &cfg); static bool verify(SampleConfig &cfg);
static SampleConfig create(float support_head_diameter_in_mm); static SampleConfig create(float support_head_diameter_in_mm);
static SampleConfig apply_density(const SampleConfig& cfg, float density);
#ifdef USE_ISLAND_GUI_FOR_SETTINGS
private: private:
// TODO: REMOVE IT. Do not use in production // TODO: REMOVE IT. Do not use in production
// Global variable to temporary set configuration from GUI into SLA print steps // Global variable to temporary set configuration from GUI into SLA print steps
@ -34,6 +37,7 @@ public:
/// 1.1f.. extend count of supports (approx to 110%) </param> /// 1.1f.. extend count of supports (approx to 110%) </param>
/// <returns>Scaled configuration</returns> /// <returns>Scaled configuration</returns>
static SampleConfig get_sample_config(float density); static SampleConfig get_sample_config(float density);
#endif // USE_ISLAND_GUI_FOR_SETTINGS
}; };
} // namespace Slic3r::sla } // namespace Slic3r::sla
#endif // slic3r_SLA_SuppotstIslands_SampleConfigFactory_hpp_ #endif // slic3r_SLA_SuppotstIslands_SampleConfigFactory_hpp_

View File

@ -543,7 +543,11 @@ void SLAPrint::Steps::prepare_for_generate_supports(SLAPrintObject &po) {
using namespace sla; using namespace sla;
std::vector<ExPolygons> slices = po.get_model_slices(); // copy std::vector<ExPolygons> slices = po.get_model_slices(); // copy
const std::vector<float> &heights = po.m_model_height_levels; const std::vector<float> &heights = po.m_model_height_levels;
const PrepareSupportConfig &prepare_cfg = SampleConfigFactory::get_sample_config().prepare_config; #ifdef USE_ISLAND_GUI_FOR_SETTINGS
const PrepareSupportConfig &prepare_cfg = SampleConfigFactory::get_sample_config(po.config().support_head_front_diameter).prepare_config; // use configuration edited by GUI
#else // USE_ISLAND_GUI_FOR_SETTINGS
const PrepareSupportConfig prepare_cfg; // use Default values of the configuration
#endif // USE_ISLAND_GUI_FOR_SETTINGS
ThrowOnCancel cancel = [this]() { throw_if_canceled(); }; ThrowOnCancel cancel = [this]() { throw_if_canceled(); };
// scaling for the sub operations // scaling for the sub operations
@ -750,8 +754,14 @@ void SLAPrint::Steps::support_points(SLAPrintObject &po)
} }
// copy current configuration for sampling islands // copy current configuration for sampling islands
#ifdef USE_ISLAND_GUI_FOR_SETTINGS
// use static variable to propagate data from GUI
config.island_configuration = SampleConfigFactory::get_sample_config(config.density_relative); config.island_configuration = SampleConfigFactory::get_sample_config(config.density_relative);
#else // USE_ISLAND_GUI_FOR_SETTINGS
config.island_configuration = SampleConfigFactory::apply_density(
SampleConfigFactory::create(config.head_diameter), config.density_relative);
#endif // USE_ISLAND_GUI_FOR_SETTINGS
// scaling for the sub operations // scaling for the sub operations
double d = objectstep_scale * OBJ_STEP_LEVELS[slaposSupportPoints] / 100.0; double d = objectstep_scale * OBJ_STEP_LEVELS[slaposSupportPoints] / 100.0;
double init = current_status(); double init = current_status();

View File

@ -785,18 +785,20 @@ RENDER_AGAIN:
ImVec4 light_gray{0.4f, 0.4f, 0.4f, 1.0f}; ImVec4 light_gray{0.4f, 0.4f, 0.4f, 1.0f};
ImGui::TextColored(light_gray, "%s", stats.c_str()); ImGui::TextColored(light_gray, "%s", stats.c_str());
//ImGui::Separator(); // START temporary debug #ifdef USE_ISLAND_GUI_FOR_SETTINGS
//ImGui::Text("Between delimiters is temporary GUI"); ImGui::Separator();
//sla::SampleConfig &sample_config = sla::SampleConfigFactory::get_sample_config(); ImGui::Text("Between delimiters is temporary GUI");
//if (float overhang_sample_distance = sample_config.prepare_config.discretize_overhang_step; sla::SampleConfig &sample_config = sla::SampleConfigFactory::get_sample_config();
// m_imgui->slider_float("overhang discretization", &overhang_sample_distance, 2e-5f, 10.f, "%.2f mm")){ if (float overhang_sample_distance = sample_config.prepare_config.discretize_overhang_step;
// sample_config.prepare_config.discretize_overhang_step = overhang_sample_distance; m_imgui->slider_float("overhang discretization", &overhang_sample_distance, 2e-5f, 10.f, "%.2f mm")){
//} else if (ImGui::IsItemHovered()) sample_config.prepare_config.discretize_overhang_step = overhang_sample_distance;
// ImGui::SetTooltip("Smaller will slow down. Step for discretization overhang outline for test of support need"); } else if (ImGui::IsItemHovered())
// ImGui::SetTooltip("Smaller will slow down. Step for discretization overhang outline for test of support need");
//draw_island_config();
//ImGui::Text("Distribution depends on './resources/data/sla_support.svg'\ninstruction for edit are in file"); draw_island_config();
//ImGui::Separator(); ImGui::Text("Distribution depends on './resources/data/sla_support.svg'\ninstruction for edit are in file");
ImGui::Separator();
#endif // USE_ISLAND_GUI_FOR_SETTINGS
if (ImGuiPureWrap::button(m_desc.at("auto_generate"))) if (ImGuiPureWrap::button(m_desc.at("auto_generate")))
auto_generate(); auto_generate();
@ -884,6 +886,7 @@ RENDER_AGAIN:
m_parent.set_as_dirty(); m_parent.set_as_dirty();
} }
#ifdef USE_ISLAND_GUI_FOR_SETTINGS
void GLGizmoSlaSupports::draw_island_config() { void GLGizmoSlaSupports::draw_island_config() {
if (!ImGui::TreeNode("Support islands:")) if (!ImGui::TreeNode("Support islands:"))
return; // no need to draw configuration for islands return; // no need to draw configuration for islands
@ -1014,6 +1017,7 @@ void GLGizmoSlaSupports::draw_island_config() {
// end of tree node // end of tree node
ImGui::TreePop(); ImGui::TreePop();
} }
#endif // USE_ISLAND_GUI_FOR_SETTINGS
bool GLGizmoSlaSupports::on_is_activable() const bool GLGizmoSlaSupports::on_is_activable() const
{ {

View File

@ -596,6 +596,9 @@ TEST_CASE("Disable visualization", "[hide]")
#ifdef STORE_ISLAND_ISSUES #ifdef STORE_ISLAND_ISSUES
CHECK(false); CHECK(false);
#endif // STORE_ISLAND_ISSUES #endif // STORE_ISLAND_ISSUES
#ifdef USE_ISLAND_GUI_FOR_SETTINGS
CHECK(false);
#endif // USE_ISLAND_GUI_FOR_SETTINGS
CHECK(is_uniform_support_island_visualization_disabled()); CHECK(is_uniform_support_island_visualization_disabled());
} }