2 # ---------------------------------------------------------------------
4 # Copyright (c) CREATIS (Centre de Recherche en Acquisition et Traitement de l'Image
6 # Authors : Eduardo Davila, Frederic Cervenansky, Claire Mouton
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.
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
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 # ------------------------------------------------------------------------
27 #include "bbPackRecalagePlaneReorientationBox.h"
28 #include "bbPackRecalagePackage.h"
29 namespace bbPackRecalage
32 BBTK_ADD_BLACK_BOX_TO_PACKAGE(PackRecalage,PlaneReorientationBox)
33 BBTK_BLACK_BOX_IMPLEMENTATION(PlaneReorientationBox,bbtk::AtomicBlackBox);
34 void PlaneReorientationBox::Process()
36 if(!bbGetInputInX().empty() && bbGetInputInX().size() == 3 && !bbGetInputInY().empty() && bbGetInputInY().size() == 3 && !bbGetInputInZ().empty() && bbGetInputInZ().size() == 3)
41 a[0] = bbGetInputInX()[1]-bbGetInputInX()[0];
42 a[1] = bbGetInputInY()[1]-bbGetInputInY()[0];
43 a[2] = bbGetInputInZ()[1]-bbGetInputInZ()[0];
48 b[0] = bbGetInputInX()[2]-bbGetInputInX()[0];
49 b[1] = bbGetInputInY()[2]-bbGetInputInY()[0];
50 b[2] = bbGetInputInZ()[2]-bbGetInputInZ()[0];
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]);
58 vtkMath::Normalize(normal);
60 std::cout << "Normal axis : " << "X: " << normal[0] << " Y: " << normal[1] << " Z: " << normal[2] << std::endl;
62 /*Unitary Vector in Y*/
68 /*Unitary Vector in X*/
74 /*Normal vector without its z factor*/
76 normalZ[0] = normal[0];
77 normalZ[1] = normal[1];
80 /*Normal vector without its y factor*/
82 normalY[0] = normal[0];
84 normalY[2] = normal[2];
86 /*Angle for the rotation in Z*/
87 double angleZ = acos(vtkMath::Dot(normalZ,y)/vtkMath::Norm(normalZ));
89 /*Angle for the rotation in Y*/
90 double angleY = acos(vtkMath::Dot(x,normalY)/vtkMath::Norm(normalY));
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;
98 transform->Identity();
101 transform->RotateWXYZ(angleZ,0,0,1);
105 transform->RotateWXYZ(angleZ,0,0,-1);
109 transform->RotateWXYZ(angleY,0,1,0);
113 if(angleY != 180){transform->RotateWXYZ(angleY,0,-1,0);}
115 //transform->Translate(bbGetInputCenterPoint()[0],bbGetInputCenterPoint()[1],bbGetInputCenterPoint()[2]);
118 /*Set output and pray to god that it works :P*/
119 bbSetOutputOut(transform);
123 transform->Identity();
125 bbSetOutputOut(transform);
128 void PlaneReorientationBox::bbUserSetDefaultValues()
130 std::vector<int> nullVector;
131 bbSetInputInX(nullVector);
132 bbSetInputInY(nullVector);
133 bbSetInputInZ(nullVector);
135 void PlaneReorientationBox::bbUserInitializeProcessing()
137 transform = vtkTransform::New();
139 void PlaneReorientationBox::bbUserFinalizeProcessing()
144 // EO namespace bbPackRecalage