From 4d992954520d43c6f2fb555b7cd721574978c23a Mon Sep 17 00:00:00 2001 From: jpr Date: Thu, 7 Jul 2005 17:31:53 +0000 Subject: [PATCH] Begin of kosherization of Example New 'gdcm2' style. --- Example/Anonymize.cxx | 44 ++++++++++++---------- Example/AnonymizeDicomDir.cxx | 21 +++++++---- Example/AnonymizeNoLoad.cxx | 37 +++++++++--------- Example/MakeDicomDir.cxx | 8 ++-- Example/PrintDicomDir.cxx | 50 ++++++++++++------------- Example/PrintFile.cxx | 9 +++-- Example/ReWrite.cxx | 62 +++++++++++++++---------------- Example/TestWrite.cxx | 70 +++++++++++++++++------------------ Example/exAnonymize.cxx | 40 ++++++++++---------- Example/exAnonymizeNoLoad.cxx | 36 +++++++++--------- Example/exBuildUpDicomDir.cxx | 7 ++-- Example/exColorToRGB.cxx | 33 ++++++++--------- Example/exGC.cxx | 31 ++++++++-------- Example/exGrey2RGB.cxx | 6 +-- Example/exImageLighten.cxx | 32 ++++++++-------- Example/exOverlaysACR.cxx | 49 ++++++++++++------------ Example/exReadPapyrus.cxx | 25 +++++++------ 17 files changed, 290 insertions(+), 270 deletions(-) diff --git a/Example/Anonymize.cxx b/Example/Anonymize.cxx index 5af051c0..defdaf00 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/06/07 11:12:10 $ - Version: $Revision: 1.1 $ + Date: $Date: 2005/07/07 17:31:53 $ + 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 @@ -74,14 +74,18 @@ int main(int argc, char *argv[]) // Read the input file. // ============================================================ - gdcm::File *f1; + gdcm::File *f; - f1 = new gdcm::File( fileName ); - if (!f1->IsReadable()) + f = new gdcm::File( ); + f->SetLoadMode( 0x00000000 ); + f->SetFileName( fileName ); + int res = f->Load(); + + if ( !res ) { std::cerr << "Sorry, " << fileName <<" not a gdcm-readable " << "DICOM / ACR File" <GetImageData(); + uint8_t *imageData = fh->GetImageData(); if ( imageData == 0 ) { std::cerr << "Sorry, Pixels of" << fileName <<" are not " << " gdcm-readable." << std::endl << "Use exAnonymizeNoLoad" << std::endl; - delete f1; - delete fh1; + delete f; + delete fh; return 0; } @@ -111,36 +115,36 @@ int main(int argc, char *argv[]) // Choose the fields to anonymize. // ============================================================ // Institution name - f1->AddAnonymizeElement(0x0008, 0x0080, "Xanadoo"); + f->AddAnonymizeElement(0x0008, 0x0080, "Xanadoo"); // Patient's name - f1->AddAnonymizeElement(0x0010, 0x0010, "Fantomas"); + f->AddAnonymizeElement(0x0010, 0x0010, "Fantomas"); // Patient's ID - f1->AddAnonymizeElement( 0x0010, 0x0020,"1515" ); + f->AddAnonymizeElement( 0x0010, 0x0020,"1515" ); // Study Instance UID - f1->AddAnonymizeElement(0x0020, 0x000d, "9.99.999.9999" ); + f->AddAnonymizeElement(0x0020, 0x000d, "9.99.999.9999" ); // Telephone - f1->AddAnonymizeElement(0x0010, 0x2154, "3615" ); + f->AddAnonymizeElement(0x0010, 0x2154, "3615" ); // Aware user will add more fields to anonymize here // The gdcm::File is modified in memory - f1->AnonymizeFile(); + f->AnonymizeFile(); // ============================================================ // Write a new file // ============================================================ - fh1->WriteDcmExplVR(outputFileName); + fh->WriteDcmExplVR(outputFileName); std::cout <<"End Anonymize" << std::cout; // ============================================================ // Remove the Anonymize list // ============================================================ - f1->ClearAnonymizeList(); + f->ClearAnonymizeList(); - delete f1; - delete fh1; + delete f; + delete fh; return 0; } diff --git a/Example/AnonymizeDicomDir.cxx b/Example/AnonymizeDicomDir.cxx index f4ab3fe3..cfb909c6 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/07/07 17:31:53 $ + Version: $Revision: 1.4 $ Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de l'Image). All rights reserved. See Doc/License.txt or @@ -100,19 +100,24 @@ int main(int argc, char *argv[]) // Read the input DICOMDIR // ============================================================ - gdcm::File *f1 = new gdcm::File( fileName ); - if (!f1->IsReadable()) { + 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); + gdcm::DocEntry *e = f->GetDocEntry(0x0004, 0x1220); if ( !e ) { std::cout << "No Directory Record Sequence (0004,1220) found" <SetLoadMode(loadMode); - int res = f1->Load(fileName); + gdcm::File *f; + f = new gdcm::File( ); + f->SetLoadMode(loadMode); + f->SetFileName( fileName ); + bool res = f->Load(); // gdcm::File::IsReadable() is no usable here, because we deal with // any kind of gdcm::Readable *document* @@ -80,7 +81,7 @@ int main(int argc, char *argv[]) << "Sorry, " << fileName <<" not a gdcm-readable " << "DICOM / ACR Document" << std::endl; - delete f1; + delete f; return 1; } std::cout << fileName << " is readable " << std::endl; @@ -95,21 +96,21 @@ int main(int argc, char *argv[]) // Choose the fields to anonymize. // ============================================================ // Institution name - f1->AddAnonymizeElement( 0x0008, 0x0080, "Xanadoo" ); + f->AddAnonymizeElement( 0x0008, 0x0080, "Xanadoo" ); // Patient's name - f1->AddAnonymizeElement( 0x0010, 0x0010, "Fantomas" ); + f->AddAnonymizeElement( 0x0010, 0x0010, "Fantomas" ); // Patient's ID - f1->AddAnonymizeElement( 0x0010, 0x0020,"1515" ); + f->AddAnonymizeElement( 0x0010, 0x0020,"1515" ); // Patient's Birthdate - f1->AddAnonymizeElement( 0x0010, 0x0030,"11.11.1111" ); + f->AddAnonymizeElement( 0x0010, 0x0030,"11.11.1111" ); // Patient's Adress - f1->AddAnonymizeElement( 0x0010, 0x1040,"Sing-sing" ); + f->AddAnonymizeElement( 0x0010, 0x1040,"Sing-sing" ); // Patient's Mother's Birth Name - f1->AddAnonymizeElement( 0x0010, 0x1060,"Vampirella" ); + f->AddAnonymizeElement( 0x0010, 0x1060,"Vampirella" ); // Study Instance UID - f1->AddAnonymizeElement( 0x0020, 0x000d, "9.99.999.9999" ); + f->AddAnonymizeElement( 0x0020, 0x000d, "9.99.999.9999" ); // Telephone - f1->AddAnonymizeElement(0x0010, 0x2154, "3615" ); + f->AddAnonymizeElement(0x0010, 0x2154, "3615" ); // Aware use will add new fields here @@ -121,7 +122,7 @@ int main(int argc, char *argv[]) // The gdcm::File remains untouched in memory - f1->AnonymizeNoLoad(); + f->AnonymizeNoLoad(); // No need to write the File : modif were done on disc ! // File was overwritten ... @@ -131,9 +132,9 @@ int main(int argc, char *argv[]) // ============================================================ // Remove the Anonymize list // ============================================================ - f1->ClearAnonymizeList(); + f->ClearAnonymizeList(); - delete f1; + delete f; return 0; } diff --git a/Example/MakeDicomDir.cxx b/Example/MakeDicomDir.cxx index 0ad1aa94..5723db7d 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/05 13:26:32 $ - Version: $Revision: 1.7 $ + Date: $Date: 2005/07/07 17:31:53 $ + 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 @@ -108,7 +108,9 @@ int main(int argc, char *argv[]) dcmdir->SetEndMethod(EndMethod); dcmdir->SetLoadMode(loadMode); - dcmdir->Load(dirName); + dcmdir->SetFileName(dirName); + + dcmdir->Load(); // ----- Check the result diff --git a/Example/PrintDicomDir.cxx b/Example/PrintDicomDir.cxx index f8abf282..adbc4c18 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/06/08 08:09:07 $ - Version: $Revision: 1.23 $ + Date: $Date: 2005/07/07 17:31:53 $ + Version: $Revision: 1.24 $ Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de l'Image). All rights reserved. See Doc/License.txt or @@ -52,7 +52,7 @@ int main(int argc, char* argv[]) return 0; } - gdcm::DicomDir *e1; + gdcm::DicomDir *f; gdcm::TSKey v; gdcm::DicomDirPatient *pa; @@ -81,34 +81,34 @@ int main(int argc, char* argv[]) // new style is useless, since it has no effect for *reading* a DICOMDIR // (only meaningfull when *creating* a DICOMDIR) - e1 = new gdcm::DicomDir( fileName ); + f = new gdcm::DicomDir( fileName ); - //e1 = new gdcm::DicomDir(); - //e1->SetParseDir(false); - //e1->Load( fileName ); + //f = new gdcm::DicomDir(); + //f->SetParseDir(false); + //f->Load( fileName ); // Test if the DicomDir is readable - if( !e1->IsReadable() ) + if( !f->IsReadable() ) { std::cout<<" DicomDir '"<SetPrintLevel(level); + f->SetPrintLevel(level); // Test if the DicomDir contains any Patient - pa = e1->GetFirstPatient(); + pa = f->GetFirstPatient(); if ( pa == 0) { std::cout<<" DicomDir '"<GetFirstPatient(); + pa = f->GetFirstPatient(); while (pa) { std::cout << pa->GetEntryValue(0x0010, 0x0010) << std::endl; // Patient's Name - pa = e1->GetNextPatient(); + pa = f->GetNextPatient(); } break; @@ -134,7 +134,7 @@ int main(int argc, char* argv[]) << " = PATIENT/STUDY List =======================================" << std::endl<< std::endl; - pa = e1->GetFirstPatient(); + pa = f->GetFirstPatient(); while ( pa ) // on degouline les PATIENT de ce DICOMDIR { std::cout << pa->GetEntryValue(0x0010, 0x0010) << std::endl; // Patient's Name @@ -144,7 +144,7 @@ int main(int argc, char* argv[]) std::cout << "--- "<< st->GetEntryValue(0x0008, 0x1030) << std::endl; // Study Description st = pa->GetNextStudy(); } - pa = e1->GetNextPatient(); + pa = f->GetNextPatient(); } break; @@ -153,7 +153,7 @@ int main(int argc, char* argv[]) << " = PATIENT/STUDY/SERIE List ==================================" << std::endl<< std::endl; - pa = e1->GetFirstPatient(); + pa = f->GetFirstPatient(); while ( pa ) // on degouline les PATIENT de ce DICOMDIR { // Patient's Name, Patient ID @@ -177,7 +177,7 @@ int main(int argc, char* argv[]) } st = pa->GetNextStudy(); } - pa = e1->GetNextPatient(); + pa = f->GetNextPatient(); } break; @@ -186,7 +186,7 @@ int main(int argc, char* argv[]) << " = PATIENT/STUDY/SERIE/IMAGE List ============================" << std::endl<< std::endl; - pa = e1->GetFirstPatient(); + pa = f->GetFirstPatient(); while ( pa ) { // les PATIENT de ce DICOMDIR // Patient's Name, Patient ID std::cout << "Pat.Name:[" << pa->GetEntryValue(0x0010, 0x0010) <<"]"; // Patient's Name @@ -215,7 +215,7 @@ int main(int argc, char* argv[]) } st = pa->GetNextStudy(); } - pa = e1->GetNextPatient(); + pa = f->GetNextPatient(); } break; @@ -223,7 +223,7 @@ int main(int argc, char* argv[]) std::cout << std::endl << std::endl << " = DICOMDIR full content ==========================================" << std::endl<< std::endl; - e1->Print(); + f->Print(); break; } // end switch @@ -241,8 +241,8 @@ int main(int argc, char* argv[]) << " = Liste des PATIENT/STUDY/SERIE/IMAGE ===================================" << std::endl<< std::endl; - itPatient = e1->GetDicomDirPatients().begin(); - while ( itPatient != e1->GetDicomDirPatients().end() ) { // on degouline les PATIENT de ce DICOMDIR + itPatient = f->GetDicomDirPatients().begin(); + while ( itPatient != f->GetDicomDirPatients().end() ) { // on degouline les PATIENT de ce DICOMDIR std::cout << (*itPatient)->GetEntryValue(0x0010, 0x0010) << std::endl; // Patient's Name itStudy = ((*itPatient)->GetDicomDirStudies()).begin(); while (itStudy != (*itPatient)->GetDicomDirStudies().end() ) { // on degouline les STUDY de ce patient @@ -264,12 +264,12 @@ int main(int argc, char* argv[]) */ - if(e1->IsReadable()) + if(f->IsReadable()) std::cout <ArgMgrPrintUnusedLabels() ) - { + { am->ArgMgrUsage(usage); delete am; return 0; @@ -180,8 +180,9 @@ int main(int argc, char *argv[]) gdcm::File *f = new gdcm::File(); f->SetLoadMode(loadMode); + f->SetFileName( fileName ); + bool res = f->Load(); // just to see - bool res = f->Load( fileName ); if ( !res ) { delete f; diff --git a/Example/ReWrite.cxx b/Example/ReWrite.cxx index 43241c1f..97f7d3f1 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/06/17 12:37:20 $ - Version: $Revision: 1.7 $ + Date: $Date: 2005/07/07 17:31:53 $ + 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 @@ -91,38 +91,38 @@ int main(int argc, char *argv[]) // ----------- End Arguments Manager --------- - gdcm::File *e1 = new gdcm::File(); - e1->SetLoadMode(loadMode); - - bool res = e1->Load( fileName ); + gdcm::File *f = new gdcm::File(); + f->SetLoadMode( loadMode ); + f->SetFileName( fileName ); + bool res = f->Load(); if ( !res ) { - delete e1; + delete f; return 0; } - if (!e1->IsReadable()) + if (!f->IsReadable()) { std::cerr << "Sorry, not a Readable DICOM / ACR File" <GetImageDataSize(); - imageData = f1->GetImageData(); // somewhat important... can't remember - f1->SetWriteModeToRGB(); + dataSize = fh->GetImageDataSize(); + imageData = fh->GetImageData(); // somewhat important... can't remember + fh->SetWriteModeToRGB(); } else { - dataSize = f1->GetImageDataRawSize(); - imageData = f1->GetImageDataRaw();// somewhat important... can't remember - f1->SetWriteModeToRaw(); + dataSize = fh->GetImageDataRawSize(); + imageData = fh->GetImageDataRaw();// somewhat important... can't remember + fh->SetWriteModeToRaw(); } if ( imageData == 0 ) // to avoid warning @@ -132,25 +132,25 @@ int main(int argc, char *argv[]) std::cout <GetXSize(); - nY=e1->GetYSize(); - nZ=e1->GetZSize(); + nX=f->GetXSize(); + nY=f->GetYSize(); + nZ=f->GetZSize(); std::cout << " DIMX=" << nX << " DIMY=" << nY << " DIMZ=" << nZ << std::endl; - pixelType = e1->GetPixelType(); - sPP = e1->GetSamplesPerPixel(); - planarConfig = e1->GetPlanarConfiguration(); + pixelType = f->GetPixelType(); + sPP = f->GetSamplesPerPixel(); + planarConfig = f->GetPlanarConfiguration(); std::cout << " pixelType=" << pixelType << " SampleserPixel=" << sPP << " PlanarConfiguration=" << planarConfig << " PhotometricInterpretation=" - << e1->GetEntryValue(0x0028,0x0004) + << f->GetEntryValue(0x0028,0x0004) << std::endl; - int numberOfScalarComponents=e1->GetNumberOfScalarComponents(); + int numberOfScalarComponents=f->GetNumberOfScalarComponents(); std::cout << "NumberOfScalarComponents " << numberOfScalarComponents <GetTransferSyntaxName(); + transferSyntaxName = f->GetTransferSyntaxName(); std::cout << " TransferSyntaxName= [" << transferSyntaxName << "]" << std::endl; switch (mode[0]) @@ -161,7 +161,7 @@ int main(int argc, char *argv[]) // from a full gdcm readable File std::cout << "WriteACR" << std::endl; - f1->WriteAcr(outputFileName); + fh->WriteAcr(outputFileName); break; case 'D' : // Not documented in the 'usage', because the method is known to be bugged. @@ -170,7 +170,7 @@ int main(int argc, char *argv[]) // from a full gdcm readable File std::cout << "WriteDCM Implicit VR" << std::endl; - f1->WriteDcmImplVR(outputFileName); + fh->WriteDcmImplVR(outputFileName); break; case 'X' : @@ -179,7 +179,7 @@ int main(int argc, char *argv[]) // from a full gdcm readable File std::cout << "WriteDCM Explicit VR" << std::endl; - f1->WriteDcmExplVR(outputFileName); + fh->WriteDcmExplVR(outputFileName); break; case 'R' : @@ -187,12 +187,12 @@ int main(int argc, char *argv[]) // Writting a Raw File, std::cout << "WriteRaw" << std::endl; - f1->WriteRawData(outputFileName); + fh->WriteRawData(outputFileName); break; } - delete e1; - delete f1; + delete f; + delete fh; return 0; } diff --git a/Example/TestWrite.cxx b/Example/TestWrite.cxx index 21304209..dd7211aa 100644 --- a/Example/TestWrite.cxx +++ b/Example/TestWrite.cxx @@ -3,8 +3,8 @@ Program: gdcm Module: $RCSfile: TestWrite.cxx,v $ Language: C++ - Date: $Date: 2005/06/15 09:54:13 $ - Version: $Revision: 1.20 $ + Date: $Date: 2005/07/07 17:31:53 $ + Version: $Revision: 1.21 $ Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de l'Image). All rights reserved. See Doc/License.txt or @@ -24,8 +24,8 @@ int main(int argc, char *argv[]) { std::string fileNameToWrite; - gdcm::File *e1; - gdcm::FileHelper *f1; + gdcm::File *f; + gdcm::FileHelper *fh; void *imageData; int dataSize; @@ -45,14 +45,14 @@ int main(int argc, char *argv[]) /* if (0) { // Just to keep the code for further use std::cout <GetFile()->IsReadable()) { + f = new gdcmFileHelper(argv[1]); + if (!fh->GetFile()->IsReadable()) { std::cout << "Sorry, not a DICOM / ACR File" < after new gdcmFile" << std::endl; - e1->PrintEntry(); + f->PrintEntry(); std::cout <SetLoadMode(0); - e1->Load( fileName.c_str() ); - - if (!e1->IsReadable()) + f = new gdcm::File( ); + f->SetLoadMode(0); + f->SetFileName( fileName ); + bool res = f->Load(); + if ( !res ) { std::cerr << "Sorry, not a Readable DICOM / ACR File" <Print(); + // f->Print(); - f1 = new gdcm::FileHelper(e1); - dataSize = f1->GetImageDataSize(); - imageData= f1->GetImageData(); + fh = new gdcm::FileHelper(f); + dataSize = fh->GetImageDataSize(); + imageData= fh->GetImageData(); // --- @@ -89,25 +89,25 @@ int main(int argc, char *argv[]) std::cout <GetXSize(); - nY=e1->GetYSize(); - nZ=e1->GetZSize(); + nX=f->GetXSize(); + nY=f->GetYSize(); + nZ=f->GetZSize(); std::cout << " DIMX=" << nX << " DIMY=" << nY << " DIMZ=" << nZ << std::endl; - pixelType = e1->GetPixelType(); - sPP = e1->GetSamplesPerPixel(); - planarConfig = e1->GetPlanarConfiguration(); + pixelType = f->GetPixelType(); + sPP = f->GetSamplesPerPixel(); + planarConfig = f->GetPlanarConfiguration(); std::cout << " pixelType=" << pixelType << " SampleserPixel=" << sPP << " PlanarConfiguration=" << planarConfig << " PhotometricInterpretation=" - << e1->GetEntryValue(0x0028,0x0004) + << f->GetEntryValue(0x0028,0x0004) << std::endl; - int numberOfScalarComponents=e1->GetNumberOfScalarComponents(); + int numberOfScalarComponents=f->GetNumberOfScalarComponents(); std::cout << "NumberOfScalarComponents " << numberOfScalarComponents <GetTransferSyntaxName(); + transferSyntaxName = f->GetTransferSyntaxName(); std::cout << " TransferSyntaxName= [" << transferSyntaxName << "]" << std::endl; /* @@ -118,7 +118,7 @@ int main(int argc, char *argv[]) && transferSyntaxName != "Uncompressed ACR-NEMA" ) { std::cout << std::endl << "===========================================" << std::endl; - f1->GetPixelReadConverter()->Print(); + fh->GetPixelReadConverter()->Print(); std::cout << std::endl << "===========================================" << std::endl; } @@ -131,7 +131,7 @@ int main(int argc, char *argv[]) fileNameToWrite = fileName + ".ACR"; std::cout << "WriteACR" << std::endl; - f1->WriteAcr(fileNameToWrite); + fh->WriteAcr(fileNameToWrite); break; case 'd' : // Not document in the 'usage', because the method is knowed to be bugged. @@ -141,7 +141,7 @@ int main(int argc, char *argv[]) fileNameToWrite = fileName + ".DCM"; std::cout << "WriteDCM Implicit VR" << std::endl; - f1->WriteDcmImplVR(fileNameToWrite); + fh->WriteDcmImplVR(fileNameToWrite); break; case 'x' : @@ -150,7 +150,7 @@ int main(int argc, char *argv[]) fileNameToWrite = fileName + ".XDCM"; std::cout << "WriteDCM Explicit VR" << std::endl; - f1->WriteDcmExplVR(fileNameToWrite); + fh->WriteDcmExplVR(fileNameToWrite); break; case 'r' : @@ -159,12 +159,12 @@ int main(int argc, char *argv[]) fileNameToWrite = fileName + ".RAW"; std::cout << "WriteRaw" << std::endl; - f1->WriteRawData(fileNameToWrite); + fh->WriteRawData(fileNameToWrite); break; case 'v' : - if ( f1->GetFile()->GetBitsAllocated() == 8) + if ( fh->GetFile()->GetBitsAllocated() == 8) { std::cout << "videoinv for 8 bits" << std::endl; for (int i=0; iWriteDcmExplVR(fileNameToWrite); + fh->WriteDcmExplVR(fileNameToWrite); break; } - delete e1; - delete f1; + delete f; + delete fh; return 0; } diff --git a/Example/exAnonymize.cxx b/Example/exAnonymize.cxx index df651483..d0672dda 100644 --- a/Example/exAnonymize.cxx +++ b/Example/exAnonymize.cxx @@ -3,8 +3,8 @@ Program: gdcm Module: $RCSfile: exAnonymize.cxx,v $ Language: C++ - Date: $Date: 2005/03/02 17:19:45 $ - Version: $Revision: 1.3 $ + Date: $Date: 2005/07/07 17:31:53 $ + Version: $Revision: 1.4 $ Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de l'Image). All rights reserved. See Doc/License.txt or @@ -23,9 +23,7 @@ #include int main(int argc, char *argv[]) -{ - gdcm::File *f1; - +{ gdcm::Debug::DebugOn(); std::cout << "------------------------------------------------" << std::endl; std::cout << "Anonymize a full gdcm-readable Dicom image" << std::endl; @@ -48,8 +46,12 @@ int main(int argc, char *argv[]) std::cout << argv[1] << std::endl; - f1 = new gdcm::File( fileName ); - if (!f1->IsReadable()) { + gdcm::File *f = new gdcm::File(); + f->SetLoadMode( 0x00000000); + f->SetFileName( fileName ); + bool res = f->Load(); + + if (!res) { std::cerr << "Sorry, " << fileName <<" not a gdcm-readable " << "DICOM / ACR File" <GetImageData(); + uint8_t *imageData = fh->GetImageData(); if ( imageData == 0 ) { @@ -82,35 +84,35 @@ int main(int argc, char *argv[]) // Choose the fields to anonymize. // ============================================================ // Institution name - f1->AddAnonymizeElement(0x0008, 0x0080, "Xanadoo"); + f->AddAnonymizeElement(0x0008, 0x0080, "Xanadoo"); // Patient's name - f1->AddAnonymizeElement(0x0010, 0x0010, "Fantomas"); + f->AddAnonymizeElement(0x0010, 0x0010, "Fantomas"); // Patient's ID - f1->AddAnonymizeElement( 0x0010, 0x0020,"1515" ); + f->AddAnonymizeElement( 0x0010, 0x0020,"1515" ); // Study Instance UID - f1->AddAnonymizeElement(0x0020, 0x000d, "9.99.999.9999" ); + f->AddAnonymizeElement(0x0020, 0x000d, "9.99.999.9999" ); // Telephone - f1->AddAnonymizeElement(0x0010, 0x2154, "3615" ); + f->AddAnonymizeElement(0x0010, 0x2154, "3615" ); // Aware use will add new fields here // The gdcm::File is modified in memory - f1->AnonymizeFile(); + f->AnonymizeFile(); // ============================================================ // Write a new file // ============================================================ - fh1->WriteDcmExplVR(outputFileName); + fh->WriteDcmExplVR(outputFileName); std::cout <<"End Anonymize" << std::cout; // ============================================================ // Remove the Anonymize list // ============================================================ - f1->ClearAnonymizeList(); + f->ClearAnonymizeList(); - delete f1; - delete fh1; + delete f; + delete fh; return 0; } diff --git a/Example/exAnonymizeNoLoad.cxx b/Example/exAnonymizeNoLoad.cxx index 52968e0e..dece2b6a 100644 --- a/Example/exAnonymizeNoLoad.cxx +++ b/Example/exAnonymizeNoLoad.cxx @@ -3,8 +3,8 @@ Program: gdcm Module: $RCSfile: exAnonymizeNoLoad.cxx,v $ Language: C++ - Date: $Date: 2005/05/04 07:29:17 $ - Version: $Revision: 1.8 $ + Date: $Date: 2005/07/07 17:31:54 $ + 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 @@ -24,7 +24,7 @@ int main(int argc, char *argv[]) { - gdcm::File *f1; + gdcm::File *f; gdcm::Debug::DebugOn(); @@ -47,11 +47,11 @@ int main(int argc, char *argv[]) // ============================================================ // Read the input image. // ============================================================ - bool res; - f1 = new gdcm::File( ); - f1->SetLoadMode(NO_SEQ - NO_SHADOW); - res = f1->Load(fileName); + f = new gdcm::File( ); + f->SetLoadMode(NO_SEQ - NO_SHADOW); + f->SetFileName( fileName ); + bool res = f->Load(); // gdcm::File::IsReadable() is no usable here, because we deal with // any kind of gdcm::Readable *document* @@ -75,21 +75,21 @@ int main(int argc, char *argv[]) // Choose the fields to anonymize. // ============================================================ // Institution name - f1->AddAnonymizeElement( 0x0008, 0x0080, "Xanadoo" ); + f->AddAnonymizeElement( 0x0008, 0x0080, "Xanadoo" ); // Patient's name - f1->AddAnonymizeElement( 0x0010, 0x0010, "Fantomas" ); + f->AddAnonymizeElement( 0x0010, 0x0010, "Fantomas" ); // Patient's ID - f1->AddAnonymizeElement( 0x0010, 0x0020,"1515" ); + f->AddAnonymizeElement( 0x0010, 0x0020,"1515" ); // Patient's Birthdate - f1->AddAnonymizeElement( 0x0010, 0x0030,"11.11.1111" ); + f->AddAnonymizeElement( 0x0010, 0x0030,"11.11.1111" ); // Patient's Adress - f1->AddAnonymizeElement( 0x0010, 0x1040,"Sing-sing" ); + f->AddAnonymizeElement( 0x0010, 0x1040,"Sing-sing" ); // Patient's Mother's Birth Name - f1->AddAnonymizeElement( 0x0010, 0x1060,"Vampirella" ); + f->AddAnonymizeElement( 0x0010, 0x1060,"Vampirella" ); // Study Instance UID - f1->AddAnonymizeElement( 0x0020, 0x000d, "9.99.999.9999" ); + f->AddAnonymizeElement( 0x0020, 0x000d, "9.99.999.9999" ); // Telephone - f1->AddAnonymizeElement(0x0010, 0x2154, "3615" ); + f->AddAnonymizeElement(0x0010, 0x2154, "3615" ); // Aware use will add new fields here @@ -104,7 +104,7 @@ int main(int argc, char *argv[]) // The gdcm::File remains untouched in memory - f1->AnonymizeNoLoad(); + f->AnonymizeNoLoad(); // No need to write the File : modif were done on disc ! // File was overwritten ... @@ -114,9 +114,9 @@ int main(int argc, char *argv[]) // ============================================================ // Remove the Anonymize list // ============================================================ - f1->ClearAnonymizeList(); + f->ClearAnonymizeList(); - delete f1; + delete f; return 0; } diff --git a/Example/exBuildUpDicomDir.cxx b/Example/exBuildUpDicomDir.cxx index f36ad9c3..883d53bb 100644 --- a/Example/exBuildUpDicomDir.cxx +++ b/Example/exBuildUpDicomDir.cxx @@ -3,8 +3,8 @@ Program: gdcm Module: $RCSfile: exBuildUpDicomDir.cxx,v $ Language: C++ - Date: $Date: 2005/02/03 15:44:50 $ - Version: $Revision: 1.1 $ + Date: $Date: 2005/07/07 17:31:54 $ + 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 @@ -46,7 +46,8 @@ int main(int argc, char *argv[]) gdcm::DicomDir *dcmdir; dcmdir = new gdcm::DicomDir(); - std::cout << "\n------- BuildUpDicomDir: Test Print Meta only -----" << std::endl; + std::cout << "\n------- BuildUpDicomDir: Test Print Meta only -----" + << std::endl; ((gdcm::Document *)dcmdir)->Print(); gdcm::DicomDirPatient *p1=dcmdir->NewPatient(); diff --git a/Example/exColorToRGB.cxx b/Example/exColorToRGB.cxx index a1a9ea64..05509fcc 100644 --- a/Example/exColorToRGB.cxx +++ b/Example/exColorToRGB.cxx @@ -3,8 +3,8 @@ Program: gdcm Module: $RCSfile: exColorToRGB.cxx,v $ Language: C++ - Date: $Date: 2005/07/06 15:49:31 $ - Version: $Revision: 1.2 $ + Date: $Date: 2005/07/07 17:31:54 $ + 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 @@ -50,13 +50,14 @@ int main(int argc, char *argv[]) // ============================================================ // a gdcm::File contains all the Dicom Field but the Pixels Element - gdcm::File *f1= new gdcm::File( fileName ); - - std::cout << argv[1] << std::endl; - f1 = new gdcm::File( fileName ); - if (!f1->IsReadable()) { + gdcm::File *f = new gdcm::File(); + f->SetLoadMode( 0x00000000); + f->SetFileName( fileName ); + bool res = f->Load(); + + if (!res) { std::cerr << "Sorry, " << fileName <<" not a gdcm-readable " << "DICOM / ACR File" <IsMonochrome()) { + if (!f->IsMonochrome()) { std::cerr << "Sorry, " << fileName <<" not a 'color' File " << " " <GetImageData(); + uint8_t *imageData = fh->GetImageData(); if ( imageData == 0 ) { @@ -92,15 +93,13 @@ int main(int argc, char *argv[]) } - - // ------ User wants write a new image without shadow groups ------------- // ------ without Sequences ------------- gdcm::FileHelper *copy = new gdcm::FileHelper( output ); - gdcm::DocEntry *d = f1->GetFirstEntry(); + gdcm::DocEntry *d = f->GetFirstEntry(); while(d) { // We skip SeqEntries, since user cannot do much with them @@ -126,19 +125,19 @@ int main(int argc, char *argv[]) // We skip gdcm::SeqEntries } } - d = f1->GetNextEntry(); + d = f->GetNextEntry(); } // User knows the image is a 'color' one -RGB, YBR, Palette Color- // and wants to write it as RGB - copy->SetImageData(imageData, fh1->GetImageDataSize()); + copy->SetImageData(imageData, fh->GetImageDataSize()); copy->SetWriteModeToRGB(); copy->WriteDcmExplVR( output ); - delete f1; - delete fh1; + delete f; + delete fh; delete copy; exit (0); diff --git a/Example/exGC.cxx b/Example/exGC.cxx index 0458b2ef..8d28ecec 100644 --- a/Example/exGC.cxx +++ b/Example/exGC.cxx @@ -3,8 +3,8 @@ Program: gdcm Module: $RCSfile: exGC.cxx,v $ Language: C++ - Date: $Date: 2005/07/06 15:49:31 $ - Version: $Revision: 1.4 $ + Date: $Date: 2005/07/07 17:31:54 $ + 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 @@ -73,13 +73,14 @@ int main(int argc, char *argv[]) // ============================================================ // a gdcm::File contains all the Dicom Field but the Pixels Element - gdcm::File *f1= new gdcm::File( fileName ); - - std::cout << argv[1] << std::endl; - f1 = new gdcm::File( fileName ); - if (!f1->IsReadable()) { + gdcm::File *f = new gdcm::File(); + f->SetLoadMode( 0x00000000); + f->SetFileName( fileName ); + bool res = f->Load(); + + if (!res) { std::cerr << "Sorry, " << fileName <<" not a gdcm-readable " << "DICOM / ACR File" <IsMonochrome()) { + if (!f->IsMonochrome()) { std::cerr << "Sorry, " << fileName <<" not a 'color' File " << " " <GetImageData(); + uint8_t *imageData = fh->GetImageData(); if ( imageData == 0 ) { @@ -120,7 +121,7 @@ int main(int argc, char *argv[]) gdcm::FileHelper *copy = new gdcm::FileHelper( output ); - gdcm::DocEntry *d = f1->GetFirstEntry(); + gdcm::DocEntry *d = f->GetFirstEntry(); while(d) { // We skip SeqEntries, since user cannot do much with them @@ -146,10 +147,10 @@ int main(int argc, char *argv[]) // We skip gdcm::SeqEntries } } - d = f1->GetNextEntry(); + d = f->GetNextEntry(); } - int imageSize = fh1->GetImageDataSize(); + int imageSize = fh->GetImageDataSize(); // Black up all 'grey' pixels int i; int n = 0; @@ -194,8 +195,8 @@ int main(int argc, char *argv[]) copy->WriteDcmExplVR( output ); - delete f1; - delete fh1; + delete f; + delete fh; delete copy; exit (0); diff --git a/Example/exGrey2RGB.cxx b/Example/exGrey2RGB.cxx index b096ad50..2c151985 100644 --- a/Example/exGrey2RGB.cxx +++ b/Example/exGrey2RGB.cxx @@ -3,8 +3,8 @@ Program: gdcm Module: $RCSfile: exGrey2RGB.cxx,v $ Language: C++ - Date: $Date: 2005/06/15 10:06:36 $ - Version: $Revision: 1.1 $ + Date: $Date: 2005/07/07 17:31:54 $ + 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 @@ -80,7 +80,7 @@ int main(int argc, char *argv[]) return 1; } } - + gdcm::FileHelper *fh = new gdcm::FileHelper( filename ); size_t dataSize = fh->GetImageDataSize(); diff --git a/Example/exImageLighten.cxx b/Example/exImageLighten.cxx index 5797d82d..c0553d12 100644 --- a/Example/exImageLighten.cxx +++ b/Example/exImageLighten.cxx @@ -3,8 +3,8 @@ Program: gdcm Module: $RCSfile: exImageLighten.cxx,v $ Language: C++ - Date: $Date: 2005/07/06 15:49:31 $ - Version: $Revision: 1.2 $ + Date: $Date: 2005/07/07 17:31:54 $ + 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 @@ -26,9 +26,7 @@ #include // for exit int main(int argc, char *argv[]) -{ - gdcm::File *f1; - +{ std::cout << "-----------------------------------------------" << std::endl; std::cout << "Removes from a full gdcm-readable Dicom image" << std::endl; std::cout << " all the 'Shadow groups' and the 'Sequence' entries" @@ -58,8 +56,12 @@ int main(int argc, char *argv[]) std::cout << argv[1] << std::endl; - f1 = new gdcm::File( fileName ); - if (!f1->IsReadable()) { + gdcm::File *f = new gdcm::File(); + f->SetLoadMode( 0x00000000); + f->SetFileName( fileName ); + bool res = f->Load(); + + if (!res) { std::cerr << "Sorry, " << fileName <<" not a gdcm-readable " << "DICOM / ACR File" <GetImageDataRaw(); + uint8_t *imageDataRaw = fh->GetImageDataRaw(); // Get the image data size - size_t dataRawSize = fh1->GetImageDataRawSize(); + size_t dataRawSize = fh->GetImageDataRawSize(); // ============================================================ // Create a new gdcm::Filehelper, to hold new image. @@ -93,9 +95,9 @@ int main(int argc, char *argv[]) // Selective copy of the entries (including Pixel Element). // ============================================================ - gdcm::DocEntry *d = f1->GetFirstEntry(); + gdcm::DocEntry *d = f->GetFirstEntry(); - d = f1->GetFirstEntry(); + d = f->GetFirstEntry(); while(d) { // We skip SeqEntries, since user cannot do much with them @@ -121,7 +123,7 @@ int main(int argc, char *argv[]) // We skip gdcm::SeqEntries } } - d = f1->GetNextEntry(); + d = f->GetNextEntry(); } // User wants to keep the Palette Color -if any- @@ -133,8 +135,8 @@ int main(int argc, char *argv[]) std::cout << std::endl << "------------------------------------------------------------" << std::endl; - delete f1; - delete fh1; + delete f; + delete fh; delete copy; exit (0); diff --git a/Example/exOverlaysACR.cxx b/Example/exOverlaysACR.cxx index ddcc4c69..00fa7520 100644 --- a/Example/exOverlaysACR.cxx +++ b/Example/exOverlaysACR.cxx @@ -3,8 +3,8 @@ Program: gdcm Module: $RCSfile: exOverlaysACR.cxx,v $ Language: C++ - Date: $Date: 2005/05/19 15:47:20 $ - Version: $Revision: 1.3 $ + Date: $Date: 2005/07/07 17:31:54 $ + Version: $Revision: 1.4 $ Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de l'Image). All rights reserved. See Doc/License.txt or @@ -58,7 +58,7 @@ V 6006|0102[US] [Overlay Bit Position] [15] x(f) int main(int argc, char *argv[]) { - gdcm::File *f1; + gdcm::File *f; //gdcm::Debug::DebugOn(); @@ -85,22 +85,23 @@ int main(int argc, char *argv[]) //std::cout << argv[1] << std::endl; - f1 = new gdcm::File( ); + f = new gdcm::File( ); - f1->SetLoadMode(NO_SEQ | NO_SHADOW); - f1->Load( fileName ); + f->SetLoadMode(NO_SEQ | NO_SHADOW); + f->SetFileName( fileName ); + bool res = f->Load(); if( gdcm::Debug::GetDebugFlag() ) { std::cout << "---------------------------------------------" << std::endl; - f1->Print(); + f->Print(); std::cout << "---------------------------------------------" << std::endl; } - if (!f1->IsReadable()) { + if (!res) { std::cout << "Sorry, " << fileName <<" not a gdcm-readable " << "DICOM / ACR File" <GetBitsAllocated(); + int bitsAllocated = f->GetBitsAllocated(); if ( bitsAllocated <= 8 ) { std::cout << " 8 bits pixel image cannot contain Overlays " << std::endl; - delete f1; + delete f; return 0; } - std::string s1 = f1->GetEntryValue(0x6000, 0x0102); + std::string s1 = f->GetEntryValue(0x6000, 0x0102); if (s1 == gdcm::GDCM_UNFOUND) { std::cout << " Image doesn't contain any Overlay " << std::endl; - delete f1; + delete f; return 0; } std::cout << " File is read! " << std::endl; @@ -133,12 +134,12 @@ int main(int argc, char *argv[]) // We don't use a gdcm::FileHelper, since it rubs out // the 'non image' bits of the pixels... - int nx = f1->GetXSize(); - int ny = f1->GetYSize(); + int nx = f->GetXSize(); + int ny = f->GetYSize(); std::cout << "Dimensions " << ny << " " <GetDocEntry(f1->GetGrPixel(), f1->GetNumPixel()); + gdcm::DocEntry *p = f->GetDocEntry(f->GetGrPixel(), f->GetNumPixel()); if (p == 0) std::cout << "Pixels element not found" << std::endl; else @@ -153,7 +154,7 @@ int main(int argc, char *argv[]) if (fp == 0) { std::cout << "Unable to open File" << std::endl; - delete f1; + delete f; return 0; } else @@ -169,7 +170,7 @@ int main(int argc, char *argv[]) << "readable. expected length :" << nx*ny << " " << "read length : " << lgt << std::endl; - delete f1; + delete f; delete pixels; return 0; } @@ -197,19 +198,19 @@ int main(int argc, char *argv[]) gdcm::FileHelper *fh = 0; -while ( (strOvlBitPosition = f1->GetEntryValue(currentOvlGroup, 0x0102)) +while ( (strOvlBitPosition = f->GetEntryValue(currentOvlGroup, 0x0102)) != gdcm::GDCM_UNFOUND ) { - strOverlayLocation = f1->GetEntryValue(currentOvlGroup, 0x0200); + strOverlayLocation = f->GetEntryValue(currentOvlGroup, 0x0200); if ( strOverlayLocation != gdcm::GDCM_UNFOUND ) { overlayLocation = atoi(strOverlayLocation.c_str()); - if ( overlayLocation != f1->GetGrPixel() ) + if ( overlayLocation != f->GetGrPixel() ) { std::cout << "Big Trouble : Overlays are NOT in the Pixels Group " << std::hex << "(" << overlayLocation << " vs " - << f1->GetGrPixel() << std::endl; + << f->GetGrPixel() << std::endl; // Actually, here, we should (try to) read the overlay location // and go on the job. continue; @@ -288,8 +289,8 @@ while ( (strOvlBitPosition = f1->GetEntryValue(currentOvlGroup, 0x0102)) i++; } - delete f1; - if (f1) + delete f; + if (f) delete fh; if (fileToBuild) delete fileToBuild; diff --git a/Example/exReadPapyrus.cxx b/Example/exReadPapyrus.cxx index 12f0a188..99badbf8 100644 --- a/Example/exReadPapyrus.cxx +++ b/Example/exReadPapyrus.cxx @@ -3,8 +3,8 @@ Program: gdcm Module: $RCSfile: exReadPapyrus.cxx,v $ Language: C++ - Date: $Date: 2005/06/27 15:46:27 $ - Version: $Revision: 1.2 $ + Date: $Date: 2005/07/07 17:31:54 $ + 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 @@ -134,35 +134,36 @@ int main(int argc, char *argv[]) } int loadMode = 0x0; // load everything - gdcm::File *e1 = new gdcm::File(); - e1->SetLoadMode(loadMode); + gdcm::File *f = new gdcm::File(); + f->SetLoadMode( loadMode ); + f->SetFileName( fileName ); + bool res = f->Load(); - bool res = e1->Load( fileName ); if ( !res ) { - delete e1; + delete f; return 0; } // Look for private Papyrus Sequence - gdcm::SeqEntry *seqPapyrus= e1->GetSeqEntry(0x0041, 0x1050); + gdcm::SeqEntry *seqPapyrus= f->GetSeqEntry(0x0041, 0x1050); if (!seqPapyrus) { std::cout << "NOT a Papyrus File : " << fileName <GetFile(); - //gdcm::FileHelper *f1 = new gdcm::FileHelper(e1); + //gdcm::FileHelper *f1 = new gdcm::FileHelper(f); gdcm::SQItem *sqi = seqPapyrus->GetFirstSQItem(); if (sqi == 0) { std::cout << "NO SQItem found within private Papyrus Sequence" << std::endl; - delete e1; + delete f; return 1; } @@ -177,8 +178,8 @@ int main(int argc, char *argv[]) // Modality, Transfer Syntax, Study Date, Study Time // Patient Name, Media Storage SOP Instance UID, etc - MediaStSOPinstUID = e1->GetEntryValue(0x0002,0x0002); - TransferSyntax = e1->GetEntryValue(0x0002,0x0010); + MediaStSOPinstUID = f->GetEntryValue(0x0002,0x0002); + TransferSyntax = f->GetEntryValue(0x0002,0x0010); StudyDate = sqi->GetEntryValue(0x0008,0x0020); StudyTime = sqi->GetEntryValue(0x0008,0x0030); Modality = sqi->GetEntryValue(0x0008,0x0060); -- 2.45.2