visualizationpipeline.h 8.27 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"
schultezub's avatar
schultezub committed
35
#include "tgt/vector.h"
36 37 38
#include "tgt/event/eventlistener.h"
#include "core/eventhandlers/abstracteventhandler.h"
#include "core/pipeline/abstractpipeline.h"
39
#include "core/properties/numericproperty.h"
40 41 42

#include <vector>

schultezub's avatar
schultezub committed
43 44 45 46
namespace tgt {
    class GLCanvas;
}

schultezub's avatar
schultezub committed
47
namespace campvis {
48
    class ImageRepresentationRenderTarget;
49 50

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

        /**
         * Virtual Destructor
         **/
        virtual ~VisualizationPipeline();


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

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

81
        /**
82 83 84 85 86 87 88
         * 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);
89 90 91 92 93 94 95 96

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

97 98 99 100 101 102
        /**
         * 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);

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

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

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

121 122 123 124 125 126
        /**
         * Adds the event handler \a eventHandler to this pipeline's list of event handlers.
         * \param   eventHandler    The event handler to add.
         */
        void addEventHandler(AbstractEventHandler* eventHandler);

127 128 129 130 131 132 133 134 135 136 137 138 139 140
        /**
         * Enables low quality mode, which effectively reduces the render target size by factor 4.
         * \note    Do not forget to call disableLowQualityMode().
         * \sa      disableLowQualityMode()
         */
        void enableLowQualityMode();

        /**
         * Disables low quality mode, which effectively resets the render target size to its original value;
         * \note    Do not forget to call disableLowQualityMode().
         * \sa      disableLowQualityMode()
         */
        void disableLowQualityMode();

schultezub's avatar
schultezub committed
141 142 143 144
        /// Signal emitted when the pipeline's render target has changed
        sigslot::signal0<> s_renderTargetChanged;

    protected:
schultezub's avatar
schultezub committed
145
        /**
schultezub's avatar
schultezub committed
146
         * Gets called when the data collection of this pipeline has changed and thus has notified its observers.
schultezub's avatar
schultezub committed
147 148 149
         * 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
150
         */
151
        void onDataContainerDataAdded(const std::string& name, const DataHandle& dh);
schultezub's avatar
schultezub committed
152

153 154 155 156 157 158
        /**
         * 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);
159 160 161 162 163 164 165
        
        /**
         * Slot getting called when one of the observed processors got invalidated.
         * The default behaviour is just to set the invalidation level to invalid.
         * \param   processor   The processor that emitted the signal
         */
        virtual void onProcessorInvalidated(AbstractProcessor* processor);
166

167 168 169 170 171
        /**
         * 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.
         */
172
        void lockGLContextAndExecuteProcessor(AbstractProcessor* processor);
173

174 175 176 177 178
        /**
         * Updates the _effectiveRenderTargetSize property considering LQ mode.
         */
        void updateEffectiveRenderTargetSize();

179 180
        tbb::concurrent_hash_map<AbstractProcessor*, bool> _isVisProcessorMap;

181
        IVec2Property _canvasSize;                              ///< original canvas size
182
        bool _lqMode;                                           ///< Flag whether low quality mode is enables
183
        bool _ignoreCanvasSizeUpdate;
184

185
        IVec2Property _effectiveRenderTargetSize;               ///< actual size of the render targets (considering LQ mode)
186 187
        StringProperty _renderTargetID;                         ///< ID of the render target image to be rendered to the canvas

188 189
        std::vector<AbstractEventHandler*> _eventHandlers;  ///< List of registered event handlers for the pipeline

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

192 193 194 195 196 197
        static const std::string loggerCat_;
    };

}

#endif // VISUALIZATIONPIPELINE_H__