fix: stylistic changes + addObservers
This commit is contained in:
parent
e0f92e4d9e
commit
3f7de8fdce
|
|
@ -32,21 +32,21 @@ endif()
|
||||||
find_package(netCDF REQUIRED)
|
find_package(netCDF REQUIRED)
|
||||||
|
|
||||||
add_executable(VtkBase MACOSX_BUNDLE main.cpp
|
add_executable(VtkBase MACOSX_BUNDLE main.cpp
|
||||||
helperClasses/BackgroundImage.cpp
|
layers/BackgroundImage.cpp
|
||||||
helperClasses/BackgroundImage.h
|
layers/BackgroundImage.h
|
||||||
helperClasses/EGlyphLayer.cpp
|
layers/EGlyphLayer.cpp
|
||||||
helperClasses/EGlyphLayer.h
|
layers/EGlyphLayer.h
|
||||||
helperClasses/Layer.cpp
|
layers/Layer.cpp
|
||||||
helperClasses/Layer.h
|
layers/Layer.h
|
||||||
helperClasses/LGlyphLayer.cpp
|
layers/LGlyphLayer.cpp
|
||||||
helperClasses/LGlyphLayer.h
|
layers/LGlyphLayer.h
|
||||||
helperClasses/Program.cpp
|
Program.cpp
|
||||||
helperClasses/Program.h
|
Program.h
|
||||||
commands/TimerCallbackCommand.h
|
commands/TimerCallbackCommand.h
|
||||||
commands/TimerCallbackCommand.cpp
|
commands/TimerCallbackCommand.cpp
|
||||||
helperClasses/SpawnPointCallback.h
|
commands/SpawnPointCallback.h
|
||||||
helperClasses/SpawnPointCallback.cpp
|
commands/SpawnPointCallback.cpp
|
||||||
helperClasses/CartographicTransformation.cpp
|
CartographicTransformation.cpp
|
||||||
)
|
)
|
||||||
|
|
||||||
execute_process(
|
execute_process(
|
||||||
|
|
|
||||||
|
|
@ -18,8 +18,8 @@
|
||||||
#include <vtkInteractorStyleUser.h>
|
#include <vtkInteractorStyleUser.h>
|
||||||
|
|
||||||
#include "Program.h"
|
#include "Program.h"
|
||||||
#include "../commands/TimerCallbackCommand.h"
|
#include "commands/TimerCallbackCommand.h"
|
||||||
#include "SpawnPointCallback.h"
|
#include "commands/SpawnPointCallback.h"
|
||||||
|
|
||||||
void Program::setWinProperties() {
|
void Program::setWinProperties() {
|
||||||
this->win->SetWindowName("Simulation");
|
this->win->SetWindowName("Simulation");
|
||||||
|
|
@ -66,25 +66,21 @@ void Program::removeLayer(Layer *layer) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
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) {
|
void Program::updateData(int t) {
|
||||||
this->win->Render();
|
win->Render();
|
||||||
for (Layer *l: layers) {
|
for (Layer *l: layers) {
|
||||||
l->updateData(t);
|
l->updateData(t);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Program::setupInteractions() {
|
||||||
|
for (Layer *l: layers) {
|
||||||
|
l->addObservers(interact);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void Program::render() {
|
void Program::render() {
|
||||||
this->win->Render();
|
setupInteractions();
|
||||||
this->interact->Start();
|
win->Render();
|
||||||
|
interact->Start();
|
||||||
}
|
}
|
||||||
|
|
@ -5,8 +5,8 @@
|
||||||
#include <vtkRenderWindowInteractor.h>
|
#include <vtkRenderWindowInteractor.h>
|
||||||
#include <vtkRenderer.h>
|
#include <vtkRenderer.h>
|
||||||
|
|
||||||
#include "Layer.h"
|
#include "layers/Layer.h"
|
||||||
#include "SpawnPointCallback.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.
|
/** 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.
|
* 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 setupTimer();
|
||||||
|
|
||||||
|
void setupInteractions();
|
||||||
|
|
||||||
public:
|
public:
|
||||||
/** Constructor.
|
/** Constructor.
|
||||||
*/
|
*/
|
||||||
|
|
@ -50,18 +52,15 @@ public:
|
||||||
*/
|
*/
|
||||||
void removeLayer(Layer *layer);
|
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.
|
/** This function updates the data for the associated layers to the given timestamp.
|
||||||
* Also updates the renderWindow.
|
* Also updates the renderWindow.
|
||||||
* @param t : the timestamp to update the data to.
|
* @param t : the timestamp to update the data to.
|
||||||
*/
|
*/
|
||||||
void updateData(int t);
|
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();
|
void render();
|
||||||
};
|
};
|
||||||
|
|
@ -7,7 +7,7 @@
|
||||||
#include <vtkCommand.h>
|
#include <vtkCommand.h>
|
||||||
#include <vtkRenderWindow.h>
|
#include <vtkRenderWindow.h>
|
||||||
|
|
||||||
#include "CartographicTransformation.h"
|
#include "../CartographicTransformation.h"
|
||||||
|
|
||||||
void convertDisplayToWorld(vtkRenderer* renderer, int x, int y, double *worldPos) {
|
void convertDisplayToWorld(vtkRenderer* renderer, int x, int y, double *worldPos) {
|
||||||
double displayPos[3] = {static_cast<double>(x), static_cast<double>(y), 0.0};
|
double displayPos[3] = {static_cast<double>(x), static_cast<double>(y), 0.0};
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
#include "TimerCallbackCommand.h"
|
#include "TimerCallbackCommand.h"
|
||||||
#include "../helperClasses/Program.h"
|
#include "../Program.h"
|
||||||
|
|
||||||
|
|
||||||
TimerCallbackCommand::TimerCallbackCommand() : dt(3600), maxTime(3600*24*365), time(0) {}
|
TimerCallbackCommand::TimerCallbackCommand() : dt(3600), maxTime(3600*24*365), time(0) {}
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,7 @@
|
||||||
#define TIMERCALLBACKCOMMAND_H
|
#define TIMERCALLBACKCOMMAND_H
|
||||||
|
|
||||||
#include <vtkCallbackCommand.h>
|
#include <vtkCallbackCommand.h>
|
||||||
#include "../helperClasses/Program.h"
|
#include "../Program.h"
|
||||||
|
|
||||||
class TimerCallbackCommand : public vtkCallbackCommand {
|
class TimerCallbackCommand : public vtkCallbackCommand {
|
||||||
public:
|
public:
|
||||||
|
|
|
||||||
|
|
@ -13,7 +13,7 @@
|
||||||
#include <vtkVertexGlyphFilter.h>
|
#include <vtkVertexGlyphFilter.h>
|
||||||
#include <netcdf>
|
#include <netcdf>
|
||||||
#include <vtkArrowSource.h>
|
#include <vtkArrowSource.h>
|
||||||
#include "CartographicTransformation.h"
|
#include "../CartographicTransformation.h"
|
||||||
|
|
||||||
using namespace netCDF;
|
using namespace netCDF;
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
#include "LGlyphLayer.h"
|
#include "LGlyphLayer.h"
|
||||||
#include "SpawnPointCallback.h"
|
#include "../commands/SpawnPointCallback.h"
|
||||||
#include <vtkActor2D.h>
|
#include <vtkActor2D.h>
|
||||||
#include <vtkGlyph2D.h>
|
#include <vtkGlyph2D.h>
|
||||||
#include <vtkGlyphSource2D.h>
|
#include <vtkGlyphSource2D.h>
|
||||||
|
|
@ -15,7 +15,7 @@
|
||||||
#include <vtkRenderWindow.h>
|
#include <vtkRenderWindow.h>
|
||||||
#include <vtkCamera.h>
|
#include <vtkCamera.h>
|
||||||
|
|
||||||
#include "CartographicTransformation.h"
|
#include "../CartographicTransformation.h"
|
||||||
|
|
||||||
|
|
||||||
vtkSmartPointer<SpawnPointCallback> LGlyphLayer::createSpawnPointCallback() {
|
vtkSmartPointer<SpawnPointCallback> LGlyphLayer::createSpawnPointCallback() {
|
||||||
|
|
@ -26,7 +26,6 @@ vtkSmartPointer<SpawnPointCallback> LGlyphLayer::createSpawnPointCallback() {
|
||||||
return newPointCallBack;
|
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.
|
// 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.
|
// 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();
|
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
|
#define LGLYPHLAYER_H
|
||||||
|
|
||||||
#include "Layer.h"
|
#include "Layer.h"
|
||||||
#include "SpawnPointCallback.h"
|
#include "../commands/SpawnPointCallback.h"
|
||||||
#include <vtkPolyData.h>
|
#include <vtkPolyData.h>
|
||||||
#include <vtkInteractorStyle.h>
|
#include <vtkInteractorStyle.h>
|
||||||
|
|
||||||
|
|
@ -31,6 +31,8 @@ public:
|
||||||
void updateData(int t) override;
|
void updateData(int t) override;
|
||||||
|
|
||||||
vtkSmartPointer<SpawnPointCallback> createSpawnPointCallback();
|
vtkSmartPointer<SpawnPointCallback> createSpawnPointCallback();
|
||||||
|
|
||||||
|
void addObservers(vtkSmartPointer<vtkRenderWindowInteractor> interactor) override;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
@ -11,7 +11,6 @@ vtkSmartPointer<vtkRenderer> Layer::getLayer() {
|
||||||
void Layer::updateData(int t) {
|
void Layer::updateData(int t) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Layer::addObservers(vtkSmartPointer<vtkRenderWindowInteractor> interactor) {
|
||||||
void Layer::addObserver(const char *event, vtkCommand *observer) {
|
// By default, do nothing.
|
||||||
this->getLayer()->GetRenderWindow()->GetInteractor()->AddObserver(event, observer);
|
|
||||||
}
|
}
|
||||||
|
|
@ -24,10 +24,9 @@ public:
|
||||||
virtual void updateData(int t);
|
virtual void updateData(int t);
|
||||||
|
|
||||||
/** Adds an observer to the renderWindowinteractor within which this layer is active.
|
/** 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 interactor : pointer to the interactor that observers can be added to.
|
||||||
* @param observer : the observer to add.
|
|
||||||
*/
|
*/
|
||||||
virtual void addObserver(const char *event, vtkCommand *observer);
|
virtual void addObservers(vtkSmartPointer<vtkRenderWindowInteractor> interactor);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
@ -8,10 +8,10 @@
|
||||||
#include <vtkRenderer.h>
|
#include <vtkRenderer.h>
|
||||||
#include <vtkVertexGlyphFilter.h>
|
#include <vtkVertexGlyphFilter.h>
|
||||||
|
|
||||||
#include "helperClasses/BackgroundImage.h"
|
#include "layers/BackgroundImage.h"
|
||||||
#include "helperClasses/EGlyphLayer.h"
|
#include "layers/EGlyphLayer.h"
|
||||||
#include "helperClasses/LGlyphLayer.h"
|
#include "layers/LGlyphLayer.h"
|
||||||
#include "helperClasses/Program.h"
|
#include "Program.h"
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
|
|
@ -25,8 +25,6 @@ int main() {
|
||||||
program->addLayer(new EGlyphLayer());
|
program->addLayer(new EGlyphLayer());
|
||||||
program->addLayer(l);
|
program->addLayer(l);
|
||||||
|
|
||||||
// auto program = new Program(bg, e, l);
|
|
||||||
program->setLagrangeInteractor(l->createSpawnPointCallback());
|
|
||||||
program->render();
|
program->render();
|
||||||
|
|
||||||
return EXIT_SUCCESS;
|
return EXIT_SUCCESS;
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue