fixed ExPolygons dealocation while using EdgeGrid

fixed warnings in Bicubic.h file
This commit is contained in:
PavelMikus 2022-03-30 11:22:35 +02:00
parent 965803822e
commit 156a60017d
2 changed files with 59 additions and 50 deletions

View File

@ -903,18 +903,26 @@ void pick_random_seam_point(std::vector<SeamCandidate> &perimeter_points, size_t
}
EdgeGrid::Grid compute_layer_merged_edge_grid(const Layer *layer) {
struct EdgeGridWrapper {
explicit EdgeGridWrapper(ExPolygons ex_polys) :
ex_polys(ex_polys) {
grid.create(this->ex_polys, distance_field_resolution);
grid.calculate_sdf();
}
const coord_t distance_field_resolution = coord_t(scale_(1.) + 0.5);
EdgeGrid::Grid grid;
ExPolygons ex_polys;
}
;
EdgeGridWrapper compute_layer_merged_edge_grid(const Layer *layer) {
static const float eps = float(scale_(layer->object()->config().slice_closing_radius.value));
// merge with offset
ExPolygons merged = layer->merged(eps);
// ofsset back
ExPolygons layer_outline = offset_ex(merged, -eps);
const coord_t distance_field_resolution = coord_t(scale_(1.) + 0.5);
EdgeGrid::Grid result { };
result.create(layer_outline, distance_field_resolution);
result.calculate_sdf();
return result;
return EdgeGridWrapper(layer_outline);
}
} // namespace SeamPlacerImpl
@ -971,9 +979,9 @@ void SeamPlacer::calculate_overhangs_and_layer_embedding(const PrintObject *po)
tbb::parallel_for(tbb::blocked_range<size_t>(0, m_perimeter_points_per_object[po].size()),
[&](tbb::blocked_range<size_t> r) {
std::unique_ptr<EdgeGrid::Grid> prev_layer_grid;
std::unique_ptr<EdgeGridWrapper> prev_layer_grid;
if (r.begin() > 0) { // previous layer exists
prev_layer_grid = std::make_unique<EdgeGrid::Grid>(
prev_layer_grid = std::make_unique<EdgeGridWrapper>(
compute_layer_merged_edge_grid(po->layers()[r.begin() - 1]));
}
@ -981,21 +989,22 @@ void SeamPlacer::calculate_overhangs_and_layer_embedding(const PrintObject *po)
bool layer_has_multiple_loops =
m_perimeter_points_per_object[po][layer_idx][0].perimeter->end_index
< m_perimeter_points_per_object[po][layer_idx].size() - 1;
std::unique_ptr<EdgeGrid::Grid> current_layer_grid = std::make_unique<EdgeGrid::Grid>(
std::unique_ptr<EdgeGridWrapper> current_layer_grid = std::make_unique<EdgeGridWrapper>(
compute_layer_merged_edge_grid(po->layers()[layer_idx]));
for (SeamCandidate &perimeter_point : m_perimeter_points_per_object[po][layer_idx]) {
Point point = Point::new_scale(Vec2f { perimeter_point.position.head<2>() });
if (prev_layer_grid.get() != nullptr) {
coordf_t overhang_dist;
prev_layer_grid->signed_distance(point, scaled(perimeter_point.perimeter->flow_width), overhang_dist);
prev_layer_grid->grid.signed_distance(point, scaled(perimeter_point.perimeter->flow_width),
overhang_dist);
perimeter_point.overhang =
unscale<float>(overhang_dist) - perimeter_point.perimeter->flow_width;
}
if (layer_has_multiple_loops) { // search for embedded perimeter points (points hidden inside the print ,e.g. multimaterial join, best position for seam)
coordf_t layer_embedded_distance;
current_layer_grid->signed_distance(point, scaled(1.0f),
current_layer_grid->grid.signed_distance(point, scaled(1.0f),
layer_embedded_distance);
perimeter_point.embedded_distance = unscale<float>(layer_embedded_distance);
}

View File

@ -78,37 +78,37 @@ struct CubicCatmulRomKernel
return 0;
}
static T a01() {
return (T) -0.5;
return T( -0.5);
}
static T a02() {
return (T) 1.;
return T( 1.);
}
static T a03() {
return (T) -0.5;
return T( -0.5);
}
static T a10() {
return (T) 1.;
return T( 1.);
}
static T a11() {
return 0;
}
static T a12() {
return (T) -5. / 2.;
return T( -5. / 2.);
}
static T a13() {
return (T) 3. / 2.;
return T( 3. / 2.);
}
static T a20() {
return 0;
}
static T a21() {
return (T) 0.5;
return T( 0.5);
}
static T a22() {
return (T) 2.;
return T( 2.);
}
static T a23() {
return (T) -3. / 2.;
return T( -3. / 2.);
}
static T a30() {
return 0;
@ -117,10 +117,10 @@ struct CubicCatmulRomKernel
return 0;
}
static T a32() {
return (T) -0.5;
return T( -0.5);
}
static T a33() {
return (T) 0.5;
return T( 0.5);
}
};
@ -131,40 +131,40 @@ struct CubicBSplineKernel
typedef T FloatType;
static T a00() {
return (T) 1. / 6.;
return T( 1. / 6.);
}
static T a01() {
return (T) -3. / 6.;
return T( -3. / 6.);
}
static T a02() {
return (T) 3. / 6.;
return T( 3. / 6.);
}
static T a03() {
return (T) -1. / 6.;
return T( -1. / 6.);
}
static T a10() {
return (T) 4. / 6.;
return T( 4. / 6.);
}
static T a11() {
return 0;
}
static T a12() {
return (T) -6. / 6.;
return T( -6. / 6.);
}
static T a13() {
return (T) 3. / 6.;
return T( 3. / 6.);
}
static T a20() {
return (T) 1. / 6.;
return T( 1. / 6.);
}
static T a21() {
return (T) 3. / 6.;
return T( 3. / 6.);
}
static T a22() {
return (T) 3. / 6.;
return T( 3. / 6.);
}
static T a23() {
return (T) -3. / 6.;
return T( -3. / 6.);
}
static T a30() {
return 0;
@ -176,7 +176,7 @@ struct CubicBSplineKernel
return 0;
}
static T a33() {
return (T) 1. / 6.;
return T( 1. / 6.);
}
};
@ -241,7 +241,7 @@ static typename KernelWrapper::FloatType cubic_interpolate(const Eigen::ArrayBas
typedef typename KernelWrapper::FloatType T;
const int w = int(F.size());
const int ix = (int) floor(pt);
const T s = pt - (T) ix;
const T s = pt - T( ix);
if (ix > 1 && ix + 2 < w) {
// Inside the fully interpolated region.
@ -262,8 +262,8 @@ static float bicubic_interpolate(const Eigen::MatrixBase<Derived> &F,
const int h = F.rows();
const int ix = (int) floor(pt[0]);
const int iy = (int) floor(pt[1]);
const T s = pt[0] - (T) ix;
const T t = pt[1] - (T) iy;
const T s = pt[0] - T( ix);
const T t = pt[1] - T( iy);
if (ix > 1 && ix + 2 < w && iy > 1 && iy + 2 < h) {
// Inside the fully interpolated region.
@ -274,7 +274,7 @@ static float bicubic_interpolate(const Eigen::MatrixBase<Derived> &F,
Kernel::interpolate(F(ix - 1, iy + 2), F(ix, iy + 2), F(ix + 1, iy + 2), F(ix + 2, iy + 2), s), t);
}
// Transition region. Extend with a constant function.
auto f = [&F, &f, w, h](int x, int y) {
auto f = [&F, w, h](int x, int y) {
return F(BicubicInternal::clamp(x, 0, w - 1), BicubicInternal::clamp(y, 0, h - 1));
};
return Kernel::interpolate(