-
Notifications
You must be signed in to change notification settings - Fork 11
/
MeshPointsIO.cpp
64 lines (58 loc) · 1.52 KB
/
MeshPointsIO.cpp
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
#include "MeshPointsIO.h"
void wReadMeshObj(std::string _fileName, std::vector<cv::Vec4f> _vertex, std::vector<cv::Vec4b> _color, std::vector<cv::Vec3f> _normal)
{
_vertex.clear();
_color.clear();
_normal.clear();
std::ifstream in_file(_fileName);
if (!in_file.is_open()) return;
char line[1024];
float x, y, z;
int r, g, b;
int ix, iy, iz;
std::string st;
while (in_file.getline(line, sizeof(line)))
{
std::stringstream lineStream(line);
lineStream >> st;
if (st == "vn")
{
lineStream >> x >> y >> z;
_normal.push_back(cv::Vec3f(x, y, z));
}
if (st == "v")
{
lineStream >> x >> y >> z >> r >> g >> b;
_vertex.push_back(cv::Vec4f(x, y, z, 1));
//std::cout << x << " " << y << " " << z << "\n";
_color.push_back(cv::Vec4b(r, g, b, 1));
}
}
in_file.clear();
in_file.close();
}
void wReadMeshPly(std::string _filename, std::vector<cv::Vec4f> _vertex, std::vector<cv::Vec4b> _color, std::vector<cv::Vec3f> _normal)
{
std::ifstream in_file(_filename);
if (!in_file.is_open()) return;
char line[1024];
std::string st;
float x, y, z;
float nx, ny, nz;
int r, g, b;
while (true)
{
in_file.getline(line, sizeof(line));
std::stringstream lineStream(line);
lineStream >> st;
if (st == "end_header") break;
}
while (in_file.getline(line, sizeof(line)))
{
std::stringstream lineStream(line);
lineStream >> x >> y >> z >> nx >> ny >> nz >> r >> g >> b;
_vertex.push_back(cv::Vec4f(x, y, z, 1));
_normal.push_back(cv::Vec3f(nx, ny, nz));
_color.push_back(cv::Vec4b(r, g, b, 1));
}
}