OrcaSlicer latest
OrcaSlicer
Loading...
Searching...
No Matches
Slic3r::Arachne::DistributedBeadingStrategy Class Reference

#include </home/runner/work/OrcaSlicer/OrcaSlicer/src/libslic3r/Arachne/BeadingStrategy/DistributedBeadingStrategy.hpp>

Inheritance diagram for Slic3r::Arachne::DistributedBeadingStrategy:
Collaboration diagram for Slic3r::Arachne::DistributedBeadingStrategy:

Public Member Functions

 DistributedBeadingStrategy (coord_t optimal_width, coord_t default_transition_length, double transitioning_angle, double wall_split_middle_threshold, double wall_add_middle_threshold, int distribution_radius)
 ~DistributedBeadingStrategy () override=default
Beading compute (coord_t thickness, coord_t bead_count) const override
coord_t getOptimalBeadCount (coord_t thickness) const override
virtual coord_t getOptimalThickness (coord_t bead_count) const
virtual coord_t getTransitionThickness (coord_t lower_bead_count) const
virtual coord_t getTransitioningLength (coord_t lower_bead_count) const
virtual float getTransitionAnchorPos (coord_t lower_bead_count) const
virtual std::vector< coord_t > getNonlinearThicknesses (coord_t lower_bead_count) const
virtual std::string toString () const
double getSplitMiddleThreshold () const
double getTransitioningAngle () const

Protected Attributes

float one_over_distribution_radius_squared
std::string name
coord_t optimal_width
double wall_split_middle_threshold
 Optimal bead width, nominal width off the walls in 'ideal' circumstances.
double wall_add_middle_threshold
 Threshold when a middle wall should be split into two, as a ratio of the optimal wall width.
coord_t default_transition_length
 Threshold when a new middle wall should be added between an even number of walls, as a ratio of the optimal wall width.
double transitioning_angle
 The length of the region to smoothly transfer between bead counts.

Detailed Description

This beading strategy chooses a wall count that would make the line width deviate the least from the optimal line width, and then distributes the lines evenly among the thickness available.

Constructor & Destructor Documentation

◆ DistributedBeadingStrategy()

Slic3r::Arachne::DistributedBeadingStrategy::DistributedBeadingStrategy ( coord_t optimal_width,
coord_t default_transition_length,
double transitioning_angle,
double wall_split_middle_threshold,
double wall_add_middle_threshold,
int distribution_radius )
Parameters
distribution_radiusthe radius (in number of beads) over which to distribute the discrepancy between the feature size and the optimal thickness
22{
23 if(distribution_radius >= 2)
24 one_over_distribution_radius_squared = 1.0f / (distribution_radius - 1) * 1.0f / (distribution_radius - 1);
25 else
26 one_over_distribution_radius_squared = 1.0f / 1 * 1.0f / 1;
27 name = "DistributedBeadingStrategy";
28}
double wall_add_middle_threshold
Threshold when a middle wall should be split into two, as a ratio of the optimal wall width.
Definition BeadingStrategy.hpp:107
coord_t optimal_width
Definition BeadingStrategy.hpp:103
std::string name
Definition BeadingStrategy.hpp:101
double transitioning_angle
The length of the region to smoothly transfer between bead counts.
Definition BeadingStrategy.hpp:115
double wall_split_middle_threshold
Optimal bead width, nominal width off the walls in 'ideal' circumstances.
Definition BeadingStrategy.hpp:105
BeadingStrategy(coord_t optimal_width, double wall_split_middle_threshold, double wall_add_middle_threshold, coord_t default_transition_length, float transitioning_angle=pi_div(3))
Definition BeadingStrategy.cpp:12
coord_t default_transition_length
Threshold when a new middle wall should be added between an even number of walls, as a ratio of the o...
Definition BeadingStrategy.hpp:109
float one_over_distribution_radius_squared
Definition DistributedBeadingStrategy.hpp:21

References Slic3r::Arachne::BeadingStrategy::BeadingStrategy(), Slic3r::Arachne::BeadingStrategy::default_transition_length, Slic3r::Arachne::BeadingStrategy::name, one_over_distribution_radius_squared, Slic3r::Arachne::BeadingStrategy::optimal_width, Slic3r::Arachne::BeadingStrategy::transitioning_angle, Slic3r::Arachne::BeadingStrategy::wall_add_middle_threshold, and Slic3r::Arachne::BeadingStrategy::wall_split_middle_threshold.

Here is the call graph for this function:

◆ ~DistributedBeadingStrategy()

Slic3r::Arachne::DistributedBeadingStrategy::~DistributedBeadingStrategy ( )
overridedefault

Member Function Documentation

◆ compute()

DistributedBeadingStrategy::Beading Slic3r::Arachne::DistributedBeadingStrategy::compute ( coord_t thickness,
coord_t bead_count ) const
overridevirtual

Retrieve the bead widths with which to cover a given thickness.

Requirement: Given a constant bead_count the output of each bead width must change gradually along with the thickness.

Note
The bead_count might be different from the BeadingStrategy::optimal_bead_count

Implements Slic3r::Arachne::BeadingStrategy.

31{
32 Beading ret;
33
34 ret.total_thickness = thickness;
35 if (bead_count > 2) {
36 const coord_t to_be_divided = thickness - bead_count * optimal_width;
37 const float middle = static_cast<float>(bead_count - 1) / 2;
38
39 const auto getWeight = [middle, this](coord_t bead_idx) {
40 const float dev_from_middle = bead_idx - middle;
41 return std::max(0.0f, 1.0f - one_over_distribution_radius_squared * dev_from_middle * dev_from_middle);
42 };
43
44 std::vector<float> weights;
45 weights.resize(bead_count);
46 for (coord_t bead_idx = 0; bead_idx < bead_count; bead_idx++)
47 weights[bead_idx] = getWeight(bead_idx);
48
49 const float total_weight = std::accumulate(weights.cbegin(), weights.cend(), 0.f);
50 coord_t accumulated_width = 0;
51 for (coord_t bead_idx = 0; bead_idx < bead_count; bead_idx++) {
52 const float weight_fraction = weights[bead_idx] / total_weight;
53 const coord_t splitup_left_over_weight = to_be_divided * weight_fraction;
54 const coord_t width = (bead_idx == bead_count - 1) ? thickness - accumulated_width : optimal_width + splitup_left_over_weight;
55
56 // Be aware that toolpath_locations is computed by dividing the width by 2, so toolpath_locations
57 // could be off by 1 because of rounding errors.
58 if (bead_idx == 0)
59 ret.toolpath_locations.emplace_back(width / 2);
60 else
61 ret.toolpath_locations.emplace_back(ret.toolpath_locations.back() + (ret.bead_widths.back() + width) / 2);
62 ret.bead_widths.emplace_back(width);
63 accumulated_width += width;
64 }
65 ret.left_over = 0;
66 assert((accumulated_width + ret.left_over) == thickness);
67 } else if (bead_count == 2) {
68 const coord_t outer_width = thickness / 2;
69 ret.bead_widths.emplace_back(outer_width);
70 ret.bead_widths.emplace_back(outer_width);
71 ret.toolpath_locations.emplace_back(outer_width / 2);
72 ret.toolpath_locations.emplace_back(thickness - outer_width / 2);
73 ret.left_over = 0;
74 } else if (bead_count == 1) {
75 const coord_t outer_width = thickness;
76 ret.bead_widths.emplace_back(outer_width);
77 ret.toolpath_locations.emplace_back(outer_width / 2);
78 ret.left_over = 0;
79 } else {
80 ret.left_over = thickness;
81 }
82
83 assert(([&ret = std::as_const(ret), thickness]() -> bool {
84 coord_t total_bead_width = 0;
85 for (const coord_t &bead_width : ret.bead_widths)
86 total_bead_width += bead_width;
87 return (total_bead_width + ret.left_over) == thickness;
88 }()));
89
90 return ret;
91}
coord_t total_thickness
Definition BeadingStrategy.hpp:37
Definition BeadingStrategy.hpp:36
int64_t coord_t
Definition libslic3r.h:48
coord_t width(const BoundingBox &box)
Definition Arrange.cpp:1184

References Slic3r::Arachne::BeadingStrategy::Beading::bead_widths, Slic3r::Arachne::BeadingStrategy::Beading::left_over, one_over_distribution_radius_squared, Slic3r::Arachne::BeadingStrategy::optimal_width, Slic3r::Arachne::BeadingStrategy::Beading::toolpath_locations, and Slic3r::Arachne::BeadingStrategy::Beading::total_thickness.

◆ getNonlinearThicknesses()

std::vector< coord_t > Slic3r::Arachne::BeadingStrategy::getNonlinearThicknesses ( coord_t lower_bead_count) const
virtualinherited

Get the locations in a bead count region where BeadingStrategy::compute exhibits a bend in the widths. Ordered from lower thickness to higher.

This is used to insert extra support bones into the skeleton, so that the resulting beads in long trapezoids don't linearly change between the two ends.

Reimplemented in Slic3r::Arachne::WideningBeadingStrategy.

47{
48 return {};
49}

◆ getOptimalBeadCount()

coord_t Slic3r::Arachne::DistributedBeadingStrategy::getOptimalBeadCount ( coord_t thickness) const
overridevirtual

The number of beads should we ideally usefor a given model thickness

Implements Slic3r::Arachne::BeadingStrategy.

94{
95 const coord_t naive_count = thickness / optimal_width; // How many lines we can fit in for sure.
96 const coord_t remainder = thickness - naive_count * optimal_width; // Space left after fitting that many lines.
97 const coord_t minimum_line_width = optimal_width * (naive_count % 2 == 1 ? wall_split_middle_threshold : wall_add_middle_threshold);
98 return naive_count + (remainder >= minimum_line_width); // If there's enough space, fit an extra one.
99}

References Slic3r::Arachne::BeadingStrategy::optimal_width, Slic3r::Arachne::BeadingStrategy::wall_add_middle_threshold, and Slic3r::Arachne::BeadingStrategy::wall_split_middle_threshold.

◆ getOptimalThickness()

coord_t Slic3r::Arachne::BeadingStrategy::getOptimalThickness ( coord_t bead_count) const
virtualinherited

The ideal thickness for a given

Parameters
bead_count

Reimplemented in Slic3r::Arachne::LimitedBeadingStrategy, Slic3r::Arachne::OuterWallInsetBeadingStrategy, Slic3r::Arachne::RedistributeBeadingStrategy, and Slic3r::Arachne::WideningBeadingStrategy.

67{
68 return optimal_width * bead_count;
69}

References optimal_width.

Referenced by getTransitionAnchorPos(), and getTransitionThickness().

Here is the caller graph for this function:

◆ getSplitMiddleThreshold()

double Slic3r::Arachne::BeadingStrategy::getSplitMiddleThreshold ( ) const
inherited

◆ getTransitionAnchorPos()

float Slic3r::Arachne::BeadingStrategy::getTransitionAnchorPos ( coord_t lower_bead_count) const
virtualinherited

The fraction of the transition length to put between the lower end of the transition and the point where the unsmoothed bead count jumps.

Transitions are used to smooth out the jumps in integer bead count; the jumps turn into ramps which could be positioned relative to the jump location.

Reimplemented in Slic3r::Arachne::LimitedBeadingStrategy, Slic3r::Arachne::RedistributeBeadingStrategy, and Slic3r::Arachne::WideningBeadingStrategy.

39{
40 coord_t lower_optimum = getOptimalThickness(lower_bead_count);
41 coord_t transition_point = getTransitionThickness(lower_bead_count);
42 coord_t upper_optimum = getOptimalThickness(lower_bead_count + 1);
43 return 1.0 - float(transition_point - lower_optimum) / float(upper_optimum - lower_optimum);
44}
virtual coord_t getOptimalThickness(coord_t bead_count) const
Definition BeadingStrategy.cpp:66
virtual coord_t getTransitionThickness(coord_t lower_bead_count) const
Definition BeadingStrategy.cpp:71

References getOptimalThickness(), and getTransitionThickness().

Here is the call graph for this function:

◆ getTransitioningAngle()

double Slic3r::Arachne::BeadingStrategy::getTransitioningAngle ( ) const
inherited
62{
64}

References transitioning_angle.

◆ getTransitioningLength()

coord_t Slic3r::Arachne::BeadingStrategy::getTransitioningLength ( coord_t lower_bead_count) const
virtualinherited

The length of the transitioning region along the marked / significant regions of the skeleton.

Transitions are used to smooth out the jumps in integer bead count; the jumps turn into ramps with some incline defined by their length.

Reimplemented in Slic3r::Arachne::LimitedBeadingStrategy, Slic3r::Arachne::OuterWallInsetBeadingStrategy, Slic3r::Arachne::RedistributeBeadingStrategy, and Slic3r::Arachne::WideningBeadingStrategy.

32{
33 if (lower_bead_count == 0)
34 return scaled<coord_t>(0.01);
36}
BoundingBox scaled(const BoundingBoxf &bb)
Definition BoundingBox.hpp:284

References default_transition_length, and Slic3r::scaled().

Here is the call graph for this function:

◆ getTransitionThickness()

coord_t Slic3r::Arachne::BeadingStrategy::getTransitionThickness ( coord_t lower_bead_count) const
virtualinherited

The model thickness at which BeadingStrategy::optimal_bead_count transitions from lower_bead_count to lower_bead_count + 1

Reimplemented in Slic3r::Arachne::LimitedBeadingStrategy, Slic3r::Arachne::OuterWallInsetBeadingStrategy, Slic3r::Arachne::RedistributeBeadingStrategy, and Slic3r::Arachne::WideningBeadingStrategy.

72{
73 const coord_t lower_ideal_width = getOptimalThickness(lower_bead_count);
74 const coord_t higher_ideal_width = getOptimalThickness(lower_bead_count + 1);
75 const double threshold = lower_bead_count % 2 == 1 ? wall_split_middle_threshold : wall_add_middle_threshold;
76 return lower_ideal_width + threshold * (higher_ideal_width - lower_ideal_width);
77}

References getOptimalThickness(), wall_add_middle_threshold, and wall_split_middle_threshold.

Referenced by getTransitionAnchorPos().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ toString()

std::string Slic3r::Arachne::BeadingStrategy::toString ( ) const
virtualinherited

Member Data Documentation

◆ default_transition_length

coord_t Slic3r::Arachne::BeadingStrategy::default_transition_length
protectedinherited

Threshold when a new middle wall should be added between an even number of walls, as a ratio of the optimal wall width.

Referenced by BeadingStrategy(), BeadingStrategy(), Slic3r::Arachne::DistributedBeadingStrategy::DistributedBeadingStrategy(), and getTransitioningLength().

◆ name

◆ one_over_distribution_radius_squared

float Slic3r::Arachne::DistributedBeadingStrategy::one_over_distribution_radius_squared
protected

◆ optimal_width

◆ transitioning_angle

double Slic3r::Arachne::BeadingStrategy::transitioning_angle
protectedinherited

The length of the region to smoothly transfer between bead counts.

The maximum angle between outline segments smaller than which we are going to add transitions Equals 180 - the "limit bisector angle" from the paper

Referenced by BeadingStrategy(), BeadingStrategy(), Slic3r::Arachne::DistributedBeadingStrategy::DistributedBeadingStrategy(), and getTransitioningAngle().

◆ wall_add_middle_threshold

double Slic3r::Arachne::BeadingStrategy::wall_add_middle_threshold
protectedinherited

◆ wall_split_middle_threshold

double Slic3r::Arachne::BeadingStrategy::wall_split_middle_threshold
protectedinherited

The documentation for this class was generated from the following files: