2 # ---------------------------------------------------------------------
4 # Copyright (c) CREATIS (Centre de Recherche en Acquisition et Traitement de l'Image
6 # Authors : Eduardo Davila, Frederic Cervenansky, Claire Mouton
7 # Previous Authors : Laurent Guigues, Jean-Pierre Roux
8 # CreaTools website : www.creatis.insa-lyon.fr/site/fr/creatools_accueil
10 # This software is governed by the CeCILL-B license under French law and
11 # abiding by the rules of distribution of free software. You can use,
12 # modify and/ or redistribute the software under the terms of the CeCILL-B
13 # license as circulated by CEA, CNRS and INRIA at the following URL
14 # http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html
15 # or in the file LICENSE.txt.
17 # As a counterpart to the access to the source code and rights to copy,
18 # modify and redistribute granted by the license, users are provided only
19 # with a limited warranty and the software's author, the holder of the
20 # economic rights, and the successive licensors have only limited
23 # The fact that you are presently reading this means that you have had
24 # knowledge of the CeCILL-B license and that you accept its terms.
25 # ------------------------------------------------------------------------ */
27 #include "bbgdcmvtkGetXCoherentInfoGdcmReader.h"
28 #include "bbgdcmvtkPackage.h"
31 #include "vtkImageData.h"
32 #include <vtkIndent.h>
35 #include "gdcmFileHelper.h"
39 #include <gdcmReader.h>
40 #include <gdcmImageHelper.h>
41 #include <gdcmIPPSorter.h>
42 #include <vtkGDCMImageReader.h>
43 #include "vtkStringArray.h"
49 BBTK_ADD_BLACK_BOX_TO_PACKAGE(gdcmvtk,GetXCoherentInfoGdcmReader)
50 BBTK_BLACK_BOX_IMPLEMENTATION(GetXCoherentInfoGdcmReader,bbtk::AtomicBlackBox);
53 vtkImageData* GetXCoherentInfoGdcmReader::CreateDefaultImage()
56 int sizeX, sizeY, sizeZ;
60 vtkImageData *newImage = vtkImageData::New();
61 newImage->Initialize();
62 newImage->SetScalarTypeToUnsignedChar();
63 newImage->SetSpacing( 1,1,1 );
64 newImage->SetDimensions( sizeX,sizeY,sizeZ );
65 newImage->SetWholeExtent(0, sizeX-1,0,sizeY-1,0,sizeZ-1 );
66 newImage->SetExtent(0, sizeX-1,0,sizeY-1,0,sizeZ-1 );
67 newImage->SetNumberOfScalarComponents(1);
68 newImage->AllocateScalars();
70 memset ( (void*)newImage->GetScalarPointer(), 0, sizeX*sizeY*1 );
71 for (i=0; i<sizeX; i++)
73 newImage->SetScalarComponentFromDouble(i,i,0, 0, 255 );
74 newImage->SetScalarComponentFromDouble(i,sizeY-1-i,0, 0, 255 );
81 void GetXCoherentInfoGdcmReader::Process()
84 // Read the *first* image file (a SET of file names is given as input)
85 f = GDCM_NAME_SPACE::File::New();
87 if ( bbGetInputIn().size()!=0 )
89 f->SetFileName( bbGetInputIn()[0] );
97 printf("EED GetXCoherentInfoGdcmReader::Process resultImage NULL\n");
99 bbSetOutputOut( CreateDefaultImage() );
102 // Get info from the first image file
104 std::vector<double> v_iop;
106 f->GetImageOrientationPatient(iop);
109 v_iop.push_back(iop[i]);
110 bbSetOutputIOP(v_iop );
112 std::vector<double> v_ipp;
114 f->GetImagePositionPatient(ipp);
117 v_ipp.push_back(ipp[i]);
118 bbSetOutputIPP(v_ipp );
120 // Add *all the files* to the SerieHelper
121 sh = GDCM_NAME_SPACE::SerieHelper::New();
122 std::vector<std::string> gii = bbGetInputIn();
124 for(std::vector<std::string>::iterator it = gii.begin();
128 sh->AddFileName(*it);
132 GDCM_NAME_SPACE::FileList::const_iterator it;
133 GDCM_NAME_SPACE::FileList *l;
135 // Should only contain one!
136 l = sh->GetFirstSingleSerieUIDFileSet();
139 double zspacing = 0.;
140 nbFiles = l->size() ;
141 sh->OrderFileList(l); // this one should compute the *actual* Z Spacing!
142 zspacing = sh->GetZSpacing();
143 std::vector<double> v_pixelspacing;
144 v_pixelspacing.push_back( f->GetXSpacing() );
145 v_pixelspacing.push_back( f->GetYSpacing() );
146 v_pixelspacing.push_back( zspacing );
147 // if (f->GetZSize() != 1) {
148 // v_pixelspacing.push_back(f->GetZSpacing());
150 bbSetOutputPixelSpacing(v_pixelspacing);
157 reader = vtkGdcmReader::New();
159 //EED 21 mars 2012 FLIP probleme ..PLOP..
160 reader->SetFlipY(false);
163 //reader->SetFileName( bbGetInputIn().c_str() );
164 reader->SetCoherentFileList(l);
166 bbSetOutputOut( reader->GetOutput() );
171 #if defined USE_GDCM2
172 void GetXCoherentInfoGdcmReader::Process()
174 // Read the *first* image file (a SET of file names is given as input)
175 gdcm::Reader *read = new gdcm::Reader();
176 reader->SetFileName( bbGetInputIn()[0].c_str() );
178 bool res = read->Read();
182 bbSetOutputOut(NULL);
188 // Get info from the first image file
189 const gdcm::File &f = read->GetFile();
191 std::vector<double> v_iop;
192 const gdcm::DataElement &deIop = f.GetDataSet().GetDataElement(gdcm::Tag(0x0020, 0x0037));
193 std::stringstream ss;
194 deIop.GetValue().Print(ss);
195 gdcm::Element<gdcm::VR::DS,gdcm::VM::VM6> iop;
198 v_iop.push_back((float)(iop[i]));
199 bbSetOutputIOP(v_iop );
201 std::vector<double> v_ipp;
202 const gdcm::DataElement &deIpp = f.GetDataSet().GetDataElement(gdcm::Tag((0x0020,0x0032)));
203 deIpp.GetValue().Print(ss);
204 gdcm::Element<gdcm::VR::DS,gdcm::VM::VM3> ipp;
207 v_ipp.push_back((float)(ipp[i]));
208 bbSetOutputIPP(v_ipp );
210 // Add *all the files* to the IPPsorter
212 s.SetComputeZSpacing( true );
213 s.SetZSpacingTolerance( 1e-3 );
214 std::vector<std::string> gii = bbGetInputIn();
217 //l = sh->GetFirstSingleSerieUIDFileSet();
218 // no Test if we have multiple series
222 double zspacing = 0.;
223 zspacing = s.GetZSpacing();
224 std::vector<double> v_pixelspacing = gdcm::ImageHelper::GetSpacingValue(f);
225 v_pixelspacing.push_back( v_pixelspacing[0] );
226 v_pixelspacing.push_back( v_pixelspacing[1] );
227 v_pixelspacing.push_back( zspacing );
228 bbSetOutputPixelSpacing(v_pixelspacing);
235 reader = vtkGDCMImageReader::New();
236 vtkStringArray *files = vtkStringArray::New();
237 std::vector< std::string >::const_iterator it = s.GetFilenames().begin();
238 for( ; it != s.GetFilenames().end(); ++it)
240 const std::string &f = *it;
241 files->InsertNextValue( f.c_str() );
243 reader->SetFileNames(files);
245 bbSetOutputOut( reader->GetOutput() );
250 void GetXCoherentInfoGdcmReader::bbUserSetDefaultValues()
252 std::vector<std::string> init;
255 //reader=NULL; /// \TODO fixme JPR
258 void GetXCoherentInfoGdcmReader::bbUserInitializeProcessing()
264 void GetXCoherentInfoGdcmReader::bbUserFinalizeProcessing()
275 #if defined USE_GDCM2
276 void GetXCoherentInfoGdcmReader::bbUserFinalizeProcessing()
284 // EO namespace bbgdcmvtk