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();
93 //reader->SetFileName( bbGetInputIn().c_str() );
94 reader->SetCoherentFileList(l);
98 bbSetOutputOut( reader->GetOutput() );
103 #if defined USE_GDCM2
104 void GetXCoherentInfoGdcmReader::Process()
106 // Read the *first* image file (a SET of file names is given as input)
107 gdcm::Reader *read = new gdcm::Reader();
108 reader->SetFileName( bbGetInputIn()[0].c_str());
110 bool res = read->Read();
118 // Get info from the first image file
119 const gdcm::File &f = read->GetFile();
121 std::vector<double> v_iop;
122 const gdcm::DataElement &deIop = f.GetDataSet().GetDataElement(gdcm::Tag(0x0020, 0x0037));
123 std::stringstream ss;
124 deIop.GetValue().Print(ss);
125 gdcm::Element<gdcm::VR::DS,gdcm::VM::VM6> iop;
128 v_iop.push_back((float)(iop[i]));
129 bbSetOutputIOP(v_iop );
131 std::vector<double> v_ipp;
132 const gdcm::DataElement &deIpp = f.GetDataSet().GetDataElement(gdcm::Tag((0x0020,0x0032)));
133 deIpp.GetValue().Print(ss);
134 gdcm::Element<gdcm::VR::DS,gdcm::VM::VM3> ipp;
137 v_ipp.push_back((float)(ipp[i]));
138 bbSetOutputIPP(v_ipp );
140 // Add *all the files* to the IPPsorter
142 s.SetComputeZSpacing( true );
143 s.SetZSpacingTolerance( 1e-3 );
144 std::vector<std::string> gii = bbGetInputIn();
147 //l = sh->GetFirstSingleSerieUIDFileSet();
148 // no Test if we have multiple series
152 double zspacing = 0.;
153 zspacing = s.GetZSpacing();
154 std::vector<double> v_pixelspacing = gdcm::ImageHelper::GetSpacingValue(f);
155 v_pixelspacing.push_back( v_pixelspacing[0] );
156 v_pixelspacing.push_back( v_pixelspacing[1] );
157 v_pixelspacing.push_back( zspacing );
158 bbSetOutputPixelSpacing(v_pixelspacing);
165 reader = vtkGDCMImageReader::New();
166 vtkStringArray *files = vtkStringArray::New();
167 std::vector< std::string >::const_iterator it = s.GetFilenames().begin();
168 for( ; it != s.GetFilenames().end(); ++it)
170 const std::string &f = *it;
171 files->InsertNextValue( f.c_str() );
173 reader->SetFileNames(files);
176 bbSetOutputOut( reader->GetOutput() );
181 void GetXCoherentInfoGdcmReader::bbUserSetDefaultValues()
183 std::vector<std::string> init;
186 //reader=NULL; /// \TODO fixme JPR
189 void GetXCoherentInfoGdcmReader::bbUserInitializeProcessing()
195 void GetXCoherentInfoGdcmReader::bbUserFinalizeProcessing()
206 #if defined USE_GDCM2
207 void GetXCoherentInfoGdcmReader::bbUserFinalizeProcessing()
215 // EO namespace bbgdcmvtk