visualizationpipeline.cpp 4.77 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
// ================================================================================================
// 
// This file is part of the TUMVis Visualization Framework.
// 
// If not explicitly stated otherwise: Copyright (C) 2012, all rights reserved,
//      Christian Schulte zu Berge (christian.szb@in.tum.de)
//      Chair for Computer Aided Medical Procedures
//      Technische Universitt Mnchen
//      Boltzmannstr. 3, 85748 Garching b. Mnchen, Germany
// 
// The licensing of this softare is not yet resolved. Until then, redistribution in source or
// binary forms outside the CAMP chair is not permitted, unless explicitly stated in legal form.
// However, the names of the original authors and the above copyright notice must retain in its
// original state in any case.
// 
// Legal disclaimer provided by the BSD license:
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR
// IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY 
// AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR 
// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 
// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 
// OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
// 
// ================================================================================================

29
#include "visualizationpipeline.h"
schultezub's avatar
schultezub committed
30
#include "tgt/tgt_gl.h"
schultezub's avatar
schultezub committed
31
#include "tgt/glcanvas.h"
32
#include "tgt/glcontext.h"
schultezub's avatar
schultezub committed
33
#include "core/datastructures/imagedatarendertarget.h"
34
35
36
37

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

38
    VisualizationPipeline::VisualizationPipeline() 
schultezub's avatar
schultezub committed
39
        : AbstractPipeline()
schultezub's avatar
schultezub committed
40
41
        , tgt::EventListener()
        , _renderTargetSize("canvasSize", "Canvas Size", tgt::ivec2(128, 128))
schultezub's avatar
schultezub committed
42
        , _renderTargetID("renderTargetID", "Render Target ID", "VisualizationPipeline.renderTarget")
43
        , _canvas(0)
44
    {
schultezub's avatar
schultezub committed
45
        _data.s_dataAdded.connect(this, &VisualizationPipeline::onDataContainerDataAdded);
46
47
        addProperty(&_renderTargetID);
        _renderTargetID.s_changed.connect<VisualizationPipeline>(this, &VisualizationPipeline::onPropertyChanged);
48
49
50
    }

    VisualizationPipeline::~VisualizationPipeline() {
schultezub's avatar
schultezub committed
51
        _data.s_dataAdded.disconnect(this);
52
53
54
55
    }

    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
56
        for (std::vector<AbstractEventHandler*>::iterator it = _eventHandlers.begin(); it != _eventHandlers.end() && e->isAccepted(); ++it) {
57
58
59
60
            if ((*it)->accept(e)) {
                (*it)->execute(e);
            }
        }
schultezub's avatar
schultezub committed
61
62
63
64

        if (e->isAccepted()) {
            EventListener::onEvent(e);
        }
65
66
67
68
69
70
71
72
73
74
    }

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

    void VisualizationPipeline::init() {
        AbstractPipeline::init();
    }

75
76
77
78
    void VisualizationPipeline::deinit() {
        AbstractPipeline::deinit();
    }

schultezub's avatar
schultezub committed
79
80
81
    const tgt::ivec2& VisualizationPipeline::getRenderTargetSize() const {
        return _renderTargetSize.getValue();
    }
schultezub's avatar
schultezub committed
82

schultezub's avatar
schultezub committed
83
84
85
    void VisualizationPipeline::onDataContainerDataAdded(const std::string& name, const DataHandle* dh) {
        if (name == _renderTargetID.getValue()) {
            s_renderTargetChanged();
schultezub's avatar
schultezub committed
86
        }
87
88
    }

89
90
    const std::string& VisualizationPipeline::getRenderTargetID() const {
        return _renderTargetID.getValue();
91
92
    }

schultezub's avatar
schultezub committed
93
94
    void VisualizationPipeline::setRenderTargetSize(const tgt::ivec2& size) {
        _renderTargetSize.setValue(size);
schultezub's avatar
schultezub committed
95
96
    }

97
    void VisualizationPipeline::lockGLContextAndExecuteProcessor(AbstractProcessor& processor) {
98
        tgtAssert(_canvas != 0, "Set a valid canvas before calling this method!");
99
100
        tgt::GLContextScopedLock lock(_canvas->getContext());
        executeProcessor(processor);
schultezub's avatar
schultezub committed
101
102
        glFinish();  // TODO: is glFlush enough or do we need a glFinish here?
        LGL_ERROR;
103
104
    }

105
106
107
108
    void VisualizationPipeline::setCanvas(tgt::GLCanvas* canvas) {
        _canvas = canvas;
    }

109
110
111
112
113
114
115
    void VisualizationPipeline::onPropertyChanged(const AbstractProperty* prop) {
        if (prop == &_renderTargetID)
            s_renderTargetChanged();
        else
            AbstractPipeline::onPropertyChanged(prop);
    }

116
}