Currently job artifacts in CI/CD pipelines on LRZ GitLab never expire. Starting from Wed 26.1.2022 the default expiration time will be 30 days (GitLab default). Currently existing artifacts in already completed jobs will not be affected by the change. The latest artifacts for all jobs in the latest successful pipelines will be kept. More information: https://gitlab.lrz.de/help/user/admin_area/settings/continuous_integration.html#default-artifacts-expiration

campvisapplication.cpp 9.59 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 Universitt Mnchen
//      Boltzmannstr. 3, 85748 Garching b. Mnchen, 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
#include "campvisapplication.h"
31
32
33
34

#include "tgt/assert.h"
#include "tgt/exception.h"
#include "tgt/glcontext.h"
35
#include "tgt/gpucapabilities.h"
36
37
38
39
#include "tgt/shadermanager.h"
#include "tgt/qt/qtapplication.h"
#include "tgt/qt/qtthreadedcanvas.h"
#include "tgt/qt/qtcontextmanager.h"
schultezub's avatar
schultezub committed
40
#include "tbb/compat/thread"
41

schultezub's avatar
schultezub committed
42
#ifdef HAS_KISSCL
43
#include "kisscl/clruntime.h"
schultezub's avatar
schultezub committed
44
#endif
45

schultezub's avatar
schultezub committed
46
#include "application/campvispainter.h"
47
#include "application/gui/mainwindow.h"
48
#include "core/tools/opengljobprocessor.h"
49
#include "core/tools/simplejobprocessor.h"
50
#include "core/tools/quadrenderer.h"
51
52
53
#include "core/pipeline/abstractpipeline.h"
#include "core/pipeline/visualizationpipeline.h"

schultezub's avatar
schultezub committed
54
namespace campvis {
55

56
    const std::string CampVisApplication::loggerCat_ = "CAMPVis.application.CampVisApplication";
57

58
    CampVisApplication::CampVisApplication(int argc, char** argv, bool useOpenCL) 
59
60
        : QApplication(argc, argv)
        , _localContext(0)
61
        , _mainWindow(0)
62
        , _initialized(false)
63
        , _useOpenCL(useOpenCL)
64
65
66
        , _argc(argc)
        , _argv(argv)
    {
67
68
        // Make Xlib and GLX thread safe under X11
        QApplication::setAttribute(Qt::AA_X11InitThreads);
69

70
71
        _mainWindow = new MainWindow(this);
        tgt::QtContextManager::init();
72
73

        OpenGLJobProcessor::init();
74
        SimpleJobProcessor::init();
75
76
    }

77
78
    CampVisApplication::~CampVisApplication() {
        tgtAssert(_initialized == false, "Destructing initialized CampVisApplication, deinitialize first!");
79
80
81
82
83
84
85
86
87
88

        // delete everything in the right order:
        for (std::vector< std::pair<VisualizationPipeline*, TumVisPainter*> >::iterator it = _visualizations.begin(); it != _visualizations.end(); ++it) {
            delete it->second;
        }
        for (std::vector<AbstractPipeline*>::iterator it = _pipelines.begin(); it != _pipelines.end(); ++it) {
            delete *it;
        }
    }

89
90
    void CampVisApplication::init() {
        tgtAssert(_initialized == false, "Tried to initialize CampVisApplication twice.");
91
92
93
94
95
96
97
98
99

        // Init TGT
        tgt::InitFeature::Features featureset = tgt::InitFeature::ALL;
        tgt::init(featureset);
        LogMgr.getConsoleLog()->addCat("", true);

        // create a local OpenGL context and init GL
        _localContext = CtxtMgr.createContext("AppContext", "", tgt::ivec2(16, 16));
        tgtAssert(_localContext != 0, "Could not create local OpenGL context");
100
101
102

        tgt::GLContextScopedLock lock(_localContext->getContext());

103
        tgt::initGL(featureset);
104
        ShdrMgr.setGlobalHeader("#version 330\n");
105
106
        LGL_ERROR;

107
        // ensure matching OpenGL specs
108
        if (GpuCaps.getGlVersion() < tgt::GpuCapabilities::GlVersion::TGT_GL_VERSION_3_3) {
schultezub's avatar
schultezub committed
109
            LERROR("Your system does not support OpenGL 3.3, which is mandatory. CAMPVis will probably not work as intendet.");
110
        }
111
        if (GpuCaps.getShaderVersion() < tgt::GpuCapabilities::GlVersion::SHADER_VERSION_330) {
schultezub's avatar
schultezub committed
112
            LERROR("Your system does not support GLSL Shader Version 3.30, which is mandatory. CAMPVis will probably not work as intendet.");
113
114
        }

115
116
        QuadRenderer::init();

schultezub's avatar
schultezub committed
117
#ifdef HAS_KISSCL
118
119
120
        if (_useOpenCL) {
            kisscl::CLRuntime::init();
        }
schultezub's avatar
schultezub committed
121
#endif
122

123
124
        if (_argc > 0) {
            // ugly hack
schultezub's avatar
schultezub committed
125
            std::string basePath(_argv[0]);
126
127
128
129
130
            basePath = tgt::FileSystem::parentDir(basePath);
            ShdrMgr.addPath(basePath);
            ShdrMgr.addPath(basePath + "/core/glsl");

            basePath = tgt::FileSystem::parentDir(tgt::FileSystem::parentDir(basePath));
schultezub's avatar
schultezub committed
131
132
133
            ShdrMgr.addPath(basePath);
            ShdrMgr.addPath(basePath + "/core/glsl");

134
135
136
137
138
139
140
141
#ifdef CAMPVIS_SOURCE_DIR
            {
                std::string sourcePath = CAMPVIS_SOURCE_DIR;
                ShdrMgr.addPath(sourcePath);
                ShdrMgr.addPath(sourcePath + "/core/glsl");
            }
#endif

schultezub's avatar
schultezub committed
142
#ifdef HAS_KISSCL
schultezub's avatar
schultezub committed
143
144
145
146
            if (_useOpenCL) {
                CLRtm.addPath(basePath);
                CLRtm.addPath(basePath + "/core/cl");
            }
schultezub's avatar
schultezub committed
147
#endif
148
149
        }

150
151
        _mainWindow->init();

152
153
154
155
156
157
158
159
160
161
        // init pipeline first
        for (std::vector<AbstractPipeline*>::iterator it = _pipelines.begin(); it != _pipelines.end(); ++it) {
            (*it)->init();
        }

        // Now init painters:
        for (std::vector< std::pair<VisualizationPipeline*, TumVisPainter*> >::iterator it = _visualizations.begin(); it != _visualizations.end(); ++it) {
            it->second->init();
        }

162
        GLJobProc.start();
163
164
165
        _initialized = true;
    }

166
167
    void CampVisApplication::deinit() {
        tgtAssert(_initialized, "Tried to deinitialize uninitialized CampVisApplication.");
168

169
170
        GLJobProc.stop();

171
172
173
        {
            // Deinit everything OpenGL related using the local context.
            tgt::GLContextScopedLock lock(_localContext->getContext());
174

175
176
177
178
179
180
181
182
183
184
            // Deinit pipeline first
            for (std::vector<AbstractPipeline*>::iterator it = _pipelines.begin(); it != _pipelines.end(); ++it) {
                (*it)->deinit();
            }

            // Now deinit painters:
            for (std::vector< std::pair<VisualizationPipeline*, TumVisPainter*> >::iterator it = _visualizations.begin(); it != _visualizations.end(); ++it) {
                it->second->deinit();
            }

185
186
            _mainWindow->deinit();

187
188
            QuadRenderer::deinit();

schultezub's avatar
schultezub committed
189
#ifdef HAS_KISSCL
190
191
192
            if (_useOpenCL) {
                kisscl::CLRuntime::deinit();
            }
schultezub's avatar
schultezub committed
193
#endif
194
195
196
197


            // deinit OpenGL and tgt
            tgt::deinitGL();
198
199
        }

200
        SimpleJobProcessor::deinit();
201
202
        OpenGLJobProcessor::deinit();

203
204
205
        tgt::QtContextManager::deinit();
        tgt::deinit();

206
        // MainWindow dtor needs a valid CampVisApplication, so we need to call it here instead of during destruction.
schultezub's avatar
schultezub committed
207
208
        delete _mainWindow;

209
210
211
        _initialized = false;
    }

212
213
    int CampVisApplication::run() {
        tgtAssert(_initialized, "Tried to run uninitialized CampVisApplication.");
214
215
216
217

        // disconnect OpenGL context from this thread so that the other threads can acquire an OpenGL context.
        CtxtMgr.releaseCurrentContext();

218
219
        _mainWindow->show();

220
221
222
223
224
225
        // Start QApplication
        int toReturn = QApplication::exec();

        return toReturn;
    }

226
    void CampVisApplication::addPipeline(AbstractPipeline* pipeline) {
227
        tgtAssert(_initialized == false, "Adding pipelines after initialization is currently not supported.");
228
229
230
        tgtAssert(pipeline != 0, "Pipeline must not be 0.");
        _pipelines.push_back(pipeline);

231
        s_PipelinesChanged();
232
233
    }

234
    void CampVisApplication::addVisualizationPipeline(const std::string& name, VisualizationPipeline* vp) {
235
        tgtAssert(_initialized == false, "Adding pipelines after initialization is currently not supported.");
236
237
238
        tgtAssert(vp != 0, "Pipeline must not be 0.");

        // create canvas and painter for the VisPipeline and connect all together
schultezub's avatar
schultezub committed
239
        tgt::QtThreadedCanvas* canvas = CtxtMgr.createContext(name, "CAMPVis", tgt::ivec2(512, 512));
240
        GLJobProc.registerContext(canvas);
241
        _mainWindow->addVisualizationPipelineWidget(name, canvas);
242
243
244
245
246
247
        canvas->init();

        TumVisPainter* painter = new TumVisPainter(canvas, vp);
        canvas->setPainter(painter, false);

        _visualizations.push_back(std::make_pair(vp, painter));
248

249
        vp->setCanvas(canvas);
250
        addPipeline(vp);
251
252

        CtxtMgr.releaseCurrentContext();
253
254
    }

255
256
257
258
259
260
    void CampVisApplication::registerDockWidget(Qt::DockWidgetArea area, QDockWidget* dock) {
        tgtAssert(dock != 0, "Dock widget must not be 0.");

        _mainWindow->addDockWidget(area, dock);
    }

261
}