X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=blobdiff_plain;f=Example%2FexSerieHelper.cxx;h=c92a7b6f941cb7569d62408f142a389c8aad0c0c;hb=3b1f653b219f72d841e3b52ef2ae20d2c7c91220;hp=41a98abd3e135cce57c3f6ddc11e84d159519435;hpb=c4fa2e74a4ce56a0a8db54e4a70d404bec9fc8dd;p=gdcm.git diff --git a/Example/exSerieHelper.cxx b/Example/exSerieHelper.cxx index 41a98abd..c92a7b6f 100644 --- a/Example/exSerieHelper.cxx +++ b/Example/exSerieHelper.cxx @@ -3,8 +3,8 @@ Program: gdcm Module: $RCSfile: exSerieHelper.cxx,v $ Language: C++ - Date: $Date: 2005/08/30 14:40:28 $ - Version: $Revision: 1.3 $ + Date: $Date: 2007/10/01 09:33:20 $ + Version: $Revision: 1.14 $ Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de l'Image). All rights reserved. See Doc/License.txt or @@ -17,12 +17,13 @@ =========================================================================*/ #include "gdcmSerieHelper.h" #include "gdcmFile.h" +#include "gdcmDirList.h" // for FileList #include "gdcmDebug.h" #include int main(int argc, char *argv[]) { - gdcm::SerieHelper *s; + GDCM_NAME_SPACE::SerieHelper *s; std::string dirName; if (argc > 1) @@ -33,14 +34,19 @@ int main(int argc, char *argv[]) } if (argc > 2) - gdcm::Debug::DebugOn(); + GDCM_NAME_SPACE::Debug::DebugOn(); std::cout << "Dir Name :[" << dirName << "]" << std::endl; + // + // Sometimes using only SerieHelper is not enought ! + // See also exXcoherentFileSet + // - s = new gdcm::SerieHelper(); - s->SetLoadMode(GDCM_LD_ALL); // Load everything for each File - //s->AddRestriction(tagKey, valueToCheck); // Keep only files where + s = GDCM_NAME_SPACE::SerieHelper::New(); + s->SetLoadMode(GDCM_NAME_SPACE::LD_ALL); // Load everything for each File + //GDCM_NAME_SPACE::TagKey t(0x0020,0x0013); + //s->AddRestriction(t, "340", GDCM_NAME_SPACE::GDCM_LESS); // Keep only files where // restriction is true s->SetDirectory(dirName, true); // true : recursive exploration @@ -51,42 +57,63 @@ int main(int argc, char *argv[]) std::cout << " ---------------------------------------- Finish printing (1)" << std::endl; + + GDCM_NAME_SPACE::FileList::const_iterator it; + GDCM_NAME_SPACE::FileList *l; + std::cout << " ---------------------------------------- Recap" + << std::endl; + l = s->GetFirstSingleSerieUIDFileSet(); + while (l) + { + it = l->begin(); + std::cout << "SerieUID [" << (*it)->GetEntryString(0x0020,0x000e) <<"] Serie Description [" + << (*it)->GetEntryString(0x0008,0x103e) << "] " + << " : " << l->size() << " files" << std::endl; + l = s->GetNextSingleSerieUIDFileSet(); + } + std::cout << " ----------------------------------------End Recap" + << std::endl; + int nbFiles; - // For all the Coherent Files lists of the gdcm::Serie - gdcm::FileList *l = s->GetFirstCoherentFileList(); + double zspacing = 0.; + // For all the Single SerieUID Files Sets of the GDCM_NAME_SPACE::Serie + l = s->GetFirstSingleSerieUIDFileSet(); while (l) { nbFiles = l->size() ; - if ( l->size() > 3 ) // Why not ? Just an example, for testing + if ( l->size() > 5 ) // Why not ? Just an example, for testing { - std::cout << "Sort list : " << nbFiles << " long" << std::endl; - s->OrderFileList(l); // sort the list + std::cout << "Sort list : " << nbFiles << " long" << std::endl; + + //--------------------------------------------------------- + s->OrderFileList(l); // sort the list (and compute ZSpacing !) + //--------------------------------------------------------- + + 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(); + 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; + } + + break; // we only deal with the first one ... Why not ? } - l = s->GetNextCoherentFileList(); + l = s->GetNextSingleSerieUIDFileSet(); } - std::cout << " -------------------------------------------- Finish sorting" + std::cout << " ------------------Prints all the Single SerieUID File Sets (sorted or not) -----" << std::endl; - s->Print(); // Prints all the Coherent Files lists (sorted or not) + s->Print(); // Prints all the Single SerieUID File Sets (sorted or not) std::cout << " -------------------------------------------- Finish printing" << std::endl; - - - // Only for the first Coherent File List - // ( Why not ? Just an example, for testing ) - // Display all the file names - - std::string fileName; - l = s->GetFirstCoherentFileList(); - for (std::vector::iterator it = l->begin(); - it != l->end(); - ++it) - { - fileName = (*it)->GetFileName(); - std::cout << fileName << std::endl; - } - - delete s; + s->Delete(); return 0; }