Prusa Slicer 2.6.0
Loading...
Searching...
No Matches
Slic3r::SlicingAdaptive Class Reference

#include <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< FaceZm_faces
 

Detailed Description


Class Documentation

◆ Slic3r::SlicingAdaptive::FaceZ

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

Member Function Documentation

◆ clear()

void Slic3r::SlicingAdaptive::clear ( )
71{
72 m_faces.clear();
73}
std::vector< FaceZ > m_faces
Definition SlicingAdaptive.hpp:37

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)
200{
201 for (size_t i = 0; i < m_faces.size(); ++ i) {
202 std::pair<float, float> zspan = m_faces[i].z_span;
203 // facet's minimum is higher than max forward distance -> end loop
204 if (zspan.first > z + m_slicing_params.max_layer_height)
205 break;
206 // min_z == max_z -> horizontal facet
207 if (zspan.first > z && zspan.first == zspan.second)
208 return zspan.first - z;
209 }
210
211 // objects maximum?
213 std::max((float)m_slicing_params.object_print_z_height() - z, 0.f) : (float)m_slicing_params.max_layer_height;
214}
SlicingParameters m_slicing_params
Definition SlicingAdaptive.hpp:35
coordf_t max_layer_height
Definition Slicing.hpp:65
coordf_t object_print_z_height() const
Definition Slicing.hpp:45

References m_faces, m_slicing_params, Slic3r::SlicingParameters::max_layer_height, and Slic3r::SlicingParameters::object_print_z_height().

Referenced by Slic3r::layer_height_profile_adaptive().

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

References EPSILON, Slic3r::SlicingParameters::layer_height, Slic3r::layer_height_from_slope(), Slic3r::lerp(), m_faces, m_slicing_params, Slic3r::SlicingParameters::max_layer_height, and Slic3r::SlicingParameters::min_layer_height.

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)
76{
77 this->clear();
78
79 TriangleMesh mesh = object.raw_mesh();
80 const ModelInstance &first_instance = *object.instances.front();
81 mesh.transform(first_instance.get_matrix(), first_instance.is_left_handed());
82
83 // 1) Collect faces from mesh.
84 m_faces.reserve(mesh.facets_count());
85 for (stl_triangle_vertex_indices face : mesh.its.indices) {
86 stl_vertex vertex[3] = { mesh.its.vertices[face[0]], mesh.its.vertices[face[1]], mesh.its.vertices[face[2]] };
88 std::pair<float, float> face_z_span {
89 std::min(std::min(vertex[0].z(), vertex[1].z()), vertex[2].z()),
90 std::max(std::max(vertex[0].z(), vertex[1].z()), vertex[2].z())
91 };
92 m_faces.emplace_back(FaceZ({ face_z_span, std::abs(n.z()), std::sqrt(n.x() * n.x() + n.y() * n.y()) }));
93 }
94
95 // 2) Sort faces lexicographically by their Z span.
96 std::sort(m_faces.begin(), m_faces.end(), [](const FaceZ &f1, const FaceZ &f2) { return f1.z_span < f2.z_span; });
97}
void clear()
Definition SlicingAdaptive.cpp:70
Vec3f face_normal_normalized(const stl_vertex vertex[3])
Definition TriangleMesh.hpp:310
TPoint< S > & vertex(S &sh, unsigned long idx, const PolygonTag &)
Definition geometry_traits.hpp:1180

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

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
18{ 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: