]> Creatis software - creaVtk.git/blob - bbtk_creaVtk_PKG/src/bbcreaVtkNIFTIImageReader.cxx
#3349 creaVtkFeature New Normal - box NIFFImageReader
[creaVtk.git] / bbtk_creaVtk_PKG / src / bbcreaVtkNIFTIImageReader.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 "bbcreaVtkNIFTIImageReader.h"
5 #include "bbcreaVtkPackage.h"
6
7 #include <vtkNIFTIImageReader.h>
8 #include <vtkStringArray.h>
9
10 namespace bbcreaVtk
11 {
12
13 BBTK_ADD_BLACK_BOX_TO_PACKAGE(creaVtk,NIFTIImageReader)
14 BBTK_BLACK_BOX_IMPLEMENTATION(NIFTIImageReader,bbtk::AtomicBlackBox);
15 //===== 
16 // 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)
17 //===== 
18 void NIFTIImageReader::Process()
19 {
20
21 // THE MAIN PROCESSING METHOD BODY
22 //   Here we simply set the input 'In' value to the output 'Out'
23 //   And print out the output value
24 // INPUT/OUTPUT ACCESSORS ARE OF THE FORM :
25 //    void bbSet{Input|Output}NAME(const TYPE&)
26 //    const TYPE& bbGet{Input|Output}NAME() const 
27 //    Where :
28 //    * NAME is the name of the input/output
29 //      (the one provided in the attribute 'name' of the tag 'input')
30 //    * TYPE is the C++ type of the input/output
31 //      (the one provided in the attribute 'type' of the tag 'input')
32 //    bbSetOutputOut( bbGetInputIn() );
33 //    std::cout << "Output value = " <<bbGetOutputOut() << std::endl;
34   
35
36         std::vector<vtkImageData*> lstImages;
37
38         if (bbGetInputType()==0) 
39         {
40                 vtkNIFTIImageReader* reader=vtkNIFTIImageReader::New();
41                 if ( bbGetInputFileNames().size()==1)
42                 {
43                         reader->SetFileName( bbGetInputFileNames()[0].c_str() );
44                         reader->Update();
45                 } else          {
46                         vtkStringArray *lstFileNames=vtkStringArray::New();
47                         int i,size=bbGetInputFileNames().size();
48                         for (i=0;i<size;i++)
49                         {
50 printf("EED Warnning, somethin is not working ????   NIFTIImageReader::Process()    %s\n ", bbGetInputFileNames()[i].c_str()  );
51                                 lstFileNames->InsertNextValue( bbGetInputFileNames()[i].c_str() );
52                         } // for i
53                         reader->SetFileNames( lstFileNames );
54                         reader->Update();
55                 } // FileNames
56                 lstImages.push_back( reader->GetOutput() );
57         } // Type 0
58
59         if (bbGetInputType()==1) 
60         {
61                 int i,size=bbGetInputFileNames().size();
62                 for (i=0;i<size;i++)
63                 {
64                         vtkNIFTIImageReader* reader=vtkNIFTIImageReader::New();
65                         reader->SetFileName( bbGetInputFileNames()[i].c_str() );
66                         reader->Update();
67                         lstImages.push_back( reader->GetOutput() );
68                 } // for i
69         } // Type 1
70
71         
72         if (lstImages.size()>=1) { bbSetOutputOut( lstImages[0] ); } else {bbSetOutputOut( NULL ); }
73         bbSetOutputOutVector( lstImages );
74 }
75 //===== 
76 // 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)
77 //===== 
78 void NIFTIImageReader::bbUserSetDefaultValues()
79 {
80
81 //  SET HERE THE DEFAULT INPUT/OUTPUT VALUES OF YOUR BOX 
82 //    Here we initialize the input 'In' to 0
83    bbSetInputType(0);
84   
85 }
86 //===== 
87 // 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)
88 //===== 
89 void NIFTIImageReader::bbUserInitializeProcessing()
90 {
91
92 //  THE INITIALIZATION METHOD BODY :
93 //    Here does nothing 
94 //    but this is where you should allocate the internal/output pointers 
95 //    if any 
96
97   
98 }
99 //===== 
100 // 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)
101 //===== 
102 void NIFTIImageReader::bbUserFinalizeProcessing()
103 {
104
105 //  THE FINALIZATION METHOD BODY :
106 //    Here does nothing 
107 //    but this is where you should desallocate the internal/output pointers 
108 //    if any
109   
110 }
111 }
112 // EO namespace bbcreaVtk
113
114