From 4d743a42c1408251f7421ed67d75d7d7f129387c Mon Sep 17 00:00:00 2001 From: djairoh Date: Sun, 5 May 2024 21:45:02 +0200 Subject: [PATCH 01/13] feat (wip): implementing camera zooming and panning functionality --- vtk/src/CMakeLists.txt | 32 +++++----- vtk/src/Program.cpp | 15 ++++- vtk/src/Program.h | 12 +++- vtk/src/commands/CameraMoveCallback.cpp | 74 +++++++++++++++++++++++ vtk/src/commands/CameraMoveCallback.h | 27 +++++++++ vtk/src/commands/SpawnPointCallback.cpp | 2 +- vtk/src/commands/TimerCallbackCommand.cpp | 2 +- vtk/src/layers/BackgroundImage.cpp | 13 ++++ vtk/src/layers/BackgroundImage.h | 3 + vtk/src/layers/EGlyphLayer.cpp | 6 +- vtk/src/layers/LGlyphLayer.cpp | 3 +- vtk/src/layers/Layer.cpp | 5 ++ vtk/src/layers/Layer.h | 5 ++ vtk/src/main.cpp | 3 + 14 files changed, 180 insertions(+), 22 deletions(-) create mode 100644 vtk/src/commands/CameraMoveCallback.cpp create mode 100644 vtk/src/commands/CameraMoveCallback.h diff --git a/vtk/src/CMakeLists.txt b/vtk/src/CMakeLists.txt index ef2a3aa..1ba0d72 100644 --- a/vtk/src/CMakeLists.txt +++ b/vtk/src/CMakeLists.txt @@ -14,6 +14,8 @@ find_package(VTK COMPONENTS FiltersProgrammable FiltersSources ImagingSources + ImagingGeneral + ImagingCore InteractionStyle IOImage RenderingContextOpenGL2 @@ -32,21 +34,23 @@ endif() find_package(netCDF REQUIRED) 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 + CartographicTransformation.cpp + commands/CameraMoveCallback.cpp + commands/CameraMoveCallback.h + commands/SpawnPointCallback.cpp + commands/SpawnPointCallback.h commands/TimerCallbackCommand.cpp - commands/SpawnPointCallback.h - commands/SpawnPointCallback.cpp - CartographicTransformation.cpp + commands/TimerCallbackCommand.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 ) execute_process( diff --git a/vtk/src/Program.cpp b/vtk/src/Program.cpp index f5d1a93..d35aa6a 100644 --- a/vtk/src/Program.cpp +++ b/vtk/src/Program.cpp @@ -19,7 +19,8 @@ #include "Program.h" #include "commands/TimerCallbackCommand.h" -#include "commands/SpawnPointCallback.h" +#include "CartographicTransformation.h" +#include "commands/CameraMoveCallback.h" void Program::setWinProperties() { this->win->SetWindowName("Simulation"); @@ -40,17 +41,28 @@ void Program::setupTimer() { 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() { this->win = vtkSmartPointer::New(); this->interact = vtkSmartPointer::New(); + this->cam = createNormalisedCamera(); this->win->SetNumberOfLayers(0); setWinProperties(); setupTimer(); + 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); @@ -66,6 +78,7 @@ void Program::removeLayer(Layer *layer) { } } + void Program::updateData(int t) { win->Render(); for (Layer *l: layers) { diff --git a/vtk/src/Program.h b/vtk/src/Program.h index 4097e4c..e92b5aa 100644 --- a/vtk/src/Program.h +++ b/vtk/src/Program.h @@ -6,7 +6,6 @@ #include #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. @@ -25,6 +24,11 @@ private: */ vtkSmartPointer interact; + + /** The camera used by all layers for this program. + */ + vtkSmartPointer cam; + /** This function sets some default properties on the vtkRenderWindow. Extracted to its' own function to keep the constructor from becoming cluttered. */ void setWinProperties(); @@ -33,8 +37,14 @@ private: */ void setupTimer(); + /** This function adds all interactors of each layer to the interactor/window + */ void setupInteractions(); + /** This function sets up the camera's associated movement callbacks.. + */ + void setupCameraCallback(); + public: /** Constructor. */ diff --git a/vtk/src/commands/CameraMoveCallback.cpp b/vtk/src/commands/CameraMoveCallback.cpp new file mode 100644 index 0000000..6a92f0b --- /dev/null +++ b/vtk/src/commands/CameraMoveCallback.cpp @@ -0,0 +1,74 @@ +#include "CameraMoveCallback.h" + +#include +#include +#include +#include +#include +#include + +using std::string; + +void CameraMoveCallback::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(caller); + + switch (evId) { + case vtkCommand::KeyPressEvent: + pan(interactor->GetKeySym()); + break; + case vtkCommand::MouseWheelForwardEvent: + zoom(true); + break; + case vtkCommand::MouseWheelBackwardEvent: + zoom(false); + break; + default: + break; + } +} + +void CameraMoveCallback::zoom(const bool in) { + double pos[3]; + this->cam->GetPosition(pos); + + if (in) { + pos[2] -= 50; + } else { + pos[2] += 50; + } + this->cam->SetPosition(pos); + +} + +void CameraMoveCallback::pan(const string dir) { + double pos[3]; + this->cam->GetPosition(pos); + + if (dir == "Left" or dir == "h") { + pos[0] -= 1; + this->cam->SetPosition(pos); + } else if (dir == "Up" or dir == "j" ) { + pos[1] += 1; + this->cam->SetPosition(pos); + } else if (dir == "Right" or dir == "k" ) { + pos[0] += 1; + this->cam->SetPosition(pos); + } else if (dir == "Down" or dir == "l" ) { + pos[1] -= 1; + this->cam->SetPosition(pos); + } +} + +CameraMoveCallback::CameraMoveCallback() : cam(nullptr) {} + +CameraMoveCallback *CameraMoveCallback::New(vtkCamera *cam) { + auto me = new CameraMoveCallback; + me->setCam(cam); + return me; +} + +void CameraMoveCallback::setCam(const vtkSmartPointer &cam) { + this->cam = cam; +} diff --git a/vtk/src/commands/CameraMoveCallback.h b/vtk/src/commands/CameraMoveCallback.h new file mode 100644 index 0000000..e63adcf --- /dev/null +++ b/vtk/src/commands/CameraMoveCallback.h @@ -0,0 +1,27 @@ +#ifndef VTKBASE_CAMERAMOVECALLBACK_H +#define VTKBASE_CAMERAMOVECALLBACK_H + + +#include +#include +#include +#include + +class CameraMoveCallback : public vtkCallbackCommand { + +public: + static CameraMoveCallback *New(vtkCamera *cam); + CameraMoveCallback(); + + void setCam(const vtkSmartPointer &cam); + +private: + vtkSmartPointer cam; + + void Execute(vtkObject *caller, unsigned long evId, void *callData) override; + void zoom(const bool in); + void pan(const std::string dir); +}; + + +#endif diff --git a/vtk/src/commands/SpawnPointCallback.cpp b/vtk/src/commands/SpawnPointCallback.cpp index e29d190..3f41acd 100644 --- a/vtk/src/commands/SpawnPointCallback.cpp +++ b/vtk/src/commands/SpawnPointCallback.cpp @@ -39,7 +39,7 @@ void SpawnPointCallback::Execute(vtkObject *caller, unsigned long evId, void *ca ren->DisplayToWorld(); ren->GetWorldPoint(worldPos); inverseCartographicProjection->MultiplyPoint(worldPos, worldPos); - cout << "clicked on lon = " << worldPos[0] << " and lat = " << worldPos[1] << endl; + // cout << "clicked on lon = " << worldPos[0] << " and lat = " << worldPos[1] << endl; vtkIdType id = points->InsertNextPoint(worldPos[0], worldPos[1], 0); data->SetPoints(points); diff --git a/vtk/src/commands/TimerCallbackCommand.cpp b/vtk/src/commands/TimerCallbackCommand.cpp index 94e9de9..6700ac5 100644 --- a/vtk/src/commands/TimerCallbackCommand.cpp +++ b/vtk/src/commands/TimerCallbackCommand.cpp @@ -2,6 +2,7 @@ #include "../Program.h" +// TODO: add getter/setters to attributes for customizability. TimerCallbackCommand::TimerCallbackCommand() : dt(3600), maxTime(3600*24*365), time(0) {} TimerCallbackCommand* TimerCallbackCommand::New(Program *program) { @@ -22,7 +23,6 @@ void TimerCallbackCommand::Execute(vtkObject* caller, unsigned long eventId, voi } - void TimerCallbackCommand::setProgram(Program *program) { this->program = program; } diff --git a/vtk/src/layers/BackgroundImage.cpp b/vtk/src/layers/BackgroundImage.cpp index 780eaae..925c27a 100644 --- a/vtk/src/layers/BackgroundImage.cpp +++ b/vtk/src/layers/BackgroundImage.cpp @@ -3,6 +3,7 @@ #include #include #include +#include using std::string; @@ -24,6 +25,13 @@ void BackgroundImage::updateImage() { imageReader->Update(); imageData = imageReader->GetOutput(); + // TODO: transform the iamge to the range [-1,1] and center it on (0,0)/ + // This will allow the backgorundImage to share a camera with our other layers. + // Facilitating the cameraMovement callback. + + // vtkSmartPointer transformFilter = createCartographicTransformFilter(); + // transformFilter->SetInputData(imageData); + vtkNew imageActor; imageActor->SetInputData(imageData); @@ -60,3 +68,8 @@ void BackgroundImage::setImagePath(string imagePath) { this->imagePath = imagePath; updateImage(); } + + +void BackgroundImage::setCamera(vtkCamera *cam) { + // TODO: fix the camera for this layer so this intentionally empty override can be removed. +} diff --git a/vtk/src/layers/BackgroundImage.h b/vtk/src/layers/BackgroundImage.h index 1061189..c837b87 100644 --- a/vtk/src/layers/BackgroundImage.h +++ b/vtk/src/layers/BackgroundImage.h @@ -32,6 +32,9 @@ public: * @param imagePath : String to the path of the new image to use. */ void setImagePath(std::string imagePath); + + + void setCamera(vtkCamera *cam) override; }; #endif diff --git a/vtk/src/layers/EGlyphLayer.cpp b/vtk/src/layers/EGlyphLayer.cpp index cb91825..b4d5b28 100644 --- a/vtk/src/layers/EGlyphLayer.cpp +++ b/vtk/src/layers/EGlyphLayer.cpp @@ -65,13 +65,13 @@ void EGlyphLayer::readCoordinates() { this->direction->SetNumberOfTuples(numLats*numLons); points->Allocate(numLats*numLons); - auto camera = createNormalisedCamera(); - ren->SetActiveCamera(camera); + // auto camera = createNormalisedCamera(); + // ren->SetActiveCamera(camera); int i = 0; for (double lat : lats) { for (double lon : lons) { - cout << "lon: " << lon << " lat: " << lat << endl; + // cout << "lon: " << lon << " lat: " << lat << endl; direction->SetTuple3(i, 0.45, 0.90, 0); //FIXME: read this info from file points->InsertPoint(i++, lon, lat, 0); // see also https://vtk.org/doc/nightly/html/classvtkPolyDataMapper2D.html diff --git a/vtk/src/layers/LGlyphLayer.cpp b/vtk/src/layers/LGlyphLayer.cpp index 845d628..a49ee7f 100644 --- a/vtk/src/layers/LGlyphLayer.cpp +++ b/vtk/src/layers/LGlyphLayer.cpp @@ -42,7 +42,8 @@ LGlyphLayer::LGlyphLayer() { auto camera = createNormalisedCamera(); ren->SetActiveCamera(camera); - auto transform = createCartographicTransformFilter(); + // TODO: this line seemed to do nothing? + // auto transform = createCartographicTransformFilter(); vtkSmartPointer transformFilter = createCartographicTransformFilter(); transformFilter->SetInputData(data); diff --git a/vtk/src/layers/Layer.cpp b/vtk/src/layers/Layer.cpp index 39073b1..e7a156d 100644 --- a/vtk/src/layers/Layer.cpp +++ b/vtk/src/layers/Layer.cpp @@ -15,3 +15,8 @@ void Layer::updateData(int t) { void Layer::addObservers(vtkSmartPointer interactor) { // By default, do nothing } + + +void Layer::setCamera(vtkCamera *camera) { + this->getLayer()->SetActiveCamera(camera); +} diff --git a/vtk/src/layers/Layer.h b/vtk/src/layers/Layer.h index 5f6fc32..fd20823 100644 --- a/vtk/src/layers/Layer.h +++ b/vtk/src/layers/Layer.h @@ -27,6 +27,11 @@ public: * @param interactor : pointer to the interactor that observers can be added to. */ virtual void addObservers(vtkSmartPointer interactor); + + /** Sets the active camera for the vtkRenderer associated with this layer. + * Used to share one camera between multiple layers. + */ + virtual void setCamera(vtkCamera *camera); }; #endif diff --git a/vtk/src/main.cpp b/vtk/src/main.cpp index fb89ea4..bfe345e 100644 --- a/vtk/src/main.cpp +++ b/vtk/src/main.cpp @@ -12,6 +12,8 @@ #include "layers/EGlyphLayer.h" #include "layers/LGlyphLayer.h" #include "Program.h" +#include "CartographicTransformation.h" + using namespace std; @@ -20,6 +22,7 @@ int main() { auto l = new LGlyphLayer(); l->spoofPoints(); + Program *program = new Program(); program->addLayer(new BackgroundImage("../../../../data/map_661-661.png")); program->addLayer(new EGlyphLayer()); From 3a4c0c295d32ccb8dc53157865627de52d20aa24 Mon Sep 17 00:00:00 2001 From: djairoh Date: Sun, 5 May 2024 22:39:45 +0200 Subject: [PATCH 02/13] feat (wip): moved image to center on 0,0 --- vtk/src/layers/BackgroundImage.cpp | 56 +++++++++++++++++++++++++----- 1 file changed, 47 insertions(+), 9 deletions(-) diff --git a/vtk/src/layers/BackgroundImage.cpp b/vtk/src/layers/BackgroundImage.cpp index 925c27a..7381241 100644 --- a/vtk/src/layers/BackgroundImage.cpp +++ b/vtk/src/layers/BackgroundImage.cpp @@ -1,8 +1,11 @@ #include "BackgroundImage.h" +#include #include #include #include #include +#include +#include #include using std::string; @@ -14,23 +17,50 @@ BackgroundImage::BackgroundImage(string imagePath) : imagePath(imagePath) { updateImage(); } +// vtkSmartPointer getMatrix(const int w, const int h) { +// const double XMin = 0; +// const double XMax = w; +// const double YMin = 0; +// const double YMax = h; +// +// double eyeTransform[] = { +// 2/(XMax-XMin), 0, 0, -(XMax+XMin)/(XMax-XMin), +// 0, 2/(YMax-YMin), 0, -(YMax+YMin)/(YMax-YMin), +// 0, 0, 1, 0, +// 0, 0, 0, 1 +// }; +// +// auto matrix = vtkSmartPointer::New(); +// matrix->DeepCopy(eyeTransform); +// return matrix; +// } void BackgroundImage::updateImage() { - vtkSmartPointer imageData; vtkSmartPointer imageReader; imageReader.TakeReference(this->readerFactory->CreateImageReader2(this->imagePath.c_str())); imageReader->SetFileName(this->imagePath.c_str()); imageReader->Update(); - imageData = imageReader->GetOutput(); - // TODO: transform the iamge to the range [-1,1] and center it on (0,0)/ + // TODO: transform the iamge to the range [-1,1] and center it on (0,0) // This will allow the backgorundImage to share a camera with our other layers. // Facilitating the cameraMovement callback. + vtkNew changeInformation; + changeInformation->SetInputConnection(imageReader->GetOutputPort()); + changeInformation->CenterImageOn(); + changeInformation->Update(); + + vtkSmartPointer imageData = changeInformation->GetOutput(); - // vtkSmartPointer transformFilter = createCartographicTransformFilter(); - // transformFilter->SetInputData(imageData); + // vtkNew transform; + // + // transform->SetMatrix(getMatrix(661, 661)); + // + // vtkSmartPointer transformFilter = vtkSmartPointer::New(); + // transformFilter->SetTransform(transform); + // transformFilter->SetInputData(imageData); + vtkNew imageActor; imageActor->SetInputData(imageData); @@ -47,16 +77,23 @@ void BackgroundImage::updateImage() { imageData->GetSpacing(spacing); imageData->GetExtent(extent); + // printf("%lf, %lf, %lf\n", origin[0], origin[1], origin[2]); + // printf("%lf, %lf, %lf\n", spacing[0], spacing[1], spacing[2]); + // printf("%d, %d, %d, ", extent[0], extent[1], extent[2]); + // printf("%d, %d, %d\n", extent[3], extent[4], extent[5]); + vtkCamera *camera = this->ren->GetActiveCamera(); camera->ParallelProjectionOn(); double xc = origin[0] + 0.5 * (extent[0] + extent[1]) * spacing[0]; double yc = origin[1] + 0.5 * (extent[2] + extent[3]) * spacing[1]; double yd = (extent[3] - extent[2] + 1) * spacing[1]; - double d = camera->GetDistance(); - camera->SetParallelScale(0.5 * yd); - camera->SetFocalPoint(xc, yc, 0.0); - camera->SetPosition(xc, yc, d); + + // printf("%lf, %lf, %lf\n", xc, yc, yd); + + camera->SetParallelScale(0.5 * yd); // sets to 330; should be 1 -> resize image. + camera->SetFocalPoint(xc, yc, 0.0); // sets to 0,0,0; isnice + camera->SetPosition(xc, yc, 1000); // sets to 0,0,1000; isnice } @@ -71,5 +108,6 @@ void BackgroundImage::setImagePath(string imagePath) { void BackgroundImage::setCamera(vtkCamera *cam) { + this->getLayer()->SetActiveCamera(cam); // TODO: fix the camera for this layer so this intentionally empty override can be removed. } From 0c32aaade1725fcdeb03ec32ad86b60d73a133d6 Mon Sep 17 00:00:00 2001 From: djairoh Date: Sun, 5 May 2024 22:43:40 +0200 Subject: [PATCH 03/13] removed commented out code --- vtk/src/layers/BackgroundImage.cpp | 26 -------------------------- 1 file changed, 26 deletions(-) diff --git a/vtk/src/layers/BackgroundImage.cpp b/vtk/src/layers/BackgroundImage.cpp index 7381241..e6da7b5 100644 --- a/vtk/src/layers/BackgroundImage.cpp +++ b/vtk/src/layers/BackgroundImage.cpp @@ -17,23 +17,6 @@ BackgroundImage::BackgroundImage(string imagePath) : imagePath(imagePath) { updateImage(); } -// vtkSmartPointer getMatrix(const int w, const int h) { -// const double XMin = 0; -// const double XMax = w; -// const double YMin = 0; -// const double YMax = h; -// -// double eyeTransform[] = { -// 2/(XMax-XMin), 0, 0, -(XMax+XMin)/(XMax-XMin), -// 0, 2/(YMax-YMin), 0, -(YMax+YMin)/(YMax-YMin), -// 0, 0, 1, 0, -// 0, 0, 0, 1 -// }; -// -// auto matrix = vtkSmartPointer::New(); -// matrix->DeepCopy(eyeTransform); -// return matrix; -// } void BackgroundImage::updateImage() { @@ -53,15 +36,6 @@ void BackgroundImage::updateImage() { vtkSmartPointer imageData = changeInformation->GetOutput(); - // vtkNew transform; - // - // transform->SetMatrix(getMatrix(661, 661)); - // - // vtkSmartPointer transformFilter = vtkSmartPointer::New(); - // transformFilter->SetTransform(transform); - // transformFilter->SetInputData(imageData); - - vtkNew imageActor; imageActor->SetInputData(imageData); From ab0916b9c7e21888e0554126f2dc827b5e20c07c Mon Sep 17 00:00:00 2001 From: djairoh Date: Sun, 5 May 2024 23:25:08 +0200 Subject: [PATCH 04/13] small fix to camera focal points --- vtk/src/commands/CameraMoveCallback.cpp | 30 ++++++++++++++++--------- 1 file changed, 19 insertions(+), 11 deletions(-) diff --git a/vtk/src/commands/CameraMoveCallback.cpp b/vtk/src/commands/CameraMoveCallback.cpp index 6a92f0b..8e6a782 100644 --- a/vtk/src/commands/CameraMoveCallback.cpp +++ b/vtk/src/commands/CameraMoveCallback.cpp @@ -12,11 +12,17 @@ using std::string; void CameraMoveCallback::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(caller); + auto intr = reinterpret_cast(caller); switch (evId) { case vtkCommand::KeyPressEvent: - pan(interactor->GetKeySym()); + if (not strcmp("minus", intr->GetKeySym())) { + zoom(false); + } else if (not strcmp("equal", intr->GetKeySym())) { + zoom(true); + } else { + pan(intr->GetKeySym()); + } break; case vtkCommand::MouseWheelForwardEvent: zoom(true); @@ -27,18 +33,21 @@ void CameraMoveCallback::Execute(vtkObject *caller, unsigned long evId, default: break; } + + // also calls the render function when the camera's position has not actually changed. This is a negligble inefficiency. + intr->GetRenderWindow()->Render(); } void CameraMoveCallback::zoom(const bool in) { - double pos[3]; - this->cam->GetPosition(pos); + double scale = this->cam->GetParallelScale(); if (in) { - pos[2] -= 50; + scale -= 1; } else { - pos[2] += 50; + scale += 1; } - this->cam->SetPosition(pos); + + this->cam->SetParallelScale(scale); } @@ -48,17 +57,16 @@ void CameraMoveCallback::pan(const string dir) { if (dir == "Left" or dir == "h") { pos[0] -= 1; - this->cam->SetPosition(pos); } else if (dir == "Up" or dir == "j" ) { pos[1] += 1; - this->cam->SetPosition(pos); } else if (dir == "Right" or dir == "k" ) { pos[0] += 1; - this->cam->SetPosition(pos); } else if (dir == "Down" or dir == "l" ) { pos[1] -= 1; - this->cam->SetPosition(pos); } + + this->cam->SetPosition(pos); + this->cam->SetFocalPoint(pos[0], pos[1], 0); } CameraMoveCallback::CameraMoveCallback() : cam(nullptr) {} From da20a2514cfd1a07de4e983ecedc6bfcbb16e7d8 Mon Sep 17 00:00:00 2001 From: djairoh Date: Sun, 5 May 2024 23:26:31 +0200 Subject: [PATCH 05/13] (wip) progress on image transform --- vtk/src/layers/BackgroundImage.cpp | 48 +++++++++++++++++++++--------- 1 file changed, 34 insertions(+), 14 deletions(-) diff --git a/vtk/src/layers/BackgroundImage.cpp b/vtk/src/layers/BackgroundImage.cpp index e6da7b5..6aa63f6 100644 --- a/vtk/src/layers/BackgroundImage.cpp +++ b/vtk/src/layers/BackgroundImage.cpp @@ -3,7 +3,9 @@ #include #include #include +#include #include +#include #include #include #include @@ -17,6 +19,24 @@ BackgroundImage::BackgroundImage(string imagePath) : imagePath(imagePath) { updateImage(); } +vtkSmartPointer getMatrix() { + const double XMin = 0; + const double XMax = 661; + const double YMin = 0; + const double YMax = 661; + + double eyeTransform[] = { + 2/(XMax-XMin), 0, 0, -(XMax+XMin)/(XMax-XMin), + 0, 2/(YMax-YMin), 0, -(YMax+YMin)/(YMax-YMin), + 0, 0, 1, 0, + 0, 0, 0, 1 + }; + + auto matrix = vtkSmartPointer::New(); + matrix->DeepCopy(eyeTransform); + return matrix; +} + void BackgroundImage::updateImage() { @@ -26,16 +46,16 @@ void BackgroundImage::updateImage() { imageReader->SetFileName(this->imagePath.c_str()); imageReader->Update(); - // TODO: transform the iamge to the range [-1,1] and center it on (0,0) + vtkNew imageCenterer; + imageCenterer->SetInputConnection(imageReader->GetOutputPort()); + imageCenterer->CenterImageOn(); + imageCenterer->Update(); + + vtkSmartPointer imageData = imageCenterer->GetOutput(); + + // TODO: transform the iamge to the range [-1,1] // This will allow the backgorundImage to share a camera with our other layers. // Facilitating the cameraMovement callback. - vtkNew changeInformation; - changeInformation->SetInputConnection(imageReader->GetOutputPort()); - changeInformation->CenterImageOn(); - changeInformation->Update(); - - vtkSmartPointer imageData = changeInformation->GetOutput(); - vtkNew imageActor; imageActor->SetInputData(imageData); @@ -51,10 +71,10 @@ void BackgroundImage::updateImage() { imageData->GetSpacing(spacing); imageData->GetExtent(extent); - // printf("%lf, %lf, %lf\n", origin[0], origin[1], origin[2]); - // printf("%lf, %lf, %lf\n", spacing[0], spacing[1], spacing[2]); - // printf("%d, %d, %d, ", extent[0], extent[1], extent[2]); - // printf("%d, %d, %d\n", extent[3], extent[4], extent[5]); + printf("%lf, %lf, %lf\n", origin[0], origin[1], origin[2]); + printf("%lf, %lf, %lf\n", spacing[0], spacing[1], spacing[2]); + printf("%d, %d, %d, ", extent[0], extent[1], extent[2]); + printf("%d, %d, %d\n", extent[3], extent[4], extent[5]); vtkCamera *camera = this->ren->GetActiveCamera(); camera->ParallelProjectionOn(); @@ -63,9 +83,9 @@ void BackgroundImage::updateImage() { double yc = origin[1] + 0.5 * (extent[2] + extent[3]) * spacing[1]; double yd = (extent[3] - extent[2] + 1) * spacing[1]; - // printf("%lf, %lf, %lf\n", xc, yc, yd); + printf("%lf, %lf, %lf\n", xc, yc, yd); - camera->SetParallelScale(0.5 * yd); // sets to 330; should be 1 -> resize image. + camera->SetParallelScale(0.5 * yd); // sets to 330; should be 1 -> transform camera->SetFocalPoint(xc, yc, 0.0); // sets to 0,0,0; isnice camera->SetPosition(xc, yc, 1000); // sets to 0,0,1000; isnice } From f2b6286ecb2062420d9b755c026efaaec3bf7abf Mon Sep 17 00:00:00 2001 From: djairoh Date: Sun, 5 May 2024 23:27:30 +0200 Subject: [PATCH 06/13] code style fix --- vtk/src/commands/TimerCallbackCommand.cpp | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/vtk/src/commands/TimerCallbackCommand.cpp b/vtk/src/commands/TimerCallbackCommand.cpp index 2cad359..75e416b 100644 --- a/vtk/src/commands/TimerCallbackCommand.cpp +++ b/vtk/src/commands/TimerCallbackCommand.cpp @@ -18,16 +18,15 @@ void TimerCallbackCommand::Execute(vtkObject* caller, unsigned long eventId, voi if (eventId == vtkCommand::KeyPressEvent and not strcmp("space", intr->GetKeySym())) { this->paused = ! this->paused; } else if (eventId == vtkCommand::TimerEvent and not this->paused) { - this->time += this->dt; - - if (this->time >= this->maxTime) { - return; - // TODO: how do we deal with reaching the end of the simulated dataset? Do we just stop simulating, loop back around? What about the location of the particles in this case? Just some ideas to consider, but we should iron this out pretty soon. + this->time += this->dt; + + if (this->time >= this->maxTime) { + return; + // TODO: how do we deal with reaching the end of the simulated dataset? Do we just stop simulating, loop back around? What about the location of the particles in this case? Just some ideas to consider, but we should iron this out pretty soon. + } + + this->program->updateData(this->time); } - - this->program->updateData(this->time); - } - } void TimerCallbackCommand::setProgram(Program *program) { From b5dd0d5e49dfe5b9143fc58ed61b1c4974fe6805 Mon Sep 17 00:00:00 2001 From: djairoh Date: Sun, 5 May 2024 23:28:01 +0200 Subject: [PATCH 07/13] comments --- vtk/src/layers/BackgroundImage.cpp | 52 +++++++++++++++--------------- 1 file changed, 26 insertions(+), 26 deletions(-) diff --git a/vtk/src/layers/BackgroundImage.cpp b/vtk/src/layers/BackgroundImage.cpp index 6aa63f6..46b0b0f 100644 --- a/vtk/src/layers/BackgroundImage.cpp +++ b/vtk/src/layers/BackgroundImage.cpp @@ -62,32 +62,32 @@ void BackgroundImage::updateImage() { this->ren->AddActor(imageActor); - // camera stuff - // essentially sets the camera to the middle of the background, and points it at the background - // TODO: extract this to its own function, separate from the background class. - double origin[3], spacing[3]; - int extent[6]; - imageData->GetOrigin(origin); - imageData->GetSpacing(spacing); - imageData->GetExtent(extent); - - printf("%lf, %lf, %lf\n", origin[0], origin[1], origin[2]); - printf("%lf, %lf, %lf\n", spacing[0], spacing[1], spacing[2]); - printf("%d, %d, %d, ", extent[0], extent[1], extent[2]); - printf("%d, %d, %d\n", extent[3], extent[4], extent[5]); - - vtkCamera *camera = this->ren->GetActiveCamera(); - camera->ParallelProjectionOn(); - - double xc = origin[0] + 0.5 * (extent[0] + extent[1]) * spacing[0]; - double yc = origin[1] + 0.5 * (extent[2] + extent[3]) * spacing[1]; - double yd = (extent[3] - extent[2] + 1) * spacing[1]; - - printf("%lf, %lf, %lf\n", xc, yc, yd); - - camera->SetParallelScale(0.5 * yd); // sets to 330; should be 1 -> transform - camera->SetFocalPoint(xc, yc, 0.0); // sets to 0,0,0; isnice - camera->SetPosition(xc, yc, 1000); // sets to 0,0,1000; isnice + // // camera stuff + // // essentially sets the camera to the middle of the background, and points it at the background + // // TODO: extract this to its own function, separate from the background class. + // double origin[3], spacing[3]; + // int extent[6]; + // imageData->GetOrigin(origin); + // imageData->GetSpacing(spacing); + // imageData->GetExtent(extent); + // + // printf("%lf, %lf, %lf\n", origin[0], origin[1], origin[2]); + // printf("%lf, %lf, %lf\n", spacing[0], spacing[1], spacing[2]); + // printf("%d, %d, %d, ", extent[0], extent[1], extent[2]); + // printf("%d, %d, %d\n", extent[3], extent[4], extent[5]); + // + // vtkCamera *camera = this->ren->GetActiveCamera(); + // camera->ParallelProjectionOn(); + // + // double xc = origin[0] + 0.5 * (extent[0] + extent[1]) * spacing[0]; + // double yc = origin[1] + 0.5 * (extent[2] + extent[3]) * spacing[1]; + // double yd = (extent[3] - extent[2] + 1) * spacing[1]; + // + // printf("%lf, %lf, %lf\n", xc, yc, yd); + // + // camera->SetParallelScale(0.5 * yd); // sets to 330; should be 1 -> transform + // camera->SetFocalPoint(xc, yc, 0.0); // sets to 0,0,0; isnice + // camera->SetPosition(xc, yc, 1000); // sets to 0,0,1000; isnice } From b75466a08f1eee9c6169abb7e8e8fb16d0f49082 Mon Sep 17 00:00:00 2001 From: djairoh Date: Sun, 5 May 2024 23:59:35 +0200 Subject: [PATCH 08/13] removed old code --- vtk/src/layers/BackgroundImage.cpp | 21 +-------------------- 1 file changed, 1 insertion(+), 20 deletions(-) diff --git a/vtk/src/layers/BackgroundImage.cpp b/vtk/src/layers/BackgroundImage.cpp index 46b0b0f..ae6d556 100644 --- a/vtk/src/layers/BackgroundImage.cpp +++ b/vtk/src/layers/BackgroundImage.cpp @@ -19,25 +19,6 @@ BackgroundImage::BackgroundImage(string imagePath) : imagePath(imagePath) { updateImage(); } -vtkSmartPointer getMatrix() { - const double XMin = 0; - const double XMax = 661; - const double YMin = 0; - const double YMax = 661; - - double eyeTransform[] = { - 2/(XMax-XMin), 0, 0, -(XMax+XMin)/(XMax-XMin), - 0, 2/(YMax-YMin), 0, -(YMax+YMin)/(YMax-YMin), - 0, 0, 1, 0, - 0, 0, 0, 1 - }; - - auto matrix = vtkSmartPointer::New(); - matrix->DeepCopy(eyeTransform); - return matrix; -} - - void BackgroundImage::updateImage() { vtkSmartPointer imageReader; @@ -53,7 +34,7 @@ void BackgroundImage::updateImage() { vtkSmartPointer imageData = imageCenterer->GetOutput(); - // TODO: transform the iamge to the range [-1,1] + // TODO: transform the image to the range [-1,1] // This will allow the backgorundImage to share a camera with our other layers. // Facilitating the cameraMovement callback. vtkNew imageActor; From 25f5456e9d8e8c0a4ff8e64bb6c62996c982378f Mon Sep 17 00:00:00 2001 From: djairoh Date: Mon, 6 May 2024 11:13:41 +0200 Subject: [PATCH 09/13] modified logic for moving/zooming the camera --- vtk/src/commands/CameraMoveCallback.cpp | 42 +++++++++++++++++++------ vtk/src/commands/CameraMoveCallback.h | 1 + 2 files changed, 33 insertions(+), 10 deletions(-) diff --git a/vtk/src/commands/CameraMoveCallback.cpp b/vtk/src/commands/CameraMoveCallback.cpp index 8e6a782..f48b087 100644 --- a/vtk/src/commands/CameraMoveCallback.cpp +++ b/vtk/src/commands/CameraMoveCallback.cpp @@ -38,17 +38,40 @@ void CameraMoveCallback::Execute(vtkObject *caller, unsigned long evId, intr->GetRenderWindow()->Render(); } + +void CameraMoveCallback::clampCamera(double pos[3]) { + double scale = this->cam->GetParallelScale(); + + // only check the x,y coords of the camera; we don't care about z + for (int i=0; i < 2; i++) { + //boundary cond: scale+|pos| < 1. + if (abs(pos[i])+scale > 1.01) { + if (pos[i] >= 0) { + pos[i] = 1 - scale; + } else { + pos[i] = scale - 1; + } + } + } + + this->cam->SetPosition(pos); + this->cam->SetFocalPoint(pos[0], pos[1], 0); +} + void CameraMoveCallback::zoom(const bool in) { double scale = this->cam->GetParallelScale(); if (in) { - scale -= 1; + if (scale >= 0.2) { + scale -= 0.1; + } } else { - scale += 1; + if (scale <= 0.9) + scale += 0.1; } - + this->cam->SetParallelScale(scale); - + clampCamera(this->cam->GetPosition()); } void CameraMoveCallback::pan(const string dir) { @@ -56,17 +79,16 @@ void CameraMoveCallback::pan(const string dir) { this->cam->GetPosition(pos); if (dir == "Left" or dir == "h") { - pos[0] -= 1; + pos[0] -= 0.1; } else if (dir == "Up" or dir == "j" ) { - pos[1] += 1; + pos[1] += 0.1; } else if (dir == "Right" or dir == "k" ) { - pos[0] += 1; + pos[0] += 0.1; } else if (dir == "Down" or dir == "l" ) { - pos[1] -= 1; + pos[1] -= 0.1; } - this->cam->SetPosition(pos); - this->cam->SetFocalPoint(pos[0], pos[1], 0); + clampCamera(pos); } CameraMoveCallback::CameraMoveCallback() : cam(nullptr) {} diff --git a/vtk/src/commands/CameraMoveCallback.h b/vtk/src/commands/CameraMoveCallback.h index e63adcf..d85b9bb 100644 --- a/vtk/src/commands/CameraMoveCallback.h +++ b/vtk/src/commands/CameraMoveCallback.h @@ -21,6 +21,7 @@ private: void Execute(vtkObject *caller, unsigned long evId, void *callData) override; void zoom(const bool in); void pan(const std::string dir); + void clampCamera(double *pos); }; From 5f6b88b34ce2a6c5073cb1fcc9dd17402a9645ae Mon Sep 17 00:00:00 2001 From: djairoh Date: Mon, 6 May 2024 11:19:13 +0200 Subject: [PATCH 10/13] documentation --- vtk/src/commands/CameraMoveCallback.cpp | 1 + vtk/src/commands/CameraMoveCallback.h | 28 +++++++++++++++++++++++++ 2 files changed, 29 insertions(+) diff --git a/vtk/src/commands/CameraMoveCallback.cpp b/vtk/src/commands/CameraMoveCallback.cpp index f48b087..a462376 100644 --- a/vtk/src/commands/CameraMoveCallback.cpp +++ b/vtk/src/commands/CameraMoveCallback.cpp @@ -74,6 +74,7 @@ void CameraMoveCallback::zoom(const bool in) { clampCamera(this->cam->GetPosition()); } +// we use the interactor's getKeySym instead of getKeyCode because getKeyCode is platform-dependent. void CameraMoveCallback::pan(const string dir) { double pos[3]; this->cam->GetPosition(pos); diff --git a/vtk/src/commands/CameraMoveCallback.h b/vtk/src/commands/CameraMoveCallback.h index d85b9bb..13e0553 100644 --- a/vtk/src/commands/CameraMoveCallback.h +++ b/vtk/src/commands/CameraMoveCallback.h @@ -10,17 +10,45 @@ class CameraMoveCallback : public vtkCallbackCommand { public: + /** Create new instance using the vtk New template. + */ static CameraMoveCallback *New(vtkCamera *cam); + + /** Constructor. + */ CameraMoveCallback(); + /** Sets the camera to operate on. + */ void setCam(const vtkSmartPointer &cam); private: + /** The camera to operate on. + */ vtkSmartPointer cam; + /** Event callback. Should be subscribed to keyPressEvent and MouseWheelForward/MouseWheelBackward events. + */ void Execute(vtkObject *caller, unsigned long evId, void *callData) override; + + /** Zooms the camera in or out. + * @param in : whether to zoom in or out. + */ void zoom(const bool in); + + /** Pans the camera in a direction, determined by the parameter. + * 'h' and 'left' : pan left + * 'j' and 'up' : pan up + * 'k' and 'down' : pan down + * 'l' and 'right' : pan right + * @param dir : string of the pressed keycode. + */ void pan(const std::string dir); + + /** Edits the camera such that it only ever renders within the [-1,1] normalised coordinate field. + * Does so by making sure that the position of the camera (on the x,y axes), combined with the parallel scale, is never > 1. + * @param pos : pointer to new desired camera position. This will be changed if it would cause points outside [-1,1] to be displayed. + */ void clampCamera(double *pos); }; From 507d0065f0a6097ab836026e0f547ac1a94a5fe7 Mon Sep 17 00:00:00 2001 From: djairoh Date: Mon, 6 May 2024 14:05:59 +0200 Subject: [PATCH 11/13] added backgroundimage transformation --- vtk/src/commands/CameraMoveCallback.cpp | 7 +- vtk/src/commands/TimerCallbackCommand.cpp | 2 +- vtk/src/layers/BackgroundImage.cpp | 80 ++++++++++++----------- vtk/src/layers/BackgroundImage.h | 12 +++- vtk/src/layers/LGlyphLayer.cpp | 20 ++++-- 5 files changed, 69 insertions(+), 52 deletions(-) diff --git a/vtk/src/commands/CameraMoveCallback.cpp b/vtk/src/commands/CameraMoveCallback.cpp index a462376..29f6ea6 100644 --- a/vtk/src/commands/CameraMoveCallback.cpp +++ b/vtk/src/commands/CameraMoveCallback.cpp @@ -62,12 +62,11 @@ void CameraMoveCallback::zoom(const bool in) { double scale = this->cam->GetParallelScale(); if (in) { - if (scale >= 0.2) { - scale -= 0.1; - } + if (scale >= 0.2) + scale -= 0.1; } else { if (scale <= 0.9) - scale += 0.1; + scale += 0.1; } this->cam->SetParallelScale(scale); diff --git a/vtk/src/commands/TimerCallbackCommand.cpp b/vtk/src/commands/TimerCallbackCommand.cpp index 75e416b..81573d8 100644 --- a/vtk/src/commands/TimerCallbackCommand.cpp +++ b/vtk/src/commands/TimerCallbackCommand.cpp @@ -8,7 +8,7 @@ TimerCallbackCommand::TimerCallbackCommand() : dt(3600), maxTime(3600*24*365), t TimerCallbackCommand* TimerCallbackCommand::New(Program *program) { TimerCallbackCommand *cb = new TimerCallbackCommand(); cb->setProgram(program); - cb->setPaused(false); + cb->setPaused(true); return cb; } diff --git a/vtk/src/layers/BackgroundImage.cpp b/vtk/src/layers/BackgroundImage.cpp index ae6d556..b20a14a 100644 --- a/vtk/src/layers/BackgroundImage.cpp +++ b/vtk/src/layers/BackgroundImage.cpp @@ -1,5 +1,7 @@ #include "BackgroundImage.h" +#include #include +#include #include #include #include @@ -7,6 +9,7 @@ #include #include #include +#include #include #include @@ -19,56 +22,62 @@ BackgroundImage::BackgroundImage(string imagePath) : imagePath(imagePath) { updateImage(); } + +vtkSmartPointer BackgroundImage::getMatrix(const double x0, const double y0, const int xMax, const int yMax) { + double eyeTransform[] = { + 2/(xMax-x0), 0, 0, -(xMax+x0)/(xMax-x0), + 0, 2/(yMax-y0), 0, -(yMax+y0)/(yMax-y0), + 0, 0, 1, 0, + 0, 0, 0, 1 + }; + auto matrix = vtkSmartPointer::New(); + matrix->DeepCopy(eyeTransform); + return matrix; +} + + void BackgroundImage::updateImage() { + // read image data vtkSmartPointer imageReader; - imageReader.TakeReference(this->readerFactory->CreateImageReader2(this->imagePath.c_str())); imageReader->SetFileName(this->imagePath.c_str()); imageReader->Update(); + // translate image such that the middle is at (0,0) vtkNew imageCenterer; imageCenterer->SetInputConnection(imageReader->GetOutputPort()); imageCenterer->CenterImageOn(); imageCenterer->Update(); + // get some info from the data we'll need in a second vtkSmartPointer imageData = imageCenterer->GetOutput(); + double origin[3]; + int extent[6]; + imageData->GetOrigin(origin); + imageData->GetExtent(extent); - // TODO: transform the image to the range [-1,1] - // This will allow the backgorundImage to share a camera with our other layers. - // Facilitating the cameraMovement callback. - vtkNew imageActor; - imageActor->SetInputData(imageData); + // map the imageData to a vtkPolydata so we can use a vtkTransform + vtkNew imageDataGeometryFilter; + imageDataGeometryFilter->SetInputData(imageData); + imageDataGeometryFilter->Update(); - this->ren->AddActor(imageActor); + // setup the vtkTransform - this is where use the data from imageData we got earlier + vtkNew transform; + transform->SetMatrix(getMatrix(origin[0], origin[1], extent[1]+origin[0], extent[3]+origin[1])); + vtkSmartPointer transformFilter = vtkSmartPointer::New(); + transformFilter->SetTransform(transform); + transformFilter->SetInputConnection(imageDataGeometryFilter->GetOutputPort()); + transformFilter->Update(); + // Create a mapper and actor + vtkNew mapper; + mapper->SetInputConnection(transformFilter->GetOutputPort()); - // // camera stuff - // // essentially sets the camera to the middle of the background, and points it at the background - // // TODO: extract this to its own function, separate from the background class. - // double origin[3], spacing[3]; - // int extent[6]; - // imageData->GetOrigin(origin); - // imageData->GetSpacing(spacing); - // imageData->GetExtent(extent); - // - // printf("%lf, %lf, %lf\n", origin[0], origin[1], origin[2]); - // printf("%lf, %lf, %lf\n", spacing[0], spacing[1], spacing[2]); - // printf("%d, %d, %d, ", extent[0], extent[1], extent[2]); - // printf("%d, %d, %d\n", extent[3], extent[4], extent[5]); - // - // vtkCamera *camera = this->ren->GetActiveCamera(); - // camera->ParallelProjectionOn(); - // - // double xc = origin[0] + 0.5 * (extent[0] + extent[1]) * spacing[0]; - // double yc = origin[1] + 0.5 * (extent[2] + extent[3]) * spacing[1]; - // double yd = (extent[3] - extent[2] + 1) * spacing[1]; - // - // printf("%lf, %lf, %lf\n", xc, yc, yd); - // - // camera->SetParallelScale(0.5 * yd); // sets to 330; should be 1 -> transform - // camera->SetFocalPoint(xc, yc, 0.0); // sets to 0,0,0; isnice - // camera->SetPosition(xc, yc, 1000); // sets to 0,0,1000; isnice + vtkNew actor; + actor->SetMapper(mapper); + + this->ren->AddActor(actor); } @@ -81,8 +90,3 @@ void BackgroundImage::setImagePath(string imagePath) { updateImage(); } - -void BackgroundImage::setCamera(vtkCamera *cam) { - this->getLayer()->SetActiveCamera(cam); - // TODO: fix the camera for this layer so this intentionally empty override can be removed. -} diff --git a/vtk/src/layers/BackgroundImage.h b/vtk/src/layers/BackgroundImage.h index c837b87..71a0d1c 100644 --- a/vtk/src/layers/BackgroundImage.h +++ b/vtk/src/layers/BackgroundImage.h @@ -16,6 +16,15 @@ private: */ void updateImage(); + /** This function returns a 4x4matrix which maps the given square of [x0,w] x [y0,h] to the range [-1,1]. + * @param x0 : x coordinate of leftmost edge of image + * @param y0 : y coordinate of bottommost edge of image + * @param xMax : x coordinate of rightmost edge of image + * @param yMax : y coordinate of topmost edge of image + * @return a 4x4 matrix which transforms the image from its original geometry to the range [-1,1] + */ + vtkSmartPointer getMatrix(const double x0, const double y0, const int xMax, const int yMax); + public: /** Constructor. @@ -32,9 +41,6 @@ public: * @param imagePath : String to the path of the new image to use. */ void setImagePath(std::string imagePath); - - - void setCamera(vtkCamera *cam) override; }; #endif diff --git a/vtk/src/layers/LGlyphLayer.cpp b/vtk/src/layers/LGlyphLayer.cpp index a49ee7f..bbcc404 100644 --- a/vtk/src/layers/LGlyphLayer.cpp +++ b/vtk/src/layers/LGlyphLayer.cpp @@ -5,6 +5,7 @@ #include #include #include +#include #include #include #include @@ -50,7 +51,7 @@ LGlyphLayer::LGlyphLayer() { vtkNew circleSource; circleSource->SetGlyphTypeToCircle(); - circleSource->SetScale(0.05); + circleSource->SetScale(0.01); circleSource->Update(); vtkNew glyph2D; @@ -65,6 +66,7 @@ LGlyphLayer::LGlyphLayer() { vtkNew actor; actor->SetMapper(mapper); + actor->GetProperty()->SetOpacity(0.8); this->ren->AddActor(actor); } @@ -72,12 +74,18 @@ LGlyphLayer::LGlyphLayer() { // creates a few points so we can test the updateData function void LGlyphLayer::spoofPoints() { this->points->InsertNextPoint(-4.125, 61.375 , 0); - this->points->InsertNextPoint(6.532949683882039, 53.24308582564463, 0); // Coordinates of Zernike - this->points->InsertNextPoint(5.315307819255385, 60.40001057122271, 0); // Coordinates of Bergen - this->points->InsertNextPoint( 6.646210231365825, 46.52346296009023, 0); // Coordinates of Lausanne - this->points->InsertNextPoint(-6.553894313570932, 62.39522131195857, 0); // Coordinates of the top of the Faroe islands + // this->points->InsertNextPoint(6.532949683882039, 53.24308582564463, 0); // Coordinates of Zernike + // this->points->InsertNextPoint(5.315307819255385, 60.40001057122271, 0); // Coordinates of Bergen + // this->points->InsertNextPoint( 6.646210231365825, 46.52346296009023, 0); // Coordinates of Lausanne + // this->points->InsertNextPoint(-6.553894313570932, 62.39522131195857, 0); // Coordinates of the top of the Faroe islands - this->points->Modified(); + for (int i=0; i < 330; i+=5) { + for (int j=0; j < 330; j+=5) { + this->points->InsertNextPoint(-15.875+(12.875+15.875)/330*j, 46.125+(62.625-46.125)/330*i, 0); + } + } + + this->points->Modified(); } // returns new coords for a point; used to test the updateData function From b6619606b6249c294c575630ac5ccdb96a68ad5e Mon Sep 17 00:00:00 2001 From: djairoh Date: Mon, 6 May 2024 14:10:02 +0200 Subject: [PATCH 12/13] removed unnecessary lines --- vtk/src/layers/EGlyphLayer.cpp | 3 --- vtk/src/layers/LGlyphLayer.cpp | 6 ------ 2 files changed, 9 deletions(-) diff --git a/vtk/src/layers/EGlyphLayer.cpp b/vtk/src/layers/EGlyphLayer.cpp index b4d5b28..9549d92 100644 --- a/vtk/src/layers/EGlyphLayer.cpp +++ b/vtk/src/layers/EGlyphLayer.cpp @@ -65,9 +65,6 @@ void EGlyphLayer::readCoordinates() { this->direction->SetNumberOfTuples(numLats*numLons); points->Allocate(numLats*numLons); - // auto camera = createNormalisedCamera(); - // ren->SetActiveCamera(camera); - int i = 0; for (double lat : lats) { for (double lon : lons) { diff --git a/vtk/src/layers/LGlyphLayer.cpp b/vtk/src/layers/LGlyphLayer.cpp index bbcc404..57821b8 100644 --- a/vtk/src/layers/LGlyphLayer.cpp +++ b/vtk/src/layers/LGlyphLayer.cpp @@ -40,12 +40,6 @@ LGlyphLayer::LGlyphLayer() { this->data = vtkSmartPointer::New(); this->data->SetPoints(this->points); - auto camera = createNormalisedCamera(); - ren->SetActiveCamera(camera); - - // TODO: this line seemed to do nothing? - // auto transform = createCartographicTransformFilter(); - vtkSmartPointer transformFilter = createCartographicTransformFilter(); transformFilter->SetInputData(data); From 5ac8ad40ee47857b6511f4dc73c851b113061518 Mon Sep 17 00:00:00 2001 From: djairoh Date: Mon, 6 May 2024 14:19:18 +0200 Subject: [PATCH 13/13] got my keys switched up --- vtk/src/commands/CameraMoveCallback.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/vtk/src/commands/CameraMoveCallback.cpp b/vtk/src/commands/CameraMoveCallback.cpp index 29f6ea6..57ff2b0 100644 --- a/vtk/src/commands/CameraMoveCallback.cpp +++ b/vtk/src/commands/CameraMoveCallback.cpp @@ -80,11 +80,11 @@ void CameraMoveCallback::pan(const string dir) { if (dir == "Left" or dir == "h") { pos[0] -= 0.1; - } else if (dir == "Up" or dir == "j" ) { + } else if (dir == "Up" or dir == "k" ) { pos[1] += 0.1; - } else if (dir == "Right" or dir == "k" ) { + } else if (dir == "Right" or dir == "l" ) { pos[0] += 0.1; - } else if (dir == "Down" or dir == "l" ) { + } else if (dir == "Down" or dir == "j" ) { pos[1] -= 0.1; }