forked from alecjacobson/meshfix
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlibigl_example.cpp
95 lines (75 loc) · 1.71 KB
/
libigl_example.cpp
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
#define MESHFIX_WITH_EIGEN
#include "meshfix.h"
#include <igl/read_triangle_mesh.h>
#include <igl/write_triangle_mesh.h>
#include <iostream>
void
loadGmsh(const std::string &fileName,
Eigen::MatrixXd &V,
Eigen::MatrixXi &F)
{
std::ifstream in(fileName.c_str());
std::string line;
// Skip first four lines
for (int i = 0; i < 4; ++i)
{
std::getline(in, line);
}
// Next line is # of vertices
int numVerts;
in >> numVerts;
V.resize(numVerts, 3);
// Read the vertices
for (int i = 0; i < numVerts; ++i)
{
int index;
double x, y, z;
in >> index >> x >> y >> z;
V.row(i) << x, y, z;
}
// Skip two lines
in >> line >> line;
// Read # of triangles
int numFaces;
in >> numFaces;
F.resize(numFaces, 3);
int fluidCounter = 0;
// Read triangles
for (int i = 0; i < numFaces; ++i)
{
int ignore, type, index, v1, v2, v3;
in >> ignore >> ignore >> ignore;
in >> type >> index >> v1 >> v2 >> v3;
v1 -= 1;
v2 -= 1;
v3 -= 1;
F.row(i) << v1, v2, v3;
}
}
int main(int argc, char * argv[])
{
// Load in libigl's (V,F) format
Eigen::MatrixXd V,W;
Eigen::MatrixXi F,G;
if(argc <= 2)
{
std::cout<<R"(Usage:
./meshfix-libigl [input](.obj|.ply|.stl|.off) [output](.obj|.ply|.stl|.off)
)";
return EXIT_FAILURE;
}
// Read gmsh if requested
int len = strlen(argv[1]);
assert(len > 3);
if (strcmp(argv[1] + len - 3, "msh") == 0)
{
loadGmsh(argv[1], V, F);
}
else
{
igl::read_triangle_mesh(argv[1],V,F);
}
meshfix(V,F,W,G,true);
// Write to OBJ
igl::write_triangle_mesh(argv[2],W,G);
}