]> Creatis software - bbtk.git/blob - packages/gdcmvtk/src/bbgdcmvtkGetXCoherentInfoGdcmReader.cxx
Try to get more accurate info from SerieHelper
[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    std::vector<double> v_pixelspacing;
44    v_pixelspacing.push_back(f->GetXSpacing());
45    v_pixelspacing.push_back(f->GetYSpacing());
46    if (f->GetZSize() != 1) {
47       v_pixelspacing.push_back(f->GetZSpacing());
48    }
49    bbSetOutputPixelSpacing(v_pixelspacing);
50
51 // Add all the files to the SerieHelper
52    sh = GDCM_NAME_SPACE::SerieHelper::New();
53    std::vector<std::string> gii = bbGetInputIn();
54    for(std::vector<std::string>::iterator it = gii.begin();
55                                           it != gii.end();
56                                         ++it)
57    {
58       sh->AddFileName(*it);
59    }
60
61    GDCM_NAME_SPACE::FileList::const_iterator it;
62    GDCM_NAME_SPACE::FileList *l;
63
64    // ==================== Just to see ==============================
65
66    std::cout << std::endl << " ---------------------------------------- Recap"
67              << std::endl;
68    l = sh->GetFirstSingleSerieUIDFileSet();
69    while (l)
70    {
71       it = l->begin();
72       std::cout << "SerieUID [" <<  (*it)->GetEntryString(0x0020,0x000e) <<"]   Serie Description ["
73                 << (*it)->GetEntryString(0x0008,0x103e) << "] "
74                 << " : " << l->size() << " files" << std::endl;
75       l = sh->GetNextSingleSerieUIDFileSet();
76    }
77     std::cout << " ----------------------------------------End Recap"
78              << std::endl << std::endl;
79
80    if(l->size() > 1)
81      std::cout << " --------------------------- More than ONE Serie UID ?!?"
82                << std::endl << std::endl;
83    // ============================================================
84
85    // Should only contain one!
86    l = sh->GetFirstSingleSerieUIDFileSet();
87
88    int nbFiles;
89    double zspacing = 0.;
90    nbFiles = l->size() ;
91    sh->OrderFileList(l);
92    zspacing = sh->GetZSpacing();
93
94    std::cout << "GetZSpacing() of sorted SingleSerieUIDFileSet "
95              << "from GDCM_NAME_SPACE::SerieHelper: " << zspacing << std::endl;
96    std::cout << " ('-1' means all the files have the same position)" << std::endl;
97
98    bbSetOutputInterSlice(zspacing);
99
100    
101    reader = vtkGdcmReader::New();
102    //reader->SetFileName( bbGetInputIn().c_str() );
103    reader->SetCoherentFileList(l);
104    reader->Update();
105    reader->GetOutput();
106
107    vtkIndent indent ;
108    reader->GetOutput()->PrintSelf(std::cout, indent);
109    bbSetOutputOut( reader->GetOutput() );
110 }
111
112 void GetXCoherentInfoGdcmReader::bbUserConstructor()
113 {
114     std::vector<std::string> init;
115     init.push_back("");
116     bbSetInputIn(init);  
117 }
118
119 void GetXCoherentInfoGdcmReader::bbUserCopyConstructor(bbtk::BlackBox::Pointer)
120 {
121   
122 }
123
124 void GetXCoherentInfoGdcmReader::bbUserDestructor()
125 {
126    if(reader)
127       reader->Delete();
128    if(f)
129       f->Delete();
130    if(sh)
131       sh->Delete();      
132 }
133
134 }
135 // EO namespace bbgdcmvtk
136
137