]> Creatis software - creaRigidRegistration.git/blob - lib/VectorMath.cxx
e9444c2fb5299df37984844d491c6b8f674d039c
[creaRigidRegistration.git] / lib / VectorMath.cxx
1 #include "VectorMath.h"
2
3
4
5 VectorMath::VectorMath()
6 {
7         
8 }
9
10 VectorMath::~VectorMath()
11 {
12         
13 }
14
15 /*Sets all the vector points*/
16 void VectorMath::SetData(std::vector<int> pointsX1, std::vector<int> pointsX2, std::vector<int> pointsY1, std::vector<int> pointsY2, std::vector<int> pointsZ1, std::vector<int> pointsZ2)
17 {
18     _pointx1a = pointsX1[0];
19         _pointx1b = pointsX1[1];
20
21         _pointx2a = pointsX2[0];
22         _pointx2b = pointsX2[1];
23
24         _pointy1a = pointsY1[0];
25         _pointy1b = pointsY1[1];
26
27         _pointy2a = pointsY2[0];
28         _pointy2b = pointsY2[1];
29
30         _pointz1a = pointsZ1[0];
31         _pointz1b = pointsZ1[1];
32
33         _pointz2a = pointsZ2[0];
34         _pointz2b = pointsZ2[1];
35 }
36
37 /*Runs the calculations*/
38 void VectorMath::Run()
39 {
40         _origin.clear();
41         _origin.push_back(_pointx2a);
42         _origin.push_back(_pointy2a);
43         _origin.push_back(_pointz2a);
44
45         std::cout << "Vector Math: Origin points: X = " <<  _pointx2a << " Y = " << _pointy2a << " Z = " << _pointz2a << std::endl;
46
47         _originReslicer.clear();
48         _originReslicer.push_back(_pointx1a);
49         _originReslicer.push_back(_pointy1a);
50         _originReslicer.push_back(_pointz1a);
51
52         std::cout << "Vector Math: Origin Reslicer points: X = " <<  _pointx1a << " Y = " << _pointy1a << " Z = " << _pointz1a << std::endl;
53
54         double _vectorA[3];
55         _vectorA[0] =(double)(_pointx1b - _pointx1a);
56         _vectorA[1] =(double)(_pointy1b - _pointy1a);
57         _vectorA[2] =(double)(_pointz1b - _pointz1a);
58
59         double normA = vtkMath::Norm(_vectorA);
60
61         _vectorA[0] =  _vectorA[0]/normA;
62         _vectorA[1] =  _vectorA[1]/normA;
63         _vectorA[2] =  _vectorA[2]/normA;
64
65         double _vectorB[3];
66         _vectorB[0] =(double)(_pointx2b - _pointx2a - _pointx1a);
67         _vectorB[1] =(double)(_pointy2b - _pointy2a - _pointy1a);
68         _vectorB[2] =(double)(_pointz2b - _pointz2a - _pointz1a);
69
70         double normB = vtkMath::Norm(_vectorB);
71
72         _vectorB[0] =  _vectorB[0]/normB;
73         _vectorB[1] =  _vectorB[1]/normB;
74         _vectorB[2] =  _vectorB[2]/normB;
75
76         vtkMath::Cross(_vectorA, _vectorB, _result);
77
78         std::cout << "Data from vector A: X: " << _vectorA[0] << " Y: " << _vectorA[1] << " Z: " << _vectorA[2] << std::endl;
79         std::cout << "Data from vector B: X: " << _vectorB[0] << " Y: " << _vectorB[1] << " Z: " << _vectorB[2] << std::endl;
80         std::cout << "Data from result: X: " << _result[0] << " Y: " << _result[1] << " Z: " << _result[2] << std::endl;
81
82         double _vectorOrigin[3] = {0,0,0};
83
84         double distanceA = vtkMath::Distance2BetweenPoints(_vectorOrigin, _vectorA);
85         double distanceB = vtkMath::Distance2BetweenPoints(_vectorOrigin, _vectorA);
86
87         double proportion = distanceA/distanceB;
88         /*
89         _scaleX = proportion;
90         _scaleY = proportion;
91         _scaleZ = proportion;
92         */
93
94         _scaleX = 1;
95         _scaleY = 1;
96         _scaleZ = 1;
97
98         _angle = acos(vtkMath::Dot(_vectorA, _vectorB));
99
100         _angle = vtkMath::DegreesFromRadians(_angle);
101
102         std::cout << "Dot " << vtkMath::Dot(_vectorA, _vectorB) << std::endl;
103         std::cout << "Angle " << (double)_angle << std::endl;
104 }
105
106 /*Returns the origin of the second vector*/
107 std::vector<int> VectorMath::GetOrigin()
108 {
109         return _origin;
110 }
111
112 /*Returns the origin of the first vector*/
113 std::vector<int> VectorMath::GetOriginReslicer()
114 {
115         return _originReslicer;
116 }
117
118 /*Returns the cross product of the two vectors*/
119 void VectorMath::GetResult(double result[3])
120 {
121         result = _result;
122 }
123
124 /*Scale in X*/
125 double VectorMath::GetScaleX()
126 {
127         return _scaleX;
128 }
129
130 /*Scale in Y*/
131 double VectorMath::GetScaleY()
132 {
133         return _scaleY;
134 }
135
136 /*Scale in Z*/
137 double VectorMath::GetScaleZ()
138 {
139         return _scaleZ;
140 }
141
142 /*Rotation angle (dot product)*/
143 double VectorMath::GetAngle()
144 {
145         return _angle;
146 }
147