X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=blobdiff_plain;ds=sidebyside;f=Testing%2FTestCopyRescaleDicom.cxx;h=f93f5e681d8125fc1a56dbba42a733e7c138111a;hb=3e82e8b67eddf5d4b95b6aa2a2e2615aced4c452;hp=975d91c8742ab1c2509e4f921db442976191ab9b;hpb=5a0d183707a94e875a595036f64d0bd506faf618;p=gdcm.git diff --git a/Testing/TestCopyRescaleDicom.cxx b/Testing/TestCopyRescaleDicom.cxx index 975d91c8..f93f5e68 100644 --- a/Testing/TestCopyRescaleDicom.cxx +++ b/Testing/TestCopyRescaleDicom.cxx @@ -3,8 +3,8 @@ Program: gdcm Module: $RCSfile: TestCopyRescaleDicom.cxx,v $ Language: C++ - Date: $Date: 2005/01/14 11:28:29 $ - Version: $Revision: 1.5 $ + Date: $Date: 2005/02/02 10:05:26 $ + 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 @@ -15,8 +15,8 @@ PURPOSE. See the above copyright notices for more information. =========================================================================*/ -#include "gdcmHeader.h" #include "gdcmFile.h" +#include "gdcmFileHelper.h" #include "gdcmValEntry.h" #include "gdcmBinEntry.h" @@ -43,65 +43,53 @@ int CopyRescaleDicom(std::string const & filename, //////////////// Step 1: std::cout << " 1..."; - gdcm::Header *originalH = new gdcm::Header( filename ); - gdcm::Header *copyH = new gdcm::Header( ); - - //First of all copy the header field by field - - // Warning :Accessor gdcmElementSet::GetEntry() should not exist - // It was commented out by Mathieu, that was a *good* idea - // (the user does NOT have to know the way we implemented the Header !) - // Waiting for a 'clean' solution, I keep the method ...JPRx + gdcm::File *originalF = new gdcm::File( filename ); + gdcm::File *copyF = new gdcm::File( ); + //First of all copy the file, field by field //////////////// Step 2: std::cout << "2..."; - // Copy of the header content - originalH->InitTraversal(); - gdcm::DocEntry* d = originalH->GetNextEntry(); + // Copy of the file content + gdcm::DocEntry* d = originalF->GetFirstEntry(); while(d) { if ( gdcm::BinEntry* b = dynamic_cast(d) ) { - copyH->ReplaceOrCreate( - b->GetBinArea(), - b->GetLength(), - b->GetGroup(), - b->GetElement(), - b->GetVR() ); + copyF->InsertBinEntry( b->GetBinArea(),b->GetLength(), + b->GetGroup(),b->GetElement(), + b->GetVR() ); } else if ( gdcm::ValEntry* v = dynamic_cast(d) ) { - copyH->ReplaceOrCreate( - v->GetValue(), - v->GetGroup(), - v->GetElement(), - v->GetVR() ); + copyF->InsertValEntry( v->GetValue(), + v->GetGroup(),v->GetElement(), + v->GetVR() ); } else { // We skip pb of SQ recursive exploration } - d=originalH->GetNextEntry(); + d=originalF->GetNextEntry(); } - gdcm::File *original = new gdcm::File( originalH ); - gdcm::File *copy = new gdcm::File( copyH ); + gdcm::FileHelper *original = new gdcm::FileHelper( originalF ); + gdcm::FileHelper *copy = new gdcm::FileHelper( copyF ); size_t dataSize = original->GetImageDataSize(); size_t rescaleSize; uint8_t *rescaleImage; - const std::string & bitsStored = originalH->GetEntry(0x0028,0x0101); + const std::string & bitsStored = originalF->GetEntryValue(0x0028,0x0101); if( bitsStored == "16" ) { std::cout << "Rescale..."; - copyH->ReplaceOrCreate( "8", 0x0028, 0x0100); // BitsAllocated - copyH->ReplaceOrCreate( "8", 0x0028, 0x0101); // BitsStored - copyH->ReplaceOrCreate( "7", 0x0028, 0x0102); // HighBit - copyH->ReplaceOrCreate( "0", 0x0028, 0x0103); //Pixel Representation + copyF->InsertValEntry( "8", 0x0028, 0x0100); // BitsAllocated + copyF->InsertValEntry( "8", 0x0028, 0x0101); // BitsStored + copyF->InsertValEntry( "7", 0x0028, 0x0102); // HighBit + copyF->InsertValEntry( "0", 0x0028, 0x0103); //Pixel Representation // We assume the value were from 0 to uint16_t max rescaleSize = dataSize / 2; @@ -133,28 +121,28 @@ int CopyRescaleDicom(std::string const & filename, delete original; delete copy; - delete originalH; - delete copyH; + delete originalF; + delete copyF; delete[] rescaleImage; return 1; } delete copy; - delete copyH; + delete copyF; //////////////// Step 4: std::cout << "4..."; - copy = new gdcm::File( output ); + copy = new gdcm::FileHelper( output ); //Is the file written still gdcm parsable ? - if ( !copy->GetHeader()->IsReadable() ) + if ( !copy->GetFile()->IsReadable() ) { std::cout << " Failed" << std::endl << " " << output << " not readable" << std::endl; delete original; - delete originalH; + delete originalF; delete[] rescaleImage; return 1; @@ -165,21 +153,21 @@ int CopyRescaleDicom(std::string const & filename, size_t dataSizeWritten = copy->GetImageDataSize(); uint8_t* imageDataWritten = copy->GetImageData(); - if (originalH->GetXSize() != copy->GetHeader()->GetXSize() || - originalH->GetYSize() != copy->GetHeader()->GetYSize() || - originalH->GetZSize() != copy->GetHeader()->GetZSize()) + if (originalF->GetXSize() != copy->GetFile()->GetXSize() || + originalF->GetYSize() != copy->GetFile()->GetYSize() || + originalF->GetZSize() != copy->GetFile()->GetZSize()) { std::cout << "Failed" << std::endl << " X Size differs: " - << "X: " << originalH->GetXSize() << " # " - << copy->GetHeader()->GetXSize() << " | " - << "Y: " << originalH->GetYSize() << " # " - << copy->GetHeader()->GetYSize() << " | " - << "Z: " << originalH->GetZSize() << " # " - << copy->GetHeader()->GetZSize() << std::endl; + << "X: " << originalF->GetXSize() << " # " + << copy->GetFile()->GetXSize() << " | " + << "Y: " << originalF->GetYSize() << " # " + << copy->GetFile()->GetYSize() << " | " + << "Z: " << originalF->GetZSize() << " # " + << copy->GetFile()->GetZSize() << std::endl; delete original; delete copy; - delete originalH; + delete originalF; delete[] rescaleImage; return 1; @@ -193,7 +181,7 @@ int CopyRescaleDicom(std::string const & filename, delete original; delete copy; - delete originalH; + delete originalF; delete[] rescaleImage; return 1; @@ -207,7 +195,7 @@ int CopyRescaleDicom(std::string const & filename, delete original; delete copy; - delete originalH; + delete originalF; delete[] rescaleImage; return 1; @@ -216,7 +204,7 @@ int CopyRescaleDicom(std::string const & filename, delete original; delete copy; - delete originalH; + delete originalF; delete[] rescaleImage; return 0; @@ -252,12 +240,12 @@ int TestCopyRescaleDicom(int argc, char* argv[]) << std::endl; std::cout << " apply the following to each filename.xxx: " << std::endl; - std::cout << " step 1: parse the image (as gdcmHeader) and call" + std::cout << " step 1: parse the image (as gdcmFile) and call" << " IsReadable(). After that, call GetImageData() and " << "GetImageDataSize() " << std::endl; std::cout << " step 2: create a copy of the readed file and the new" - << " pixel datas are set to the copy" + << " pixel data are set to the copy" << std::endl; std::cout << " step 3: write the copy of the image" << std::endl;