-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsetInput.cpp
207 lines (193 loc) · 5.18 KB
/
setInput.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
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
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
#include "setInput.h"
using namespace std;
setInput::setInput()
{
AddOption("render", "visualization", render);
AddOption("saveData", "should results be saved", saveData);
AddOption("helixradius", "Radius of Helix", helixradius);
AddOption("helixpitchRatio", "Pitch of Helix/Radius of Helix", helixpitchRatio);
AddOption("rodRadiusRatio", "Radius of Helix/Radius of Rod ", rodRadiusRatio);
AddOption("contourRatio", "Contour Length of Helix/Radius of Helix", contourRatio);
AddOption("numVertices", "Number of Vertices", numVertices);
AddOption("youngM", "Young's Modulus", youngM);
AddOption("Poisson", "Poisson Ratio", Poisson);
AddOption("deltaTime", "Time Step Length", deltaTime);
AddOption("totalTime", "Total Running Time", totalTime);
AddOption("tol", "Tolerance of Newton Method", tol);
AddOption("stol", "Ratio between initial and final error", stol);
AddOption("maxIter", "Maximum Running Times of Each Stepper", maxIter);
AddOption("maxIterContact", "Maximum Iteration of Contact Solver", maxIterContact);
AddOption("density", "Density of the Rod", density);
AddOption("viscosity", "Viscous Froce", viscosity);
AddOption("epsilon", "epsilon", epsilon);
AddOption("gVector", "Gravity", gVector);
AddOption("distance", "distance", distance);
AddOption("use-RSS", "Should RSS be used?", useRSS);
AddOption("use-RFT", "Should RFT be used?", useRFT);
AddOption("headSize", "Size of the Robothead", headSize);
AddOption("translation", "Translation-MLRFT model?", translation);
AddOption("input-file", "input omega file", inputName);
AddOption("input-coefficient", "input coefficient file for RFT", inputName2);
AddOption("include-contact", "should contact be included?", includeContact);
}
setInput::~setInput()
{
;
}
Option *setInput::GetOption(const string &name)
{
if (m_options.find(name) == m_options.end())
{
cerr << "Option " << name << " does not exist" << endl;
// exit(-1);
}
return &(m_options.find(name)->second);
}
bool &setInput::GetBoolOpt(const string &name)
{
return GetOption(name)->b;
}
int &setInput::GetIntOpt(const string &name)
{
return GetOption(name)->i;
}
double &setInput::GetScalarOpt(const string &name)
{
return GetOption(name)->r;
}
Vector3d &setInput::GetVecOpt(const string &name)
{
return GetOption(name)->v;
}
string &setInput::GetStringOpt(const string &name)
{
return GetOption(name)->s;
}
int setInput::LoadOptions(const char *filename)
{
ifstream input(filename);
if (!input.is_open())
{
cerr << "ERROR: File " << filename << " not found" << endl;
return -1;
}
string line, option;
istringstream sIn;
string tmp;
for (getline(input, line); !input.eof(); getline(input, line))
{
sIn.clear();
option.clear();
sIn.str(line);
sIn >> option;
if (option.size() == 0 || option.c_str()[0] == '#')
continue;
OptionMap::iterator itr;
itr = m_options.find(option);
if (itr == m_options.end())
{
cerr << "Invalid option: " << option << endl;
continue;
}
if (itr->second.type == Option::BOOL)
{
sIn >> tmp;
if (tmp == "true" || tmp == "1")
itr->second.b = true;
else if (tmp == "false" || tmp == "0")
itr->second.b = false;
}
else if (itr->second.type == Option::INT)
{
sIn >> itr->second.i;
}
else if (itr->second.type == Option::DOUBLE)
{
sIn >> itr->second.r;
}
else if (itr->second.type == Option::VEC)
{
Vector3d &v = itr->second.v;
sIn >> v[0];
sIn >> v[1];
sIn >> v[2];
}
else if (itr->second.type == Option::STRING)
{
sIn >> itr->second.s;
}
else
{
cerr << "Invalid option type" << endl;
}
}
input.close();
return 0;
}
int setInput::LoadOptions(int argc, char **argv)
{
string option, tmp;
int start = 0;
while (start < argc && string(argv[start]) != "--")
++start;
for (int i = start + 1; i < argc; ++i)
{
option = argv[i];
OptionMap::iterator itr;
itr = m_options.find(option);
if (itr == m_options.end())
{
cerr << "Invalid option on command line: " << option << endl;
continue;
}
if (i == argc - 1)
{
cerr << "Too few arguments on command line" << endl;
break;
}
if (itr->second.type == Option::BOOL)
{
tmp = argv[i + 1];
++i;
if (tmp == "true" || tmp == "1")
itr->second.b = true;
if (tmp == "false" || tmp == "0")
itr->second.b = false;
}
else if (itr->second.type == Option::INT)
{
itr->second.i = atoi(argv[i + 1]);
++i;
}
else if (itr->second.type == Option::DOUBLE)
{
itr->second.r = atof(argv[i + 1]);
++i;
}
else if (itr->second.type == Option::VEC)
{
if (i >= argc - 3)
{
cerr << "Too few arguments on command line" << endl;
break;
}
Vector3d &v = itr->second.v;
v[0] = atof(argv[i + 1]);
++i;
v[1] = atof(argv[i + 1]);
++i;
v[2] = atof(argv[i + 1]);
++i;
}
else if (itr->second.type == Option::STRING)
{
itr->second.s = argv[i + 1];
++i;
}
else
{
// cerr << "Invalid option type" << endl;
}
}
return 0;
}