1 /*=========================================================================
4 Module: $RCSfile: exSerieHelper.cxx,v $
6 Date: $Date: 2010/09/01 14:41:48 $
7 Version: $Revision: 1.19 $
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.
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.
17 =========================================================================*/
18 #include "gdcmSerieHelper.h"
20 #include "gdcmDirList.h" // for FileList
21 #include "gdcmDebug.h"
23 #include "gdcmArgMgr.h"
25 int main(int argc, char *argv[])
28 "\n exSerieHelper :\n ",
29 "Example on how to use the methods of gdcm::SerieHelper ",
30 "usage: exSerieHelper {dirin=inputDirectoryName} ",
31 " [ { [noshadowseq] | [noshadow][noseq] } ] [debug] ",
33 " dirin : user wants to analyze *all* the files ",
34 " within the directory ",
35 " noshadowseq: user doesn't want to load Private Sequences ",
36 " noshadow : user doesn't want to load Private groups (odd number) ",
37 " noseq : user doesn't want to load Sequences ",
38 " verbose : user wants to run the program in 'verbose mode' ",
39 " warning : user wants to run the program in 'warning mode' ",
40 " debug : developper wants to run the program in 'debug mode' ",
43 // ----- Initialize Arguments Manager ------
45 GDCM_NAME_SPACE::ArgMgr *am = new GDCM_NAME_SPACE::ArgMgr(argc, argv);
47 if (am->ArgMgrDefined("usage") || argc == 1)
49 am->ArgMgrUsage(usage); // Display 'usage'
54 if (am->ArgMgrDefined("debug"))
55 GDCM_NAME_SPACE::Debug::DebugOn();
57 if (am->ArgMgrDefined("warning"))
58 GDCM_NAME_SPACE::Debug::WarningOn();
60 bool verbose = ( 0 != am->ArgMgrDefined("verbose") );
62 int loadMode = GDCM_NAME_SPACE::LD_ALL;
63 if ( am->ArgMgrDefined("noshadowseq") )
64 loadMode |= GDCM_NAME_SPACE::LD_NOSHADOWSEQ;
67 if ( am->ArgMgrDefined("noshadow") )
68 loadMode |= GDCM_NAME_SPACE::LD_NOSHADOW;
69 if ( am->ArgMgrDefined("noseq") )
70 loadMode |= GDCM_NAME_SPACE::LD_NOSEQ;
73 const char *dirName = am->ArgMgrGetString("dirin");
77 << "'dirin=' must be present;"
79 am->ArgMgrUsage(usage); // Display 'usage'
84 std::cout << "Dir Name :[" << dirName << "]" << std::endl;
86 // Sometimes using only SerieHelper is not enought !
87 // See also exXcoherentFileSet
91 GDCM_NAME_SPACE::SerieHelper *s;
92 s = GDCM_NAME_SPACE::SerieHelper::New();
93 s->SetLoadMode(GDCM_NAME_SPACE::LD_ALL); // Load everything for each File
94 //GDCM_NAME_SPACE::TagKey t(0x0020,0x0013);
95 //s->AddRestriction(t, "340", GDCM_NAME_SPACE::GDCM_LESS); // Keep only files where
96 // restriction is true
97 s->SetDirectory(dirName, true); // true : recursive exploration
100 std::cout << " ---------------------------------------- Finish parsing :["
101 << dirName << "]" << std::endl;
104 std::cout << " ---------------------------------------- Finish printing (1)"
108 GDCM_NAME_SPACE::FileList::const_iterator it;
109 GDCM_NAME_SPACE::FileList *l;
110 std::cout << std::endl << " ---------------------------------------- Recap"
112 l = s->GetFirstSingleSerieUIDFileSet();
116 std::cout << "SerieUID [" << (*it)->GetEntryString(0x0020,0x000e) <<"] Serie Description ["
117 << (*it)->GetEntryString(0x0008,0x103e) << "] "
118 << " : " << l->size() << " files" << std::endl;
119 l = s->GetNextSingleSerieUIDFileSet();
121 std::cout << " ----------------------------------------End Recap"
122 << std::endl << std::endl;
125 double zspacing = 0.;
126 // For all the Single SerieUID Files Sets of the GDCM_NAME_SPACE::Serie
127 l = s->GetFirstSingleSerieUIDFileSet();
130 nbFiles = l->size() ;
131 if ( nbFiles > 2 ) // Why not ? Just an example, for testing
133 std::cout << "List to sort : " << nbFiles << " long" << std::endl;
134 //---------------------------------------------------------
135 s->OrderFileList(l); // sort the list (and compute ZSpacing !)
136 //---------------------------------------------------------
137 std::cout << "List after sorting : " << l->size() << " long" << std::endl;
139 zspacing = s->GetZSpacing();
140 // Just to show : GetZSpacing from a GDCM_NAME_SPACE::SerieHelper is right
141 std::cout << "GetZSpacing() of sorted SingleSerieUIDFileSet "
142 << "from GDCM_NAME_SPACE::SerieHelper: " << zspacing << std::endl;
143 std::cout << " ('-1' means all the files have the same position)" << std::endl;
145 // Check the vector content
147 // for (std::vector<GDCM_NAME_SPACE::File* >::iterator it2 = l->begin();
148 for (GDCM_NAME_SPACE::FileList::const_iterator it2 = l->begin();
152 // Just to show : GetZSpacing from a GDCM_NAME_SPACE::File may be different
153 std::cout << (*it2)->GetFileName() << " --> Get{X/Y/Z}Spacing() from GDCM_NAME_SPACE::File : "
154 << (*it2)->GetXSpacing() << " "
155 << (*it2)->GetYSpacing() << " "
156 << (*it2)->GetZSpacing() << std::endl;
159 std::cout << "Iterate trough vector, nb of files : " << fileCount << std::endl;
161 //break; // we only deal with the first one ... Why not ?
163 l = s->GetNextSingleSerieUIDFileSet();
165 std::cout << std::endl
166 << " ------------------Prints all the Single SerieUID File Sets (sorted or not) -----"
168 s->Print(); // Prints all the Single SerieUID File Sets (sorted or not)
169 std::cout << " -------------------------------------------- Finish printing"