Merge branch 'robin-spawn-particles' into djairo-vtk-test
This commit is contained in:
commit
06315a3d52
|
|
@ -1,2 +1,2 @@
|
|||
.DS_Store
|
||||
|
||||
.idea
|
||||
|
|
|
|||
|
|
@ -44,6 +44,8 @@ add_executable(VtkBase MACOSX_BUNDLE main.cpp
|
|||
helperClasses/Program.h
|
||||
commands/TimerCallbackCommand.h
|
||||
commands/TimerCallbackCommand.cpp
|
||||
helperClasses/SpawnPointCallback.h
|
||||
helperClasses/SpawnPointCallback.cpp
|
||||
)
|
||||
|
||||
execute_process(
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
#include "LGlyphLayer.h"
|
||||
#include "SpawnPointCallback.h"
|
||||
#include <vtkActor2D.h>
|
||||
#include <vtkGlyph2D.h>
|
||||
#include <vtkGlyphSource2D.h>
|
||||
|
|
@ -6,6 +7,17 @@
|
|||
#include <vtkPolyDataMapper2D.h>
|
||||
#include <vtkProperty2D.h>
|
||||
#include <vtkVertexGlyphFilter.h>
|
||||
#include <vtkInteractorStyle.h>
|
||||
#include <vtkInteractorStyleUser.h>
|
||||
|
||||
|
||||
vtkSmartPointer<SpawnPointCallback> LGlyphLayer::createSpawnPointCallback() {
|
||||
auto newPointCallBack = vtkSmartPointer<SpawnPointCallback>::New();
|
||||
newPointCallBack->setData(data);
|
||||
newPointCallBack->setPoints(points);
|
||||
return newPointCallBack;
|
||||
}
|
||||
|
||||
|
||||
// TODO: add interactionStyle functionality
|
||||
// TODO: add timer + advection (probably from the program class not here)
|
||||
|
|
|
|||
|
|
@ -2,7 +2,9 @@
|
|||
#define LGLYPHLAYER_H
|
||||
|
||||
#include "Layer.h"
|
||||
#include "SpawnPointCallback.h"
|
||||
#include <vtkPolyData.h>
|
||||
#include <vtkInteractorStyle.h>
|
||||
|
||||
/** Implements the Layer class for the case of a Lagrangian visualization.
|
||||
* Specifically, this class models the Lagrangian particles in the simulation using the 'glyph' mark and 'transparency' channel to denote age.
|
||||
|
|
@ -13,6 +15,7 @@ private:
|
|||
vtkSmartPointer<vtkPolyData> data;
|
||||
|
||||
|
||||
|
||||
public:
|
||||
/** Constructor.
|
||||
*/
|
||||
|
|
@ -27,6 +30,7 @@ public:
|
|||
*/
|
||||
void updateData(int t) override;
|
||||
|
||||
vtkSmartPointer<SpawnPointCallback> createSpawnPointCallback();
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -15,9 +15,11 @@
|
|||
#include <vtkArrowSource.h>
|
||||
#include <vtkNew.h>
|
||||
#include <vtkCallbackCommand.h>
|
||||
#include <vtkInteractorStyleUser.h>
|
||||
|
||||
#include "Program.h"
|
||||
#include "../commands/TimerCallbackCommand.h"
|
||||
#include "SpawnPointCallback.h"
|
||||
|
||||
void Program::setWinProperties() {
|
||||
this->win->SetWindowName("Simulation");
|
||||
|
|
@ -27,6 +29,8 @@ void Program::setWinProperties() {
|
|||
this->interact->SetRenderWindow(this->win);
|
||||
this->interact->Initialize();
|
||||
|
||||
vtkNew<vtkInteractorStyleUser> style;
|
||||
interact->SetInteractorStyle(style);
|
||||
}
|
||||
|
||||
void Program::setupTimer() {
|
||||
|
|
@ -36,7 +40,6 @@ void Program::setupTimer() {
|
|||
this->interact->CreateRepeatingTimer(17); // 60 fps == 1000 / 60 == 16.7 ms per frame
|
||||
}
|
||||
|
||||
|
||||
Program::Program(Layer *bg, Layer *e, Layer *l) : background(bg), euler(e), lagrange(l), win(), interact() {
|
||||
this->win = vtkSmartPointer<vtkRenderWindow>::New();
|
||||
this->interact = vtkSmartPointer<vtkRenderWindowInteractor>::New();
|
||||
|
|
@ -71,7 +74,11 @@ void Program::setLagrange(Layer *l) {
|
|||
this->win->AddRenderer(l->getLayer());
|
||||
}
|
||||
|
||||
// void Program::addInteractionStyle(vtkInteractorStyle style);
|
||||
void Program::setLagrangeInteractor(SpawnPointCallback *cb){
|
||||
interact->AddObserver(vtkCommand::LeftButtonPressEvent, cb);
|
||||
interact->AddObserver(vtkCommand::LeftButtonReleaseEvent, cb);
|
||||
interact->AddObserver(vtkCommand::MouseMoveEvent, cb);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@
|
|||
#include <vtkRenderer.h>
|
||||
|
||||
#include "Layer.h"
|
||||
#include "SpawnPointCallback.h"
|
||||
|
||||
class Program {
|
||||
private:
|
||||
|
|
@ -24,6 +25,7 @@ public:
|
|||
void setBackground(Layer *bg);
|
||||
void setEuler(Layer *e);
|
||||
void setLagrange(Layer *l);
|
||||
void setLagrangeInteractor(SpawnPointCallback *cb);
|
||||
|
||||
// void addInteractionStyle(vtkInteractorStyle style);
|
||||
void updateData(int t);
|
||||
|
|
|
|||
|
|
@ -0,0 +1,60 @@
|
|||
#include "SpawnPointCallback.h"
|
||||
|
||||
#include <vtkVertex.h>
|
||||
#include <vtkRenderer.h>
|
||||
#include <vtkRenderWindowInteractor.h>
|
||||
#include <vtkSmartPointer.h>
|
||||
#include <vtkCommand.h>
|
||||
#include <vtkRenderWindow.h>
|
||||
|
||||
void convertDisplayToWorld(vtkRenderer* renderer, int x, int y, double *worldPos) {
|
||||
double displayPos[3] = {static_cast<double>(x), static_cast<double>(y), 0.0};
|
||||
renderer->SetDisplayPoint(displayPos);
|
||||
renderer->DisplayToWorld();
|
||||
renderer->GetWorldPoint(worldPos);
|
||||
}
|
||||
|
||||
void SpawnPointCallback::Execute(vtkObject *caller, unsigned long evId, void *callData) {
|
||||
// Note the use of reinterpret_cast to cast the caller to the expected type.
|
||||
auto interactor = reinterpret_cast<vtkRenderWindowInteractor *>(caller);
|
||||
|
||||
if (evId == vtkCommand::LeftButtonPressEvent) {
|
||||
dragging = true;
|
||||
}
|
||||
if (evId == vtkCommand::LeftButtonReleaseEvent) {
|
||||
dragging = false;
|
||||
}
|
||||
if (!dragging) {
|
||||
return;
|
||||
}
|
||||
|
||||
int x, y;
|
||||
interactor->GetEventPosition(x, y);
|
||||
|
||||
vtkIdType id = points->InsertNextPoint(x, y, 0);
|
||||
data->SetPoints(points);
|
||||
|
||||
vtkSmartPointer<vtkVertex> vertex = vtkSmartPointer<vtkVertex>::New();
|
||||
vertex->GetPointIds()->SetId(0, id);
|
||||
|
||||
vtkSmartPointer<vtkCellArray> vertices = vtkSmartPointer<vtkCellArray>::New();
|
||||
vertices->InsertNextCell(vertex);
|
||||
data->SetVerts(vertices);
|
||||
// data->Modified(); // These might be needed im not sure.
|
||||
// ren->GetRenderWindow()->Render();
|
||||
}
|
||||
|
||||
|
||||
SpawnPointCallback::SpawnPointCallback() : data(nullptr), points(nullptr) {}
|
||||
|
||||
SpawnPointCallback *SpawnPointCallback::New() {
|
||||
return new SpawnPointCallback;
|
||||
}
|
||||
|
||||
void SpawnPointCallback::setData(const vtkSmartPointer<vtkPolyData> &data) {
|
||||
this->data = data;
|
||||
}
|
||||
|
||||
void SpawnPointCallback::setPoints(const vtkSmartPointer<vtkPoints> &points) {
|
||||
this->points = points;
|
||||
}
|
||||
|
|
@ -0,0 +1,31 @@
|
|||
#ifndef VTKBASE_SPAWNPOINTCALLBACK_H
|
||||
#define VTKBASE_SPAWNPOINTCALLBACK_H
|
||||
|
||||
|
||||
#include <vtkCallbackCommand.h>
|
||||
#include <vtkRenderWindowInteractor.h>
|
||||
#include <vtkPoints.h>
|
||||
#include <vtkPolyData.h>
|
||||
|
||||
class SpawnPointCallback : public vtkCallbackCommand {
|
||||
|
||||
public:
|
||||
static SpawnPointCallback *New();
|
||||
SpawnPointCallback();
|
||||
|
||||
void setPoints(const vtkSmartPointer<vtkPoints> &points);
|
||||
|
||||
void setData(const vtkSmartPointer<vtkPolyData> &data);
|
||||
|
||||
private:
|
||||
vtkSmartPointer<vtkPolyData> data;
|
||||
vtkSmartPointer<vtkPoints> points;
|
||||
public:
|
||||
|
||||
private:
|
||||
void Execute(vtkObject *caller, unsigned long evId, void *callData) override;
|
||||
bool dragging = false;
|
||||
};
|
||||
|
||||
|
||||
#endif //VTKBASE_SPAWNPOINTCALLBACK_H
|
||||
|
|
@ -23,6 +23,7 @@ int main() {
|
|||
l->spoofPoints();
|
||||
|
||||
auto program = new Program(bg, e, l);
|
||||
program->setLagrangeInteractor(l->createSpawnPointCallback());
|
||||
program->render();
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
|
|
|
|||
Loading…
Reference in New Issue