-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTFTexture.cpp
141 lines (113 loc) · 3.19 KB
/
TFTexture.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
/*! \file TFTexture.cpp
\brief TFTexture source file.
Contains the source code for the TFTexture class, which represents the transfer function
both as a series of TFNodes and as the texture generated from them.
*/
#include "TFTexture.h"
#include <algorithm>
TFTexture::TFTexture(QWidget *parent)
{
this->parent = parent;
nodes = std::map<int, TFNode>();
addNode(TFNode(0, 0.0, 0.0, 0.0, 0.0));
addNode(TFNode(96 * 8.0, 0.5, 0.1, 0.0, 0.05));
addNode(TFNode(128 * 8.0, 0.9, 0.05, 0.1, 0.1));
addNode(TFNode(164 * 8.0, 0.75, 0.8, 0.5, 0.36));
addNode(TFNode(196 * 8.0, 0.95, 0.89, 0.65, 0.76));
addNode(TFNode(256 * 8.0, 0.99, 0.99, 0.96, 0.97));
}
TFTexture::~TFTexture(void)
{
}
void TFTexture::addNode(TFNode node)
{
nodes.insert(std::pair<int, TFNode>(node.x, node));
}
void TFTexture::removeNode(GLuint x)
{
nodes.erase(x);
}
std::map<int, TFNode>::iterator TFTexture::begin()
{
return nodes.begin();
}
std::map<int, TFNode>::iterator TFTexture::end()
{
return nodes.end();
}
void TFTexture::clear(void)
{
nodes.clear();
}
void TFTexture::setFBO(GLuint fbo, GLuint texture)
{
this->fbo = fbo;
this->texture = texture;
}
void TFTexture::setHistogram(int* histogram)
{
int histHeight = 0;
for (int i = 1; i < 256; i++) {
if (histogram[i] > histHeight)
histHeight = histogram[i];
}
for (int i = 1; i < 256; i++) {
this->histogram[i] = static_cast<float>(histogram[i]) / histHeight;
}
}
void TFTexture::generate(void)
{
glPushMatrix();
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_3D, 0);
glActiveTexture(GL_TEXTURE1);
glBindTexture(GL_TEXTURE_2D, 0);
glActiveTexture(GL_TEXTURE2);
glBindTexture(GL_TEXTURE_2D, 0);
glActiveTexture(GL_TEXTURE3);
glBindTexture(GL_TEXTURE_2D, 0);
glUseProgram(0);
glDisable(GL_TEXTURE_2D);
glDisable(GL_TEXTURE_3D);
glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fbo);
glViewport(0, 0, 2048, 2048);
glMatrixMode(GL_PROJECTION);
glPushMatrix();
glLoadIdentity();
glOrtho(0.0, 2048.0, 0.0, 2048.0, -1.0, 1.0);
glMatrixMode(GL_MODELVIEW);
glPushMatrix();
glLoadIdentity();
glClearColor(0.0, 0.0, 0.0, 0.0);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
glBegin(GL_QUADS);
std::map<int, TFNode>::iterator node;
TFNode thisNode, prevNode;
for(node = nodes.begin(); node != nodes.end(); node++)
{
if(node == nodes.begin())
{
prevNode = node->second;
continue;
}
thisNode = node->second;
glColor4f(prevNode.r, prevNode.g, prevNode.b, prevNode.a);
glVertex3f(prevNode.x, 0, -1);
glColor4f(thisNode.r, thisNode.g, thisNode.b, thisNode.a);
glVertex3f(thisNode.x, 0, -1);
glColor4f(thisNode.r, thisNode.g, thisNode.b, thisNode.a);
glVertex3f(thisNode.x, 2048, -1);
glColor4f(prevNode.r, prevNode.g, prevNode.b, prevNode.a);
glVertex3f(prevNode.x, 2048, -1);
prevNode = node->second;
}
glEnd();
glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);
glViewport(0, 0, parent->width(), parent->height());
glMatrixMode(GL_PROJECTION);
glPopMatrix();
glMatrixMode(GL_MODELVIEW);
glPopMatrix();
glPopMatrix();
}