-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvtkOFRenderer.cpp
207 lines (168 loc) · 6.02 KB
/
vtkOFRenderer.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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
/*Created by Tristan Wellman 2024*/
#include <filesystem>
#include <functional>
#include "vtkOFRenderer.hpp"
using namespace Aftr;
std::vector<std::string> getDirectoryListing(std::string filePath) {
std::vector<std::string> dirs;
if(!std::filesystem::is_directory(filePath)) return dirs;
for (auto& curDir : std::filesystem::recursive_directory_iterator(filePath)) {
if (curDir.is_directory()) dirs.push_back(curDir.path().string());
}
return dirs;
}
std::string splitStr(std::string & str, char delim) {
int i;
for (i = 0; i < str.length(); i++) {
if (str.at(i) == delim) {
// return the first half of split string and set original to rest of string
std::string ret = str.substr(0, i);
str = str.substr(i + 1, str.length());
return ret;
}
}
return "";
}
std::vector<std::string> vtkOFRenderer::getOpenFoamTimeStamps(std::vector<std::string> dirs) {
std::vector<std::string> ret;
for (std::string i : dirs) {
while(splitStr(i, '/')!="");
if(splitStr(i, '\\') != "") continue;
try {
if(std::stoi(i)||i=="0") ret.push_back(i);
} catch (const std::invalid_argument &e) { continue; }
}
return ret;
}
vtkOFRenderer::vtkOFRenderer(std::string openFoamPath) : filePath(openFoamPath) {
//parser = (vtkParser*)malloc(sizeof(vtkParser*));
std::vector<std::string> listing = getDirectoryListing(openFoamPath);
VTKASSERT(!listing.empty(),
"ERROR:: Failed to open OPENFOAM test case folder");
timeStamps = getOpenFoamTimeStamps(listing);
VTKASSERT(!timeStamps.empty(),
"ERROR:: Failed to retrieve OpenFoam case Time Stamps!");
if (openFoamPath.at(openFoamPath.length() - 1) != '/') openFoamPath += '/';
for (int i = 0; i < timeStamps.size();i++) {
std::string fullPath = openFoamPath +
"postProcessing/streamlines/" + timeStamps.at(i) + "/tracks.vtk";
tracksFiles.push_back(fullPath);
std::cout << fullPath << std::endl;
}
isReady = false; // will be ready after parser is ran
}
void vtkOFRenderer::parseThread(int index) {
vtkParser* parser = &threadParsers.at(index);
parser->setVtkFile(tracksFiles.at(index));
//parser->printVTKFILE();
parser->init();
parser->parseOpenFoam();
tracksFileData.push_back(parser->getOpenFoamData());
//parser->dumpOFOAMPolyDataset();
parser->freeVtkData();
threadStates.at(index) = 1;
}
int vtkOFRenderer::parseTracksFiles() {
threadStates.resize(tracksFiles.size(), 0);
threadParsers.resize(tracksFiles.size());
threads.resize(tracksFiles.size());
int i, finished=0;
for (i = 0; i < tracksFiles.size(); i++) {
threads.at(i) = std::thread(std::mem_fn(&vtkOFRenderer::parseThread), this, i);
VTKLOG("INFO:: Started parser thread for: {}", tracksFiles.at(i));
}
while (!finished) {
int totalFinished = 0;
for (i = 0; i < threadStates.size();i++) {
if (threadStates.at(i)) totalFinished++;
}
if (totalFinished == threadStates.size() - 1) finished = 1;
}
for (i = 0; i < tracksFiles.size(); i++) {
threads.at(i).join();
VTKLOG("INFO:: Finished parser thread for: {}", tracksFiles.at(i));
}
isReady = true;
currentSelectedTimeStamp = timeStamps.at(0).c_str();
return 0;
}
void vtkOFRenderer::updateVtkTrackModel(WorldContainer* wl) {
static const char* pastTS = currentSelectedTimeStamp;
openFoamVtkFileData* pptr = new openFoamVtkFileData;
int i = 0;
if (currentSelectedTimeStamp != pastTS) {
for (i = 0; i < WOIDS.size(); i++) {
WO* tmp = wl->getWOByID(WOIDS.at(i));
wl->eraseViaWOptr(tmp);
delete tmp;
}
WOIDS.clear();
int i = 0;
for (i = 0; i < timeStamps.size(); i++) {
if (timeStamps.at(i).c_str() == currentSelectedTimeStamp) break;
}
pptr = &tracksFileData.at(i);
std::string point(ManagerEnvironmentConfiguration::getSMM() + "/models/OppenheimerBoxTimeMag10x10x10.wrl");
for (i = 0; i < pptr->points.polyData.size(); i++) {
WO* wo = WO::New(point, Vector(0.001, 0.001, 0.001), MESH_SHADING_TYPE::mstFLAT);
wo->setPosition(Vector(
pptr->points.polyData.at(i).at(0) * 50, pptr->points.polyData.at(i).at(1) * 50, pptr->points.polyData.at(i).at(2) * 50));
wo->renderOrderType = RENDER_ORDER_TYPE::roOPAQUE;
std::string id = "ball";
wo->setLabel(id);
wl->push_back(wo);
WOIDS.push_back(wo->getID());
}
}
pastTS = currentSelectedTimeStamp;
}
WO *vtkOFRenderer::renderTimeStampTrack(WorldContainer *worldList) {
//WO* wo = WO::New();
VTKASSERT(currentSelectedTimeStamp != NULL,
"ERROR:: Uninitialized vtk timestamps!");
static const char* pastTS;
openFoamVtkFileData* pptr = new openFoamVtkFileData;
//if (currentSelectedTimeStamp != pastTS) {
int i = 0;
for (i = 0; i < timeStamps.size(); i++) {
if (timeStamps.at(i).c_str() == currentSelectedTimeStamp) break;
}
pptr = &tracksFileData.at(i);
//}
//int i;
std::string point(ManagerEnvironmentConfiguration::getSMM() + "/models/OppenheimerBoxTimeMag10x10x10.wrl");
for (i = 0; i < pptr->points.polyData.size();i++) {
WO* wo = WO::New(point, Vector(0.001, 0.001, 0.001), MESH_SHADING_TYPE::mstFLAT);
wo->setPosition(Vector(
pptr->points.polyData.at(i).at(0)*50, pptr->points.polyData.at(i).at(1)*50, pptr->points.polyData.at(i).at(2)*50));
wo->renderOrderType = RENDER_ORDER_TYPE::roOPAQUE;
std::string id = "ball";
wo->setLabel(id);
worldList->push_back(wo);
WOIDS.push_back(wo->getID());
}
pastTS = currentSelectedTimeStamp;
return nullptr;
}
/*This must be ran in already initialized WOImGui istance*/
void vtkOFRenderer::renderImGuivtkSettings() {
static int curTime = 0;
static const char* curItem = timeStamps.at(0).c_str();
ImGui::SetNextWindowSize(ImVec2(400, 200));
if (ImGui::Begin("Vtk View", NULL)) {
ImGui::BulletText("Select a timestamp to view!");
if (ImGui::BeginCombo("TimeStamps", currentSelectedTimeStamp)) {
for (int n = 0; n < timeStamps.size(); n++)
{
bool is_selected = (currentSelectedTimeStamp == timeStamps.at(n).c_str());
if (ImGui::Selectable(timeStamps.at(n).c_str(), is_selected))
currentSelectedTimeStamp = timeStamps.at(n).c_str();
if (is_selected)
ImGui::SetItemDefaultFocus();
}
ImGui::EndCombo();
}
}
ImGui::End();
//currentSelectedTimeStamp = curItem;
}