]> Creatis software - creaRigidRegistration.git/blob - PackRecalage/src/bbPackRecalagePlaneReorientationBox.cxx
Feature #1766 Add licence terms for all files.
[creaRigidRegistration.git] / PackRecalage / src / bbPackRecalagePlaneReorientationBox.cxx
1 /*
2 # ---------------------------------------------------------------------
3 #
4 # Copyright (c) CREATIS (Centre de Recherche en Acquisition et Traitement de l'Image 
5 #                        pour la Santé)
6 # Authors : Eduardo Davila, Frederic Cervenansky, Claire Mouton
7 #
8 #  This software is governed by the CeCILL-B license under French law and 
9 #  abiding by the rules of distribution of free software. You can  use, 
10 #  modify and/ or redistribute the software under the terms of the CeCILL-B 
11 #  license as circulated by CEA, CNRS and INRIA at the following URL 
12 #  http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html 
13 #  or in the file LICENSE.txt.
14 #
15 #  As a counterpart to the access to the source code and  rights to copy,
16 #  modify and redistribute granted by the license, users are provided only
17 #  with a limited warranty  and the software's author,  the holder of the
18 #  economic rights,  and the successive licensors  have only  limited
19 #  liability. 
20 #
21 #  The fact that you are presently reading this means that you have had
22 #  knowledge of the CeCILL-B license and that you accept its terms.
23 # ------------------------------------------------------------------------   
24 */
25
26
27 #include "bbPackRecalagePlaneReorientationBox.h"
28 #include "bbPackRecalagePackage.h"
29 namespace bbPackRecalage
30 {
31
32 BBTK_ADD_BLACK_BOX_TO_PACKAGE(PackRecalage,PlaneReorientationBox)
33 BBTK_BLACK_BOX_IMPLEMENTATION(PlaneReorientationBox,bbtk::AtomicBlackBox);
34 void PlaneReorientationBox::Process()
35 {
36         if(!bbGetInputInX().empty() && bbGetInputInX().size() == 3 && !bbGetInputInY().empty() && bbGetInputInY().size() == 3 && !bbGetInputInZ().empty() && bbGetInputInZ().size() == 3)
37         {
38                 double a[3];            
39                 
40                 /*First Vector*/
41                 a[0] = bbGetInputInX()[1]-bbGetInputInX()[0];
42                 a[1] = bbGetInputInY()[1]-bbGetInputInY()[0];
43                 a[2] = bbGetInputInZ()[1]-bbGetInputInZ()[0];
44
45                 double b[3];
46
47                 /*Second Vector*/
48                 b[0] = bbGetInputInX()[2]-bbGetInputInX()[0];
49                 b[1] = bbGetInputInY()[2]-bbGetInputInY()[0];
50                 b[2] = bbGetInputInZ()[2]-bbGetInputInZ()[0];
51
52                 double normal[3];
53
54                 normal[0]=(a[1]*b[2])-(a[2]*b[1]);
55                 normal[1]=(a[2]*b[0])-(a[0]*b[2]);
56                 normal[2]=(a[0]*b[1])-(a[1]*b[0]);
57
58                 vtkMath::Normalize(normal);
59
60                 std::cout << "Normal axis : " << "X: " << normal[0] << " Y: " << normal[1] << " Z: " << normal[2] << std::endl;
61                 
62                 /*Unitary Vector in Y*/
63                 double y[3];
64                 y[0] = 0;
65                 y[1] = 1;
66                 y[2] = 0;
67
68                 /*Unitary Vector in X*/
69                 double x[3];
70                 x[0] = 1;
71                 x[1] = 0;
72                 x[2] = 0;               
73
74                 /*Normal vector without its z factor*/
75                 double normalZ[3];
76                 normalZ[0] = normal[0];
77                 normalZ[1] = normal[1];
78                 normalZ[2] = 0;
79
80                 /*Normal vector without its y factor*/
81                 double normalY[3];
82                 normalY[0] = normal[0];
83                 normalY[1] = 0;
84                 normalY[2] = normal[2];
85
86                 /*Angle for the rotation in Z*/
87                 double angleZ = acos(vtkMath::Dot(normalZ,y)/vtkMath::Norm(normalZ));           
88
89                 /*Angle for the rotation in Y*/
90                 double angleY = acos(vtkMath::Dot(x,normalY)/vtkMath::Norm(normalY));
91
92                 /*Convert from Radians to Degrees*/
93                 angleZ = vtkMath::DegreesFromRadians(angleZ);
94                 angleY = vtkMath::DegreesFromRadians(angleY);
95                 std::cout << "Angle for Z: " << angleZ << std::endl;
96                 std::cout << "Angle for Y: " << angleY << std::endl;
97
98                 transform->Identity();
99                 if(normal[0] < 0)
100                 {
101                         transform->RotateWXYZ(angleZ,0,0,1);
102                 }
103                 else
104                 {
105                         transform->RotateWXYZ(angleZ,0,0,-1);
106                 }
107                 if(normal[1]<0)
108                 {
109                         transform->RotateWXYZ(angleY,0,1,0);
110                 }
111                 else
112                 {
113                         if(angleY != 180){transform->RotateWXYZ(angleY,0,-1,0);}
114                 }
115                 //transform->Translate(bbGetInputCenterPoint()[0],bbGetInputCenterPoint()[1],bbGetInputCenterPoint()[2]);
116                 transform->Update();
117
118                 /*Set output and pray to god that it works :P*/
119                 bbSetOutputOut(transform);
120         }
121         else
122         {
123                 transform->Identity();
124                 transform->Update();
125                 bbSetOutputOut(transform);
126         }
127 }
128 void PlaneReorientationBox::bbUserSetDefaultValues()
129 {
130         std::vector<int> nullVector;
131         bbSetInputInX(nullVector);
132         bbSetInputInY(nullVector);
133         bbSetInputInZ(nullVector);
134 }
135 void PlaneReorientationBox::bbUserInitializeProcessing()
136 {
137         transform = vtkTransform::New();
138 }
139 void PlaneReorientationBox::bbUserFinalizeProcessing()
140 {
141         transform->Delete(); 
142 }
143 }
144 // EO namespace bbPackRecalage
145
146