constructor parses the input stream */
| 102 | |
| 103 | /* constructor parses the input stream */ |
| 104 | PlyParser(const FileName& fileName) : format(ASCII) |
| 105 | { |
| 106 | /* open file */ |
| 107 | fs.open (fileName.c_str(), std::fstream::in | std::fstream::binary); |
| 108 | if (!fs.is_open()) throw std::runtime_error("cannot open file : " + fileName.str()); |
| 109 | |
| 110 | /* check for file signature */ |
| 111 | std::string signature; getline(fs,signature); |
| 112 | if (signature != "ply") throw std::runtime_error("invalid PLY file signature: " + signature); |
| 113 | |
| 114 | /* read header */ |
| 115 | std::list<std::string> header; |
| 116 | while (true) { |
| 117 | std::string line; getline(fs,line); |
| 118 | if (line == "end_header") break; |
| 119 | if (line.find_first_of('#') == 0) continue; |
| 120 | if (line == "") continue; |
| 121 | header.emplace_back(line); |
| 122 | } |
| 123 | |
| 124 | /* parse header */ |
| 125 | parseHeader(header); |
| 126 | |
| 127 | /* now parse all elements */ |
| 128 | for (std::vector<std::string>::iterator i = mesh.order.begin(); i!=mesh.order.end(); i++) |
| 129 | parseElementData(mesh.elements[*i]); |
| 130 | |
| 131 | /* create triangle mesh */ |
| 132 | scene = import(); |
| 133 | } |
| 134 | |
| 135 | /* parse the PLY header */ |
| 136 | void parseHeader(std::list<std::string>& header) |