X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=blobdiff_plain;f=Example%2FexSerieHelper.cxx;h=5305fe4dbbe1c4287e4f5b63c72b8dbac784772e;hb=7e3167602a9c730d1c515527b0fc47fa2168e47d;hp=9922486ef7580a21109f1ad12d170c1db1aa95bb;hpb=49f2072fc0ceb8934abd40a2febd1ef650535370;p=gdcm.git diff --git a/Example/exSerieHelper.cxx b/Example/exSerieHelper.cxx index 9922486e..5305fe4d 100644 --- a/Example/exSerieHelper.cxx +++ b/Example/exSerieHelper.cxx @@ -3,8 +3,8 @@ Program: gdcm Module: $RCSfile: exSerieHelper.cxx,v $ Language: C++ - Date: $Date: 2007/06/22 11:01:57 $ - Version: $Revision: 1.13 $ + Date: $Date: 2007/10/30 14:55:20 $ + Version: $Revision: 1.17 $ Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de l'Image). All rights reserved. See Doc/License.txt or @@ -20,29 +20,76 @@ #include "gdcmDirList.h" // for FileList #include "gdcmDebug.h" #include +#include "gdcmArgMgr.h" int main(int argc, char *argv[]) -{ - GDCM_NAME_SPACE::SerieHelper *s; +{ + START_USAGE(usage) + "\n exSerieHelper :\n ", + "Example on how to use the methodes of gdcm::SerieHelper ", + "usage: exSerieHelper {dirin=inputDirectoryName} ", + " [ { [noshadowseq] | [noshadow][noseq] } ] [debug] ", + " ", + " dirin : user wants to analyze *all* the files ", + " within the directory ", + " noshadowseq: user doesn't want to load Private Sequences ", + " noshadow : user doesn't want to load Private groups (odd number) ", + " noseq : user doesn't want to load Sequences ", + " verbose : user wants to run the program in 'verbose mode' ", + " warning : user wants to run the program in 'warning mode' ", + " debug : developper wants to run the program in 'debug mode' ", + FINISH_USAGE + + // ----- Initialize Arguments Manager ------ - std::string dirName; - if (argc > 1) - dirName = argv[1]; - else + GDCM_NAME_SPACE::ArgMgr *am = new GDCM_NAME_SPACE::ArgMgr(argc, argv); + + if (am->ArgMgrDefined("usage") || argc == 1) { - dirName = GDCM_DATA_ROOT; + am->ArgMgrUsage(usage); // Display 'usage' + delete am; + return 0; } - if (argc > 2) + if (am->ArgMgrDefined("debug")) GDCM_NAME_SPACE::Debug::DebugOn(); + + if (am->ArgMgrDefined("warning")) + GDCM_NAME_SPACE::Debug::WarningOn(); + + bool verbose = ( 0 != am->ArgMgrDefined("verbose") ); + + int loadMode = GDCM_NAME_SPACE::LD_ALL; + if ( am->ArgMgrDefined("noshadowseq") ) + loadMode |= GDCM_NAME_SPACE::LD_NOSHADOWSEQ; + else + { + if ( am->ArgMgrDefined("noshadow") ) + loadMode |= GDCM_NAME_SPACE::LD_NOSHADOW; + if ( am->ArgMgrDefined("noseq") ) + loadMode |= GDCM_NAME_SPACE::LD_NOSEQ; + } + + const char *dirName = am->ArgMgrGetString("dirin"); + if (dirName == 0) + { + std::cout <SetLoadMode(GDCM_NAME_SPACE::LD_ALL); // Load everything for each File //GDCM_NAME_SPACE::TagKey t(0x0020,0x0013); @@ -50,17 +97,18 @@ int main(int argc, char *argv[]) // restriction is true s->SetDirectory(dirName, true); // true : recursive exploration - std::cout << " ---------------------------------------- Finish parsing :[" - << dirName << "]" << std::endl; - - s->Print(); - std::cout << " ---------------------------------------- Finish printing (1)" - << std::endl; + if (verbose) { + std::cout << " ---------------------------------------- Finish parsing :[" + << dirName << "]" << std::endl; + s->Print(); + std::cout << " ---------------------------------------- Finish printing (1)" + << std::endl; + } GDCM_NAME_SPACE::FileList::const_iterator it; GDCM_NAME_SPACE::FileList *l; - std::cout << " ---------------------------------------- Recap" + std::cout << std::endl << " ---------------------------------------- Recap" << std::endl; l = s->GetFirstSingleSerieUIDFileSet(); while (l) @@ -72,7 +120,7 @@ int main(int argc, char *argv[]) l = s->GetNextSingleSerieUIDFileSet(); } std::cout << " ----------------------------------------End Recap" - << std::endl; + << std::endl << std::endl; int nbFiles; double zspacing = 0.; @@ -81,33 +129,40 @@ int main(int argc, char *argv[]) while (l) { nbFiles = l->size() ; - if ( l->size() > 5 ) // Why not ? Just an example, for testing + if ( nbFiles > 5 ) // Why not ? Just an example, for testing { - std::cout << "Sort list : " << nbFiles << " long" << std::endl; - + std::cout << "List to sort : " << nbFiles << " long" << std::endl; //--------------------------------------------------------- s->OrderFileList(l); // sort the list (and compute ZSpacing !) //--------------------------------------------------------- - + std::cout << "List after sorting : " << l->size() << " long" << std::endl; + zspacing = s->GetZSpacing(); // Just to show : GetZSpacing from a GDCM_NAME_SPACE::SerieHelper is right std::cout << "GetZSpacing() of sorted SingleSerieUIDFileSet " << "from GDCM_NAME_SPACE::SerieHelper: " << zspacing << std::endl; std::cout << " ('-1' means all the files have the same position)" << std::endl; - for (std::vector::iterator it2 = l->begin(); + + // Check the vector content + int fileCount = 0; + // for (std::vector::iterator it2 = l->begin(); + for (GDCM_NAME_SPACE::FileList::const_iterator it2 = l->begin(); it2 != l->end(); ++it2) { // Just to show : GetZSpacing from a GDCM_NAME_SPACE::File may be different std::cout << (*it2)->GetFileName() << " --> GetZSpacing() from GDCM_NAME_SPACE::File : " - << (*it2)->GetZSpacing() << std::endl; - } + << (*it2)->GetZSpacing() << std::endl; + fileCount++; + } + std::cout << "Iterate trough vector, nb of files : " << fileCount << std::endl; - break; // we only deal with the first one ... Why not ? + //break; // we only deal with the first one ... Why not ? } l = s->GetNextSingleSerieUIDFileSet(); } - std::cout << " ------------------Prints all the Single SerieUID File Sets (sorted or not) -----" + std::cout << std::endl + << " ------------------Prints all the Single SerieUID File Sets (sorted or not) -----" << std::endl; s->Print(); // Prints all the Single SerieUID File Sets (sorted or not) std::cout << " -------------------------------------------- Finish printing"