visualizationpipeline.cpp 2.91 KB
Newer Older
1
#include "visualizationpipeline.h"
schultezub's avatar
schultezub committed
2
#include "tgt/glcanvas.h"
3
#include "tgt/glcontext.h"
schultezub's avatar
schultezub committed
4
#include "core/datastructures/imagedatarendertarget.h"
5
6
7
8

namespace TUMVis {
    const std::string VisualizationPipeline::loggerCat_ = "TUMVis.core.datastructures.VisualizationPipeline";

9
    VisualizationPipeline::VisualizationPipeline() 
schultezub's avatar
schultezub committed
10
        : AbstractPipeline()
schultezub's avatar
schultezub committed
11
12
        , tgt::EventListener()
        , _renderTargetSize("canvasSize", "Canvas Size", tgt::ivec2(128, 128))
schultezub's avatar
schultezub committed
13
        , _renderTargetID("renderTargetID", "Render Target ID", "VisualizationPipeline.renderTarget")
14
        , _canvas(0)
15
    {
schultezub's avatar
schultezub committed
16
        _data.s_dataAdded.connect(this, &VisualizationPipeline::onDataContainerDataAdded);
17
18
19
    }

    VisualizationPipeline::~VisualizationPipeline() {
schultezub's avatar
schultezub committed
20
        _data.s_dataAdded.disconnect(this);
21
22
23
24
    }

    void VisualizationPipeline::onEvent(tgt::Event* e) {
        // cycle through event handlers, ask each one if it handles the event and if so, execute it.
schultezub's avatar
schultezub committed
25
        for (std::vector<AbstractEventHandler*>::iterator it = _eventHandlers.begin(); it != _eventHandlers.end() && e->isAccepted(); ++it) {
26
27
28
29
            if ((*it)->accept(e)) {
                (*it)->execute(e);
            }
        }
schultezub's avatar
schultezub committed
30
31
32
33

        if (e->isAccepted()) {
            EventListener::onEvent(e);
        }
34
35
36
37
38
39
40
    }

    PropertyCollection& VisualizationPipeline::getPropertyCollection() {
        return _properties;
    }

    void VisualizationPipeline::init() {
41
        tgtAssert(_canvas != 0, "Set a valid canvas before calling this method!");
42
        tgt::GLContextScopedLock lock(_canvas->getContext());
43
44
45
        AbstractPipeline::init();
    }

46
    void VisualizationPipeline::deinit() {
47
        tgtAssert(_canvas != 0, "Set a valid canvas before calling this method!");
48
49
50
51
        tgt::GLContextScopedLock lock(_canvas->getContext());
        AbstractPipeline::deinit();
    }

schultezub's avatar
schultezub committed
52
53
54
    const tgt::ivec2& VisualizationPipeline::getRenderTargetSize() const {
        return _renderTargetSize.getValue();
    }
schultezub's avatar
schultezub committed
55

schultezub's avatar
schultezub committed
56
57
58
    void VisualizationPipeline::onDataContainerDataAdded(const std::string& name, const DataHandle* dh) {
        if (name == _renderTargetID.getValue()) {
            s_renderTargetChanged();
schultezub's avatar
schultezub committed
59
        }
60
61
    }

62
63
    const std::string& VisualizationPipeline::getRenderTargetID() const {
        return _renderTargetID.getValue();
64
65
    }

schultezub's avatar
schultezub committed
66
67
    void VisualizationPipeline::setRenderTargetSize(const tgt::ivec2& size) {
        _renderTargetSize.setValue(size);
schultezub's avatar
schultezub committed
68
69
    }

70
    void VisualizationPipeline::lockGLContextAndExecuteProcessor(AbstractProcessor& processor) {
71
        tgtAssert(_canvas != 0, "Set a valid canvas before calling this method!");
72
73
        tgt::GLContextScopedLock lock(_canvas->getContext());
        executeProcessor(processor);
74
        glFlush();  // TODO: is glFlush enough or do we need a glFinish here?
75
76
    }

77
78
79
80
    void VisualizationPipeline::setCanvas(tgt::GLCanvas* canvas) {
        _canvas = canvas;
    }

81
}