-
Notifications
You must be signed in to change notification settings - Fork 183
Expand file tree
/
Copy pathload_test_meshes.cpp
More file actions
178 lines (149 loc) · 5.44 KB
/
load_test_meshes.cpp
File metadata and controls
178 lines (149 loc) · 5.44 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
165
166
167
168
169
170
171
172
173
174
175
176
177
178
#include "load_test_meshes.h"
#include "geometrycentral/surface/meshio.h"
using namespace geometrycentral;
using namespace geometrycentral::surface;
using std::cout;
using std::endl;
// Helpers
namespace {
std::string guessNiceNameFromPath(std::string fullname) {
size_t startInd = 0;
for (std::string sep : {"/", "\\"}) {
size_t pos = fullname.rfind(sep);
if (pos != std::string::npos) {
startInd = std::max(startInd, pos + 1);
}
}
return fullname.substr(startInd, fullname.size() - startInd);
};
} // namespace
MeshAsset::MeshAsset(std::string localPath, bool loadManifold) {
name = guessNiceNameFromPath(localPath);
std::string fullPath = std::string(GC_TEST_ASSETS_ABS_PATH) + "/" + name;
cout << " -- info: Loading mesh asset " << name << " from " << fullPath << endl;
sourcePath = fullPath;
if (loadManifold) {
std::unique_ptr<ManifoldSurfaceMesh> manifMesh;
std::tie(manifMesh, geometry) = readManifoldSurfaceMesh(fullPath);
manifoldMesh = manifMesh.release();
mesh.reset(manifoldMesh);
isSubclassManifoldSurfaceMesh = true;
} else {
std::tie(mesh, geometry) = readSurfaceMesh(fullPath);
isSubclassManifoldSurfaceMesh = false;
}
hasBoundary = mesh->hasBoundary();
isTriangular = mesh->isTriangular();
}
MeshAsset MeshAsset::copy() const {
MeshAsset newM;
newM.name = name;
newM.sourcePath = sourcePath;
newM.mesh = mesh->copy();
if (geometry) {
newM.geometry = geometry->reinterpretTo(*newM.mesh);
}
newM.isSubclassManifoldSurfaceMesh = isSubclassManifoldSurfaceMesh;
if (isSubclassManifoldSurfaceMesh) {
newM.manifoldMesh = dynamic_cast<ManifoldSurfaceMesh*>(newM.mesh.get());
}
newM.hasBoundary = hasBoundary;
newM.isTriangular = isTriangular;
newM.isPolygonalComplex = isPolygonalComplex;
return newM;
}
void MeshAsset::printThyName() const { cout << " testing on mesh (" << (isSubclassManifoldSurfaceMesh ? "manifold" : "general") << "): " << name << endl; }
// Static storage for mesh assets
std::vector<MeshAsset> MeshAssetSuite::allMeshAssets;
void MeshAssetSuite::SetUpTestSuite() {
// no need to set up more than once
if (allMeshAssets.size() > 0) return;
// Load manifold surface mesh variants
allMeshAssets.emplace_back("tet.obj", true);
allMeshAssets.emplace_back("spot.ply", true);
allMeshAssets.emplace_back("bob_small.ply", true);
allMeshAssets.emplace_back("sphere_small.ply", true);
allMeshAssets.emplace_back("lego.ply", true);
allMeshAssets.emplace_back("dodecahedron_poly.obj", true);
allMeshAssets.emplace_back("platonic_shelf.obj", true);
allMeshAssets.emplace_back("fox.ply", true);
allMeshAssets.emplace_back("cat_head.obj", true);
allMeshAssets.emplace_back("dijkstra.obj", true);
// Load general surface mesh variants
allMeshAssets.emplace_back("tet.obj", false);
allMeshAssets.emplace_back("spot.ply", false);
allMeshAssets.emplace_back("bob_small.ply", false);
allMeshAssets.emplace_back("sphere_small.ply", false);
allMeshAssets.emplace_back("lego.ply", false);
allMeshAssets.emplace_back("dodecahedron_poly.obj", false);
allMeshAssets.emplace_back("platonic_shelf.obj", false);
allMeshAssets.emplace_back("fox.ply", false);
allMeshAssets.emplace_back("cat_head.obj", false);
// Load nonmanifold models
allMeshAssets.emplace_back("fan3.obj", false);
allMeshAssets.emplace_back("hourglass_ico.obj", false);
allMeshAssets.emplace_back("triple_vierbein.obj", false);
allMeshAssets.emplace_back("moebius.obj", false);
}
MeshAsset MeshAssetSuite::getAsset(std::string name, bool loadManifold) {
for (MeshAsset& a : allMeshAssets) {
if (a.name == name && a.isSubclassManifoldSurfaceMesh == loadManifold) {
return a.copy();
}
}
throw std::runtime_error("no mesh asset named " + name);
}
std::vector<MeshAsset> MeshAssetSuite::allMeshes(bool includeNoGeom) {
std::vector<MeshAsset> result;
for (MeshAsset& a : allMeshAssets) {
if (includeNoGeom || a.geometry) result.push_back(a.copy());
}
return result;
}
std::vector<MeshAsset> MeshAssetSuite::manifoldSurfaceMeshes(bool includeNoGeom) {
std::vector<MeshAsset> result;
for (MeshAsset& a : allMeshAssets) {
if (a.isSubclassManifoldSurfaceMesh) {
if (includeNoGeom || a.geometry) result.push_back(a.copy());
}
}
return result;
}
std::vector<MeshAsset> MeshAssetSuite::closedMeshes(bool includeNoGeom) {
std::vector<MeshAsset> result;
for (MeshAsset& a : allMeshAssets) {
if (!a.hasBoundary) {
if (includeNoGeom || a.geometry) result.push_back(a.copy());
}
}
return result;
}
std::vector<MeshAsset> MeshAssetSuite::boundaryMeshes(bool includeNoGeom) {
std::vector<MeshAsset> result;
for (MeshAsset& a : allMeshAssets) {
if (a.hasBoundary) {
if (includeNoGeom || a.geometry) result.push_back(a.copy());
}
}
return result;
}
std::vector<MeshAsset> MeshAssetSuite::polygonalComplexMeshes(bool includeNoGeom) {
std::vector<MeshAsset> result;
for (MeshAsset& a : allMeshAssets) {
if (a.isPolygonalComplex) {
if (includeNoGeom || a.geometry) result.push_back(a.copy());
}
}
return result;
}
std::vector<MeshAsset> MeshAssetSuite::triangularMeshes(bool includeNoGeom, bool includeNonmanifold) {
std::vector<MeshAsset> result;
for (MeshAsset& a : allMeshAssets) {
if (a.isTriangular) {
if (!includeNoGeom && !a.geometry) continue;
if (!includeNonmanifold && !a.isSubclassManifoldSurfaceMesh) continue;
result.push_back(a.copy());
}
}
return result;
}