]> Creatis software - creaVtk.git/blob - bbtk_creaVtk_PKG/src/bbcreaVtkWriteLstImages.cxx
#3457 creaVtk Feature New Normal - new box VtkWriteLstImages
[creaVtk.git] / bbtk_creaVtk_PKG / src / bbcreaVtkWriteLstImages.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 "bbcreaVtkWriteLstImages.h"
5 #include "bbcreaVtkPackage.h"
6
7 #include "vtkMetaImageWriter.h"
8 #include <vtkNIFTIImageWriter.h>
9 namespace bbcreaVtk
10 {
11
12 BBTK_ADD_BLACK_BOX_TO_PACKAGE(creaVtk,WriteLstImages)
13 BBTK_BLACK_BOX_IMPLEMENTATION(WriteLstImages,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 WriteLstImages::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 WriteLstImages::Process Start\n");
36         vtkImageData    *inImg;
37         std::string     txtNum;
38         int i,size=bbGetInputLstImages().size();
39         for (i=0;i<size;i++)
40         {
41 printf("  EED WriteLstImages::Process i=%d\n",i );
42
43                 txtNum=std::to_string(i);
44                 while (txtNum.length()<=5) 
45                 {
46                         txtNum="0"+txtNum;
47                 } // while
48
49                 inImg=bbGetInputLstImages()[i];
50                 if (bbGetInputType()==0)  // mhd
51                 {
52                         vtkMetaImageWriter* w = vtkMetaImageWriter::New();
53                         w->SetInputData( inImg );
54                 w->SetCompression( bbGetInputCompression() );  
55                         w->SetFileDimensionality(inImg->GetDataDimension()); // NTU
56                         std::string filename = bbGetInputOutputDir()+"/"+bbGetInputFileName()+"-"+txtNum+".mhd";
57                     w->SetFileName(filename.c_str());  
58                     w->Write();
59                         w->Delete();
60                 } // Type
61
62                 if (bbGetInputType()==1)  // NIFTI 
63                 {
64                         vtkNIFTIImageWriter* w = vtkNIFTIImageWriter::New();
65                         w->SetInputData( inImg );
66                         std::string filename = bbGetInputOutputDir()+"/"+bbGetInputFileName()+"-"+txtNum+".nii";
67                     w->SetFileName(filename.c_str());  
68                     w->Write();
69                         w->Delete();
70                 } // Type
71
72
73
74         } // for i  
75 printf("EED WriteLstImages::Process END\n");
76
77 }
78 //===== 
79 // 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)
80 //===== 
81 void WriteLstImages::bbUserSetDefaultValues()
82 {
83
84 //  SET HERE THE DEFAULT INPUT/OUTPUT VALUES OF YOUR BOX 
85 //    Here we initialize the input 'In' to 0
86         bbSetInputType(0);
87         bbSetInputCompression(false);
88         bbSetInputFileName("void");
89         bbSetInputOutputDir(".");
90 }
91 //===== 
92 // 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)
93 //===== 
94 void WriteLstImages::bbUserInitializeProcessing()
95 {
96
97 //  THE INITIALIZATION METHOD BODY :
98 //    Here does nothing 
99 //    but this is where you should allocate the internal/output pointers 
100 //    if any 
101
102   
103 }
104 //===== 
105 // 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)
106 //===== 
107 void WriteLstImages::bbUserFinalizeProcessing()
108 {
109
110 //  THE FINALIZATION METHOD BODY :
111 //    Here does nothing 
112 //    but this is where you should desallocate the internal/output pointers 
113 //    if any
114   
115 }
116 }
117 // EO namespace bbcreaVtk
118
119