eepgenerator.cpp 7.27 KB
Newer Older
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
#include "eepgenerator.h"

#include "tgt/glmath.h"
#include "tgt/logmanager.h"
#include "tgt/quadrenderer.h"
#include "tgt/shadermanager.h"
#include "tgt/textureunit.h"

#include "core/datastructures/imagedata.h"
#include "core/datastructures/imagedatagl.h"
#include "core/datastructures/imagedatarendertarget.h"
#include "core/datastructures/imagedataconverter.h"

#include "core/classification/simpletransferfunction.h"

namespace TUMVis {
    const std::string EEPGenerator::loggerCat_ = "TUMVis.modules.vis.EEPGenerator";

    EEPGenerator::EEPGenerator(GenericProperty<tgt::ivec2>& canvasSize)
        : VisualizationProcessor(canvasSize)
        , _sourceImageID("sourceImageID", "Input Image", "")
        , _entryImageID("entryImageID", "Output Entry Points Image", "")
        , _exitImageID("exitImageID", "Output Exit Points Image", "")
        , _camera("camera", "Camera")
        , _jitterEntryPoints("jitterEntryPoints", "Jitter Entry Points", true)
        , _shader(0)
    {
        addProperty(&_sourceImageID);
        addProperty(&_entryImageID);
        addProperty(&_exitImageID);
        addProperty(&_camera);
    }

    EEPGenerator::~EEPGenerator() {

    }

    void EEPGenerator::init() {
        VisualizationProcessor::init();
        _shader = ShdrMgr.loadSeparate("core/glsl/passthrough.vert", "modules/vis/eepgenerator.frag", "", false);
    }

    void EEPGenerator::deinit() {
        ShdrMgr.dispose(_shader);
        VisualizationProcessor::deinit();
    }

    void EEPGenerator::process(DataContainer& data) {
        DataContainer::ScopedTypedData<ImageDataGL> img(data, _sourceImageID.getValue());

        if (img != 0) {
            if (img->getDimensionality() == 3) {
                // TODO: implement some kind of proxy geometry...
                tgt::Bounds volumeExtent = img->getWorldBounds();
                //tgt::Bounds volumeExtent(tgt::vec3(-1.f), tgt::vec3(1.f));
                tgt::Bounds textureBounds(tgt::vec3(0.f), tgt::vec3(1.f));

                tgt::vec3 pos = volumeExtent.center() - tgt::vec3(0, 0, tgt::length(volumeExtent.diagonal()));
                tgt::Camera cam(pos, volumeExtent.center());
                cam.setFarDist(500.f);

                // set modelview and projection matrices
                glPushAttrib(GL_ALL_ATTRIB_BITS);

                glMatrixMode(GL_PROJECTION);
                glPushMatrix();
                tgt::loadMatrix(cam.getProjectionMatrix());

                glMatrixMode(GL_MODELVIEW);
                glPushMatrix();
                tgt::loadMatrix(cam.getViewMatrix());

                _shader->activate();

                // create entry points texture
                ImageDataRenderTarget* entrypoints = new ImageDataRenderTarget(tgt::svec3(_renderTargetSize.getValue(), 1));
                entrypoints->activate();

                glDepthFunc(GL_LESS);
                glClearDepth(1.0f);
                glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
                glCullFace(GL_BACK);
                _shader->setUniform("_jitterPoints", _jitterEntryPoints.getValue());
                renderProxyGeometry(volumeExtent, textureBounds);

                entrypoints->deactivate();

                // create exit points texture
                ImageDataRenderTarget* exitpoints = new ImageDataRenderTarget(tgt::svec3(_renderTargetSize.getValue(), 1));
                exitpoints->activate();

                glDepthFunc(GL_GREATER);
                glClearDepth(0.0f);
                glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
                glCullFace(GL_FRONT);
                _shader->setUniform("_jitterPoints", false);
                renderProxyGeometry(volumeExtent, textureBounds);

                exitpoints->deactivate();

                _shader->deactivate();


                glMatrixMode(GL_MODELVIEW);
                glPopMatrix();
                glMatrixMode(GL_PROJECTION);
                glPopMatrix();
                glPopAttrib();

                data.addData(_entryImageID.getValue(), entrypoints);
                data.addData(_exitImageID.getValue(), exitpoints);
            }
            else {
                LERROR("Input image must have dimensionality of 3.");
            }
        }
        else {
            LERROR("No suitable input image found.");
        }

        _invalidationLevel.setValid();
    }

    void EEPGenerator::renderProxyGeometry(const tgt::Bounds& bounds, const tgt::Bounds& texBounds) {
        const tgt::vec3& llf = bounds.getLLF();
        const tgt::vec3& urb = bounds.getURB();
        const tgt::vec3& tLlf = texBounds.getLLF();
        const tgt::vec3& tUrb = texBounds.getURB();

        // TODO: get fuckin' rid of intermediate mode, it simply sucks...
        glColor3f(1.f, 0.f, 1.f);
        glBegin(GL_QUADS);
            // front
            glTexCoord3f(tLlf.x, tLlf.y, tLlf.z);
            glVertex3fv(llf.elem);
            glTexCoord3f(tUrb.x, tLlf.y, tLlf.z);
            glVertex3f(urb.x, llf.y, llf.z);
            glTexCoord3f(tUrb.x, tUrb.y, tLlf.z);
            glVertex3f(urb.x, urb.y, llf.z);
            glTexCoord3f(tLlf.x, tLlf.y, tLlf.z);
            glVertex3f(llf.x, llf.y, llf.z);

            // right
            glTexCoord3f(tUrb.x, tLlf.y, tLlf.z);
            glVertex3f(urb.x, llf.y, llf.z);
            glTexCoord3f(tUrb.x, tLlf.y, tUrb.z);
            glVertex3f(urb.x, llf.y, urb.z);
            glTexCoord3f(tUrb.x, tUrb.y, tUrb.z);
            glVertex3f(urb.x, urb.y, urb.z);
            glTexCoord3f(tUrb.x, tUrb.y, tLlf.z);
            glVertex3f(urb.x, urb.y, llf.z);

            // top
            glTexCoord3f(tLlf.x, tUrb.y, tLlf.z);
            glVertex3f(llf.x, urb.y, llf.z);
            glTexCoord3f(tUrb.x, tUrb.y, tLlf.z);
            glVertex3f(urb.x, urb.y, llf.z);
            glTexCoord3f(tUrb.x, tUrb.y, tUrb.z);
            glVertex3f(urb.x, urb.y, urb.z);
            glTexCoord3f(tLlf.x, tUrb.y, tUrb.z);
            glVertex3f(llf.x, urb.y, urb.z);

            // left
            glTexCoord3f(tLlf.x, tLlf.y, tUrb.z);
            glVertex3f(llf.x, llf.y, urb.z);
            glTexCoord3f(tLlf.x, tLlf.y, tLlf.z);
            glVertex3f(llf.x, llf.y, llf.z);
            glTexCoord3f(tLlf.x, tUrb.y, tLlf.z);
            glVertex3f(llf.x, urb.y, llf.z);
            glTexCoord3f(tLlf.x, tUrb.y, tUrb.z);
            glVertex3f(llf.x, urb.y, urb.z);

            // bottom
            glTexCoord3f(tLlf.x, tLlf.y, tLlf.z);
            glVertex3f(llf.x, llf.y, llf.z);
            glTexCoord3f(tLlf.x, tLlf.y, tUrb.z);
            glVertex3f(llf.x, llf.y, urb.z);
            glTexCoord3f(tUrb.x, tLlf.y, tUrb.z);
            glVertex3f(urb.x, llf.y, urb.z);
            glTexCoord3f(tUrb.x, tLlf.y, tLlf.z);
            glVertex3f(urb.x, llf.y, llf.z);

            // back
            glTexCoord3f(tUrb.x, tLlf.y, tUrb.z);
            glVertex3f(urb.x, llf.y, urb.z);
            glTexCoord3f(tLlf.x, tLlf.y, tUrb.z);
            glVertex3f(llf.x, llf.y, urb.z);
            glTexCoord3f(tLlf.x, tUrb.y, tUrb.z);
            glVertex3f(llf.x, urb.y, urb.z);
            glTexCoord3f(tUrb.x, tUrb.y, tUrb.z);
            glVertex3f(urb.x, urb.y, urb.z);
        glEnd();
    }

}