1 /*=========================================================================
4 Module: $RCSfile: test4DSplitter.cxx,v $
6 Date: $Date: 2011/09/20 16:09:05 $
7 Version: $Revision: 1.8 $
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
33 #include "gdcmSerieHelper.h"
34 #include <vtkImageData.h>
36 #include "vtkGdcmReader.h"
39 #include "vtkGdcm4DSplitter.h"
45 typedef std::map<std::string, GDCM_NAME_SPACE::File*> SortedFiles;
47 // Due to a deep C++ trouble in 'SortOnTag', we use 'SortOnUserFunction'
48 bool myCompareFunction(GDCM_NAME_SPACE::File *file1, GDCM_NAME_SPACE::File *file2)
50 return atof(file1->GetEntryString(0x0018,0x1060).c_str()) < atof(file2->GetEntryString(0x0018,0x1060).c_str());
53 bool myCompareFunction0008_0032(GDCM_NAME_SPACE::File *file1, GDCM_NAME_SPACE::File *file2)
55 return atof(file1->GetEntryString(0x0008,0x0032).c_str()) < atof(file2->GetEntryString(0x0008,0x0032).c_str());
57 int main(int argc, char *argv[])
61 std::cout << "... inside : " << argv[0] << std::endl;
64 //std::string strDirName("/home/jpr/Desktop/Patients_Emilie/Patient.3T/AUB Jos/AUBERTIN JOSEPH/PROSTATE - 305629373/dSSh_DWISENSE_602");
67 //std::string strDirName("/home/jpr/Desktop/Patients_Emilie/Patient.3T/AUB Jos/AUBERTIN JOSEPH/PROSTATE - 305629373/DYN7INJDYN6_901");
70 std::string strDirName("/home/jpr/Desktop/patient Andrei Dyn/dyn");
71 //std::string strDirName("/home/jpr/Desktop/patient Andrei Dyn/dyn2"); // very small sample
72 // ----- Begin Processing -----
74 unsigned short int grSplit;
75 unsigned short int elSplit;
77 unsigned short int grSort;
78 unsigned short int elSort;
80 // Pour un directory '4D'
81 // en sortie, chaque vtkImageData contiendra une coupe au cours du temps
84 std::vector<vtkImageData*> *output;
85 std::vector<vtkImageData*>::iterator it;
87 // ========================================
88 // Split on Position (IPP)
89 // Sort on UserFunction (use 0008|0032 : Aquisition Time )
91 // Should give a vector of 2D+T vtkImageData*
92 // ========================================
94 //vtkGdcm4DSplitter *spl = new vtkGdcm4DSplitter();
98 std::cout << "Try with : Split on Position (IPP) / Sort on UserFunction (use 0008|0032 : Aquisition Time )" << std::endl;
100 vtkGdcm4DSplitter *spl = new vtkGdcm4DSplitter();
101 spl->setFlipY(false);
102 spl->setDirName(strDirName);
103 spl->setRecursive(true);
105 spl->setSplitOnPosition();
107 // Time triger : 0018|1060
111 // ==> use SortOnUserFunction !
112 spl->setSortOnUserFunction(myCompareFunction0008_0032);
114 std::cout << "Everything set" << std::endl;
117 std::cout << "GO() done, status " << res << std::endl;
120 std::cout << "plantage!" << std::endl;
123 output = spl->GetImageDataVector();
125 std::cout << "--------------------------------" << std::endl;
126 std::cout << "Vector size " << output->size() << std::endl;
127 std::cout << "--------------------------------" << std::endl;
129 // Print the first one (why not?)
130 //(*output)[0]->PrintSelf(std::cout, vtkIndent(2));
132 for(it=output->begin(); it!=output->end(); ++it) {
133 //std::cout << "========================================" << std::endl;
134 //(*it)->PrintSelf(std::cout, vtkIndent(2));
139 // To please valgring
140 std::vector<vtkImageData*>::iterator it2;
141 for ( it2 = output->begin(); // for each vtkImageData*
142 it2 != output->end();
145 (*it2)->Delete(); // delete vtkImageData
151 for(int i=0; i<3; i++)
152 std::cout << "---------------------------------------------" << std::endl;
156 // ========================================
157 // Split on Tag 0008|0032 (Aquisition Time)
158 // Sort on Position (IPP)
160 // Should give a vector of 'true 3D' vtkImageData*
161 // ========================================
165 std::cout << "Try with : Split on Tag 0008|0032 (Aquisition Time) / Sort on Position (IPP)" << std::endl;
167 vtkGdcm4DSplitter *spl = new vtkGdcm4DSplitter();
168 spl->setFlipY(false);
169 spl->setDirName(strDirName);
170 spl->setRecursive(true);
172 // Time triger : 0018|1060
176 // Aquisition Time : 0008|0032
177 spl->setSplitOnTag(0x0008, 0x0032);
179 spl->setSortOnPosition();
181 std::cout << "Everything set" << std::endl;
184 std::cout << "GO() done, status " << res << std::endl;
187 std::cout << "plantage!" << std::endl;
190 output = spl->GetImageDataVector();
193 std::cout << "--------------------------------" << std::endl;
194 std::cout << "Vector size " << output->size() << std::endl;
195 std::cout << "--------------------------------" << std::endl;
197 // Print the first one (why not?)
198 //(*output)[0]->PrintSelf(std::cout, vtkIndent(2));
201 for(it=output->begin(); it!=output->end(); ++it) {
202 //std::cout << "========================================" << std::endl;
203 //(*it)->PrintSelf(std::cout, vtkIndent(2));
208 // To please valgring
209 std::vector<vtkImageData*>::iterator it2;
210 for ( it2 = output->begin(); // for each vtkImageData*
211 it2 != output->end();
214 (*it2)->Delete(); // delete vtkImageData
219 // Pour un directory '4D'
220 // en sortie, chaque vtkImageData contiendra un volume au cours du temps.