Hide factory include into cpp file

+ remove unused minimal island area
This commit is contained in:
Filip Sykala - NTB T15p 2025-02-21 09:16:00 +01:00 committed by Lukas Matena
parent 63ea165f00
commit 60e8163900
2 changed files with 96 additions and 58 deletions

View File

@ -10,8 +10,10 @@
#include "libslic3r/KDTreeIndirect.hpp" #include "libslic3r/KDTreeIndirect.hpp"
#include "libslic3r/ClipperUtils.hpp" #include "libslic3r/ClipperUtils.hpp"
#include "libslic3r/AABBTreeLines.hpp" // closest point to layer part #include "libslic3r/AABBTreeLines.hpp" // closest point to layer part
#include "libslic3r/AABBMesh.hpp" // move_on_mesh_surface Should be in another file
// SupportIslands // SupportIslands
#include "libslic3r/SLA/SupportIslands/UniformSupportIsland.hpp" #include "libslic3r/SLA/SupportIslands/UniformSupportIsland.hpp"
#include "libslic3r/SLA/SupportIslands/SampleConfigFactory.hpp"
using namespace Slic3r; using namespace Slic3r;
using namespace Slic3r::sla; using namespace Slic3r::sla;
@ -798,6 +800,7 @@ SupportPointGeneratorData Slic3r::sla::prepare_generator_data(
return result; return result;
} }
#ifdef USE_ISLAND_GUI_FOR_SETTINGS
#include "libslic3r/NSVGUtils.hpp" #include "libslic3r/NSVGUtils.hpp"
#include "libslic3r/Utils.hpp" #include "libslic3r/Utils.hpp"
std::vector<Vec2f> load_curve_from_file() { std::vector<Vec2f> load_curve_from_file() {
@ -837,6 +840,7 @@ std::vector<Vec2f> load_curve_from_file() {
assert(false); assert(false);
return {}; return {};
} }
#endif // USE_ISLAND_GUI_FOR_SETTINGS
// Processing permanent support points // Processing permanent support points
// Permanent are manualy edited points by user // Permanent are manualy edited points by user
@ -1165,20 +1169,41 @@ Points get_permanents(const PermanentSupports &supports, size_t support_index,
} // namespace } // namespace
LayerSupportPoints Slic3r::sla::generate_support_points( namespace Slic3r::sla {
using namespace Slic3r;
std::vector<Vec2f> create_default_support_curve(){
#ifdef USE_ISLAND_GUI_FOR_SETTINGS
return {};
#else // USE_ISLAND_GUI_FOR_SETTINGS
return std::vector<Vec2f>{
Vec2f{3.2f, 0.f},
Vec2f{4.f, 3.9f},
Vec2f{5.f, 15.f},
Vec2f{6.f, 40.f},
};
#endif // USE_ISLAND_GUI_FOR_SETTINGS
}
SampleConfig create_default_island_configuration(float head_diameter_in_mm) {
return SampleConfigFactory::create(head_diameter_in_mm);
}
LayerSupportPoints generate_support_points(
const SupportPointGeneratorData &data, const SupportPointGeneratorData &data,
const SupportPointGeneratorConfig &config, const SupportPointGeneratorConfig &config,
ThrowOnCancel throw_on_cancel, ThrowOnCancel throw_on_cancel,
StatusFunction statusfn StatusFunction statusfn
){ ) {
const Layers &layers = data.layers; const Layers &layers = data.layers;
double increment = 100.0 / static_cast<double>(layers.size()); double increment = 100.0 / static_cast<double>(layers.size());
double status = 0; // current progress double status = 0; // current progress
int status_int = 0; int status_int = 0;
#ifdef USE_ISLAND_GUI_FOR_SETTINGS
// Hack to set curve for testing // Hack to set curve for testing
if (config.support_curve.empty()) if (config.support_curve.empty())
const_cast<SupportPointGeneratorConfig &>(config).support_curve = load_curve_from_file(); const_cast<SupportPointGeneratorConfig &>(config).support_curve = load_curve_from_file();
#endif // USE_ISLAND_GUI_FOR_SETTINGS
// Maximal radius of supported area of one support point // Maximal radius of supported area of one support point
double max_support_radius = config.support_curve.back().x(); double max_support_radius = config.support_curve.back().x();
@ -1207,9 +1232,13 @@ LayerSupportPoints Slic3r::sla::generate_support_points(
size_t part_id = &part - &layer.parts.front(); size_t part_id = &part - &layer.parts.front();
if (part.prev_parts.empty()) { // Island ? if (part.prev_parts.empty()) { // Island ?
grids.emplace_back(&result); // only island add new grid grids.emplace_back(&result); // only island add new grid
Points permanent = get_permanents(permanent_supports, permanent_index, layer_id, part_id); Points permanent =
get_permanents(permanent_supports, permanent_index, layer_id, part_id);
support_island(part, grids.back(), layer.print_z, permanent, config); support_island(part, grids.back(), layer.print_z, permanent, config);
copy_permanent_supports(grids.back(), permanent_supports, permanent_index, layer.print_z, layer_id, part_id, config); copy_permanent_supports(
grids.back(), permanent_supports, permanent_index, layer.print_z, layer_id,
part_id, config
);
continue; continue;
} }
@ -1220,10 +1249,14 @@ LayerSupportPoints Slic3r::sla::generate_support_points(
remove_supports_out_of_part(near_points, part, layer.print_z); remove_supports_out_of_part(near_points, part, layer.print_z);
if (!part.peninsulas.empty()) { if (!part.peninsulas.empty()) {
// only get copy of points do not modify permanent_index // only get copy of points do not modify permanent_index
Points permanent = get_permanents(permanent_supports, permanent_index, layer_id, part_id); Points permanent =
get_permanents(permanent_supports, permanent_index, layer_id, part_id);
support_peninsulas(part.peninsulas, near_points, layer.print_z, permanent, config); support_peninsulas(part.peninsulas, near_points, layer.print_z, permanent, config);
} }
copy_permanent_supports(near_points, permanent_supports, permanent_index, layer.print_z, layer_id, part_id, config); copy_permanent_supports(
near_points, permanent_supports, permanent_index, layer.print_z, layer_id, part_id,
config
);
support_part_overhangs(part, config, near_points, layer.print_z, maximal_radius); support_part_overhangs(part, config, near_points, layer.print_z, maximal_radius);
grids.push_back(std::move(near_points)); grids.push_back(std::move(near_points));
} }
@ -1239,14 +1272,16 @@ LayerSupportPoints Slic3r::sla::generate_support_points(
} }
// Remove permanent supports from result // Remove permanent supports from result
// To preserve permanent 3d position it is necessary to append points after move_on_mesh_surface // To preserve permanent 3d position it is necessary to append points after move_on_mesh_surface
result.erase(std::remove_if(result.begin(), result.end(), result.erase(
[](const LayerSupportPoint &p) { return p.is_permanent; }), result.end()); std::remove_if(
result.begin(), result.end(), [](const LayerSupportPoint &p) { return p.is_permanent; }
),
result.end()
);
return result; return result;
} }
// TODO: Should be in another file SupportPoints move_on_mesh_surface(
#include "libslic3r/AABBMesh.hpp"
SupportPoints Slic3r::sla::move_on_mesh_surface(
const LayerSupportPoints &points, const LayerSupportPoints &points,
const AABBMesh &mesh, const AABBMesh &mesh,
double allowed_move, double allowed_move,
@ -1258,13 +1293,15 @@ SupportPoints Slic3r::sla::move_on_mesh_surface(
pts.push_back(static_cast<SupportPoint>(p)); pts.push_back(static_cast<SupportPoint>(p));
// The function makes sure that all the points are really exactly placed on the mesh. // The function makes sure that all the points are really exactly placed on the mesh.
execution::for_each(ex_tbb, size_t(0), pts.size(), [&pts, &mesh, &throw_on_cancel, allowed_move](size_t idx) execution::for_each(
{ ex_tbb, size_t(0), pts.size(),
[&pts, &mesh, &throw_on_cancel, allowed_move](size_t idx) {
if ((idx % 16) == 0) if ((idx % 16) == 0)
// Don't call the following function too often as it flushes CPU write caches due to synchronization primitves. // Don't call the following function too often as it flushes CPU write caches due to
// synchronization primitves.
throw_on_cancel(); throw_on_cancel();
Vec3f& p = pts[idx].pos; Vec3f &p = pts[idx].pos;
Vec3d p_double = p.cast<double>(); Vec3d p_double = p.cast<double>();
const Vec3d up_vec(0., 0., 1.); const Vec3d up_vec(0., 0., 1.);
const Vec3d down_vec(0., 0., -1.); const Vec3d down_vec(0., 0., -1.);
@ -1275,12 +1312,14 @@ SupportPoints Slic3r::sla::move_on_mesh_surface(
bool up = hit_up.is_hit(); bool up = hit_up.is_hit();
bool down = hit_down.is_hit(); bool down = hit_down.is_hit();
// no hit means support points lay exactly on triangle surface // no hit means support points lay exactly on triangle surface
if (!up && !down) return; if (!up && !down)
return;
AABBMesh::hit_result &hit = (!down || hit_up.distance() < hit_down.distance()) ? hit_up : hit_down; AABBMesh::hit_result &hit = (!down || hit_up.distance() < hit_down.distance()) ?
hit_up :
hit_down;
if (hit.distance() <= allowed_move) { if (hit.distance() <= allowed_move) {
p[2] += static_cast<float>(hit.distance() * p[2] += static_cast<float>(hit.distance() * hit.direction()[2]);
hit.direction()[2]);
return; return;
} }
@ -1288,8 +1327,13 @@ SupportPoints Slic3r::sla::move_on_mesh_surface(
int triangle_index; int triangle_index;
Vec3d closest_point; Vec3d closest_point;
double distance = mesh.squared_distance(p_double, triangle_index, closest_point); double distance = mesh.squared_distance(p_double, triangle_index, closest_point);
if (distance <= std::numeric_limits<float>::epsilon()) return; // correct coordinate if (distance <= std::numeric_limits<float>::epsilon())
return; // correct coordinate
p = closest_point.cast<float>(); p = closest_point.cast<float>();
}, 64 /* gransize */); },
64 /* gransize */
);
return pts; return pts;
} }
} // namespace Slic3r::sla

View File

@ -14,10 +14,12 @@
#include "libslic3r/ExPolygon.hpp" #include "libslic3r/ExPolygon.hpp"
#include "libslic3r/SLA/SupportPoint.hpp" #include "libslic3r/SLA/SupportPoint.hpp"
#include "libslic3r/SLA/SupportIslands/SampleConfig.hpp" #include "libslic3r/SLA/SupportIslands/SampleConfig.hpp"
#include "libslic3r/SLA/SupportIslands/SampleConfigFactory.hpp"
namespace Slic3r::sla { namespace Slic3r::sla {
std::vector<Vec2f> create_default_support_curve();
SampleConfig create_default_island_configuration(float head_diameter_in_mm);
/// <summary> /// <summary>
/// Configuration for automatic support placement /// Configuration for automatic support placement
/// </summary> /// </summary>
@ -35,22 +37,14 @@ struct SupportPointGeneratorConfig{
/// </summary> /// </summary>
float head_diameter = 0.4f; // [in mm] float head_diameter = 0.4f; // [in mm]
// FIXME: calculate actual pixel area from printer config:
// const float pixel_area =
// pow(wxGetApp().preset_bundle->project_config.option<ConfigOptionFloat>("display_width") /
// wxGetApp().preset_bundle->project_config.option<ConfigOptionInt>("display_pixels_x"), 2.f); //
// Minimal island Area to print - TODO: Should be modifiable from UI
// !! Filter should be out of sampling algorithm !!
float minimal_island_area = pow(0.047f, 2.f); // [in mm^2] pixel_area
// maximal distance to nearest support point(define radiuses per layer) // maximal distance to nearest support point(define radiuses per layer)
// x axis .. mean distance on layer(XY) // x axis .. mean distance on layer(XY)
// y axis .. mean difference of height(Z) // y axis .. mean difference of height(Z)
// Points of lines [in mm] // Points of lines [in mm]
std::vector<Vec2f> support_curve; std::vector<Vec2f> support_curve = create_default_support_curve();
// Configuration for sampling island // Configuration for sampling island
SampleConfig island_configuration = SampleConfigFactory::create(head_diameter); SampleConfig island_configuration = create_default_island_configuration(head_diameter);
// maximal allowed distance to layer part for permanent(manual edited) support // maximal allowed distance to layer part for permanent(manual edited) support
// helps to identify not wanted support points during automatic support generation. // helps to identify not wanted support points during automatic support generation.