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()
41 bbSetInputInverse(false);
43 vecScale.push_back(1); // scale x
44 vecScale.push_back(1); // scale y
45 vecScale.push_back(1); // scale z
46 bbSetInputScale(vecScale);
48 vecRotateWXYZ.push_back(0); //angle
49 vecRotateWXYZ.push_back(1); //vx
50 vecRotateWXYZ.push_back(0); //vy
51 vecRotateWXYZ.push_back(0); //vz
52 bbSetInputRotateWXYZ(vecRotateWXYZ);
54 vecTranslate.push_back(0); //tx
55 vecTranslate.push_back(0); //ty
56 vecTranslate.push_back(0); //tz
57 bbSetInputTranslate(vecTranslate);
59 vecSpacing.push_back(1); //spacing x
60 vecSpacing.push_back(1); //spacing y
61 vecSpacing.push_back(1); //spacing z
62 bbSetInputSpacing(vecSpacing);
67 // --------------------------------------------------------------
68 void Transform::bbUserInitializeProcessing()
70 bbUserFinalizeProcessing();
71 result = vtkTransform::New();
73 resultInverse = vtkTransform::New();
74 resultInverse->Update();
77 // --------------------------------------------------------------
78 void Transform::bbUserFinalizeProcessing()
88 // --------------------------------------------------------------
89 void Transform::Process()
91 bbUserInitializeProcessing();
92 if (bbGetInputIn()!=NULL)
94 result->Concatenate( bbGetInputIn()->GetMatrix() );
96 if ((bbGetInputTranslate().size()>=3) && (bbGetInputSpacing().size()>=3))
98 double tx = bbGetInputTranslate()[0] * bbGetInputSpacing()[0];
99 double ty = bbGetInputTranslate()[1] * bbGetInputSpacing()[1];
100 double tz = bbGetInputTranslate()[2] * bbGetInputSpacing()[2];
101 result->Translate(tx,ty,tz);
102 } // if translate spacing size >=3
103 if (bbGetInputScale().size()>=3)
105 result->Scale(bbGetInputScale()[0], bbGetInputScale()[1], bbGetInputScale()[2]);
106 } // if scale size >=3
107 if (bbGetInputRotateWXYZ().size()>=4)
109 result->RotateWXYZ(bbGetInputRotateWXYZ()[0],bbGetInputRotateWXYZ()[1], bbGetInputRotateWXYZ()[2], bbGetInputRotateWXYZ()[3]);
110 } // if rotation size >=4
112 if (bbGetInputRotateToNormal().size()>=3)
114 double v1[3],v2[3],v3[3];
118 v2[0] = bbGetInputRotateToNormal()[0];
119 v2[1] = bbGetInputRotateToNormal()[1];
120 v2[2] = bbGetInputRotateToNormal()[2];
122 double mag= sqrt( v2[0]*v2[0] + v2[1]*v2[1]+ v2[2]*v2[2] ) ;
126 vtkMath *vtkmath = vtkMath::New();
127 double ang = acos ( vtkmath->Dot(v1,v2) );
128 ang = vtkmath->DegreesFromRadians( ang );
129 vtkmath->Cross( v1,v2,v3 );
131 result->RotateWXYZ( ang , v3[0], v3[1], v3[2] );
132 } // if rotation size >=4
134 if (bbGetInputInverse()==false)
136 bbSetOutputOut(result);
138 vtkMatrix4x4 *matrix;
139 matrix=vtkMatrix4x4::New();
140 result->GetInverse(matrix);
141 resultInverse->SetMatrix( matrix );
142 bbSetOutputOut(resultInverse);
146 }// EO namespace bbvtk