2 # ---------------------------------------------------------------------
4 # Copyright (c) CREATIS (Centre de Recherche en Acquisition et Traitement de l'Image
6 # Authors : Eduardo Davila, Frederic Cervenansky, Claire Mouton
7 # Previous Authors : Laurent Guigues, Jean-Pierre Roux
8 # CreaTools website : www.creatis.insa-lyon.fr/site/fr/creatools_accueil
10 # This software is governed by the CeCILL-B license under French law and
11 # abiding by the rules of distribution of free software. You can use,
12 # modify and/ or redistribute the software under the terms of the CeCILL-B
13 # license as circulated by CEA, CNRS and INRIA at the following URL
14 # http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html
15 # or in the file LICENSE.txt.
17 # As a counterpart to the access to the source code and rights to copy,
18 # modify and redistribute granted by the license, users are provided only
19 # with a limited warranty and the software's author, the holder of the
20 # economic rights, and the successive licensors have only limited
23 # The fact that you are presently reading this means that you have had
24 # knowledge of the CeCILL-B license and that you accept its terms.
25 # ------------------------------------------------------------------------ */
28 #include "bbvtkTransform.h"
29 #include "bbvtkPackage.h"
33 BBTK_ADD_BLACK_BOX_TO_PACKAGE(vtk,Transform);
34 BBTK_BLACK_BOX_IMPLEMENTATION(Transform,bbtk::AtomicBlackBox);
36 // --------------------------------------------------------------
38 void Transform::bbUserSetDefaultValues()
42 vecScale.push_back(1); // scale x
43 vecScale.push_back(1); // scale y
44 vecScale.push_back(1); // scale z
45 bbSetInputScale(vecScale);
47 vecRotateWXYZ.push_back(0); //angle
48 vecRotateWXYZ.push_back(1); //vx
49 vecRotateWXYZ.push_back(0); //vy
50 vecRotateWXYZ.push_back(0); //vz
51 bbSetInputRotateWXYZ(vecRotateWXYZ);
53 vecTranslate.push_back(0); //tx
54 vecTranslate.push_back(0); //ty
55 vecTranslate.push_back(0); //tz
56 bbSetInputTranslate(vecTranslate);
58 vecSpacing.push_back(1); //spacing x
59 vecSpacing.push_back(1); //spacing y
60 vecSpacing.push_back(1); //spacing z
61 bbSetInputSpacing(vecSpacing);
66 // --------------------------------------------------------------
67 void Transform::bbUserInitializeProcessing()
69 bbUserFinalizeProcessing();
70 result = vtkTransform::New();
72 resultInverse = vtkTransform::New();
73 resultInverse->Update();
76 // --------------------------------------------------------------
77 void Transform::bbUserFinalizeProcessing()
87 // --------------------------------------------------------------
88 void Transform::Process()
90 bbUserInitializeProcessing();
91 if (bbGetInputIn()!=NULL)
93 result->Concatenate( bbGetInputIn()->GetMatrix() );
95 if ((bbGetInputTranslate().size()>=3) && (bbGetInputSpacing().size()>=3))
97 double tx = bbGetInputTranslate()[0] * bbGetInputSpacing()[0];
98 double ty = bbGetInputTranslate()[1] * bbGetInputSpacing()[1];
99 double tz = bbGetInputTranslate()[2] * bbGetInputSpacing()[2];
100 result->Translate(tx,ty,tz);
101 } // if translate spacing size >=3
102 if (bbGetInputScale().size()>=3)
104 result->Scale(bbGetInputScale()[0], bbGetInputScale()[1], bbGetInputScale()[2]);
105 } // if scale size >=3
106 if (bbGetInputRotateWXYZ().size()>=4)
108 result->RotateWXYZ(bbGetInputRotateWXYZ()[0],bbGetInputRotateWXYZ()[1], bbGetInputRotateWXYZ()[2], bbGetInputRotateWXYZ()[3]);
109 } // if rotation size >=4
111 if (bbGetInputRotateToNormal().size()>=3)
113 double v1[3],v2[3],v3[3];
117 v2[0] = bbGetInputRotateToNormal()[0];
118 v2[1] = bbGetInputRotateToNormal()[1];
119 v2[2] = bbGetInputRotateToNormal()[2];
120 vtkMath *vtkmath = vtkMath::New();
121 double ang = acos ( vtkmath->Dot(v1,v2) );
122 ang = vtkmath->DegreesFromRadians( ang );
123 vtkmath->Cross( v1,v2,v3 );
125 result->RotateWXYZ( ang , v3[0], v3[1], v3[2] );
126 } // if rotation size >=4
128 if (bbGetInputInverse()==false)
130 bbSetOutputOut(result);
132 vtkMatrix4x4 *matrix;
133 matrix=vtkMatrix4x4::New();
134 result->GetInverse(matrix);
135 resultInverse->SetMatrix( matrix );
136 bbSetOutputOut(resultInverse);
140 }// EO namespace bbvtk