fix: stylistic changes + addObservers
This commit is contained in:
parent
e0f92e4d9e
commit
3f7de8fdce
|
|
@ -32,21 +32,21 @@ endif()
|
|||
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
|
||||
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(
|
||||
|
|
|
|||
|
|
@ -18,8 +18,8 @@
|
|||
#include <vtkInteractorStyleUser.h>
|
||||
|
||||
#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,10 +50,10 @@ 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) {
|
||||
|
|
@ -62,29 +62,25 @@ void Program::removeLayer(Layer *layer) {
|
|||
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);
|
||||
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();
|
||||
}
|
||||
|
|
@ -5,8 +5,8 @@
|
|||
#include <vtkRenderWindowInteractor.h>
|
||||
#include <vtkRenderer.h>
|
||||
|
||||
#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,18 +52,15 @@ 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();
|
||||
};
|
||||
|
|
@ -7,7 +7,7 @@
|
|||
#include <vtkCommand.h>
|
||||
#include <vtkRenderWindow.h>
|
||||
|
||||
#include "CartographicTransformation.h"
|
||||
#include "../CartographicTransformation.h"
|
||||
|
||||
void convertDisplayToWorld(vtkRenderer* renderer, int x, int y, double *worldPos) {
|
||||
double displayPos[3] = {static_cast<double>(x), static_cast<double>(y), 0.0};
|
||||
|
|
@ -1,5 +1,5 @@
|
|||
#include "TimerCallbackCommand.h"
|
||||
#include "../helperClasses/Program.h"
|
||||
#include "../Program.h"
|
||||
|
||||
|
||||
TimerCallbackCommand::TimerCallbackCommand() : dt(3600), maxTime(3600*24*365), time(0) {}
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
#define TIMERCALLBACKCOMMAND_H
|
||||
|
||||
#include <vtkCallbackCommand.h>
|
||||
#include "../helperClasses/Program.h"
|
||||
#include "../Program.h"
|
||||
|
||||
class TimerCallbackCommand : public vtkCallbackCommand {
|
||||
public:
|
||||
|
|
|
|||
|
|
@ -13,7 +13,7 @@
|
|||
#include <vtkVertexGlyphFilter.h>
|
||||
#include <netcdf>
|
||||
#include <vtkArrowSource.h>
|
||||
#include "CartographicTransformation.h"
|
||||
#include "../CartographicTransformation.h"
|
||||
|
||||
using namespace netCDF;
|
||||
using namespace std;
|
||||
|
|
@ -1,5 +1,5 @@
|
|||
#include "LGlyphLayer.h"
|
||||
#include "SpawnPointCallback.h"
|
||||
#include "../commands/SpawnPointCallback.h"
|
||||
#include <vtkActor2D.h>
|
||||
#include <vtkGlyph2D.h>
|
||||
#include <vtkGlyphSource2D.h>
|
||||
|
|
@ -15,7 +15,7 @@
|
|||
#include <vtkRenderWindow.h>
|
||||
#include <vtkCamera.h>
|
||||
|
||||
#include "CartographicTransformation.h"
|
||||
#include "../CartographicTransformation.h"
|
||||
|
||||
|
||||
vtkSmartPointer<SpawnPointCallback> LGlyphLayer::createSpawnPointCallback() {
|
||||
|
|
@ -26,7 +26,6 @@ vtkSmartPointer<SpawnPointCallback> 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<vtkRenderWindowInteractor> interactor) {
|
||||
auto newPointCallBack = vtkSmartPointer<SpawnPointCallback>::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);
|
||||
}
|
||||
|
|
@ -2,7 +2,7 @@
|
|||
#define LGLYPHLAYER_H
|
||||
|
||||
#include "Layer.h"
|
||||
#include "SpawnPointCallback.h"
|
||||
#include "../commands/SpawnPointCallback.h"
|
||||
#include <vtkPolyData.h>
|
||||
#include <vtkInteractorStyle.h>
|
||||
|
||||
|
|
@ -31,6 +31,8 @@ public:
|
|||
void updateData(int t) override;
|
||||
|
||||
vtkSmartPointer<SpawnPointCallback> createSpawnPointCallback();
|
||||
|
||||
void addObservers(vtkSmartPointer<vtkRenderWindowInteractor> interactor) override;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
@ -11,7 +11,6 @@ vtkSmartPointer<vtkRenderer> 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<vtkRenderWindowInteractor> interactor) {
|
||||
// By default, do nothing.
|
||||
}
|
||||
|
|
@ -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<vtkRenderWindowInteractor> interactor);
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
@ -8,10 +8,10 @@
|
|||
#include <vtkRenderer.h>
|
||||
#include <vtkVertexGlyphFilter.h>
|
||||
|
||||
#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;
|
||||
|
|
|
|||
Loading…
Reference in New Issue