]> Creatis software - bbtk.git/blob - packages/gdcmvtk/src/bbgdcmvtkGetXCoherentInfoGdcmReader.cxx
defaultBalues InitializeProcessing FinalizeProcessing
[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    
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    for(i=0; i< 6; i++)
33       v_iop.push_back(iop[i]);
34    bbSetOutputIOP(v_iop );
35  
36    std::vector<double> v_ipp;
37    float ipp[3];
38    f->GetImagePositionPatient(ipp);
39    for(i=0; i< 3; i++)
40       v_ipp.push_back(ipp[i]);
41    bbSetOutputIPP(v_ipp );
42
43
44 // Add all the files to the SerieHelper
45    sh = GDCM_NAME_SPACE::SerieHelper::New();
46    std::vector<std::string> gii = bbGetInputIn();
47    for(std::vector<std::string>::iterator it = gii.begin();
48                                           it != gii.end();
49                                         ++it)
50    {
51       sh->AddFileName(*it);
52    }
53
54    GDCM_NAME_SPACE::FileList::const_iterator it;
55    GDCM_NAME_SPACE::FileList *l;
56
57    // Should only contain one!
58    l = sh->GetFirstSingleSerieUIDFileSet();
59
60    int nbFiles;
61    double zspacing = 0.;
62    nbFiles = l->size() ;
63    sh->OrderFileList(l);
64    zspacing = sh->GetZSpacing();
65
66         std::vector<double> v_pixelspacing;
67         v_pixelspacing.push_back( f->GetXSpacing() );
68         v_pixelspacing.push_back( f->GetYSpacing() );
69         v_pixelspacing.push_back( zspacing );
70 //      if (f->GetZSize() != 1) {
71 //              v_pixelspacing.push_back(f->GetZSpacing());
72 //      }
73         bbSetOutputPixelSpacing(v_pixelspacing);
74         
75         
76
77         if (reader!=NULL)
78         { 
79                 reader->Delete();
80                 reader=NULL;
81         }
82         reader = vtkGdcmReader::New();
83    //reader->SetFileName( bbGetInputIn().c_str() );
84    reader->SetCoherentFileList(l);
85    reader->Update();
86    reader->GetOutput();
87
88    bbSetOutputOut( reader->GetOutput() );
89 }
90
91 void GetXCoherentInfoGdcmReader::bbUserSetDefaultValues()
92 {
93     std::vector<std::string> init;
94     init.push_back("");
95     bbSetInputIn(init);  
96         reader=NULL;
97 }
98
99 void GetXCoherentInfoGdcmReader::bbUserInitializeProcessing()
100 {
101         
102 }
103
104 void GetXCoherentInfoGdcmReader::bbUserFinalizeProcessing()
105 {
106    if(reader)
107       reader->Delete();
108    if(f)
109       f->Delete();
110    if(sh)
111       sh->Delete();      
112 }
113
114 }
115 // EO namespace bbgdcmvtk
116
117