Starting from 2021-07-01, all LRZ GitLab users will be required to explicitly accept the GitLab Terms of Service. Please see the detailed information at https://doku.lrz.de/display/PUBLIC/GitLab and make sure that your projects conform to the requirements.

campvispainter.h 5.06 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.
// 
// ================================================================================================

schultezub's avatar
schultezub committed
30 31
#ifndef CAMPVISPAINTER_H__
#define CAMPVISPAINTER_H__
32

schultezub's avatar
schultezub committed
33
#include "sigslot/sigslot.h"
schultezub's avatar
schultezub committed
34 35
#include "tbb/atomic.h"
#include "tbb/compat/condition_variable"
36

schultezub's avatar
schultezub committed
37
#include "tgt/logmanager.h"
38 39
#include "tgt/painter.h"
#include "core/tools/runnable.h"
schultezub's avatar
schultezub committed
40 41 42

namespace tgt {
    class Shader;
43
    class QtThreadedCanvas;
schultezub's avatar
schultezub committed
44 45
}

schultezub's avatar
schultezub committed
46
namespace campvis {
schultezub's avatar
schultezub committed
47
    class VisualizationPipeline;
schultezub's avatar
schultezub committed
48 49

    /**
schultezub's avatar
schultezub committed
50
     * Painter class for CAMPVis, rendering the render target of a VisualizationPipeline.
51 52 53 54
     * This painter implements Runnable, hence, it runs in its own thread and the associated canvas
     * must be of type QtThreadedCanvas.
     * Rendering is implemented using condidional wait - hence the canvas is only updated when
     * \a pipeline emits the s_RenderTargetChanged signal.
schultezub's avatar
schultezub committed
55
     * 
56
     * \sa  Runnable, VisualizationPipeline
schultezub's avatar
schultezub committed
57
     */
58
    class CampVisPainter : public Runnable, public tgt::Painter, public sigslot::has_slots<> {
schultezub's avatar
schultezub committed
59
    public:
60
        /**
61
         * Creates a new CampVisPainter rendering the render target of \a pipeline on \a canvas.
62 63 64
         * \param   canvas      Canvas to render on
         * \param   pipeline    Pipeline to render
         */
65
        CampVisPainter(tgt::GLCanvas* canvas, VisualizationPipeline* pipeline);
schultezub's avatar
schultezub committed
66

67 68 69
        /**
         * Destructor, stops and waits for the rendering thread if it's still running.
         */
70
        virtual ~CampVisPainter();
71 72 73 74 75 76 77 78 79 80 81

        /// \see Runnable::stop
        void stop();
        
        /**
         * Performs the rendering using conditional wait.
         * \sa Runnable::run
         */
        void run();

        /**
82
         * Schedule a repaint job for the pipeline's render target
83
         */
84
        virtual void repaint();
85 86

        /// \see tgt::Painter::sizeChanged
87
        virtual void sizeChanged(const tgt::ivec2& size);
88 89 90 91

        /**
         * Initializes the painter, i.e. loads the OpenGL shader.
         */
schultezub's avatar
schultezub committed
92
        virtual void init();
93 94 95 96

        /**
         * Deinitializes the painter, i.e. disposes its shader.
         */
97
        virtual void deinit();
schultezub's avatar
schultezub committed
98

99 100 101 102 103 104 105 106 107 108
        /**
         * Sets the target canvas for rendering
         * \param   canvas  Canvas to render on, must be of type QtThreadedCanvas
         */
        virtual void setCanvas(tgt::GLCanvas* canvas);

        /**
         * Pipeline with the render target to render.
         * \param   pipeline    Pipeline to render
         */
schultezub's avatar
schultezub committed
109
        void setPipeline(VisualizationPipeline* pipeline);
110 111 112 113 114

        /**
         * Slot being notified when the pipeline's render target changed.
         */
        void onRenderTargetChanged();
schultezub's avatar
schultezub committed
115 116

    private:
117 118 119 120 121
        /**
         * Performs the actual rendering of the pipeline's render target
         */
        virtual void paint();

schultezub's avatar
schultezub committed
122
        static const std::string loggerCat_;
schultezub's avatar
schultezub committed
123

124
        VisualizationPipeline* _pipeline;                   ///< Pipeline to render
schultezub's avatar
schultezub committed
125
        tgt::Shader* _copyShader;                           ///< Shader for copying the render target to the framebuffer.
126 127
        tbb::atomic<bool> _dirty;                           ///< Flag whether render result is dirty and needs to be rerendered.
        std::condition_variable _renderCondition;           ///< conditional wait condition for rendering
schultezub's avatar
schultezub committed
128 129 130
    };

}
131

schultezub's avatar
schultezub committed
132
#endif // CAMPVISPAINTER_H__