From 29abec47b1470fc63f7f65ddf09cf5911302f1ef Mon Sep 17 00:00:00 2001 From: sentientstardust Date: Thu, 28 May 2026 19:41:35 +0100 Subject: [PATCH] Add high resolution option for polygonize color regions --- src/libslic3r/Fill/Fill.cpp | 23 ++++++++++++++++++---- src/libslic3r/TextureMapping.cpp | 6 ++++++ src/libslic3r/TextureMapping.hpp | 3 +++ src/slic3r/GUI/Plater.cpp | 33 ++++++++++++++++++++++++++++++++ 4 files changed, 61 insertions(+), 4 deletions(-) diff --git a/src/libslic3r/Fill/Fill.cpp b/src/libslic3r/Fill/Fill.cpp index 5721ac9fab7..9f034392983 100644 --- a/src/libslic3r/Fill/Fill.cpp +++ b/src/libslic3r/Fill/Fill.cpp @@ -502,6 +502,7 @@ struct TopSurfaceImageRegionPlan { bool contoning_blue_noise_error_diffusion_enabled = false; bool contoning_supersampled_cells_enabled = false; bool contoning_polygonize_color_regions_enabled = false; + bool contoning_polygonize_high_resolution_enabled = TextureMappingZone::DefaultTopSurfaceContoningPolygonizeHighResolutionEnabled; bool contoning_surface_anchored_stacks_enabled = false; int contoning_flat_surface_infill_mode = TextureMappingZone::SlicerDefaultTopSurfaceContoningFlatSurfaceInfillMode; }; @@ -1164,6 +1165,7 @@ struct TopSurfaceImageContoningStackPlanKey { bool supersampled { false }; bool blue_noise { false }; bool polygonize { false }; + bool polygonize_high_resolution { false }; bool operator<(const TopSurfaceImageContoningStackPlanKey &rhs) const { @@ -1189,7 +1191,8 @@ struct TopSurfaceImageContoningStackPlanKey { recolor_surrounding_perimeters, supersampled, blue_noise, - polygonize) < + polygonize, + polygonize_high_resolution) < std::tie(rhs.source_layer, rhs.source_layer_id, rhs.target_layer, @@ -1212,7 +1215,8 @@ struct TopSurfaceImageContoningStackPlanKey { rhs.recolor_surrounding_perimeters, rhs.supersampled, rhs.blue_noise, - rhs.polygonize); + rhs.polygonize, + rhs.polygonize_high_resolution); } }; @@ -1468,15 +1472,21 @@ static float top_surface_image_contoning_sample_pitch_mm(const TopSurfaceImageRe float pitch = std::clamp(plan.contoning_external_width_mm, 0.25f, std::max(0.25f, plan.contoning_min_feature_mm * 0.5f)); + const bool high_resolution = + plan.contoning_polygonize_color_regions_enabled && + plan.contoning_polygonize_high_resolution_enabled; + const float min_pitch = high_resolution ? 0.125f : 0.25f; + if (high_resolution) + pitch = std::max(min_pitch, pitch * 0.5f); const double width_mm = unscale(bbox.max.x() - bbox.min.x()); const double height_mm = unscale(bbox.max.y() - bbox.min.y()); - const double max_samples = 350000.0; + const double max_samples = high_resolution ? 2600000.0 : 650000.0; if (width_mm > 0.0 && height_mm > 0.0) { const double estimated = std::ceil(width_mm / double(pitch)) * std::ceil(height_mm / double(pitch)); if (estimated > max_samples) pitch = float(std::sqrt(width_mm * height_mm / max_samples)); } - return std::clamp(pitch, 0.25f, std::max(0.25f, plan.contoning_min_feature_mm)); + return std::clamp(pitch, min_pitch, std::max(min_pitch, plan.contoning_min_feature_mm)); } static float top_surface_image_contoning_angle_rad(int depth, bool varied_angles) @@ -2582,6 +2592,9 @@ static TopSurfaceImageContoningStackPlanKey top_surface_image_contoning_stack_pl key.supersampled = plan.contoning_supersampled_cells_enabled; key.blue_noise = use_blue_noise_error_diffusion; key.polygonize = plan.contoning_polygonize_color_regions_enabled; + key.polygonize_high_resolution = + plan.contoning_polygonize_color_regions_enabled && + plan.contoning_polygonize_high_resolution_enabled; return key; } @@ -3230,6 +3243,8 @@ static std::vector top_surface_image_region_plans( plan.contoning_blue_noise_error_diffusion_enabled = zone->top_surface_contoning_blue_noise_error_diffusion_enabled; plan.contoning_supersampled_cells_enabled = zone->top_surface_contoning_supersampled_cells_enabled; plan.contoning_polygonize_color_regions_enabled = zone->top_surface_contoning_polygonize_color_regions_enabled; + plan.contoning_polygonize_high_resolution_enabled = + zone->top_surface_contoning_polygonize_high_resolution_enabled; plan.contoning_surface_anchored_stacks_enabled = zone->effective_top_surface_contoning_surface_anchored_stacks_enabled(); const TextureMappingContoningSolver contoning_solver(*zone, print_config, components); diff --git a/src/libslic3r/TextureMapping.cpp b/src/libslic3r/TextureMapping.cpp index af9f94020ca..2fcaa5288ae 100644 --- a/src/libslic3r/TextureMapping.cpp +++ b/src/libslic3r/TextureMapping.cpp @@ -1145,6 +1145,7 @@ bool TextureMappingZone::operator==(const TextureMappingZone &rhs) const top_surface_contoning_blue_noise_error_diffusion_enabled == rhs.top_surface_contoning_blue_noise_error_diffusion_enabled && top_surface_contoning_supersampled_cells_enabled == rhs.top_surface_contoning_supersampled_cells_enabled && top_surface_contoning_polygonize_color_regions_enabled == rhs.top_surface_contoning_polygonize_color_regions_enabled && + top_surface_contoning_polygonize_high_resolution_enabled == rhs.top_surface_contoning_polygonize_high_resolution_enabled && effective_top_surface_contoning_surface_anchored_stacks_enabled() == rhs.effective_top_surface_contoning_surface_anchored_stacks_enabled() && compact_offset_mode == rhs.compact_offset_mode && use_legacy_fixed_color_mode == rhs.use_legacy_fixed_color_mode && @@ -1542,6 +1543,8 @@ std::string TextureMappingManager::serialize_entries() zone.top_surface_contoning_supersampled_cells_enabled; texture["top_surface_contoning_polygonize_color_regions_enabled"] = zone.top_surface_contoning_polygonize_color_regions_enabled; + texture["top_surface_contoning_polygonize_high_resolution_enabled"] = + zone.top_surface_contoning_polygonize_high_resolution_enabled; texture["top_surface_contoning_surface_anchored_stacks_enabled"] = zone.effective_top_surface_contoning_surface_anchored_stacks_enabled(); texture["compact_offset_mode"] = zone.compact_offset_mode; @@ -1831,6 +1834,9 @@ void TextureMappingManager::load_entries(const std::string &serialized, zone.top_surface_contoning_polygonize_color_regions_enabled = texture.value("top_surface_contoning_polygonize_color_regions_enabled", TextureMappingZone::DefaultTopSurfaceContoningPolygonizeColorRegionsEnabled); + zone.top_surface_contoning_polygonize_high_resolution_enabled = + texture.value("top_surface_contoning_polygonize_high_resolution_enabled", + TextureMappingZone::DefaultTopSurfaceContoningPolygonizeHighResolutionEnabled); zone.top_surface_contoning_surface_anchored_stacks_enabled = texture.value("top_surface_contoning_surface_anchored_stacks_enabled", TextureMappingZone::DefaultTopSurfaceContoningSurfaceAnchoredStacksEnabled); diff --git a/src/libslic3r/TextureMapping.hpp b/src/libslic3r/TextureMapping.hpp index 95855eef387..bc047de69d7 100644 --- a/src/libslic3r/TextureMapping.hpp +++ b/src/libslic3r/TextureMapping.hpp @@ -202,6 +202,7 @@ struct TextureMappingZone static constexpr bool DefaultTopSurfaceContoningBlueNoiseErrorDiffusionEnabled = false; static constexpr bool DefaultTopSurfaceContoningSupersampledCellsEnabled = false; static constexpr bool DefaultTopSurfaceContoningPolygonizeColorRegionsEnabled = false; + static constexpr bool DefaultTopSurfaceContoningPolygonizeHighResolutionEnabled = true; static constexpr bool DefaultTopSurfaceContoningSurfaceAnchoredStacksEnabled = false; static constexpr bool DefaultCompactOffsetMode = true; static constexpr bool DefaultUseLegacyFixedColorMode = false; @@ -354,6 +355,7 @@ struct TextureMappingZone bool top_surface_contoning_blue_noise_error_diffusion_enabled = DefaultTopSurfaceContoningBlueNoiseErrorDiffusionEnabled; bool top_surface_contoning_supersampled_cells_enabled = DefaultTopSurfaceContoningSupersampledCellsEnabled; bool top_surface_contoning_polygonize_color_regions_enabled = DefaultTopSurfaceContoningPolygonizeColorRegionsEnabled; + bool top_surface_contoning_polygonize_high_resolution_enabled = DefaultTopSurfaceContoningPolygonizeHighResolutionEnabled; bool top_surface_contoning_surface_anchored_stacks_enabled = DefaultTopSurfaceContoningSurfaceAnchoredStacksEnabled; bool compact_offset_mode = DefaultCompactOffsetMode; bool use_legacy_fixed_color_mode = DefaultUseLegacyFixedColorMode; @@ -544,6 +546,7 @@ struct TextureMappingZone top_surface_contoning_blue_noise_error_diffusion_enabled = DefaultTopSurfaceContoningBlueNoiseErrorDiffusionEnabled; top_surface_contoning_supersampled_cells_enabled = DefaultTopSurfaceContoningSupersampledCellsEnabled; top_surface_contoning_polygonize_color_regions_enabled = DefaultTopSurfaceContoningPolygonizeColorRegionsEnabled; + top_surface_contoning_polygonize_high_resolution_enabled = DefaultTopSurfaceContoningPolygonizeHighResolutionEnabled; top_surface_contoning_surface_anchored_stacks_enabled = DefaultTopSurfaceContoningSurfaceAnchoredStacksEnabled; compact_offset_mode = DefaultCompactOffsetMode; use_legacy_fixed_color_mode = DefaultUseLegacyFixedColorMode; diff --git a/src/slic3r/GUI/Plater.cpp b/src/slic3r/GUI/Plater.cpp index 4d402e40578..af596118fd5 100644 --- a/src/slic3r/GUI/Plater.cpp +++ b/src/slic3r/GUI/Plater.cpp @@ -1982,6 +1982,7 @@ public: bool top_surface_contoning_blue_noise_error_diffusion_enabled, bool top_surface_contoning_supersampled_cells_enabled, bool top_surface_contoning_polygonize_color_regions_enabled, + bool top_surface_contoning_polygonize_high_resolution_enabled, bool top_surface_contoning_surface_anchored_stacks_enabled, const TextureMappingManager &texture_mapping_zones, const TextureMappingGlobalSettings &global_settings, @@ -2768,6 +2769,15 @@ public: 0, wxEXPAND | wxTOP | wxBOTTOM, gap / 2); + m_top_surface_contoning_polygonize_high_resolution_checkbox = + new wxCheckBox(m_top_surface_contoning_checkboxes_panel, wxID_ANY, _L("High-resolution polygon tracing")); + m_top_surface_contoning_polygonize_high_resolution_checkbox->SetValue(top_surface_contoning_polygonize_high_resolution_enabled); + m_top_surface_contoning_polygonize_high_resolution_checkbox->SetMinSize( + wxSize(-1, std::max(m_top_surface_contoning_polygonize_high_resolution_checkbox->GetBestSize().GetHeight(), FromDIP(24)))); + contoning_checkboxes_root->Add(m_top_surface_contoning_polygonize_high_resolution_checkbox, + 0, + wxEXPAND | wxTOP | wxBOTTOM, + gap / 2); if (TextureMappingZone::ShowExperimentalTopSurfaceContoningOptions) { m_top_surface_contoning_surface_anchored_stacks_checkbox = new wxCheckBox(m_top_surface_contoning_checkboxes_panel, wxID_ANY, _L("Surface-anchored stacks")); @@ -2805,6 +2815,11 @@ public: update_top_surface_image_options_visibility(true); }); } + if (m_top_surface_contoning_polygonize_color_regions_checkbox != nullptr) { + m_top_surface_contoning_polygonize_color_regions_checkbox->Bind(wxEVT_CHECKBOX, [this](wxCommandEvent &) { + update_top_surface_image_options_visibility(true); + }); + } m_top_surface_image_printing_enabled_checkbox->Bind(wxEVT_CHECKBOX, [this](wxCommandEvent &) { update_top_surface_image_options_visibility(true); }); @@ -3224,6 +3239,12 @@ public: return m_top_surface_contoning_polygonize_color_regions_checkbox != nullptr && m_top_surface_contoning_polygonize_color_regions_checkbox->GetValue(); } + bool top_surface_contoning_polygonize_high_resolution_enabled() const + { + return m_top_surface_contoning_polygonize_high_resolution_checkbox == nullptr ? + TextureMappingZone::DefaultTopSurfaceContoningPolygonizeHighResolutionEnabled : + m_top_surface_contoning_polygonize_high_resolution_checkbox->GetValue(); + } bool top_surface_contoning_surface_anchored_stacks_enabled() const { if (!TextureMappingZone::ShowExperimentalTopSurfaceContoningOptions) @@ -3732,6 +3753,14 @@ private: m_top_surface_contoning_polygonize_color_regions_checkbox->Show(contoning); m_top_surface_contoning_polygonize_color_regions_checkbox->Enable(contoning); } + const bool polygonize_color_regions = + contoning && + m_top_surface_contoning_polygonize_color_regions_checkbox != nullptr && + m_top_surface_contoning_polygonize_color_regions_checkbox->GetValue(); + if (m_top_surface_contoning_polygonize_high_resolution_checkbox != nullptr) { + m_top_surface_contoning_polygonize_high_resolution_checkbox->Show(polygonize_color_regions); + m_top_surface_contoning_polygonize_high_resolution_checkbox->Enable(polygonize_color_regions); + } if (m_top_surface_contoning_surface_anchored_stacks_checkbox != nullptr) { m_top_surface_contoning_surface_anchored_stacks_checkbox->Show(contoning); m_top_surface_contoning_surface_anchored_stacks_checkbox->Enable(contoning); @@ -3810,6 +3839,7 @@ private: wxCheckBox *m_top_surface_contoning_blue_noise_error_diffusion_checkbox {nullptr}; wxCheckBox *m_top_surface_contoning_supersampled_cells_checkbox {nullptr}; wxCheckBox *m_top_surface_contoning_polygonize_color_regions_checkbox {nullptr}; + wxCheckBox *m_top_surface_contoning_polygonize_high_resolution_checkbox {nullptr}; wxCheckBox *m_top_surface_contoning_surface_anchored_stacks_checkbox {nullptr}; wxCheckBox *m_use_legacy_fixed_color_mode_checkbox {nullptr}; wxCheckBox *m_minimum_visibility_offset_checkbox {nullptr}; @@ -8833,6 +8863,7 @@ void Sidebar::update_texture_mapping_panel(bool sync_manager) updated.top_surface_contoning_blue_noise_error_diffusion_enabled, updated.top_surface_contoning_supersampled_cells_enabled, updated.top_surface_contoning_polygonize_color_regions_enabled, + updated.top_surface_contoning_polygonize_high_resolution_enabled, updated.top_surface_contoning_surface_anchored_stacks_enabled, bundle->texture_mapping_zones, bundle->texture_mapping_global_settings, @@ -8905,6 +8936,8 @@ void Sidebar::update_texture_mapping_panel(bool sync_manager) dlg.top_surface_contoning_supersampled_cells_enabled(); updated.top_surface_contoning_polygonize_color_regions_enabled = dlg.top_surface_contoning_polygonize_color_regions_enabled(); + updated.top_surface_contoning_polygonize_high_resolution_enabled = + dlg.top_surface_contoning_polygonize_high_resolution_enabled(); updated.top_surface_contoning_surface_anchored_stacks_enabled = dlg.top_surface_contoning_surface_anchored_stacks_enabled(); if (updated.top_surface_image_printing_enabled &&