campvisapplication.h 5.68 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
37
38
39
40
41
42
43
#include <QApplication>
#include <utility>
#include <vector>

namespace tgt {
    class QtThreadedCanvas;
}

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

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

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

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

        /**
         * 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).
102
103
         * For each added pipeline, an OpenGL context will be created (for the evaluation 
         * and rendering).
104
         * 
schultezub's avatar
schultezub committed
105
         * \note    You do \b not need to call addPipeline.
106
107
108
109
110
111
112
113
114
115
116
117
         * \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);

        /**
         * Runs the actual application.
         * Make sure to call init() before.
         * \return  0 on success.
         */
        int run();

schultezub's avatar
schultezub committed
118
        /// Signal emitted when the collection of pipelines has changed.
119
120
        sigslot::signal0<> s_PipelinesChanged;

121
122
123
124
125
126
127
128
    private:
        /// All pipelines (incuding VisualizationPipelines)
        std::vector<AbstractPipeline*> _pipelines;
        /// All visualisations (i.e. VisualizationPipelines with their corresponding painters/canvases)
        std::vector< std::pair<VisualizationPipeline*, TumVisPainter*> > _visualizations;

        /// A local OpenGL context used for initialization
        tgt::QtThreadedCanvas* _localContext;
129
130
        /// Main window hosting GUI stuff
        MainWindow* _mainWindow;
131

132
        /// Flag, whether CampVisApplication was correctly initialized
133
134
        bool _initialized;

135
136
137
        /// Flag, whether to use OpenCL (inits and deinits KissCL lib at the appropriate time).
        bool _useOpenCL;

138
139
        int _argc;
        char** _argv;
140
141

        static const std::string loggerCat_;
142
143
144
    };
}

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