X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=blobdiff_plain;f=Example%2FAnonymizeDicomDir.cxx;h=27aa994462240bd9bc0f81d777ad31a5e2fb867f;hb=5933681dcd56380dd0f7a1477fc1fb3246be8809;hp=1c86608cd4f5d22b11861ab5b73318c1994d6fd9;hpb=1d9e55eaf7f1a4fdabb89d17fed3708dd908135f;p=gdcm.git diff --git a/Example/AnonymizeDicomDir.cxx b/Example/AnonymizeDicomDir.cxx index 1c86608c..27aa9944 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/03/09 19:15:04 $ - Version: $Revision: 1.1 $ + Date: $Date: 2007/05/23 14:18:04 $ + Version: $Revision: 1.11 $ Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de l'Image). All rights reserved. See Doc/License.txt or @@ -22,22 +22,28 @@ #include "gdcmSQItem.h" #include "gdcmSeqEntry.h" -#include "gdcmValEntry.h" +#include "gdcmDataEntry.h" #include "gdcmDocument.h" #include "gdcmFile.h" +#include "gdcmArgMgr.h" + #include -void AnoNoLoad(gdcm::SQItem *s, std::fstream *fp, +/** + * \brief AnonymizeDicomDir + */ + +void AnoNoLoad(GDCM_NAME_SPACE::SQItem *s, std::fstream *fp, uint16_t group, uint16_t elem, std::string val); -void AnoNoLoad(gdcm::SQItem *s, std::fstream *fp, +void AnoNoLoad(GDCM_NAME_SPACE::SQItem *s, std::fstream *fp, uint16_t group, uint16_t elem, std::string val) { - gdcm::DocEntry *d; + GDCM_NAME_SPACE::DocEntry *d; uint32_t offset; uint32_t lgth; uint32_t valLgth = 0; @@ -49,7 +55,7 @@ void AnoNoLoad(gdcm::SQItem *s, std::fstream *fp, if ( d == NULL) return; - if ( ! dynamic_cast(d) ) + if ( ! dynamic_cast(d) ) return; offset = d->GetOffset(); @@ -64,82 +70,99 @@ void AnoNoLoad(gdcm::SQItem *s, std::fstream *fp, fp->write( v.c_str(), lgth ); } + int main(int argc, char *argv[]) -{ - gdcm::File *f1; - - gdcm::Debug::DebugOn(); - std::cout << "------------------------------------------------" << std::endl; - std::cout << "Anonymize a gdcm-readable DICOMDIR " << std::endl; - std::cout << "even some Objects are not yet taken into account" << std::endl; - std::cout << "Warning : the DICOMDIR is overwritten" << std::endl; - std::cout << " : to preserve file integrity " - << " think unto using a copy .. " << std::endl; +{ + + START_USAGE(usage) + " \n AnonymizeDicomDir :\n ", + " Anonymize a gdcm-readable DICOMDIR ", + " even when some 'Objects' are not yet taken into account ", + " Warning : the DICOMDIR is overwritten ", + " usage: AnonymizeDicomDir filein=dicomDirName [debug] ", + " debug : developper wants to run the program in 'debug mode' ", + FINISH_USAGE + + // ----- Initialize Arguments Manager ------ + GDCM_NAME_SPACE::ArgMgr *am = new GDCM_NAME_SPACE::ArgMgr(argc, argv); + + if (argc == 1 || am->ArgMgrDefined("usage")) + { + am->ArgMgrUsage(usage); // Display 'usage' + delete am; + return 0; + } - if( argc < 3 ) - { - std::cerr << "Usage " << argv[0] << " DICOMDIR to anonymize " - << std::endl; - return 1; - } - - std::string fileName = argv[1]; + char *fileName = am->ArgMgrWantString("filein",usage); -// ============================================================ -// Read the input DICOMDIR -// ============================================================ + // 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 --- - std::cout << argv[1] << std::endl; - f1 = new gdcm::File( fileName ); - if (!f1->IsReadable()) { + // Read the input DICOMDIR + GDCM_NAME_SPACE::File *f; + f = GDCM_NAME_SPACE::File::New( ); + f->SetLoadMode(0); + f->SetFileName( fileName ); + bool res = f->Load(); + if ( !res ) + { std::cerr << "Sorry, " << fileName <<" not a gdcm-readable " << "file" <GetDocEntry(0x0004, 0x1220); + // Look for Directory record sequence + GDCM_NAME_SPACE::DocEntry *e = f->GetDocEntry(0x0004, 0x1220); if ( !e ) { std::cout << "No Directory Record Sequence (0004,1220) found" <Delete(); + return 0; } - gdcm::SeqEntry *s = dynamic_cast(e); + GDCM_NAME_SPACE::SeqEntry *s = dynamic_cast(e); if ( !s ) { std::cout << "Element (0004,1220) is not a Sequence ?!?" <Delete(); return 0; } // Open the file LTTG (aka ALAP) - std::fstream *fp = new std::fstream(fileName.c_str(), + std::fstream *fp = new std::fstream(fileName, std::ios::in | std::ios::out | std::ios::binary); - gdcm::DocEntry *d; + GDCM_NAME_SPACE::DocEntry *d; std::string v; int patientNumber = 0; std::ostringstream oss; - gdcm::SQItem *tmpSI=s->GetFirstSQItem(); // For all the SQItems + GDCM_NAME_SPACE::SQItem *tmpSI=s->GetFirstSQItem(); // For all the SQItems while(tmpSI) { d = tmpSI->GetDocEntry(0x0004, 0x1430); // Directory Record Type - if ( gdcm::ValEntry* valEntry = dynamic_cast(d) ) + if ( GDCM_NAME_SPACE::DataEntry *dataEntry = + dynamic_cast(d) ) { - v = valEntry->GetValue(); + v = dataEntry->GetString(); } else { - std::cout << "(0004,1430) not a ValEntry ?!?" << std::endl; + std::cout << "(0004,1430) not a DataEntry ?!?" << std::endl; continue; } - if( v != "PATIENT " ) + if( v != "PATIENT " ) // Work only on PATIENT { - continue; // Work only on PATIENT + tmpSI=s->GetNextSQItem(); + continue; } oss << patientNumber; @@ -155,7 +178,7 @@ int main(int argc, char *argv[]) // Telephone AnoNoLoad(tmpSI, fp, 0x0010, 0x2154, oss.str()); - // Aware use will add more Entries he wants to rubb out here + // Aware use will add here more Entries if he wants to rubb them out oss << ""; patientNumber++; @@ -165,9 +188,9 @@ int main(int argc, char *argv[]) // Close the file ASAP fp->close(); + delete fp; - - delete f1; + f->Delete(); return 0; }