]> Creatis software - creaVtk.git/blob - bbtk_creaVtk_PKG/src/bbcreaVtkNIFTIImageReader.cxx
N#3508 IFTI read multiple images
[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     std::vector<vtkImageData*> lstImages;
36
37     if ( bbGetInputFileNames().size()>0 )
38     {
39         if (bbGetInputType()==0)
40         {
41             vtkNIFTIImageReader* reader=vtkNIFTIImageReader::New();
42             if ( bbGetInputFileNames().size()==1)
43             {
44                 reader->SetFileName( bbGetInputFileNames()[0].c_str() );
45                 reader->Update();
46             } else         {
47                 vtkStringArray *lstFileNames=vtkStringArray::New();
48                 int i,size=bbGetInputFileNames().size();
49                 for (i=0;i<size;i++)
50                 {
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     } // if
72         
73         if (lstImages.size()>=1) { bbSetOutputOut( lstImages[0] ); } else {bbSetOutputOut( NULL ); }
74         bbSetOutputOutVector( lstImages );
75     
76 }
77 //===== 
78 // 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)
79 //===== 
80 void NIFTIImageReader::bbUserSetDefaultValues()
81 {
82
83 //  SET HERE THE DEFAULT INPUT/OUTPUT VALUES OF YOUR BOX 
84 //    Here we initialize the input 'In' to 0
85    bbSetInputType(0);
86   
87 }
88 //===== 
89 // 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)
90 //===== 
91 void NIFTIImageReader::bbUserInitializeProcessing()
92 {
93
94 //  THE INITIALIZATION METHOD BODY :
95 //    Here does nothing 
96 //    but this is where you should allocate the internal/output pointers 
97 //    if any 
98
99   
100 }
101 //===== 
102 // 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)
103 //===== 
104 void NIFTIImageReader::bbUserFinalizeProcessing()
105 {
106
107 //  THE FINALIZATION METHOD BODY :
108 //    Here does nothing 
109 //    but this is where you should desallocate the internal/output pointers 
110 //    if any
111   
112 }
113 }
114 // EO namespace bbcreaVtk
115
116