X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=blobdiff_plain;f=Example%2FexXCoherentFileSet.cxx;h=42199db9c0a771632071eefa7ec9f8f1c7f77d65;hb=1e66f7398c38a3d71b480e0297e29636ea6e1c1b;hp=4e60070acbcaec76a84733b149c1b6ae45230aee;hpb=1eba3390e6cf61ea34dae11dfcf7de4e353c97c6;p=gdcm.git diff --git a/Example/exXCoherentFileSet.cxx b/Example/exXCoherentFileSet.cxx index 4e60070a..42199db9 100755 --- a/Example/exXCoherentFileSet.cxx +++ b/Example/exXCoherentFileSet.cxx @@ -3,8 +3,8 @@ Program: gdcm Module: $RCSfile: exXCoherentFileSet.cxx,v $ Language: C++ - Date: $Date: 2007/09/28 14:08:08 $ - Version: $Revision: 1.11 $ + Date: $Date: 2007/10/30 14:55:20 $ + Version: $Revision: 1.15 $ Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de l'Image). All rights reserved. See Doc/License.txt or @@ -21,40 +21,14 @@ #include #include "gdcmDirList.h" #include "gdcmUtil.h" - #include "gdcmArgMgr.h" - -void removeSpecChar(std::string &s); - -void removeSpecChar(std::string &s) { - unsigned int s_size = s.size(); - for(unsigned int i=0; i= '+' && s[i] <= '-') - || (s[i] >= 'a' && s[i] <= 'z') - || (s[i] >= '0' && s[i] <= '9') - || (s[i] >= 'A' && s[i] <= 'Z'))) - { - s.replace(i, 1, "_"); // ImagePositionPatient related stuff will be more human readable - } - } - - // deal with Dicom strings trailing '\0' - if(s[s_size-1] == '_') - s.erase(s_size-1, 1); - -} - int main(int argc, char *argv[]) -{ +{ START_USAGE(usage) "\n exXCoherentFileSet :\n ", "Shows the various 'XCoherent' Filesets within a directory ", - "Optionaly copis the images in a Directories tree ", + "Optionaly copies the images in a Directories tree ", "usage: exXCoherentFileSet {dirin=inputDirectoryName} ", " dirout=outputDirectoryName ", " { tag=group-elem | pos | ori } [sort] [write] ", @@ -76,7 +50,7 @@ int main(int argc, char *argv[]) " 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' ", + " verbose : user wants to run the program in 'verbose mode' ", " debug : developper wants to run the program in 'debug mode' ", FINISH_USAGE @@ -97,7 +71,7 @@ int main(int argc, char *argv[]) int loadMode = GDCM_NAME_SPACE::LD_ALL; if ( am->ArgMgrDefined("noshadowseq") ) loadMode |= GDCM_NAME_SPACE::LD_NOSHADOWSEQ; - else + else { if ( am->ArgMgrDefined("noshadow") ) loadMode |= GDCM_NAME_SPACE::LD_NOSHADOW; @@ -167,17 +141,17 @@ int main(int argc, char *argv[]) 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); + //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 // The Dicom file set is splitted into several 'Single SerieUID Files Sets' // (a 'Single SerieUID Files Set' per SerieUID) // In some cases, it's not enough, since, in some cases // we can find scout view with the same SerieUID - + /* std::cout << " ---------------------------------------- " << "'Single UID' Filesets found in :[" @@ -189,8 +163,8 @@ int main(int argc, char *argv[]) */ std::string systemCommand; - std::string filenameout; - if (write) { + std::string filenameout; + if (write) { if (verbose) std::cout << "Check for output directory :[" << dirNameout << "]." < End of checking supposed-to-be-directory names - + int nbFiles; std::string fileName; - + // For all the Single SerieUID Files Sets of the GDCM_NAME_SPACE::Serie GDCM_NAME_SPACE::FileList *l = s->GetFirstSingleSerieUIDFileSet(); - GDCM_NAME_SPACE::XCoherentFileSetmap xcm; - + std::string serieUID; std::string currentSerieWriteDir = ""; - std::string xCoherentWriteDir = ""; - std::string xCoherentName = ""; + std::string xCoherentWriteDir = ""; + std::string xCoherentName = ""; std::string serieDirectory; std::string lastFilename; - - int controlCount = 0; + std::string rep("_"); + int controlCount = 0; + while (l) // for each 'Single SerieUID FileSet' { nbFiles = l->size() ; @@ -247,14 +220,14 @@ int main(int argc, char *argv[]) // Why not ? Just an example, for testing! { serieUID = s->GetCurrentSerieUIDFileSetUID(); - removeSpecChar(serieUID); + GDCM_NAME_SPACE::Util::ReplaceSpecChar(serieUID, rep); // --- for write if (write) { currentSerieWriteDir = currentSerieWriteDir + dirNameout; - unsigned int l = strlen(dirNameout)-1; - if ( dirNameout[l] != '/' && dirNameout[l] != '\\') + unsigned int lg = strlen(dirNameout)-1; + if ( dirNameout[lg] != '/' && dirNameout[lg] != '\\') currentSerieWriteDir = currentSerieWriteDir + GDCM_NAME_SPACE::GDCM_FILESEPARATOR; currentSerieWriteDir = currentSerieWriteDir + serieUID; @@ -279,17 +252,18 @@ int main(int argc, char *argv[]) xcm = s->SplitOnOrientation(l); else if (pos) xcm = s->SplitOnPosition(l); - else if (groupelem != 0) + else if (groupelem != 0) { xcm = s->SplitOnTagValue(l, groupelem[0],groupelem[1] ); + } for (GDCM_NAME_SPACE::XCoherentFileSetmap::iterator i = xcm.begin(); i != xcm.end(); ++i) { - xCoherentName = (*i).first; + xCoherentName = (*i).first; if (verbose) std::cout << "xCoherentName = " << xCoherentName << std::endl; - removeSpecChar(xCoherentName); + GDCM_NAME_SPACE::Util::ReplaceSpecChar(serieUID, rep); // --- for write if (write) { @@ -299,7 +273,7 @@ int main(int argc, char *argv[]) systemCommand = "mkdir " + xCoherentWriteDir; system( systemCommand.c_str()); if (verbose) - std::cout << "2 " << systemCommand << std::endl; + std::cout << systemCommand << std::endl; } } // --- end for write @@ -320,7 +294,7 @@ int main(int argc, char *argv[]) // OrderFileList() causes trouble, since some files // (eg:MIP views) don't have 'Position', now considered as mandatory // Commented out for the moment. - + if (sort) { s->OrderFileList((*i).second); // sort the XCoherent Fileset std::cout << "ZSpacing for the file set " << s->GetZSpacing() @@ -339,14 +313,14 @@ int main(int argc, char *argv[]) if (write) { lastFilename = GDCM_NAME_SPACE::Util::GetName( fileName ); - filenameout = xCoherentWriteDir + GDCM_NAME_SPACE::GDCM_FILESEPARATOR+ lastFilename; + filenameout = xCoherentWriteDir + GDCM_NAME_SPACE::GDCM_FILESEPARATOR+ lastFilename; systemCommand = "cp " + fileName + " " + filenameout; system( systemCommand.c_str()); if (verbose) std::cout << "3 " << systemCommand << std::endl; - } + } // --- end for write - } + } std::cout << std::endl; } } @@ -355,7 +329,7 @@ int main(int argc, char *argv[]) if ( controlCount == 0 ) std::cout << "No suitable file was found!" << std::endl; - + s->Delete(); return 0;