visualizationpipeline.cpp 2.96 KB
Newer Older
1
#include "visualizationpipeline.h"
schultezub's avatar
schultezub committed
2
#include "tgt/camera.h"
schultezub's avatar
schultezub committed
3
#include "tgt/quadrenderer.h"
schultezub's avatar
schultezub committed
4
#include "tgt/quadric.h"
5
#include "tgt/glcontext.h"
schultezub's avatar
schultezub committed
6
#include "core/datastructures/imagedatarendertarget.h"
7
8
9
10

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

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

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

    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
27
        for (std::vector<AbstractEventHandler*>::iterator it = _eventHandlers.begin(); it != _eventHandlers.end() && e->isAccepted(); ++it) {
28
29
30
31
            if ((*it)->accept(e)) {
                (*it)->execute(e);
            }
        }
schultezub's avatar
schultezub committed
32
33
34
35

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

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

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

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

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

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

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

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

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

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

83
}