-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathparser.h
77 lines (53 loc) · 1.64 KB
/
parser.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
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
#pragma once
#include "vec3.h"
#include "triangle.h"
#include "scene.h"
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
void read_file(string filename, float size,Vec3<float> pos, Triangle triangles[]){
string buff;
ifstream file (filename);
if (file.is_open()){
getline(file, buff); // OFF
int nb_vertices, nb_triangles;
char delim_space=' ';
char delim_endline='\n';
getline(file,buff, delim_space);
nb_vertices = stoi(buff);
getline(file,buff, delim_space);
nb_triangles = stoi(buff);
getline(file,buff, delim_endline); // nb_edges
Vec3<float> vertices[nb_vertices];
for(int i = 0; i < nb_vertices; i++){
getline(file, buff, delim_space);
float x = stof(buff) * (float) size + pos.x;
getline(file, buff, delim_space);
float y = stof(buff) * (float) size + pos.y;
getline(file, buff, delim_endline);
float z = stof(buff) * (float) size + pos.z;
vertices[i] = {x, y, z};
// DEBUG
// std::cout << vertices[i] << std::endl;
}
for( int j = 0; j < nb_triangles; j++){
Triangle triangle;
getline(file, buff, delim_space); // 3
getline(file, buff, delim_space);
triangle.a = vertices[stoi(buff)];
getline(file, buff, delim_space);
triangle.b = vertices[stoi(buff)];
getline(file, buff, delim_endline);
triangle.c = vertices[stoi(buff)];
triangle.color = {0, 1, 1};
triangles[j] = triangle;
}
file.close();
}
}
string read_buff_str(ifstream file, string buff, char delim){
buff = "";
getline(file, buff, delim);
return buff;
}