campvisapplication.h 6.15 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-2014, 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
37
#include "core/datastructures/datacontainer.h"

38
39
40
41
#ifdef CAMPVIS_HAS_SCRIPTING
#include "scripting/glue/luavmstate.h"
#endif

42
namespace tgt {
43
    class GLCanvas;
44
    class QtThreadedCanvas;
45
    class Texture;
46
47
}

schultezub's avatar
schultezub committed
48
namespace campvis {
49
    class AbstractPipeline;
50
    class MainWindow;
51
    class CampVisPainter;
52
    class LuaVmState;
53
54

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

69
    public:
70
71
72
73
74
75
        /// Record storing a pipeline together with its painter and Lua VM state.
        struct PipelineRecord {
            AbstractPipeline* _pipeline;
            CampVisPainter* _painter;
        };

76
        /**
77
         * Creates a new CampVisApplication.
78
79
         * \param   argc        number of passed arguments
         * \param   argv        vector of arguments
80
         */
81
        CampVisApplication(int& argc, char** argv);
82
83
84
85

        /**
         * Destructor, make sure to call deinit() first.
         */
86
        ~CampVisApplication();
87
88
89
90
91
92
93
94
95
96
97
98
99

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

        /**
100
101
102
         * 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.
103
104
         * 
         * \param   name    Name of the OpenGL context to create for the pipeline.
105
         * \param   vp      AbstractPipeline to add.
106
         */
107
        void addPipeline(const std::string& name, AbstractPipeline* pipeline);
108
109

        /**
110
111
112
113
114
115
116
117
118
         * 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);

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

125

126
127
128
129
130
        /**
         * Creates a new DataContainer with the given name.
         * \param   name    Name of the new DataContainer
         * \return  The newly created DataContainer
         */
131
        DataContainer* createAndAddDataContainer(const std::string& name);
132

133
134
135
136
137
        /**
         * Reloads all GLSL shaders from file and rebuilds them.
         */
        void rebuildAllShadersFromFiles();

138
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
149
        sigslot::signal0<> s_PipelinesChanged;

150
151
152
        /// Signal emitted when the collection of DataContainers has changed.
        sigslot::signal0<> s_DataContainersChanged;

153
    private:
154
155
        void initGlContextAndPipeline(tgt::GLCanvas* canvas, AbstractPipeline* pipeline);

156

157
        /// All pipelines 
158
        std::vector<PipelineRecord> _pipelines;
159

160
161
162
        /// All DataContainers
        std::vector<DataContainer*> _dataContainers;

163
164
165
166
167
168
        /**
         * Triggers the ShaderManager to rebuild all shaders from file and then 
         * invalidates all VisualizationProcessors.
         */
        void triggerShaderRebuild();

169
        /// A local OpenGL context used for initialization
170
        tgt::GLCanvas* _localContext;
171
172
        /// Main window hosting GUI stuff
        MainWindow* _mainWindow;
173

174
        /// Error texture to show if there is no output found
175
176
        tgt::Texture* _errorTexture;

177
178
179
        /// the global LuaVmState of this application
        LuaVmState* _luaVmState;

180
        /// Flag, whether CampVisApplication was correctly initialized
181
182
183
184
        bool _initialized;

        int _argc;
        char** _argv;
185
186

        static const std::string loggerCat_;
187
188
189
    };
}

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