abstractpipeline.h 9.87 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
//      Chair for Computer Aided Medical Procedures
8
9
//      Technische Universität München
//      Boltzmannstr. 3, 85748 Garching b. München, 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
31
32
#ifndef ABSTRACTPIPELINE_H__
#define ABSTRACTPIPELINE_H__

33
#include "sigslot/sigslot.h"
34

35
#include "tgt/logmanager.h"
36
37
38
39
#include "tgt/vector.h"
#include "tgt/event/eventhandler.h"
#include "tgt/event/eventlistener.h"

40
41
#include <tbb/spin_mutex.h>
#include <tbb/mutex.h>
42

43
#include "core/datastructures/datacontainer.h"
44
45
#include "core/properties/datanameproperty.h"
#include "core/properties/floatingpointproperty.h"
schultezub's avatar
schultezub committed
46
#include "core/properties/propertycollection.h"
47

48
#include <map>
49
50
#include <vector>

51
52
53
54
namespace tgt {
    class GLCanvas;
}

schultezub's avatar
schultezub committed
55
namespace campvis {
schultezub's avatar
schultezub committed
56
57
    class AbstractProcessor;

58
    /**
schultezub's avatar
schultezub committed
59
     * Abstract base class for CAMPVis Pipelines.
60
     */
61
    class AbstractPipeline : public HasPropertyCollection, public tgt::EventHandler, public tgt::EventListener {
62
63
64
    public:
        /**
         * Creates a AbstractPipeline.
65
66
         * If you derive from AbstractPipeline, you will have to implement the pipeline evaluation
         * logic yourself. You might want to have a look at AutoEvaluationPipeline.
67
68
69
         * 
         * \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.
70
         */
71
        AbstractPipeline(DataContainer* dc);
72
73
74
75
76

        /**
         * Virtual Destructor
         **/
        virtual ~AbstractPipeline();
77
78
79
80
81
82
        
        /**
         * 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;
83
84
85


        /**
86
87
88
         * 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.
89
         * 
90
         * \note    Must be called with a valid and locked OpenGL context.
91
         * \note    When overwriting this method, make sure to call the base class version first.
92
         */
93
        virtual void init();
94

95
        /**
96
97
98
99
100
         * 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.
101
102
103
         * \note    When overwriting this method, make sure to call the base class version first.
         */
        virtual void deinit();
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
        
        /**
         * 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);

121

schultezub's avatar
schultezub committed
122
        /**
123
         * Returns the DataContainer of this pipeline, const version.
schultezub's avatar
schultezub committed
124
125
126
         * \return _data
         */
        const DataContainer& getDataContainer() const;
127

128
129
130
131
132
133
        /**
         * Returns the DataContainer of this pipeline, non-const version.
         * \return _data
         */
        DataContainer& getDataContainer();

134
135
136
137
138
139
        /**
         * Returns the list of processors of this pipeline.
         * \return  _processors
         */
        const std::vector<AbstractProcessor*>& getProcessors() const;

140
141
142
143
144
145
146
147
148
149
150
151
        /**
         * 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);

152
        /**
153
154
         * Sets the Canvas hosting the OpenGL context for this pipeline.
         * \param   canvas  Canvas hosting the OpenGL context for this pipeline
155
         */
156
        void setCanvas(tgt::GLCanvas* canvas);
157
158

        /**
159
160
         * Sets the size of the render target
         * \param size  New viewport dimensions
161
         */
162
        void setRenderTargetSize(const tgt::ivec2& size);
163

schultezub's avatar
schultezub committed
164
        /**
165
166
         * Returns the viewport size of the target canvas
         * \return _canvasSize
schultezub's avatar
schultezub committed
167
         */
168
        const tgt::ivec2& getRenderTargetSize() const;
schultezub's avatar
schultezub committed
169
170

        /**
171
172
         * 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
173
         */
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
        const std::string& getRenderTargetID() const;


        /// Signal emitted when the pipeline's render target has changed
        sigslot::signal0<> s_renderTargetChanged;

    protected:
        /**
         * Locks all processors.
         */
        void lockAllProcessors();

        /**
         * Unlocks all processors.
         */
        void unlockAllProcessors();
schultezub's avatar
schultezub committed
190

191
192
193
        /**
         * Executes the processor \a processor on the pipeline's data and locks its properties meanwhile.
         * \param   processor   Processor to execute.
194
         * \param   unlockInExtraThred  If true, the call to processor->unlock() will be done in an extra thread.
195
         */
196
        void executeProcessor(AbstractProcessor* processor, bool unlockInExtraThred);
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
        
        /**
         * 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);
218

219
220
221
222
223
224
225
        /**
         * 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.
         */
        virtual void onDataContainerDataAdded(const std::string& name, const DataHandle& dh);
226

227
228
        /// Pointer to the DataContainer containing local working set of data for this Pipeline, must not be 0.
        DataContainer* _data;
229

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

233
234
235
236
237
        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
238
239

        static const std::string loggerCat_;
240

241
242
243
244
245
246
    };

}


#endif // ABSTRACTPIPELINE_H__