FIX:"split to parts" should consider scale_det

jira: STUDIO-8789
Change-Id: Id1b224f9e5dc2666fc4364fccde0cd79eb164f05
This commit is contained in:
zhou.xu 2024-11-18 09:19:39 +08:00 committed by Lane.Wei
parent d7c65dd992
commit c1179de25a
5 changed files with 16 additions and 14 deletions

View File

@ -3241,10 +3241,10 @@ std::string ModelVolume::type_to_string(const ModelVolumeType t)
// Split this volume, append the result to the object owning this volume. // Split this volume, append the result to the object owning this volume.
// Return the number of volumes created from this one. // Return the number of volumes created from this one.
// This is useful to assign different materials to different volumes of an object. // This is useful to assign different materials to different volumes of an object.
size_t ModelVolume::split(unsigned int max_extruders) size_t ModelVolume::split(unsigned int max_extruders, float scale_det)
{ {
std::vector<std::unordered_map<int, int>> ships; std::vector<std::unordered_map<int, int>> ships;
std::vector<TriangleMesh> meshes = this->mesh().split_and_save_relationship(ships); std::vector<TriangleMesh> meshes = this->mesh().split_and_save_relationship(ships, scale_det);
if (meshes.size() <= 1) if (meshes.size() <= 1)
return 1; return 1;
if (meshes.size() != ships.size()) if (meshes.size() != ships.size())

View File

@ -959,7 +959,7 @@ public:
// Split this volume, append the result to the object owning this volume. // Split this volume, append the result to the object owning this volume.
// Return the number of volumes created from this one. // Return the number of volumes created from this one.
// This is useful to assign different materials to different volumes of an object. // This is useful to assign different materials to different volumes of an object.
size_t split(unsigned int max_extruders); size_t split(unsigned int max_extruders, float scale_det = 1.f);
void translate(double x, double y, double z) { translate(Vec3d(x, y, z)); } void translate(double x, double y, double z) { translate(Vec3d(x, y, z)); }
void translate(const Vec3d& displacement); void translate(const Vec3d& displacement);
void scale(const Vec3d& scaling_factors); void scale(const Vec3d& scaling_factors);

View File

@ -386,8 +386,8 @@ bool TriangleMesh::is_splittable() const
{ {
return its_is_splittable(this->its); return its_is_splittable(this->its);
} }
const float MIN_MESH_VOLUME = 1e-2f;
std::vector<TriangleMesh> TriangleMesh::split() const std::vector<TriangleMesh> TriangleMesh::split(float scale_det) const
{ {
std::vector<indexed_triangle_set> itss = its_split(this->its); std::vector<indexed_triangle_set> itss = its_split(this->its);
std::vector<TriangleMesh> out; std::vector<TriangleMesh> out;
@ -395,7 +395,7 @@ std::vector<TriangleMesh> TriangleMesh::split() const
for (indexed_triangle_set &m : itss) { for (indexed_triangle_set &m : itss) {
// The TriangleMesh constructor shall fill in the mesh statistics including volume. // The TriangleMesh constructor shall fill in the mesh statistics including volume.
TriangleMesh temp_triangle_mesh(std::move(m)); TriangleMesh temp_triangle_mesh(std::move(m));
if (abs(temp_triangle_mesh.volume()< 0.01)) {//0.01mm^3 if (abs(temp_triangle_mesh.volume() * scale_det) < MIN_MESH_VOLUME) {
continue; continue;
} }
if (temp_triangle_mesh.volume() < 0) {// Some source mesh parts may be incorrectly oriented. Correct them. if (temp_triangle_mesh.volume() < 0) {// Some source mesh parts may be incorrectly oriented. Correct them.
@ -406,7 +406,8 @@ std::vector<TriangleMesh> TriangleMesh::split() const
return out; return out;
} }
std::vector<TriangleMesh> TriangleMesh::split_and_save_relationship(std::vector<std::unordered_map<int, int>> &result) const { std::vector<TriangleMesh> TriangleMesh::split_and_save_relationship(std::vector<std::unordered_map<int, int>> &result, float scale_det) const
{
auto itss_and_ships = its_split_and_save_relationship<>(this->its); auto itss_and_ships = its_split_and_save_relationship<>(this->its);
std::vector<TriangleMesh> out; std::vector<TriangleMesh> out;
out.reserve(itss_and_ships.itses.size()); out.reserve(itss_and_ships.itses.size());
@ -415,7 +416,7 @@ std::vector<TriangleMesh> TriangleMesh::split_and_save_relationship(std::vector<
for (indexed_triangle_set &m : itss_and_ships.itses) { for (indexed_triangle_set &m : itss_and_ships.itses) {
// The TriangleMesh constructor shall fill in the mesh statistics including volume. // The TriangleMesh constructor shall fill in the mesh statistics including volume.
TriangleMesh temp_triangle_mesh(std::move(m)); TriangleMesh temp_triangle_mesh(std::move(m));
if (abs(temp_triangle_mesh.volume() < 0.01)) { // 0.01mm^3 if (abs(temp_triangle_mesh.volume() * scale_det) < MIN_MESH_VOLUME) {
index++; index++;
continue; continue;
} }

View File

@ -118,8 +118,8 @@ public:
void flip_triangles(); void flip_triangles();
void align_to_origin(); void align_to_origin();
void rotate(double angle, Point* center); void rotate(double angle, Point* center);
std::vector<TriangleMesh> split() const; std::vector<TriangleMesh> split(float scale_det = 1.f) const;
std::vector<TriangleMesh> split_and_save_relationship(std::vector<std::unordered_map<int, int>> &result) const; std::vector<TriangleMesh> split_and_save_relationship(std::vector<std::unordered_map<int, int>> &result, float scale_det = 1.f) const;
void merge(const TriangleMesh &mesh); void merge(const TriangleMesh &mesh);
ExPolygons horizontal_projection() const; ExPolygons horizontal_projection() const;
// 2D convex hull of a 3D mesh projected into the Z=0 plane. // 2D convex hull of a 3D mesh projected into the Z=0 plane.

View File

@ -2695,12 +2695,13 @@ void ObjectList::split()
} }
take_snapshot("Split to parts"); take_snapshot("Split to parts");
volume->split(filament_cnt);
wxBusyCursor wait; wxBusyCursor wait;
auto model_object = (*m_objects)[obj_idx];
auto world_tran = model_object->instances[0]->get_transformation().get_matrix() * volume->get_matrix();
float scale_det = std::fabs(world_tran.matrix().block(0, 0, 3, 3).determinant());
volume->split(filament_cnt, scale_det);
auto model_object = (*m_objects)[obj_idx];
auto parent = m_objects_model->GetObject(item); auto parent = m_objects_model->GetObject(item);
if (parent) if (parent)