1 #include "bbgdcmvtkGetXCoherentInfoGdcmReader.h"
2 #include "bbgdcmvtkPackage.h"
5 #include "vtkImageData.h"
8 #include "gdcmFileHelper.h"
11 #include <gdcmReader.h>
12 #include <gdcmImageHelper.h>
13 #include <gdcmIPPSorter.h>
14 #include <vtkGDCMImageReader.h>
15 #include "vtkStringArray.h"
21 BBTK_ADD_BLACK_BOX_TO_PACKAGE(gdcmvtk,GetXCoherentInfoGdcmReader)
22 BBTK_BLACK_BOX_IMPLEMENTATION(GetXCoherentInfoGdcmReader,bbtk::AtomicBlackBox);
24 void GetXCoherentInfoGdcmReader::Process()
26 // Read the *first* image file (a SET of file names is given as input)
27 f = GDCM_NAME_SPACE::File::New();
28 f->SetFileName( bbGetInputIn()[0] );
36 // Get info from the first image file
38 std::vector<double> v_iop;
40 f->GetImageOrientationPatient(iop);
43 v_iop.push_back(iop[i]);
44 bbSetOutputIOP(v_iop );
46 std::vector<double> v_ipp;
48 f->GetImagePositionPatient(ipp);
51 v_ipp.push_back(ipp[i]);
52 bbSetOutputIPP(v_ipp );
54 // Add *all the files* to the SerieHelper
55 sh = GDCM_NAME_SPACE::SerieHelper::New();
56 std::vector<std::string> gii = bbGetInputIn();
58 for(std::vector<std::string>::iterator it = gii.begin();
65 GDCM_NAME_SPACE::FileList::const_iterator it;
66 GDCM_NAME_SPACE::FileList *l;
68 // Should only contain one!
69 l = sh->GetFirstSingleSerieUIDFileSet();
74 sh->OrderFileList(l); // this one should compute the *actual* Z Spacing!
75 zspacing = sh->GetZSpacing();
76 std::vector<double> v_pixelspacing;
77 v_pixelspacing.push_back( f->GetXSpacing() );
78 v_pixelspacing.push_back( f->GetYSpacing() );
79 v_pixelspacing.push_back( zspacing );
80 // if (f->GetZSize() != 1) {
81 // v_pixelspacing.push_back(f->GetZSpacing());
83 bbSetOutputPixelSpacing(v_pixelspacing);
90 reader = vtkGdcmReader::New();
91 //reader->SetFileName( bbGetInputIn().c_str() );
92 reader->SetCoherentFileList(l);
96 bbSetOutputOut( reader->GetOutput() );
100 #if defined USE_GDCM2
101 void GetXCoherentInfoGdcmReader::Process()
103 // Read the *first* image file (a SET of file names is given as input)
104 gdcm::Reader *read = new gdcm::Reader();
105 reader->SetFileName( bbGetInputIn()[0].c_str());
107 bool res = read->Read();
115 // Get info from the first image file
116 const gdcm::File &f = read->GetFile();
118 std::vector<double> v_iop;
119 const gdcm::DataElement &deIop = f.GetDataSet().GetDataElement(gdcm::Tag(0x0020, 0x0037));
120 std::stringstream ss;
121 deIop.GetValue().Print(ss);
122 gdcm::Element<gdcm::VR::DS,gdcm::VM::VM6> iop;
125 v_iop.push_back((float)(iop[i]));
126 bbSetOutputIOP(v_iop );
128 std::vector<double> v_ipp;
129 const gdcm::DataElement &deIpp = f.GetDataSet().GetDataElement(gdcm::Tag((0x0020,0x0032)));
130 deIpp.GetValue().Print(ss);
131 gdcm::Element<gdcm::VR::DS,gdcm::VM::VM3> ipp;
134 v_ipp.push_back((float)(ipp[i]));
135 bbSetOutputIPP(v_ipp );
137 // Add *all the files* to the IPPsorter
139 s.SetComputeZSpacing( true );
140 s.SetZSpacingTolerance( 1e-3 );
141 std::vector<std::string> gii = bbGetInputIn();
144 //l = sh->GetFirstSingleSerieUIDFileSet();
145 // no Test if we have multiple series
149 double zspacing = 0.;
150 zspacing = s.GetZSpacing();
151 std::vector<double> v_pixelspacing = gdcm::ImageHelper::GetSpacingValue(f);
152 v_pixelspacing.push_back( v_pixelspacing[0] );
153 v_pixelspacing.push_back( v_pixelspacing[1] );
154 v_pixelspacing.push_back( zspacing );
155 bbSetOutputPixelSpacing(v_pixelspacing);
162 reader = vtkGDCMImageReader::New();
163 vtkStringArray *files = vtkStringArray::New();
164 std::vector< std::string >::const_iterator it = s.GetFilenames().begin();
165 for( ; it != s.GetFilenames().end(); ++it)
167 const std::string &f = *it;
168 files->InsertNextValue( f.c_str() );
170 reader->SetFileNames(files);
173 bbSetOutputOut( reader->GetOutput() );
177 void GetXCoherentInfoGdcmReader::bbUserSetDefaultValues()
179 std::vector<std::string> init;
185 void GetXCoherentInfoGdcmReader::bbUserInitializeProcessing()
191 void GetXCoherentInfoGdcmReader::bbUserFinalizeProcessing()
202 #if defined USE_GDCM2
203 void GetXCoherentInfoGdcmReader::bbUserFinalizeProcessing()
211 // EO namespace bbgdcmvtk