-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathExporter.cpp
More file actions
126 lines (101 loc) · 4.47 KB
/
Exporter.cpp
File metadata and controls
126 lines (101 loc) · 4.47 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
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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
#include "Exporter.h"
Exporter::Exporter(const DataLoader* data_loader, const Solver* solver) : m_data_loader(data_loader), m_solver(solver), m_exe_file_path("") {
}
void Exporter::setExeFilePath(const string& file_path) {
m_exe_file_path = file_path;
unsigned int index = m_exe_file_path.find_last_of('\\');
m_exe_file_path = m_exe_file_path.substr(0, index);
index = m_exe_file_path.find("\\");
while (index != -1) {
m_exe_file_path.at(index) = '/';
index = m_exe_file_path.find("\\");
}
}
void Exporter::generateJSFile(const string& file_path) const {
unsigned int number_of_nodes = m_data_loader->getNodeCount();
unsigned int max_coord = m_data_loader->getMaxCoord();
double max_temperature = m_solver->getMaxTemperature();
double min_temperature = m_solver->getMinTemperature();
double temperature_delta = max_temperature - min_temperature;
double current_node_temperature;
double color_coeff;
double red_coeff, green_coeff, blue_coeff;
const array<double, COORDS_PER_NODE>* current_node_coord;
const array <double, COORDS_PER_NODE>* object_center = m_data_loader->getObjectCenter();
vector <unsigned int > boundary_nodes;
ofstream js_file;
ifstream js_template_1;
ifstream js_template_2;
cout << "Exporting data to html file..." << endl << endl;
js_template_1.open(m_exe_file_path + "/webgl sources/1.txt", ios::in);
js_template_2.open(m_exe_file_path + "/webgl sources/2.txt", ios::in);
js_file.open(m_exe_file_path + file_path, ios::out);
js_file << js_template_1.rdbuf();
js_file << endl;
js_file << " let number_of_nodes = " << number_of_nodes << ";" << endl;
js_file << " let coord = new Float32Array(number_of_nodes * COORDS_PER_NODE);" << endl;
js_file << " let color = new Float32Array(number_of_nodes * COLOR_COMPONENTS);" << endl << endl;
for (unsigned int i = 0; i < number_of_nodes; ++i) {
current_node_coord = m_data_loader->getNodeCoord(i);
current_node_temperature = m_solver->getTemperatureAtNode(i);
color_coeff = (current_node_temperature - min_temperature) / temperature_delta;
red_coeff = 0;
blue_coeff = 0;
green_coeff = 0;
if (color_coeff >= 0 && color_coeff <= 0.25) {
red_coeff = 0;
green_coeff = 4 * color_coeff;
blue_coeff = 1;
}
if (color_coeff > 0.25 && color_coeff <= 0.5) {
red_coeff = 0;
green_coeff = 1;
blue_coeff = 2 - 4 * color_coeff;
}
if (color_coeff > 0.5 && color_coeff <= 0.75) {
red_coeff = 4 * color_coeff - 2;
green_coeff = 1;
blue_coeff = 0;
}
if (color_coeff > 0.75 && color_coeff <= 1) {
red_coeff = 1;
green_coeff = 4 - 4 * color_coeff;
blue_coeff = 0;
}
js_file << " coord[" << i * 3 << "] = " << (current_node_coord->at(0) - object_center->at(0)) / max_coord << ";" << endl;
js_file << " coord[" << i * 3 + 1 << "] = " << (current_node_coord->at(1) - object_center->at(1)) / max_coord << ";" << endl;
js_file << " coord[" << i * 3 + 2 << "] = " << (current_node_coord->at(2) - object_center->at(2)) / max_coord << ";" << endl;
js_file << " color[" << i * 3 << "] = " << red_coeff << ";" << endl;
js_file << " color[" << i * 3 + 1 << "] = " << green_coeff << ";" << endl;
js_file << " color[" << i * 3 + 2 << "] = " << blue_coeff << ";" << endl;
js_file << endl;
}
boundary_nodes = m_data_loader->getBoundaryNodes();
js_file << " let indices = new Uint16Array(" << boundary_nodes.size() << ");" << endl << endl;
for (unsigned int i = 0; i < boundary_nodes.size(); ++i)
js_file << " indices[" << i << "] = " << boundary_nodes.at(i) << ";" << endl;
js_file << endl;
js_file << js_template_2.rdbuf();
js_template_1.close();
js_template_2.close();
js_file.close();
cout << "Data exported" << endl << endl;
}
void Exporter::genetateTxtFile(const string& file_path) const {
unsigned int number_of_nodes = m_data_loader->getNodeCount();
double current_node_temperature;
double max_temperature = m_solver->getMaxTemperature();
double min_temperature = m_solver->getMinTemperature();
ofstream txt_file;
cout << "Exporting data to txt file..." << endl << endl;
txt_file.open(m_exe_file_path + file_path, ios::out);
txt_file << max_temperature << endl;
txt_file << min_temperature << endl;
for (unsigned int i = 0; i < number_of_nodes; ++i) {
current_node_temperature = m_solver->getTemperatureAtNode(i);
txt_file << i << " " << current_node_temperature;
txt_file << endl;
}
txt_file.close();
cout << "Data exported" << endl << endl;
}