X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=blobdiff_plain;f=Example%2FAnonymizeDicomDir.cxx;h=02190c34f61bd63ab2c715f2d5e1533b1a2a6291;hb=0f14224ae88b397db01e3de8edca0ab671f4ffa4;hp=f4ab3fe3dba629b8805e1892851bdec3dba31df8;hpb=998aa4a03f2f7e299226e84fbc7c0c02143f863e;p=gdcm.git diff --git a/Example/AnonymizeDicomDir.cxx b/Example/AnonymizeDicomDir.cxx index f4ab3fe3..02190c34 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/06/07 14:41:47 $ - Version: $Revision: 1.3 $ + Date: $Date: 2005/10/18 08:35:43 $ + 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 @@ -22,7 +22,7 @@ #include "gdcmSQItem.h" #include "gdcmSeqEntry.h" -#include "gdcmValEntry.h" +#include "gdcmDataEntry.h" #include "gdcmDocument.h" #include "gdcmFile.h" @@ -55,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(); @@ -70,6 +70,7 @@ void AnoNoLoad(gdcm::SQItem *s, std::fstream *fp, fp->write( v.c_str(), lgth ); } + int main(int argc, char *argv[]) { @@ -85,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; @@ -94,35 +95,43 @@ int main(int argc, char *argv[]) char *fileName = am->ArgMgrWantString("filein",usage); - delete am; // we don't need Argument Manager any longer + // 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 --- -// ============================================================ -// Read the input DICOMDIR -// ============================================================ - gdcm::File *f1 = new gdcm::File( fileName ); - if (!f1->IsReadable()) { + // Read the input DICOMDIR + gdcm::File *f; + f = new gdcm::File( ); + 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::DocEntry *e = f->GetDocEntry(0x0004, 0x1220); if ( !e ) { std::cout << "No Directory Record Sequence (0004,1220) found" <(e); if ( !s ) { std::cout << "Element (0004,1220) is not a Sequence ?!?" <GetDocEntry(0x0004, 0x1430); // Directory Record Type - if ( gdcm::ValEntry* valEntry = dynamic_cast(d) ) + if ( gdcm::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; @@ -167,7 +177,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++; @@ -178,9 +188,7 @@ int main(int argc, char *argv[]) fp->close(); - delete fp; - delete e; - delete f1; + delete f; return 0; }