]> Creatis software - bbtk.git/blob - packages/vtk/src/bbvtkTransform.cxx
7923cb586c8c7733e430ebdf0cc884ea89051e74
[bbtk.git] / packages / vtk / src / bbvtkTransform.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  # Previous Authors : Laurent Guigues, Jean-Pierre Roux
8  # CreaTools website : www.creatis.insa-lyon.fr/site/fr/creatools_accueil
9  #
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.
16  #
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
21  #  liability.
22  #
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  # ------------------------------------------------------------------------ */
26
27
28 #include "bbvtkTransform.h"
29 #include "bbvtkPackage.h"
30 namespace bbvtk
31 {
32   BBTK_ADD_BLACK_BOX_TO_PACKAGE(vtk,Transform);
33   BBTK_BLACK_BOX_IMPLEMENTATION(Transform,bbtk::AtomicBlackBox);
34
35         // --------------------------------------------------------------       
36
37         void Transform::bbUserSetDefaultValues()
38         {
39                 bbSetInputIn(NULL);
40
41                 vecScale.push_back(1);  // scale x
42                 vecScale.push_back(1);  // scale y
43                 vecScale.push_back(1);  // scale z
44                 bbSetInputScale(vecScale);
45
46                 vecRotateWXYZ.push_back(0);  //angle 
47                 vecRotateWXYZ.push_back(1);  //vx
48                 vecRotateWXYZ.push_back(0);  //vy
49                 vecRotateWXYZ.push_back(0);  //vz
50                 bbSetInputRotateWXYZ(vecRotateWXYZ);
51
52                 vecTranslate.push_back(0);  //tx
53                 vecTranslate.push_back(0);  //ty
54                 vecTranslate.push_back(0);  //tz
55                 bbSetInputTranslate(vecTranslate);
56
57                 vecSpacing.push_back(1);  //spacing x
58                 vecSpacing.push_back(1);  //spacing y
59                 vecSpacing.push_back(1);  //spacing z
60                 bbSetInputSpacing(vecSpacing);
61
62                 result = NULL;  
63         }
64
65         // --------------------------------------------------------------       
66         void Transform::bbUserInitializeProcessing()
67         {
68                 bbUserFinalizeProcessing();
69                 result = vtkTransform::New();
70         }
71
72         // --------------------------------------------------------------       
73         void Transform::bbUserFinalizeProcessing()
74         {
75                 if (result!=NULL)
76                 {
77                         result->Delete();
78                         result=NULL;
79                 }
80         }
81
82         // --------------------------------------------------------------       
83   void Transform::Process()
84   {
85           bbUserInitializeProcessing();
86           if (bbGetInputIn()!=NULL)
87       {
88                   result->Concatenate( bbGetInputIn()->GetMatrix() );
89       }
90
91           if (bbGetInputScale().size()>=3)
92       {
93                   result->Scale(bbGetInputScale()[0], bbGetInputScale()[1], bbGetInputScale()[2]);
94       }
95  
96           if ((bbGetInputTranslate().size()>=3) && (bbGetInputSpacing().size()>=3))
97       {
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       }
103
104           if (bbGetInputRotateWXYZ().size()>=4)
105       {
106                   result->RotateWXYZ(bbGetInputRotateWXYZ()[0],bbGetInputRotateWXYZ()[1], bbGetInputRotateWXYZ()[2], bbGetInputRotateWXYZ()[3]);
107       }
108
109           result->Update();
110  
111           bbSetOutputOut(result);
112   }
113 }
114 // EO namespace bbvtk