MCPcopy Create free account
hub / github.com/RenderKit/embree / PlyParser

Class PlyParser

tutorials/common/scenegraph/ply_loader.cpp:94–325  ·  view source on GitHub ↗

PLY parser class */

Source from the content-addressed store, hash-verified

92
93 /* PLY parser class */
94 struct PlyParser
95 {
96 std::fstream fs;
97 Mesh mesh;
98 Ref<SceneGraph::Node> scene;
99
100 /* storage format of data in file */
101 enum Format { ASCII, BINARY_BIG_ENDIAN, BINARY_LITTLE_ENDIAN } format;
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)
137 {
138 while (!header.empty())
139 {
140 std::stringstream line(header.front());
141 header.pop_front();
142
143 std::string tag; line >> tag;
144
145 /* ignore comments */
146 if (tag == "comment") {
147 }
148
149 /* parse format */
150 else if (tag == "format")
151 {

Callers 1

loadPLYFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected