-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
578 lines (501 loc) · 24.3 KB
/
Copy pathmain.cpp
File metadata and controls
578 lines (501 loc) · 24.3 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
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
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
// absolve some linking errors with glad
#include "src/extern/glad.c"
// for rendering
#include "src/opengl/app.h" // window management, events, etc
#include "src/opengl/fonts.h" // text rendering
// cluster and paper management
#include "src/paper_loader.h" // loading papers & clusters
#include "src/clusters.h" // rendering clusters
// small struct for bar charts
#include "src/bar_chart.h"
// standard library stuff
#include <string>
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <cstdlib>
// constants
constexpr unsigned int FONT_SIZE {8}; // font size of text on screen
constexpr bool DEBUG_INFO_ENABLED {true}; // flag to toggle whether to show text on screen or not
constexpr float ANIMATION_SENSITIVITY{1.f}; // amount to change animation speed by on key press
// (NOTE: Changing the scale requires the convex hull models for the clusters to be regenerated)
constexpr float SCALE {5.0}; // scalar value to scale raw coordinates from csv by
int MAX_BARS{40}; // maximum amount of bars to display
// cluster depth for rendering
constexpr int CLUSTER_DEPTH {6}; // amount of clusters is 2^CLUSTER_DEPTH, so 2:4, 3:8, 4:16, 5:32, 6:64
// animation tweaks
float ANIMATION_SPEED {1.f};
bool RESET{false};
// view mode: default is all shown, unseen hidden is unexplored clusters hidden, and hidden is no clusters
enum VIEW_MODE
{
CLUSTERS_DEFAULT,
CLUSTERS_UNSEEN_HIDDEN,
CLUSTERS_HIDDEN,
};
// view mode (global for callbacks)
int viewMode{CLUSTERS_DEFAULT};
enum BAR_MODE
{
BARS_FULL, // show proportion of papers across clusters
BARS_INDIVIDUAL // show proportion of explored/unexplored papers inside clusters
};
// bar mode (global for callbacks)
int barMode{BARS_FULL};
// convert from wstring (wide-string) to regular standard string
void wstring2string(const std::wstring& ws, std::string& s);
// glfw keycallback to handle interactivity
void key_callback(GLFWwindow* window, int key, int scancode, int action, int mods);
// gets string format for VIEW_MODe enum
std::string getViewMode();
int main()
{
// load papers
PaperLoader paperLoader{};
paperLoader.loadFromFile("data/papers_with_labels.csv", SCALE);
paperLoader.generateClusters(); // group papers into clusters
std::cout << "Loaded papers!\n";
// ---- OpenGL ---- //
// initialize opengl wrapper
App app{640, 640, "OpenGL window"};
// for keyboard interactivity
glfwSetKeyCallback(app.getWindow(), key_callback);
app.enableDepthTesting(); // IMPORTANT
// first person camera
app.setCameraEnabled(true);
// configure global opengl state
glEnable(GL_PROGRAM_POINT_SIZE);
glEnable(GL_LINE_SMOOTH);
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); // for text & cluster rendering
// glLineWidth(5.0f);
// glEnable(GL_CULL_FACE);
// load coordinates from papers
std::vector<float> paperData;
paperLoader.getVertices(paperData);
// generate convex hull models from clusters (saved at data/cluster_models/)
Clusters::ClusterRenderer clusterRenderer{};
// // generates .obj file of convex hull for each cluster
// clusterRenderer.generateClusters(paperLoader.getClustersFull());
clusterRenderer.loadClusters(paperLoader.getClustersFull()); // load convex hulls
// generate vbo for paper instances (offset xyz, included flag, counter)
unsigned int instanceVBO;
glGenBuffers(1, &instanceVBO);
glBindBuffer(GL_ARRAY_BUFFER, instanceVBO);
glBufferData(GL_ARRAY_BUFFER, static_cast<GLsizeiptr>(paperData.size() * sizeof(paperData[0])), paperData.data(), GL_STATIC_DRAW);
glBindBuffer(GL_ARRAY_BUFFER, 0);
// create vertex array and vertex buffer for paper cubes
unsigned int VAO, VBO;
glGenVertexArrays(1, &VAO);
glGenBuffers(1, &VBO);
glBindVertexArray(VAO);
glBindBuffer(GL_ARRAY_BUFFER, VBO);
glBufferData(GL_ARRAY_BUFFER, static_cast<GLsizeiptr>(sizeof(Shapes3D::cubeVerticesNormals)), Shapes3D::cubeVerticesNormals, GL_STATIC_DRAW);
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 6 * sizeof(float), reinterpret_cast<void*>(0));
glEnableVertexAttribArray(0);
glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, 6 * sizeof(float), reinterpret_cast<void*>(3 * sizeof(float)));
glEnableVertexAttribArray(1);
// set instance data
glEnableVertexAttribArray(2);
glBindBuffer(GL_ARRAY_BUFFER, instanceVBO);
glVertexAttribPointer(2, 3, GL_FLOAT, GL_FALSE, 5 * sizeof(float), reinterpret_cast<void*>(0));
glEnableVertexAttribArray(3);
glVertexAttribPointer(3, 1, GL_FLOAT, GL_FALSE, 5 * sizeof(float), reinterpret_cast<void*>(3 * sizeof(float)));
glEnableVertexAttribArray(4);
glVertexAttribPointer(4, 1, GL_FLOAT, GL_FALSE, 5 * sizeof(float), reinterpret_cast<void*>(4 * sizeof(float)));
glVertexAttribDivisor(2, 1); // update this index every 1th instance
glVertexAttribDivisor(3, 1); // "" ""
glVertexAttribDivisor(4, 1); // "" ""
// load papers shader
const Shader pointShader{"shaders/pointsLighting.vert", "shaders/pointsLighting.frag"};
// shader.addGeometryShader("shaders/points.geom");
// post-processing shader
const Shader screenShader{"shaders/builtin/screenShader.vert", "shaders/builtin/screenShader.frag"};
const Shader uiShader {"shaders/builtin/screenShader.vert", "shaders/ui.frag"};
app.initPostProcessing();
// initialize font manager
FontManager fontManager{};
fontManager.init("data/fonts/Acme 9 Regular Bold Xtnd.ttf", FONT_SIZE);
// load fonts shader
const Shader fontShader{"shaders/builtin/fonts.vert", "shaders/builtin/fonts.frag"};
// cluster shader
const Shader clusterShader{"shaders/cluster.vert", "shaders/cluster.frag"};
// keep track of passed clusters
std::vector<int> passedClusters{};
int lastPaperIndex{0};
std::cout << "Successfully initialized!\n";
// data for bar chart
std::map<int, Bar> bars{};
std::map paperClusters{paperLoader.getClusters(CLUSTER_DEPTH)};
// create a bar for each cluster
for (int b {0}; b < std::pow(2, CLUSTER_DEPTH); ++b)
{
std::string name;
wstring2string(paperClusters[b].label, name);
bars[b] = Bar{
0.0f,
0,
b,
std::move(name),
paperClusters[b].num_papers
};
}
// counter to keep track of num. papers
int numPapers{0};
// animation progress
float animationProgress{0.f};
// main loop
while (!app.shouldClose())
{
// refresh keyboard events
app.handleInput();
app.enablePostProcessing(); // write to framebuffer
// ---- do rendering ---- //
app.clear(); // clear depth and color buffers (+stencil but that's not used)
if (RESET)
{
// reset bars
for (int b {0}; b < std::pow(2, CLUSTER_DEPTH); ++b)
{
bars[b].numPapers = 0;
bars[b].numIncluded = 0;
bars[b].numNotIncluded = 0;
}
// reset clusters
passedClusters.clear();
animationProgress = 0.0f;
RESET = false;
}
// ------------------------ //
// Render the points (cubes)
// The cubes are rendered instanced to improve performance
pointShader.use();
pointShader.setMat4("projection", app.getPerspectiveMatrix());
pointShader.setMat4("view", app.getViewMatrix());
pointShader.setMat4("model", glm::mat4(1.0f));
pointShader.setVec3("camerapos", app.getCameraPosition());
pointShader.setFloat("time", animationProgress);
pointShader.setInt("lastIndex", static_cast<int>(paperLoader.getLastIndex()));
glBindVertexArray(VAO);
// there are five pieces of data per instance (5 * sizeof(float)), so number of instances = paperData.size() / 5
// not paperData.size()
glDrawArraysInstanced(GL_TRIANGLES, 0, 36, static_cast<int>(paperData.size() / 5));
// ------------------------ //
// update progress, lastPaperIndex, currentCluster & currentPaper
// progress of animation
const float progress {std::min(animationProgress, static_cast<float>(paperLoader.getLastIndex()))};
// current paper animation is at
const Paper& currentPaper {paperLoader.getPaper(progress)};
// current cluster the current paper is located in
const int currentCluster {paperLoader.getClusterID(currentPaper, CLUSTER_DEPTH)};
// update passed clusters
if (std::ranges::find(passedClusters, currentCluster) == passedClusters.end())
{
passedClusters.push_back(currentCluster);
}
// update all the clusters animation skipped (animation speed > 1 paper/sec)
for (int i{lastPaperIndex}; i < static_cast<int>(progress); ++i)
{
const Paper& paperTemp {paperLoader.getPaper(static_cast<float>(i))};
const int paperCluster {paperLoader.getClusterID(paperTemp, CLUSTER_DEPTH)};
if (std::ranges::find(passedClusters, paperCluster) == passedClusters.end())
{
passedClusters.push_back(paperCluster);
}
// add clusters to bar chart
++bars[paperCluster].numPapers;
if (paperTemp.included)
{
++bars[paperCluster].numIncluded;
} else {
++bars[paperCluster].numNotIncluded;
}
// increment total
++numPapers;
}
lastPaperIndex = static_cast<int>(progress);
// ---- Render clusters ---- //
/* Clusters are transparent, so order is:
* 1. Render opaque objects (points/papers/cubes)
* 2. Sort transparent objects (clusters)
* 3. Render transparent objects in order (blending works now)
*/
clusterShader.use();
clusterShader.setVec3("CameraPos", app.getCameraPosition());
// iterate through clusters (n = 2^CLUSTER_DEPTH)
std::map<float, std::pair<int, glm::vec3>> sortedClusters{};
for (int c {0}; c < std::pow(2, CLUSTER_DEPTH); ++c)
{
// color & idx is info needed for rendering
glm::vec3 color;
float distance; // info needed for sorting
// get cluster data for position
const Clusters::ClusterData* clusterData {clusterRenderer.getClusterData(CLUSTER_DEPTH, c)};
distance = glm::length(app.getCameraPosition() - clusterData->position);
if (currentCluster == c)
{
color = {0.9f, 1.0f, 0.0f};
} else if (std::ranges::find(passedClusters, c) != passedClusters.end())
{
color = {0.0f, 0.9f, 1.0f};
} else
{
if (viewMode == CLUSTERS_DEFAULT)
{
color = {0.4f, 0.3f, 0.4f};
} else
{
color = {0.0f, 0.0f, 0.0f};
}
}
if (viewMode == CLUSTERS_HIDDEN)
{
color = {0.0f, 0.0f, 0.0f};
}
// add to map to be sorted
sortedClusters[distance] = std::make_pair(c, color);
}
// sort & render the clusters
clusterShader.use();
clusterShader.setVec3("CameraPos", app.getCameraPosition());
clusterShader.setInt("lighting", 1);
glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
for (std::map<float, std::pair<int, glm::vec3>>::reverse_iterator it {sortedClusters.rbegin()}; it != sortedClusters.rend(); ++it)
{
clusterRenderer.renderCluster(clusterShader, app.getPerspectiveMatrix(), app.getViewMatrix(),
it->second.second, CLUSTER_DEPTH, it->second.first);
}
glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
// ------------------------ //
// ---- debug info and post-processing ---- //
// app.enablePostProcessing(); // write to framebuffer
if (DEBUG_INFO_ENABLED)
{
// Calculate bar chart of percentages to render //
// update font manager first
fontManager.updateProjection(static_cast<float>(app.getWidth()), static_cast<float>(app.getHeight()));
// set up bars to sort
std::vector<std::pair<int, Bar>> sortedBars{};
for (const std::pair<const int, Bar>& bar : bars)
{
sortedBars.emplace_back(bar);
}
// sort bars
std::ranges::sort(sortedBars, [](const std::pair<int, Bar>& bar1, const std::pair<int, Bar>& bar2)
{
return bar1.second.numPapers > bar2.second.numPapers;
});
// render bars
int numBars{0};
std::stringstream ss; // for percentages & cluster labesl
for (const std::pair<int, Bar>& bar : sortedBars)
{
if (barMode == BARS_FULL)
{
// render bar
const float percentage {static_cast<float>(bar.second.numPapers) / std::max(0.001f, static_cast<float>(lastPaperIndex))};
FRect rect {50.f, static_cast<float>(app.getHeight() - 205 - numBars * 17), 1.f + 200.f * percentage, 14.f};
app.drawRect({
rect.x * 2.f / static_cast<float>(app.getWidth()) - 1.f, rect.y * 2.f / static_cast<float>(app.getHeight()) - 1.f,
rect.w * 2.f / static_cast<float>(app.getWidth()), rect.h * 2.f / static_cast<float>(app.getHeight())
}, {255, 255, 255});
// render text
ss << static_cast<float>(static_cast<int>(percentage * 1000.f)) / 10.f << "%";
fontManager.renderText(fontShader, ss.str(), 3.f, static_cast<float>(app.getHeight() - 217 - numBars * 17), 1.0f, glm::vec3{1.0f});
ss.str("");
ss << bar.second.name;
fontManager.renderText(fontShader, ss.str(), 55.f + 200.f * percentage, static_cast<float>(app.getHeight() - 217 - numBars * 17), 1.0f, glm::vec3{1.0f});
ss.str("");
} else {
const float percentExplored {static_cast<float>(bar.second.numPapers) / static_cast<float>(bar.second.totalPapers)};
FRect erect {50.f, static_cast<float>(app.getHeight() - 205 - numBars * 17), 1.f + 200.f * percentExplored, 14.f};
const FRect urect = {erect.x + erect.w, erect.y, 201.f - erect.w, erect.h};
app.drawRect({
urect.x * 2.f / static_cast<float>(app.getWidth()) - 1.f, urect.y * 2.f / static_cast<float>(app.getHeight()) - 1.f,
urect.w * 2.f / static_cast<float>(app.getWidth()), urect.h * 2.f / static_cast<float>(app.getHeight())
}, {5, 5, 5, 120});
const float percentIncluded {static_cast<float>(bar.second.numIncluded) / static_cast<float>(bar.second.numPapers)};
const float percentNotIncluded {static_cast<float>(bar.second.numNotIncluded) / static_cast<float>(bar.second.numPapers)};
const FRect irect {erect.x, erect.y, erect.w * percentIncluded, erect.h};
app.drawRect({
irect.x * 2.f / static_cast<float>(app.getWidth()) - 1.f, irect.y * 2.f / static_cast<float>(app.getHeight()) - 1.f,
irect.w * 2.f / static_cast<float>(app.getWidth()), irect.h * 2.f / static_cast<float>(app.getHeight())
}, {0, 255, 10});
const FRect nrect {erect.x + irect.w, erect.y, erect.w * percentNotIncluded, erect.h};
app.drawRect({
nrect.x * 2.f / static_cast<float>(app.getWidth()) - 1.f, nrect.y * 2.f / static_cast<float>(app.getHeight()) - 1.f,
nrect.w * 2.f / static_cast<float>(app.getWidth()), nrect.h * 2.f / static_cast<float>(app.getHeight())
}, {255, 10, 10});
// render text
ss << static_cast<float>(static_cast<int>(percentExplored * 1000.f)) / 10.f << "%";
fontManager.renderText(fontShader, ss.str(), 3.f, static_cast<float>(app.getHeight() - 217 - numBars * 17), 1.0f, glm::vec3{1.0f});
ss.str("");
ss << bar.second.name;
fontManager.renderText(fontShader, ss.str(), 55.f + 200.f, static_cast<float>(app.getHeight() - 217 - numBars * 17), 1.0f, glm::vec3{1.0f});
ss.str("");
}
// cap number of bars
++numBars;
if (numBars > MAX_BARS)
{
break;
}
}
if (barMode == BARS_FULL) {
ss << "% = Percent of total papers in cluster";
fontManager.renderText(fontShader, ss.str(), 5.f, static_cast<float>(app.getHeight() - 217 - numBars * 17), 1.0f, glm::vec3{1.0f});
ss.str("");
} else {
ss << "% = Percent of papers within cluster explored";
fontManager.renderText(fontShader, ss.str(), 5.f, static_cast<float>(app.getHeight() - 217 - numBars * 17), 1.0f, glm::vec3{1.0f});
ss.str("");
}
std::stringstream text;
std::vector<std::string> info;
// average frame time
float avgTime {static_cast<int>(app.getAvgFrameTime() * 1000) / 1000.0f};
text << "Avg. frame time: " << avgTime * 1000.0f<< " ms";
info.emplace_back(text.str());
text.str(""); // clear string stream
// framebuffer size
text << "Framebuffer size: " << app.getWidth() << " * " << static_cast<float>(app.getHeight());
info.emplace_back(text.str());
text.str(""); // clear string stream
// progress
int prog {std::min(static_cast<int>(paperLoader.getNumPapers()), static_cast<int>(animationProgress + 1.f))};
float percentage {(animationProgress + 1.f) / static_cast<float>(paperLoader.getNumPapers())}; // progress as percentage
percentage = std::min(100.0f, static_cast<float>(static_cast<int>(percentage * 1000.f)) / 10.f); // (n / 10.f = n / 1000.f * 100.f)
text << "Raw Progress: " << prog << "/" << paperLoader.getNumPapers() << " (" << percentage << "%)";
info.emplace_back(text.str());
text.str("");
prog = std::min(static_cast<int>(paperLoader.getLastIndex()), prog);
percentage = (animationProgress + 1.f) / static_cast<float>(paperLoader.getLastIndex()); // progress as percentage
percentage = std::min(100.0f, static_cast<float>(static_cast<int>(percentage * 1000.f)) / 10.f); // (n / 10.f = n / 1000.f * 100.f)
text << "Progress: " << prog << "/" << paperLoader.getLastIndex() << " (" << percentage << "%)";// n." << animationProgress;
info.emplace_back(text.str());
text.str("");
// animation speed
text << "Animation speed: " << ANIMATION_SPEED << " papers/sec";
info.emplace_back(text.str());
text.str("");
// papers size & vertices size
text << "Paper data size (MB): " << static_cast<int>(paperLoader.getPapersSize()) / 1000000;
info.emplace_back(text.str());
text.str("");
text << "Vertex data size (KB): " << static_cast<int>(paperLoader.getVerticesSize() + sizeof(Shapes3D::cubeVerticesNormals)) / 1000;
info.emplace_back(text.str());
text.str("");
text << "Num. papers explored: " << paperLoader.getLastIndex();
info.emplace_back(text.str());
text.str("");
text << "Num. papers unexplored: " << paperLoader.getNumPapers() - paperLoader.getLastIndex();
info.emplace_back(text.str());
text.str("");
text << "Current cluster depth: " << CLUSTER_DEPTH;
info.emplace_back(text.str());
text.str("");
std::wstring clusterLabel {paperLoader.getClusterLabel(currentPaper, CLUSTER_DEPTH)};
std::string label;
wstring2string(clusterLabel, label);
text << "Current cluster label: " << label;
info.emplace_back(text.str());
text.str("");
text << "Current cluster ID: " << paperLoader.getClusterID(currentPaper, CLUSTER_DEPTH);
info.emplace_back(text.str());
text.str("");
for (int i {0}; i < info.size(); ++i)
{
fontManager.renderText(fontShader, info[i], 10.0f, static_cast<float>(app.getHeight() - 25 - 15 * i), 1.0f, glm::vec3(1.0f, 1.0f, 1.0f));
}
std::string paperTitle;
wstring2string(currentPaper.title, paperTitle);
text << "Current paper title: " << paperTitle;
fontManager.renderText(fontShader, text.str(), 5.0f, 5.0f, 1.0f, glm::vec3(1.0f, 1.0f, 1.0f));
text.str("");
text << "View mode: " << getViewMode();
fontManager.renderText(fontShader, text.str(), 5.0f, 20.0f, 1.0f, glm::vec3(1.0f, 1.0f, 1.0f));
text.str("");
glm::vec3 cameraPos {app.getCameraPosition()};
text << "Camera Position: " << cameraPos.x << ", " << cameraPos.y << ", " << cameraPos.z;
fontManager.renderText(fontShader, text.str(), 5.0f, 35.0f, 1.0f, glm::vec3(1.0f, 1.0f, 1.0f));
text.str("");
}
// ------------------------ //
// update buffers and stuff
app.disablePostProcessing();
app.getPostProcessor()->render(uiShader);
glBindFramebuffer(GL_FRAMEBUFFER, 0);
app.tick();
// animation is updated at constant speed
animationProgress += ANIMATION_SPEED * app.getDeltaTime();
// clamp animation progress to avoid user messing it up
animationProgress = std::max(0.0f, std::min(static_cast<float>(paperLoader.getNumPapers() - 1), animationProgress));
}
// clean up
glDeleteVertexArrays(1, &VAO);
glDeleteBuffers(1, &VBO);
glDeleteBuffers(1, &instanceVBO);
app.close();
return EXIT_SUCCESS;
}
void wstring2string(const std::wstring& ws, std::string& s)
{
const std::size_t len {std::wcstombs(nullptr, ws.c_str(), 0) + 1};
// buffer to hold multibyte string
char* buffer {new char[len]};
wcstombs(buffer, ws.c_str(), len);
s = buffer;
delete[] buffer;
}
void key_callback(GLFWwindow* window, int key, int scancode, int action, int mods)
{
// switch between different view modes
if (key == GLFW_KEY_C && action == GLFW_PRESS)
{
viewMode = (viewMode + 1) % 3;
}
// toggle bar mode
if (key == GLFW_KEY_B && action == GLFW_PRESS)
{
barMode = (barMode + 1) % 2;
}
if (key == GLFW_KEY_M && (action == GLFW_REPEAT || action == GLFW_PRESS))
{
MAX_BARS = std::max(0, std::min(static_cast<int>(std::pow(2, CLUSTER_DEPTH)), ++MAX_BARS));
}
if (key == GLFW_KEY_N && (action == GLFW_REPEAT || action == GLFW_PRESS))
{
MAX_BARS = std::max(0, std::min(static_cast<int>(std::pow(2, CLUSTER_DEPTH)), --MAX_BARS));
}
// increase animation speed
if (key == GLFW_KEY_UP && (action == GLFW_REPEAT || action == GLFW_PRESS))
{
ANIMATION_SPEED += ANIMATION_SENSITIVITY;
}
// decrease animation speed
if (key == GLFW_KEY_DOWN && (action == GLFW_REPEAT || action == GLFW_PRESS))
{
ANIMATION_SPEED -= ANIMATION_SENSITIVITY;
// limit to positive values for now
ANIMATION_SPEED = std::max(0.f, ANIMATION_SPEED); // TODO: Fix this
}
// reset animation
if (key == GLFW_KEY_0 && (action == GLFW_PRESS))
{
RESET = true;
}
}
std::string getViewMode()
{
switch (viewMode)
{
case CLUSTERS_DEFAULT:
return "CLUSTERS_DEFAULT";
case CLUSTERS_UNSEEN_HIDDEN:
return "CLUSTERS_UNSEEN_HIDDEN";
case CLUSTERS_HIDDEN:
return "CLUSTERS_HIDDEN";
default:
return "CLUSTERS_DEFAULT";
};
}