OrcaSlicer latest
OrcaSlicer
Loading...
Searching...
No Matches
Slic3r::SlicingAdaptive Class Reference

#include </home/runner/work/OrcaSlicer/OrcaSlicer/src/libslic3r/SlicingAdaptive.hpp>

Collaboration diagram for Slic3r::SlicingAdaptive:

Classes

struct  FaceZ

Public Member Functions

void clear ()
void set_slicing_parameters (SlicingParameters params)
void prepare (const ModelObject &object)
float next_layer_height (const float print_z, float quality, size_t &current_facet)
float horizontal_facet_distance (float z)

Protected Attributes

SlicingParameters m_slicing_params
std::vector< FaceZ > m_faces

Detailed Description


Class Documentation

◆ Slic3r::SlicingAdaptive::FaceZ

struct Slic3r::SlicingAdaptive::FaceZ
Collaboration diagram for Slic3r::SlicingAdaptive::FaceZ:
Class Members
float n_cos
float n_sin
pair< float, float > z_span

Member Function Documentation

◆ clear()

void Slic3r::SlicingAdaptive::clear ( )
77{
78 m_faces.clear();
79}
std::vector< FaceZ > m_faces
Definition SlicingAdaptive.hpp:42

References m_faces.

Referenced by prepare().

Here is the caller graph for this function:

◆ horizontal_facet_distance()

float Slic3r::SlicingAdaptive::horizontal_facet_distance ( float z)
206{
207 for (size_t i = 0; i < m_faces.size(); ++ i) {
208 std::pair<float, float> zspan = m_faces[i].z_span;
209 // facet's minimum is higher than max forward distance -> end loop
210 if (zspan.first > z + m_slicing_params.max_layer_height)
211 break;
212 // min_z == max_z -> horizontal facet
213 if (zspan.first > z && zspan.first == zspan.second)
214 return zspan.first - z;
215 }
216
217 // objects maximum?
218 return (z + (float)m_slicing_params.max_layer_height > (float)m_slicing_params.object_print_z_height()) ?
219 std::max((float)m_slicing_params.object_print_z_height() - z, 0.f) : (float)m_slicing_params.max_layer_height;
220}
SlicingParameters m_slicing_params
Definition SlicingAdaptive.hpp:40

References m_faces, and m_slicing_params.

Referenced by Slic3r::layer_height_profile_adaptive().

Here is the caller graph for this function:

◆ next_layer_height()

float Slic3r::SlicingAdaptive::next_layer_height ( const float print_z,
float quality,
size_t & current_facet )
110{
111 float height = (float)m_slicing_params.max_layer_height;
112
113 float max_surface_deviation;
114
115 {
116#if 0
117// @platch's formula for quality:
118 double delta_min = SURFACE_CONST * m_slicing_params.min_layer_height;
119 double delta_mid = (SURFACE_CONST + 0.5) * m_slicing_params.layer_height;
120 double delta_max = (SURFACE_CONST + 0.5) * m_slicing_params.max_layer_height;
121#else
122// Vojtech's formula for triangle area error metric.
123 double delta_min = m_slicing_params.min_layer_height;
124 double delta_mid = m_slicing_params.layer_height;
125 double delta_max = m_slicing_params.max_layer_height;
126#endif
127 max_surface_deviation = (quality_factor < 0.5f) ?
128 lerp(delta_min, delta_mid, 2. * quality_factor) :
129 lerp(delta_max, delta_mid, 2. * (1. - quality_factor));
130 }
131
132 // find all facets intersecting the slice-layer
133 size_t ordered_id = current_facet;
134 {
135 bool first_hit = false;
136 for (; ordered_id < m_faces.size(); ++ ordered_id) {
137 const std::pair<float, float> &zspan = m_faces[ordered_id].z_span;
138 // facet's minimum is higher than slice_z -> end loop
139 if (zspan.first >= print_z)
140 break;
141 // facet's maximum is higher than slice_z -> store the first event for next cusp_height call to begin at this point
142 if (zspan.second > print_z) {
143 // first event?
144 if (! first_hit) {
145 first_hit = true;
146 current_facet = ordered_id;
147 }
148 // skip touching facets which could otherwise cause small cusp values
149 if (zspan.second < print_z + EPSILON)
150 continue;
151 // compute cusp-height for this facet and store minimum of all heights
152 height = std::min(height, layer_height_from_slope(m_faces[ordered_id], max_surface_deviation));
153 }
154 }
155 }
156
157 // lower height limit due to printer capabilities
158 height = std::max(height, float(m_slicing_params.min_layer_height));
159
160 // check for sloped facets inside the determined layer and correct height if necessary
161 if (height > float(m_slicing_params.min_layer_height)) {
162 for (; ordered_id < m_faces.size(); ++ ordered_id) {
163 const std::pair<float, float> &zspan = m_faces[ordered_id].z_span;
164 // facet's minimum is higher than slice_z + height -> end loop
165 if (zspan.first >= print_z + height)
166 break;
167
168 // skip touching facets which could otherwise cause small cusp values
169 if (zspan.second < print_z + EPSILON)
170 continue;
171
172 // Compute cusp-height for this facet and check against height.
173 float reduced_height = layer_height_from_slope(m_faces[ordered_id], max_surface_deviation);
174
175 float z_diff = zspan.first - print_z;
176 if (reduced_height < z_diff) {
177 assert(z_diff < height + EPSILON);
178 // The currently visited triangle's slope limits the next layer height so much, that
179 // the lowest point of the currently visible triangle is already above the newly proposed layer height.
180 // This means, that we need to limit the layer height so that the offending newly visited triangle
181 // is just above of the new layer.
182#ifdef ADAPTIVE_LAYER_HEIGHT_DEBUG
183 BOOST_LOG_TRIVIAL(trace) << "cusp computation, height is reduced from " << height << "to " << z_diff << " due to z-diff";
184#endif /* ADAPTIVE_LAYER_HEIGHT_DEBUG */
185 height = z_diff;
186 } else if (reduced_height < height) {
187#ifdef ADAPTIVE_LAYER_HEIGHT_DEBUG
188 BOOST_LOG_TRIVIAL(trace) << "adaptive layer computation: height is reduced from " << height << "to " << reduced_height << " due to higher facet";
189#endif /* ADAPTIVE_LAYER_HEIGHT_DEBUG */
190 height = reduced_height;
191 }
192 }
193 // lower height limit due to printer capabilities again
194 height = std::max(height, float(m_slicing_params.min_layer_height));
195 }
196
197#ifdef ADAPTIVE_LAYER_HEIGHT_DEBUG
198 BOOST_LOG_TRIVIAL(trace) << "adaptive layer computation, layer-bottom at z:" << print_z << ", quality_factor:" << quality_factor << ", resulting layer height:" << height;
199#endif /* ADAPTIVE_LAYER_HEIGHT_DEBUG */
200 return height;
201}
#define EPSILON
Definition ColorUtils.cpp:64
coord_t height(const BoundingBox &box)
Definition Arrange.cpp:1185
void trace(unsigned int level, const char *message)
Definition utils.cpp:247
ColorRGB lerp(const ColorRGB &a, const ColorRGB &b, float t)
Definition Color.cpp:244
static float layer_height_from_slope(const SlicingAdaptive::FaceZ &face, float max_surface_deviation)
Definition SlicingAdaptive.cpp:58

References EPSILON, Slic3r::layer_height_from_slope(), Slic3r::lerp(), m_faces, m_slicing_params, and Slic3r::trace().

Referenced by Slic3r::layer_height_profile_adaptive().

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

◆ prepare()

void Slic3r::SlicingAdaptive::prepare ( const ModelObject & object)
82{
83 this->clear();
84
85 TriangleMesh mesh = object.raw_mesh();
86 const ModelInstance &first_instance = *object.instances.front();
87 mesh.transform(first_instance.get_matrix(), first_instance.is_left_handed());
88
89 // 1) Collect faces from mesh.
90 m_faces.reserve(mesh.facets_count());
91 for (stl_triangle_vertex_indices face : mesh.its.indices) {
92 stl_vertex vertex[3] = { mesh.its.vertices[face[0]], mesh.its.vertices[face[1]], mesh.its.vertices[face[2]] };
93 stl_vertex n = face_normal_normalized(vertex);
94 std::pair<float, float> face_z_span {
95 std::min(std::min(vertex[0].z(), vertex[1].z()), vertex[2].z()),
96 std::max(std::max(vertex[0].z(), vertex[1].z()), vertex[2].z())
97 };
98 m_faces.emplace_back(FaceZ({ face_z_span, std::abs(n.z()), std::sqrt(n.x() * n.x() + n.y() * n.y()) }));
99 }
100
101 // 2) Sort faces lexicographically by their Z span.
102 std::sort(m_faces.begin(), m_faces.end(), [](const FaceZ &f1, const FaceZ &f2) { return f1.z_span < f2.z_span; });
103}
void clear()
Definition SlicingAdaptive.cpp:76
Definition SlicingAdaptive.hpp:31
Vec3f face_normal_normalized(const stl_vertex vertex[3])
Definition TriangleMesh.hpp:350

References clear(), Slic3r::face_normal_normalized(), Slic3r::TriangleMesh::facets_count(), Slic3r::ModelInstance::get_matrix(), Slic3r::ModelInstance::is_left_handed(), Slic3r::TriangleMesh::its, m_faces, and Slic3r::TriangleMesh::transform().

Referenced by Slic3r::layer_height_profile_adaptive().

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

◆ set_slicing_parameters()

void Slic3r::SlicingAdaptive::set_slicing_parameters ( SlicingParameters params)
inline
23{ m_slicing_params = params; }

References m_slicing_params.

Referenced by Slic3r::layer_height_profile_adaptive().

Here is the caller graph for this function:

Member Data Documentation

◆ m_faces

std::vector<FaceZ> Slic3r::SlicingAdaptive::m_faces
protected

◆ m_slicing_params

SlicingParameters Slic3r::SlicingAdaptive::m_slicing_params
protected

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