]> Creatis software - creaVtk.git/blob - bbtk_creaVtk_PKG/src/bbcreaVtksave_YZ_XZ_volume.cxx
#3389 creaVtk Feature New Normal - new box save_YZ_XZ_volume
[creaVtk.git] / bbtk_creaVtk_PKG / src / bbcreaVtksave_YZ_XZ_volume.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 "bbcreaVtksave_YZ_XZ_volume.h"
5 #include "bbcreaVtkPackage.h"
6
7 #include "vtkMetaImageReader.h"
8 #include "vtkMetaImageWriter.h"
9 #include "vtkImageData.h"
10 #include "creaVtk_MACROS.h"
11
12 namespace bbcreaVtk
13 {
14
15 BBTK_ADD_BLACK_BOX_TO_PACKAGE(creaVtk,save_YZ_XZ_volume)
16 BBTK_BLACK_BOX_IMPLEMENTATION(save_YZ_XZ_volume,bbtk::AtomicBlackBox);
17 //===== 
18 // 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)
19 //===== 
20 void save_YZ_XZ_volume::Process()
21 {
22
23 // THE MAIN PROCESSING METHOD BODY
24 //   Here we simply set the input 'In' value to the output 'Out'
25 //   And print out the output value
26 // INPUT/OUTPUT ACCESSORS ARE OF THE FORM :
27 //    void bbSet{Input|Output}NAME(const TYPE&)
28 //    const TYPE& bbGet{Input|Output}NAME() const 
29 //    Where :
30 //    * NAME is the name of the input/output
31 //      (the one provided in the attribute 'name' of the tag 'input')
32 //    * TYPE is the C++ type of the input/output
33 //      (the one provided in the attribute 'type' of the tag 'input')
34         FILE *ff = fopen(bbGetInputFileName().c_str(),"r");
35         if (ff!=NULL)
36         {
37                 fclose(ff);
38                 vtkMetaImageReader *reader=vtkMetaImageReader::New();
39                 reader->SetFileName(bbGetInputFileName().c_str());
40                 reader->Update();
41                 vtkImageData *image = reader->GetOutput();
42                 int dim[3];
43                 int ext[6];
44                 image->GetExtent(ext);
45                 dim[0]  = ext[1]-ext[0]+1;
46                 dim[1]  = ext[3]-ext[2]+1;
47                 dim[2]  = ext[5]-ext[4]+1;
48                 double spc[3];
49                 image->GetSpacing(spc);
50
51                 vtkImageData *newImageYZ = vtkImageData::New();
52                 newImageYZ->Initialize();
53                 newImageYZ->SetSpacing( spc[1],spc[2],spc[0] );
54                 newImageYZ->SetDimensions(  dim[1],dim[2], dim[0] );
55
56 //EED 2017-01-01 Migration VTK7
57 #if (VTK_MAJOR_VERSION <= 5) 
58                 newImageYZ->SetScalarType( image->GetScalarType() );
59                 newImageYZ->SetNumberOfScalarComponents(1);
60                 newImageYZ->AllocateScalars();
61 #endif
62 #if (VTK_MAJOR_VERSION >= 6) 
63                 newImageYZ->AllocateScalars( image->GetScalarType(),1 );
64 #endif
65                                 
66                 vtkImageData *newImageZX = vtkImageData::New();
67                 newImageZX->Initialize();
68                 newImageZX->SetSpacing( spc[0],spc[2],spc[1] );
69                 newImageZX->SetDimensions(  dim[0],dim[2], dim[1] );
70
71 //EED 2017-01-01 Migration VTK7
72 #if (VTK_MAJOR_VERSION <= 5) 
73                 newImageZX->SetScalarType( image->GetScalarType() );
74                 newImageZX->SetNumberOfScalarComponents(1);
75                 newImageZX->AllocateScalars();
76 #endif
77 #if (VTK_MAJOR_VERSION >= 6) 
78                 newImageZX->AllocateScalars( image->GetScalarType(),1 );
79 #endif
80
81                 DEF_POINTER_IMAGE_VTK_CREA(imageV,imageSS,imageP,imageST,image)         
82                 DEF_POINTER_IMAGE_VTK_CREA(newImageYZ_V,newImageYZ_SS,newImageYZ_P,newImageYZ_ST,newImageYZ)            
83                 DEF_POINTER_IMAGE_VTK_CREA(newImageZX_V,newImageZX_SS,newImageZX_P,newImageZX_ST,newImageZX)            
84                 long int newImageYZ_index;
85                 long int newImageZX_index;
86
87                 int i,j,k;
88 //              double value;
89                 for (k=0;k<dim[2];k++)
90                 {
91                         for (j=0;j<dim[1];j++)
92                         {
93                                 for (i=0;i<dim[0];i++)
94                                 {
95 //                                      value = image->GetScalarComponentAsDouble (i,j,k,0);
96                                         GETVALUE_VTK_CREA(imageV,imageP,imageST)                                        
97                                         imageP=imageP+imageSS;
98
99 //                                      newImageYZ->SetScalarComponentFromDouble( j , dim[2]-k-1 , i , 0 , value );
100                                         newImageYZ_index=j + (dim[2]-k-1)*dim[1]  +  i*dim[1]*dim[2];
101                                         SETVALUE2_VTK_CREA(imageV,newImageYZ_P,newImageYZ_ST,newImageYZ_index)                                                                                                  
102
103 //                                      newImageZX->SetScalarComponentFromDouble( i , dim[2]-k-1 , j , 0 ,value );
104                                         newImageZX_index=i + (dim[2]-k-1)*dim[0]  +  j*dim[0]*dim[2];
105                                         SETVALUE2_VTK_CREA(imageV,newImageZX_P,newImageZX_ST,newImageZX_index)                                                                                                  
106                                 } // for i
107                         } // for j
108                 } // for k
109
110                 //-- Split FileName
111                 std::size_t found               =       bbGetInputFileName().find_last_of("/\\");
112                 std::string path                =       bbGetInputFileName().substr(0,found+1);
113                 std::string filename    =       bbGetInputFileName().substr(found+1);
114 #ifdef _WIN32
115                 path=path+"YZ_ZX\\";
116 #else
117                 path=path+"YZ_ZX/";
118 #endif
119                 std::string command_mkdir = "mkdir "+path;
120                 system(command_mkdir.c_str());
121                 std::string newFileNameYZ = path+filename+"_YZ.mhd";
122                 std::string newFileNameZX = path+filename+"_ZX.mhd";
123
124                 //-- Save _YZ 
125                 vtkMetaImageWriter * writerYZ = vtkMetaImageWriter::New();
126 //EED 2017-01-01 Migration VTK7
127 #if (VTK_MAJOR_VERSION <= 5) 
128                 writerYZ->SetInput(newImageYZ);
129 #endif
130 #if (VTK_MAJOR_VERSION >= 6) 
131                 writerYZ->SetInputData(newImageYZ);
132 #endif
133                 writerYZ->SetFileName(newFileNameYZ.c_str());
134                 writerYZ->SetCompression( bbGetInputCompression() );
135                 writerYZ->Write();
136
137                 //-- Save _ZX 
138                 vtkMetaImageWriter * writerZX = vtkMetaImageWriter::New();
139 //EED 2017-01-01 Migration VTK7
140 #if (VTK_MAJOR_VERSION <= 5) 
141                 writerZX->SetInput(newImageZX);
142 #endif
143 #if (VTK_MAJOR_VERSION >= 6) 
144                 writerZX->SetInputData(newImageZX);
145 #endif
146                 writerZX->SetFileName(newFileNameZX.c_str());
147                 writerZX->SetCompression(  bbGetInputCompression() );
148                 writerZX->Write();
149
150         } else {
151                 printf("EED Save-YZ-XZ-planes::Process %s Not Exist!\n", bbGetInputFileName().c_str() );
152         }
153 }
154 //===== 
155 // 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)
156 //===== 
157 void save_YZ_XZ_volume::bbUserSetDefaultValues()
158 {
159
160 //  SET HERE THE DEFAULT INPUT/OUTPUT VALUES OF YOUR BOX 
161 //    Here we initialize the input 'In' to 0
162    bbSetInputFileName("");
163    bbSetInputCompression( false );
164 }
165 //===== 
166 // 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)
167 //===== 
168 void save_YZ_XZ_volume::bbUserInitializeProcessing()
169 {
170
171 //  THE INITIALIZATION METHOD BODY :
172 //    Here does nothing 
173 //    but this is where you should allocate the internal/output pointers 
174 //    if any 
175
176   
177 }
178 //===== 
179 // 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)
180 //===== 
181 void save_YZ_XZ_volume::bbUserFinalizeProcessing()
182 {
183
184 //  THE FINALIZATION METHOD BODY :
185 //    Here does nothing 
186 //    but this is where you should desallocate the internal/output pointers 
187 //    if any
188   
189 }
190 }
191 // EO namespace bbcreaVtk
192
193