-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathperspective_transform.cpp
60 lines (49 loc) · 1.53 KB
/
perspective_transform.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
#include "vtkMatrix4x4.h"
#include "vtkNew.h"
#include "vtkPerspectiveTransform.h"
#include "vtkTransform.h"
#include <array>
#include <iostream>
using pointType = std::array<double, 3>;
auto operator<<(std::ostream& os, const pointType& p) -> std::ostream& {
os << "[" << p[0];
for (std::size_t i = 1; i < p.size(); ++i) {
os << "," << p[i];
}
os << "]";
return os;
}
auto main(int argc, char** argv) -> int {
vtkNew<vtkMatrix4x4> matrix;
matrix->SetElement(0, 0, 1);
matrix->SetElement(0, 1, 2);
matrix->SetElement(0, 2, 3);
matrix->SetElement(0, 3, 4);
matrix->SetElement(1, 0, 2);
matrix->SetElement(1, 1, 2);
matrix->SetElement(1, 2, 3);
matrix->SetElement(1, 3, 4);
matrix->SetElement(2, 0, 3);
matrix->SetElement(2, 1, 2);
matrix->SetElement(2, 2, 3);
matrix->SetElement(2, 3, 4);
matrix->SetElement(3, 0, 4);
matrix->SetElement(3, 1, 2);
matrix->SetElement(3, 2, 3);
matrix->SetElement(3, 3, 4);
vtkNew<vtkPerspectiveTransform> perspective_transform;
perspective_transform->SetMatrix(matrix);
vtkNew<vtkTransform> transfrom;
transfrom->SetMatrix(matrix);
pointType p;
p[0] = 1.0;
p[1] = 2.0;
p[2] = 3.0;
pointType normal_projection;
transfrom->TransformPoint(p.data(), normal_projection.data());
std::cout << "Standard projection: " << normal_projection << std::endl;
pointType perspectiveProjection;
perspective_transform->TransformPoint(p.data(), perspectiveProjection.data());
std::cout << "Perspective projection: " << perspectiveProjection << std::endl;
return 0;
}