1 /*=========================================================================
4 Module: $RCSfile: exSerieHelper.cxx,v $
6 Date: $Date: 2007/10/30 14:55:20 $
7 Version: $Revision: 1.17 $
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 methodes 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'
85 std::cout << "Dir Name :[" << dirName << "]" << std::endl;
87 // Sometimes using only SerieHelper is not enought !
88 // See also exXcoherentFileSet
92 GDCM_NAME_SPACE::SerieHelper *s;
93 s = GDCM_NAME_SPACE::SerieHelper::New();
94 s->SetLoadMode(GDCM_NAME_SPACE::LD_ALL); // Load everything for each File
95 //GDCM_NAME_SPACE::TagKey t(0x0020,0x0013);
96 //s->AddRestriction(t, "340", GDCM_NAME_SPACE::GDCM_LESS); // Keep only files where
97 // restriction is true
98 s->SetDirectory(dirName, true); // true : recursive exploration
101 std::cout << " ---------------------------------------- Finish parsing :["
102 << dirName << "]" << std::endl;
105 std::cout << " ---------------------------------------- Finish printing (1)"
109 GDCM_NAME_SPACE::FileList::const_iterator it;
110 GDCM_NAME_SPACE::FileList *l;
111 std::cout << std::endl << " ---------------------------------------- Recap"
113 l = s->GetFirstSingleSerieUIDFileSet();
117 std::cout << "SerieUID [" << (*it)->GetEntryString(0x0020,0x000e) <<"] Serie Description ["
118 << (*it)->GetEntryString(0x0008,0x103e) << "] "
119 << " : " << l->size() << " files" << std::endl;
120 l = s->GetNextSingleSerieUIDFileSet();
122 std::cout << " ----------------------------------------End Recap"
123 << std::endl << std::endl;
126 double zspacing = 0.;
127 // For all the Single SerieUID Files Sets of the GDCM_NAME_SPACE::Serie
128 l = s->GetFirstSingleSerieUIDFileSet();
131 nbFiles = l->size() ;
132 if ( nbFiles > 5 ) // Why not ? Just an example, for testing
134 std::cout << "List to sort : " << nbFiles << " long" << std::endl;
135 //---------------------------------------------------------
136 s->OrderFileList(l); // sort the list (and compute ZSpacing !)
137 //---------------------------------------------------------
138 std::cout << "List after sorting : " << l->size() << " long" << std::endl;
140 zspacing = s->GetZSpacing();
141 // Just to show : GetZSpacing from a GDCM_NAME_SPACE::SerieHelper is right
142 std::cout << "GetZSpacing() of sorted SingleSerieUIDFileSet "
143 << "from GDCM_NAME_SPACE::SerieHelper: " << zspacing << std::endl;
144 std::cout << " ('-1' means all the files have the same position)" << std::endl;
146 // Check the vector content
148 // for (std::vector<GDCM_NAME_SPACE::File* >::iterator it2 = l->begin();
149 for (GDCM_NAME_SPACE::FileList::const_iterator it2 = l->begin();
153 // Just to show : GetZSpacing from a GDCM_NAME_SPACE::File may be different
154 std::cout << (*it2)->GetFileName() << " --> GetZSpacing() from GDCM_NAME_SPACE::File : "
155 << (*it2)->GetZSpacing() << std::endl;
158 std::cout << "Iterate trough vector, nb of files : " << fileCount << std::endl;
160 //break; // we only deal with the first one ... Why not ?
162 l = s->GetNextSingleSerieUIDFileSet();
164 std::cout << std::endl
165 << " ------------------Prints all the Single SerieUID File Sets (sorted or not) -----"
167 s->Print(); // Prints all the Single SerieUID File Sets (sorted or not)
168 std::cout << " -------------------------------------------- Finish printing"