forked from kidanger/vpv
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathColormap.cpp
More file actions
99 lines (85 loc) · 2.38 KB
/
Colormap.cpp
File metadata and controls
99 lines (85 loc) · 2.38 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
#include <cassert>
#include <string>
#include "imgui.h"
#include "Colormap.hpp"
#include "Shader.hpp"
#include "globals.hpp"
Colormap::Colormap()
{
static int id = 0;
id++;
ID = "Colormap " + std::to_string(id);
for (int i = 0; i < 3; i++)
center[i] = .5f,
radius = .5f;
shader = gShaders[0];
}
void Colormap::displaySettings()
{
ImGui::DragFloat("Inverse Contrast", &radius);
ImGui::SameLine(); ImGui::ShowHelpMarker("Change the contrast/radius (shift + mouse wheel)");
ImGui::DragFloat3("Inverse Brightness", ¢er[0]);
ImGui::SameLine(); ImGui::ShowHelpMarker("Change the brightness/center (mouse wheel)");
const char* items[gShaders.size()];
for (int i = 0; i < gShaders.size(); i++)
items[i] = gShaders[i]->name.c_str();
int index = 0;
while (shader != gShaders[index]) index++;
ImGui::Combo("Tonemap", &index, items, gShaders.size());
ImGui::SameLine(); ImGui::ShowHelpMarker("Change the shader (s / shift+s)");
shader = gShaders[index];
}
std::array<float, 3> Colormap::getScale() const
{
std::array<float,3> scale;
for (int i = 0; i < 3; i++)
scale[i] = 1 / (2.f * radius);
return scale;
}
std::array<float, 3> Colormap::getBias() const
{
std::array<float,3> bias;
std::array<float,3> scale = getScale();
for (int i = 0; i < 3; i++)
bias[i] = (radius - center[i]) * scale[i];
return bias;
}
void Colormap::autoCenterAndRadius(float min, float max)
{
radius = (max - min) / 2.f;
for (int i = 0; i < 3; i++)
center[i] = (max + min) / 2.f;
}
void Colormap::getRange(float& min, float& max, int n) const
{
min = std::numeric_limits<float>::max();
max = std::numeric_limits<float>::min();
for (int i = 0; i < n; i++) {
min = std::min(min, center[i] - radius);
max = std::max(max, center[i] + radius);
}
}
void Colormap::nextShader()
{
for (int i = 0; i < gShaders.size() - 1; i++) {
if (gShaders[i] == shader) {
shader = gShaders[i + 1];
return;
}
}
shader = gShaders[0];
}
void Colormap::previousShader()
{
for (int i = 1; i < gShaders.size(); i++) {
if (gShaders[i] == shader) {
shader = gShaders[i - 1];
return;
}
}
shader = gShaders[gShaders.size() - 1];
}
std::string Colormap::getShaderName() const
{
return shader->name;
}