]> 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                 /*Unitary Vector in Y*/
13                 double y[3];
14                 y[0] = 0;
15                 y[1] = 1;
16                 y[2] = 0;
17
18                 /*Unitary Vector in X*/
19                 double x[3];
20                 x[0] = 1;
21                 x[1] = 0;
22                 x[2] = 0;
23
24                 double normal[3];
25
26                 /*Normal vector without its z factor*/
27                 double normalZ[3];
28                 normalZ[0] = normal[0];
29                 normalZ[1] = normal[1];
30                 normalZ[2] = 0;
31
32                 /*Normal vector without its y factor*/
33                 double normalY[3];
34                 normalY[0] = normal[0];
35                 normalY[1] = 0;
36                 normalY[2] = normal[2];
37
38                 /*Angle for the rotation in Z*/
39                 double angleZ = acos(vtkMath::Dot(normalZ,y)/vtkMath::Norm(normalZ));           
40
41                 /*Angle for the rotation in Y*/
42                 double angleY = acos(vtkMath::Dot(x,normalY)/vtkMath::Norm(normalY));
43
44                 /*Convert from Radians to Degrees*/
45                 angleZ = vtkMath::DegreesFromRadians(angleZ);
46                 angleY = vtkMath::DegreesFromRadians(angleY);
47                 std::cout << "Angle for Z: " << angleZ << std::endl;
48                 std::cout << "Angle for Y: " << angleY << std::endl;
49
50                 vtkTransform *transform = vtkTransform::New();
51                 transform->Identity();
52                 if(normal[0] < 0)
53                 {
54                         transform->RotateWXYZ(angleZ,0,0,1);
55                 }
56                 else
57                 {
58                         transform->RotateWXYZ(angleZ,0,0,-1);
59                 }
60                 if(normal[1]<0)
61                 {
62                         transform->RotateWXYZ(angleY,0,1,0);
63                 }
64                 else
65                 {
66                         if(angleY != 180){transform->RotateWXYZ(angleY,0,-1,0);}
67                 }
68                 //transform->Translate(bbGetInputCenterPoint()[0],bbGetInputCenterPoint()[1],bbGetInputCenterPoint()[2]);
69                 transform->Update();
70
71                 /*Set output and pray to god that it works :P*/
72                 bbSetOutputOut(transform);
73         }
74 }
75 void PlaneReorientationBox::bbUserSetDefaultValues()
76 {
77         std::vector<int> nullVector;
78         bbSetInputInX(nullVector);
79         bbSetInputInY(nullVector);
80         bbSetInputInZ(nullVector);
81 }
82 void PlaneReorientationBox::bbUserInitializeProcessing()
83 {
84  
85 //  THE INITIALIZATION METHOD BODY : 
86 //    Here does nothing  
87 //    but this is where you should allocate the internal/output pointers  
88 //    if any  
89  
90   
91 }
92 void PlaneReorientationBox::bbUserFinalizeProcessing()
93 {
94  
95 //  THE FINALIZATION METHOD BODY : 
96 //    Here does nothing  
97 //    but this is where you should desallocate the internal/output pointers  
98 //    if any 
99   
100 }
101 }
102 // EO namespace bbPackRecalage
103
104