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)
4 #include "bbcreaVtksave_YZ_XZ_volume.h"
5 #include "bbcreaVtkPackage.h"
7 #include "vtkMetaImageReader.h"
8 #include "vtkMetaImageWriter.h"
9 #include "vtkImageData.h"
10 #include "creaVtk_MACROS.h"
15 BBTK_ADD_BLACK_BOX_TO_PACKAGE(creaVtk,save_YZ_XZ_volume)
16 BBTK_BLACK_BOX_IMPLEMENTATION(save_YZ_XZ_volume,bbtk::AtomicBlackBox);
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)
20 void save_YZ_XZ_volume::Process()
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
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");
38 vtkMetaImageReader *reader=vtkMetaImageReader::New();
39 reader->SetFileName(bbGetInputFileName().c_str());
41 vtkImageData *image = reader->GetOutput();
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;
49 image->GetSpacing(spc);
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] );
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();
62 #if (VTK_MAJOR_VERSION >= 6)
63 newImageYZ->AllocateScalars( image->GetScalarType(),1 );
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] );
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();
77 #if (VTK_MAJOR_VERSION >= 6)
78 newImageZX->AllocateScalars( image->GetScalarType(),1 );
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;
89 for (k=0;k<dim[2];k++)
91 for (j=0;j<dim[1];j++)
93 for (i=0;i<dim[0];i++)
95 // value = image->GetScalarComponentAsDouble (i,j,k,0);
96 GETVALUE_VTK_CREA(imageV,imageP,imageST)
97 imageP=imageP+imageSS;
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)
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)
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);
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";
125 vtkMetaImageWriter * writerYZ = vtkMetaImageWriter::New();
126 //EED 2017-01-01 Migration VTK7
127 #if (VTK_MAJOR_VERSION <= 5)
128 writerYZ->SetInput(newImageYZ);
130 #if (VTK_MAJOR_VERSION >= 6)
131 writerYZ->SetInputData(newImageYZ);
133 writerYZ->SetFileName(newFileNameYZ.c_str());
134 writerYZ->SetCompression( bbGetInputCompression() );
138 vtkMetaImageWriter * writerZX = vtkMetaImageWriter::New();
139 //EED 2017-01-01 Migration VTK7
140 #if (VTK_MAJOR_VERSION <= 5)
141 writerZX->SetInput(newImageZX);
143 #if (VTK_MAJOR_VERSION >= 6)
144 writerZX->SetInputData(newImageZX);
146 writerZX->SetFileName(newFileNameZX.c_str());
147 writerZX->SetCompression( bbGetInputCompression() );
151 printf("EED Save-YZ-XZ-planes::Process %s Not Exist!\n", bbGetInputFileName().c_str() );
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)
157 void save_YZ_XZ_volume::bbUserSetDefaultValues()
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 );
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)
168 void save_YZ_XZ_volume::bbUserInitializeProcessing()
171 // THE INITIALIZATION METHOD BODY :
173 // but this is where you should allocate the internal/output pointers
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)
181 void save_YZ_XZ_volume::bbUserFinalizeProcessing()
184 // THE FINALIZATION METHOD BODY :
186 // but this is where you should desallocate the internal/output pointers
191 // EO namespace bbcreaVtk