Skip to content

Commit 6098d1b

Browse files
committed
Improve adaptive layer height quality control
Refactored adaptive layer height calculation to use explicit min/max settings and improved quality factor handling. Advanced algorithms now allow more dynamic layer height changes based on quality, and default to quality-based heights when no geometry constraints are present.
1 parent b2b0d0f commit 6098d1b

File tree

3 files changed

+27
-13
lines changed

3 files changed

+27
-13
lines changed

src/FffPolygonGenerator.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -139,10 +139,9 @@ bool FffPolygonGenerator::sliceModel(MeshGroup* meshgroup, TimeKeeper& timeKeepe
139139
{
140140
// Use advanced quality-based algorithm
141141
const auto quality_factor = mesh_group_settings.get<double>("adaptive_layer_height_quality_factor");
142-
const auto variable_layer_height_max_variation = mesh_group_settings.get<coord_t>("adaptive_layer_height_variation");
143-
const coord_t min_layer_height = std::max(coord_t(10), layer_thickness - variable_layer_height_max_variation); // Minimum 0.01mm
144-
const coord_t max_layer_height = layer_thickness + variable_layer_height_max_variation;
145-
142+
const coord_t min_layer_height = mesh_group_settings.get<coord_t>("adaptive_layer_height_min");
143+
const coord_t max_layer_height = mesh_group_settings.get<coord_t>("adaptive_layer_height_max");
144+
146145
adaptive_layer_heights = new AdaptiveLayerHeights(layer_thickness, min_layer_height, max_layer_height, quality_factor, meshgroup);
147146
}
148147
else

src/settings/AdaptiveLayerHeights.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,10 @@ void AdaptiveLayerHeights::calculateLayersAdvanced()
238238

239239
// Use advanced adaptive algorithm
240240
size_t current_facet = 0;
241-
const double LAYER_HEIGHT_CHANGE_STEP = 40.0; // microns, gradual change limit
241+
// Allow larger height changes for quality-based control
242+
// Quality factor 0.0 (best quality) allows more dramatic changes for precision
243+
// Quality factor 1.0 (speed) uses more gradual changes for stability
244+
const double LAYER_HEIGHT_CHANGE_STEP = 100.0 + quality_factor_ * 100.0; // 100-200 microns range
242245

243246
while (z_level < model_max_z && layers_.size() < 10000) // Safety limit
244247
{
@@ -251,11 +254,11 @@ void AdaptiveLayerHeights::calculateLayersAdvanced()
251254
coord_t previous_height = layers_.back().layer_height_;
252255
if (previous_height < height && height - previous_height > LAYER_HEIGHT_CHANGE_STEP)
253256
{
254-
height = previous_height + LAYER_HEIGHT_CHANGE_STEP;
257+
height = previous_height + coord_t(LAYER_HEIGHT_CHANGE_STEP);
255258
}
256259
else if (previous_height > height && previous_height - height > LAYER_HEIGHT_CHANGE_STEP)
257260
{
258-
height = previous_height - LAYER_HEIGHT_CHANGE_STEP;
261+
height = previous_height - coord_t(LAYER_HEIGHT_CHANGE_STEP);
259262
}
260263
}
261264

src/settings/SlicingAdaptive.cpp

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -95,17 +95,18 @@ coord_t SlicingAdaptive::next_layer_height(const double print_z, double quality_
9595
// Calculate max surface deviation based on quality factor
9696
double max_surface_deviation;
9797
{
98-
// Convert layer heights from microns to mm for calculation
99-
double delta_min = m_slicing_params.min_layer_height / 1000.0;
100-
double delta_mid = m_slicing_params.layer_height / 1000.0;
101-
double delta_max = m_slicing_params.max_layer_height / 1000.0;
102-
103-
max_surface_deviation = (quality_factor < 0.5) ? lerp(delta_min, delta_mid, 2.0 * quality_factor) : lerp(delta_max, delta_mid, 2.0 * (1.0 - quality_factor));
98+
// Quality factor 0.0 = best quality (smallest surface deviation, thinner layers)
99+
// Quality factor 1.0 = fastest speed (larger surface deviation, thicker layers)
100+
const double min_surface_deviation = 0.01; // 0.01mm for highest quality
101+
const double max_surface_deviation_val = 0.2; // 0.2mm for fastest speed
102+
103+
max_surface_deviation = min_surface_deviation + quality_factor * (max_surface_deviation_val - min_surface_deviation);
104104
}
105105

106106
// Find all facets intersecting the slice layer
107107
size_t ordered_id = current_facet;
108108
bool first_hit = false;
109+
bool found_influencing_geometry = false;
109110

110111
for (; ordered_id < m_faces.size(); ++ordered_id)
111112
{
@@ -132,11 +133,22 @@ coord_t SlicingAdaptive::next_layer_height(const double print_z, double quality_
132133
// Compute cusp height for this facet and store minimum
133134
coord_t facet_height = layer_height_from_slope(m_faces[ordered_id], max_surface_deviation);
134135
height = std::min(height, facet_height);
136+
found_influencing_geometry = true;
135137
}
136138
}
137139

138140
// Apply printer capability limits
139141
height = std::max(height, m_slicing_params.min_layer_height);
142+
143+
// If no geometry influenced the layer height, use quality-based default
144+
if (!found_influencing_geometry)
145+
{
146+
// Create a quality-based layer height when no geometry constraints exist
147+
// Quality 0.0 -> use minimum layer height, Quality 1.0 -> use maximum layer height
148+
coord_t quality_based_height = coord_t(m_slicing_params.min_layer_height +
149+
quality_factor * (m_slicing_params.max_layer_height - m_slicing_params.min_layer_height));
150+
height = std::min(height, quality_based_height);
151+
}
140152

141153
// Check for sloped facets inside the determined layer and correct height if necessary
142154
if (height > m_slicing_params.min_layer_height)

0 commit comments

Comments
 (0)