From ac2e8ecc8319069451f1fe5a4413915d56f9cbdc Mon Sep 17 00:00:00 2001 From: jpr Date: Thu, 21 Jul 2005 04:55:50 +0000 Subject: [PATCH] Unify user interface --- Example/Anonymize.cxx | 18 +++++++-------- Example/AnonymizeDicomDir.cxx | 13 ++++++++--- Example/AnonymizeNoLoad.cxx | 36 ++++++++++++++++++------------ Example/CMakeLists.txt | 1 + Example/MakeDicomDir.cxx | 25 +++++++++++---------- Example/PrintDicomDir.cxx | 6 ++--- Example/ReWrite.cxx | 41 ++++++++++++++++++++--------------- 7 files changed, 83 insertions(+), 57 deletions(-) diff --git a/Example/Anonymize.cxx b/Example/Anonymize.cxx index defdaf00..69a7d8a1 100644 --- a/Example/Anonymize.cxx +++ b/Example/Anonymize.cxx @@ -3,8 +3,8 @@ Program: gdcm Module: $RCSfile: Anonymize.cxx,v $ Language: C++ - Date: $Date: 2005/07/07 17:31:53 $ - Version: $Revision: 1.2 $ + Date: $Date: 2005/07/21 04:55:50 $ + 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 @@ -27,18 +27,18 @@ int main(int argc, char *argv[]) { START_USAGE(usage) - " \n Anonymize :\n", - " Anonymize a full gdcm-readable Dicom image", - " Warning : probably segfaults if pixels are not gdcm readable.", - " Use exAnonymizeNoLoad instead.", - " usage: Anonymize filein=inputFileName fileout=anonymizedFileName[debug] ", - " debug : user wants to run the program in 'debug mode' ", + " \n Anonymize :\n ", + " Anonymize a full gdcm-readable Dicom image ", + " Warning : probably segfaults if pixels are not gdcm readable. ", + " Use exAnonymizeNoLoad instead. ", + " usage: Anonymize filein=inputFileName fileout=anonymizedFileName[debug] ", + " debug : user wants to run the program in 'debug mode' ", FINISH_USAGE // ----- Initialize Arguments Manager ------ gdcm::ArgMgr *am = new gdcm::ArgMgr(argc, argv); - if (am->ArgMgrDefined("usage")) + if (argc == 1 || am->ArgMgrDefined("usage")) { am->ArgMgrUsage(usage); // Display 'usage' delete am; diff --git a/Example/AnonymizeDicomDir.cxx b/Example/AnonymizeDicomDir.cxx index 47915d81..388a92e0 100644 --- a/Example/AnonymizeDicomDir.cxx +++ b/Example/AnonymizeDicomDir.cxx @@ -3,8 +3,8 @@ Program: gdcm Module: $RCSfile: AnonymizeDicomDir.cxx,v $ Language: C++ - Date: $Date: 2005/07/12 14:56:48 $ - Version: $Revision: 1.6 $ + Date: $Date: 2005/07/21 04:55:50 $ + Version: $Revision: 1.7 $ Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de l'Image). All rights reserved. See Doc/License.txt or @@ -86,7 +86,7 @@ int main(int argc, char *argv[]) // ----- Initialize Arguments Manager ------ gdcm::ArgMgr *am = new gdcm::ArgMgr(argc, argv); - if (am->ArgMgrDefined("usage")) + if (argc == 1 || am->ArgMgrDefined("usage")) { am->ArgMgrUsage(usage); // Display 'usage' delete am; @@ -95,6 +95,13 @@ int main(int argc, char *argv[]) char *fileName = am->ArgMgrWantString("filein",usage); + // if unused Param we give up + if ( am->ArgMgrPrintUnusedLabels() ) + { + am->ArgMgrUsage(usage); + delete am; + return 0; + } delete am; // --- we don't need Argument Manager any longer --- diff --git a/Example/AnonymizeNoLoad.cxx b/Example/AnonymizeNoLoad.cxx index 4f3cfcdb..84fe1119 100644 --- a/Example/AnonymizeNoLoad.cxx +++ b/Example/AnonymizeNoLoad.cxx @@ -3,8 +3,8 @@ Program: gdcm Module: $RCSfile: AnonymizeNoLoad.cxx,v $ Language: C++ - Date: $Date: 2005/07/20 14:48:15 $ - Version: $Revision: 1.7 $ + Date: $Date: 2005/07/21 04:55:50 $ + Version: $Revision: 1.8 $ Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de l'Image). All rights reserved. See Doc/License.txt or @@ -38,8 +38,8 @@ int main(int argc, char *argv[]) " inputFileName : Name of the (single) file user wants to anonymize ", " inputDirectoryName : user wants to anonymize *all* the files ", " within the (single Patient!) directory ", - " listOfPrivateElementsToRubOut : group,elem (in hexa) of private ", - " Elements to rub out ", + " listOfPrivateElementsToRubOut : group-elem,g2-e2,... (in hexa) ", + " of private Elements to rub out ", " 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 ", @@ -50,7 +50,7 @@ int main(int argc, char *argv[]) gdcm::ArgMgr *am = new gdcm::ArgMgr(argc, argv); - if (am->ArgMgrDefined("usage")) + if (am->ArgMgrDefined("usage") || argc == 1) { am->ArgMgrUsage(usage); // Display 'usage' delete am; @@ -65,11 +65,12 @@ int main(int argc, char *argv[]) if ( (fileName == 0 && dirName == 0) || - (fileName != 0 && dirName != 0) ) + (fileName != 0 && dirName != 0) ) { std::cout <ArgMgrGetXInt16Enum("rubout", &rubOutNb); + + /* if unused Param we give up */ + if ( am->ArgMgrPrintUnusedLabels() ) + { + am->ArgMgrUsage(usage); + delete am; + return 0; + } - std::cout << " ---------------------------- rubOutNb " << rubOutNb - << std::endl; delete am; // ------ we don't need Arguments Manager any longer ------ - if ( fileName != 0 ) // ====== Deal with a single file ====== { @@ -165,9 +171,8 @@ int main(int argc, char *argv[]) f->AnonymizeNoLoad(); - // No need to write the File : modif were done on disc ! - // File was overwritten ... - + // No need to write the file : modif were done on disc ! + // ( The Dicom file is overwritten ) std::cout <<"End AnonymizeNoLoad" << std::endl; // @@ -222,6 +227,8 @@ int main(int argc, char *argv[]) // Telephone f->AddAnonymizeElement(0x0010, 0x2154, "3615" ); + // deal with user defined Elements set + for (int ri=0; riAddAnonymizeElement((uint32_t)elemsToRubOut[2*ri], @@ -230,6 +237,7 @@ int main(int argc, char *argv[]) std::cout <<"Let's AnonymizeNoLoad " << it->c_str() << std::endl; // The gdcm::File remains untouched in memory + // The Dicom file is overwritten on disc f->AnonymizeNoLoad(); diff --git a/Example/CMakeLists.txt b/Example/CMakeLists.txt index 814cdb46..49a7c63a 100644 --- a/Example/CMakeLists.txt +++ b/Example/CMakeLists.txt @@ -16,6 +16,7 @@ SET(EXAMPLE_SOURCES exGC exImageLighten exOverlaysACR + exSerieHelper #the following are utilities PrintDicomDir diff --git a/Example/MakeDicomDir.cxx b/Example/MakeDicomDir.cxx index 597020a8..9f87f5df 100644 --- a/Example/MakeDicomDir.cxx +++ b/Example/MakeDicomDir.cxx @@ -3,8 +3,8 @@ Program: gdcm Module: $RCSfile: MakeDicomDir.cxx,v $ Language: C++ - Date: $Date: 2005/07/08 10:15:04 $ - Version: $Revision: 1.9 $ + Date: $Date: 2005/07/21 04:55:50 $ + Version: $Revision: 1.10 $ Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de l'Image). All rights reserved. See Doc/License.txt or @@ -48,14 +48,17 @@ void EndMethod(void *toto) { int main(int argc, char *argv[]) { START_USAGE(usage) - " \n MakeDicomDir :\n", - " Explores recursively the given directory, makes the relevant DICOMDIR", - " and writes it as 'NewDICOMDIR'", - " usage: MakeDicomDir dirname=rootDirectoryName [noshadowseq][noshadow][noseq] [debug] ", - " 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 ", - " debug : user wants to run the program in 'debug mode' ", + " \n MakeDicomDir :\n ", + " Explores recursively the given directory, makes the relevant DICOMDIR ", + " and writes it as 'NewDICOMDIR' ", + " ", + " usage: MakeDicomDir dirname=rootDirectoryName ", + " [noshadowseq][noshadow][noseq] [debug] ", + " ", + " 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 ", + " debug : user wants to run the program in 'debug mode' ", FINISH_USAGE // ----- Initialize Arguments Manager ------ @@ -108,7 +111,7 @@ int main(int argc, char *argv[]) dcmdir->SetLoadMode(loadMode); dcmdir->SetDirectoryName(dirName); -dcmdir->SetParseDir(true); + //dcmdir->SetParseDir(true); dcmdir->Load(); // ----- Check the result diff --git a/Example/PrintDicomDir.cxx b/Example/PrintDicomDir.cxx index ecb488e9..7025c18d 100644 --- a/Example/PrintDicomDir.cxx +++ b/Example/PrintDicomDir.cxx @@ -3,8 +3,8 @@ Program: gdcm Module: $RCSfile: PrintDicomDir.cxx,v $ Language: C++ - Date: $Date: 2005/07/11 13:54:51 $ - Version: $Revision: 1.27 $ + Date: $Date: 2005/07/21 04:55:50 $ + Version: $Revision: 1.28 $ Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de l'Image). All rights reserved. See Doc/License.txt or @@ -46,7 +46,7 @@ int main(int argc, char* argv[]) // Initialize Arguments Manager gdcm::ArgMgr *am= new gdcm::ArgMgr(argc, argv); - if (argc == 1) + if (argc == 1 || am->ArgMgrDefined("usage") ) { am->ArgMgrUsage(usage); // Display 'usage' delete am; diff --git a/Example/ReWrite.cxx b/Example/ReWrite.cxx index 97f7d3f1..37d15073 100644 --- a/Example/ReWrite.cxx +++ b/Example/ReWrite.cxx @@ -3,8 +3,8 @@ Program: gdcm Module: $RCSfile: ReWrite.cxx,v $ Language: C++ - Date: $Date: 2005/07/07 17:31:53 $ - Version: $Revision: 1.8 $ + Date: $Date: 2005/07/21 04:55:50 $ + Version: $Revision: 1.9 $ Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de l'Image). All rights reserved. See Doc/License.txt or @@ -29,10 +29,12 @@ int main(int argc, char *argv[]) " \n ReWrite :\n", " Re write a full gdcm-readable Dicom image ", " (usefull when the file header is not very straight). ", - "", + " ", " usage: ReWrite filein=inputFileName fileout=anonymizedFileName ", " [mode=write mode] [noshadow] [noseq][debug] ", + " ", " mode = a (ACR), x (Explicit VR Dicom), r (RAW : only pixels) ", + " 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 ", " rgb : user wants to tranform LUT (if any) to RGB pixels ", @@ -42,7 +44,7 @@ int main(int argc, char *argv[]) // ----- Initialize Arguments Manager ------ gdcm::ArgMgr *am = new gdcm::ArgMgr(argc, argv); - if (am->ArgMgrDefined("usage")) + if (argc == 1 || am->ArgMgrDefined("usage")) { am->ArgMgrUsage(usage); // Display 'usage' delete am; @@ -51,6 +53,7 @@ int main(int argc, char *argv[]) char *fileName = am->ArgMgrWantString("filein",usage); if ( fileName == NULL ) { + std::cout << "'filein= ...' is mandatory" << std::endl; delete am; return 0; } @@ -58,21 +61,23 @@ int main(int argc, char *argv[]) char *outputFileName = am->ArgMgrWantString("fileout",usage); if ( outputFileName == NULL ) { + std::cout << "'fileout= ...' is mandatory" << std::endl; delete am; return 0; } char *mode = am->ArgMgrGetString("mode",(char *)"X"); - int loadMode; - if ( am->ArgMgrDefined("noshadow") && am->ArgMgrDefined("noseq") ) - loadMode = NO_SEQ | NO_SHADOW; - else if ( am->ArgMgrDefined("noshadow") ) - loadMode = NO_SHADOW; - else if ( am->ArgMgrDefined("noseq") ) - loadMode = NO_SEQ; - else - loadMode = 0; + int loadMode = 0x00000000; + if ( am->ArgMgrDefined("noshadowseq") ) + loadMode |= NO_SHADOWSEQ; + else + { + if ( am->ArgMgrDefined("noshadow") ) + loadMode |= NO_SHADOW; + if ( am->ArgMgrDefined("noseq") ) + loadMode |= NO_SEQ; + } bool rgb = ( 0 != am->ArgMgrDefined("RGB") ); @@ -149,9 +154,11 @@ int main(int argc, char *argv[]) << std::endl; int numberOfScalarComponents=f->GetNumberOfScalarComponents(); - std::cout << "NumberOfScalarComponents " << numberOfScalarComponents <GetTransferSyntaxName(); - std::cout << " TransferSyntaxName= [" << transferSyntaxName << "]" << std::endl; + std::cout << " TransferSyntaxName= [" << transferSyntaxName << "]" + << std::endl; switch (mode[0]) { @@ -164,8 +171,8 @@ int main(int argc, char *argv[]) fh->WriteAcr(outputFileName); break; - case 'D' : // Not documented in the 'usage', because the method is known to be bugged. - case 'd' : + case 'D' : // Not documented in the 'usage', because the method + case 'd' : // is known to be bugged. // Writting a DICOM Implicit VR file // from a full gdcm readable File -- 2.45.1