root/src/examples/flowingcanvas/main.cu @ 166:064e0c4d99fe

Revision 166:064e0c4d99fe, 2.9 KB (checked in by Andreas Schaefer <gentryx@…>, 14 months ago)

simulation and visualization now run synchronously. not perfect, but it'll do

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    // InteractiveSimulatorCPU<CanvasCell> *sim = new InteractiveSimulatorCPU<CanvasCell>(
31        &flow,
32        new CanvasInitializer());
33    CanvasWriter *writer = new CanvasWriter(sim->getOutputFrame(), sim);
34    FrameGrabber *grabber = new FrameGrabber(false, &flow);
35
36    QTimer *timerFlow = new QTimer(&flow);
37    QTimer *timerGrab = new QTimer(&flow);
38    QTimer *timerInfo = new QTimer(&flow);
39
40    QObject::connect(timerInfo, SIGNAL(timeout()),           &flow,   SLOT(info()));
41    QObject::connect(timerInfo, SIGNAL(timeout()),           grabber, SLOT(info()));
42    QObject::connect(timerInfo, SIGNAL(timeout()),           sim,     SLOT(info()));
43    QObject::connect(timerFlow, SIGNAL(timeout()),           &flow,   SLOT(ping()));
44    QObject::connect(timerGrab, SIGNAL(timeout()),           grabber, SLOT(grab()));
45
46    QObject::connect(&flow,     SIGNAL(cycleViewMode()),     writer,  SLOT(cycleViewMode()));
47    QObject::connect(grabber,   SIGNAL(newFrame(char*, unsigned, unsigned)),
48                     sim,       SLOT(updateCam( char*, unsigned, unsigned)));
49    QObject::connect(&flow,     SIGNAL(updateImage(QImage*)),
50                     sim,       SLOT(renderImage(QImage*)));
51    QObject::connect(&app,      SIGNAL(lastWindowClosed()),  sim,       SLOT(quit()));
52    QObject::connect(&app,      SIGNAL(lastWindowClosed()),  timerFlow, SLOT(stop()));
53    QObject::connect(&app,      SIGNAL(lastWindowClosed()),  timerGrab, SLOT(stop()));
54    QObject::connect(&app,      SIGNAL(lastWindowClosed()),  timerInfo, SLOT(stop()));
55
56    QThreadPool *threadPool = QThreadPool::globalInstance();
57    // fixme: sync_update_patch
58    // threadPool->start(sim);
59    // fixme: sync_update_patch
60    QObject::connect(timerFlow, SIGNAL(timeout()),           sim,       SLOT(step()));
61
62    grabber->grab();
63    timerFlow->start(10);
64    timerGrab->start(200);
65    timerInfo->start(5000);
66    flow.show();
67    int ret = app.exec();
68    threadPool->waitForDone();
69    return ret;
70}
71
72
73int main(int argc, char *argv[])
74{
75    runGUI(argc, argv);
76}
Note: See TracBrowser for help on using the browser.