]> Creatis software - gdcm.git/blob - Testing/TestSerieHelper.cxx
use GDCM_NAME_SPACE:: instead of gdcm::, even in Examples ...
[gdcm.git] / Testing / TestSerieHelper.cxx
1 /*=========================================================================
2                                                                                 
3   Program:   gdcm
4   Module:    $RCSfile: TestSerieHelper.cxx,v $
5   Language:  C++
6   Date:      $Date: 2008/09/15 15:49:21 $
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 "gdcmDebug.h"
21 #include <iostream>
22
23 int TestSerieHelper(int argc, char *argv[])
24 {  
25    GDCM_NAME_SPACE::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_NAME_SPACE::Debug::DebugOn();
37
38   
39    std::cout << "-------------- Dir Name :[" << dirName << "]" << std::endl;
40
41    s = GDCM_NAME_SPACE::SerieHelper::New();
42    s->SetLoadMode(GDCM_NAME_SPACE::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    std::cout << " ---------------------------------------- Finish parsing :["
47              << dirName << "]" << std::endl;
48
49    s->Print();
50    std::cout << " ---------------------------------------- Finish printing (1)"
51              << std::endl;
52
53    int nbFiles;
54    // For all the SingleSerieUID filesets of the GDCM_NAME_SPACE::Serie
55    GDCM_NAME_SPACE::FileList *l = s->GetFirstSingleSerieUIDFileSet();
56    while (l)
57    { 
58       nbFiles = l->size() ;
59       if ( l->size() > 3 ) // Why not ? Just an example, for testing
60       {
61          std::cout << "Sort list : " << nbFiles << " long" << std::endl;
62          s->OrderFileList(l);  // sort the list
63       }
64       l = s->GetNextSingleSerieUIDFileSet();
65    } 
66    std::cout << " -------------------------------------------- Finish sorting"
67              << std::endl;
68    s->Print(); // Prints all the SingleSerieUID filesets (sorted or not)
69    std::cout << " -------------------------------------------- Finish printing"
70              << std::endl;
71
72
73    // Only for the first SingleSerieUID fileset 
74    // ( Why not ? Just an example, for testing )
75    // Display all the file names
76
77    std::string fileName; 
78    l = s->GetFirstSingleSerieUIDFileSet();
79    for (std::vector<GDCM_NAME_SPACE::File* >::iterator it =  l->begin();
80                                             it != l->end();
81                                           ++it)
82    {
83       fileName = (*it)->GetFileName();
84       std::cout << fileName << std::endl;
85       // Remark : vtkGdcmReader users can use this loop to AddFileName(fileName)
86       //          in the right order 
87    } 
88      
89
90    s->Delete();
91
92    return 0;
93 }