]> Creatis software - gdcm.git/blob - Example/exSerieHelper.cxx
Some more output to show the difference between
[gdcm.git] / Example / exSerieHelper.cxx
1 /*=========================================================================
2                                                                                 
3   Program:   gdcm
4   Module:    $RCSfile: exSerieHelper.cxx,v $
5   Language:  C++
6   Date:      $Date: 2007/05/30 15:13:25 $
7   Version:   $Revision: 1.9 $
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_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    //GDCM_NAME_SPACE::TagKey t(0x0020,0x0013);
44    //s->AddRestriction(t, "340", GDCM_NAME_SPACE::GDCM_LESS); // Keep only files where
45                                               // restriction is true
46    s->SetDirectory(dirName, true); // true : recursive exploration
47
48    std::cout << " ---------------------------------------- Finish parsing :["
49              << dirName << "]" << std::endl;
50
51    s->Print();
52    std::cout << " ---------------------------------------- Finish printing (1)"
53              << std::endl;
54
55    int nbFiles;
56    // For all the Single SerieUID Files Sets of the GDCM_NAME_SPACE::Serie
57    GDCM_NAME_SPACE::FileList *l = s->GetFirstSingleSerieUIDFileSet();
58    while (l)
59    { 
60       nbFiles = l->size() ;
61       if ( l->size() > 3 ) // Why not ? Just an example, for testing
62       {
63          std::cout << "Sort list : " << nbFiles << " long" << std::endl;
64          s->OrderFileList(l);  // sort the list
65       }
66       l = s->GetNextSingleSerieUIDFileSet();
67    } 
68    std::cout << " -------------------------------------------- Finish sorting"
69              << std::endl;
70    s->Print(); // Prints all the Single SerieUID File Sets (sorted or not)
71    std::cout << " -------------------------------------------- Finish printing"
72              << std::endl;
73   
74   // Just to show : GetZSpacing from a gdcm::SerieHelper is right  
75     std::cout << "GetZSpacing() from gdcm::SerieHelper: "    << s->GetZSpacing()    << std::endl;
76
77    // Only for the first Coherent File List 
78    // ( Why not ? Just an example, for testing )
79    // Display all the file names
80
81    std::string fileName; 
82    l = s->GetFirstSingleSerieUIDFileSet();
83    for (std::vector<GDCM_NAME_SPACE::File* >::iterator it =  l->begin();
84                                             it != l->end();
85                                           ++it)
86    {
87       fileName = (*it)->GetFileName();
88       std::cout << fileName << std::endl;
89  // Just to show : GetZSpacing from a gdcm::File is wrong!        
90       std::cout << "       GetZSpacing() from gdcm::File : " << (*it)->GetZSpacing() << std::endl;      
91    } 
92      
93
94    s->Delete();
95
96    return 0;
97 }