diff --git a/vtk/src/CMakeLists.txt b/vtk/src/CMakeLists.txt index cb39085..ef2a3aa 100644 --- a/vtk/src/CMakeLists.txt +++ b/vtk/src/CMakeLists.txt @@ -31,22 +31,22 @@ endif() # netcdf setup find_package(netCDF REQUIRED) -add_executable(VtkBase MACOSX_BUNDLE main.cpp - helperClasses/BackgroundImage.cpp - helperClasses/BackgroundImage.h - helperClasses/EGlyphLayer.cpp - helperClasses/EGlyphLayer.h - helperClasses/Layer.cpp - helperClasses/Layer.h - helperClasses/LGlyphLayer.cpp - helperClasses/LGlyphLayer.h - helperClasses/Program.cpp - helperClasses/Program.h +add_executable(VtkBase MACOSX_BUNDLE main.cpp + layers/BackgroundImage.cpp + layers/BackgroundImage.h + layers/EGlyphLayer.cpp + layers/EGlyphLayer.h + layers/Layer.cpp + layers/Layer.h + layers/LGlyphLayer.cpp + layers/LGlyphLayer.h + Program.cpp + Program.h commands/TimerCallbackCommand.h commands/TimerCallbackCommand.cpp - helperClasses/SpawnPointCallback.h - helperClasses/SpawnPointCallback.cpp - helperClasses/CartographicTransformation.cpp + commands/SpawnPointCallback.h + commands/SpawnPointCallback.cpp + CartographicTransformation.cpp ) execute_process( diff --git a/vtk/src/helperClasses/CartographicTransformation.cpp b/vtk/src/CartographicTransformation.cpp similarity index 100% rename from vtk/src/helperClasses/CartographicTransformation.cpp rename to vtk/src/CartographicTransformation.cpp diff --git a/vtk/src/helperClasses/CartographicTransformation.h b/vtk/src/CartographicTransformation.h similarity index 100% rename from vtk/src/helperClasses/CartographicTransformation.h rename to vtk/src/CartographicTransformation.h diff --git a/vtk/src/helperClasses/Program.cpp b/vtk/src/Program.cpp similarity index 70% rename from vtk/src/helperClasses/Program.cpp rename to vtk/src/Program.cpp index 3be950b..f5d1a93 100644 --- a/vtk/src/helperClasses/Program.cpp +++ b/vtk/src/Program.cpp @@ -18,8 +18,8 @@ #include #include "Program.h" -#include "../commands/TimerCallbackCommand.h" -#include "SpawnPointCallback.h" +#include "commands/TimerCallbackCommand.h" +#include "commands/SpawnPointCallback.h" void Program::setWinProperties() { this->win->SetWindowName("Simulation"); @@ -50,41 +50,37 @@ Program::Program() { } -void Program::addLayer(Layer* layer) { +void Program::addLayer(Layer *layer) { this->layers.push_back(layer); this->win->AddRenderer(layer->getLayer()); - this->win->SetNumberOfLayers(this->win->GetNumberOfLayers()+1); + 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); + 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::setLagrangeInteractor(SpawnPointCallback *cb){ - this->interact->AddObserver(vtkCommand::LeftButtonPressEvent, cb); - this->interact->AddObserver(vtkCommand::LeftButtonReleaseEvent, cb); - this->interact->AddObserver(vtkCommand::MouseMoveEvent, cb); -} - - - void Program::updateData(int t) { - this->win->Render(); - for (Layer *l : layers) { + win->Render(); + for (Layer *l: layers) { l->updateData(t); } } +void Program::setupInteractions() { + for (Layer *l: layers) { + l->addObservers(interact); + } +} void Program::render() { - this->win->Render(); - this->interact->Start(); + setupInteractions(); + win->Render(); + interact->Start(); } diff --git a/vtk/src/helperClasses/Program.h b/vtk/src/Program.h similarity index 86% rename from vtk/src/helperClasses/Program.h rename to vtk/src/Program.h index 642eadd..4097e4c 100644 --- a/vtk/src/helperClasses/Program.h +++ b/vtk/src/Program.h @@ -5,8 +5,8 @@ #include #include -#include "Layer.h" -#include "SpawnPointCallback.h" +#include "layers/Layer.h" +#include "commands/SpawnPointCallback.h" /** This class manages the upper levels of the vtk pipeline; it has attributes for the vtkrenderWindow and a vector of Layers to represent a variable number of vtkRenderers. * It can also set up a vtkTimer by connecting an instance of TimerCallbackCommand with its contained vtkRenderWindowInteractor. @@ -33,6 +33,8 @@ private: */ void setupTimer(); + void setupInteractions(); + public: /** Constructor. */ @@ -50,19 +52,16 @@ public: */ void removeLayer(Layer *layer); - /** This function sets the given SpawnpointCallback to be used with the program. - * @param cb : the callback to use. - */ - void setLagrangeInteractor(SpawnPointCallback *cb); - /** This function updates the data for the associated layers to the given timestamp. * Also updates the renderWindow. * @param t : the timestamp to update the data to. */ void updateData(int t); - /** This function renders the vtkRenderWindow for the first time. - */ + /** + * This function renders the vtkRenderWindow for the first time. + * Only call this function once! + */ void render(); }; diff --git a/vtk/src/helperClasses/SpawnPointCallback.cpp b/vtk/src/commands/SpawnPointCallback.cpp similarity index 98% rename from vtk/src/helperClasses/SpawnPointCallback.cpp rename to vtk/src/commands/SpawnPointCallback.cpp index e52b88f..e29d190 100644 --- a/vtk/src/helperClasses/SpawnPointCallback.cpp +++ b/vtk/src/commands/SpawnPointCallback.cpp @@ -7,7 +7,7 @@ #include #include -#include "CartographicTransformation.h" +#include "../CartographicTransformation.h" void convertDisplayToWorld(vtkRenderer* renderer, int x, int y, double *worldPos) { double displayPos[3] = {static_cast(x), static_cast(y), 0.0}; diff --git a/vtk/src/helperClasses/SpawnPointCallback.h b/vtk/src/commands/SpawnPointCallback.h similarity index 100% rename from vtk/src/helperClasses/SpawnPointCallback.h rename to vtk/src/commands/SpawnPointCallback.h diff --git a/vtk/src/commands/TimerCallbackCommand.cpp b/vtk/src/commands/TimerCallbackCommand.cpp index d8edfd7..94e9de9 100644 --- a/vtk/src/commands/TimerCallbackCommand.cpp +++ b/vtk/src/commands/TimerCallbackCommand.cpp @@ -1,5 +1,5 @@ #include "TimerCallbackCommand.h" -#include "../helperClasses/Program.h" +#include "../Program.h" TimerCallbackCommand::TimerCallbackCommand() : dt(3600), maxTime(3600*24*365), time(0) {} diff --git a/vtk/src/commands/TimerCallbackCommand.h b/vtk/src/commands/TimerCallbackCommand.h index ff478b8..618c7bf 100644 --- a/vtk/src/commands/TimerCallbackCommand.h +++ b/vtk/src/commands/TimerCallbackCommand.h @@ -2,7 +2,7 @@ #define TIMERCALLBACKCOMMAND_H #include -#include "../helperClasses/Program.h" +#include "../Program.h" class TimerCallbackCommand : public vtkCallbackCommand { public: diff --git a/vtk/src/helperClasses/BackgroundImage.cpp b/vtk/src/layers/BackgroundImage.cpp similarity index 100% rename from vtk/src/helperClasses/BackgroundImage.cpp rename to vtk/src/layers/BackgroundImage.cpp diff --git a/vtk/src/helperClasses/BackgroundImage.h b/vtk/src/layers/BackgroundImage.h similarity index 100% rename from vtk/src/helperClasses/BackgroundImage.h rename to vtk/src/layers/BackgroundImage.h diff --git a/vtk/src/helperClasses/EGlyphLayer.cpp b/vtk/src/layers/EGlyphLayer.cpp similarity index 98% rename from vtk/src/helperClasses/EGlyphLayer.cpp rename to vtk/src/layers/EGlyphLayer.cpp index 0722a34..cb91825 100644 --- a/vtk/src/helperClasses/EGlyphLayer.cpp +++ b/vtk/src/layers/EGlyphLayer.cpp @@ -13,7 +13,7 @@ #include #include #include -#include "CartographicTransformation.h" +#include "../CartographicTransformation.h" using namespace netCDF; using namespace std; diff --git a/vtk/src/helperClasses/EGlyphLayer.h b/vtk/src/layers/EGlyphLayer.h similarity index 100% rename from vtk/src/helperClasses/EGlyphLayer.h rename to vtk/src/layers/EGlyphLayer.h diff --git a/vtk/src/helperClasses/LGlyphLayer.cpp b/vtk/src/layers/LGlyphLayer.cpp similarity index 86% rename from vtk/src/helperClasses/LGlyphLayer.cpp rename to vtk/src/layers/LGlyphLayer.cpp index 6fe6caf..845d628 100644 --- a/vtk/src/helperClasses/LGlyphLayer.cpp +++ b/vtk/src/layers/LGlyphLayer.cpp @@ -1,5 +1,5 @@ #include "LGlyphLayer.h" -#include "SpawnPointCallback.h" +#include "../commands/SpawnPointCallback.h" #include #include #include @@ -15,7 +15,7 @@ #include #include -#include "CartographicTransformation.h" +#include "../CartographicTransformation.h" vtkSmartPointer LGlyphLayer::createSpawnPointCallback() { @@ -26,7 +26,6 @@ vtkSmartPointer LGlyphLayer::createSpawnPointCallback() { return newPointCallBack; } -// TODO: how do we handle mapping between pixelspace and lat/lon (needed for advection)? Current idea: store the vtkPoints in lat/lon system, then apply a transformfilter to map them to the current window geometry. This should allow for a changing viewport as well - we can query the new camera position and map accordingly. // Further notes; current thinking is to allow tracking a particle's age by using a scalar array in the VtkPolyData. This would be incremented for every tick/updateData function call. // Another challenge is the concept of beaching; dead particles must not be included in the advect function call (wasted computations), but they should not be outright deleted from the vtkPoints either (we still want to display them). Working Solution: have another array of ints in the vtkPolyData, which tracks for how many calls of UpdateData a given particle has not had its position changed. If this int reaches some treshold (5? 10? 3? needs some testing), exclude the particle from the advect call. // @@ -94,3 +93,13 @@ void LGlyphLayer::updateData(int t) { } this->points->Modified(); } + +void LGlyphLayer::addObservers(vtkSmartPointer interactor) { + auto newPointCallBack = vtkSmartPointer::New(); + newPointCallBack->setData(data); + newPointCallBack->setPoints(points); + newPointCallBack->setRen(ren); + interactor->AddObserver(vtkCommand::LeftButtonPressEvent, newPointCallBack); + interactor->AddObserver(vtkCommand::LeftButtonReleaseEvent, newPointCallBack); + interactor->AddObserver(vtkCommand::MouseMoveEvent, newPointCallBack); +} diff --git a/vtk/src/helperClasses/LGlyphLayer.h b/vtk/src/layers/LGlyphLayer.h similarity index 87% rename from vtk/src/helperClasses/LGlyphLayer.h rename to vtk/src/layers/LGlyphLayer.h index edc751d..22993b4 100644 --- a/vtk/src/helperClasses/LGlyphLayer.h +++ b/vtk/src/layers/LGlyphLayer.h @@ -2,7 +2,7 @@ #define LGLYPHLAYER_H #include "Layer.h" -#include "SpawnPointCallback.h" +#include "../commands/SpawnPointCallback.h" #include #include @@ -31,6 +31,8 @@ public: void updateData(int t) override; vtkSmartPointer createSpawnPointCallback(); + + void addObservers(vtkSmartPointer interactor) override; }; #endif diff --git a/vtk/src/helperClasses/Layer.cpp b/vtk/src/layers/Layer.cpp similarity index 58% rename from vtk/src/helperClasses/Layer.cpp rename to vtk/src/layers/Layer.cpp index f5a4a50..6b7bb56 100644 --- a/vtk/src/helperClasses/Layer.cpp +++ b/vtk/src/layers/Layer.cpp @@ -11,7 +11,6 @@ vtkSmartPointer Layer::getLayer() { void Layer::updateData(int t) { } - -void Layer::addObserver(const char *event, vtkCommand *observer) { - this->getLayer()->GetRenderWindow()->GetInteractor()->AddObserver(event, observer); +void Layer::addObservers(vtkSmartPointer interactor) { + // By default, do nothing. } diff --git a/vtk/src/helperClasses/Layer.h b/vtk/src/layers/Layer.h similarity index 78% rename from vtk/src/helperClasses/Layer.h rename to vtk/src/layers/Layer.h index 5a357c5..7ee86b1 100644 --- a/vtk/src/helperClasses/Layer.h +++ b/vtk/src/layers/Layer.h @@ -24,10 +24,9 @@ public: virtual void updateData(int t); /** Adds an observer to the renderWindowinteractor within which this layer is active. - * @param event : the specific event type to subscribe to (see the vtkCommand::EventIds enum) - * @param observer : the observer to add. + * @param interactor : pointer to the interactor that observers can be added to. */ - virtual void addObserver(const char *event, vtkCommand *observer); + virtual void addObservers(vtkSmartPointer interactor); }; #endif diff --git a/vtk/src/main.cpp b/vtk/src/main.cpp index 7be9e38..fb89ea4 100644 --- a/vtk/src/main.cpp +++ b/vtk/src/main.cpp @@ -8,10 +8,10 @@ #include #include -#include "helperClasses/BackgroundImage.h" -#include "helperClasses/EGlyphLayer.h" -#include "helperClasses/LGlyphLayer.h" -#include "helperClasses/Program.h" +#include "layers/BackgroundImage.h" +#include "layers/EGlyphLayer.h" +#include "layers/LGlyphLayer.h" +#include "Program.h" using namespace std; @@ -25,8 +25,6 @@ int main() { program->addLayer(new EGlyphLayer()); program->addLayer(l); - // auto program = new Program(bg, e, l); - program->setLagrangeInteractor(l->createSpawnPointCallback()); program->render(); return EXIT_SUCCESS;