eepgenerator.cpp 6.93 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
#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")
        , _shader(0)
    {
        addProperty(&_sourceImageID);
        addProperty(&_entryImageID);
        addProperty(&_exitImageID);
        addProperty(&_camera);
31
32
33
        tgt::Camera c;
        c.setFarDist(512.f);
        _camera.setValue(c);
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
    }

    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 textureBounds(tgt::vec3(0.f), tgt::vec3(1.f));

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

                glMatrixMode(GL_PROJECTION);
                glPushMatrix();
64
                tgt::loadMatrix(_camera.getValue().getProjectionMatrix());
65
66
67

                glMatrixMode(GL_MODELVIEW);
                glPushMatrix();
68
                tgt::loadMatrix(_camera.getValue().getViewMatrix());
69
70

                _shader->activate();
71
                glEnable(GL_CULL_FACE);
72
73
74
75
76

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

77
78
                glDepthFunc(GL_GREATER);
                glClearDepth(0.0f);
79
                glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
80
                glCullFace(GL_FRONT);
81
82
83
84
85
86
87
88
                renderProxyGeometry(volumeExtent, textureBounds);

                entrypoints->deactivate();

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

89
90
                glDepthFunc(GL_LESS);
                glClearDepth(1.0f);
91
                glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
92
                glCullFace(GL_BACK);
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
                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);
131
            glVertex3f(llf.x, llf.y, llf.z);
132
133
134
135
            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);
136
137
            glTexCoord3f(tLlf.x, tUrb.y, tLlf.z);
            glVertex3f(llf.x, urb.y, llf.z);
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

            // 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, 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);
176
177
            glTexCoord3f(tLlf.x, tLlf.y, tLlf.z);
            glVertex3f(llf.x, llf.y, llf.z);
178
179
180
181
182
183
184
185
186
187
188
189
190
191

            // 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();
    }

}