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

autoevaluationpipeline.cpp 9.11 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 "autoevaluationpipeline.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"
34
#include "core/pipeline/visualizationprocessor.h"
35
36
#include "core/tools/job.h"
#include "core/tools/opengljobprocessor.h"
37
#include "core/tools/simplejobprocessor.h"
38

39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
namespace {
    GLboolean getGlBool(GLenum param) {
        GLboolean toReturn;
        glGetBooleanv(param, &toReturn);
        return toReturn;
    };

    GLint getGlInt(GLenum param) {
        GLint toReturn;
        glGetIntegerv(param, &toReturn);
        return toReturn;
    };

    GLfloat getGlFloat(GLenum param) {
        GLfloat toReturn;
        glGetFloatv(param, &toReturn);
        return toReturn;
    }
}

schultezub's avatar
schultezub committed
59
namespace campvis {
60
    const std::string AutoEvaluationPipeline::loggerCat_ = "CAMPVis.core.datastructures.AutoEvaluationPipeline";
61

62
    AutoEvaluationPipeline::AutoEvaluationPipeline() 
schultezub's avatar
schultezub committed
63
        : AbstractPipeline()
64
        , tgt::EventHandler()
schultezub's avatar
schultezub committed
65
        , tgt::EventListener()
66
        , _ignoreCanvasSizeUpdate(false)
67
        , _canvasSize("CanvasSize", "Canvas Size", tgt::ivec2(128, 128), tgt::ivec2(1, 1), tgt::ivec2(4096, 4096))
68
        , _renderTargetID("renderTargetID", "Render Target ID", "AutoEvaluationPipeline.renderTarget", DataNameProperty::READ)
69
        , _canvas(0)
70
    {
71
        _data.s_dataAdded.connect(this, &AutoEvaluationPipeline::onDataContainerDataAdded);
72
        addProperty(&_renderTargetID);
73
        addProperty(&_canvasSize);
74
        _renderTargetID.s_changed.connect<AutoEvaluationPipeline>(this, &AutoEvaluationPipeline::onPropertyChanged);
75
76
    }

77
    AutoEvaluationPipeline::~AutoEvaluationPipeline() {
78
79
    }

80
    void AutoEvaluationPipeline::onEvent(tgt::Event* e) {
81
82
83
84
85
86
87
        // copy and paste from tgt::EventHandler::onEvent() but without deleting e
        for (size_t i = 0 ; i < listeners_.size() ; ++i) {
            // check if current listener listens to the eventType of e
            if(listeners_[i]->getEventTypes() & e->getEventType() ){
                listeners_[i]->onEvent(e);
                if (e->isAccepted())
                    break;
88
89
90
91
            }
        }
    }

92
    void AutoEvaluationPipeline::init() {
93
94
95
        AbstractPipeline::init();
    }

96
    void AutoEvaluationPipeline::deinit() {
97
98
99
        _data.s_dataAdded.disconnect(this);
        _renderTargetID.s_changed.disconnect(this);
	
100
101
102
        AbstractPipeline::deinit();
    }

103
    const tgt::ivec2& AutoEvaluationPipeline::getRenderTargetSize() const {
104
        return _canvasSize.getValue();
105
106
    }

107
    void AutoEvaluationPipeline::setRenderTargetSize(const tgt::ivec2& size) {
108
        if (_canvasSize.getValue() != size && !_ignoreCanvasSizeUpdate) {
109
            _canvasSize.setValue(size);
110
        }
schultezub's avatar
schultezub committed
111
    }
schultezub's avatar
schultezub committed
112

113
    void AutoEvaluationPipeline::onDataContainerDataAdded(const std::string& name, const DataHandle& dh) {
schultezub's avatar
schultezub committed
114
115
        if (name == _renderTargetID.getValue()) {
            s_renderTargetChanged();
schultezub's avatar
schultezub committed
116
        }
117
118
    }

119
    const std::string& AutoEvaluationPipeline::getRenderTargetID() const {
120
        return _renderTargetID.getValue();
121
122
    }

123
    void AutoEvaluationPipeline::lockGLContextAndExecuteProcessor(AbstractProcessor* processor) {
124
        tgtAssert(_canvas != 0, "Set a valid canvas before calling this method!");
125
126
        GLJobProc.enqueueJob(
            _canvas, 
127
            makeJobOnHeap<AutoEvaluationPipeline, AbstractProcessor*, bool>(this, &AutoEvaluationPipeline::executeProcessor, processor, true),
128
            OpenGLJobProcessor::SerialJob);
129
130
    }

131
    void AutoEvaluationPipeline::setCanvas(tgt::GLCanvas* canvas) {
132
133
134
        _canvas = canvas;
    }

135
    void AutoEvaluationPipeline::onPropertyChanged(const AbstractProperty* prop) {
136
137
        if (prop == &_renderTargetID)
            s_renderTargetChanged();
138
139
140
        else if (prop == &_canvasSize && _canvas != 0 && !_ignoreCanvasSizeUpdate) {
            if (_canvasSize.getValue() != _canvas->getSize()) {
                _ignoreCanvasSizeUpdate = true;
141
                _canvas->setSize(_canvasSize.getValue());
142
143
                _ignoreCanvasSizeUpdate = false;
            }
144
        }
145
146
147
148
        else
            AbstractPipeline::onPropertyChanged(prop);
    }

149
    void AutoEvaluationPipeline::onProcessorInvalidated(AbstractProcessor* processor) {
150
151
152
153
154
155
156
157
158
        if (_canvas == 0)
            return;

        tbb::concurrent_hash_map<AbstractProcessor*, bool>::const_accessor a;
        if (_isVisProcessorMap.find(a, processor)) {
            if (a->second) {
                // is VisualizationProcessor
                GLJobProc.enqueueJob(
                    _canvas, 
159
                    makeJobOnHeap<AutoEvaluationPipeline, AbstractProcessor*>(this, &AutoEvaluationPipeline::executeProcessorAndCheckOpenGLState, processor), 
160
161
162
                    OpenGLJobProcessor::SerialJob);
            }
            else {
163
                SimpleJobProc.enqueueJob(makeJob<AutoEvaluationPipeline, AbstractProcessor*, bool>(this, &AutoEvaluationPipeline::executeProcessor, processor, false));
164
165
166
167
168
169
170
171
            }
        }
        else {
            tgtAssert(false, "Could not find processor in processor map.");
            LWARNING("Caught invalidation of a non-registered processor!");
        }
    }

172
    void AutoEvaluationPipeline::addProcessor(AbstractProcessor* processor) {
173
174
175
        _isVisProcessorMap.insert(std::make_pair(processor, (dynamic_cast<VisualizationProcessor*>(processor) != 0)));
        AbstractPipeline::addProcessor(processor);
    }
176
    
177
    void AutoEvaluationPipeline::executeProcessorAndCheckOpenGLState(AbstractProcessor* processor) {
178
        AbstractPipeline::executeProcessor(processor, true);
179
180

#ifdef CAMPVIS_DEBUG
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
        tgtAssert(getGlBool(GL_DEPTH_TEST) == false, "Invalid OpenGL state after processor execution, GL_DEPTH_TEST != false.");
        tgtAssert(getGlBool(GL_SCISSOR_TEST) == false, "Invalid OpenGL state after processor execution, GL_SCISSOR_TEST != false.");

        tgtAssert(getGlInt(GL_CULL_FACE_MODE) == GL_BACK, "Invalid OpenGL state after processor execution, GL_CULL_FACE_MODE != GL_BACk.");
        tgtAssert(getGlInt(GL_DEPTH_FUNC) == GL_LESS, "Invalid OpenGL state after processor execution, GL_DEPTH_FUNC != GL_LESS.");

        tgtAssert(getGlFloat(GL_DEPTH_CLEAR_VALUE) == 1.f, "Invalid OpenGL state after processor execution, GL_DEPTH_CLEAR_VALUE != 1.f.");

        tgtAssert(getGlFloat(GL_RED_SCALE) == 1.f, "Invalid OpenGL state after processor execution, GL_RED_SCALE != 1.f.");
        tgtAssert(getGlFloat(GL_GREEN_SCALE) == 1.f, "Invalid OpenGL state after processor execution, GL_GREEN_SCALE != 1.f.");
        tgtAssert(getGlFloat(GL_BLUE_SCALE) == 1.f, "Invalid OpenGL state after processor execution, GL_BLUE_SCALE != 1.f.");
        tgtAssert(getGlFloat(GL_ALPHA_SCALE) == 1.f, "Invalid OpenGL state after processor execution, GL_ALPHA_SCALE != 1.f.");

        tgtAssert(getGlFloat(GL_RED_BIAS) == 0.f, "Invalid OpenGL state after processor execution, GL_RED_BIAS != 0.f.");
        tgtAssert(getGlFloat(GL_GREEN_BIAS) == 0.f, "Invalid OpenGL state after processor execution, GL_GREEN_BIAS != 0.f.");
        tgtAssert(getGlFloat(GL_BLUE_BIAS) == 0.f, "Invalid OpenGL state after processor execution, GL_BLUE_BIAS != 0.f.");
        tgtAssert(getGlFloat(GL_ALPHA_BIAS) == 0.f, "Invalid OpenGL state after processor execution, GL_ALPHA_BIAS != 0.f.");
198
199
#endif
    }
200

201
}