visualizationpipeline.cpp 5.06 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
#include "core/tools/job.h"
#include "core/tools/opengljobprocessor.h"
36
37
38
39

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

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

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

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

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

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

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

77
78
79
80
    void VisualizationPipeline::deinit() {
        AbstractPipeline::deinit();
    }

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

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

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

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

99
    void VisualizationPipeline::lockGLContextAndExecuteProcessor(AbstractProcessor* processor) {
100
        tgtAssert(_canvas != 0, "Set a valid canvas before calling this method!");
101
102
103
104
105
        GLJobProc.enqueueJob(
            _canvas, 
            new CallMemberFunc1ArgJob<VisualizationPipeline, AbstractProcessor*>(this, &VisualizationPipeline::executeProcessor, processor),
            Normal);
        /*tgt::GLContextScopedLock lock(_canvas->getContext());
106
        executeProcessor(processor);
schultezub's avatar
schultezub committed
107
        glFinish();  // TODO: is glFlush enough or do we need a glFinish here?
108
        LGL_ERROR;*/
109
110
    }

111
112
113
114
    void VisualizationPipeline::setCanvas(tgt::GLCanvas* canvas) {
        _canvas = canvas;
    }

115
116
117
118
119
120
121
    void VisualizationPipeline::onPropertyChanged(const AbstractProperty* prop) {
        if (prop == &_renderTargetID)
            s_renderTargetChanged();
        else
            AbstractPipeline::onPropertyChanged(prop);
    }

122
}