merge conflic

This commit is contained in:
robin committed 2024-05-06 17:08:09 +02:00
1 parent 59bd2f5a73
commit c9a88b1a46
19 files changed
+325 -86

No files matched your search

@@ -0,0 +1,104 @@
#include "CameraMoveCallback.h"
#include <vtkVertex.h>
#include <vtkRenderer.h>
#include <vtkRenderWindowInteractor.h>
#include <vtkSmartPointer.h>
#include <vtkCommand.h>
#include <vtkRenderWindow.h>
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 intr = reinterpret_cast<vtkRenderWindowInteractor *>(caller);
switch (evId) {
case vtkCommand::KeyPressEvent:
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);
break;
case vtkCommand::MouseWheelBackwardEvent:
zoom(false);
break;
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::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) {
if (scale >= 0.2)
scale -= 0.1;
} else {
if (scale <= 0.9)
scale += 0.1;
}
this->cam->SetParallelScale(scale);
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);
if (dir == "Left" or dir == "h") {
pos[0] -= 0.1;
} else if (dir == "Up" or dir == "k" ) {
pos[1] += 0.1;
} else if (dir == "Right" or dir == "l" ) {
pos[0] += 0.1;
} else if (dir == "Down" or dir == "j" ) {
pos[1] -= 0.1;
}
clampCamera(pos);
}
CameraMoveCallback::CameraMoveCallback() : cam(nullptr) {}
CameraMoveCallback *CameraMoveCallback::New(vtkCamera *cam) {
auto me = new CameraMoveCallback;
me->setCam(cam);
return me;
}
void CameraMoveCallback::setCam(const vtkSmartPointer<vtkCamera> &cam) {
this->cam = cam;
}
@@ -0,0 +1,56 @@
#ifndef CAMERAMOVECALLBACK_H
#define CAMERAMOVECALLBACK_H
#include <vtkCallbackCommand.h>
#include <vtkCamera.h>
#include <vtkRenderWindowInteractor.h>
#include <vtkMatrix4x4.h>
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<vtkCamera> &cam);
private:
/** The camera to operate on.
*/
vtkSmartPointer<vtkCamera> 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);
};
#endif
@@ -17,40 +17,40 @@ void convertDisplayToWorld(vtkRenderer *renderer, int x, int y, double *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);
// 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;
}
if (evId == vtkCommand::LeftButtonPressEvent) {
dragging = true;
}
if (evId == vtkCommand::LeftButtonReleaseEvent) {
dragging = false;
}
if (!dragging) {
return;
}
int x, y;
interactor->GetEventPosition(x, y);
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;
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);
vtkIdType id = points->InsertNextPoint(worldPos[0], worldPos[1], 0);
data->SetPoints(points);
vtkSmartPointer<vtkVertex> vertex = vtkSmartPointer<vtkVertex>::New();
vertex->GetPointIds()->SetId(0, id);
vtkSmartPointer<vtkVertex> vertex = vtkSmartPointer<vtkVertex>::New();
vertex->GetPointIds()->SetId(0, id);
vtkSmartPointer<vtkCellArray> vertices = vtkSmartPointer<vtkCellArray>::New();
vertices->InsertNextCell(vertex);
data->SetVerts(vertices);
ren->GetRenderWindow()->Render();
vtkSmartPointer<vtkCellArray> vertices = vtkSmartPointer<vtkCellArray>::New();
vertices->InsertNextCell(vertex);
data->SetVerts(vertices);
ren->GetRenderWindow()->Render();
}
@@ -2,6 +2,7 @@
#define SPAWNPOINTCALLBACK_H
#include <memory>
#include <vtkCallbackCommand.h>
#include <vtkRenderWindowInteractor.h>
#include <vtkPoints.h>
@@ -2,12 +2,13 @@
#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) {
TimerCallbackCommand *cb = new TimerCallbackCommand();
cb->setProgram(program);
cb->setPaused(false);
cb->setPaused(true);
return cb;
}
@@ -17,19 +18,17 @@ 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) {
this->program = program;
}
Reference in new issue
Block a user
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.