]> Creatis software - gdcm.git/blob - vtk/test4DSplitter.cxx
re indent
[gdcm.git] / vtk / test4DSplitter.cxx
1 /*=========================================================================
2
3   Program:   gdcm
4   Module:    $RCSfile: test4DSplitter.cxx,v $
5   Language:  C++
6   Date:      $Date: 2011/09/20 16:09:05 $
7   Version:   $Revision: 1.8 $
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.
12                  
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.
16                                                                                 
17 =========================================================================*/
18
19 /* Raisons ne pas utiliser itkImageSeriesReader:
20
21 On Wed, Feb 16, 2011 at 11:51 AM, Roger Bramon Feixas <rogerbramon@gmail.com>
22     Hi,
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 
29     the same time.
30 */
31
32 #include "gdcmFile.h"
33 #include "gdcmSerieHelper.h"
34 #include <vtkImageData.h>
35 #include <iostream>
36 #include "vtkGdcmReader.h"
37
38 #include <algorithm>
39 #include "vtkGdcm4DSplitter.h"
40     
41 /**
42   * \brief
43   */
44
45 typedef std::map<std::string, GDCM_NAME_SPACE::File*> SortedFiles;
46
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)
49  { 
50    return atof(file1->GetEntryString(0x0018,0x1060).c_str()) < atof(file2->GetEntryString(0x0018,0x1060).c_str()); 
51  }
52  
53 bool myCompareFunction0008_0032(GDCM_NAME_SPACE::File *file1, GDCM_NAME_SPACE::File *file2)
54  { 
55    return atof(file1->GetEntryString(0x0008,0x0032).c_str()) < atof(file2->GetEntryString(0x0008,0x0032).c_str()); 
56  } 
57 int main(int argc, char *argv[])
58 {
59   
60   
61    std::cout << "... inside : " << argv[0] << std::endl;
62
63 // 3D     
64 //std::string strDirName("/home/jpr/Desktop/Patients_Emilie/Patient.3T/AUB Jos/AUBERTIN JOSEPH/PROSTATE - 305629373/dSSh_DWISENSE_602");
65
66 // 4D
67 //std::string strDirName("/home/jpr/Desktop/Patients_Emilie/Patient.3T/AUB Jos/AUBERTIN JOSEPH/PROSTATE - 305629373/DYN7INJDYN6_901");
68
69 // n directories 
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 -----  
73    
74    unsigned short int grSplit;
75    unsigned short int elSplit;
76
77    unsigned short int grSort;
78    unsigned short int elSort;
79
80 // Pour un directory '4D'
81 // en sortie, chaque vtkImageData contiendra une coupe au cours du temps
82 // n * 2D+T
83
84   std::vector<vtkImageData*> *output;
85   std::vector<vtkImageData*>::iterator it;
86
87 //  ========================================
88 //  Split on Position (IPP)
89 //  Sort on UserFunction (use 0008|0032 : Aquisition Time )
90 //
91 // Should give a vector of 2D+T vtkImageData*
92 //  ========================================
93
94 //vtkGdcm4DSplitter *spl = new vtkGdcm4DSplitter();
95
96 if (1) {
97
98    std::cout << "Try with :  Split on Position (IPP) / Sort on UserFunction (use 0008|0032 : Aquisition Time )" << std::endl;
99
100    vtkGdcm4DSplitter *spl = new vtkGdcm4DSplitter();
101    spl->setFlipY(false);
102    spl->setDirName(strDirName);
103    spl->setRecursive(true);
104    
105    spl->setSplitOnPosition();
106    
107    // Time triger : 0018|1060
108    //grSort=0x0018;
109    //elSort=0x1060;
110       
111    // ==> use SortOnUserFunction !
112    spl->setSortOnUserFunction(myCompareFunction0008_0032);  
113
114    std::cout << "Everything set" << std::endl;  
115    bool res=spl->Go();
116    
117     std::cout << "GO() done, status " << res << std::endl;
118     if(!res)
119     {
120        std::cout << "plantage!" << std::endl;
121     } 
122
123    output = spl->GetImageDataVector();
124
125 std::cout << "--------------------------------" << std::endl;
126 std::cout << "Vector size " << output->size()   << std::endl;
127 std::cout << "--------------------------------" << std::endl;
128
129 // Print the first one (why not?)
130 //(*output)[0]->PrintSelf(std::cout, vtkIndent(2));
131
132    for(it=output->begin(); it!=output->end(); ++it) {
133       //std::cout << "========================================" << std::endl;
134       //(*it)->PrintSelf(std::cout, vtkIndent(2));
135    }
136
137    delete spl;
138
139    // To please valgring  
140    std::vector<vtkImageData*>::iterator it2;       
141    for ( it2 = output->begin(); // for each vtkImageData*
142              it2 != output->end();
143            ++it2)
144    {
145            (*it2)->Delete(); // delete vtkImageData
146    }       
147    delete output;    
148
149
150
151 for(int i=0; i<3; i++)
152    std::cout << "---------------------------------------------" << std::endl;
153
154
155
156 //  ========================================
157 //  Split on Tag 0008|0032 (Aquisition Time)
158 //  Sort on Position (IPP)
159 //
160 // Should give a vector of 'true 3D' vtkImageData*
161 //  ========================================
162  
163  if (1) {
164  
165    std::cout << "Try with :  Split on Tag 0008|0032 (Aquisition Time) / Sort on Position (IPP)" << std::endl; 
166
167    vtkGdcm4DSplitter *spl = new vtkGdcm4DSplitter();
168    spl->setFlipY(false);
169    spl->setDirName(strDirName);
170    spl->setRecursive(true);
171    
172    // Time triger : 0018|1060
173    //grSort=0x0018;
174    //elSort=0x1060;
175  
176    // Aquisition Time  : 0008|0032
177    spl->setSplitOnTag(0x0008, 0x0032); 
178    
179    spl->setSortOnPosition();
180
181    std::cout << "Everything set" << std::endl;  
182    bool res=spl->Go();
183    
184     std::cout << "GO() done, status " << res << std::endl;
185     if(!res)
186     {
187        std::cout << "plantage!" << std::endl;
188     } 
189
190    output = spl->GetImageDataVector();
191
192
193 std::cout << "--------------------------------" << std::endl;
194 std::cout << "Vector size " << output->size()   << std::endl;
195 std::cout << "--------------------------------" << std::endl;
196
197 // Print the first one (why not?)
198 //(*output)[0]->PrintSelf(std::cout, vtkIndent(2));
199
200
201    for(it=output->begin(); it!=output->end(); ++it) {
202       //std::cout << "========================================" << std::endl;
203       //(*it)->PrintSelf(std::cout, vtkIndent(2));
204    }
205    
206    delete spl;
207
208    // To please valgring  
209    std::vector<vtkImageData*>::iterator it2;       
210    for ( it2 = output->begin(); // for each vtkImageData*
211              it2 != output->end();
212            ++it2)
213    {
214            (*it2)->Delete(); // delete vtkImageData
215    }       
216    delete output;
217 }
218
219 // Pour un directory '4D'
220 // en sortie, chaque  vtkImageData contiendra un volume au cours du temps.
221 // 3D + T
222
223
224 }