tumvis.cpp 2.56 KB
Newer Older
schultezub's avatar
schultezub committed
1
#include "tgt/camera.h"
2
3
#include "tgt/exception.h"
#include "tgt/shadermanager.h"
schultezub's avatar
schultezub committed
4
5
#include "tgt/qt/qtapplication.h"
#include "tgt/qt/qtcanvas.h"
6
#include "tgt/qt/qtcontextmanager.h"
schultezub's avatar
schultezub committed
7

schultezub's avatar
schultezub committed
8
#include "tbb/include/tbb/task_scheduler_init.h"
9
#include "tbb/include/tbb/compat/thread"
schultezub's avatar
schultezub committed
10

schultezub's avatar
schultezub committed
11
#include "tumvispainter.h"
12
#include "core/pipeline/pipelineevaluator.h"
schultezub's avatar
schultezub committed
13
14
#include "modules/pipelines/slicevis.h"

15
using namespace TUMVis;
schultezub's avatar
schultezub committed
16

17
18
19
20
SliceVis* sliceVis = 0;
TumVisPainter* painter = 0;
PipelineEvaluator* pe;

schultezub's avatar
schultezub committed
21
22
23
24
25
26
27
/**
 * TUMVis main function, application entry point
 *
 * \param   argc    number of passed arguments
 * \param   argv    vector of arguments
 * \return  0 if program exited successfully
 **/
28
29
int main(int argc, char** argv) {  
    tgt::QtApplication* app = new tgt::QtApplication(argc, argv);
30
    tgt::QtContextManager::init();
31
32
    tgt::QtThreadedCanvas* renderCanvas = CtxtMgr.createContext("render", "TUMVis");
    tgt::QtThreadedCanvas* sliceVisCanvas = CtxtMgr.createContext("sliceVis", "SliceVis");
33
    
schultezub's avatar
schultezub committed
34
    tbb::task_scheduler_init init;
35
36
    renderCanvas->getContext()->acquire();
    app->addCanvas(renderCanvas);
schultezub's avatar
schultezub committed
37
    app->init();
38
    LogMgr.getConsoleLog()->addCat("", true);
39
    LGL_ERROR;
40
41
42
43
44
45
46
47

    if (argc > 0) {
        // ugly hack
        std::string programPath(argv[0]);
        programPath = tgt::FileSystem::parentDir(tgt::FileSystem::parentDir(tgt::FileSystem::parentDir(programPath)));
        ShdrMgr.addPath(programPath);
        ShdrMgr.addPath(programPath + "/core/glsl");
    }
48
    LGL_ERROR;
schultezub's avatar
schultezub committed
49

50
    tgt::Camera camera;
51
52
    renderCanvas->setCamera(&camera); 

schultezub's avatar
schultezub committed
53

54
    try {
55
56
57
58
59
        sliceVis = new SliceVis(sliceVisCanvas);
        painter = new TumVisPainter(renderCanvas, sliceVis);
        LGL_ERROR;
        renderCanvas->setPainter(painter);
        LGL_ERROR;
schultezub's avatar
schultezub committed
60
        sliceVis->init();
61
        LGL_ERROR;
62
63
64
65
66
67
68
    }
    catch (tgt::Exception& e) {
        LERRORC("main.cpp", "Encountered tgt::Exception: " << e.what());
    }
    catch (std::exception& e) {
        LERRORC("main.cpp", "Encountered std::exception: " << e.what());
    }
schultezub's avatar
schultezub committed
69

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

73
74
    pe = new PipelineEvaluator(sliceVis);
    pe->start();
75
    painter->start();
76

77
    app->run();
schultezub's avatar
schultezub committed
78

79
    pe->stop();
80
    painter->stop();
81

82
83
84
85
86
87
    sliceVis->deinit();
    painter->deinit();
    tgt::deinitGL();
    tgt::QtContextManager::deinit();
    tgt::deinit();

schultezub's avatar
schultezub committed
88
    delete painter;
89
    delete sliceVis;
90
    delete app;
schultezub's avatar
schultezub committed
91

92
    return 0;
schultezub's avatar
schultezub committed
93
}