]> Creatis software - creaRigidRegistration.git/blob - PackRecalage/src/bbPackRecalagePlaneReorientationBox.cxx
*** empty log message ***
[creaRigidRegistration.git] / PackRecalage / src / bbPackRecalagePlaneReorientationBox.cxx
1 #include "bbPackRecalagePlaneReorientationBox.h"
2 #include "bbPackRecalagePackage.h"
3 namespace bbPackRecalage
4 {
5
6 BBTK_ADD_BLACK_BOX_TO_PACKAGE(PackRecalage,PlaneReorientationBox)
7 BBTK_BLACK_BOX_IMPLEMENTATION(PlaneReorientationBox,bbtk::AtomicBlackBox);
8 void PlaneReorientationBox::Process()
9 {
10         if(!bbGetInputInX().empty() && bbGetInputInX().size() == 3 && !bbGetInputInY().empty() && bbGetInputInY().size() == 3 && !bbGetInputInZ().empty() && bbGetInputInZ().size() == 3)
11         {
12                 double a[3];            
13                 
14                 /*First Vector*/
15                 a[0] = bbGetInputInX()[1]-bbGetInputInX()[0];
16                 a[1] = bbGetInputInY()[1]-bbGetInputInY()[0];
17                 a[2] = bbGetInputInZ()[1]-bbGetInputInZ()[0];
18
19                 double b[3];
20
21                 /*Second Vector*/
22                 b[0] = bbGetInputInX()[2]-bbGetInputInX()[0];
23                 b[1] = bbGetInputInY()[2]-bbGetInputInY()[0];
24                 b[2] = bbGetInputInZ()[2]-bbGetInputInZ()[0];
25
26                 double normal[3];
27
28                 normal[0]=(a[1]*b[2])-(a[2]*b[1]);
29                 normal[1]=(a[2]*b[0])-(a[0]*b[2]);
30                 normal[2]=(a[0]*b[1])-(a[1]*b[0]);
31
32                 vtkMath::Normalize(normal);
33
34                 std::cout << "Normal axis : " << "X: " << normal[0] << " Y: " << normal[1] << " Z: " << normal[2] << std::endl;
35                 
36                 /*Unitary Vector in Y*/
37                 double y[3];
38                 y[0] = 0;
39                 y[1] = 1;
40                 y[2] = 0;
41
42                 /*Unitary Vector in X*/
43                 double x[3];
44                 x[0] = 1;
45                 x[1] = 0;
46                 x[2] = 0;               
47
48                 /*Normal vector without its z factor*/
49                 double normalZ[3];
50                 normalZ[0] = normal[0];
51                 normalZ[1] = normal[1];
52                 normalZ[2] = 0;
53
54                 /*Normal vector without its y factor*/
55                 double normalY[3];
56                 normalY[0] = normal[0];
57                 normalY[1] = 0;
58                 normalY[2] = normal[2];
59
60                 /*Angle for the rotation in Z*/
61                 double angleZ = acos(vtkMath::Dot(normalZ,y)/vtkMath::Norm(normalZ));           
62
63                 /*Angle for the rotation in Y*/
64                 double angleY = acos(vtkMath::Dot(x,normalY)/vtkMath::Norm(normalY));
65
66                 /*Convert from Radians to Degrees*/
67                 angleZ = vtkMath::DegreesFromRadians(angleZ);
68                 angleY = vtkMath::DegreesFromRadians(angleY);
69                 std::cout << "Angle for Z: " << angleZ << std::endl;
70                 std::cout << "Angle for Y: " << angleY << std::endl;
71
72                 transform->Identity();
73                 if(normal[0] < 0)
74                 {
75                         transform->RotateWXYZ(angleZ,0,0,1);
76                 }
77                 else
78                 {
79                         transform->RotateWXYZ(angleZ,0,0,-1);
80                 }
81                 if(normal[1]<0)
82                 {
83                         transform->RotateWXYZ(angleY,0,1,0);
84                 }
85                 else
86                 {
87                         if(angleY != 180){transform->RotateWXYZ(angleY,0,-1,0);}
88                 }
89                 //transform->Translate(bbGetInputCenterPoint()[0],bbGetInputCenterPoint()[1],bbGetInputCenterPoint()[2]);
90                 transform->Update();
91
92                 /*Set output and pray to god that it works :P*/
93                 bbSetOutputOut(transform);
94         }
95         else
96         {
97                 transform->Identity();
98                 transform->Update();
99                 bbSetOutputOut(transform);
100         }
101 }
102 void PlaneReorientationBox::bbUserSetDefaultValues()
103 {
104         std::vector<int> nullVector;
105         bbSetInputInX(nullVector);
106         bbSetInputInY(nullVector);
107         bbSetInputInZ(nullVector);
108 }
109 void PlaneReorientationBox::bbUserInitializeProcessing()
110 {
111         transform = vtkTransform::New();
112 }
113 void PlaneReorientationBox::bbUserFinalizeProcessing()
114 {
115         transform->Delete(); 
116 }
117 }
118 // EO namespace bbPackRecalage
119
120