reflex2q3/ReflexToQ3/wip/test-oopless-parser.cpp

78 lines
2.3 KiB
C++

#include "oopless-parser.hpp"
#include "brushdef.hpp"
#include <iostream>
using namespace std;
void print_TFace(const TFace x, int i) {
cout << "----------------------------" << endl;
cout << "TFace #" << i << endl;
cout << "\tOffset X: " << x.m_fXOffset << endl;
cout << "\tOffset Y: " << x.m_fYOffset << endl;
cout << "\tScale X: " << x.m_fXScale << endl;
cout << "\tScale Y: " << x.m_fYScale << endl;
cout << "\tRotation: " << x.m_fRotation << endl;
for (unsigned int i = 0; i < x.m_Indices.size(); ++i) {
cout << x.m_Indices[i] << ", ";
}
cout << "\n\tMaterial: " << x.m_Material << endl;
cout << "----------------------------" << endl;
}
// jump to a line in fstream
// this is to set the stream position to test individual parsing functions.
void gotoline(ifstream &f, unsigned int n) {
string t;
for (unsigned int i = 0; i < n; ++i) {
getline(f, t);
}
}
void test_parsevertices (const char * const fn, const int ln) {
ifstream fin;
fin.open(fn);
string line;
gotoline(fin, ln);
vector<Eigen::Vector3f> x = parse_vertices(fin);
cout << "size has a size of " << x.size() << endl;
// display data retrieved.
for (unsigned int i = 0; i < x.size(); ++i) {
for (unsigned int j = 0; j < 3; ++j) {
cout << x[i][j] << "\t";
}
cout << endl;
}
getline(fin, line);
cout << "check stream state \n current line: " << endl;
cout << line << endl;
fin.close();
}
// test if faces are parsing correctly
void test_parseface(const char * const fn, const int ln) {
ifstream fin;
fin.open(fn);
string line;
gotoline(fin, ln);
vector<TFace> x = parse_face(fin);
cout << "size has a size of " << x.size() << endl;
// display data retrieved.
for (unsigned int i = 0; i < x.size(); ++i) {
print_TFace(x[i], i);
}
// parse_face will rollback to a position if it comes across a keyword
// check the line that fin will retrieve.
getline(fin, line);
cout << "check stream state \n current line: " << endl;
cout << line << endl;
fin.close();
}
int main() {
//loadmap("empty.map", "empty-test.map");
test_parsevertices("empty.map", 10);
test_parseface("empty.map", 19);
test_parseface("pocket-infinity.map", 16);
convertmap("empty.map", "test-empty.map", &brushdef_net);
}