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