]> Creatis software - gdcm.git/blob - Example/exSerieHelper.cxx
More verbosity
[gdcm.git] / Example / exSerieHelper.cxx
1 /*=========================================================================
2                                                                                 
3   Program:   gdcm
4   Module:    $RCSfile: exSerieHelper.cxx,v $
5   Language:  C++
6   Date:      $Date: 2007/05/31 12:22:46 $
7   Version:   $Revision: 1.10 $
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    s = GDCM_NAME_SPACE::SerieHelper::New();
43    s->SetLoadMode(GDCM_NAME_SPACE::LD_ALL);     // Load everything for each File
44    //GDCM_NAME_SPACE::TagKey t(0x0020,0x0013);
45    //s->AddRestriction(t, "340", GDCM_NAME_SPACE::GDCM_LESS); // Keep only files where
46                                               // restriction is true
47    s->SetDirectory(dirName, true); // true : recursive exploration
48
49    std::cout << " ---------------------------------------- Finish parsing :["
50              << dirName << "]" << std::endl;
51
52    s->Print();
53    std::cout << " ---------------------------------------- Finish printing (1)"
54              << std::endl;
55
56
57    GDCM_NAME_SPACE::FileList::const_iterator it;
58    GDCM_NAME_SPACE::FileList *l;
59    std::cout << " ---------------------------------------- Recap"
60              << std::endl;  
61    l = s->GetFirstSingleSerieUIDFileSet();
62    while (l)
63    { 
64       it = l->begin();
65       std::cout << "SerieUID [" <<  (*it)->GetEntryString(0x0020,0x000e) <<"]   Serie Description ["
66                 << (*it)->GetEntryString(0x0008,0x103e) << "] "  
67                 << " : " << l->size() << " files" << std::endl;
68       l = s->GetNextSingleSerieUIDFileSet();
69    } 
70     std::cout << " ----------------------------------------End Recap"
71              << std::endl;
72
73    int nbFiles;
74    // For all the Single SerieUID Files Sets of the GDCM_NAME_SPACE::Serie
75    l = s->GetFirstSingleSerieUIDFileSet();
76    while (l)
77    { 
78       nbFiles = l->size() ;
79       if ( l->size() > 5 ) // Why not ? Just an example, for testing
80       {
81          std::cout << "Sort list : " << nbFiles << " long" << std::endl;
82          s->OrderFileList(l);  // sort the list
83          // Just to show : GetZSpacing from a gdcm::SerieHelper is right  
84          std::cout << "GetZSpacing() of sorted SingleSerieUIDFileSet "
85                    << "from gdcm::SerieHelper: " << s->GetZSpacing() << std::endl;
86          std::cout << " ('-1' means all the files have the same position)" << std::endl;
87          for (std::vector<GDCM_NAME_SPACE::File* >::iterator it =  l->begin();
88                                             it != l->end();
89                                           ++it)
90          {
91           // Just to show : GetZSpacing from a gdcm::File may be different        
92              std::cout << (*it)->GetFileName() << " -->  GetZSpacing() from gdcm::File : " 
93                        << (*it)->GetZSpacing() << std::endl;      
94          }  
95
96          break; // we only deal with the first one ... Why not ?
97       }
98       l = s->GetNextSingleSerieUIDFileSet();
99    } 
100    std::cout << " ------------------Prints all the Single SerieUID File Sets (sorted or not) -----"
101              << std::endl;
102    s->Print(); // Prints all the Single SerieUID File Sets (sorted or not)
103    std::cout << " -------------------------------------------- Finish printing"
104              << std::endl;
105      
106    s->Delete();
107
108    return 0;
109 }