1 /*=========================================================================
4 Module: $RCSfile: test4DSplitter.cxx,v $
6 Date: $Date: 2011/04/20 15:03:54 $
7 Version: $Revision: 1.7 $
9 Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
10 l'Image). All rights reserved. See Doc/License.txt or
11 http://www.creatis.insa-lyon.fr/Public/Gdcm/License.html for details.
13 This software is distributed WITHOUT ANY WARRANTY; without even
14 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 PURPOSE. See the above copyright notices for more information.
17 =========================================================================*/
19 /* Raisons ne pas utiliser itkImageSeriesReader:
21 On Wed, Feb 16, 2011 at 11:51 AM, Roger Bramon Feixas <rogerbramon@gmail.com>
23 I'm developing with ITK 3.20 + GDCM 2.0.17 + VTK 5.6 and I've noticed
24 itkImageSeriesReader is ~2x slower than vtkGDCMImageReader (from GDCM2).
25 I compared both codes and I think the difference is the extra copy which
26 itkImageSeriesReader makes from ImageFileReader's output to its own output
27 (ImageSeriesReader::GenerateData() line 393). I've commented it just to test
28 the time needed without making the copy and now both readers take more or less
34 #include "gdcmSerieHelper.h"
35 #include <vtkImageData.h>
37 #include "vtkGdcmReader.h"
40 #include "vtkGdcm4DSplitter.h"
46 typedef std::map<std::string, GDCM_NAME_SPACE::File*> SortedFiles;
48 // Due to a deep C++ trouble in 'SortOnTag', we use 'SortOnUserFunction'
49 bool myCompareFunction(GDCM_NAME_SPACE::File *file1, GDCM_NAME_SPACE::File *file2)
51 return atof(file1->GetEntryString(0x0018,0x1060).c_str()) < atof(file2->GetEntryString(0x0018,0x1060).c_str());
54 bool myCompareFunction0008_0032(GDCM_NAME_SPACE::File *file1, GDCM_NAME_SPACE::File *file2)
56 return atof(file1->GetEntryString(0x0008,0x0032).c_str()) < atof(file2->GetEntryString(0x0008,0x0032).c_str());
58 int main(int argc, char *argv[])
62 std::cout << "... inside : " << argv[0] << std::endl;
65 //std::string strDirName("/home/jpr/Desktop/Patients_Emilie/Patient.3T/AUB Jos/AUBERTIN JOSEPH/PROSTATE - 305629373/dSSh_DWISENSE_602");
68 //std::string strDirName("/home/jpr/Desktop/Patients_Emilie/Patient.3T/AUB Jos/AUBERTIN JOSEPH/PROSTATE - 305629373/DYN7INJDYN6_901");
71 std::string strDirName("/home/jpr/Desktop/patient Andrei Dyn/dyn");
73 // ----- Begin Processing -----
75 unsigned short int grSplit;
76 unsigned short int elSplit;
78 unsigned short int grSort;
79 unsigned short int elSort;
81 // Pour un directory '4D'
82 // en sortie, chaque vtkImageData contiendra une coupe au cours du temps
85 std::vector<vtkImageData*> *output;
86 std::vector<vtkImageData*>::iterator it;
88 // ========================================
89 // Split on Position (IPP)
90 // Sort on UserFunction (use 0008|0032 : Aquisition Time )
92 // Should give a vector of 2D+T vtkImageData*
93 // ========================================
95 //vtkGdcm4DSplitter *spl = new vtkGdcm4DSplitter();
99 std::cout << "Try with : Split on Position (IPP) / Sort on UserFunction (use 0008|0032 : Aquisition Time )" << std::endl;
101 vtkGdcm4DSplitter *spl = new vtkGdcm4DSplitter();
102 spl->setFlipY(false);
103 spl->setDirName(strDirName);
104 spl->setRecursive(true);
106 spl->setSplitOnPosition();
108 // Time triger : 0018|1060
112 // ==> use SortOnUserFunction !
113 spl->setSortOnUserFunction(myCompareFunction0008_0032);
116 std::cout << "Everything set" << std::endl;
119 std::cout << "GO() done, status " << res << std::endl;
122 std::cout << "plantage!" << std::endl;
125 output = spl->GetImageDataVector();
128 std::cout << "--------------------------------" << std::endl;
129 std::cout << "Vector size " << output->size() << std::endl;
130 std::cout << "--------------------------------" << std::endl;
132 // Print the first one (why not?)
133 //(*output)[0]->PrintSelf(std::cout, vtkIndent(2));
135 for(it=output->begin(); it!=output->end(); ++it) {
136 //std::cout << "========================================" << std::endl;
137 //(*it)->PrintSelf(std::cout, vtkIndent(2));
143 for(int i=0; i<3; i++)
144 std::cout << "---------------------------------------------" << std::endl;
148 // ========================================
149 // Split on Tag 0008|0032 (Aquisition Time)
150 // Sort on Position (IPP)
152 // Should give a vector of 'true 3D' vtkImageData*
153 // ========================================
157 std::cout << "Try with : Split on Tag 0008|0032 (Aquisition Time) / Sort on Position (IPP)" << std::endl;
159 vtkGdcm4DSplitter *spl = new vtkGdcm4DSplitter();
160 spl->setFlipY(false);
161 spl->setDirName(strDirName);
162 spl->setRecursive(true);
164 // Time triger : 0018|1060
168 // Aquisition Time : 0008|0032
169 spl->setSplitOnTag(0x0008, 0x0032);
171 spl->setSortOnPosition();
173 std::cout << "Everything set" << std::endl;
176 std::cout << "GO() done, status " << res << std::endl;
179 std::cout << "plantage!" << std::endl;
182 output = spl->GetImageDataVector();
185 std::cout << "--------------------------------" << std::endl;
186 std::cout << "Vector size " << output->size() << std::endl;
187 std::cout << "--------------------------------" << std::endl;
189 // Print the first one (why not?)
190 //(*output)[0]->PrintSelf(std::cout, vtkIndent(2));
193 for(it=output->begin(); it!=output->end(); ++it) {
194 //std::cout << "========================================" << std::endl;
195 //(*it)->PrintSelf(std::cout, vtkIndent(2));
201 // Pour un directory '4D'
202 // en sortie, chaque vtkImageData contiendra un volume au cours du temps.