forked from pavelsevecek/pvl
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPlyReader.hpp
80 lines (72 loc) · 2.26 KB
/
PlyReader.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
#pragma once
#include "TriangleMesh.hpp"
#include "Vector.hpp"
#include <fstream>
#include <iostream>
#include <sstream>
#include <vector>
namespace Pvl {
class PlyReader {
std::istream& in_;
public:
PlyReader(std::istream& in)
: in_(in) {
PVL_ASSERT(in);
}
std::vector<Vec3f> readCloud() {
std::string line;
// std::string countTag("element vertex ");
while (std::getline(in_, line)) {
/* if (line.size() > countTag.size() && line.substr(0, countTag.size()) ==
countTag) {
}*/
if (line == "end_header") {
break;
}
}
std::vector<Vec3f> points;
while (std::getline(in_, line)) {
std::stringstream ss(line);
Vec3f p;
ss >> p[0] >> p[1] >> p[2];
points.push_back(p);
}
return points;
}
TriangleMesh<Vec3f> readMesh() {
std::string line;
std::size_t numVertices = 0;
std::size_t numFaces = 0;
while (std::getline(in_, line)) {
sscanf(line.c_str(), "element vertex %zu", &numVertices);
sscanf(line.c_str(), "element face %zu", &numFaces);
if (line == "end_header") {
break;
}
}
TriangleMesh<Vec3f> mesh;
std::cout << "Loading mesh with " << numVertices << " vertices and " << numFaces << " faces"
<< std::endl;
for (std::size_t i = 0; i < numVertices; ++i) {
std::getline(in_, line);
std::stringstream ss(line);
Vec3f p;
ss >> p[0] >> p[1] >> p[2];
mesh.addVertex();
mesh.points.push_back(p);
}
std::cout << "Added " << mesh.numVertices() << " vertices " << std::endl;
for (std::size_t i = 0; i < numFaces; ++i) {
std::getline(in_, line);
std::stringstream ss(line);
int dummy, a, b, c;
ss >> dummy >> a >> b >> c;
mesh.addFace(VertexHandle(a), VertexHandle(b), VertexHandle(c));
if (i % 100000 == 99999) {
std::cout << "added " << mesh.numFaces() << " faces" << std::endl;
}
}
return mesh;
}
};
} // namespace Pvl