mirror of
https://github.com/SoftFever/OrcaSlicer.git
synced 2025-07-19 20:57:53 -06:00
1) New methods PrintObject::num_regions() and ::has_region() to make
the code more readable and to highlight where PrintObject::region_volumes are actually set and consumed. 2) Replaced Slic3r::clamp() with std::clamp(). They differ in the order of their parameters, thus hopefully no new bugs were introduced. 3) Some refactoring of MultiMaterialSegmentation for efficiency.
This commit is contained in:
parent
4f950343c8
commit
38bb7d2950
19 changed files with 139 additions and 161 deletions
|
@ -298,7 +298,7 @@ std::vector<double> layer_height_profile_adaptive(const SlicingParameters& slici
|
|||
if (z_gap > 0.0)
|
||||
{
|
||||
layer_height_profile.push_back(slicing_params.object_print_z_height());
|
||||
layer_height_profile.push_back(clamp(slicing_params.min_layer_height, slicing_params.max_layer_height, z_gap));
|
||||
layer_height_profile.push_back(std::clamp(z_gap, slicing_params.min_layer_height, slicing_params.max_layer_height));
|
||||
}
|
||||
|
||||
return layer_height_profile;
|
||||
|
@ -376,7 +376,7 @@ std::vector<double> smooth_height_profile(const std::vector<double>& profile, co
|
|||
}
|
||||
}
|
||||
|
||||
height = clamp(slicing_params.min_layer_height, slicing_params.max_layer_height, (weight_total != 0.0) ? height /= weight_total : hi);
|
||||
height = std::clamp((weight_total != 0.0) ? height /= weight_total : hi, slicing_params.min_layer_height, slicing_params.max_layer_height);
|
||||
if (smoothing_params.keep_min)
|
||||
height = std::min(height, hi);
|
||||
}
|
||||
|
@ -502,7 +502,7 @@ void adjust_layer_height_profile(
|
|||
assert(false);
|
||||
break;
|
||||
}
|
||||
height = clamp(slicing_params.min_layer_height, slicing_params.max_layer_height, height);
|
||||
height = std::clamp(height, slicing_params.min_layer_height, slicing_params.max_layer_height);
|
||||
if (zz == z_span_variable.second) {
|
||||
// This is the last point of the profile.
|
||||
if (profile_new[profile_new.size() - 2] + EPSILON > zz) {
|
||||
|
@ -670,11 +670,11 @@ int generate_layer_height_texture(
|
|||
assert(mid <= slicing_params.object_print_z_height());
|
||||
coordf_t h = hi - lo;
|
||||
hi = std::min(hi, slicing_params.object_print_z_height());
|
||||
int cell_first = clamp(0, ncells-1, int(ceil(lo * z_to_cell)));
|
||||
int cell_last = clamp(0, ncells-1, int(floor(hi * z_to_cell)));
|
||||
int cell_first = std::clamp(int(ceil(lo * z_to_cell)), 0, ncells-1);
|
||||
int cell_last = std::clamp(int(floor(hi * z_to_cell)), 0, ncells-1);
|
||||
for (int cell = cell_first; cell <= cell_last; ++ cell) {
|
||||
coordf_t idxf = (0.5 * hscale + (h - slicing_params.layer_height)) * coordf_t(palette_raw.size()-1) / hscale;
|
||||
int idx1 = clamp(0, int(palette_raw.size() - 1), int(floor(idxf)));
|
||||
int idx1 = std::clamp(int(floor(idxf)), 0, int(palette_raw.size() - 1));
|
||||
int idx2 = std::min(int(palette_raw.size() - 1), idx1 + 1);
|
||||
coordf_t t = idxf - coordf_t(idx1);
|
||||
const Vec3crd &color1 = palette_raw[idx1];
|
||||
|
@ -693,9 +693,9 @@ int generate_layer_height_texture(
|
|||
assert(row >= 0 && row < rows);
|
||||
assert(col >= 0 && col < cols);
|
||||
unsigned char *ptr = (unsigned char*)data + (row * cols + col) * 4;
|
||||
ptr[0] = (unsigned char)clamp<int>(0, 255, int(floor(color(0) + 0.5)));
|
||||
ptr[1] = (unsigned char)clamp<int>(0, 255, int(floor(color(1) + 0.5)));
|
||||
ptr[2] = (unsigned char)clamp<int>(0, 255, int(floor(color(2) + 0.5)));
|
||||
ptr[0] = (unsigned char)std::clamp(int(floor(color(0) + 0.5)), 0, 255);
|
||||
ptr[1] = (unsigned char)std::clamp(int(floor(color(1) + 0.5)), 0, 255);
|
||||
ptr[2] = (unsigned char)std::clamp(int(floor(color(2) + 0.5)), 0, 255);
|
||||
ptr[3] = 255;
|
||||
if (col == 0 && row > 0) {
|
||||
// Duplicate the first value in a row as a last value of the preceding row.
|
||||
|
@ -706,11 +706,11 @@ int generate_layer_height_texture(
|
|||
}
|
||||
}
|
||||
if (level_of_detail_2nd_level) {
|
||||
cell_first = clamp(0, ncells1-1, int(ceil(lo * z_to_cell1)));
|
||||
cell_last = clamp(0, ncells1-1, int(floor(hi * z_to_cell1)));
|
||||
cell_first = std::clamp(int(ceil(lo * z_to_cell1)), 0, ncells1-1);
|
||||
cell_last = std::clamp(int(floor(hi * z_to_cell1)), 0, ncells1-1);
|
||||
for (int cell = cell_first; cell <= cell_last; ++ cell) {
|
||||
coordf_t idxf = (0.5 * hscale + (h - slicing_params.layer_height)) * coordf_t(palette_raw.size()-1) / hscale;
|
||||
int idx1 = clamp(0, int(palette_raw.size() - 1), int(floor(idxf)));
|
||||
int idx1 = std::clamp(int(floor(idxf)), 0, int(palette_raw.size() - 1));
|
||||
int idx2 = std::min(int(palette_raw.size() - 1), idx1 + 1);
|
||||
coordf_t t = idxf - coordf_t(idx1);
|
||||
const Vec3crd &color1 = palette_raw[idx1];
|
||||
|
@ -725,9 +725,9 @@ int generate_layer_height_texture(
|
|||
assert(row >= 0 && row < rows/2);
|
||||
assert(col >= 0 && col < cols/2);
|
||||
unsigned char *ptr = data1 + (row * cols1 + col) * 4;
|
||||
ptr[0] = (unsigned char)clamp<int>(0, 255, int(floor(color(0) + 0.5)));
|
||||
ptr[1] = (unsigned char)clamp<int>(0, 255, int(floor(color(1) + 0.5)));
|
||||
ptr[2] = (unsigned char)clamp<int>(0, 255, int(floor(color(2) + 0.5)));
|
||||
ptr[0] = (unsigned char)std::clamp(int(floor(color(0) + 0.5)), 0, 255);
|
||||
ptr[1] = (unsigned char)std::clamp(int(floor(color(1) + 0.5)), 0, 255);
|
||||
ptr[2] = (unsigned char)std::clamp(int(floor(color(2) + 0.5)), 0, 255);
|
||||
ptr[3] = 255;
|
||||
if (col == 0 && row > 0) {
|
||||
// Duplicate the first value in a row as a last value of the preceding row.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue