]> Creatis software - gdcm.git/blob - Example/exXCoherentFileSet.cxx
Commit *very first* version of an example for using the splitting of a 'single
[gdcm.git] / Example / exXCoherentFileSet.cxx
1 /*=========================================================================
2                                                                                 
3   Program:   gdcm
4   Module:    $RCSfile: exXCoherentFileSet.cxx,v $
5   Language:  C++
6   Date:      $Date: 2005/10/25 15:57:20 $
7   Version:   $Revision: 1.1 $
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    s = new gdcm::SerieHelper();
39    s->SetLoadMode(gdcm::LD_ALL);     // Load everything for each File
40    //s->AddRestriction(tagKey, valueToCheck); // Keep only files where
41                                               // restriction is true
42    s->SetDirectory(dirName, true); // true : recursive exploration
43
44    std::cout << " ---------------------------------------- "
45              << "'Single UID' Filesets found in :["
46              << dirName << "]" << std::endl;
47
48    s->Print();
49    std::cout << " ------------------------------------- Result after splitting"
50              << std::endl;
51
52    int nbFiles;
53    std::string fileName;
54    // For all the Single SerieUID Files Sets of the gdcm::Serie
55    gdcm::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 << "Split the 'Single SerieUID' FileSet :[" 
62                    << s->GetCurrentSerieUIDFileSetUID()
63            << "]  " << nbFiles << " long" << std::endl;
64          std::cout << "-----------------------------------" << std::endl;  
65          gdcm::XCoherentFileSetmap xcm = s->SplitOnOrientation(l);
66          //gdcm::XCoherentFileSetmap xcm = s->SplitOnPosition(l);
67  
68          for (gdcm::XCoherentFileSetmap::iterator i = xcm.begin();
69                                                   i != xcm.end();
70                                                 ++i)
71          {
72             std::cout << "Orientation : [" << (*i).first << "]" << std::endl;
73     
74            // Nowadays OrderFileList() causes trouble, since some files
75            // (MIP views) don't have 'Position', now considered as mandatory
76            // Commented out for the moment. 
77            //s->OrderFileList((*i).second);  // sort the XCoherent Fileset
78     
79             for (std::vector<gdcm::File* >::iterator it =  ((*i).second)->begin();
80                                                      it != ((*i).second)->end();
81                                                    ++it)
82             {
83                fileName = (*it)->GetFileName();
84                std::cout << "    " << fileName << std::endl;
85             } 
86             std::cout << std::endl;   
87          }
88       }
89       l = s->GetNextSingleSerieUIDFileSet();
90    } 
91   
92    delete s;
93
94    return 0;
95 }