]> Creatis software - bbtk.git/blob - packages/vtk/src/bbvtkTransform.cxx
#2808, #2807, #2806, #2805, #2804 BBTK Feature New Normal Add new functionality MathO...
[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                 result->Update();
71         }
72
73         // --------------------------------------------------------------       
74         void Transform::bbUserFinalizeProcessing()
75         {
76                 if (result!=NULL)
77                 {
78                         result->Delete();
79                         result=NULL;
80                 }
81         }
82
83         // --------------------------------------------------------------       
84   void Transform::Process()
85   {
86           bbUserInitializeProcessing();
87           if (bbGetInputIn()!=NULL)
88       {
89                   result->Concatenate( bbGetInputIn()->GetMatrix() );
90       }
91
92  
93           if ((bbGetInputTranslate().size()>=3) && (bbGetInputSpacing().size()>=3))
94       {
95                   double tx = bbGetInputTranslate()[0] * bbGetInputSpacing()[0];
96                   double ty = bbGetInputTranslate()[1] * bbGetInputSpacing()[1];
97                   double tz = bbGetInputTranslate()[2] * bbGetInputSpacing()[2];
98 printf("Transform::Process() %f %f %f\n",tx, ty,tz);
99                   result->Translate(tx,ty,tz);
100       }
101
102           if (bbGetInputScale().size()>=3)
103       {
104                   result->Scale(bbGetInputScale()[0], bbGetInputScale()[1], bbGetInputScale()[2]);
105       }
106
107           if (bbGetInputRotateWXYZ().size()>=4)
108       {
109                   result->RotateWXYZ(bbGetInputRotateWXYZ()[0],bbGetInputRotateWXYZ()[1], bbGetInputRotateWXYZ()[2], bbGetInputRotateWXYZ()[3]);
110       }
111
112          
113  
114           bbSetOutputOut(result);
115   }
116 }
117 // EO namespace bbvtk