mirror of
https://github.com/SoftFever/OrcaSlicer.git
synced 2025-10-19 06:41:14 -06:00
NEW: add boolean in export stl
Change-Id: Ibeab33f27ad7a2531bb256edd0e3f853cf8def7c (cherry picked from commit 6cfb4371a1b9053b54569d91a9c29af97a753c0e)
This commit is contained in:
parent
2c620aa855
commit
7c5e96a43a
21 changed files with 1664 additions and 134 deletions
|
@ -12,6 +12,7 @@
|
|||
#include <CGAL/Polygon_mesh_processing/corefinement.h>
|
||||
#include <CGAL/Exact_integer.h>
|
||||
#include <CGAL/Surface_mesh.h>
|
||||
#include <CGAL/Cartesian_converter.h>
|
||||
#include <CGAL/Polygon_mesh_processing/orient_polygon_soup.h>
|
||||
#include <CGAL/Polygon_mesh_processing/repair.h>
|
||||
#include <CGAL/Polygon_mesh_processing/remesh.h>
|
||||
|
@ -114,6 +115,11 @@ struct CGALMesh {
|
|||
CGALMesh(const _EpicMesh& _m) :m(_m) {}
|
||||
};
|
||||
|
||||
void save_CGALMesh(const std::string& fname, const CGALMesh& cgal_mesh) {
|
||||
std::ofstream os(fname);
|
||||
os << cgal_mesh.m;
|
||||
os.close();
|
||||
}
|
||||
// /////////////////////////////////////////////////////////////////////////////
|
||||
// Converions from and to CGAL mesh
|
||||
// /////////////////////////////////////////////////////////////////////////////
|
||||
|
@ -179,7 +185,8 @@ inline Vec3f to_vec3f(const _EpecMesh::Point& v)
|
|||
return { float(iv.x()), float(iv.y()), float(iv.z()) };
|
||||
}
|
||||
|
||||
template<class _Mesh> TriangleMesh cgal_to_triangle_mesh(const _Mesh &cgalmesh)
|
||||
template<class _Mesh>
|
||||
indexed_triangle_set cgal_to_indexed_triangle_set(const _Mesh &cgalmesh)
|
||||
{
|
||||
indexed_triangle_set its;
|
||||
its.vertices.reserve(cgalmesh.num_vertices());
|
||||
|
@ -209,7 +216,7 @@ template<class _Mesh> TriangleMesh cgal_to_triangle_mesh(const _Mesh &cgalmesh)
|
|||
its.indices.emplace_back(facet);
|
||||
}
|
||||
|
||||
return TriangleMesh(std::move(its));
|
||||
return its;
|
||||
}
|
||||
|
||||
std::unique_ptr<CGALMesh, CGALMeshDeleter>
|
||||
|
@ -223,7 +230,12 @@ triangle_mesh_to_cgal(const std::vector<stl_vertex> &V,
|
|||
|
||||
TriangleMesh cgal_to_triangle_mesh(const CGALMesh &cgalmesh)
|
||||
{
|
||||
return cgal_to_triangle_mesh(cgalmesh.m);
|
||||
return TriangleMesh{cgal_to_indexed_triangle_set(cgalmesh.m)};
|
||||
}
|
||||
|
||||
indexed_triangle_set cgal_to_indexed_triangle_set(const CGALMesh &cgalmesh)
|
||||
{
|
||||
return cgal_to_indexed_triangle_set(cgalmesh.m);
|
||||
}
|
||||
|
||||
// /////////////////////////////////////////////////////////////////////////////
|
||||
|
@ -303,10 +315,7 @@ void segment(CGALMesh& src, std::vector<CGALMesh>& dst, double smoothing_alpha =
|
|||
_EpicMesh out;
|
||||
CGAL::copy_face_graph(segment_mesh, out);
|
||||
|
||||
//std::ostringstream oss;
|
||||
//oss << "Segment_" << id << ".off";
|
||||
//std::ofstream os(oss.str().data());
|
||||
//os << out;
|
||||
// save_CGALMesh("out.off", out);
|
||||
|
||||
// fill holes
|
||||
typedef boost::graph_traits<_EpicMesh>::halfedge_descriptor halfedge_descriptor;
|
||||
|
@ -382,9 +391,17 @@ TriangleMesh merge(std::vector<TriangleMesh> meshes)
|
|||
return cgal_to_triangle_mesh(dst);
|
||||
}
|
||||
|
||||
// /////////////////////////////////////////////////////////////////////////////
|
||||
// Now the public functions for TriangleMesh input:
|
||||
// /////////////////////////////////////////////////////////////////////////////
|
||||
template<class Op> void _mesh_boolean_do(Op &&op, indexed_triangle_set &A, const indexed_triangle_set &B)
|
||||
{
|
||||
CGALMesh meshA;
|
||||
CGALMesh meshB;
|
||||
triangle_mesh_to_cgal(A.vertices, A.indices, meshA.m);
|
||||
triangle_mesh_to_cgal(B.vertices, B.indices, meshB.m);
|
||||
|
||||
_cgal_do(op, meshA, meshB);
|
||||
|
||||
A = cgal_to_indexed_triangle_set(meshA.m);
|
||||
}
|
||||
|
||||
template<class Op> void _mesh_boolean_do(Op &&op, TriangleMesh &A, const TriangleMesh &B)
|
||||
{
|
||||
|
@ -392,10 +409,10 @@ template<class Op> void _mesh_boolean_do(Op &&op, TriangleMesh &A, const Triangl
|
|||
CGALMesh meshB;
|
||||
triangle_mesh_to_cgal(A.its.vertices, A.its.indices, meshA.m);
|
||||
triangle_mesh_to_cgal(B.its.vertices, B.its.indices, meshB.m);
|
||||
|
||||
|
||||
_cgal_do(op, meshA, meshB);
|
||||
|
||||
A = cgal_to_triangle_mesh(meshA.m);
|
||||
|
||||
A = cgal_to_triangle_mesh(meshA);
|
||||
}
|
||||
|
||||
void minus(TriangleMesh &A, const TriangleMesh &B)
|
||||
|
@ -413,6 +430,21 @@ void intersect(TriangleMesh &A, const TriangleMesh &B)
|
|||
_mesh_boolean_do(_cgal_intersection, A, B);
|
||||
}
|
||||
|
||||
void minus(indexed_triangle_set &A, const indexed_triangle_set &B)
|
||||
{
|
||||
_mesh_boolean_do(_cgal_diff, A, B);
|
||||
}
|
||||
|
||||
void plus(indexed_triangle_set &A, const indexed_triangle_set &B)
|
||||
{
|
||||
_mesh_boolean_do(_cgal_union, A, B);
|
||||
}
|
||||
|
||||
void intersect(indexed_triangle_set &A, const indexed_triangle_set &B)
|
||||
{
|
||||
_mesh_boolean_do(_cgal_intersection, A, B);
|
||||
}
|
||||
|
||||
bool does_self_intersect(const TriangleMesh &mesh)
|
||||
{
|
||||
CGALMesh cgalm;
|
||||
|
@ -424,7 +456,7 @@ void CGALMeshDeleter::operator()(CGALMesh *ptr) { delete ptr; }
|
|||
|
||||
bool does_bound_a_volume(const CGALMesh &mesh)
|
||||
{
|
||||
return CGALProc::does_bound_a_volume(mesh.m);
|
||||
return CGAL::is_closed(mesh.m) && CGALProc::does_bound_a_volume(mesh.m);
|
||||
}
|
||||
|
||||
bool empty(const CGALMesh &mesh)
|
||||
|
@ -432,7 +464,11 @@ bool empty(const CGALMesh &mesh)
|
|||
return mesh.m.is_empty();
|
||||
}
|
||||
|
||||
} // namespace cgal
|
||||
CGALMeshPtr clone(const CGALMesh &m)
|
||||
{
|
||||
return CGALMeshPtr{new CGALMesh{m}};
|
||||
}
|
||||
|
||||
} // namespace cgal
|
||||
} // namespace MeshBoolean
|
||||
} // namespace Slic3r
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue