-
Notifications
You must be signed in to change notification settings - Fork 0
/
output.cpp
68 lines (61 loc) · 2.2 KB
/
output.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
65
66
67
68
#include "output.h"
bool Output::OutputOBJFile(QString name, BaseMesh *mesh) {
if (!mesh) return false;
std::cout << "Outputing OBJ file..." << std::endl;
QString fileName = name + ".obj";
QFile file(fileName);
if (file.open(QIODevice::WriteOnly)) {
std::cout <<"Open file sucessfully!" << std::endl;
QTextStream stream(&file);
QVector <Vertex*> vts = mesh->GetVertices();
QMap <Vertex*, int> vTable;
int num = 1;
for (int i=0; i<vts.size(); ++i) {
stream << "v " << vts[i]->x() << " " << vts[i]->y() << " " << vts[i]->z() << endl;
vTable[vts[i]] = num;
num++;
}
stream << "# " << vts.size() << " vertices" << endl;
stream << endl;
QVector <Face* > faces = mesh->GetFaces();
for (int i=0; i<faces.size(); ++i) {
QVector <Vertex* > vFace = faces[i]->GetVertices();
stream << "f";
for (int j=0; j<vFace.size(); ++j)
stream << " " << vTable[vFace[j]];
stream << endl;
}
stream << "# " << faces.size() << " faces" << endl;
}
file.close();
return true;
}
bool Output::OutputINFFile(QString name, BaseMesh *mesh) {
if (!mesh) return false;
std::cout << "Outputing INF file..." << std::endl;
QString fileName = name + ".inf";
QFile file(fileName);
if (file.open(QIODevice::WriteOnly)) {
std::cout <<"Open file sucessfully!" << std::endl;
QTextStream stream(&file);
QVector <Vertex*> vts = mesh->GetVertices();
QMap <Vertex*, int> vTable;
int num = 1;
for (int i=0; i<vts.size(); ++i) {
stream << i+1 << ", " << vts[i]->x() << ", " << vts[i]->y() << ", " << vts[i]->z() << endl;
vTable[vts[i]] = num;
num++;
}
stream << endl;
QVector <Face* > faces = mesh->GetFaces();
for (int i=0; i<faces.size(); ++i) {
QVector <Vertex* > vFace = faces[i]->GetVertices();
stream << i+1;
for (int j=0; j<vFace.size(); ++j)
stream << ", " << vTable[vFace[j]];
stream << endl;
}
}
file.close();
return true;
}