-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.cpp
105 lines (100 loc) · 3.58 KB
/
main.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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
#include <GL/glew.h>
#include <GL/glut.h>
#include <iostream>
#include <fstream>
#include <sstream>
#include <map>
#include <string>
#include "Converter.h"
#include "ObjTrianglesLoader.h"
#include "MinGWStopwatch.h"
conv::Initializer parse(const std::string ¶mFilename)
{
std::ifstream parametersFile(paramFilename);
std::string line;
std::map<std::string, std::string> parameters;
parameters["Model path"] = "";
parameters["Size factor"] = "";
parameters["SDF path"] = "";
parameters["Resolution"] = "";
parameters["Loader type"] = "";
parameters["Filler value"] = "";
parameters["Delta"] = "";
parameters["Path to filler shader"] = "";
parameters["Path to modifier shader"] = "";
parameters["Path to kernel shader"] = "";
char delimeter = ':';
size_t pos = 0;
char rubbish[2];
std::stringstream source;
conv::Initializer initializer;
while(std::getline(parametersFile, line))
{
pos = line.find(delimeter);
if(parameters.count(line.substr(0, pos)) == 0)
{
std::cout << "Unknown key:" << line.substr(0, pos) << std::endl;
parametersFile.close();
return initializer;
}
else
parameters[line.substr(0, pos)] = line.substr(pos + 1);
}
parametersFile.close();
initializer.sizeFactor = std::stof(parameters["Size factor"]);
initializer.SDFfilename = parameters["SDF path"];
source.str(parameters["Resolution"]);
source >> initializer.resolution.x >> rubbish[0]
>> initializer.resolution.y >> rubbish[1]
>> initializer.resolution.z;
if(parameters["Loader type"] == "Obj Loader")
initializer.trianglesLoader.reset(new conv::ObjTrianglesLoader(parameters["Model path"]));
else
return initializer;
initializer.stopwatch.reset(new conv::MinGWStopwatch);
initializer.fillerValue = std::stof(parameters["Filler value"]);
initializer.delta = std::stof(parameters["Delta"]);
initializer.fillerPath = parameters["Path to filler shader"];
initializer.modifierPath = parameters["Path to modifier shader"];
initializer.kernelPath = parameters["Path to kernel shader"];
return initializer;
}
int main(int argc, char **argv) {
std::ios::sync_with_stdio(false);
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_RGBA | GLUT_ALPHA | GLUT_DOUBLE);
glutInitWindowSize(1, 1);
glutCreateWindow("Converter");
glewInit();
glewExperimental = true;
conv::Converter converter;
conv::Initializer initializer = parse("converter.parm");
if(initializer.trianglesLoader.get() == nullptr)
return 1;
converter.initialize(initializer);
converter.compute();
auto laps = initializer.stopwatch->getLaps();
for(uint16_t i = 0; i < laps.size(); ++i)
{
switch(i)
{
case 0:
std::cout << "Loading model: " << laps[0] << " milliseconds\n";
break;
case 1:
std::cout << "Preparing for computations: " << laps[1] << " milliseconds\n";
break;
case 2:
std::cout << "Computing SDF: " << laps[2] << " milliseconds\n";
break;
case 3:
std::cout << "Writing SDF to file: " << laps[3] << " milliseconds\n";
break;
default:
std::cout << "Unknown lap description\n";
}
}
glm::uvec3 resolution = converter.getResolution();
std::cout << "Resolution: " << resolution.x << "," << resolution.y << "," << resolution.z << std::endl;
return 0;
}