campvisapplication.h 6.41 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-2015, 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 Universitaet Muenchen
//      Boltzmannstr. 3, 85748 Garching b. Muenchen, Germany
10
// 
schultezub's avatar
schultezub committed
11
// For a full list of authors and contributors, please refer to the file "AUTHORS.txt".
12
// 
13 14 15 16
// Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file 
// except in compliance with the License. You may obtain a copy of the License at
// 
// http://www.apache.org/licenses/LICENSE-2.0
17
// 
18 19 20 21
// Unless required by applicable law or agreed to in writing, software distributed under the 
// License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, 
// either express or implied. See the License for the specific language governing permissions 
// and limitations under the License.
22 23 24
// 
// ================================================================================================

schultezub's avatar
schultezub committed
25 26
#ifndef CAMPVISAPPLICATION_H__
#define CAMPVISAPPLICATION_H__
27

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

30
#include "sigslot/sigslot.h"
31
#include <QApplication>
32
#include <QDockWidget>
33 34 35
#include <utility>
#include <vector>

36
#include "core/datastructures/datacontainer.h"
37
#include "application/applicationapi.h"
CAMP C++ Builder's avatar
CAMP C++ Builder committed
38

39
namespace cgt {
40
    class GLCanvas;
41
    class QtCanvas;
42
    class QtThreadedCanvas;
43
    class Texture;
44 45
}

schultezub's avatar
schultezub committed
46
namespace campvis {
47
    class AbstractPipeline;
48
    class AbstractWorkflow;
49
    class MainWindow;
CAMP C++ Builder's avatar
CAMP C++ Builder committed
50
    class MdiDockableWindow;
51
    class LuaVmState;
52 53

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

68 69
    public:
        /**
70
         * Creates a new CampVisApplication.
71 72
         * \param   argc        number of passed arguments
         * \param   argv        vector of arguments
73
         */
74
        CampVisApplication(int& argc, char** argv);
75 76 77 78

        /**
         * Destructor, make sure to call deinit() first.
         */
79
        ~CampVisApplication();
80 81

        /**
82
         * Initializes cgt, OpenGL, and all pipelines, evaluators and painters.
83 84 85 86 87
         * Make sure to have everything setup before calling init().
         */
        void init();

        /**
88
         * Deinitializes cgt, OpenGL, and all pipelines, evaluators and painters.
89 90 91 92
         */
        void deinit();

        /**
93 94 95
         * Adds a pipeline to this CAMPVis application.
         * Each pipeline will automatically get its own OpenGL context, the corresponding CampvisPainter
         * and all necessary connections will be created.
96
         * 
97
         * \param   vp      AbstractPipeline to add.
98
         */
99
        void addPipeline(AbstractPipeline* pipeline);
100 101

        /**
102 103 104 105 106 107 108 109 110
         * 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);

        /**
111 112 113 114 115 116
         * Runs the actual application.
         * Make sure to call init() before.
         * \return  0 on success.
         */
        int run();

117

118 119 120 121 122
        /**
         * Creates a new DataContainer with the given name.
         * \param   name    Name of the new DataContainer
         * \return  The newly created DataContainer
         */
123
        DataContainer* createAndAddDataContainer(const std::string& name);
124

125 126 127 128 129
        /**
         * Reloads all GLSL shaders from file and rebuilds them.
         */
        void rebuildAllShadersFromFiles();

130

131 132 133 134 135 136 137 138
        /**
         * Sets the visibility of the given pipeline's canvas to \a visibility.
         * \param   pipeline    Pipeline whose canvas' visibility should be changed.
         * \param   visibility  New visibility of the canvas.
         */
        void setPipelineVisibility(AbstractPipeline* pipeline, bool visibility);


139 140 141 142 143 144 145 146
#ifdef CAMPVIS_HAS_SCRIPTING
        /**
         * Returns the global LuaVmState of this application.
         */
        LuaVmState* getLuaVmState();
#endif


schultezub's avatar
schultezub committed
147
        /// Signal emitted when the collection of pipelines has changed.
148
        sigslot::signal0 s_PipelinesChanged;
149
        /// Signal emitted when the collection of DataContainers has changed.
150
        sigslot::signal0 s_DataContainersChanged;
151

152
    private:
153
        void initGlContextAndPipeline(cgt::GLCanvas* canvas, AbstractPipeline* pipeline);
154

155 156
        /// All workflows
        std::vector<AbstractWorkflow*> _workflows;
157

158
        /// All pipelines 
159
        std::vector<AbstractPipeline*> _pipelines;
160

161 162
        /// Map of all pipelines with their MDI windows
        std::map<AbstractPipeline*, MdiDockableWindow*> _pipelineWindows;
163

164 165 166
        /// All DataContainers
        std::vector<DataContainer*> _dataContainers;

167 168 169 170 171 172
        /**
         * Triggers the ShaderManager to rebuild all shaders from file and then 
         * invalidates all VisualizationProcessors.
         */
        void triggerShaderRebuild();

173
        /// A local OpenGL context used for initialization
174
        cgt::QtCanvas* _localContext;
175 176
        /// Main window hosting GUI stuff
        MainWindow* _mainWindow;
177

178
        /// Error texture to show if there is no output found
179
        cgt::Texture* _errorTexture;
180

181 182 183
        /// the global LuaVmState of this application
        LuaVmState* _luaVmState;

184
        /// Flag, whether CampVisApplication was correctly initialized
185 186 187 188
        bool _initialized;

        int _argc;
        char** _argv;
189 190

        static const std::string loggerCat_;
191 192 193
    };
}

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