eepgenerator.cpp 4.08 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
#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/imagedatagl.h"
#include "core/datastructures/imagedatarendertarget.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);
schultezub's avatar
schultezub committed
27
28

        // TODO: remove this ugly hack: automatically adapt near/far plane to volume extent.
29
30
31
        tgt::Camera c;
        c.setFarDist(512.f);
        _camera.setValue(c);
32
33
34
35
36
37
38
39
40
41
42
43
44
    }

    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);
schultezub's avatar
schultezub committed
45
        _shader = 0;
46
47
48
49
50
51
52
53
        VisualizationProcessor::deinit();
    }

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

        if (img != 0) {
            if (img->getDimensionality() == 3) {
54
                // TODO: implement some kind of cool proxy geometry supporting clipping (camera in volume)...
55
56
57
58
59
60
61
62
                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();
63
                tgt::loadMatrix(_camera.getValue().getProjectionMatrix());
64
65
66

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

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

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

76
77
                glDepthFunc(GL_LESS);
                glClearDepth(1.0f);
78
                glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
79
80
                glCullFace(GL_BACK);
                tgt::QuadRenderer::renderCube(volumeExtent, textureBounds);
81
82
83
84
85
86
87

                entrypoints->deactivate();

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

88
89
                glDepthFunc(GL_GREATER);
                glClearDepth(0.0f);
90
                glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
91
92
                glCullFace(GL_FRONT);
                tgt::QuadRenderer::renderCube(volumeExtent, textureBounds);
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

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

}