Prusa Slicer 2.6.0
Loading...
Searching...
No Matches
Slic3r::MeshBoolean::cgal Namespace Reference

Classes

struct  CGALMesh
 
struct  CGALMeshDeleter
 

Typedefs

using EpecKernel = CGAL::Exact_predicates_exact_constructions_kernel
 
using EpicKernel = CGAL::Exact_predicates_inexact_constructions_kernel
 
using _EpicMesh = CGAL::Surface_mesh< EpicKernel::Point_3 >
 
using _EpecMesh = CGAL::Surface_mesh< EpecKernel::Point_3 >
 
using CGALMeshPtr = std::unique_ptr< CGALMesh, CGALMeshDeleter >
 

Functions

template<class _Mesh >
void triangle_mesh_to_cgal (const std::vector< stl_vertex > &V, const std::vector< stl_triangle_vertex_indices > &F, _Mesh &out)
 
Vec3f to_vec3f (const _EpicMesh::Point &v)
 
Vec3f to_vec3f (const _EpecMesh::Point &v)
 
template<class _Mesh >
indexed_triangle_set cgal_to_indexed_triangle_set (const _Mesh &cgalmesh)
 
std::unique_ptr< CGALMesh, CGALMeshDeletertriangle_mesh_to_cgal (const std::vector< stl_vertex > &V, const std::vector< stl_triangle_vertex_indices > &F)
 
TriangleMesh cgal_to_triangle_mesh (const CGALMesh &cgalmesh)
 
indexed_triangle_set cgal_to_indexed_triangle_set (const CGALMesh &cgalmesh)
 
static bool _cgal_diff (CGALMesh &A, CGALMesh &B, CGALMesh &R)
 
static bool _cgal_union (CGALMesh &A, CGALMesh &B, CGALMesh &R)
 
static bool _cgal_intersection (CGALMesh &A, CGALMesh &B, CGALMesh &R)
 
template<class Op >
void _cgal_do (Op &&op, CGALMesh &A, CGALMesh &B)
 
void minus (CGALMesh &A, CGALMesh &B)
 
void plus (CGALMesh &A, CGALMesh &B)
 
void intersect (CGALMesh &A, CGALMesh &B)
 
bool does_self_intersect (const CGALMesh &mesh)
 
template<class Op >
void _mesh_boolean_do (Op &&op, indexed_triangle_set &A, const indexed_triangle_set &B)
 
template<class Op >
void _mesh_boolean_do (Op &&op, TriangleMesh &A, const TriangleMesh &B)
 
void minus (TriangleMesh &A, const TriangleMesh &B)
 
void plus (TriangleMesh &A, const TriangleMesh &B)
 
void intersect (TriangleMesh &A, const TriangleMesh &B)
 
void minus (indexed_triangle_set &A, const indexed_triangle_set &B)
 
void plus (indexed_triangle_set &A, const indexed_triangle_set &B)
 
void intersect (indexed_triangle_set &A, const indexed_triangle_set &B)
 
bool does_self_intersect (const TriangleMesh &mesh)
 
bool does_bound_a_volume (const CGALMesh &mesh)
 
bool empty (const CGALMesh &mesh)
 
CGALMeshPtr clone (const CGALMesh &m)
 
CGALMeshPtr triangle_mesh_to_cgal (const indexed_triangle_set &M)
 
CGALMeshPtr triangle_mesh_to_cgal (const TriangleMesh &M)
 

Class Documentation

◆ Slic3r::MeshBoolean::cgal::CGALMesh

struct Slic3r::MeshBoolean::cgal::CGALMesh
Class Members
_EpicMesh m

Typedef Documentation

◆ _EpecMesh

using Slic3r::MeshBoolean::cgal::_EpecMesh = typedef CGAL::Surface_mesh<EpecKernel::Point_3>

◆ _EpicMesh

using Slic3r::MeshBoolean::cgal::_EpicMesh = typedef CGAL::Surface_mesh<EpicKernel::Point_3>

◆ CGALMeshPtr

◆ EpecKernel

using Slic3r::MeshBoolean::cgal::EpecKernel = typedef CGAL::Exact_predicates_exact_constructions_kernel

◆ EpicKernel

using Slic3r::MeshBoolean::cgal::EpicKernel = typedef CGAL::Exact_predicates_inexact_constructions_kernel

Function Documentation

◆ _cgal_diff()

static bool Slic3r::MeshBoolean::cgal::_cgal_diff ( CGALMesh A,
CGALMesh B,
CGALMesh R 
)
static
198{
199 const auto &p = CGALParams::throw_on_self_intersection(true);
200 return CGALProc::corefine_and_compute_difference(A.m, B.m, R.m, p, p);
201}
_EpicMesh m
Definition MeshBoolean.cpp:102

References _cgal_diff(), and Slic3r::MeshBoolean::cgal::CGALMesh::m.

Referenced by _cgal_diff(), minus(), minus(), and minus().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ _cgal_do()

template<class Op >
void Slic3r::MeshBoolean::cgal::_cgal_do ( Op &&  op,
CGALMesh A,
CGALMesh B 
)
216{
217 bool success = false;
218 bool hw_fail = false;
219 try {
220 CGALMesh result;
221 try_catch_signal({SIGSEGV, SIGFPE}, [&success, &A, &B, &result, &op] {
222 success = op(A, B, result);
223 }, [&] { hw_fail = true; });
224 A = std::move(result); // In-place operation does not work
225 } catch (...) {
226 success = false;
227 }
228
229 if (hw_fail)
230 throw Slic3r::HardCrash("CGAL mesh boolean operation crashed.");
231
232 if (! success)
233 throw Slic3r::RuntimeError("CGAL mesh boolean operation failed.");
234}
void try_catch_signal(const SignalT(&)[N], TryFn &&fn, CatchFn &&)
Definition TryCatchSignal.hpp:13
Definition MeshBoolean.cpp:102

References _cgal_do(), and Slic3r::try_catch_signal().

Referenced by _cgal_do(), _mesh_boolean_do(), _mesh_boolean_do(), intersect(), minus(), and plus().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ _cgal_intersection()

static bool Slic3r::MeshBoolean::cgal::_cgal_intersection ( CGALMesh A,
CGALMesh B,
CGALMesh R 
)
static
210{
211 const auto &p = CGALParams::throw_on_self_intersection(true);
212 return CGALProc::corefine_and_compute_intersection(A.m, B.m, R.m, p, p);
213}

References _cgal_intersection(), and Slic3r::MeshBoolean::cgal::CGALMesh::m.

Referenced by _cgal_intersection(), intersect(), intersect(), and intersect().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ _cgal_union()

static bool Slic3r::MeshBoolean::cgal::_cgal_union ( CGALMesh A,
CGALMesh B,
CGALMesh R 
)
static
204{
205 const auto &p = CGALParams::throw_on_self_intersection(true);
206 return CGALProc::corefine_and_compute_union(A.m, B.m, R.m, p, p);
207}

References _cgal_union(), and Slic3r::MeshBoolean::cgal::CGALMesh::m.

Referenced by _cgal_union(), plus(), plus(), and plus().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ _mesh_boolean_do() [1/2]

template<class Op >
void Slic3r::MeshBoolean::cgal::_mesh_boolean_do ( Op &&  op,
indexed_triangle_set A,
const indexed_triangle_set B 
)
246{
247 CGALMesh meshA;
248 CGALMesh meshB;
251
252 _cgal_do(op, meshA, meshB);
253
255}
void _cgal_do(Op &&op, CGALMesh &A, CGALMesh &B)
Definition MeshBoolean.cpp:215
void triangle_mesh_to_cgal(const std::vector< stl_vertex > &V, const std::vector< stl_triangle_vertex_indices > &F, _Mesh &out)
Definition MeshBoolean.cpp:109
indexed_triangle_set cgal_to_indexed_triangle_set(const _Mesh &cgalmesh)
Definition MeshBoolean.cpp:141
std::vector< stl_vertex > vertices
Definition stl.h:165
std::vector< stl_triangle_vertex_indices > indices
Definition stl.h:164

References _cgal_do(), _mesh_boolean_do(), cgal_to_indexed_triangle_set(), indexed_triangle_set::indices, Slic3r::MeshBoolean::cgal::CGALMesh::m, triangle_mesh_to_cgal(), and indexed_triangle_set::vertices.

Referenced by _mesh_boolean_do(), _mesh_boolean_do(), intersect(), intersect(), minus(), minus(), plus(), and plus().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ _mesh_boolean_do() [2/2]

template<class Op >
void Slic3r::MeshBoolean::cgal::_mesh_boolean_do ( Op &&  op,
TriangleMesh A,
const TriangleMesh B 
)
258{
259 CGALMesh meshA;
260 CGALMesh meshB;
263
264 _cgal_do(op, meshA, meshB);
265
266 A = cgal_to_triangle_mesh(meshA);
267}
indexed_triangle_set its
Definition TriangleMesh.hpp:155
TriangleMesh cgal_to_triangle_mesh(const CGALMesh &cgalmesh)
Definition MeshBoolean.cpp:183

References _cgal_do(), _mesh_boolean_do(), cgal_to_triangle_mesh(), indexed_triangle_set::indices, Slic3r::TriangleMesh::its, Slic3r::MeshBoolean::cgal::CGALMesh::m, triangle_mesh_to_cgal(), and indexed_triangle_set::vertices.

+ Here is the call graph for this function:

◆ cgal_to_indexed_triangle_set() [1/2]

template<class _Mesh >
indexed_triangle_set Slic3r::MeshBoolean::cgal::cgal_to_indexed_triangle_set ( const _Mesh &  cgalmesh)
142{
144 its.vertices.reserve(cgalmesh.num_vertices());
145 its.indices.reserve(cgalmesh.num_faces());
146
147 const auto &faces = cgalmesh.faces();
148 const auto &vertices = cgalmesh.vertices();
149 int vsize = int(vertices.size());
150
151 for (auto &vi : vertices) {
152 auto &v = cgalmesh.point(vi); // Don't ask...
153 its.vertices.emplace_back(to_vec3f(v));
154 }
155
156 for (auto &face : faces) {
157 auto vtc = cgalmesh.vertices_around_face(cgalmesh.halfedge(face));
158
159 int i = 0;
160 Vec3i facet;
161 for (auto v : vtc) {
162 int iv = v;
163 if (i > 2 || iv < 0 || iv >= vsize) { i = 0; break; }
164 facet(i++) = iv;
165 }
166
167 if (i == 3)
168 its.indices.emplace_back(facet);
169 }
170
171 return its;
172}
Vec3f to_vec3f(const _EpicMesh::Point &v)
Definition MeshBoolean.cpp:128
Definition stl.h:157

References cgal_to_indexed_triangle_set(), indexed_triangle_set::indices, Slic3r::to_vec3f(), and indexed_triangle_set::vertices.

Referenced by _mesh_boolean_do(), cgal_to_indexed_triangle_set(), cgal_to_indexed_triangle_set(), cgal_to_triangle_mesh(), and Slic3r::SLAPrint::Steps::generate_preview().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ cgal_to_indexed_triangle_set() [2/2]

indexed_triangle_set Slic3r::MeshBoolean::cgal::cgal_to_indexed_triangle_set ( const CGALMesh cgalmesh)
189{
190 return cgal_to_indexed_triangle_set(cgalmesh.m);
191}

References cgal_to_indexed_triangle_set(), and Slic3r::MeshBoolean::cgal::CGALMesh::m.

+ Here is the call graph for this function:

◆ cgal_to_triangle_mesh()

TriangleMesh Slic3r::MeshBoolean::cgal::cgal_to_triangle_mesh ( const CGALMesh cgalmesh)
184{
186}
Definition TriangleMesh.hpp:88

References cgal_to_indexed_triangle_set(), cgal_to_triangle_mesh(), and Slic3r::MeshBoolean::cgal::CGALMesh::m.

Referenced by _mesh_boolean_do(), cgal_to_triangle_mesh(), and Slic3r::GUI::Plater::export_stl_obj().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ clone()

CGALMeshPtr Slic3r::MeshBoolean::cgal::clone ( const CGALMesh m)
319{
320 return CGALMeshPtr{new CGALMesh{m}};
321}
std::unique_ptr< CGALMesh, CGALMeshDeleter > CGALMeshPtr
Definition MeshBoolean.hpp:29

◆ does_bound_a_volume()

bool Slic3r::MeshBoolean::cgal::does_bound_a_volume ( const CGALMesh mesh)
309{
310 return CGAL::is_closed(mesh.m) && CGALProc::does_bound_a_volume(mesh.m);
311}

References does_bound_a_volume(), and Slic3r::MeshBoolean::cgal::CGALMesh::m.

Referenced by Slic3r::csg::check_csgmesh_booleans(), and does_bound_a_volume().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ does_self_intersect() [1/2]

bool Slic3r::MeshBoolean::cgal::does_self_intersect ( const CGALMesh mesh)
239{ return CGALProc::does_self_intersect(mesh.m); }

References does_self_intersect(), and Slic3r::MeshBoolean::cgal::CGALMesh::m.

Referenced by Slic3r::csg::check_csgmesh_booleans(), does_self_intersect(), and does_self_intersect().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ does_self_intersect() [2/2]

bool Slic3r::MeshBoolean::cgal::does_self_intersect ( const TriangleMesh mesh)
300{
301 CGALMesh cgalm;
302 triangle_mesh_to_cgal(mesh.its.vertices, mesh.its.indices, cgalm.m);
303 return CGALProc::does_self_intersect(cgalm.m);
304}

References does_self_intersect(), indexed_triangle_set::indices, Slic3r::TriangleMesh::its, Slic3r::MeshBoolean::cgal::CGALMesh::m, triangle_mesh_to_cgal(), and indexed_triangle_set::vertices.

+ Here is the call graph for this function:

◆ empty()

bool Slic3r::MeshBoolean::cgal::empty ( const CGALMesh mesh)
314{
315 return mesh.m.is_empty();
316}

References Slic3r::MeshBoolean::cgal::CGALMesh::m.

Referenced by Slic3r::csg::check_csgmesh_booleans().

+ Here is the caller graph for this function:

◆ intersect() [1/3]

void Slic3r::MeshBoolean::cgal::intersect ( CGALMesh A,
CGALMesh B 
)
238{ _cgal_do(_cgal_intersection, A, B); }

References _cgal_do(), and _cgal_intersection().

Referenced by Slic3r::csg::detail_cgal::perform_csg().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ intersect() [2/3]

void Slic3r::MeshBoolean::cgal::intersect ( indexed_triangle_set A,
const indexed_triangle_set B 
)
295{
296 _mesh_boolean_do(_cgal_intersection, A, B);
297}
void _mesh_boolean_do(Op &&op, indexed_triangle_set &A, const indexed_triangle_set &B)
Definition MeshBoolean.cpp:245

References _cgal_intersection(), and _mesh_boolean_do().

+ Here is the call graph for this function:

◆ intersect() [3/3]

void Slic3r::MeshBoolean::cgal::intersect ( TriangleMesh A,
const TriangleMesh B 
)
280{
281 _mesh_boolean_do(_cgal_intersection, A, B);
282}

References _cgal_intersection(), and _mesh_boolean_do().

+ Here is the call graph for this function:

◆ minus() [1/3]

void Slic3r::MeshBoolean::cgal::minus ( CGALMesh A,
CGALMesh B 
)
236{ _cgal_do(_cgal_diff, A, B); }

References _cgal_diff(), and _cgal_do().

Referenced by Slic3r::csg::detail_cgal::perform_csg().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ minus() [2/3]

void Slic3r::MeshBoolean::cgal::minus ( indexed_triangle_set A,
const indexed_triangle_set B 
)
285{
286 _mesh_boolean_do(_cgal_diff, A, B);
287}

References _cgal_diff(), and _mesh_boolean_do().

+ Here is the call graph for this function:

◆ minus() [3/3]

void Slic3r::MeshBoolean::cgal::minus ( TriangleMesh A,
const TriangleMesh B 
)
270{
271 _mesh_boolean_do(_cgal_diff, A, B);
272}

References _cgal_diff(), and _mesh_boolean_do().

+ Here is the call graph for this function:

◆ plus() [1/3]

void Slic3r::MeshBoolean::cgal::plus ( CGALMesh A,
CGALMesh B 
)
237{ _cgal_do(_cgal_union, A, B); }

References _cgal_do(), _cgal_union(), and plus().

Referenced by Slic3r::csg::detail_cgal::perform_csg(), plus(), plus(), and plus().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ plus() [2/3]

void Slic3r::MeshBoolean::cgal::plus ( indexed_triangle_set A,
const indexed_triangle_set B 
)
290{
291 _mesh_boolean_do(_cgal_union, A, B);
292}

References _cgal_union(), _mesh_boolean_do(), and plus().

+ Here is the call graph for this function:

◆ plus() [3/3]

void Slic3r::MeshBoolean::cgal::plus ( TriangleMesh A,
const TriangleMesh B 
)
275{
276 _mesh_boolean_do(_cgal_union, A, B);
277}

References _cgal_union(), _mesh_boolean_do(), and plus().

+ Here is the call graph for this function:

◆ to_vec3f() [1/2]

Vec3f Slic3r::MeshBoolean::cgal::to_vec3f ( const _EpecMesh::Point &  v)
inline
134{
135 CGAL::Cartesian_converter<EpecKernel, EpicKernel> cvt;
136 auto iv = cvt(v);
137 return { float(iv.x()), float(iv.y()), float(iv.z()) };
138}

◆ to_vec3f() [2/2]

Vec3f Slic3r::MeshBoolean::cgal::to_vec3f ( const _EpicMesh::Point &  v)
inline
129{
130 return { float(v.x()), float(v.y()), float(v.z()) };
131}

◆ triangle_mesh_to_cgal() [1/4]

CGALMeshPtr Slic3r::MeshBoolean::cgal::triangle_mesh_to_cgal ( const indexed_triangle_set M)
inline
38{
40}

References indexed_triangle_set::indices, triangle_mesh_to_cgal(), and indexed_triangle_set::vertices.

+ Here is the call graph for this function:

◆ triangle_mesh_to_cgal() [2/4]

CGALMeshPtr Slic3r::MeshBoolean::cgal::triangle_mesh_to_cgal ( const std::vector< stl_vertex > &  V,
const std::vector< stl_triangle_vertex_indices > &  F 
)
177{
178 std::unique_ptr<CGALMesh, CGALMeshDeleter> out(new CGALMesh{});
179 triangle_mesh_to_cgal(V, F, out->m);
180 return out;
181}

References Slic3r::F, and triangle_mesh_to_cgal().

+ Here is the call graph for this function:

◆ triangle_mesh_to_cgal() [3/4]

template<class _Mesh >
void Slic3r::MeshBoolean::cgal::triangle_mesh_to_cgal ( const std::vector< stl_vertex > &  V,
const std::vector< stl_triangle_vertex_indices > &  F,
_Mesh &  out 
)
112{
113 if (F.empty()) return;
114
115 size_t vertices_count = V.size();
116 size_t edges_count = (F.size()* 3) / 2;
117 size_t faces_count = F.size();
118 out.reserve(vertices_count, edges_count, faces_count);
119
120 for (auto &v : V)
121 out.add_vertex(typename _Mesh::Point{v.x(), v.y(), v.z()});
122
123 using VI = typename _Mesh::Vertex_index;
124 for (auto &f : F)
125 out.add_face(VI(f(0)), VI(f(1)), VI(f(2)));
126}
Definition Point.hpp:158
@ F
Definition libslic3r.h:102

References Slic3r::F.

Referenced by _mesh_boolean_do(), _mesh_boolean_do(), Slic3r::csg::check_csgmesh_booleans(), does_self_intersect(), Slic3r::csg::get_cgalmesh(), Slic3r::csg::perform_csgmesh_booleans(), triangle_mesh_to_cgal(), triangle_mesh_to_cgal(), and triangle_mesh_to_cgal().

+ Here is the caller graph for this function:

◆ triangle_mesh_to_cgal() [4/4]

CGALMeshPtr Slic3r::MeshBoolean::cgal::triangle_mesh_to_cgal ( const TriangleMesh M)
inline
42{
43 return triangle_mesh_to_cgal(M.its);
44}

References Slic3r::TriangleMesh::its, and triangle_mesh_to_cgal().

+ Here is the call graph for this function: