-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathfutils.h
50 lines (44 loc) · 1.24 KB
/
futils.h
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
#pragma once
#include <vector>
#include <fstream>
#include <sstream>
#include <string>
#include "vertex.h"
inline std::vector<Vertex> readPly(const std::string& fpath) {
std::ifstream infile(fpath);
std::vector<Vertex> res;
std::string line, str;
int numVertices;
while (std::getline(infile, line))
{
if (std::string::npos != line.find("element vertex")) {
std::istringstream iss(line);
if (!(iss >> str >> str >> numVertices)) {
qDebug() << "error reading element vertex";
// error
}
qDebug() << numVertices << " | " << line.c_str();
break;
}
}
while (std::getline(infile, line))
{
if (std::string::npos != line.find("end_header")) {
break;
}
}
float x, y, z;
for (int i = 0; i < numVertices; i++) {
float t = (float)i / numVertices;
std::getline(infile, line);
std::istringstream iss(line);
if (!(iss >> x >> y >> z)) {
qDebug() << "error reading vertex: " << line.c_str();
}
else {
res.push_back(Vertex(QVector3D(x, y, z) * 10, { t, 1.0f, 0.0f }));
}
}
infile.close();
return res;
}