From: regrain Date: Tue, 7 Dec 2004 18:16:39 +0000 (+0000) Subject: * Test/ShowDicom.cxx, TestWriteWithVTK.cxx : bug fix, now this test pass X-Git-Tag: Version1.0.bp~523 X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=commitdiff_plain;h=412cf9757709333001ae81f5f4079e53c62840c7;p=gdcm.git * Test/ShowDicom.cxx, TestWriteWithVTK.cxx : bug fix, now this test pass not at all time * Test/TestCopyRescaleDicom.cxx : rearrange the test to correctly pass... Some fields in BinEntry must be copied to not seg fault when making the : gdcm::File *copy = new gdcm::File( copyH ); and tests are now made on good variables -- BeNours --- diff --git a/ChangeLog b/ChangeLog index a4db53cd..7e630ff6 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,11 @@ +2004-12-07 Benoit Regrain + * Test/ShowDicom.cxx, TestWriteWithVTK.cxx : bug fix, now this test pass + not at all time + * Test/TestCopyRescaleDicom.cxx : rearrange the test to correctly pass... + Some fields in BinEntry must be copied to not seg fault when making the : + gdcm::File *copy = new gdcm::File( copyH ); + and tests are now made on good variables + 2004-12-07 Benoit Regrain * vtk/vtkGdcmWriter.[h|cxx] : add a first version of vtkGdcmWriter * src/gdcmValEntry.cxx : bug fix when setting the value. Problems of odd diff --git a/Testing/TestCopyDicom.cxx b/Testing/TestCopyDicom.cxx index 38cc73e0..79825ae0 100644 --- a/Testing/TestCopyDicom.cxx +++ b/Testing/TestCopyDicom.cxx @@ -3,8 +3,8 @@ Program: gdcm Module: $RCSfile: TestCopyDicom.cxx,v $ Language: C++ - Date: $Date: 2004/12/03 20:16:56 $ - Version: $Revision: 1.25 $ + Date: $Date: 2004/12/07 18:16:39 $ + Version: $Revision: 1.26 $ Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de l'Image). All rights reserved. See Doc/License.txt or @@ -110,10 +110,6 @@ int CopyDicom(std::string const & filename, else { // We skip pb of SQ recursive exploration - //std::cout << "Skipped Sequence " - // << "------------- " << d->GetVR() << " "<< std::hex - // << d->GetGroup() << " " << d->GetElement() - // << std::endl; } d=originalH->GetNextEntry(); diff --git a/Testing/TestCopyRescaleDicom.cxx b/Testing/TestCopyRescaleDicom.cxx index 9b29da1f..6a1d1521 100644 --- a/Testing/TestCopyRescaleDicom.cxx +++ b/Testing/TestCopyRescaleDicom.cxx @@ -3,8 +3,8 @@ Program: gdcm Module: $RCSfile: TestCopyRescaleDicom.cxx,v $ Language: C++ - Date: $Date: 2004/12/07 16:55:56 $ - Version: $Revision: 1.1 $ + Date: $Date: 2004/12/07 18:16:40 $ + 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 @@ -59,9 +59,19 @@ int CopyRescaleDicom(std::string const & filename, originalH->Initialize(); gdcm::DocEntry* d = originalH->GetNextEntry(); + // Copy of the header content while(d) { - if ( gdcm::ValEntry* v = dynamic_cast(d) ) + if ( gdcm::BinEntry* b = dynamic_cast(d) ) + { + copyH->ReplaceOrCreateByNumber( + b->GetBinArea(), + b->GetLength(), + b->GetGroup(), + b->GetElement(), + b->GetVR() ); + } + else if ( gdcm::ValEntry* v = dynamic_cast(d) ) { copyH->ReplaceOrCreateByNumber( v->GetValue(), @@ -69,6 +79,10 @@ int CopyRescaleDicom(std::string const & filename, v->GetElement(), v->GetVR() ); } + else + { + // We skip pb of SQ recursive exploration + } d=originalH->GetNextEntry(); } @@ -79,43 +93,38 @@ int CopyRescaleDicom(std::string const & filename, size_t dataSize = original->GetImageDataSize(); uint8_t* imageData = original->GetImageData(); - size_t rescaleSize = dataSize / 2; -#ifdef VERSION_1 - uint8_t *rescaleImage = new uint8_t[dataSize]; -#endif - - //2 case now, if 16 bits input then try to downscale to 8bits just for - //fun: + size_t rescaleSize; + uint8_t *rescaleImage; const std::string & bitsStored = originalH->GetEntryByNumber(0x0028,0x0101); -// std::cout << "BitsStored: " << bitsStored << std::endl; - if( bitsStored == "16" ) { - uint16_t* imageData16 = (uint16_t*)original->GetImageData(); + std::cout << "Rescale..."; copyH->ReplaceOrCreateByNumber( "8", 0x0028, 0x0100); // BitsAllocated copyH->ReplaceOrCreateByNumber( "8", 0x0028, 0x0101); // BitsStored copyH->ReplaceOrCreateByNumber( "7", 0x0028, 0x0102); // HighBit copyH->ReplaceOrCreateByNumber( "0", 0x0028, 0x0103); //Pixel Representation // We assume the value were from 0 to uint16_t max + rescaleSize = dataSize / 2; + rescaleImage = new uint8_t[dataSize]; + + uint16_t* imageData16 = (uint16_t*)original->GetImageData(); for(unsigned int i=0; iSetImageData(rescaleImage, rescaleSize); -#endif } else { - copy->SetImageData(imageData, dataSize); + std::cout << "Same..."; + rescaleSize = dataSize; + rescaleImage = new uint8_t[dataSize]; + memcpy(rescaleImage,original->GetImageData(),dataSize); } + copy->SetImageData(rescaleImage, rescaleSize); + //////////////// Step 3: std::cout << "3..."; copy->SetWriteModeToRGB(); @@ -128,6 +137,7 @@ int CopyRescaleDicom(std::string const & filename, delete copy; delete originalH; delete copyH; + delete[] rescaleImage; return 1; } @@ -147,6 +157,7 @@ int CopyRescaleDicom(std::string const & filename, delete original; delete originalH; + delete[] rescaleImage; return 1; } @@ -156,7 +167,27 @@ int CopyRescaleDicom(std::string const & filename, size_t dataSizeWritten = copy->GetImageDataSize(); uint8_t* imageDataWritten = copy->GetImageData(); - if (dataSize != dataSizeWritten) + if (originalH->GetXSize() != copy->GetHeader()->GetXSize() || + originalH->GetYSize() != copy->GetHeader()->GetYSize() || + originalH->GetZSize() != copy->GetHeader()->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; + delete original; + delete copy; + delete originalH; + delete[] rescaleImage; + + return 1; + } + + if (rescaleSize != dataSizeWritten) { std::cout << " Failed" << std::endl << " Pixel areas lengths differ: " @@ -165,11 +196,12 @@ int CopyRescaleDicom(std::string const & filename, delete original; delete copy; delete originalH; + delete[] rescaleImage; return 1; } - if (int res = memcmp(imageData, imageDataWritten, dataSize) !=0) + if (int res = memcmp(rescaleImage, imageDataWritten, rescaleSize) !=0) { (void)res; std::cout << " Failed" << std::endl @@ -178,6 +210,7 @@ int CopyRescaleDicom(std::string const & filename, delete original; delete copy; delete originalH; + delete[] rescaleImage; return 1; } @@ -186,9 +219,7 @@ int CopyRescaleDicom(std::string const & filename, delete original; delete copy; delete originalH; -#ifdef VERSION_1 delete[] rescaleImage; -#endif return 0; }