]> Creatis software - gdcm.git/blob - Example/exSerieHelper.cxx
* Remove #define and replace then by the call to the corresponding
[gdcm.git] / Example / exSerieHelper.cxx
1 /*=========================================================================
2                                                                                 
3   Program:   gdcm
4   Module:    $RCSfile: exSerieHelper.cxx,v $
5   Language:  C++
6   Date:      $Date: 2005/08/30 15:13:06 $
7   Version:   $Revision: 1.4 $
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 "gdcmDebug.h"
21 #include <iostream>
22
23 int main(int argc, char *argv[])
24 {  
25    gdcm::SerieHelper *s;
26   
27    std::string dirName; 
28    if (argc > 1) 
29       dirName = argv[1];    
30    else 
31    {
32       dirName = GDCM_DATA_ROOT;
33    }
34
35    if (argc > 2)
36       gdcm::Debug::DebugOn();
37
38   
39    std::cout << "Dir Name :[" << dirName << "]" << std::endl;
40
41    s = new gdcm::SerieHelper();
42    s->SetLoadMode(gdcm::LD_ALL);     // Load everything for each File
43    //s->AddRestriction(tagKey, valueToCheck); // Keep only files where
44                                               // restriction is true
45    s->SetDirectory(dirName, true); // true : recursive exploration
46
47    std::cout << " ---------------------------------------- Finish parsing :["
48              << dirName << "]" << std::endl;
49
50    s->Print();
51    std::cout << " ---------------------------------------- Finish printing (1)"
52              << std::endl;
53
54    int nbFiles;
55    // For all the Coherent Files lists of the gdcm::Serie
56    gdcm::FileList *l = s->GetFirstCoherentFileList();
57    while (l)
58    { 
59       nbFiles = l->size() ;
60       if ( l->size() > 3 ) // Why not ? Just an example, for testing
61       {
62          std::cout << "Sort list : " << nbFiles << " long" << std::endl;
63          s->OrderFileList(l);  // sort the list
64       }
65       l = s->GetNextCoherentFileList();
66    } 
67    std::cout << " -------------------------------------------- Finish sorting"
68              << std::endl;
69    s->Print(); // Prints all the Coherent Files lists (sorted or not)
70    std::cout << " -------------------------------------------- Finish printing"
71              << std::endl;
72
73
74    // Only for the first Coherent File List 
75    // ( Why not ? Just an example, for testing )
76    // Display all the file names
77
78    std::string fileName; 
79    l = s->GetFirstCoherentFileList();
80    for (std::vector<gdcm::File* >::iterator it =  l->begin();
81                                             it != l->end();
82                                           ++it)
83    {
84       fileName = (*it)->GetFileName();
85       std::cout << fileName << std::endl;
86    } 
87      
88
89    delete s;
90
91    return 0;
92 }