| 25 | |
| 26 | |
| 27 | bool VEGAParser::parse(const std::string& filename) { |
| 28 | std::ifstream fin(filename.c_str()); |
| 29 | if (!fin.is_open()) { |
| 30 | std::stringstream err_msg; |
| 31 | err_msg << "failed to open file \"" << filename << "\""; |
| 32 | throw IOError(err_msg.str()); |
| 33 | } |
| 34 | |
| 35 | while(!fin.eof()) { |
| 36 | const std::string line = IOUtils::next_line(fin); |
| 37 | assert(line.size() > 0); |
| 38 | |
| 39 | if (line[0] == '*') { |
| 40 | if (IOUtils::is_prefix("*VERTICES", line.c_str())) { |
| 41 | parse_vertices(fin); |
| 42 | } else if (IOUtils::is_prefix("*ELEMENTS", line.c_str())) { |
| 43 | parse_elements(fin); |
| 44 | } else if (IOUtils::is_prefix("*MATERIAL", line.c_str())) { |
| 45 | parse_material(fin); |
| 46 | } else if (IOUtils::is_prefix("*REGION", line.c_str())) { |
| 47 | parse_region(fin); |
| 48 | } else if (IOUtils::is_prefix("*SET", line.c_str())) { |
| 49 | parse_set(fin); |
| 50 | } else { |
| 51 | std::stringstream err_msg; |
| 52 | err_msg << "Unknown VEGA command: " << line; |
| 53 | throw IOError(err_msg.str()); |
| 54 | } |
| 55 | } else { |
| 56 | std::cerr << "Warning: unknown line skipped: " << line << std::endl; |
| 57 | } |
| 58 | } |
| 59 | extract_faces_from_voxels(); |
| 60 | return true; |
| 61 | } |
| 62 | |
| 63 | void VEGAParser::parse_vertices(std::ifstream& fin) { |
| 64 | const std::string header = IOUtils::next_line(fin); |