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

abstractpipeline.h 8.98 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-2014, all rights reserved,
schultezub's avatar
schultezub committed
6
//      Christian Schulte zu Berge <christian.szb@in.tum.de>
7
//      Chair for Computer Aided Medical Procedures
8
9
//      Technische Universitaet Muenchen
//      Boltzmannstr. 3, 85748 Garching b. Muenchen, Germany
10
// 
schultezub's avatar
schultezub committed
11
// For a full list of authors and contributors, please refer to the file "AUTHORS.txt".
12
// 
13
14
15
16
// Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file 
// except in compliance with the License. You may obtain a copy of the License at
// 
// http://www.apache.org/licenses/LICENSE-2.0
17
// 
18
19
20
21
// Unless required by applicable law or agreed to in writing, software distributed under the 
// License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, 
// either express or implied. See the License for the specific language governing permissions 
// and limitations under the License.
22
23
24
// 
// ================================================================================================

25
26
27
#ifndef ABSTRACTPIPELINE_H__
#define ABSTRACTPIPELINE_H__

28
#include "sigslot/sigslot.h"
29

30
#include "tgt/logmanager.h"
31
32
33
34
#include "tgt/vector.h"
#include "tgt/event/eventhandler.h"
#include "tgt/event/eventlistener.h"

35
36
#include <tbb/spin_mutex.h>
#include <tbb/mutex.h>
37

38
#include "core/coreapi.h"
39
#include "core/datastructures/datacontainer.h"
40
41
#include "core/properties/datanameproperty.h"
#include "core/properties/floatingpointproperty.h"
schultezub's avatar
schultezub committed
42
#include "core/properties/propertycollection.h"
43

44
#include <map>
45
46
#include <vector>

47
48
49
50
namespace tgt {
    class GLCanvas;
}

schultezub's avatar
schultezub committed
51
namespace campvis {
schultezub's avatar
schultezub committed
52
53
    class AbstractProcessor;

54
    /**
schultezub's avatar
schultezub committed
55
     * Abstract base class for CAMPVis Pipelines.
56
     */
57
    class CAMPVIS_CORE_API AbstractPipeline : public HasPropertyCollection, public tgt::EventHandler, public tgt::EventListener {
58
59
60
    public:
        /**
         * Creates a AbstractPipeline.
61
62
         * If you derive from AbstractPipeline, you will have to implement the pipeline evaluation
         * logic yourself. You might want to have a look at AutoEvaluationPipeline.
63
64
65
         * 
         * \param   dc  Pointer to the DataContainer containing local working set of data for this 
         *              pipeline, must not be 0, must be valid the whole lifetime of this pipeline.
66
         */
67
        AbstractPipeline(DataContainer* dc);
68
69
70
71
72

        /**
         * Virtual Destructor
         **/
        virtual ~AbstractPipeline();
73
74
75
76
77
78
        
        /**
         * Gets the name of this very pipeline. To be defined by every subclass.
         * \return  The name of this pipeline.
         */
        virtual const std::string getName() const = 0;
79
80
81


        /**
82
83
84
         * Initializes this pipeline, its OpenGL context  and all of its processors.
         * Everything that requires a valid OpenGL context, valid construction of all other 
         * processors/properties or is otherwise expensive gets in here.
85
         * 
86
         * \note    Must be called with a valid and locked OpenGL context.
87
         * \note    When overwriting this method, make sure to call the base class version first.
88
         */
89
        virtual void init();
90

91
        /**
92
93
94
95
96
         * Deinitializes this pipeline, its OpenGL context and all of its processors.
         * Everything that requires a valid OpenGL context, cannont be executed during destruction
         * or is otherwise expensive gets in here.
         * 
         * \note    Must be called with a valid and locked OpenGL context.
97
98
99
         * \note    When overwriting this method, make sure to call the base class version first.
         */
        virtual void deinit();
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
        
        /**
         * Adds the processor \a processor to this pipeline's processor list.
         * \note    The s_invalidated signal of each processor on this list will be automatically 
         *          connected to onProcessorInvalidated() during initialization and disconnected
         *          during deinitialization.
         * \param   processor   The processor to add.
         */
        virtual void addProcessor(AbstractProcessor* processor);
                
        /**
         * Performs the event handling for the assigned canvas.
         * Default behaviour is to execute all assigned EventHandlers, may be overwritten by subclasses.
         * \param e     event parameters
         */
        virtual void onEvent(tgt::Event* e);

117

schultezub's avatar
schultezub committed
118
        /**
119
         * Returns the DataContainer of this pipeline, const version.
schultezub's avatar
schultezub committed
120
121
122
         * \return _data
         */
        const DataContainer& getDataContainer() const;
123

124
125
126
127
128
129
        /**
         * Returns the DataContainer of this pipeline, non-const version.
         * \return _data
         */
        DataContainer& getDataContainer();

130
131
132
133
134
135
        /**
         * Returns the list of processors of this pipeline.
         * \return  _processors
         */
        const std::vector<AbstractProcessor*>& getProcessors() const;

136
137
138
139
140
141
142
143
144
145
146
147
        /**
         * Gets the flag whether this pipeline is currently enabled.
         * \return _enabled
         */
        bool getEnabled() const;

        /**
         * Sets the flag whether this pipeline is currently enabled.
         * \param   enabled     New flag whether this pipeline is currently enabled.
         */
        void setEnabled(bool enabled);

148
        /**
149
150
         * Sets the Canvas hosting the OpenGL context for this pipeline.
         * \param   canvas  Canvas hosting the OpenGL context for this pipeline
151
         */
152
        void setCanvas(tgt::GLCanvas* canvas);
153
154

        /**
155
156
         * Sets the size of the render target
         * \param size  New viewport dimensions
157
         */
158
        void setRenderTargetSize(const tgt::ivec2& size);
159

schultezub's avatar
schultezub committed
160
        /**
161
162
         * Returns the viewport size of the target canvas
         * \return _canvasSize
schultezub's avatar
schultezub committed
163
         */
164
        const tgt::ivec2& getRenderTargetSize() const;
schultezub's avatar
schultezub committed
165
166

        /**
167
168
         * Returns the ID of the render target image to be rendered to the canvas
         * \return  The DataHandle named _renderTargetID in the pipeline's DataContainer, 0 if no such handle exists.
schultezub's avatar
schultezub committed
169
         */
170
171
172
173
        const std::string& getRenderTargetID() const;


        /// Signal emitted when the pipeline's render target has changed
174
        sigslot::signal0 s_renderTargetChanged;
175
176

    protected:
177
178
179
180
        /**
         * Executes the processor \a processor on the pipeline's data and locks its properties meanwhile.
         * \param   processor   Processor to execute.
         */
181
        void executeProcessor(AbstractProcessor* processor);
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
        
        /**
         * Acquires and locks the OpenGL context, executes the processor \a processor on the pipeline's data 
         * and locks its properties meanwhile.
         * \param   processor   Processor to execute.
         */
        void lockGLContextAndExecuteProcessor(AbstractProcessor* processor);
        
        /**
         * Executes \a processor and afterwards checks the OpenGL state to be valid.
         * \note    Only call from with a valid OpenGL context
         * \param   processor   Processor to execute
         */
        void executeProcessorAndCheckOpenGLState(AbstractProcessor* processor);

        /**
         * Slot getting called when one of the observed properties changed and notifies its observers.
         * The default behaviour is just to set the invalidation level to invalid.
         * \param   prop    Property that emitted the signal
         */
        virtual void onPropertyChanged(const AbstractProperty* prop);
203

204
205
206
207
208
209
        /**
         * Gets called when the data collection of this pipeline has changed and thus has notified its observers.
         * If \a name equals the name of the renderTarget, the s_renderTargetChanged signal will be emitted.
         * \param   name    Name of the added data.
         * \param   dh      DataHandle to the newly added data.
         */
210
        virtual void onDataContainerDataAdded(const std::string& name, DataHandle dh);
211

212
213
        /// Pointer to the DataContainer containing local working set of data for this Pipeline, must not be 0.
        DataContainer* _data;
214

215
        std::vector<AbstractProcessor*> _processors;        ///< List of all processors of this pipeline
216
        tbb::atomic<bool> _enabled;                         ///< flag whether this pipeline is currently enabled
schultezub's avatar
schultezub committed
217

218
219
220
221
222
        tgt::GLCanvas* _canvas;                             ///< Canvas hosting the OpenGL context for this pipeline.
        IVec2Property _canvasSize;                          ///< original canvas size
        bool _ignoreCanvasSizeUpdate;

        DataNameProperty _renderTargetID;                   ///< ID of the render target image to be rendered to the canvas
223
224

        static const std::string loggerCat_;
225

226
227
228
229
230
231
    };

}


#endif // ABSTRACTPIPELINE_H__