autoevaluationpipeline.h 7.31 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 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 VISUALIZATIONPIPELINE_H__
#define VISUALIZATIONPIPELINE_H__

schultezub's avatar
schultezub committed
33
#include "sigslot/sigslot.h"
34
#include "tbb/concurrent_hash_map.h"
35

schultezub's avatar
schultezub committed
36
#include "tgt/vector.h"
37
#include "tgt/event/eventhandler.h"
38
#include "tgt/event/eventlistener.h"
39

40
#include "core/pipeline/abstractpipeline.h"
41
#include "core/properties/datanameproperty.h"
42
#include "core/properties/numericproperty.h"
43
44
45

#include <vector>

schultezub's avatar
schultezub committed
46
47
48
49
namespace tgt {
    class GLCanvas;
}

schultezub's avatar
schultezub committed
50
namespace campvis {
51
    /**
schultezub's avatar
schultezub committed
52
     * Abstract base class for CAMPVis Pipelines.
53
54
     * 
     */
55
    class AutoEvaluationPipeline : public AbstractPipeline, public tgt::EventHandler, public tgt::EventListener {
56
57
    public:
        /**
58
         * Creates a AutoEvaluationPipeline.
59
         */
60
        AutoEvaluationPipeline();
61
62
63
64

        /**
         * Virtual Destructor
         **/
65
        virtual ~AutoEvaluationPipeline();
66
67
68
69


        /**
         * Initializes the OpenGL context of the pipeline and its processors.
70
         * Must be called with a valid and locked OpenGL context.
71
72
73
74
         * \note    When overwriting this method, make sure to call the base class version first.
         */
        virtual void init();

75
76
        /**
         * Deinitializes this pipeline and all of its processors.
77
         * Must be called with a valid and locked OpenGL context.
78
79
80
81
         * \note    When overwriting this method, make sure to call the base class version first.
         */
        virtual void deinit();

82
        /**
83
84
85
86
87
88
89
         * 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.
         */
        void addProcessor(AbstractProcessor* processor);
90
91
92
93
94
95
96
97

        /**
         * 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);

98
99
100
101
102
103
        /**
         * Sets the Canvas hosting the OpenGL context for this pipeline.
         * \param   canvas  Canvas hosting the OpenGL context for this pipeline
         */
        void setCanvas(tgt::GLCanvas* canvas);

104
        /**
schultezub's avatar
schultezub committed
105
         * Sets the size of the render target
106
107
         * \param size  New viewport dimensions
         */
schultezub's avatar
schultezub committed
108
        void setRenderTargetSize(const tgt::ivec2& size);
109
110

        /**
schultezub's avatar
schultezub committed
111
         * Returns the viewport size of the target canvas
112
         * \return _canvasSize
113
         */
schultezub's avatar
schultezub committed
114
        const tgt::ivec2& getRenderTargetSize() const;
115
116

        /**
117
         * Returns the ID of the render target image to be rendered to the canvas
schultezub's avatar
schultezub committed
118
         * \return  The DataHandle named _renderTargetID in the pipeline's DataContainer, 0 if no such handle exists.
119
         */
120
        const std::string& getRenderTargetID() const;
121

122
123
124
125
126
127
128
129
        /**
         * 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);


schultezub's avatar
schultezub committed
130
131
132
133
        /// Signal emitted when the pipeline's render target has changed
        sigslot::signal0<> s_renderTargetChanged;

    protected:
schultezub's avatar
schultezub committed
134
        /**
schultezub's avatar
schultezub committed
135
         * Gets called when the data collection of this pipeline has changed and thus has notified its observers.
schultezub's avatar
schultezub committed
136
137
138
         * 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.
schultezub's avatar
schultezub committed
139
         */
140
        void onDataContainerDataAdded(const std::string& name, const DataHandle& dh);
schultezub's avatar
schultezub committed
141

142
143
144
145
146
147
        /**
         * Slot getting called when one of the observed properties changed and notifies its observers.
         * If \a prop equals _renderTargetID, the s_renderTargetChanged is emitted.
         * \param   prop    Property that emitted the signal
         */
        virtual void onPropertyChanged(const AbstractProperty* prop);
148
149
150
        
        /**
         * Slot getting called when one of the observed processors got invalidated.
151
         * The default behaviour is to dispatch a job to execute the invalidated processor and emit the s_invalidated signal.
152
153
154
         * \param   processor   The processor that emitted the signal
         */
        virtual void onProcessorInvalidated(AbstractProcessor* processor);
155

156
157
158
159
160
        /**
         * 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.
         */
161
        void lockGLContextAndExecuteProcessor(AbstractProcessor* processor);
162

163
164
        tbb::concurrent_hash_map<AbstractProcessor*, bool> _isVisProcessorMap;

165
        IVec2Property _canvasSize;                          ///< original canvas size
166
        bool _ignoreCanvasSizeUpdate;
167

168
        DataNameProperty _renderTargetID;                   ///< ID of the render target image to be rendered to the canvas
169

170
171
        tgt::GLCanvas* _canvas;                             ///< Canvas hosting the OpenGL context for this pipeline.

172
173
174
175
176
177
        static const std::string loggerCat_;
    };

}

#endif // VISUALIZATIONPIPELINE_H__