]> Creatis software - creaVtk.git/blob - bbtk_creaVtk_PKG/src/bbcreaVtkTurnImage.cxx
35870de60313c0daaff32fbdc6e823db6573026b
[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 printf("EED TurnImage::Proces Start\n");
36
37   
38         if (bbGetInputIn()!=NULL)
39         {
40                 int dim[3];
41                 int ext[6];
42                 bbGetInputIn()->GetExtent(ext);
43                 dim[0]  = ext[1]-ext[0]+1;
44                 dim[1]  = ext[3]-ext[2]+1;
45                 dim[2]  = ext[5]-ext[4]+1;
46                 double spc[3];
47                 bbGetInputIn()->GetSpacing(spc);
48
49                 vtkImageData *newImage = vtkImageData::New();
50                 newImage->Initialize();
51                 if (bbGetInputDir()==1)
52                 {
53                         newImage->SetSpacing( spc[1],spc[2],spc[0] );
54                         newImage->SetDimensions(  dim[1],dim[2], dim[0] );
55                 } else if (bbGetInputDir()==2)
56                 {
57                         newImage->SetSpacing( spc[0],spc[2],spc[1] );
58                         newImage->SetDimensions(  dim[0],dim[2], dim[1] );
59                 } else {
60                         newImage->SetSpacing( spc[0],spc[1],spc[2] );
61                         newImage->SetDimensions(  dim[0],dim[1], dim[2] );
62                 }// if Dir
63
64 //EED 2017-01-01 Migration VTK7
65 #if (VTK_MAJOR_VERSION <= 5) 
66                 newImage->SetScalarType( bbGetInputIn()->GetScalarType() );
67                 newImage->SetNumberOfScalarComponents(1);
68                 newImage->AllocateScalars();
69 #endif
70 #if (VTK_MAJOR_VERSION >= 6) 
71                 newImage->AllocateScalars( bbGetInputIn()->GetScalarType(),1 );
72 #endif
73
74                 DEF_POINTER_IMAGE_VTK_CREA(vIn,ssIn,pIn,stIn,bbGetInputIn())                                    
75                 DEF_POINTER_IMAGE_VTK_CREA(vNI,ssNI,pNI,stNI,newImage)                                          
76
77                 long int index=0;
78                 int i,j,k;
79                 double value;
80                 for (k=0;k<dim[2];k++)
81                 {
82                         for (j=0;j<dim[1];j++)
83                         {
84                                 for (i=0;i<dim[0];i++)
85                                 {
86                                         GETVALUE2_VTK_CREA(vIn,pIn,stIn,index) 
87 //                                      value = bbGetInputIn()->GetScalarComponentAsDouble (i,j,k,0);
88                                         if (bbGetInputDir()==1)
89                                         {
90                                                 SETVALUE2_VTK_CREA(vIn,pNI,stNI, j + (dim[2]-k-1)*dim[1] + i*dim[1]*dim[2] )            
91 //                                              newImage->SetScalarComponentFromDouble(j,dim[2]-k-1,i,0,value);
92                                         } else if (bbGetInputDir()==2)
93                                         {
94                                                 SETVALUE2_VTK_CREA(vIn,pNI,stNI, i + (dim[2]-k-1)*dim[0] + j*dim[0]*dim[2] )            
95 //                                              newImage->SetScalarComponentFromDouble(i,dim[2]-k-1,j,0,value);
96                                         } else {
97                                                 SETVALUE2_VTK_CREA(vIn,pNI,stNI,index)          
98 //                                              newImage->SetScalarComponentFromDouble(i,j,k,0,value);
99                                         }// if Dir
100                                         index++;
101                                 } // for i
102                         } // for j
103                 } // for k
104                 bbSetOutputOut(newImage);
105         } else {
106                 bbSetOutputOut(NULL);
107         }// if In!=NULL
108
109 printf("EED TurnImage::Proces End\n");
110
111 }
112 //===== 
113 // 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)
114 //===== 
115 void TurnImage::bbUserSetDefaultValues()
116 {
117
118 //  SET HERE THE DEFAULT INPUT/OUTPUT VALUES OF YOUR BOX 
119 //    Here we initialize the input 'In' to 0
120    bbSetInputIn(NULL);
121    bbSetInputDir(0);
122   
123 }
124 //===== 
125 // 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)
126 //===== 
127 void TurnImage::bbUserInitializeProcessing()
128 {
129
130 //  THE INITIALIZATION METHOD BODY :
131 //    Here does nothing 
132 //    but this is where you should allocate the internal/output pointers 
133 //    if any 
134
135   
136 }
137 //===== 
138 // 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)
139 //===== 
140 void TurnImage::bbUserFinalizeProcessing()
141 {
142
143 //  THE FINALIZATION METHOD BODY :
144 //    Here does nothing 
145 //    but this is where you should desallocate the internal/output pointers 
146 //    if any
147   
148 }
149 }
150 // EO namespace bbcreaVtk
151
152