2.12.2021, 9:00 - 11:00: Due to updates GitLab may be unavailable for some minutes between 09:00 and 11:00.

visualizationpipeline.cpp 2.75 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(tgt::GLCanvas* canvas) 
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(canvas)
17
    {
18
        tgtAssert(canvas != 0, "Canvas must not be 0.");
schultezub's avatar
schultezub committed
19
        _data.s_dataAdded.connect(this, &VisualizationPipeline::onDataContainerDataAdded);
20
21
22
    }

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

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

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

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

    void VisualizationPipeline::init() {
44
        tgt::GLContextScopedLock lock(_canvas->getContext());
45
46
47
        AbstractPipeline::init();
    }

48
49
50
51
52
    void VisualizationPipeline::deinit() {
        tgt::GLContextScopedLock lock(_canvas->getContext());
        AbstractPipeline::deinit();
    }

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

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

schultezub's avatar
schultezub committed
63
64
    const ImageDataRenderTarget* VisualizationPipeline::getRenderTarget() const {
        return _data.getTypedData<ImageDataRenderTarget>(_renderTargetID.getValue());
65
66
    }

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

71
72
73
    void VisualizationPipeline::lockGLContextAndExecuteProcessor(AbstractProcessor& processor) {
        tgt::GLContextScopedLock lock(_canvas->getContext());
        executeProcessor(processor);
74
        glFlush();  // TODO: is glFlush enough or do we need a glFinish here?
75
76
    }

77
}