From 346e44da481ba470105e130a4b336528fe5ffc15 Mon Sep 17 00:00:00 2001 From: robin Date: Sun, 5 May 2024 14:50:26 +0200 Subject: [PATCH 1/4] normalised cartographic camera --- vtk/src/CMakeLists.txt | 1 + vtk/src/commands/TimerCallbackCommand.cpp | 2 - vtk/src/helperClasses/EGlyphLayer.cpp | 17 ++- vtk/src/helperClasses/LGlyphLayer.cpp | 104 +++++++++--------- .../NormalisedCartographicCamera.cpp | 43 ++++++++ .../NormalisedCartographicCamera.h | 8 ++ vtk/src/helperClasses/SpawnPointCallback.cpp | 15 ++- vtk/src/helperClasses/SpawnPointCallback.h | 3 + 8 files changed, 128 insertions(+), 65 deletions(-) create mode 100644 vtk/src/helperClasses/NormalisedCartographicCamera.cpp create mode 100644 vtk/src/helperClasses/NormalisedCartographicCamera.h diff --git a/vtk/src/CMakeLists.txt b/vtk/src/CMakeLists.txt index 8a20136..9cb04bc 100644 --- a/vtk/src/CMakeLists.txt +++ b/vtk/src/CMakeLists.txt @@ -46,6 +46,7 @@ add_executable(VtkBase MACOSX_BUNDLE main.cpp commands/TimerCallbackCommand.cpp helperClasses/SpawnPointCallback.h helperClasses/SpawnPointCallback.cpp + helperClasses/NormalisedCartographicCamera.cpp ) execute_process( diff --git a/vtk/src/commands/TimerCallbackCommand.cpp b/vtk/src/commands/TimerCallbackCommand.cpp index 4c43b74..d8edfd7 100644 --- a/vtk/src/commands/TimerCallbackCommand.cpp +++ b/vtk/src/commands/TimerCallbackCommand.cpp @@ -11,8 +11,6 @@ TimerCallbackCommand* TimerCallbackCommand::New(Program *program) { } void TimerCallbackCommand::Execute(vtkObject* caller, unsigned long eventId, void* vtkNotUsed(callData)) { - cout << this->time << " " << this->maxTime << endl; - this->time += this->dt; if (this->time >= this->maxTime) { diff --git a/vtk/src/helperClasses/EGlyphLayer.cpp b/vtk/src/helperClasses/EGlyphLayer.cpp index 4e4b9c0..4d3265d 100644 --- a/vtk/src/helperClasses/EGlyphLayer.cpp +++ b/vtk/src/helperClasses/EGlyphLayer.cpp @@ -13,6 +13,7 @@ #include #include #include +#include "NormalisedCartographicCamera.h" using namespace netCDF; using namespace std; @@ -64,11 +65,15 @@ void EGlyphLayer::readCoordinates() { this->direction->SetNumberOfTuples(numLats*numLons); points->Allocate(numLats*numLons); + auto camera = createNormalisedCartographicCamera(); + ren->SetActiveCamera(camera); + int i = 0; for (double lat : lats) { for (double lon : lons) { + cout << "lon: " << lon << " lat: " << lat << endl; direction->SetTuple3(i, 0.45, 0.90, 0); //FIXME: read this info from file - points->InsertPoint(i++, (lat*1000-46125)/25, (lon*1000+15875)/43.5, 0); // FIXME: counts on fixed window geometry to map properly; refactor to make use of active window geometry. + points->InsertPoint(i++, lon, lat, 0); // FIXME: counts on fixed window geometry to map properly; refactor to make use of active window geometry. // see also https://vtk.org/doc/nightly/html/classvtkPolyDataMapper2D.html } } @@ -78,7 +83,7 @@ void EGlyphLayer::readCoordinates() { vtkNew arrowSource; arrowSource->SetGlyphTypeToArrow(); - arrowSource->SetScale(8); //TODO: set this properly + arrowSource->SetScale(0.2); //TODO: set this properly arrowSource->Update(); vtkNew glyph2D; @@ -90,15 +95,15 @@ void EGlyphLayer::readCoordinates() { glyph2D->SetVectorModeToUseVector(); glyph2D->Update(); - vtkNew coordinate; - coordinate->SetCoordinateSystemToWorld(); +// vtkNew coordinate; +// coordinate->SetCoordinateSystemToWorld(); - vtkNew(mapper); + vtkNew(mapper); // mapper->SetTransformCoordinate(coordinate); mapper->SetInputConnection(glyph2D->GetOutputPort()); mapper->Update(); - vtkNew actor; + vtkNew actor; actor->SetMapper(mapper); actor->GetProperty()->SetColor(0,0,0); diff --git a/vtk/src/helperClasses/LGlyphLayer.cpp b/vtk/src/helperClasses/LGlyphLayer.cpp index e3d10d2..00e3ef5 100644 --- a/vtk/src/helperClasses/LGlyphLayer.cpp +++ b/vtk/src/helperClasses/LGlyphLayer.cpp @@ -9,16 +9,23 @@ #include #include #include +#include +#include +#include +#include +#include + +#include "NormalisedCartographicCamera.h" vtkSmartPointer LGlyphLayer::createSpawnPointCallback() { auto newPointCallBack = vtkSmartPointer::New(); newPointCallBack->setData(data); newPointCallBack->setPoints(points); + newPointCallBack->setRen(ren); return newPointCallBack; } - // TODO: add interactionStyle functionality // TODO: add timer + advection (probably from the program class not here) // 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. @@ -28,74 +35,61 @@ vtkSmartPointer LGlyphLayer::createSpawnPointCallback() { // TODO: modelling all this in vtkClasses is workable, but ideally i would want to work with a native C++ class. See if this is doable and feasible. LGlyphLayer::LGlyphLayer() { - this->ren = vtkSmartPointer::New(); - this->ren->SetLayer(2); + this->ren = vtkSmartPointer::New(); + this->ren->SetLayer(2); - this->points = vtkSmartPointer::New(); - this->data = vtkSmartPointer::New(); - this->data->SetPoints(this->points); - - vtkNew circleSource; - circleSource->SetGlyphTypeToCircle(); - circleSource->SetScale(15); - circleSource->Update(); + this->points = vtkSmartPointer::New(); + this->data = vtkSmartPointer::New(); + this->data->SetPoints(this->points); - vtkNew glyph2D; - glyph2D->SetSourceConnection(circleSource->GetOutputPort()); - glyph2D->SetInputData(this->data); - glyph2D->SetColorModeToColorByScalar(); - glyph2D->Update(); + vtkNew circleSource; + circleSource->SetGlyphTypeToCircle(); + circleSource->SetScale(1); + circleSource->Update(); - vtkNew mapper; - mapper->SetInputConnection(glyph2D->GetOutputPort()); - mapper->Update(); + vtkNew glyph2D; + glyph2D->SetSourceConnection(circleSource->GetOutputPort()); + glyph2D->SetInputData(this->data); + glyph2D->SetColorModeToColorByScalar(); + glyph2D->Update(); - vtkNew actor; - actor->SetMapper(mapper); - actor->GetProperty()->SetColor(1,1,1); + auto camera = createNormalisedCartographicCamera(); + ren->SetActiveCamera(camera); - this->ren->AddActor(actor); + vtkNew mapper; + mapper->SetInputConnection(glyph2D->GetOutputPort()); + mapper->Update(); + + vtkNew actor; + actor->SetMapper(mapper); + + this->ren->AddActor(actor); } // creates a few points so we can test the updateData function void LGlyphLayer::spoofPoints() { - this->points->InsertNextPoint(53, 2, 0); - this->points->InsertNextPoint(48.2, 111.01, 0); - this->points->InsertNextPoint(331, 331, 0); +// this->points->InsertNextPoint(200, 200 , 0); + this->points->InsertNextPoint(-4.125, 61.375 , 0); + this->points->InsertNextPoint(4.896555178870355, 52.373557841669516, 0); +// this->points->InsertNextPoint(48.2, 111.01, 0); +// this->points->InsertNextPoint(331, 331, 0); +// this->points->InsertNextPoint(0, 50, 0); +// this->points->InsertNextPoint(200, 200 , 0); - this->points->Modified(); + this->points->Modified(); } - // returns new coords for a point; used to test the updateData function std::pair advect(int time, double lat, double lon) { - return {lat+0.1, lon+0.1} ; + return {lat + 0., lon + 0.}; } - -// converts a x,y pair from pixel coordinates to real world latitude and longitude. -// TODO: make this more modular by having it interact with the backgroundImage layer (and possibly the camera panning/zooming logic when that is implemented). -std::pair pixelToReal(double x, double y) { - //assumes a 661x661 window with a range of [46.125, 62.625] lat and [-15.875, 12.875] lon. - return {(x*25+46125)/1000, (y*43.5-15875)/1000}; -} - -// converts a lat,lon pair from real world values to pixel coordinates. -// TODO: see above. -std::pair realToPixel(double lat, double lon) { - //assumes a 661x661 window with a range of [46.125, 62.625] lat and [-15.875, 12.875] lon. - return {(lat*1000-46125)/25, (lon*1000+15875)/43.5}; -} - -// FIXME: actually the above functions are a bit of a naive way of modelling these. Much better would be to have the points at the real-world latitude and longitude, and apply a filter in the pipeline to convert them to the appropriate window geometry. - void LGlyphLayer::updateData(int t) { - double point[3]; - for (vtkIdType n=0; n < this->points->GetNumberOfPoints(); n++) { - this->points->GetPoint(n, point); - auto grads = pixelToReal(point[0], point[1]); - auto newGrads = advect(n, grads.first, grads.second); - auto newPixs = realToPixel(newGrads.first, newGrads.second); - this->points->SetPoint(n, newPixs.first, newPixs.second, 0); - } - this->points->Modified(); +void LGlyphLayer::updateData(int t) { + double point[3]; + for (vtkIdType n = 0; n < this->points->GetNumberOfPoints(); n++) { + this->points->GetPoint(n, point); + auto [xNew, yNew] = advect(n, point[0], point[1]); + this->points->SetPoint(n, xNew, yNew, 0); + } + this->points->Modified(); } diff --git a/vtk/src/helperClasses/NormalisedCartographicCamera.cpp b/vtk/src/helperClasses/NormalisedCartographicCamera.cpp new file mode 100644 index 0000000..d34bafe --- /dev/null +++ b/vtk/src/helperClasses/NormalisedCartographicCamera.cpp @@ -0,0 +1,43 @@ +#include "NormalisedCartographicCamera.h" +#include + +vtkSmartPointer createNormalisedCartographicCamera() { + const double XMin = -15.875; + const double XMax = 12.875; + const double YMin = 46.125; + const double YMax = 62.625; + + double farClipPlane = 100; + double nearClipPlane = 1; + double eyeTransform[] = { + 2/(XMax-XMin), 0, 0, -(XMax+XMin)/(XMax-XMin), + 0, 2/(YMax-YMin), 0, -(YMax+YMin)/(YMax-YMin), + 0, 0, 2/(nearClipPlane-farClipPlane), -(farClipPlane+nearClipPlane)/(farClipPlane-nearClipPlane), + 0, 0, 0, 1 + }; + + vtkSmartPointer camera = vtkSmartPointer::New(); + camera->ParallelProjectionOn(); // Enable parallel projection + camera->UseExplicitProjectionTransformMatrixOn(); + +//// // Calculate the center and the size of the view + double centerX = (XMax + XMin) / 2.0; + double centerY = (YMax + YMin) / 2.0; + double width = XMax - XMin; + double height = YMax - YMin; +//// // Set the camera position, focal point, and view up +// camera->SetPosition(centerX, centerY, 1000); // Place the camera above the center +// camera->SetFocalPoint(centerX, centerY, 0); // Look at the center +// camera->SetViewUp(0, 1, 0); // Set the up vector to be along the Y-axis +//// +//// // Set parallel scale +// double parallelScale = std::max(width, height) / 2.0; +// camera->SetParallelScale(parallelScale); + + vtkNew projectionMatrix; + projectionMatrix->DeepCopy(eyeTransform); + camera->SetExplicitProjectionTransformMatrix(projectionMatrix); +// camera->SetScreenBottomLeft(XMin, YMin, 0); +// camera->SetScreenTopRight(XMax, YMax, 0); + return camera; +} diff --git a/vtk/src/helperClasses/NormalisedCartographicCamera.h b/vtk/src/helperClasses/NormalisedCartographicCamera.h new file mode 100644 index 0000000..fca5a39 --- /dev/null +++ b/vtk/src/helperClasses/NormalisedCartographicCamera.h @@ -0,0 +1,8 @@ +#include + +#ifndef VTKBASE_NORMALISEDCARTOGRAPHICCAMERA_H +#define VTKBASE_NORMALISEDCARTOGRAPHICCAMERA_H + +#endif //VTKBASE_NORMALISEDCARTOGRAPHICCAMERA_H + +vtkSmartPointer createNormalisedCartographicCamera(); \ No newline at end of file diff --git a/vtk/src/helperClasses/SpawnPointCallback.cpp b/vtk/src/helperClasses/SpawnPointCallback.cpp index 14dbc49..15eca3b 100644 --- a/vtk/src/helperClasses/SpawnPointCallback.cpp +++ b/vtk/src/helperClasses/SpawnPointCallback.cpp @@ -31,7 +31,14 @@ void SpawnPointCallback::Execute(vtkObject *caller, unsigned long evId, void *ca int x, y; interactor->GetEventPosition(x, y); - vtkIdType id = points->InsertNextPoint(x, y, 0); + double worldPos[4] = {2, 0 ,0, 0}; + double displayPos[3] = {static_cast(x), static_cast(y), 0.0}; + ren->SetDisplayPoint(displayPos); + ren->DisplayToWorld(); + ren->GetWorldPoint(worldPos); + cout << "clicked on lon = " << worldPos[0] << " and lat = " << worldPos[1] << endl; + + vtkIdType id = points->InsertNextPoint(worldPos[0], worldPos[1], 0); data->SetPoints(points); vtkSmartPointer vertex = vtkSmartPointer::New(); @@ -57,4 +64,8 @@ void SpawnPointCallback::setData(const vtkSmartPointer &data) { void SpawnPointCallback::setPoints(const vtkSmartPointer &points) { this->points = points; -} \ No newline at end of file +} + +void SpawnPointCallback::setRen(const vtkSmartPointer &ren) { + this->ren = ren; +} diff --git a/vtk/src/helperClasses/SpawnPointCallback.h b/vtk/src/helperClasses/SpawnPointCallback.h index 99ab160..e71063d 100644 --- a/vtk/src/helperClasses/SpawnPointCallback.h +++ b/vtk/src/helperClasses/SpawnPointCallback.h @@ -17,9 +17,12 @@ public: void setData(const vtkSmartPointer &data); + void setRen(const vtkSmartPointer &ren); + private: vtkSmartPointer data; vtkSmartPointer points; + vtkSmartPointer ren; public: private: From 3356b5561aa7384894e90c424f4954d868b5fa40 Mon Sep 17 00:00:00 2001 From: robin Date: Sun, 5 May 2024 16:33:45 +0200 Subject: [PATCH 2/4] Feat: Improved organisation of Cartographic transformation --- vtk/.gitignore | 3 +- vtk/src/CMakeLists.txt | 2 +- vtk/src/compile_commands.json | 1 - .../CartographicTransformation.cpp | 46 +++++++++++++++++++ .../CartographicTransformation.h | 29 ++++++++++++ vtk/src/helperClasses/EGlyphLayer.cpp | 11 +++-- vtk/src/helperClasses/LGlyphLayer.cpp | 27 ++++++----- .../NormalisedCartographicCamera.cpp | 43 ----------------- .../NormalisedCartographicCamera.h | 8 ---- vtk/src/helperClasses/SpawnPointCallback.cpp | 8 +++- vtk/src/helperClasses/SpawnPointCallback.h | 5 +- 11 files changed, 109 insertions(+), 74 deletions(-) delete mode 120000 vtk/src/compile_commands.json create mode 100644 vtk/src/helperClasses/CartographicTransformation.cpp create mode 100644 vtk/src/helperClasses/CartographicTransformation.h delete mode 100644 vtk/src/helperClasses/NormalisedCartographicCamera.cpp delete mode 100644 vtk/src/helperClasses/NormalisedCartographicCamera.h diff --git a/vtk/.gitignore b/vtk/.gitignore index 95abd3d..ea37cb8 100644 --- a/vtk/.gitignore +++ b/vtk/.gitignore @@ -3,4 +3,5 @@ src/.DS_Store src/.cache src/build .idea -src/cmake-build-debug \ No newline at end of file +src/cmake-build-debug +compile_commands.json \ No newline at end of file diff --git a/vtk/src/CMakeLists.txt b/vtk/src/CMakeLists.txt index 9cb04bc..cb39085 100644 --- a/vtk/src/CMakeLists.txt +++ b/vtk/src/CMakeLists.txt @@ -46,7 +46,7 @@ add_executable(VtkBase MACOSX_BUNDLE main.cpp commands/TimerCallbackCommand.cpp helperClasses/SpawnPointCallback.h helperClasses/SpawnPointCallback.cpp - helperClasses/NormalisedCartographicCamera.cpp + helperClasses/CartographicTransformation.cpp ) execute_process( diff --git a/vtk/src/compile_commands.json b/vtk/src/compile_commands.json deleted file mode 120000 index 25eb4b2..0000000 --- a/vtk/src/compile_commands.json +++ /dev/null @@ -1 +0,0 @@ -build/compile_commands.json \ No newline at end of file diff --git a/vtk/src/helperClasses/CartographicTransformation.cpp b/vtk/src/helperClasses/CartographicTransformation.cpp new file mode 100644 index 0000000..54c528e --- /dev/null +++ b/vtk/src/helperClasses/CartographicTransformation.cpp @@ -0,0 +1,46 @@ +#include "CartographicTransformation.h" +#include +#include +#include + +vtkSmartPointer createNormalisedCamera() { + vtkSmartPointer camera = vtkSmartPointer::New(); + camera->ParallelProjectionOn(); // Enable parallel projection + + camera->SetPosition(0, 0, 1000); // Place the camera above the center + camera->SetFocalPoint(0, 0, 0); // Look at the center + camera->SetViewUp(0, 1, 0); // Set the up vector to be along the Y-axis + camera->SetParallelScale(1); // x,y in [-1, 1] + + return camera; +} + +vtkSmartPointer getCartographicTransformMatrix() { + const double XMin = -15.875; + const double XMax = 12.875; + const double YMin = 46.125; + const double YMax = 62.625; + + 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; +} + +// Assumes Normalised camera is used +vtkSmartPointer createCartographicTransformFilter() { + vtkNew transform; + + transform->SetMatrix(getCartographicTransformMatrix()); + + vtkSmartPointer transformFilter = vtkSmartPointer::New(); + transformFilter->SetTransform(transform); + + return transformFilter; +} diff --git a/vtk/src/helperClasses/CartographicTransformation.h b/vtk/src/helperClasses/CartographicTransformation.h new file mode 100644 index 0000000..368483d --- /dev/null +++ b/vtk/src/helperClasses/CartographicTransformation.h @@ -0,0 +1,29 @@ +#include +#include + +#ifndef VTKBASE_NORMALISEDCARTOGRAPHICCAMERA_H +#define VTKBASE_NORMALISEDCARTOGRAPHICCAMERA_H + +#endif //VTKBASE_NORMALISEDCARTOGRAPHICCAMERA_H + +/** + * Constructs a orthographically projected camera that looks at the square x,y in [-1, 1] with z = 0 and w = 1. + * The space [-1,1] x [-1,1] x {0} will be referred to as the normalised space. + * @return pointer to camera + */ +vtkSmartPointer createNormalisedCamera(); + +/** + * Constructs a 4x4 projection matrix that maps homogenious (longitude, latitude, 0, 1) points + * to the normalised space. + * TODO: This transformation has room for improvement see: + * https://github.com/MakeNEnjoy/interactive-track-and-trace/issues/12 + * @return pointer to 4x4 matrix + */ +vtkSmartPointer getCartographicTransformMatrix(); + +/** + * Convenience function that converts the 4x4 projection matrix into a vtkTransformFilter + * @return pointer to transform filter + */ +vtkSmartPointer createCartographicTransformFilter(); \ No newline at end of file diff --git a/vtk/src/helperClasses/EGlyphLayer.cpp b/vtk/src/helperClasses/EGlyphLayer.cpp index 4d3265d..0722a34 100644 --- a/vtk/src/helperClasses/EGlyphLayer.cpp +++ b/vtk/src/helperClasses/EGlyphLayer.cpp @@ -13,7 +13,7 @@ #include #include #include -#include "NormalisedCartographicCamera.h" +#include "CartographicTransformation.h" using namespace netCDF; using namespace std; @@ -65,7 +65,7 @@ void EGlyphLayer::readCoordinates() { this->direction->SetNumberOfTuples(numLats*numLons); points->Allocate(numLats*numLons); - auto camera = createNormalisedCartographicCamera(); + auto camera = createNormalisedCamera(); ren->SetActiveCamera(camera); int i = 0; @@ -73,7 +73,7 @@ void EGlyphLayer::readCoordinates() { for (double lon : lons) { 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); // FIXME: counts on fixed window geometry to map properly; refactor to make use of active window geometry. + points->InsertPoint(i++, lon, lat, 0); // see also https://vtk.org/doc/nightly/html/classvtkPolyDataMapper2D.html } } @@ -81,6 +81,9 @@ void EGlyphLayer::readCoordinates() { this->data->GetPointData()->AddArray(this->direction); this->data->GetPointData()->SetActiveVectors("direction"); + vtkSmartPointer transformFilter = createCartographicTransformFilter(); + transformFilter->SetInputData(data); + vtkNew arrowSource; arrowSource->SetGlyphTypeToArrow(); arrowSource->SetScale(0.2); //TODO: set this properly @@ -88,7 +91,7 @@ void EGlyphLayer::readCoordinates() { vtkNew glyph2D; glyph2D->SetSourceConnection(arrowSource->GetOutputPort()); - glyph2D->SetInputData(this->data); + glyph2D->SetInputConnection(transformFilter->GetOutputPort()); glyph2D->OrientOn(); glyph2D->ClampingOn(); glyph2D->SetScaleModeToScaleByVector(); diff --git a/vtk/src/helperClasses/LGlyphLayer.cpp b/vtk/src/helperClasses/LGlyphLayer.cpp index 00e3ef5..3b1a051 100644 --- a/vtk/src/helperClasses/LGlyphLayer.cpp +++ b/vtk/src/helperClasses/LGlyphLayer.cpp @@ -15,7 +15,7 @@ #include #include -#include "NormalisedCartographicCamera.h" +#include "CartographicTransformation.h" vtkSmartPointer LGlyphLayer::createSpawnPointCallback() { @@ -42,20 +42,25 @@ LGlyphLayer::LGlyphLayer() { this->data = vtkSmartPointer::New(); this->data->SetPoints(this->points); + auto camera = createNormalisedCamera(); + ren->SetActiveCamera(camera); + + auto transform = createCartographicTransformFilter(); + + vtkSmartPointer transformFilter = createCartographicTransformFilter(); + transformFilter->SetInputData(data); + vtkNew circleSource; circleSource->SetGlyphTypeToCircle(); - circleSource->SetScale(1); + circleSource->SetScale(0.05); circleSource->Update(); vtkNew glyph2D; glyph2D->SetSourceConnection(circleSource->GetOutputPort()); - glyph2D->SetInputData(this->data); + glyph2D->SetInputConnection(transformFilter->GetOutputPort()); glyph2D->SetColorModeToColorByScalar(); glyph2D->Update(); - auto camera = createNormalisedCartographicCamera(); - ren->SetActiveCamera(camera); - vtkNew mapper; mapper->SetInputConnection(glyph2D->GetOutputPort()); mapper->Update(); @@ -68,13 +73,11 @@ LGlyphLayer::LGlyphLayer() { // creates a few points so we can test the updateData function void LGlyphLayer::spoofPoints() { -// this->points->InsertNextPoint(200, 200 , 0); this->points->InsertNextPoint(-4.125, 61.375 , 0); - this->points->InsertNextPoint(4.896555178870355, 52.373557841669516, 0); -// this->points->InsertNextPoint(48.2, 111.01, 0); -// this->points->InsertNextPoint(331, 331, 0); -// this->points->InsertNextPoint(0, 50, 0); -// this->points->InsertNextPoint(200, 200 , 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->Modified(); } diff --git a/vtk/src/helperClasses/NormalisedCartographicCamera.cpp b/vtk/src/helperClasses/NormalisedCartographicCamera.cpp deleted file mode 100644 index d34bafe..0000000 --- a/vtk/src/helperClasses/NormalisedCartographicCamera.cpp +++ /dev/null @@ -1,43 +0,0 @@ -#include "NormalisedCartographicCamera.h" -#include - -vtkSmartPointer createNormalisedCartographicCamera() { - const double XMin = -15.875; - const double XMax = 12.875; - const double YMin = 46.125; - const double YMax = 62.625; - - double farClipPlane = 100; - double nearClipPlane = 1; - double eyeTransform[] = { - 2/(XMax-XMin), 0, 0, -(XMax+XMin)/(XMax-XMin), - 0, 2/(YMax-YMin), 0, -(YMax+YMin)/(YMax-YMin), - 0, 0, 2/(nearClipPlane-farClipPlane), -(farClipPlane+nearClipPlane)/(farClipPlane-nearClipPlane), - 0, 0, 0, 1 - }; - - vtkSmartPointer camera = vtkSmartPointer::New(); - camera->ParallelProjectionOn(); // Enable parallel projection - camera->UseExplicitProjectionTransformMatrixOn(); - -//// // Calculate the center and the size of the view - double centerX = (XMax + XMin) / 2.0; - double centerY = (YMax + YMin) / 2.0; - double width = XMax - XMin; - double height = YMax - YMin; -//// // Set the camera position, focal point, and view up -// camera->SetPosition(centerX, centerY, 1000); // Place the camera above the center -// camera->SetFocalPoint(centerX, centerY, 0); // Look at the center -// camera->SetViewUp(0, 1, 0); // Set the up vector to be along the Y-axis -//// -//// // Set parallel scale -// double parallelScale = std::max(width, height) / 2.0; -// camera->SetParallelScale(parallelScale); - - vtkNew projectionMatrix; - projectionMatrix->DeepCopy(eyeTransform); - camera->SetExplicitProjectionTransformMatrix(projectionMatrix); -// camera->SetScreenBottomLeft(XMin, YMin, 0); -// camera->SetScreenTopRight(XMax, YMax, 0); - return camera; -} diff --git a/vtk/src/helperClasses/NormalisedCartographicCamera.h b/vtk/src/helperClasses/NormalisedCartographicCamera.h deleted file mode 100644 index fca5a39..0000000 --- a/vtk/src/helperClasses/NormalisedCartographicCamera.h +++ /dev/null @@ -1,8 +0,0 @@ -#include - -#ifndef VTKBASE_NORMALISEDCARTOGRAPHICCAMERA_H -#define VTKBASE_NORMALISEDCARTOGRAPHICCAMERA_H - -#endif //VTKBASE_NORMALISEDCARTOGRAPHICCAMERA_H - -vtkSmartPointer createNormalisedCartographicCamera(); \ No newline at end of file diff --git a/vtk/src/helperClasses/SpawnPointCallback.cpp b/vtk/src/helperClasses/SpawnPointCallback.cpp index 15eca3b..e52b88f 100644 --- a/vtk/src/helperClasses/SpawnPointCallback.cpp +++ b/vtk/src/helperClasses/SpawnPointCallback.cpp @@ -7,6 +7,8 @@ #include #include +#include "CartographicTransformation.h" + void convertDisplayToWorld(vtkRenderer* renderer, int x, int y, double *worldPos) { double displayPos[3] = {static_cast(x), static_cast(y), 0.0}; renderer->SetDisplayPoint(displayPos); @@ -36,6 +38,7 @@ void SpawnPointCallback::Execute(vtkObject *caller, unsigned long evId, void *ca ren->SetDisplayPoint(displayPos); ren->DisplayToWorld(); ren->GetWorldPoint(worldPos); + inverseCartographicProjection->MultiplyPoint(worldPos, worldPos); cout << "clicked on lon = " << worldPos[0] << " and lat = " << worldPos[1] << endl; vtkIdType id = points->InsertNextPoint(worldPos[0], worldPos[1], 0); @@ -52,7 +55,10 @@ void SpawnPointCallback::Execute(vtkObject *caller, unsigned long evId, void *ca } -SpawnPointCallback::SpawnPointCallback() : data(nullptr), points(nullptr) {} +SpawnPointCallback::SpawnPointCallback() : data(nullptr), points(nullptr), inverseCartographicProjection(nullptr) { + inverseCartographicProjection = getCartographicTransformMatrix(); + inverseCartographicProjection->Invert(); +} SpawnPointCallback *SpawnPointCallback::New() { return new SpawnPointCallback; diff --git a/vtk/src/helperClasses/SpawnPointCallback.h b/vtk/src/helperClasses/SpawnPointCallback.h index e71063d..bef6ca4 100644 --- a/vtk/src/helperClasses/SpawnPointCallback.h +++ b/vtk/src/helperClasses/SpawnPointCallback.h @@ -6,6 +6,7 @@ #include #include #include +#include class SpawnPointCallback : public vtkCallbackCommand { @@ -18,14 +19,12 @@ public: void setData(const vtkSmartPointer &data); void setRen(const vtkSmartPointer &ren); - private: vtkSmartPointer data; vtkSmartPointer points; vtkSmartPointer ren; -public: + vtkSmartPointer inverseCartographicProjection; -private: void Execute(vtkObject *caller, unsigned long evId, void *callData) override; bool dragging = false; }; From c8fac120dc40585a8c7a1ff97eeb86334f36756c Mon Sep 17 00:00:00 2001 From: robin Date: Sun, 5 May 2024 16:37:39 +0200 Subject: [PATCH 3/4] fix: added warning --- vtk/src/helperClasses/CartographicTransformation.h | 1 + 1 file changed, 1 insertion(+) diff --git a/vtk/src/helperClasses/CartographicTransformation.h b/vtk/src/helperClasses/CartographicTransformation.h index 368483d..56ffbeb 100644 --- a/vtk/src/helperClasses/CartographicTransformation.h +++ b/vtk/src/helperClasses/CartographicTransformation.h @@ -16,6 +16,7 @@ vtkSmartPointer createNormalisedCamera(); /** * Constructs a 4x4 projection matrix that maps homogenious (longitude, latitude, 0, 1) points * to the normalised space. + * TODO: This will soon require UVGrid as a parameter after the advection code is merged properly. * TODO: This transformation has room for improvement see: * https://github.com/MakeNEnjoy/interactive-track-and-trace/issues/12 * @return pointer to 4x4 matrix From a36991dbcaa746a5f24bc10fb42147265c402bbf Mon Sep 17 00:00:00 2001 From: robin Date: Sun, 5 May 2024 16:44:16 +0200 Subject: [PATCH 4/4] fix:added back non-identity advection --- vtk/src/helperClasses/LGlyphLayer.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/vtk/src/helperClasses/LGlyphLayer.cpp b/vtk/src/helperClasses/LGlyphLayer.cpp index 3b1a051..fdc4741 100644 --- a/vtk/src/helperClasses/LGlyphLayer.cpp +++ b/vtk/src/helperClasses/LGlyphLayer.cpp @@ -84,7 +84,7 @@ void LGlyphLayer::spoofPoints() { // returns new coords for a point; used to test the updateData function std::pair advect(int time, double lat, double lon) { - return {lat + 0., lon + 0.}; + return {lat + 0.01, lon + 0.01}; } void LGlyphLayer::updateData(int t) {