]> Creatis software - creaVtk.git/blob - bbtk_creaVtk_PKG/src/bbcreaVtkTurnImage.cxx
Clean Comments
[creaVtk.git] / bbtk_creaVtk_PKG / src / bbcreaVtkTurnImage.cxx
1 //===== 
2 // Before editing this file, make sure it's a file of your own (i.e.: it wasn't generated from xml description; if so : your modifications will be lost)
3 //===== 
4 #include "bbcreaVtkTurnImage.h"
5 #include "bbcreaVtkPackage.h"
6
7 #include "creaVtk_MACROS.h"
8
9 namespace bbcreaVtk
10 {
11
12 BBTK_ADD_BLACK_BOX_TO_PACKAGE(creaVtk,TurnImage)
13 BBTK_BLACK_BOX_IMPLEMENTATION(TurnImage,bbtk::AtomicBlackBox);
14 //===== 
15 // Before editing this file, make sure it's a file of your own (i.e.: it wasn't generated from xml description; if so : your modifications will be lost)
16 //===== 
17 void TurnImage::Process()
18 {
19
20 // THE MAIN PROCESSING METHOD BODY
21 //   Here we simply set the input 'In' value to the output 'Out'
22 //   And print out the output value
23 // INPUT/OUTPUT ACCESSORS ARE OF THE FORM :
24 //    void bbSet{Input|Output}NAME(const TYPE&)
25 //    const TYPE& bbGet{Input|Output}NAME() const 
26 //    Where :
27 //    * NAME is the name of the input/output
28 //      (the one provided in the attribute 'name' of the tag 'input')
29 //    * TYPE is the C++ type of the input/output
30 //      (the one provided in the attribute 'type' of the tag 'input')
31 //    bbSetOutputOut( bbGetInputIn() );
32 //    std::cout << "Output value = " <<bbGetOutputOut() << std::endl;
33
34   
35         if (bbGetInputIn()!=NULL)
36         {
37                 int dim[3];
38                 int ext[6];
39                 bbGetInputIn()->GetExtent(ext);
40                 dim[0]  = ext[1]-ext[0]+1;
41                 dim[1]  = ext[3]-ext[2]+1;
42                 dim[2]  = ext[5]-ext[4]+1;
43                 double spc[3];
44                 bbGetInputIn()->GetSpacing(spc);
45
46                 vtkImageData *newImage = vtkImageData::New();
47                 newImage->Initialize();
48                 if (bbGetInputDir()==1)
49                 {
50                         newImage->SetSpacing( spc[1],spc[2],spc[0] );
51                         newImage->SetDimensions(  dim[1],dim[2], dim[0] );
52                 } else if (bbGetInputDir()==2)
53                 {
54                         newImage->SetSpacing( spc[0],spc[2],spc[1] );
55                         newImage->SetDimensions(  dim[0],dim[2], dim[1] );
56                 } else {
57                         newImage->SetSpacing( spc[0],spc[1],spc[2] );
58                         newImage->SetDimensions(  dim[0],dim[1], dim[2] );
59                 }// if Dir
60
61 //EED 2017-01-01 Migration VTK7
62 #if (VTK_MAJOR_VERSION <= 5) 
63                 newImage->SetScalarType( bbGetInputIn()->GetScalarType() );
64                 newImage->SetNumberOfScalarComponents(1);
65                 newImage->AllocateScalars();
66 #endif
67 #if (VTK_MAJOR_VERSION >= 6) 
68                 newImage->AllocateScalars( bbGetInputIn()->GetScalarType(),1 );
69 #endif
70
71                 DEF_POINTER_IMAGE_VTK_CREA(vIn,ssIn,pIn,stIn,bbGetInputIn())                                    
72                 DEF_POINTER_IMAGE_VTK_CREA(vNI,ssNI,pNI,stNI,newImage)                                          
73
74                 long int index=0;
75                 int i,j,k;
76                 double value;
77                 for (k=0;k<dim[2];k++)
78                 {
79                         for (j=0;j<dim[1];j++)
80                         {
81                                 for (i=0;i<dim[0];i++)
82                                 {
83                                         GETVALUE2_VTK_CREA(vIn,pIn,stIn,index) 
84 //                                      value = bbGetInputIn()->GetScalarComponentAsDouble (i,j,k,0);
85                                         if (bbGetInputDir()==1)
86                                         {
87                                                 SETVALUE2_VTK_CREA(vIn,pNI,stNI, j + (dim[2]-k-1)*dim[1] + i*dim[1]*dim[2] )            
88 //                                              newImage->SetScalarComponentFromDouble(j,dim[2]-k-1,i,0,value);
89                                         } else if (bbGetInputDir()==2)
90                                         {
91                                                 SETVALUE2_VTK_CREA(vIn,pNI,stNI, i + (dim[2]-k-1)*dim[0] + j*dim[0]*dim[2] )            
92 //                                              newImage->SetScalarComponentFromDouble(i,dim[2]-k-1,j,0,value);
93                                         } else {
94                                                 SETVALUE2_VTK_CREA(vIn,pNI,stNI,index)          
95 //                                              newImage->SetScalarComponentFromDouble(i,j,k,0,value);
96                                         }// if Dir
97                                         index++;
98                                 } // for i
99                         } // for j
100                 } // for k
101                 bbSetOutputOut(newImage);
102         } else {
103                 bbSetOutputOut(NULL);
104         }// if In!=NULL
105 }
106 //===== 
107 // Before editing this file, make sure it's a file of your own (i.e.: it wasn't generated from xml description; if so : your modifications will be lost)
108 //===== 
109 void TurnImage::bbUserSetDefaultValues()
110 {
111
112 //  SET HERE THE DEFAULT INPUT/OUTPUT VALUES OF YOUR BOX 
113 //    Here we initialize the input 'In' to 0
114    bbSetInputIn(NULL);
115    bbSetInputDir(0);
116   
117 }
118 //===== 
119 // Before editing this file, make sure it's a file of your own (i.e.: it wasn't generated from xml description; if so : your modifications will be lost)
120 //===== 
121 void TurnImage::bbUserInitializeProcessing()
122 {
123
124 //  THE INITIALIZATION METHOD BODY :
125 //    Here does nothing 
126 //    but this is where you should allocate the internal/output pointers 
127 //    if any 
128
129   
130 }
131 //===== 
132 // Before editing this file, make sure it's a file of your own (i.e.: it wasn't generated from xml description; if so : your modifications will be lost)
133 //===== 
134 void TurnImage::bbUserFinalizeProcessing()
135 {
136
137 //  THE FINALIZATION METHOD BODY :
138 //    Here does nothing 
139 //    but this is where you should desallocate the internal/output pointers 
140 //    if any
141   
142 }
143 }
144 // EO namespace bbcreaVtk
145
146