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.

campvisapplication.h 6.12 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 CAMPVISAPPLICATION_H__
#define CAMPVISAPPLICATION_H__
32

schultezub's avatar
schultezub committed
33 34
//#include <vld.h> // Uncomment this for using Visual Leak Detector

35
#include "sigslot/sigslot.h"
36
#include <QApplication>
37
#include <QDockWidget>
38 39 40 41 42 43 44
#include <utility>
#include <vector>

namespace tgt {
    class QtThreadedCanvas;
}

schultezub's avatar
schultezub committed
45
namespace campvis {
46
    class AbstractPipeline;
47
    class MainWindow;
48
    class CampVisPainter;
49 50 51
    class VisualizationPipeline;

    /**
52
     * The CampVisApplication class wraps Pipelines, Evaluators and Painters all together and takes
53 54 55
     * care about correctly handling all those instances.
     * 
     * Intended usage is:
56
     *  1. Create your CampVisApplication
schultezub's avatar
schultezub committed
57 58 59 60
     *  2. Add Pipelines and Visualizations as needed
     *  3. call init()
     *  4. call run()
     *  5. call deinit()
61
     *  6. You can now safely destroy your CampVisApplication
62
     */
Christian Schulte zu Berge's avatar
Christian Schulte zu Berge committed
63
    class CampVisApplication : public QApplication {
64 65
    friend class MainWindow;

66 67
    public:
        /**
68
         * Creates a new CampVisApplication.
69 70 71
         * \param   argc        number of passed arguments
         * \param   argv        vector of arguments
         * \param   useOpenCL   Flag, whether to use OpenCL (inits and deinits KissCL lib at the appropriate time).
72
         */
73
        CampVisApplication(int& argc, char** argv, bool useOpenCL = true);
74 75 76 77

        /**
         * Destructor, make sure to call deinit() first.
         */
78
        ~CampVisApplication();
79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102

        /**
         * Initializes tgt, OpenGL, and all pipelines, evaluators and painters.
         * Make sure to have everything setup before calling init().
         */
        void init();

        /**
         * Deinitializes tgt, OpenGL, and all pipelines, evaluators and painters.
         */
        void deinit();

        /**
         * Adds a pipeline which doesn't need visualization (OpenGL) support.
         * Each pipeline will automatically get its own evaluator.
         * 
         * \note    If you want to add a pipeline that needs a valid OpenGL context, use 
         *          addVisualizationPipeline() instead.
         * \param   pipeline    Pipeline to add, must not need OpenGL support.
         */
        void addPipeline(AbstractPipeline* pipeline);

        /**
         * Adds a visualization pipeline (i.e. a pipeline that needs a OpenGL context).
103 104
         * For each added pipeline, an OpenGL context will be created (for the evaluation 
         * and rendering).
105
         * 
schultezub's avatar
schultezub committed
106
         * \note    You do \b not need to call addPipeline.
107 108 109 110 111 112
         * \param   name    Name of the OpenGL context to create for the pipeline.
         * \param   vp      VisualizationPipeline to add.
         */
        void addVisualizationPipeline(const std::string& name, VisualizationPipeline* vp);

        /**
113 114 115 116 117 118 119 120 121
         * Adds a dock widget to the main window.
         * The dock widget will be automatically docked in the specified area.
         *
         * \param   area    Area of the main window to which the dock widget should be added.
         * \param   dock    The dock widget to add to the main window.
         */
        void registerDockWidget(Qt::DockWidgetArea area, QDockWidget* dock);

        /**
122 123 124 125 126 127
         * Runs the actual application.
         * Make sure to call init() before.
         * \return  0 on success.
         */
        int run();

schultezub's avatar
schultezub committed
128
        /// Signal emitted when the collection of pipelines has changed.
129 130
        sigslot::signal0<> s_PipelinesChanged;

131 132 133 134
    private:
        /// All pipelines (incuding VisualizationPipelines)
        std::vector<AbstractPipeline*> _pipelines;
        /// All visualisations (i.e. VisualizationPipelines with their corresponding painters/canvases)
135
        std::vector< std::pair<VisualizationPipeline*, CampVisPainter*> > _visualizations;
136 137 138

        /// A local OpenGL context used for initialization
        tgt::QtThreadedCanvas* _localContext;
139 140
        /// Main window hosting GUI stuff
        MainWindow* _mainWindow;
141

142
        /// Flag, whether CampVisApplication was correctly initialized
143 144
        bool _initialized;

145 146 147
        /// Flag, whether to use OpenCL (inits and deinits KissCL lib at the appropriate time).
        bool _useOpenCL;

148 149
        int _argc;
        char** _argv;
150 151

        static const std::string loggerCat_;
152 153 154
    };
}

schultezub's avatar
schultezub committed
155
#endif // CAMPVISAPPLICATION_H__