From 6fc9a59ce58ba4bb71d63a57e6b1ef2c3c87292a Mon Sep 17 00:00:00 2001 From: jpr Date: Thu, 28 May 2009 15:44:34 +0000 Subject: [PATCH] minor improvements --- Example/CMakeLists.txt | 1 + Example/PrintFile.cxx | 17 ++-- Example/SplitIntoDirectories.cxx | 88 +++++++++---------- Example/SplitIntoXCoherentDirectories.cxx | 68 +++++++------- ...IntoXCoherentDirectoriesIgnoreSerieUID.cxx | 67 +++++++------- Example/exExtractOverlaysDCM.cxx | 6 +- Example/exPresentationState.cxx | 23 +++-- Example/exSerieHelper.cxx | 8 +- Example/exXCoherentFileSet.cxx | 71 ++++++++------- 9 files changed, 192 insertions(+), 157 deletions(-) diff --git a/Example/CMakeLists.txt b/Example/CMakeLists.txt index df209e4c..d98b401d 100644 --- a/Example/CMakeLists.txt +++ b/Example/CMakeLists.txt @@ -9,6 +9,7 @@ SET(EXAMPLE_SOURCES #Txt2Mat #exDicomRTStructSetFile #exExtractCSA + exPresentationState exReadPapyrus exReadWriteFile diff --git a/Example/PrintFile.cxx b/Example/PrintFile.cxx index a89c6260..23f64835 100644 --- a/Example/PrintFile.cxx +++ b/Example/PrintFile.cxx @@ -3,8 +3,8 @@ Program: gdcm Module: $RCSfile: PrintFile.cxx,v $ Language: C++ - Date: $Date: 2009/03/04 08:57:40 $ - Version: $Revision: 1.92 $ + Date: $Date: 2009/05/28 15:44:34 $ + Version: $Revision: 1.93 $ Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de l'Image). All rights reserved. See Doc/License.txt or @@ -347,13 +347,18 @@ if (!noex) std::cout << " SwapCode= " << f->GetSwapCode() << std::endl; std::cout << " ------" << std::endl; + std::cout << "\n\n" << std::endl; std::cout << "X spacing " << f->GetXSpacing() << std::endl; std::cout << "Y spacing " << f->GetYSpacing() << std::endl; std::cout << "Z spacing " << f->GetZSpacing() << std::endl; - + //------------------------------ + + + + // Let's get and print some usefull fields about 'Orientation' // ------------------------------------------------------------ @@ -407,9 +412,11 @@ if (!noex) << strImagePositionPatientRET << "]" << std::endl; float iop[6]; - /*bool riop = */f->GetImageOrientationPatient(iop); + //bool riop = + f->GetImageOrientationPatient(iop); float ipp[3]; - /*bool ripp = */f->GetImagePositionPatient(ipp); + //bool ripp = + f->GetImagePositionPatient(ipp); std::cout << "Image Position (0x0020,0x0032|0x0030) : " << ipp[0] << " , " << ipp[1] << " , "<< ipp[2] diff --git a/Example/SplitIntoDirectories.cxx b/Example/SplitIntoDirectories.cxx index 07e7b58e..abcfbe75 100755 --- a/Example/SplitIntoDirectories.cxx +++ b/Example/SplitIntoDirectories.cxx @@ -3,8 +3,8 @@ Program: gdcm Module: $RCSfile: SplitIntoDirectories.cxx,v $ Language: C++ - Date: $Date: 2007/10/30 11:37:16 $ - Version: $Revision: 1.4 $ + Date: $Date: 2009/05/28 15:44:34 $ + Version: $Revision: 1.5 $ Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de l'Image). All rights reserved. See Doc/License.txt or @@ -29,16 +29,16 @@ #include /** - * \brief + * \brief * - explores recursively the given directory * - keeps the requested series * - orders the gdcm-readable found Files * according to their Patient/Study/Serie/Image characteristics - */ + */ typedef std::map SortedFiles; -int main(int argc, char *argv[]) +int main(int argc, char *argv[]) { START_USAGE(usage) " \n SplitIntoDirectories :\n ", @@ -46,7 +46,7 @@ int main(int argc, char *argv[]) " - keeps the requested series / drops the unrequested series ", " - orders the gdcm-readable found Files according to their ", " (0x0010, 0x0010) Patient's Name ", - " (0x0020, 0x000d) Study Instance UID ", + " (0x0020, 0x000d) Study Instance UID ", " (0x0020, 0x000e) Series Instance UID ", " - fills a tree-like structure of directories as : ", " - Patient ", @@ -98,7 +98,7 @@ int main(int argc, char *argv[]) std::cout << "... inside " << argv[0] << std::endl; // ----- Initialize Arguments Manager ------ - + GDCM_NAME_SPACE::ArgMgr *am = new GDCM_NAME_SPACE::ArgMgr(argc, argv); if (argc == 1 || am->ArgMgrDefined("usage")) @@ -108,16 +108,16 @@ int main(int argc, char *argv[]) return 0; } - const char *dirNamein; - dirNamein = am->ArgMgrGetString("dirin","."); + const char *dirNamein; + dirNamein = am->ArgMgrGetString("dirin","."); const char *dirNameout; - dirNameout = am->ArgMgrGetString("dirout","."); + dirNameout = am->ArgMgrGetString("dirout","."); 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; @@ -131,30 +131,30 @@ int main(int argc, char *argv[]) bool verbose = ( 0 != am->ArgMgrDefined("verbose") ); bool listonly = ( 0 != am->ArgMgrDefined("listonly") ); bool seriedescr = ( 0 != am->ArgMgrDefined("seriedescr") ); - + int nbSeriesToKeep; int *seriesToKeep = am->ArgMgrGetListOfInt("keep", &nbSeriesToKeep); int nbSeriesToDrop; int *seriesToDrop = am->ArgMgrGetListOfInt("drop", &nbSeriesToDrop); - + if ( nbSeriesToKeep!=0 && nbSeriesToDrop!=0) { std::cout << "KEEP and DROP are mutually exclusive !" << std::endl; delete am; - return 0; + return 0; } - bool hasSkel = ( 0 != am->ArgMgrDefined("hasSkel") ); + bool hasSkel = ( 0 != am->ArgMgrDefined("hasSkel") ); const char *skel; if (hasSkel) - skel = am->ArgMgrGetString("skel"); - - + skel = am->ArgMgrGetString("skel"); + + const char *input = am->ArgMgrGetString("input","DCM"); // if unused Param we give up if ( am->ArgMgrPrintUnusedLabels() ) - { + { am->ArgMgrUsage(usage); delete am; return 0; @@ -179,7 +179,7 @@ int main(int argc, char *argv[]) } std::string systemCommand; - + std::cout << "Check for output directory :[" << dirNameout << "]." <Load(); - if (!f->IsReadable()) + if (!f->Document::IsReadable()) { if (verbose) std::cout << "File : [" << *it << "] not gdcm-readable -> skipped !" << std::endl; - continue; + continue; } if (verbose) std::cout << "Loaded!\n"; @@ -326,13 +325,13 @@ int main(int argc, char *argv[]) // drop all unrequested Series bool drop = false; if (nbSeriesToDrop != 0) - { + { strSeriesNumber = f->GetEntryString(0x0020, 0x0011 ); seriesNumber = atoi( strSeriesNumber.c_str() ); for (j=0;jArgMgrGetString("dirin"); if (dirName == 0) { @@ -96,13 +96,13 @@ int main(int argc, char *argv[]) bool write = ( 0 != am->ArgMgrDefined("write") ); bool verbose = ( 0 != am->ArgMgrDefined("verbose") ); bool tag = ( 0 != am->ArgMgrDefined("tag") ); - + if( copy && write ) { std::cout << "COPY and WRITE are mutually exclusive" << std::endl; delete am; - return 0; - } + return 0; + } if( (tag && (pos || ori)) || (pos && (tag || ori)) || (ori && (tag || pos)) ) { @@ -143,10 +143,13 @@ int main(int argc, char *argv[]) delete am; // ------ we don't need Arguments Manager any longer ------ - + GDCM_NAME_SPACE::SerieHelper *s; s = GDCM_NAME_SPACE::SerieHelper::New(); - + + s->SetLoadMode(GDCM_NAME_SPACE::LD_ALL); // Load everything for each File + s->SetDirectory(dirName, true); // true : recursive exploration + GDCM_NAME_SPACE::File *f; GDCM_NAME_SPACE::DirList dirlist(dirName, true); // recursive exploration @@ -163,7 +166,7 @@ int main(int argc, char *argv[]) if (write) { loadMode = GDCM_NAME_SPACE::LD_ALL; // load any DataElement - maxSize = 0x7fff; // load any length + maxSize = 0x7fff; // load any length } else { loadMode = GDCM_NAME_SPACE::LD_NOSEQ | GDCM_NAME_SPACE::LD_NOSHADOW ; maxSize = 0x0100; @@ -217,7 +220,13 @@ int main(int argc, char *argv[]) // For all the Single SerieUID Files Sets of the GDCM_NAME_SPACE::Serie - //GDCM_NAME_SPACE::FileList *l = s->GetFirstSingleSerieUIDFileSet();//===> Ignore 'Serie UID" + // GDCM_NAME_SPACE::FileList *l = s->GetFirstSingleSerieUIDFileSet(); + + l = s->GetFirstSingleSerieUIDFileSet(); + if (l == NULL) { + std::cout << "No Serie found ?!?" << std::endl; + exit (0); + } GDCM_NAME_SPACE::XCoherentFileSetmap xcm; @@ -229,7 +238,7 @@ int main(int argc, char *argv[]) std::string lastFilename; std::string rep("_"); int controlCount = 0; - + // 'Study Instance UID' // The user is allowed to create his own Study, // keeping the same 'Study Instance UID' for various images @@ -243,16 +252,19 @@ int main(int argc, char *argv[]) strStudyUID = studyUID; } -// while (l) // for each 'Single SerieUID FileSet' //===> Ignore 'Serie UID" -// { + while (l) // for each 'Single SerieUID FileSet' //===> Ignore 'Serie UID" + { + currentSerieWriteDir = ""; nbFiles = l->size() ; if ( l->size() > 2 ) // ignore a Directory with less than 2 images. // Why not ? Just an example, for testing! { // Just not to make too many modif in the code - serieUID = "SingleSerie"; //s->GetCurrentSerieUIDFileSetUID(); + //serieUID = "SingleSerie"; // s->GetCurrentSerieUIDFileSetUID(); + serieUID = s->GetCurrentSerieUIDFileSetUID(); + GDCM_NAME_SPACE::Util::ReplaceSpecChar(serieUID, rep); - + // --- for write if (write || copy) { @@ -278,17 +290,14 @@ int main(int argc, char *argv[]) << serieUID << "] " << nbFiles << " long" << std::endl; std::cout << "-----------------------------------" << std::endl; - -GDCM_NAME_SPACE::Debug::DebugOn(); - if (ori) xcm = s->SplitOnOrientation(l); else if (pos) xcm = s->SplitOnPosition(l); else if (groupelem != 0) { - - std:: cout << GDCM_NAME_SPACE::Global::GetDicts()->GetDefaultPubDict()->GetEntry(groupelem[0],groupelem[1])->GetName() << std::endl; + // Crashes if DataElement not found + //std:: cout << GDCM_NAME_SPACE::Global::GetDicts()->GetDefaultPubDict()->GetEntry(groupelem[0],groupelem[1])->GetName() << std::endl; xcm = s->SplitOnTagValue(l, groupelem[0],groupelem[1] ); } @@ -301,7 +310,7 @@ GDCM_NAME_SPACE::Debug::DebugOn(); { xCoherentName = (*i).first; if (verbose) - std::cout << "xCoherentName = " << xCoherentName << std::endl; + std::cout << "==========================================xCoherentName = " << xCoherentName << std::endl; GDCM_NAME_SPACE::Util::ReplaceSpecChar(xCoherentName, rep); // --- for write if (write || copy) @@ -334,11 +343,11 @@ GDCM_NAME_SPACE::Debug::DebugOn(); // (eg:MIP views) don't have 'Position', now considered as mandatory // --> Activated on user demand. - if (sort) { + if (sort) { s->OrderFileList((*i).second); // sort the XCoherent Fileset std::cout << "ZSpacing for the file set " << s->GetZSpacing() << std::endl; - } + } std::string strSerieUID = GDCM_NAME_SPACE::Util::CreateUniqueUID(); @@ -348,11 +357,9 @@ GDCM_NAME_SPACE::Debug::DebugOn(); { controlCount ++; fileName = (*it2)->GetFileName(); - std::cout << " " << fileName << std::endl; - // --- for write lastFilename = GDCM_NAME_SPACE::Util::GetName( fileName ); - filenameout = xCoherentWriteDir + GDCM_NAME_SPACE::GDCM_FILESEPARATOR+ lastFilename; + filenameout = xCoherentWriteDir + GDCM_NAME_SPACE::GDCM_FILESEPARATOR+ lastFilename; if (write) { fh = GDCM_NAME_SPACE::FileHelper::New( (*it2) ); @@ -361,7 +368,7 @@ GDCM_NAME_SPACE::Debug::DebugOn(); unsigned int dataSize = fh->GetImageDataRawSize(); uint8_t *imageData = fh->GetImageDataRaw();// somewhat important : Loads the Pixels in memory ! if (!imageData) - std::cout << "fail to read [" << (*it2)->GetFileName() << std::endl; + std::cout << "fail to read [" << (*it2)->GetFileName() << std::endl; fh->SetWriteTypeToDcmExplVR(); fh->SetContentType(GDCM_NAME_SPACE::UNMODIFIED_PIXELS_IMAGE); if (!fh->Write(filenameout)) @@ -379,10 +386,11 @@ GDCM_NAME_SPACE::Debug::DebugOn(); if (verbose) std::cout << "3 " << systemCommand << std::endl; } - std::cout << std::endl; } + std::cout << std::endl; } - // l = s->GetNextSingleSerieUIDFileSet(); //===> Ignore 'Serie UID" + l = s->GetNextSingleSerieUIDFileSet(); + } if ( controlCount == 0 ) std::cout << "No suitable file was found!" << std::endl; diff --git a/Example/SplitIntoXCoherentDirectoriesIgnoreSerieUID.cxx b/Example/SplitIntoXCoherentDirectoriesIgnoreSerieUID.cxx index 5b5a2263..bec07d82 100755 --- a/Example/SplitIntoXCoherentDirectoriesIgnoreSerieUID.cxx +++ b/Example/SplitIntoXCoherentDirectoriesIgnoreSerieUID.cxx @@ -3,8 +3,8 @@ Program: gdcm Module: $RCSfile: SplitIntoXCoherentDirectoriesIgnoreSerieUID.cxx,v $ Language: C++ - Date: $Date: 2007/10/01 09:56:42 $ - Version: $Revision: 1.1 $ + Date: $Date: 2009/05/28 15:44:34 $ + Version: $Revision: 1.2 $ Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de l'Image). All rights reserved. See Doc/License.txt or @@ -34,7 +34,7 @@ int main(int argc, char *argv[]) "usage: SplitIntoCoherentFileSetIgnoreSerieUID{dirin=inputDirectoryName} ", " dirout=outputDirectoryName ", " { tag=group-elem | pos | ori } [sort] ", - " [{ write | copy }] ", + " [{ write | copy }] ", " [ { [noshadowseq] | [noshadow][noseq] } ] [debug] ", " [studyUID = ] ", " dirin : user wants to analyze *all* the files ", @@ -89,10 +89,18 @@ int main(int argc, char *argv[]) bool pos = ( 0 != am->ArgMgrDefined("pos") ); bool ori = ( 0 != am->ArgMgrDefined("ori") ); bool sort = ( 0 != am->ArgMgrDefined("sort") ); + bool copy = ( 0 != am->ArgMgrDefined("copy") ); bool write = ( 0 != am->ArgMgrDefined("write") ); bool verbose = ( 0 != am->ArgMgrDefined("verbose") ); bool tag = ( 0 != am->ArgMgrDefined("tag") ); + if( copy && write ) + { + std::cout << "COPY and WRITE are mutually exclusive" << std::endl; + delete am; + return 0; + } + if( (tag && (pos || ori)) || (pos && (tag || ori)) || (ori && (tag || pos)) ) { std::cout << " POS, ORI and TAG are mutually exclusive" << std::endl; @@ -133,7 +141,6 @@ int main(int argc, char *argv[]) delete am; // ------ we don't need Arguments Manager any longer ------ - GDCM_NAME_SPACE::SerieHelper *s; s = GDCM_NAME_SPACE::SerieHelper::New(); @@ -155,14 +162,14 @@ int main(int argc, char *argv[]) f->SetMaxSizeLoadEntry(0x7fff); // load any length f->SetFileName( *it ); f->Load(); - l->push_back(f); + l->push_back(f); } /* ===========================================================================================*/ 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; @@ -201,26 +207,26 @@ int main(int argc, char *argv[]) // For all the Single SerieUID Files Sets of the GDCM_NAME_SPACE::Serie - //GDCM_NAME_SPACE::FileList *l = s->GetFirstSingleSerieUIDFileSet();//===> Ignore 'Serie UID" + // GDCM_NAME_SPACE::FileList *l = s->GetFirstSingleSerieUIDFileSet();//===> Ignore 'Serie UID" GDCM_NAME_SPACE::XCoherentFileSetmap xcm; std::string serieUID; std::string currentSerieWriteDir = ""; std::string xCoherentWriteDir = ""; - std::string xCoherentName = ""; + std::string xCoherentName = ""; std::string serieDirectory; std::string lastFilename; std::string rep("_"); int controlCount = 0; - + // 'Study Instance UID' // The user is allowed to create his own Study, // keeping the same 'Study Instance UID' for various images // The user may add images to a 'Manufacturer Study', // adding new Series to an already existing Study std::string strStudyUID; - if ( !userDefinedStudy) + if ( !userDefinedStudy ) strStudyUID = GDCM_NAME_SPACE::Util::CreateUniqueUID(); else strStudyUID = studyUID; @@ -233,9 +239,10 @@ int main(int argc, char *argv[]) // Why not ? Just an example, for testing! { // Just not to make too many modif in the code - serieUID = "aaaa"; //s->GetCurrentSerieUIDFileSetUID(); + //serieUID = "SingleSerie"; // s->GetCurrentSerieUIDFileSetUID(); + serieUID = s->GetCurrentSerieUIDFileSetUID(); GDCM_NAME_SPACE::Util::ReplaceSpecChar(serieUID, rep); - + // --- for write if (write) { @@ -267,19 +274,19 @@ int main(int argc, char *argv[]) else if (pos) xcm = s->SplitOnPosition(l); else if (groupelem != 0) { - + std:: cout << GDCM_NAME_SPACE::Global::GetDicts()->GetDefaultPubDict()->GetEntry(groupelem[0],groupelem[1])->GetName() << std::endl; xcm = s->SplitOnTagValue(l, groupelem[0],groupelem[1] ); } - + GDCM_NAME_SPACE::FileHelper *fh; - + 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; GDCM_NAME_SPACE::Util::ReplaceSpecChar(xCoherentName, rep); @@ -313,7 +320,7 @@ int main(int argc, char *argv[]) // OrderFileList() causes trouble, since some files // (eg:MIP views) don't have 'Position', now considered as mandatory // --> Activated on user demand. - + if (sort) { s->OrderFileList((*i).second); // sort the XCoherent Fileset std::cout << "ZSpacing for the file set " << s->GetZSpacing() @@ -321,7 +328,7 @@ int main(int argc, char *argv[]) } std::string strSerieUID = GDCM_NAME_SPACE::Util::CreateUniqueUID(); - + for (GDCM_NAME_SPACE::FileList::iterator it2 = ((*i).second)->begin(); it2 != ((*i).second)->end(); ++it2) @@ -333,32 +340,32 @@ int main(int argc, char *argv[]) // --- for write if (write) { - fh = GDCM_NAME_SPACE::FileHelper::New( (*it2) ); + fh = GDCM_NAME_SPACE::FileHelper::New( (*it2) ); fh->SetKeepOverlays( true ); fh->InsertEntryString(strSerieUID,0x0020,0x000e,"UI"); unsigned int dataSize = fh->GetImageDataRawSize(); uint8_t *imageData = fh->GetImageDataRaw();// somewhat important : Loads the Pixels in memory ! if (!imageData) - std::cout << "fail to read [" << (*it2)->GetFileName() << std::endl; + std::cout << "fail to read [" << (*it2)->GetFileName() << std::endl; lastFilename = GDCM_NAME_SPACE::Util::GetName( fileName ); filenameout = xCoherentWriteDir + GDCM_NAME_SPACE::GDCM_FILESEPARATOR+ lastFilename; //systemCommand = "cp " + fileName + " " + filenameout; //system( systemCommand.c_str()); - + fh->SetWriteTypeToDcmExplVR(); fh->SetContentType(GDCM_NAME_SPACE::UNMODIFIED_PIXELS_IMAGE); if (!fh->Write(filenameout)) { std::cout << "Fail to write :[" << filenameout << "]" << std::endl; - } + } if (verbose) std::cout << "3 " << systemCommand << std::endl; fh->Delete(); - } - // --- end for write + } + // --- end for write } - std::cout << std::endl; + std::cout << std::endl; } } // l = s->GetNextSingleSerieUIDFileSet(); //===> Ignore 'Serie UID" @@ -366,7 +373,7 @@ int main(int argc, char *argv[]) if ( controlCount == 0 ) std::cout << "No suitable file was found!" << std::endl; - + s->Delete(); /*===============================================================================================*/ return 0; diff --git a/Example/exExtractOverlaysDCM.cxx b/Example/exExtractOverlaysDCM.cxx index 306bb8c2..da5d5212 100755 --- a/Example/exExtractOverlaysDCM.cxx +++ b/Example/exExtractOverlaysDCM.cxx @@ -3,8 +3,8 @@ Program: gdcm Module: $RCSfile: exExtractOverlaysDCM.cxx,v $ Language: C++ - Date: $Date: 2007/10/30 09:15:58 $ - Version: $Revision: 1.5 $ + Date: $Date: 2009/05/28 15:44:34 $ + Version: $Revision: 1.6 $ Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de l'Image). All rights reserved. See Doc/License.txt or @@ -236,7 +236,7 @@ str << fileName << ".ovly." << tmp.str() << ".dcm" << std::ends; } // end on loop on 60xx - if (f) + if (fh) fh->Delete(); if (fileToBuild) fileToBuild->Delete(); diff --git a/Example/exPresentationState.cxx b/Example/exPresentationState.cxx index 49aab734..23f41749 100644 --- a/Example/exPresentationState.cxx +++ b/Example/exPresentationState.cxx @@ -4,8 +4,8 @@ Program: gdcm Module: $RCSfile: exPresentationState.cxx,v $ Language: C++ - Date: $Date: 2009/05/25 14:29:16 $ - Version: $Revision: 1.2 $ + Date: $Date: 2009/05/28 15:44:34 $ + Version: $Revision: 1.3 $ Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de l'Image). All rights reserved. See Doc/License.txt or @@ -54,6 +54,10 @@ int main(int argc, char *argv[]) " noseq : user doesn't want to load Sequences ", " verbose : developper wants to run the program in 'verbose mode' ", " debug : developper wants to run the program in 'debug mode' ", + " ", + " you can use it as : ", + " for i in `ls PS*`; do exPresentationState PSFile=$i; done ", + " just to see ... ", FINISH_USAGE // ----- Initialize Arguments Manager ------ @@ -133,14 +137,19 @@ int main(int argc, char *argv[]) //displaySeekResult(se, 0x0070, 0x0001); if (!se) { - std::cout << "Hopeless : " << std::hex << 0x0070 << "|" << 0x0001 << std::dec << " doesn't exist..." <GetFirstSQItem(); // Get the first 'ROI' + if (currentItem == NULL) + { + std::cout << "======== Deal With NOTHING! (Sequence 0070|0001 [Graphic Annotation Sequence] has NO item ?!?)" << std::endl; + } int i =0; while (currentItem != NULL) { @@ -170,6 +179,8 @@ int main(int argc, char *argv[]) f->Delete(); fPS->Delete(); + + std::cout << "\n\n" <GetFileName() << " --> GetZSpacing() from GDCM_NAME_SPACE::File : " + std::cout << (*it2)->GetFileName() << " --> Get{X/Y/Z}Spacing() from GDCM_NAME_SPACE::File : " + << (*it2)->GetXSpacing() << " " + << (*it2)->GetYSpacing() << " " << (*it2)->GetZSpacing() << std::endl; fileCount++; } diff --git a/Example/exXCoherentFileSet.cxx b/Example/exXCoherentFileSet.cxx index 42199db9..8f22110c 100755 --- a/Example/exXCoherentFileSet.cxx +++ b/Example/exXCoherentFileSet.cxx @@ -1,15 +1,15 @@ /*========================================================================= - + Program: gdcm Module: $RCSfile: exXCoherentFileSet.cxx,v $ Language: C++ - Date: $Date: 2007/10/30 14:55:20 $ - Version: $Revision: 1.15 $ + Date: $Date: 2009/05/28 15:44:34 $ + Version: $Revision: 1.16 $ Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de l'Image). All rights reserved. See Doc/License.txt or http://www.creatis.insa-lyon.fr/Public/Gdcm/License.html for details. - + This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the above copyright notices for more information. @@ -24,7 +24,6 @@ #include "gdcmArgMgr.h" int main(int argc, char *argv[]) { - START_USAGE(usage) "\n exXCoherentFileSet :\n ", "Shows the various 'XCoherent' Filesets within a directory ", @@ -55,7 +54,7 @@ int main(int argc, char *argv[]) FINISH_USAGE // ----- Initialize Arguments Manager ------ - + GDCM_NAME_SPACE::ArgMgr *am = new GDCM_NAME_SPACE::ArgMgr(argc, argv); if (am->ArgMgrDefined("usage") || argc == 1) @@ -67,7 +66,7 @@ int main(int argc, char *argv[]) if (am->ArgMgrDefined("debug")) GDCM_NAME_SPACE::Debug::DebugOn(); - + int loadMode = GDCM_NAME_SPACE::LD_ALL; if ( am->ArgMgrDefined("noshadowseq") ) loadMode |= GDCM_NAME_SPACE::LD_NOSHADOWSEQ; @@ -85,16 +84,16 @@ int main(int argc, char *argv[]) std::cout <ArgMgrUsage(usage); // Display 'usage' delete am; return 0; } - const char *dirNameout; + const char *dirNameout; dirNameout = am->ArgMgrGetString("dirout","."); - bool pos = ( 0 != am->ArgMgrDefined("pos") ); - bool ori = ( 0 != am->ArgMgrDefined("ori") ); + bool pos = ( 0 != am->ArgMgrDefined("pos") ); + bool ori = ( 0 != am->ArgMgrDefined("ori") ); bool sort = ( 0 != am->ArgMgrDefined("sort") ); bool write = ( 0 != am->ArgMgrDefined("write") ); bool verbose = ( 0 != am->ArgMgrDefined("verbose") ); @@ -104,15 +103,15 @@ int main(int argc, char *argv[]) { std::cout << " POS, ORI and TAG are mutually exclusive" << std::endl; delete am; - return 0; + return 0; } if( (!tag && !pos && !ori)) { std::cout << " One of POS, ORI and TAG is mandatory!" << std::endl; delete am; - return 0; - } + return 0; + } int nb; uint16_t *groupelem; if (tag) @@ -124,16 +123,16 @@ int main(int argc, char *argv[]) delete am; return 0; } - } - + } + /* if unused Param we give up */ if ( am->ArgMgrPrintUnusedLabels() ) { am->ArgMgrUsage(usage); delete am; return 0; - } - + } + delete am; // ------ we don't need Arguments Manager any longer ------ GDCM_NAME_SPACE::SerieHelper *s; @@ -144,7 +143,7 @@ int main(int argc, char *argv[]) //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' @@ -212,7 +211,7 @@ int main(int argc, char *argv[]) std::string lastFilename; std::string rep("_"); int controlCount = 0; - + while (l) // for each 'Single SerieUID FileSet' { nbFiles = l->size() ; @@ -221,7 +220,7 @@ int main(int argc, char *argv[]) { serieUID = s->GetCurrentSerieUIDFileSetUID(); GDCM_NAME_SPACE::Util::ReplaceSpecChar(serieUID, rep); - + // --- for write if (write) { @@ -229,25 +228,25 @@ int main(int argc, char *argv[]) unsigned int lg = strlen(dirNameout)-1; if ( dirNameout[lg] != '/' && dirNameout[lg] != '\\') currentSerieWriteDir = currentSerieWriteDir + GDCM_NAME_SPACE::GDCM_FILESEPARATOR; - + currentSerieWriteDir = currentSerieWriteDir + serieUID; if (verbose) std::cout << "[" << currentSerieWriteDir<< "]" << std::endl; // if ( ! GDCM_NAME_SPACE::DirList::IsDirectory(currentSerieWriteDir) ) - { + { systemCommand = "mkdir " + currentSerieWriteDir; system( systemCommand.c_str()); if (verbose) std::cout << "1 " <SplitOnOrientation(l); else if (pos) @@ -266,18 +265,18 @@ int main(int argc, char *argv[]) GDCM_NAME_SPACE::Util::ReplaceSpecChar(serieUID, rep); // --- for write if (write) - { + { xCoherentWriteDir = currentSerieWriteDir + GDCM_NAME_SPACE::GDCM_FILESEPARATOR+ xCoherentName; // if ( ! GDCM_NAME_SPACE::DirList::IsDirectory(xCoherentWriteDir) ) - { + { systemCommand = "mkdir " + xCoherentWriteDir; system( systemCommand.c_str()); if (verbose) - std::cout << systemCommand << std::endl; + std::cout << systemCommand << std::endl; } } // --- end for write - + if (ori) std::cout << "Orientation : "; else if (pos) @@ -286,10 +285,10 @@ int main(int argc, char *argv[]) std::cout << "Tag (" << std::hex << groupelem[0] << "|" << groupelem[1] << ") value : "; std::cout << "[" << (*i).first << "]" << std::endl; - + if (verbose) std::cout << "xCoherentName [" << xCoherentName << "]" << std::endl; - + // Within a 'just to see' program, // OrderFileList() causes trouble, since some files // (eg:MIP views) don't have 'Position', now considered as mandatory @@ -299,7 +298,7 @@ int main(int argc, char *argv[]) s->OrderFileList((*i).second); // sort the XCoherent Fileset std::cout << "ZSpacing for the file set " << s->GetZSpacing() << std::endl; - } + } for (GDCM_NAME_SPACE::FileList::iterator it = ((*i).second)->begin(); it != ((*i).second)->end(); @@ -308,7 +307,7 @@ int main(int argc, char *argv[]) controlCount ++; fileName = (*it)->GetFileName(); std::cout << " " << fileName << std::endl; - + // --- for write if (write) { @@ -319,9 +318,9 @@ int main(int argc, char *argv[]) if (verbose) std::cout << "3 " << systemCommand << std::endl; } - // --- end for write + // --- end for write } - std::cout << std::endl; + std::cout << std::endl; } } l = s->GetNextSingleSerieUIDFileSet(); -- 2.45.0