1 #include "bbgdcmvtkGetXCoherentInfoGdcmReader.h"
2 #include "bbgdcmvtkPackage.h"
5 #include "vtkImageData.h"
9 #include "gdcmFileHelper.h"
13 #include <gdcmReader.h>
14 #include <gdcmImageHelper.h>
15 #include <gdcmIPPSorter.h>
16 #include <vtkGDCMImageReader.h>
17 #include "vtkStringArray.h"
23 BBTK_ADD_BLACK_BOX_TO_PACKAGE(gdcmvtk,GetXCoherentInfoGdcmReader)
24 BBTK_BLACK_BOX_IMPLEMENTATION(GetXCoherentInfoGdcmReader,bbtk::AtomicBlackBox);
26 void GetXCoherentInfoGdcmReader::Process()
28 // Read the *first* image file (a SET of file names is given as input)
29 f = GDCM_NAME_SPACE::File::New();
30 f->SetFileName( bbGetInputIn()[0] );
38 // Get info from the first image file
40 std::vector<double> v_iop;
42 f->GetImageOrientationPatient(iop);
45 v_iop.push_back(iop[i]);
46 bbSetOutputIOP(v_iop );
48 std::vector<double> v_ipp;
50 f->GetImagePositionPatient(ipp);
53 v_ipp.push_back(ipp[i]);
54 bbSetOutputIPP(v_ipp );
56 // Add *all the files* to the SerieHelper
57 sh = GDCM_NAME_SPACE::SerieHelper::New();
58 std::vector<std::string> gii = bbGetInputIn();
60 for(std::vector<std::string>::iterator it = gii.begin();
67 GDCM_NAME_SPACE::FileList::const_iterator it;
68 GDCM_NAME_SPACE::FileList *l;
70 // Should only contain one!
71 l = sh->GetFirstSingleSerieUIDFileSet();
76 sh->OrderFileList(l); // this one should compute the *actual* Z Spacing!
77 zspacing = sh->GetZSpacing();
78 std::vector<double> v_pixelspacing;
79 v_pixelspacing.push_back( f->GetXSpacing() );
80 v_pixelspacing.push_back( f->GetYSpacing() );
81 v_pixelspacing.push_back( zspacing );
82 // if (f->GetZSize() != 1) {
83 // v_pixelspacing.push_back(f->GetZSpacing());
85 bbSetOutputPixelSpacing(v_pixelspacing);
92 reader = vtkGdcmReader::New();
94 //EED 21 mars 2012 FLIP probleme ..PLOP..
95 reader->SetFlipY(false);
98 //reader->SetFileName( bbGetInputIn().c_str() );
99 reader->SetCoherentFileList(l);
103 bbSetOutputOut( reader->GetOutput() );
108 #if defined USE_GDCM2
109 void GetXCoherentInfoGdcmReader::Process()
111 // Read the *first* image file (a SET of file names is given as input)
112 gdcm::Reader *read = new gdcm::Reader();
113 reader->SetFileName( bbGetInputIn()[0].c_str());
115 bool res = read->Read();
123 // Get info from the first image file
124 const gdcm::File &f = read->GetFile();
126 std::vector<double> v_iop;
127 const gdcm::DataElement &deIop = f.GetDataSet().GetDataElement(gdcm::Tag(0x0020, 0x0037));
128 std::stringstream ss;
129 deIop.GetValue().Print(ss);
130 gdcm::Element<gdcm::VR::DS,gdcm::VM::VM6> iop;
133 v_iop.push_back((float)(iop[i]));
134 bbSetOutputIOP(v_iop );
136 std::vector<double> v_ipp;
137 const gdcm::DataElement &deIpp = f.GetDataSet().GetDataElement(gdcm::Tag((0x0020,0x0032)));
138 deIpp.GetValue().Print(ss);
139 gdcm::Element<gdcm::VR::DS,gdcm::VM::VM3> ipp;
142 v_ipp.push_back((float)(ipp[i]));
143 bbSetOutputIPP(v_ipp );
145 // Add *all the files* to the IPPsorter
147 s.SetComputeZSpacing( true );
148 s.SetZSpacingTolerance( 1e-3 );
149 std::vector<std::string> gii = bbGetInputIn();
152 //l = sh->GetFirstSingleSerieUIDFileSet();
153 // no Test if we have multiple series
157 double zspacing = 0.;
158 zspacing = s.GetZSpacing();
159 std::vector<double> v_pixelspacing = gdcm::ImageHelper::GetSpacingValue(f);
160 v_pixelspacing.push_back( v_pixelspacing[0] );
161 v_pixelspacing.push_back( v_pixelspacing[1] );
162 v_pixelspacing.push_back( zspacing );
163 bbSetOutputPixelSpacing(v_pixelspacing);
170 reader = vtkGDCMImageReader::New();
171 vtkStringArray *files = vtkStringArray::New();
172 std::vector< std::string >::const_iterator it = s.GetFilenames().begin();
173 for( ; it != s.GetFilenames().end(); ++it)
175 const std::string &f = *it;
176 files->InsertNextValue( f.c_str() );
178 reader->SetFileNames(files);
181 bbSetOutputOut( reader->GetOutput() );
186 void GetXCoherentInfoGdcmReader::bbUserSetDefaultValues()
188 std::vector<std::string> init;
191 //reader=NULL; /// \TODO fixme JPR
194 void GetXCoherentInfoGdcmReader::bbUserInitializeProcessing()
200 void GetXCoherentInfoGdcmReader::bbUserFinalizeProcessing()
211 #if defined USE_GDCM2
212 void GetXCoherentInfoGdcmReader::bbUserFinalizeProcessing()
220 // EO namespace bbgdcmvtk