-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathargparser.cpp
95 lines (78 loc) · 2.59 KB
/
argparser.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
// ================================================================
// Parse the command line arguments and the input file
// ================================================================
#include <iostream>
#include <glm/gtc/type_ptr.hpp>
#include "argparser.h"
#include "meshdata.h"
#include "triangulator.h"
ArgParser *GLOBAL_args;
ArgParser::ArgParser(int argc, const char *argv[], MeshData *_mesh_data) {
mesh_data = _mesh_data;
// parse the command line arguments
for (int i = 1; i < argc; i++) {
if (std::string(argv[i]) == std::string("--input")) {
i++; assert (i < argc);
separatePathAndFile(argv[i],path,input_file);
} else if (std::string(argv[i]) == std::string("--size")) {
i++; assert (i < argc);
mesh_data->width = atoi(argv[i]);
i++; assert (i < argc);
mesh_data->height = atoi(argv[i]);
} else if (std::string(argv[i]) == std::string("--triangulate")) {
i++; assert (i < argc);
auto input = std::string(argv[i]);
i++; assert (i < argc);
auto output = std::string(argv[i]);
Triangulator::Triangulate(input, output);
exit(0);
} else if (std::string(argv[i]) == std::string("--time-step")) {
i++; assert (i < argc);
mesh_data->timestep = std::stof(std::string(argv[i]));
} else if (std::string(argv[i]) == std::string("--cross-section")) {
i++; assert (i < argc);
cross_section = true;
} else {
std::cout << "ERROR: unknown command line argument "
<< i << ": '" << argv[i] << "'" << std::endl;
exit(1);
}
}
mesh_data->Load(path+"/"+input_file);
GLOBAL_args = this;
mesh = new fractureMesh(mesh_data);
mesh->packMesh();
}
void ArgParser::Load() {
delete mesh;
mesh = new fractureMesh(mesh_data);
mesh->packMesh();
}
void ArgParser::separatePathAndFile(const std::string &input, std::string &path, std::string &file) {
// we need to separate the filename from the path
// (we assume the vertex & fragment shaders are in the same directory)
// first, locate the last '/' in the filename
size_t last = std::string::npos;
while (1) {
int next = input.find('/',last+1);
if (next != (int)std::string::npos) {
last = next;
continue;
}
next = input.find('\\',last+1);
if (next != (int)std::string::npos) {
last = next;
continue;
}
break;
}
if (last == std::string::npos) {
// if there is no directory in the filename
file = input;
path = ".";
} else {
// separate filename & path
file = input.substr(last+1,input.size()-last-1);
path = input.substr(0,last);
}
}