fix: stylistic changes + addObservers
This commit is contained in:
77
vtk/src/commands/SpawnPointCallback.cpp
Normal file
77
vtk/src/commands/SpawnPointCallback.cpp
Normal file
@@ -0,0 +1,77 @@
|
||||
#include "SpawnPointCallback.h"
|
||||
|
||||
#include <vtkVertex.h>
|
||||
#include <vtkRenderer.h>
|
||||
#include <vtkRenderWindowInteractor.h>
|
||||
#include <vtkSmartPointer.h>
|
||||
#include <vtkCommand.h>
|
||||
#include <vtkRenderWindow.h>
|
||||
|
||||
#include "../CartographicTransformation.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);
|
||||
|
||||
double worldPos[4] = {2, 0 ,0, 0};
|
||||
double displayPos[3] = {static_cast<double>(x), static_cast<double>(y), 0.0};
|
||||
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);
|
||||
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), inverseCartographicProjection(nullptr) {
|
||||
inverseCartographicProjection = getCartographicTransformMatrix();
|
||||
inverseCartographicProjection->Invert();
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
void SpawnPointCallback::setRen(const vtkSmartPointer<vtkRenderer> &ren) {
|
||||
this->ren = ren;
|
||||
}
|
||||
33
vtk/src/commands/SpawnPointCallback.h
Normal file
33
vtk/src/commands/SpawnPointCallback.h
Normal file
@@ -0,0 +1,33 @@
|
||||
#ifndef VTKBASE_SPAWNPOINTCALLBACK_H
|
||||
#define VTKBASE_SPAWNPOINTCALLBACK_H
|
||||
|
||||
|
||||
#include <vtkCallbackCommand.h>
|
||||
#include <vtkRenderWindowInteractor.h>
|
||||
#include <vtkPoints.h>
|
||||
#include <vtkPolyData.h>
|
||||
#include <vtkMatrix4x4.h>
|
||||
|
||||
class SpawnPointCallback : public vtkCallbackCommand {
|
||||
|
||||
public:
|
||||
static SpawnPointCallback *New();
|
||||
SpawnPointCallback();
|
||||
|
||||
void setPoints(const vtkSmartPointer<vtkPoints> &points);
|
||||
|
||||
void setData(const vtkSmartPointer<vtkPolyData> &data);
|
||||
|
||||
void setRen(const vtkSmartPointer<vtkRenderer> &ren);
|
||||
private:
|
||||
vtkSmartPointer<vtkPolyData> data;
|
||||
vtkSmartPointer<vtkPoints> points;
|
||||
vtkSmartPointer<vtkRenderer> ren;
|
||||
vtkSmartPointer<vtkMatrix4x4> inverseCartographicProjection;
|
||||
|
||||
void Execute(vtkObject *caller, unsigned long evId, void *callData) override;
|
||||
bool dragging = false;
|
||||
};
|
||||
|
||||
|
||||
#endif //VTKBASE_SPAWNPOINTCALLBACK_H
|
||||
@@ -1,5 +1,5 @@
|
||||
#include "TimerCallbackCommand.h"
|
||||
#include "../helperClasses/Program.h"
|
||||
#include "../Program.h"
|
||||
|
||||
|
||||
TimerCallbackCommand::TimerCallbackCommand() : dt(3600), maxTime(3600*24*365), time(0) {}
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
#define TIMERCALLBACKCOMMAND_H
|
||||
|
||||
#include <vtkCallbackCommand.h>
|
||||
#include "../helperClasses/Program.h"
|
||||
#include "../Program.h"
|
||||
|
||||
class TimerCallbackCommand : public vtkCallbackCommand {
|
||||
public:
|
||||
|
||||
Reference in New Issue
Block a user