Density change quadraticaly supported radius

This commit is contained in:
Filip Sykala - NTB T15p 2025-01-24 16:40:15 +01:00 committed by Lukas Matena
parent 998175137c
commit 5dec0ea57a
2 changed files with 35 additions and 26 deletions

View File

@ -143,7 +143,10 @@ public:
m_tree.build(indices); // consume indices
}
private:
/// <summary>
/// Getter on used indices
/// </summary>
/// <returns>Current used Indices into m_points</returns>
std::vector<size_t> get_indices() const {
std::vector<size_t> indices = m_tree.get_nodes(); // copy
// nodes in tree contain "max values for size_t" on unused leaf of tree,
@ -154,6 +157,7 @@ private:
return indices;
}
};
using NearPointss = std::vector<NearPoints>;
/// <summary>
/// Intersection of line segment and circle
@ -209,7 +213,7 @@ Point intersection_line_circle(const Point &p1, const Point &p2, const Point &cn
NearPoints create_near_points(
const LayerParts &prev_layer_parts,
const LayerPart &part,
std::vector<NearPoints> &prev_grids
NearPointss &prev_grids
) {
const LayerParts::const_iterator &prev_part_it = part.prev_parts.front();
size_t index_of_prev_part = prev_part_it - prev_layer_parts.begin();
@ -480,25 +484,32 @@ Points sample_overhangs(const LayerPart& part, double dist2) {
}
coord_t calc_influence_radius(float z_distance, const SupportPointGeneratorConfig &config) {
float island_support_distance = config.support_curve.front().x() / config.density_relative;
if (z_distance >= island_support_distance)
float island_support_distance_sq = sqr(config.support_curve.front().x());
if (!is_approx(config.density_relative, 1.f, 1e-4f)) // exist relative density
island_support_distance_sq /= config.density_relative;
float z_distance_sq = sqr(z_distance);
if (z_distance_sq >= island_support_distance_sq)
return 0.f;
// IMPROVE: use curve interpolation instead of sqrt(stored in config).
// shape of supported area before permanent supports is sphere with radius of island_support_distance
return static_cast<coord_t>(scale_(
std::sqrt(sqr(island_support_distance) - sqr(z_distance))
));
return static_cast<coord_t>(scale_(std::sqrt(island_support_distance_sq - z_distance_sq)));
}
void prepare_supports_for_layer(LayerSupportPoints &supports, float layer_z,
const SupportPointGeneratorConfig &config) {
const NearPointss& activ_points, const SupportPointGeneratorConfig &config) {
auto set_radius = [&config](LayerSupportPoint &support, float radius) {
if (!is_approx(config.density_relative, 1.f, 1e-4f)) // exist relative density
radius /= config.density_relative;
radius = std::sqrt(sqr(radius) / config.density_relative);
support.current_radius = static_cast<coord_t>(scale_(radius));
};
std::vector<bool> is_active(supports.size(), {false});
for (const NearPoints& pts : activ_points) {
std::vector<size_t> indices = pts.get_indices();
for (size_t i : indices)
is_active[i] = true;
}
const std::vector<Vec2f>& curve = config.support_curve;
// calculate support area for each support point as radius
// IMPROVE: use some offsets of previous supported island
@ -507,6 +518,9 @@ void prepare_supports_for_layer(LayerSupportPoints &supports, float layer_z,
if (index + 1 >= curve.size())
continue; // already contain maximal radius
if (!is_active[&support - &supports.front()])
continue; // Point is not used in any part of the current layer
// find current segment
float diff_z = layer_z - support.pos.z();
if (diff_z < 0.) {
@ -1180,13 +1194,13 @@ LayerSupportPoints Slic3r::sla::generate_support_points(
prepare_permanent_supports(data.permanent_supports, layers, config);
// grid index == part in layer index
std::vector<NearPoints> prev_grids; // same count as previous layer item size
NearPointss prev_grids; // same count as previous layer item size
for (size_t layer_id = 0; layer_id < layers.size(); ++layer_id) {
const Layer &layer = layers[layer_id];
prepare_supports_for_layer(result, layer.print_z, config);
prepare_supports_for_layer(result, layer.print_z, prev_grids, config);
// grid index == part in layer index
std::vector<NearPoints> grids;
NearPointss grids;
grids.reserve(layer.parts.size());
for (const LayerPart &part : layer.parts) {

View File

@ -297,8 +297,10 @@ void GLGizmoSlaSupports::render_points(const Selection& selection)
if (clipped)
continue;
render_color = support_point.type == sla::SupportPointType::manual_add ?
manual_color : inactive_color;
render_color =
support_point.type == sla::SupportPointType::manual_add ? manual_color :
support_point.type == sla::SupportPointType::island ? island_color :
inactive_color;
// First decide about the color of the point.
if (m_editing_mode) {
if (size_t(m_hover_id) == i) // ignore hover state unless editing mode is active
@ -307,7 +309,7 @@ void GLGizmoSlaSupports::render_points(const Selection& selection)
render_color = selected_color;
else if (m_lock_unique_islands) {
render_color = support_point.type == sla::SupportPointType::island?
island_color : ColorRGBA{ 0.7f, 0.7f, 0.7f, 1.f };
island_color : inactive_color;
}
}
@ -744,16 +746,9 @@ RENDER_AGAIN:
const char *support_points_density = "support_points_density_relative";
float density = static_cast<const ConfigOptionInt*>(get_config_options({support_points_density})[0])->value;
float old_density = density;
wxString tooltip = _L(
"Divider for the supported radius\n"
"Smaller value means less point, supported radius is enlarged.\n"
"Larger value means more points, supported radius is reduced.\n"
"-- density percent ----- radisu change from 100 --\n"
"| 50 | 200 |\n"
"| 75 | 133 |\n"
"| 125 | 80 |\n"
"| 150 | 66 |\n"
"| 200 | 50 |\n");
wxString tooltip = _L("Change amount of the generated support points.\n"
"Smaller value means less points and\n"
"larger value means more points.");
if (m_imgui->slider_float("##density", &density, 50.f, 200.f, "%.f %%", 1.f, false, tooltip)){
if (density < 10.f) // not neccessary, but lower value seems pointless. Zero cause issues inside algorithms.
density = 10.f;