campvisapplication.h 6.17 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
//      Chair for Computer Aided Medical Procedures
8
9
//      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
#include <utility>
#include <vector>

41
42
#include "core/datastructures/datacontainer.h"

43
44
45
46
namespace tgt {
    class QtThreadedCanvas;
}

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

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

67
68
    public:
        /**
69
         * Creates a new CampVisApplication.
70
71
72
         * \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).
73
         */
74
        CampVisApplication(int& argc, char** argv, bool useOpenCL = true);
75
76
77
78

        /**
         * Destructor, make sure to call deinit() first.
         */
79
        ~CampVisApplication();
80
81
82
83
84
85
86
87
88
89
90
91
92

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

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

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

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

118

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

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

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

132
    private:
133
134
        void addPipelineImpl(tgt::QtThreadedCanvas* canvas, const std::string& name, AbstractPipeline* pipeline);

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

140
141
142
        /// All DataContainers
        std::vector<DataContainer*> _dataContainers;

143
144
        /// A local OpenGL context used for initialization
        tgt::QtThreadedCanvas* _localContext;
145
146
        /// Main window hosting GUI stuff
        MainWindow* _mainWindow;
147

148
        /// Flag, whether CampVisApplication was correctly initialized
149
150
        bool _initialized;

151
152
153
        /// Flag, whether to use OpenCL (inits and deinits KissCL lib at the appropriate time).
        bool _useOpenCL;

154
155
        int _argc;
        char** _argv;
156
157

        static const std::string loggerCat_;
158
159
160
    };
}

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