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

visualizationpipeline.cpp 4.86 KB
Newer Older
1
2
// ================================================================================================
// 
schultezub's avatar
schultezub committed
3
// This file is part of the CAMPVis Software Framework.
4
5
// 
// If not explicitly stated otherwise: Copyright (C) 2012, all rights reserved,
schultezub's avatar
schultezub committed
6
//      Christian Schulte zu Berge <christian.szb@in.tum.de>
7
8
9
//      Chair for Computer Aided Medical Procedures
//      Technische Universitt Mnchen
//      Boltzmannstr. 3, 85748 Garching b. Mnchen, Germany
schultezub's avatar
schultezub committed
10
// For a full list of authors and contributors, please refer to the file "AUTHORS.txt".
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
// 
// 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.
// 
// ================================================================================================

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

schultezub's avatar
schultezub committed
38
39
namespace campvis {
    const std::string VisualizationPipeline::loggerCat_ = "CAMPVis.core.datastructures.VisualizationPipeline";
40

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

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

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

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

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

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

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

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

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

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

96
    void VisualizationPipeline::lockGLContextAndExecuteProcessor(AbstractProcessor* processor) {
97
        tgtAssert(_canvas != 0, "Set a valid canvas before calling this method!");
98
99
100
        GLJobProc.enqueueJob(
            _canvas, 
            new CallMemberFunc1ArgJob<VisualizationPipeline, AbstractProcessor*>(this, &VisualizationPipeline::executeProcessor, processor),
101
            OpenGLJobProcessor::SerialJob);
102
103
    }

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

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

115
}