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.46 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
40
41
#include "tgt/shadermanager.h"
#include "tgt/qt/qtapplication.h"
#include "tgt/qt/qtthreadedcanvas.h"
#include "tgt/qt/qtcontextmanager.h"
#include "tbb/include/tbb/compat/thread"

42
43
#include "kisscl/clruntime.h"

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

schultezub's avatar
schultezub committed
52
namespace campvis {
53

54
    const std::string CampVisApplication::loggerCat_ = "CAMPVis.application.CampVisApplication";
55

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

68
69
        _mainWindow = new MainWindow(this);
        tgt::QtContextManager::init();
70
71

        OpenGLJobProcessor::init();
72
73
    }

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

        // delete everything in the right order:
        for (std::vector<PipelineEvaluator*>::iterator it = _pipelineEvaluators.begin(); it != _pipelineEvaluators.end(); ++it) {
            delete *it;
        }
        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
104
105
        tgt::initGL(featureset);
        LGL_ERROR;

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

114
115
        QuadRenderer::init();

116
117
118
119
        if (_useOpenCL) {
            kisscl::CLRuntime::init();
        }

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

            if (_useOpenCL) {
                CLRtm.addPath(basePath);
                CLRtm.addPath(basePath + "/core/cl");
            }
131
132
        }

133
134
        _mainWindow->init();

135
136
137
138
139
140
141
142
143
144
        // 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();
        }

145
        GLJobProc.start();
146
147
148
        _initialized = true;
    }

149
150
    void CampVisApplication::deinit() {
        tgtAssert(_initialized, "Tried to deinitialize uninitialized CampVisApplication.");
151

152
153
        GLJobProc.stop();

154
155
156
        {
            // Deinit everything OpenGL related using the local context.
            tgt::GLContextScopedLock lock(_localContext->getContext());
157

158
159
160
161
162
163
164
165
166
167
            // 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();
            }

168
169
            _mainWindow->deinit();

170
171
            // deinit OpenGL and tgt
            tgt::deinitGL();
172

173
174
            QuadRenderer::deinit();

175
176
177
            if (_useOpenCL) {
                kisscl::CLRuntime::deinit();
            }
178
179
        }

180
181
        OpenGLJobProcessor::deinit();

182
183
184
        tgt::QtContextManager::deinit();
        tgt::deinit();

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

188
189
190
        _initialized = false;
    }

191
192
    int CampVisApplication::run() {
        tgtAssert(_initialized, "Tried to run uninitialized CampVisApplication.");
193
194
195
196

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

197
198
        _mainWindow->show();

199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
        // Start evaluator/render threads
        for (std::vector<PipelineEvaluator*>::iterator it = _pipelineEvaluators.begin(); it != _pipelineEvaluators.end(); ++it) {
            (*it)->start();
        }

        // Start QApplication
        int toReturn = QApplication::exec();

        // QApplication has returned -> Stop evaluator/render threads
        for (std::vector<PipelineEvaluator*>::iterator it = _pipelineEvaluators.begin(); it != _pipelineEvaluators.end(); ++it) {
            (*it)->stop();
        }

        return toReturn;
    }

215
    void CampVisApplication::addPipeline(AbstractPipeline* pipeline) {
216
        tgtAssert(_initialized == false, "Adding pipelines after initialization is currently not supported.");
217
218
219
220
221
        tgtAssert(pipeline != 0, "Pipeline must not be 0.");
        _pipelines.push_back(pipeline);

        PipelineEvaluator* pe = new PipelineEvaluator(pipeline);
        _pipelineEvaluators.push_back(pe);
222
223

        s_PipelinesChanged();
224
225
    }

226
    void CampVisApplication::addVisualizationPipeline(const std::string& name, VisualizationPipeline* vp) {
227
        tgtAssert(_initialized == false, "Adding pipelines after initialization is currently not supported.");
228
229
230
        tgtAssert(vp != 0, "Pipeline must not be 0.");

        // create canvas and painter for the VisPipeline and connect all together
schultezub's avatar
schultezub committed
231
        tgt::QtThreadedCanvas* canvas = CtxtMgr.createContext(name, "CAMPVis", tgt::ivec2(512, 512));
232
        GLJobProc.registerContext(canvas);
233
234
235
236
237
238
        canvas->init();

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

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

240
        vp->setCanvas(canvas);
241
        addPipeline(vp);
242
243

        CtxtMgr.releaseCurrentContext();
244
245
246
    }

}