1 # ---------------------------------------------------------------------
3 # Copyright (c) CREATIS (Centre de Recherche en Acquisition et Traitement de l'Image
5 # Authors : Eduardo Davila, Frederic Cervenansky, Claire Mouton
6 # Previous Authors : Laurent Guigues, Jean-Pierre Roux
7 # CreaTools website : www.creatis.insa-lyon.fr/site/fr/creatools_accueil
9 # This software is governed by the CeCILL-B license under French law and
10 # abiding by the rules of distribution of free software. You can use,
11 # modify and/ or redistribute the software under the terms of the CeCILL-B
12 # license as circulated by CEA, CNRS and INRIA at the following URL
13 # http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html
14 # or in the file LICENSE.txt.
16 # As a counterpart to the access to the source code and rights to copy,
17 # modify and redistribute granted by the license, users are provided only
18 # with a limited warranty and the software's author, the holder of the
19 # economic rights, and the successive licensors have only limited
22 # The fact that you are presently reading this means that you have had
23 # knowledge of the CeCILL-B license and that you accept its terms.
24 # ------------------------------------------------------------------------ */
26 #include "bbgdcmvtkGetXCoherentInfoGdcmReader.h"
27 #include "bbgdcmvtkPackage.h"
30 #include "vtkImageData.h"
31 #include <vtkIndent.h>
34 #include "gdcmFileHelper.h"
38 #include <gdcmReader.h>
39 #include <gdcmImageHelper.h>
40 #include <gdcmIPPSorter.h>
41 #include <vtkGDCMImageReader.h>
42 #include "vtkStringArray.h"
48 BBTK_ADD_BLACK_BOX_TO_PACKAGE(gdcmvtk,GetXCoherentInfoGdcmReader)
49 BBTK_BLACK_BOX_IMPLEMENTATION(GetXCoherentInfoGdcmReader,bbtk::AtomicBlackBox);
51 void GetXCoherentInfoGdcmReader::Process()
53 // Read the *first* image file (a SET of file names is given as input)
54 f = GDCM_NAME_SPACE::File::New();
55 f->SetFileName( bbGetInputIn()[0] );
63 // Get info from the first image file
65 std::vector<double> v_iop;
67 f->GetImageOrientationPatient(iop);
70 v_iop.push_back(iop[i]);
71 bbSetOutputIOP(v_iop );
73 std::vector<double> v_ipp;
75 f->GetImagePositionPatient(ipp);
78 v_ipp.push_back(ipp[i]);
79 bbSetOutputIPP(v_ipp );
81 // Add *all the files* to the SerieHelper
82 sh = GDCM_NAME_SPACE::SerieHelper::New();
83 std::vector<std::string> gii = bbGetInputIn();
85 for(std::vector<std::string>::iterator it = gii.begin();
92 GDCM_NAME_SPACE::FileList::const_iterator it;
93 GDCM_NAME_SPACE::FileList *l;
95 // Should only contain one!
96 l = sh->GetFirstSingleSerieUIDFileSet();
100 nbFiles = l->size() ;
101 sh->OrderFileList(l); // this one should compute the *actual* Z Spacing!
102 zspacing = sh->GetZSpacing();
103 std::vector<double> v_pixelspacing;
104 v_pixelspacing.push_back( f->GetXSpacing() );
105 v_pixelspacing.push_back( f->GetYSpacing() );
106 v_pixelspacing.push_back( zspacing );
107 // if (f->GetZSize() != 1) {
108 // v_pixelspacing.push_back(f->GetZSpacing());
110 bbSetOutputPixelSpacing(v_pixelspacing);
117 reader = vtkGdcmReader::New();
119 //EED 21 mars 2012 FLIP probleme ..PLOP..
120 reader->SetFlipY(false);
123 //reader->SetFileName( bbGetInputIn().c_str() );
124 reader->SetCoherentFileList(l);
128 bbSetOutputOut( reader->GetOutput() );
133 #if defined USE_GDCM2
134 void GetXCoherentInfoGdcmReader::Process()
136 // Read the *first* image file (a SET of file names is given as input)
137 gdcm::Reader *read = new gdcm::Reader();
138 reader->SetFileName( bbGetInputIn()[0].c_str());
140 bool res = read->Read();
148 // Get info from the first image file
149 const gdcm::File &f = read->GetFile();
151 std::vector<double> v_iop;
152 const gdcm::DataElement &deIop = f.GetDataSet().GetDataElement(gdcm::Tag(0x0020, 0x0037));
153 std::stringstream ss;
154 deIop.GetValue().Print(ss);
155 gdcm::Element<gdcm::VR::DS,gdcm::VM::VM6> iop;
158 v_iop.push_back((float)(iop[i]));
159 bbSetOutputIOP(v_iop );
161 std::vector<double> v_ipp;
162 const gdcm::DataElement &deIpp = f.GetDataSet().GetDataElement(gdcm::Tag((0x0020,0x0032)));
163 deIpp.GetValue().Print(ss);
164 gdcm::Element<gdcm::VR::DS,gdcm::VM::VM3> ipp;
167 v_ipp.push_back((float)(ipp[i]));
168 bbSetOutputIPP(v_ipp );
170 // Add *all the files* to the IPPsorter
172 s.SetComputeZSpacing( true );
173 s.SetZSpacingTolerance( 1e-3 );
174 std::vector<std::string> gii = bbGetInputIn();
177 //l = sh->GetFirstSingleSerieUIDFileSet();
178 // no Test if we have multiple series
182 double zspacing = 0.;
183 zspacing = s.GetZSpacing();
184 std::vector<double> v_pixelspacing = gdcm::ImageHelper::GetSpacingValue(f);
185 v_pixelspacing.push_back( v_pixelspacing[0] );
186 v_pixelspacing.push_back( v_pixelspacing[1] );
187 v_pixelspacing.push_back( zspacing );
188 bbSetOutputPixelSpacing(v_pixelspacing);
195 reader = vtkGDCMImageReader::New();
196 vtkStringArray *files = vtkStringArray::New();
197 std::vector< std::string >::const_iterator it = s.GetFilenames().begin();
198 for( ; it != s.GetFilenames().end(); ++it)
200 const std::string &f = *it;
201 files->InsertNextValue( f.c_str() );
203 reader->SetFileNames(files);
206 bbSetOutputOut( reader->GetOutput() );
211 void GetXCoherentInfoGdcmReader::bbUserSetDefaultValues()
213 std::vector<std::string> init;
216 //reader=NULL; /// \TODO fixme JPR
219 void GetXCoherentInfoGdcmReader::bbUserInitializeProcessing()
225 void GetXCoherentInfoGdcmReader::bbUserFinalizeProcessing()
236 #if defined USE_GDCM2
237 void GetXCoherentInfoGdcmReader::bbUserFinalizeProcessing()
245 // EO namespace bbgdcmvtk