]> Creatis software - bbtk.git/blob - packages/gdcmvtk/src/bbgdcmvtkGetXCoherentInfoGdcmReader.cxx
re-indent
[bbtk.git] / packages / gdcmvtk / src / bbgdcmvtkGetXCoherentInfoGdcmReader.cxx
1 #include "bbgdcmvtkGetXCoherentInfoGdcmReader.h"
2 #include "bbgdcmvtkPackage.h"
3
4 #include "gdcmFile.h"
5 #include "gdcmFileHelper.h"
6 #include "vtkImageData.h"
7 #include "vtkGdcmReader.h"
8 #include <vtkIndent.h>
9
10 namespace bbgdcmvtk
11 {
12
13 BBTK_ADD_BLACK_BOX_TO_PACKAGE(gdcmvtk,GetXCoherentInfoGdcmReader)
14 BBTK_BLACK_BOX_IMPLEMENTATION(GetXCoherentInfoGdcmReader,bbtk::AtomicBlackBox);
15 void GetXCoherentInfoGdcmReader::Process()
16 {
17  // Read the *first* image file (a SET of file names is given as input) 
18    f = GDCM_NAME_SPACE::File::New();
19    f->SetFileName( bbGetInputIn()[0] );
20    bool res = f->Load();  
21    if ( !res )
22    {
23       f->Delete();
24       bbSetOutputOut(0);
25       return;
26    }
27  // Get info from the first image file
28    int i;
29    std::vector<double> v_iop;
30    float iop[6];
31    f->GetImageOrientationPatient(iop);
32    
33    for(i=0; i< 6; i++)
34       v_iop.push_back(iop[i]);
35    bbSetOutputIOP(v_iop );
36  
37    std::vector<double> v_ipp;
38    float ipp[3];
39    f->GetImagePositionPatient(ipp);
40    
41    for(i=0; i< 3; i++)
42       v_ipp.push_back(ipp[i]);
43    bbSetOutputIPP(v_ipp );
44
45 // Add *all the files* to the SerieHelper
46    sh = GDCM_NAME_SPACE::SerieHelper::New();
47    std::vector<std::string> gii = bbGetInputIn();
48    
49    for(std::vector<std::string>::iterator it = gii.begin();
50                                           it != gii.end();
51                                         ++it)
52    {
53       sh->AddFileName(*it);
54    }
55
56    GDCM_NAME_SPACE::FileList::const_iterator it;
57    GDCM_NAME_SPACE::FileList *l;
58
59    // Should only contain one!
60    l = sh->GetFirstSingleSerieUIDFileSet();
61
62    int nbFiles;
63    double zspacing = 0.;
64    nbFiles = l->size() ;
65    sh->OrderFileList(l); // this one should compute the *actual* Z Spacing!
66    zspacing = sh->GetZSpacing();
67    std::vector<double> v_pixelspacing;
68    v_pixelspacing.push_back( f->GetXSpacing() );
69    v_pixelspacing.push_back( f->GetYSpacing() );
70    v_pixelspacing.push_back( zspacing );
71 //   if (f->GetZSize() != 1) {
72 //      v_pixelspacing.push_back(f->GetZSpacing());
73 //   }
74    bbSetOutputPixelSpacing(v_pixelspacing);
75
76    if (reader!=NULL)
77    { 
78       reader->Delete();
79       reader=NULL;
80    }
81    reader = vtkGdcmReader::New();
82    //reader->SetFileName( bbGetInputIn().c_str() );
83    reader->SetCoherentFileList(l);
84    reader->Update();
85    reader->GetOutput();
86
87    bbSetOutputOut( reader->GetOutput() );
88 }
89
90 void GetXCoherentInfoGdcmReader::bbUserSetDefaultValues()
91 {
92    std::vector<std::string> init;
93    init.push_back("");
94    bbSetInputIn(init);  
95    reader=NULL;
96 }
97
98 void GetXCoherentInfoGdcmReader::bbUserInitializeProcessing()
99 {
100         
101 }
102
103 void GetXCoherentInfoGdcmReader::bbUserFinalizeProcessing()
104 {
105    if(reader)
106       reader->Delete();
107    if(f)
108       f->Delete();
109    if(sh)
110       sh->Delete();      
111 }
112
113 }
114 // EO namespace bbgdcmvtk