15 #include "qtessInputFile.h" 16 #include "config_egg_qtess.h" 17 #include "string_utils.h" 35 _filename = Filename::text_filename(filename);
41 <<
"Unable to open input file " << _filename <<
"\n";
49 while (getline(input, line)) {
54 size_t comment = line.find(
'#');
55 while (comment != string::npos) {
56 if (comment == 0 || isspace(line[comment - 1])) {
57 line = line.substr(0, comment);
58 comment = string::npos;
61 comment = line.find(
'#', comment + 1);
66 line = trim_right(line);
67 if (!line.empty() && line[line.size() - 1] ==
'\\') {
69 complete_line += line.substr(0, line.size() - 1);
73 line = trim(complete_line + line);
74 complete_line = string();
80 size_t colon = line.find(
": ");
81 if (colon == string::npos) {
83 << _filename <<
": line " << line_number
84 <<
" has no colon followed by whitespace.\n";
89 << _filename <<
": line " << line_number
90 <<
" has no nodes.\n";
96 vector_string names, params;
97 extract_words(line.substr(0, colon), names);
98 extract_words(line.substr(colon + 1), params);
100 vector_string::const_iterator ni;
101 for (ni = names.begin(); ni != names.end(); ++ni) {
102 entry.add_node_name(*ni);
107 vector_string::iterator ci, cnext;
109 while (ci != params.end()) {
115 if (param[0] ==
'!' && param.size() > 1) {
117 param = param.substr(1);
119 if (tolower(param[0]) ==
'a' && param.size() > 1) {
120 switch (tolower(param[1])) {
122 entry._auto_place = !invert;
126 entry._auto_distribute = !invert;
130 if (!string_to_double(param.substr(2), entry._curvature_ratio)) {
132 << _filename <<
": line " << line_number
133 <<
" - invalid field " << param <<
"\n";
140 << _filename <<
": invalid parameters at line " 141 << line_number <<
".\n";
150 if (!params.empty()) {
152 if (cmp_nocase(params[0],
"omit")==0) {
155 }
else if (cmp_nocase(params[0],
"matchuu")==0) {
156 entry.set_match_uu();
157 if (params.size() > 1 && cmp_nocase(params[1],
"matchvv")==0) {
158 entry.set_match_vv();
161 }
else if (cmp_nocase(params[0],
"matchvv")==0) {
162 entry.set_match_vv();
163 if (params.size() > 1 && cmp_nocase(params[1],
"matchuu")==0) {
164 entry.set_match_uu();
167 }
else if (cmp_nocase(params[0],
"matchuv")==0) {
168 entry.set_match_uv();
169 if (params.size() > 1 && cmp_nocase(params[1],
"matchvu")==0) {
170 entry.set_match_vu();
173 }
else if (cmp_nocase(params[0],
"matchvu")==0) {
174 entry.set_match_vu();
175 if (params.size() > 1 && cmp_nocase(params[1],
"matchuv")==0) {
176 entry.set_match_uv();
179 }
else if (cmp_nocase(params[0],
"minu")==0) {
181 if (params.size() < 2) {
185 okflag = string_to_int(params[1], value);
186 entry.set_min_u(value);
189 }
else if (cmp_nocase(params[0],
"minv")==0) {
191 if (params.size() < 2) {
195 okflag = string_to_int(params[1], value);
196 entry.set_min_v(value);
199 }
else if (tolower(params[0][0]) ==
'i') {
202 okflag = string_to_int(params[0].substr(1), value);
203 entry.set_per_isoparam(value);
205 }
else if (params[0][params[0].length() - 1] ==
'%') {
207 okflag = string_to_double(params[0].substr(0, params[0].length() - 1), value);
208 entry.set_importance(value / 100.0);
210 }
else if (params.size() == 1) {
213 okflag = string_to_int(params[0], value);
214 entry.set_num_tris(value);
216 }
else if (params.size() >= 2) {
220 okflag = string_to_int(params[0], u) && string_to_int(params[1], v);
221 entry.set_uv(u, v, ¶ms[2], params.size() - 2);
229 << _filename <<
": invalid parameters at line " 230 << line_number <<
".\n";
234 _entries.push_back(entry);
239 if (qtess_cat.is_info()) {
241 <<
"read qtess parameter file " << _filename <<
".\n";
242 if (qtess_cat.is_debug()) {
243 write(qtess_cat.debug(
false));
262 if (_entries.empty()) {
266 return _entries.back();
285 QtessInputEntry::Type type;
287 if (_entries.empty()) {
292 Entries::iterator ei;
293 for (ei = _entries.begin(); ei != _entries.end(); ++ei) {
294 type = (*ei).match(surface);
295 if (type != QtessInputEntry::T_undefined) {
299 return QtessInputEntry::T_undefined;
314 Entries::iterator ei;
315 for (ei = _entries.begin(); ei != _entries.end(); ++ei) {
316 total_tris += (*ei).count_tris();
326 void QtessInputFile::
327 write(ostream &out,
int indent_level)
const {
328 Entries::const_iterator ei;
329 for (ei = _entries.begin(); ei != _entries.end(); ++ei) {
330 (*ei).write(out, indent_level);
340 void QtessInputFile::
341 add_default_entry() {
344 _entries.push_back(entry);
A reference to an EggNurbsSurface in the egg file, and its parameters as set by the user input file a...
bool open_read(ifstream &stream) const
Opens the indicated ifstream for reading the file, if possible.
The name of a file, such as a texture file or an Egg file.
Stores one entry in the qtess input file.