feat: improved pausing simulation
This commit is contained in:
parent
efeed7fcb9
commit
7b06a54542
|
|
@ -1,3 +1,4 @@
|
|||
#include <qurl.h>
|
||||
#include <stdexcept>
|
||||
#include <vtkRenderWindow.h>
|
||||
#include <vtkPointData.h>
|
||||
|
|
@ -18,6 +19,7 @@
|
|||
#include <vtkGenericOpenGLRenderWindow.h>
|
||||
#include <vtkCallbackCommand.h>
|
||||
#include <vtkInteractorStyleUser.h>
|
||||
#include <QKeyEvent>
|
||||
|
||||
#include "Program.h"
|
||||
#include "commands/TimerCallbackCommand.h"
|
||||
|
|
@ -130,3 +132,7 @@ vtkSmartPointer<vtkCamera> Program::getCamera() {
|
|||
std::vector<Technique *> Program::getTechniques() {
|
||||
return this->techniques;
|
||||
}
|
||||
|
||||
vtkSmartPointer<vtkRenderWindowInteractor> Program::getInteractor() {
|
||||
return this->interact;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -81,6 +81,9 @@ public:
|
|||
|
||||
std::vector<Technique *> getTechniques();
|
||||
|
||||
|
||||
vtkSmartPointer<vtkRenderWindowInteractor> getInteractor();
|
||||
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -2,24 +2,28 @@
|
|||
#include "ui_mainwindow.h"
|
||||
|
||||
#include <QFile>
|
||||
#include <QKeyEvent>
|
||||
#include <QFileDialog>
|
||||
#include <QMessageBox>
|
||||
|
||||
#include <vtkDataSetReader.h>
|
||||
|
||||
#include "../layers/BackgroundImage.h"
|
||||
#include "../layers/EColLayer.h"
|
||||
#include "../layers/EGlyphLayer.h"
|
||||
#include "../layers/LGlyphLayer.h"
|
||||
#include "../layers/LColLayer.h"
|
||||
#include "../Program.h"
|
||||
#include "../advection/UVGrid.h"
|
||||
#include "../advection/kernel/RK4AdvectionKernel.h"
|
||||
#include "../advection/kernel/SnapBoundaryConditionKernel.h"
|
||||
#include "../commands/TimerCallbackCommand.h"
|
||||
#include "../layers/BackgroundImage.h"
|
||||
#include "../layers/EColLayer.h"
|
||||
#include "../layers/EGlyphLayer.h"
|
||||
#include "../layers/LColLayer.h"
|
||||
#include "../layers/LGlyphLayer.h"
|
||||
#include "../layers/enums.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
#define DT 3600
|
||||
|
||||
MainWindow::MainWindow(QWidget* parent)
|
||||
: QMainWindow(parent)
|
||||
, ui(new Ui::MainWindow)
|
||||
|
|
@ -60,8 +64,8 @@ void MainWindow::setupTechniques() {
|
|||
auto kernelRK4_2 = make_unique<RK4AdvectionKernel>(uvGrid);
|
||||
auto kernelRK4BoundaryChecked_2 = make_unique<SnapBoundaryConditionKernel>(std::move(kernelRK4_2), uvGrid);
|
||||
auto lCol = new LColLayer(uvGrid, std::move(kernelRK4BoundaryChecked_2));
|
||||
lGlyph->setDt(3600);
|
||||
lCol->setDt(3600);
|
||||
lGlyph->setDt(DT);
|
||||
lCol->setDt(DT);
|
||||
|
||||
technique1->addLayer(lGlyph);
|
||||
technique2->addLayer(lCol);
|
||||
|
|
@ -73,10 +77,24 @@ void MainWindow::setupTechniques() {
|
|||
|
||||
// TODO: implement feature to call this function on widget
|
||||
// l->spoofPoints();
|
||||
// l->cycleGlyphStyle();
|
||||
|
||||
// Setup timer
|
||||
auto intr = program->getInteractor();
|
||||
this->timer = vtkSmartPointer<TimerCallbackCommand>::New(program);
|
||||
this->timer->SetClientData(program);
|
||||
this->timer->setDt(DT);
|
||||
intr->AddObserver(vtkCommand::TimerEvent, this->timer);
|
||||
intr->AddObserver(vtkCommand::KeyPressEvent, this->timer);
|
||||
intr->CreateRepeatingTimer(17); // 60 fps == 1000 / 60 == 16.7 ms per frame
|
||||
}
|
||||
|
||||
|
||||
void MainWindow::keyPressEvent(QKeyEvent *ev) {
|
||||
if (ev->key() == Qt::Key_Space) {
|
||||
this->timer->togglePaused();
|
||||
}
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------
|
||||
* + QTWidget callbacks +
|
||||
* --------------------------------------------------------------------*/
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
#define MAINWINDOW_H
|
||||
|
||||
#include <QMainWindow>
|
||||
#include "../advection/UVGrid.h"
|
||||
#include "../commands/TimerCallbackCommand.h"
|
||||
|
||||
namespace Ui {
|
||||
class MainWindow;
|
||||
|
|
@ -15,6 +15,8 @@ public:
|
|||
explicit MainWindow(QWidget* parent = 0);
|
||||
~MainWindow();
|
||||
|
||||
void keyPressEvent(QKeyEvent *ev);
|
||||
|
||||
private slots:
|
||||
void on_FirstButton_clicked(bool checked);
|
||||
void on_SecondButton_clicked(bool checked);
|
||||
|
|
@ -33,6 +35,7 @@ private slots:
|
|||
|
||||
private:
|
||||
Ui::MainWindow* ui;
|
||||
vtkSmartPointer<TimerCallbackCommand> timer;
|
||||
|
||||
void setupTechniques();
|
||||
};
|
||||
|
|
|
|||
|
|
@ -28,6 +28,10 @@ void TimerCallbackCommand::Execute(vtkObject* caller, unsigned long eventId, voi
|
|||
}
|
||||
}
|
||||
|
||||
void TimerCallbackCommand::togglePaused() {
|
||||
this->paused = !this->paused;
|
||||
}
|
||||
|
||||
void TimerCallbackCommand::setProgram(Program *program) {
|
||||
this->program = program;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -12,6 +12,7 @@ public:
|
|||
|
||||
void setProgram(Program *program);
|
||||
void setPaused(const bool val);
|
||||
void togglePaused();
|
||||
|
||||
void setDt(int dt);
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue