#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include "Program.h" #include "commands/TimerCallbackCommand.h" #include "CartographicTransformation.h" #include "commands/CameraMoveCallback.h" void Program::setWinProperties() { this->win->SetWindowName("Simulation"); this->win->SetSize(661, 661); this->win->SetDesiredUpdateRate(60); this->interact->SetRenderWindow(this->win); this->interact->Initialize(); vtkNew style; interact->SetInteractorStyle(style); } void Program::setupTimer(int dt) { auto callback = vtkSmartPointer::New(this); callback->SetClientData(this); callback->setDt(dt); this->interact->AddObserver(vtkCommand::TimerEvent, callback); this->interact->AddObserver(vtkCommand::KeyPressEvent, callback); this->interact->CreateRepeatingTimer(17); // 60 fps == 1000 / 60 == 16.7 ms per frame } void Program::setupCameraCallback() { auto callback = vtkSmartPointer::New(this->cam); this->interact->AddObserver(vtkCommand::MouseWheelForwardEvent, callback); this->interact->AddObserver(vtkCommand::MouseWheelBackwardEvent, callback); this->interact->AddObserver(vtkCommand::KeyPressEvent, callback); } Program::Program(int timerDT) { this->win = vtkSmartPointer::New(); this->interact = vtkSmartPointer::New(); this->cam = createNormalisedCamera(); this->win->SetNumberOfLayers(0); setWinProperties(); setupTimer(timerDT); setupCameraCallback(); } void Program::addLayer(Layer *layer) { layer->setCamera(this->cam); this->layers.push_back(layer); this->win->AddRenderer(layer->getLayer()); this->win->SetNumberOfLayers(this->win->GetNumberOfLayers() + 1); } void Program::removeLayer(Layer *layer) { this->win->RemoveRenderer(layer->getLayer()); auto it = std::find(this->layers.begin(), this->layers.end(), layer); if (it != this->layers.end()) { this->layers.erase(it); this->win->SetNumberOfLayers(this->win->GetNumberOfLayers() - 1); } } void Program::updateData(int t) { win->Render(); for (Layer *l: layers) { l->updateData(t); } } void Program::setupInteractions() { for (Layer *l: layers) { l->addObservers(interact); } } void Program::render() { setupInteractions(); win->Render(); interact->Start(); }