OrcaSlicer latest
OrcaSlicer
Loading...
Searching...
No Matches
Slic3r::anonymous_namespace{AdaptiveInfillField.cpp} Namespace Reference

Classes

struct  DensityLevels
class  RadialScale

Functions

void distance_transform_line (const float *f, float *d, int n, int *v, double *s)
void distance_transform_axis (std::vector< float > &grid, const Vec3i32 &size, int axis, const std::function< void()> &throw_if_canceled)
void rasterize (const ExPolygons &expolygons, const Vec2d &origin, double cell, int nx, int ny, float *nodes)
double target_scale (double ratio, AdaptiveInfillGradient gradient, double depth)

Variables

constexpr double MaxNodes = double(1 << 20)
constexpr double MinCellSize = 0.5
constexpr double NeckRatio = 0.8
constexpr double MinLobeRatio = 0.3
constexpr double LobeReach = 2.
constexpr double LobeMorph = 0.1
constexpr double ShellRatio = 1.5
constexpr double BlendRatio = 2.5
constexpr int Samples = 32
constexpr float InfF = std::numeric_limits<float>::infinity()
constexpr double InfD = std::numeric_limits<double>::infinity()

Function Documentation

◆ distance_transform_axis()

void Slic3r::anonymous_namespace{AdaptiveInfillField.cpp}::distance_transform_axis ( std::vector< float > & grid,
const Vec3i32 & size,
int axis,
const std::function< void()> & throw_if_canceled )
87{
88 const int n = size[axis];
89 const int a1 = (axis + 1) % 3;
90 const int a2 = (axis + 2) % 3;
91 const size_t stride = axis == 0 ? 1 : axis == 1 ? size_t(size.x()) : size_t(size.x()) * size.y();
92 tbb::parallel_for(tbb::blocked_range<size_t>(0, size_t(size[a1]) * size[a2]), [&](const tbb::blocked_range<size_t> &range) {
93 std::vector<float> f(n), d(n);
94 std::vector<int> v(n);
95 std::vector<double> s(n + 1);
96 for (size_t line = range.begin(); line < range.end(); ++line) {
97 Vec3i32 idx;
98 idx[axis] = 0;
99 idx[a1] = int(line % size[a1]);
100 idx[a2] = int(line / size[a1]);
101 const size_t first = (size_t(idx.z()) * size.y() + idx.y()) * size.x() + idx.x();
102 for (int i = 0; i < n; ++i)
103 f[i] = grid[first + i * stride];
104 distance_transform_line(f.data(), d.data(), n, v.data(), s.data());
105 for (int i = 0; i < n; ++i)
106 grid[first + i * stride] = d[i];
107 }
108 throw_if_canceled();
109 });
110}
void distance_transform_line(const float *f, float *d, int n, int *v, double *s)
Definition AdaptiveInfillField.cpp:56
auto range(Cont &&cont)
Definition libslic3r.h:405
std::vector< ArithmeticOnly< T > > grid(const T &start, const T &stop, const T &stride)
A set of equidistant values starting from 'start' (inclusive), ending in the closest multiple of 'str...
Definition MTUtils.hpp:127
static double f(double x, double z_sin, double z_cos, bool vertical, bool flip)
Definition FillGyroid.cpp:124
Eigen::Matrix< int32_t, 3, 1, Eigen::DontAlign > Vec3i32
Definition Point.hpp:59

References distance_transform_axis(), distance_transform_line(), Slic3r::f(), Slic3r::grid(), and Slic3r::range().

Referenced by distance_transform_axis().

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

◆ distance_transform_line()

void Slic3r::anonymous_namespace{AdaptiveInfillField.cpp}::distance_transform_line ( const float * f,
float * d,
int n,
int * v,
double * s )
57{
58 int k = -1;
59 for (int q = 0; q < n; ++q) {
60 if (f[q] == InfF)
61 continue;
62 double x = -InfD;
63 while (k >= 0) {
64 x = (f[q] + double(q) * q - f[v[k]] - double(v[k]) * v[k]) / (2. * (q - v[k]));
65 if (x > s[k])
66 break;
67 --k;
68 }
69 if (k < 0)
70 x = -InfD;
71 v[++k] = q;
72 s[k] = x;
73 s[k + 1] = InfD;
74 }
75 if (k < 0) {
76 std::fill(d, d + n, InfF);
77 return;
78 }
79 for (int q = 0, j = 0; q < n; ++q) {
80 while (s[j + 1] < q)
81 ++j;
82 d[q] = float(sqr(double(q - v[j])) + f[v[j]]);
83 }
84}
constexpr double InfD
Definition AdaptiveInfillField.cpp:53
constexpr float InfF
Definition AdaptiveInfillField.cpp:52
constexpr T sqr(T x)
Definition libslic3r.h:301

References distance_transform_line(), Slic3r::f(), InfD, InfF, and Slic3r::sqr().

Referenced by distance_transform_axis(), and distance_transform_line().

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

◆ rasterize()

void Slic3r::anonymous_namespace{AdaptiveInfillField.cpp}::rasterize ( const ExPolygons & expolygons,
const Vec2d & origin,
double cell,
int nx,
int ny,
float * nodes )
114{
115 std::vector<std::vector<double>> crossings(ny);
116 auto add_crossings = [&](const Polygon &polygon) {
117 const Points &pts = polygon.points;
118 for (size_t i = 0; i < pts.size(); ++i) {
119 const Vec2d a = unscaled(pts[i]);
120 const Vec2d b = unscaled(pts[i + 1 == pts.size() ? 0 : i + 1]);
121 if (a.y() == b.y())
122 continue;
123 const auto [lo, hi] = std::minmax(a.y(), b.y());
124 const int j0 = std::max(0, int(std::ceil((lo - origin.y()) / cell)));
125 const int j1 = std::min(ny, int(std::ceil((hi - origin.y()) / cell)));
126 for (int j = j0; j < j1; ++j) {
127 const double y = origin.y() + j * cell;
128 crossings[j].push_back(a.x() + (b.x() - a.x()) * (y - a.y()) / (b.y() - a.y()));
129 }
130 }
131 };
132 for (const ExPolygon &expolygon : expolygons) {
133 add_crossings(expolygon.contour);
134 for (const Polygon &hole : expolygon.holes)
135 add_crossings(hole);
136 }
137 for (int j = 0; j < ny; ++j) {
138 std::vector<double> &xs = crossings[j];
139 std::sort(xs.begin(), xs.end());
140 for (size_t k = 0; k + 1 < xs.size(); k += 2) {
141 const int i0 = std::max(0, int(std::ceil((xs[k] - origin.x()) / cell)));
142 const int i1 = std::min(nx, int(std::ceil((xs[k + 1] - origin.x()) / cell)));
143 std::fill(nodes + size_t(j) * nx + std::min(i0, i1), nodes + size_t(j) * nx + i1, InfF);
144 }
145 }
146}
Definition Polygon.hpp:31
constexpr Eigen::Matrix< Tout, 2, EigenArgs... > unscaled(const Slic3r::Point &v) noexcept
Definition Arrange.cpp:81
std::vector< Point, PointsAllocator< Point > > Points
Definition Point.hpp:73
Eigen::Matrix< double, 2, 1, Eigen::DontAlign > Vec2d
Definition Point.hpp:67

References InfF, rasterize(), and Slic3r::unscaled().

Referenced by rasterize().

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

◆ target_scale()

double Slic3r::anonymous_namespace{AdaptiveInfillField.cpp}::target_scale ( double ratio,
AdaptiveInfillGradient gradient,
double depth )
150{
151 switch (gradient) {
152 case AdaptiveInfillGradient::Quadratic: return 1. + (ratio - 1.) * depth * depth;
153 case AdaptiveInfillGradient::Exponential: return std::pow(ratio, depth);
154 default: return 1. + (ratio - 1.) * depth;
155 }
156}
@ Quadratic
Definition PrintConfig.hpp:305
@ Exponential
Definition PrintConfig.hpp:306

References Slic3r::Exponential, Slic3r::Quadratic, and target_scale().

Referenced by Slic3r::anonymous_namespace{AdaptiveInfillField.cpp}::RadialScale::RadialScale(), Slic3r::anonymous_namespace{AdaptiveInfillField.cpp}::DensityLevels::level(), and target_scale().

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

Variable Documentation

◆ BlendRatio

double Slic3r::anonymous_namespace{AdaptiveInfillField.cpp}::BlendRatio = 2.5
constexpr

◆ InfD

double Slic3r::anonymous_namespace{AdaptiveInfillField.cpp}::InfD = std::numeric_limits<double>::infinity()
constexpr

Referenced by distance_transform_line().

◆ InfF

float Slic3r::anonymous_namespace{AdaptiveInfillField.cpp}::InfF = std::numeric_limits<float>::infinity()
constexpr

◆ LobeMorph

double Slic3r::anonymous_namespace{AdaptiveInfillField.cpp}::LobeMorph = 0.1
constexpr

◆ LobeReach

double Slic3r::anonymous_namespace{AdaptiveInfillField.cpp}::LobeReach = 2.
constexpr

◆ MaxNodes

double Slic3r::anonymous_namespace{AdaptiveInfillField.cpp}::MaxNodes = double(1 << 20)
constexpr

◆ MinCellSize

double Slic3r::anonymous_namespace{AdaptiveInfillField.cpp}::MinCellSize = 0.5
constexpr

◆ MinLobeRatio

double Slic3r::anonymous_namespace{AdaptiveInfillField.cpp}::MinLobeRatio = 0.3
constexpr

◆ NeckRatio

double Slic3r::anonymous_namespace{AdaptiveInfillField.cpp}::NeckRatio = 0.8
constexpr

◆ Samples

int Slic3r::anonymous_namespace{AdaptiveInfillField.cpp}::Samples = 32
constexpr

◆ ShellRatio

double Slic3r::anonymous_namespace{AdaptiveInfillField.cpp}::ShellRatio = 1.5
constexpr