]> Creatis software - gdcm.git/blob - vtk/test4DSplitter.cxx
249c4ce56da511f0b2f8492d1f261099ccb219a2
[gdcm.git] / vtk / test4DSplitter.cxx
1 /*=========================================================================
2
3   Program:   gdcm
4   Module:    $RCSfile: test4DSplitter.cxx,v $
5   Language:  C++
6   Date:      $Date: 2011/03/30 14:50:44 $
7   Version:   $Revision: 1.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.
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 "gdcmDocEntry.h"
33 //#include "gdcmDicomDir.h"
34 //#include "gdcmDicomDirPatient.h"
35 #include "gdcmFile.h"
36 #include "gdcmFileHelper.h"
37 //#include "gdcmDirList.h"
38 //#include "gdcmDebug.h"
39 //#include "gdcmArgMgr.h"
40 #include "gdcmUtil.h"
41 #include "gdcmSerieHelper.h"
42 #include <vtkImageData.h>
43 #include <iostream>
44 #include "vtkGdcmReader.h"
45
46 #include <algorithm>
47 #include "vtkGdcm4DSplitter.h"
48     
49 /**
50   * \brief
51   */
52
53 typedef std::map<std::string, GDCM_NAME_SPACE::File*> SortedFiles;
54
55 // Due to a deep C++ trouble in 'SortOnTag', we use 'SortOnUserFunction'
56 bool myCompareFunction(GDCM_NAME_SPACE::File *file1, GDCM_NAME_SPACE::File *file2)
57  { 
58    return atof(file1->GetEntryString(0x0018,0x1060).c_str()) < atof(file2->GetEntryString(0x0018,0x1060).c_str()); 
59  } 
60
61 int main(int argc, char *argv[])
62 {
63   
64   
65    std::cout << "... inside " << argv[0] << std::endl;
66
67      
68
69 std::string strDirName("/home/jpr/Desktop/Patients_Emilie/Patient.3T/AUB Jos/AUBERTIN JOSEPH/PROSTATE - 305629373/DYN7INJDYN6_901");
70    
71
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
86  if (1) {
87    vtkGdcm4DSplitter *spl = new vtkGdcm4DSplitter();
88    spl->setDirName(strDirName);
89    spl->setRecursive(false);
90    spl->setSplitOnPosition();
91
92    // Time triger : 0018|1060
93    grSort=0x0018;
94    elSort=0x1060;
95    
96    // ==> Big troubles with SortOnTag
97    //spl->setSortOnTag(grSort, elSort);
98    //spl->setSortConvertToFloat(true); 
99       
100    // ==> use SortOnUserFunction !
101    spl->setSortOnUserFunction(myCompareFunction);   
102
103    std::cout << "Everything set" << std::endl;  
104    bool res=spl->Go();
105    
106     std::cout << "GO() done, status " << res << std::endl;
107     if(!res)
108     {
109        std::cout << "plantage!" << std::endl;
110     } 
111
112    output = spl->GetImageDataVector();
113 }
114
115 std::cout << "--------------------------------" << std::endl;
116 std::cout << "Vector size " << output->size()   << std::endl;
117 std::cout << "--------------------------------" << std::endl;
118
119 std::vector<vtkImageData*>::iterator it;
120 // Print the first one (why not?)
121 it=output->begin();
122 (*it)->PrintSelf(std::cout, vtkIndent(2));
123
124
125 // Pour un directory '4D'
126 // en sortie, chaque  vtkImageData contiendra un volume au cours du temps.
127 // 3D + T
128
129 }
130   
131
132