Repository navigation
Expand file tree
/
Copy pathBooleanEngine.cpp
More file actions
165 lines (151 loc) · 4.19 KB
/
Copy pathBooleanEngine.cpp
File metadata and controls
165 lines (151 loc) · 4.19 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
/* This file is part of PyMesh. Copyright (c) 2015 by Qingnan Zhou */
#include "BooleanEngine.h"
#ifdef WITH_CORK
#include "Cork/CorkEngine.h"
#endif
#ifdef WITH_CLIPPER
#include "Clipper/ClipperEngine.h"
#endif
#ifdef WITH_IGL_AND_CGAL
#include "IGL/IGLEngine.h"
#endif
#ifdef WITH_CGAL
#include "CGAL/CGALBooleanEngine.h"
#ifdef WITH_CGAL_COREFINEMENT
#include "CGAL/CGALCorefinementEngine.h"
#endif
#endif
#ifdef WITH_CARVE
#include "Carve/CarveEngine.h"
#endif
#ifdef WITH_BSP
#include "BSP/BSPEngine.h"
#endif
#include <sstream>
#include <iostream>
#include <Core/Exception.h>
#include <MeshUtils/DuplicatedVertexRemoval.h>
#include <MeshUtils/IsolatedVertexRemoval.h>
#include <MeshUtils/ShortEdgeRemoval.h>
using namespace PyMesh;
BooleanEngine::Ptr BooleanEngine::create(const std::string& engine_name) {
if (engine_name == "auto") {
#if WITH_IGL_AND_CGAL
return BooleanEngine::create("igl");
#elif WITH_CORK
return BooleanEngine::create("cork");
#elif WITH_CLIPPER
return BooleanEngine::create("clipper");
#elif WITH_CGAL
return BooleanEngine::create("cgal");
#elif WITH_CARVE
return BooleanEngine::create("carve");
#elif WITH_BSP
#endif
}
#ifdef WITH_CORK
if (engine_name == "cork") { return Ptr(new CorkEngine()); }
#endif
#ifdef WITH_CLIPPER
if (engine_name == "clipper") { return Ptr(new ClipperEngine()); }
#endif
#ifdef WITH_IGL_AND_CGAL
if (engine_name == "igl") { return Ptr(new IGLEngine()); }
#endif
#ifdef WITH_CGAL
if (engine_name == "cgal") { return Ptr(new CGALBooleanEngine()); }
#ifdef WITH_CGAL_COREFINEMENT
if (engine_name == "corefinement") {
return Ptr(new CGALCorefinementEngine());
}
#endif
#endif
#ifdef WITH_CARVE
if (engine_name == "carve") { return Ptr(new CarveEngine()); }
#endif
#ifdef WITH_BSP
if (engine_name == "bsp") { return Ptr(new BSPEngine()); }
#endif
std::stringstream err_msg;
err_msg << "Boolean engine \"" << engine_name
<< "\" is not supported." << std::endl;
throw NotImplementedError(err_msg.str());
}
bool BooleanEngine::supports(const std::string& engine_name) {
#if WITH_IGL_AND_CGAL
if (engine_name == "igl") return true;
#endif
#if WITH_CORK
if (engine_name == "cork") return true;
#endif
#if WITH_CLIPPER
if (engine_name == "clipper") return true;
#endif
#if WITH_CGAL
if (engine_name == "cgal") return true;
#endif
#if WITH_CGAL_COREFINEMENT
if (engine_name == "corefinement") return true;
#endif
#if WITH_CARVE
if (engine_name == "carve") return true;
#endif
#if WITH_BSP
if (engine_name == "bsp") return true;
#endif
return false;
}
std::vector<std::string> get_available_engines() {
std::vector<std::string> engine_names;
#if WITH_IGL_AND_CGAL
engine_names.push_back("igl");
#endif
#if WITH_CORK
engine_names.push_back("cork");
#endif
#if WITH_CLIPPER
engine_names.push_back("clipper");
#endif
#if WITH_CGAL
engine_names.push_back("cgal");
#endif
#if WITH_CGAL_COREFINEMENT
engine_names.push_back("corefinement");
#endif
#if WITH_CARVE
engine_names.push_back("carve");
#endif
#if WITH_BSP
engine_names.push_back("bsp");
#endif
return engine_names;
}
void BooleanEngine::clean_up() {
remove_duplicated_vertices();
remove_short_edges();
remove_isolated_vertices();
}
void BooleanEngine::remove_duplicated_vertices() {
DuplicatedVertexRemoval remover(m_vertices, m_faces);
size_t num_removed = remover.run(1e-6);
assert(num_removed <= m_vertices.rows());
m_vertices = remover.get_vertices();
m_faces = remover.get_faces();
}
void BooleanEngine::remove_short_edges() {
ShortEdgeRemoval remover(m_vertices, m_faces);
size_t num_removed = remover.run(1e-6);
assert(num_removed <= m_faces.rows() * m_faces.cols());
m_vertices = remover.get_vertices();
m_faces = remover.get_faces();
}
void BooleanEngine::remove_isolated_vertices() {
IsolatedVertexRemoval remover(m_vertices, m_faces);
size_t num_removed = remover.run();
assert(num_removed <= m_vertices.rows());
m_vertices = remover.get_vertices();
m_faces = remover.get_faces();
}
void BooleanEngine::serialize_xml(const std::string& filename) const {
throw NotImplementedError("Serialization is not supported");
}