X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=blobdiff_plain;f=Example%2FAnonymize.cxx;h=908726dc6498eb04a3779a4590e6ad5c93e0b2a6;hb=d37154e4495e1e1c18c44f6cae6ef2ff8a2891cf;hp=defdaf007539dfb5eb97f56c768fa2acf14b6ef2;hpb=4d992954520d43c6f2fb555b7cd721574978c23a;p=gdcm.git diff --git a/Example/Anonymize.cxx b/Example/Anonymize.cxx index defdaf00..908726dc 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: 2007/06/15 13:18:50 $ + Version: $Revision: 1.13 $ Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de l'Image). All rights reserved. See Doc/License.txt or @@ -24,21 +24,26 @@ #include + +/// \todo : AnonymizeDirectory +/// That should split the images : Patient/Study/Serie +/// and keeps coherent the StudyInstanceUID, SeriesInstanceUID +/// (Now, a new one is generated fore each image :-( ) 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 AnonymizeNoLoad 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); + GDCM_NAME_SPACE::ArgMgr *am = new GDCM_NAME_SPACE::ArgMgr(argc, argv); - if (am->ArgMgrDefined("usage")) + if (argc == 1 || am->ArgMgrDefined("usage")) { am->ArgMgrUsage(usage); // Display 'usage' delete am; @@ -58,7 +63,7 @@ int main(int argc, char *argv[]) return 0; } if (am->ArgMgrDefined("debug")) - gdcm::Debug::DebugOn(); + GDCM_NAME_SPACE::Debug::DebugOn(); // if unused Param we give up if ( am->ArgMgrPrintUnusedLabels() ) @@ -74,10 +79,10 @@ int main(int argc, char *argv[]) // Read the input file. // ============================================================ - gdcm::File *f; + GDCM_NAME_SPACE::File *f; - f = new gdcm::File( ); - f->SetLoadMode( 0x00000000 ); + f = GDCM_NAME_SPACE::File::New( ); + f->SetLoadMode( GDCM_NAME_SPACE::LD_ALL ); f->SetFileName( fileName ); int res = f->Load(); @@ -85,7 +90,7 @@ int main(int argc, char *argv[]) { std::cerr << "Sorry, " << fileName <<" not a gdcm-readable " << "DICOM / ACR File" <Delete(); return 0; } std::cout << " ... is readable " << std::endl; @@ -95,19 +100,20 @@ int main(int argc, char *argv[]) // ============================================================ // We need a gdcm::FileHelper, since we want to load the pixels - gdcm::FileHelper *fh = new gdcm::FileHelper(f); + GDCM_NAME_SPACE::FileHelper *fh = GDCM_NAME_SPACE::FileHelper::New(f); - // (unit8_t DOESN'T mean it's mandatory for the image to be a 8 bits one) + // unit8_t DOESN'T mean it's mandatory for the image to be a 8 bits one ! + // Feel free to cast if you know it's not. uint8_t *imageData = fh->GetImageData(); if ( imageData == 0 ) { std::cerr << "Sorry, Pixels of" << fileName <<" are not " - << " gdcm-readable." << std::endl + << " gdcm-readable." << std::endl << "Use exAnonymizeNoLoad" << std::endl; - delete f; - delete fh; + f->Delete(); + fh->Delete(); return 0; } @@ -117,7 +123,7 @@ int main(int argc, char *argv[]) // Institution name f->AddAnonymizeElement(0x0008, 0x0080, "Xanadoo"); // Patient's name - f->AddAnonymizeElement(0x0010, 0x0010, "Fantomas"); + f->AddAnonymizeElement(0x0010, 0x0010, "Fantomas^X"); // Patient's ID f->AddAnonymizeElement( 0x0010, 0x0020,"1515" ); // Study Instance UID @@ -125,7 +131,7 @@ int main(int argc, char *argv[]) // Telephone f->AddAnonymizeElement(0x0010, 0x2154, "3615" ); - // Aware user will add more fields to anonymize here + // Aware user will add here more fields to anonymize here // The gdcm::File is modified in memory @@ -134,7 +140,14 @@ int main(int argc, char *argv[]) // ============================================================ // Write a new file // ============================================================ - + + // Since we just Anonymized the file, we know that no modification + // was performed on the pixels. + // The written image will not appear as a 'Secondary Captured image' + // nor as a DERIVED one + + fh->SetContentType(GDCM_NAME_SPACE::UNMODIFIED_PIXELS_IMAGE); + fh->WriteDcmExplVR(outputFileName); std::cout <<"End Anonymize" << std::cout; @@ -143,8 +156,8 @@ int main(int argc, char *argv[]) // ============================================================ f->ClearAnonymizeList(); - delete f; - delete fh; + f->Delete(); + fh->Delete(); return 0; }