-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathgeneric.cpp
More file actions
33 lines (29 loc) · 1.3 KB
/
generic.cpp
File metadata and controls
33 lines (29 loc) · 1.3 KB
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
#include "generic.h"
bool loadOFF(const std::string& path, std::vector<Point>& vertices, std::vector<Face>& faces) {
std::ifstream file(path); // since OFF are text files this is fine
if (!file.is_open()) return false;
std::string header;
file >> header;
if (header != "OFF") return false;
int vCount, fCount, _;
file >> vCount >> fCount >> _; // get header info and read out a dummy value from the header;
vertices.resize(vCount); // initialize the vector to the size of the number of vertices we will be adding
for (int i = 0; i < vCount; ++i)
file >> vertices[i].x >> vertices[i].y >> vertices[i].z; // read in line by line until there are no more....
faces.resize(fCount); // same but for faces
for (int i = 0; i < fCount; ++i) {
int n; file >> n; // line starts with the number of vertices in each face
faces[i].indices.resize(n);
for (int j = 0; j < n; ++j)
file >> faces[i].indices[j]; // then we can read in each vertex individually
}
file.close();
return true;
}
float distance(const Point& p1, const Point& p2) { // distance between 3d points O(1)
float dist = 0.0;
dist += (p1.x - p2.x) * (p1.x - p2.x);
dist += (p1.y - p2.y) * (p1.y - p2.y);
dist += (p1.z - p2.z) * (p1.z - p2.z);
return dist;
}