]> Creatis software - gdcm.git/blob - Example/exSerieHelper.cxx
Normalization
[gdcm.git] / Example / exSerieHelper.cxx
1 /*=========================================================================
2                                                                                 
3   Program:   gdcm
4   Module:    $RCSfile: exSerieHelper.cxx,v $
5   Language:  C++
6   Date:      $Date: 2007/06/22 11:01:57 $
7   Version:   $Revision: 1.13 $
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 #include "gdcmSerieHelper.h"
19 #include "gdcmFile.h"
20 #include "gdcmDirList.h" // for FileList
21 #include "gdcmDebug.h"
22 #include <iostream>
23
24 int main(int argc, char *argv[])
25 {  
26    GDCM_NAME_SPACE::SerieHelper *s;
27   
28    std::string dirName; 
29    if (argc > 1) 
30       dirName = argv[1];    
31    else 
32    {
33       dirName = GDCM_DATA_ROOT;
34    }
35
36    if (argc > 2)
37       GDCM_NAME_SPACE::Debug::DebugOn();
38
39   
40    std::cout << "Dir Name :[" << dirName << "]" << std::endl;
41    //   
42    // Something, using only SerieHelper is not enought !
43    // See also exXcoherentFileSet
44    //
45
46    s = GDCM_NAME_SPACE::SerieHelper::New();
47    s->SetLoadMode(GDCM_NAME_SPACE::LD_ALL);     // Load everything for each File
48    //GDCM_NAME_SPACE::TagKey t(0x0020,0x0013);
49    //s->AddRestriction(t, "340", GDCM_NAME_SPACE::GDCM_LESS); // Keep only files where
50                                               // restriction is true
51    s->SetDirectory(dirName, true); // true : recursive exploration
52
53    std::cout << " ---------------------------------------- Finish parsing :["
54              << dirName << "]" << std::endl;
55
56    s->Print();
57    std::cout << " ---------------------------------------- Finish printing (1)"
58              << std::endl;
59
60
61    GDCM_NAME_SPACE::FileList::const_iterator it;
62    GDCM_NAME_SPACE::FileList *l;
63    std::cout << " ---------------------------------------- Recap"
64              << std::endl;  
65    l = s->GetFirstSingleSerieUIDFileSet();
66    while (l)
67    { 
68       it = l->begin();
69       std::cout << "SerieUID [" <<  (*it)->GetEntryString(0x0020,0x000e) <<"]   Serie Description ["
70                 << (*it)->GetEntryString(0x0008,0x103e) << "] "  
71                 << " : " << l->size() << " files" << std::endl;
72       l = s->GetNextSingleSerieUIDFileSet();
73    } 
74     std::cout << " ----------------------------------------End Recap"
75              << std::endl;
76
77    int nbFiles;
78    double zspacing = 0.;
79    // For all the Single SerieUID Files Sets of the GDCM_NAME_SPACE::Serie
80    l = s->GetFirstSingleSerieUIDFileSet();
81    while (l)
82    { 
83       nbFiles = l->size() ;
84       if ( l->size() > 5 ) // Why not ? Just an example, for testing
85       {
86          std::cout << "Sort list : " << nbFiles << " long" << std::endl; 
87  
88          //---------------------------------------------------------
89          s->OrderFileList(l);  // sort the list (and compute ZSpacing !)
90          //---------------------------------------------------------
91  
92           zspacing = s->GetZSpacing();
93          // Just to show : GetZSpacing from a GDCM_NAME_SPACE::SerieHelper is right  
94          std::cout << "GetZSpacing() of sorted SingleSerieUIDFileSet "
95                    << "from GDCM_NAME_SPACE::SerieHelper: " << zspacing << std::endl;
96          std::cout << " ('-1' means all the files have the same position)" << std::endl;
97          for (std::vector<GDCM_NAME_SPACE::File* >::iterator it2 =  l->begin();
98                                             it2 != l->end();
99                                           ++it2)
100          {
101           // Just to show : GetZSpacing from a GDCM_NAME_SPACE::File may be different        
102              std::cout << (*it2)->GetFileName() << " -->  GetZSpacing() from GDCM_NAME_SPACE::File : " 
103                        << (*it2)->GetZSpacing() << std::endl;      
104          }  
105
106          break; // we only deal with the first one ... Why not ?
107       }
108       l = s->GetNextSingleSerieUIDFileSet();
109    } 
110    std::cout << " ------------------Prints all the Single SerieUID File Sets (sorted or not) -----"
111              << std::endl;
112    s->Print(); // Prints all the Single SerieUID File Sets (sorted or not)
113    std::cout << " -------------------------------------------- Finish printing"
114              << std::endl;
115      
116    s->Delete();
117
118    return 0;
119 }