-
Notifications
You must be signed in to change notification settings - Fork 0
/
SliceInteractorStyle.cpp
107 lines (90 loc) · 3.02 KB
/
SliceInteractorStyle.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
//
// SliceInteractorStyle.cpp
// VentTrackS
//
// Created by Tobias Lang on 09.04.17.
//
//
#include "vtkRenderwindowInteractor.h"
#include "vtkSmartPointer.h"
#include "vtkCoordinate.h"
#include "vtkRenderWindow.h"
#include "vtkRendererCollection.h"
#include "VentTrackS.h"
#include "SliceInteractorStyle.h"
extern VolumeData vd;
void SliceInteractorStyle::SetMainWindow(VMainWindow* _mainWindow)
{
mainWindow = _mainWindow;
}
void SliceInteractorStyle::SetSliceType(SliceType _sliceType)
{
sliceType = _sliceType;
}
void SliceInteractorStyle::OnLeftButtonDown()
{
std::cout << "Pressed left mouse button." << std::endl;
int x = this->Interactor->GetEventPosition()[0];
int y = this->Interactor->GetEventPosition()[1];
std::cout << "(x,y) = (" << x << "," << y << ")" << std::endl;
vtkSmartPointer<vtkCoordinate> coordinate = vtkSmartPointer<vtkCoordinate>::New();
coordinate->SetCoordinateSystemToDisplay();
coordinate->SetValue(x,y,0);
// This doesn't produce the right value if the sphere is zoomed in???
double* world = coordinate->GetComputedWorldValue(this->Interactor->GetRenderWindow()->GetRenderers()->GetFirstRenderer());
std::cout << "World coordinate: " << world[0] << ", " << world[1] << ", " << world[2] << std::endl;
switch(sliceType) {
case SliceType::X:
//mainWindow->changeY((world[0] + vd.height/2));
mainWindow->changeY(calcY(world[0])*10/9);
//mainWindow->changeZ(-world[1]*1.13 + vd.width/2);
mainWindow->changeZ(calcZ(world[1])/1.06);
break;
case SliceType::Y:
//mainWindow->changeX(world[0] + vd.width/2);
mainWindow->changeX(calcX(world[0])*10/9);
mainWindow->changeZ(calcZ(world[1])/1.06);
break;
case SliceType::Z:
mainWindow->changeX((world[0] + vd.height/2));
mainWindow->changeY((world[1] + vd.width/2)*10/9);
}
// Forward events
vtkInteractorStyleTrackballCamera::OnLeftButtonDown();
}
void SliceInteractorStyle::OnKeyPress()
{
// Get the keypress
vtkRenderWindowInteractor *rwi = this->Interactor;
std::string key = rwi->GetKeySym();
// Output the key that was pressed
std::cout << "Pressed " << key << std::endl;
// Handle an arrow key
if (key == "Up")
{
std::cout << "The up arrow was pressed." << std::endl;
}
// Handle a "normal" key
if (key == "a")
{
std::cout << "The a key was pressed." << std::endl;
}
// Forward events
vtkInteractorStyleTrackballCamera::OnKeyPress();
}
int SliceInteractorStyle::calcX(double coord) {
double xLeft = 98;
double xRight = -100;
return vd.width / (xRight - xLeft) * (coord - xLeft);
}
int SliceInteractorStyle::calcY(double coord) {
double yBack = 105;
double yFront = -102;
return vd.depth / (yBack - yFront) * (coord - yFront);
}
int SliceInteractorStyle::calcZ(double coord) {
double zTop = 98;
double zBottom = -100;
return vd.height / (zBottom - zTop) * (coord - zTop);
}
vtkStandardNewMacro(SliceInteractorStyle);