campvisapplication.h 5.7 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
namespace tgt {
39
    class GLCanvas;
40
    class QtThreadedCanvas;
41
    class Texture;
42
43
}

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

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

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

        /**
         * Destructor, make sure to call deinit() first.
         */
75
        ~CampVisApplication();
76
77
78
79
80
81
82
83
84
85
86
87
88

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

        /**
89
90
91
         * 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.
92
93
         * 
         * \param   name    Name of the OpenGL context to create for the pipeline.
94
         * \param   vp      AbstractPipeline to add.
95
         */
96
        void addPipeline(const std::string& name, AbstractPipeline* pipeline);
97
98

        /**
99
100
101
102
103
104
105
106
107
         * 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);

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

114

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

122
123
124
125
126
        /**
         * Reloads all GLSL shaders from file and rebuilds them.
         */
        void rebuildAllShadersFromFiles();

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

130
131
132
        /// Signal emitted when the collection of DataContainers has changed.
        sigslot::signal0<> s_DataContainersChanged;

133
    private:
134
135
        void initGlContextAndPipeline(tgt::GLCanvas* canvas, AbstractPipeline* pipeline);

136

137
        /// All pipelines 
138
        std::vector<AbstractPipeline*> _pipelines;
139
140
        /// All visualisations (i.e. Pipelines with their corresponding painters/canvases)
        std::vector< std::pair<AbstractPipeline*, CampVisPainter*> > _visualizations;
141

142
143
144
        /// All DataContainers
        std::vector<DataContainer*> _dataContainers;

145
146
147
148
149
150
        /**
         * Triggers the ShaderManager to rebuild all shaders from file and then 
         * invalidates all VisualizationProcessors.
         */
        void triggerShaderRebuild();

151
        /// A local OpenGL context used for initialization
152
        tgt::GLCanvas* _localContext;
153
154
        /// Main window hosting GUI stuff
        MainWindow* _mainWindow;
155

156
157
        tgt::Texture* _errorTexture;

158
        /// Flag, whether CampVisApplication was correctly initialized
159
160
161
162
        bool _initialized;

        int _argc;
        char** _argv;
163
164

        static const std::string loggerCat_;
165
166
167
    };
}

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