FIX:add "Slic3r::Emboss::union_with_delta" api for single ExPolygons

and add_indice api
jira: STUDIO-10576

Change-Id: I85086552bb7eec0118e00299d4c07fbde7cc4aed
This commit is contained in:
zhou.xu 2025-02-26 10:37:04 +08:00 committed by lane.wei
parent 15560894e7
commit 43617a96df
4 changed files with 33 additions and 13 deletions

View File

@ -28,7 +28,7 @@
#include <stddef.h>
#include <vector>
#include <Eigen/Geometry>
#include <Eigen/Geometry>
// Size of the binary STL header, free form.
#define LABEL_SIZE 80
@ -178,7 +178,7 @@ struct FaceProperty
std::string to_string() const
{
std::string str;
// skip normal type facet to improve performance
// skip normal type facet to improve performance
if (type > eNormal && type < eMaxNumFaceTypes) {
str += std::to_string(type);
if (area != 0.f)
@ -230,7 +230,16 @@ struct indexed_triangle_set
size_t memsize() const {
return sizeof(*this) + (sizeof(stl_triangle_vertex_indices) + sizeof(FaceProperty)) * indices.size() + sizeof(stl_vertex) * vertices.size();
}
void add_indice(int f0, int f1, int f2, bool check_pts_size = false)
{
if (f0 < 0 || f1 < 0 || f2 < 0) { return; }
if (check_pts_size) {
auto pts_size = vertices.size();
if (f0 < pts_size && f1 < pts_size && f2 < pts_size) { indices.emplace_back(f0, f1, f2); }
} else {
indices.emplace_back(f0, f1, f2);
}
}
std::vector<stl_triangle_vertex_indices> indices;
std::vector<stl_vertex> vertices;
std::vector<FaceProperty> properties;

View File

@ -1270,6 +1270,16 @@ ExPolygons Slic3r::union_with_delta(EmbossShape &shape, float delta, unsigned ma
return shape.final_shape.expolygons;
}
HealedExPolygons Emboss::union_with_delta(ExPolygons expoly, float delta, unsigned max_heal_iteration)
{
ExPolygons expolygons;
expolygons_append(expolygons, offset_ex(expoly, delta));
ExPolygons result = union_ex(expolygons);
result = offset_ex(result, -delta);
bool is_healed = heal_expolygons(result, max_heal_iteration);
return {result, is_healed};
}
void Slic3r::translate(ExPolygonsWithIds &expolygons_with_ids, const Point &p)
{
for (ExPolygonsWithId &expolygons_with_id : expolygons_with_ids)
@ -1490,8 +1500,8 @@ void add_quad(uint32_t i1,
// bottom indices
uint32_t i1_ = i1 + count_point;
uint32_t i2_ = i2 + count_point;
result.indices.emplace_back(i2, i2_, i1);
result.indices.emplace_back(i1_, i1, i2_);
result.add_indice(i2, i2_, i1,true);
result.add_indice(i1_, i1, i2_, true);
};
indexed_triangle_set polygons2model_unique(
@ -1522,12 +1532,11 @@ indexed_triangle_set polygons2model_unique(
result.indices.reserve(shape_triangles.size() * 2 + points.size() * 2);
// top triangles - change to CCW
for (const Vec3i32 &t : shape_triangles)
result.indices.emplace_back(t.x(), t.z(), t.y());
result.add_indice(t.x(), t.z(), t.y(), true);
// bottom triangles - use CW
for (const Vec3i32 &t : shape_triangles)
result.indices.emplace_back(t.x() + count_point,
t.y() + count_point,
t.z() + count_point);
result.add_indice(t.x() + count_point,
t.y() + count_point, t.z() + count_point, true);
// quads around - zig zag by triangles
size_t polygon_offset = 0;
@ -1593,11 +1602,10 @@ indexed_triangle_set polygons2model_duplicit(
result.indices.reserve(shape_triangles.size() * 2 + points.size() * 2);
// top triangles - change to CCW
for (const Vec3i32 &t : shape_triangles)
result.indices.emplace_back(t.x(), t.z(), t.y());
result.add_indice(t.x(), t.z(), t.y(),true);
// bottom triangles - use CW
for (const Vec3i32 &t : shape_triangles)
result.indices.emplace_back(t.x() + count_point, t.y() + count_point,
t.z() + count_point);
result.add_indice(t.x() + count_point, t.y() + count_point, t.z() + count_point, true);
// quads around - zig zag by triangles
size_t polygon_offset = 0;

View File

@ -155,6 +155,8 @@ namespace Emboss
HealedExPolygons text2shapes (FontFileWithCache &font, const char *text, const FontProp &font_prop, const std::function<bool()> &was_canceled = []() {return false;});
ExPolygonsWithIds text2vshapes(FontFileWithCache &font, const std::wstring& text, const FontProp &font_prop, const std::function<bool()>& was_canceled = []() {return false;});
HealedExPolygons union_with_delta(ExPolygons expoly, float delta, unsigned max_heal_iteration);
const unsigned ENTER_UNICODE = static_cast<unsigned>('\n');
/// Sum of character '\n'
unsigned get_count_lines(const std::wstring &ws);

View File

@ -666,7 +666,8 @@ std::vector<TriangleMesh> create_meshs(DataBase &input)
for (auto shape : input.shape.shapes_with_ids) {
if (shape.expoly.empty()) continue;
meshs.emplace_back(TriangleMesh(polygons2model(shape.expoly, project)));
HealedExPolygons result = Slic3r::Emboss::union_with_delta(shape.expoly, UNION_DELTA, UNION_MAX_ITERATIN);
meshs.emplace_back(TriangleMesh(polygons2model(result.expolygons, project)));
}
return meshs;
}