10 int main(
int argc,
char* argv[]) {
13 cout <<
"Not enough arguments, please use ./AppSTLParser [path/filename_in] [path/filename_out]" << endl;
17 cout <<
"Too many arguments, please use ./AppSTLParser [path/filename_in] [path/filename_out]" << endl;
22 string filename_in = argv[1];
23 string filename_out = argv[2];
26 if (filename_in.find(
".stl") == string::npos) {
27 cout <<
"Incorrect filetype, application for ASCII STL files only" << endl;
31 cout <<
"File to parse: " << filename_in << endl;
36 file_in.open(filename_in.c_str(), fstream::in);
38 if (!file_in.is_open()) {
39 cout <<
"Failed to open input file, please check filename" << endl;
43 cout <<
"Input file opened successfully" << endl;
46 cout <<
"Parsed info writing to: " << filename_out << endl;
48 file_out.open(filename_out.c_str(), fstream::out);
50 if (!file_out.is_open()) {
51 cout <<
"Failed to open output file" << endl;
55 cout <<
"Output file opened successfully" << endl;
58 string key =
"vertex";
62 int triangle_count = 0;
63 int element_index = 0;
70 getline(file_in, line_in);
72 cout <<
"Lines processed: " << line_index << endl;
74 size_t found_key = line_in.find(key);
76 if (found_key != string::npos) {
79 size_t found_char_last = line_in.find_first_of(
" ", found_key);
80 size_t found_char_curr;
81 while (found_char_last != string::npos) {
82 found_char_curr = line_in.find_first_of(
" ", found_char_last + 1);
84 if (found_char_curr == string::npos) {
85 element = line_in.substr(found_char_last + 1, line_in.size()-found_char_last);
89 element = line_in.substr(found_char_last + 1, found_char_curr - 1 - found_char_last);
92 size_t found_E = element.find_first_of(
"E");
93 string coeff = element.substr(0, found_E);
94 string exp = element.substr(found_E + 1, element.size() - found_E);
96 double coeff_num = atof(coeff.c_str());
97 double exp_num = atof(exp.c_str());
99 double num = coeff_num * pow(10.0, exp_num);
102 switch (element_index) {
104 file_out <<
"[" << num <<
", ";
108 file_out << num <<
", ";
112 file_out << num <<
"] ";
116 found_char_last = found_char_curr;
120 if (vertex_index >= 3) {
131 cout <<
"Reached end of file, closing files" << endl;
132 cout <<
"Number of verticies extracted: " << vertex_count << endl;
133 cout <<
"Number of triangles: " << triangle_count << endl;
136 else if (file_in.fail()) {
137 cout <<
"Read failed" << endl;
int main(int argc, char **argv)