#include "SpawnPointCallback.h" #include #include #include #include #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); 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(caller); if (evId == vtkCommand::LeftButtonPressEvent) { dragging = true; } if (evId == vtkCommand::LeftButtonReleaseEvent) { dragging = false; } if (!dragging) { return; } int x, y; interactor->GetEventPosition(x, y); 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 " << worldPos[1] << ", " << worldPos[0] << endl; inverseCartographicProjection->TransformPoint(worldPos, worldPos); vtkIdType id = points->InsertNextPoint(worldPos[0], worldPos[1], 0); data->SetPoints(points); vtkSmartPointer vertex = vtkSmartPointer::New(); vertex->GetPointIds()->SetId(0, id); vtkSmartPointer vertices = vtkSmartPointer::New(); vertices->InsertNextCell(vertex); data->SetVerts(vertices); ren->GetRenderWindow()->Render(); } SpawnPointCallback::SpawnPointCallback() : data(nullptr), points(nullptr), inverseCartographicProjection(nullptr), uvGrid(nullptr) { } SpawnPointCallback *SpawnPointCallback::New() { return new SpawnPointCallback; } void SpawnPointCallback::setData(const vtkSmartPointer &data) { this->data = data; } void SpawnPointCallback::setPoints(const vtkSmartPointer &points) { this->points = points; } void SpawnPointCallback::setRen(const vtkSmartPointer &ren) { this->ren = ren; } void SpawnPointCallback::setUVGrid(const std::shared_ptr &uvGrid) { this->uvGrid = uvGrid; inverseCartographicProjection = createInverseCartographicTransformFilter(uvGrid)->GetTransform(); }