root/src/examples/flowingcanvas/main.cpp @ 159:2c1d8c3eb30d

Revision 159:2c1d8c3eb30d, 2.7 KB (checked in by Andreas Schaefer <gentryx@…>, 14 months ago)
  • qt particle rendering is too slow,
  • fleshing out the GPU simulator
Line 
1#include <QTimer>
2#include <QApplication>
3#include <QThreadPool>
4#include <libgeodecomp/examples/flowingcanvas/canvascell.h>
5#include <libgeodecomp/examples/flowingcanvas/canvasinitializer.h>
6#include <libgeodecomp/examples/flowingcanvas/canvaswriter.h>
7#include <libgeodecomp/examples/flowingcanvas/flowwidget.h>
8#include <libgeodecomp/examples/flowingcanvas/framegrabber.h>
9#include <libgeodecomp/examples/flowingcanvas/interactivesimulatorcpu.h>
10#include <libgeodecomp/examples/flowingcanvas/interactivesimulatorgpu.h>
11#include <libgeodecomp/io/simpleinitializer.h>
12#include <libgeodecomp/misc/floatcoord.h>
13
14using namespace LibGeoDecomp;
15
16// class SimParams
17// {
18// public:
19//     int maxCameraFrames;
20//     float gradientCutoff;
21// };
22
23int runGUI(int argc, char **argv)
24{
25    QApplication app(argc, argv);
26    FlowWidget flow;
27    flow.resize(1200, 900);
28
29    InteractiveSimulatorGPU<CanvasCell> *sim = new InteractiveSimulatorGPU<CanvasCell>(
30        &flow,
31        new CanvasInitializer());
32    CanvasWriter *writer = new CanvasWriter(sim->getOutputFrame(), sim);
33    FrameGrabber *grabber = new FrameGrabber(true, &flow);
34
35    QTimer *timerFlow = new QTimer(&flow);
36    QTimer *timerGrab = new QTimer(&flow);
37    QTimer *timerInfo = new QTimer(&flow);
38
39    QObject::connect(timerInfo, SIGNAL(timeout()),           &flow,   SLOT(info()));
40    QObject::connect(timerInfo, SIGNAL(timeout()),           grabber, SLOT(info()));
41    QObject::connect(timerInfo, SIGNAL(timeout()),           sim,     SLOT(info()));
42    QObject::connect(timerFlow, SIGNAL(timeout()),           &flow,   SLOT(ping()));
43    QObject::connect(timerGrab, SIGNAL(timeout()),           grabber, SLOT(grab()));
44
45    QObject::connect(&flow,     SIGNAL(cycleViewMode()),     writer,  SLOT(cycleViewMode()));
46    QObject::connect(grabber,   SIGNAL(newFrame(char*, unsigned, unsigned)), 
47                     sim,       SLOT(updateCam( char*, unsigned, unsigned)));
48    QObject::connect(&flow,     SIGNAL(updateImage(QImage*)),
49                     sim,       SLOT(renderImage(QImage*)));
50    QObject::connect(&app,      SIGNAL(lastWindowClosed()),  sim,       SLOT(quit()));
51    QObject::connect(&app,      SIGNAL(lastWindowClosed()),  timerFlow, SLOT(stop()));
52    QObject::connect(&app,      SIGNAL(lastWindowClosed()),  timerGrab, SLOT(stop()));
53    QObject::connect(&app,      SIGNAL(lastWindowClosed()),  timerInfo, SLOT(stop()));
54
55    QThreadPool *threadPool = QThreadPool::globalInstance();
56    threadPool->start(sim);
57
58    grabber->grab();
59    timerFlow->start(50);
60    timerGrab->start(100);
61    timerInfo->start(5000);
62    flow.show();
63    int ret = app.exec();
64    threadPool->waitForDone();
65    return ret;
66}
67
68
69int main(int argc, char *argv[])
70{
71    runGUI(argc, argv);
72}
Note: See TracBrowser for help on using the browser.