forked from dgobbi/ToolCursor
-
Notifications
You must be signed in to change notification settings - Fork 0
/
vtkPanCameraTool.cxx
104 lines (78 loc) · 2.77 KB
/
vtkPanCameraTool.cxx
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
/*=========================================================================
Program: ToolCursor
Module: vtkPanCameraTool.cxx
Copyright (c) 2010 David Gobbi
All rights reserved.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notice for more information.
=========================================================================*/
#include "vtkPanCameraTool.h"
#include "vtkObjectFactory.h"
#include "vtkToolCursor.h"
#include "vtkCamera.h"
#include "vtkRenderer.h"
#include "vtkTransform.h"
#include "vtkMath.h"
#include "vtkVolumePicker.h"
vtkStandardNewMacro(vtkPanCameraTool);
//----------------------------------------------------------------------------
vtkPanCameraTool::vtkPanCameraTool()
{
this->Transform = vtkTransform::New();
}
//----------------------------------------------------------------------------
vtkPanCameraTool::~vtkPanCameraTool()
{
this->Transform->Delete();
}
//----------------------------------------------------------------------------
void vtkPanCameraTool::PrintSelf(ostream& os, vtkIndent indent)
{
this->Superclass::PrintSelf(os,indent);
}
//----------------------------------------------------------------------------
void vtkPanCameraTool::StartAction()
{
this->Superclass::StartAction();
vtkToolCursor *cursor = this->GetToolCursor();
vtkCamera *camera = cursor->GetRenderer()->GetActiveCamera();
camera->GetFocalPoint(this->StartCameraFocalPoint);
camera->GetPosition(this->StartCameraPosition);
this->Transform->Identity();
}
//----------------------------------------------------------------------------
void vtkPanCameraTool::StopAction()
{
this->Superclass::StopAction();
}
//----------------------------------------------------------------------------
void vtkPanCameraTool::DoAction()
{
this->Superclass::DoAction();
vtkToolCursor *cursor = this->GetToolCursor();
vtkCamera *camera = cursor->GetRenderer()->GetActiveCamera();
// Get the initial point.
double p0[3];
this->GetStartPosition(p0);
// Get the depth.
double x, y, z;
this->WorldToDisplay(p0, x, y, z);
// Get the display position.
double p[3];
this->GetDisplayPosition(x, y);
this->DisplayToWorld(x, y, z, p);
// Get the vector.
double v[3];
v[0] = p[0] - p0[0];
v[1] = p[1] - p0[1];
v[2] = p[2] - p0[2];
this->Transform->PostMultiply();
this->Transform->Translate(-v[0], -v[1], -v[2]);
double cameraPos[3], cameraFocalPoint[3];
this->Transform->TransformPoint(this->StartCameraPosition, cameraPos);
this->Transform->TransformPoint(this->StartCameraFocalPoint,
cameraFocalPoint);
camera->SetPosition(cameraPos);
camera->SetFocalPoint(cameraFocalPoint);
}