From 62946e7406184480447cc7170f4b0edb394b9d64 Mon Sep 17 00:00:00 2001 From: regrain Date: Tue, 23 Nov 2004 11:14:13 +0000 Subject: [PATCH] * src/gdcmDocEntryArchive.cxx : complete the print function, that prints all replaced DocEntry's * src/gdcmFile.[h|cxx] : remove all changes of the header when getting datas. Now, each needed DocEntry to modify is duplicated, modified and inserted to the header using DocEntryArchive. Thus, after save, we can restore the header initial state. -- BeNours --- ChangeLog | 8 ++ src/gdcmDocEntryArchive.cxx | 12 ++- src/gdcmFile.cxx | 154 ++++++++++++++++++++++++++++++------ src/gdcmFile.h | 20 +++-- 4 files changed, 160 insertions(+), 34 deletions(-) diff --git a/ChangeLog b/ChangeLog index 15d4ca7d..f4cff36d 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,11 @@ +2004-11-23 Benoit Regrain + * src/gdcmDocEntryArchive.cxx : complete the print function, that prints + all replaced DocEntry's + * src/gdcmFile.[h|cxx] : remove all changes of the header when getting datas. + Now, each needed DocEntry to modify is duplicated, modified and inserted + to the header using DocEntryArchive. Thus, after save, we can restore the + header initial state. + 2004-11-22 Benoit Regrain * src/gdcmFile.h : fix compilation errors on zorglub linuc computer diff --git a/src/gdcmDocEntryArchive.cxx b/src/gdcmDocEntryArchive.cxx index 8ee46339..263f8a75 100644 --- a/src/gdcmDocEntryArchive.cxx +++ b/src/gdcmDocEntryArchive.cxx @@ -3,8 +3,8 @@ Program: gdcm Module: $RCSfile: gdcmDocEntryArchive.cxx,v $ Language: C++ - Date: $Date: 2004/11/19 18:49:39 $ - Version: $Revision: 1.1 $ + Date: $Date: 2004/11/23 11:14:13 $ + 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 @@ -49,6 +49,14 @@ DocEntryArchive::~DocEntryArchive() */ void DocEntryArchive::Print(std::ostream &os) { + os << "Elements in archives :" << std::endl; + for(TagDocEntryHT::iterator it = Archive.begin(); + it!=Archive.end(); + ++it) + { + if(it->second) + it->second->Print(os); + } } //----------------------------------------------------------------------------- diff --git a/src/gdcmFile.cxx b/src/gdcmFile.cxx index 94c6efcb..d198c1c9 100644 --- a/src/gdcmFile.cxx +++ b/src/gdcmFile.cxx @@ -3,8 +3,8 @@ Program: gdcm Module: $RCSfile: gdcmFile.cxx,v $ Language: C++ - Date: $Date: 2004/11/19 18:49:39 $ - Version: $Revision: 1.158 $ + Date: $Date: 2004/11/23 11:14:13 $ + Version: $Revision: 1.159 $ Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de l'Image). All rights reserved. See Doc/License.txt or @@ -75,7 +75,7 @@ File::File(std::string const & filename ) */ void File::Initialise() { - WriteMode = WMODE_NATIVE; + WriteMode = WMODE_DECOMPRESSED; WriteType = WTYPE_IMPL_VR; PixelConverter = NULL; //just in case Archive = NULL; @@ -336,7 +336,7 @@ uint8_t* File::GetImageData() pixelData = PixelConverter->GetDecompressed(); } -// PIXELCONVERT CLEANME +/*// PIXELCONVERT CLEANME // Restore the header in a disk-consistent state // (if user asks twice to get the pixels from disk) if ( PixelRead != -1 ) // File was "read" before @@ -391,7 +391,7 @@ uint8_t* File::GetImageData() // We say the value *is* loaded. SetPixelData(pixelData); -// END PIXELCONVERT CLEANME +// END PIXELCONVERT CLEANME*/ return pixelData; } @@ -473,7 +473,7 @@ uint8_t* File::GetImageDataRaw () return 0; } -// PIXELCONVERT CLEANME +/*// PIXELCONVERT CLEANME // Restore the header in a disk-consistent state // (if user asks twice to get the pixels from disk) if ( PixelRead != -1 ) // File was "read" before @@ -503,7 +503,7 @@ uint8_t* File::GetImageDataRaw () SetPixelData(decompressed); PixelRead = 1; // PixelRaw -// END PIXELCONVERT CLEANME +// END PIXELCONVERT CLEANME*/ return decompressed; } @@ -673,6 +673,19 @@ bool File::WriteBase (std::string const & fileName, FileType type) fp1->write("DICM", 4); } + switch(WriteMode) + { + case WMODE_NATIVE : + SetWriteToNative(); + break; + case WMODE_DECOMPRESSED : + SetWriteToDecompressed(); + break; + case WMODE_RGB : + SetWriteToRGB(); + break; + } + // -------------------------------------------------------------- // Special Patch to allow gdcm to re-write ACR-LibIDO formated images // @@ -686,12 +699,7 @@ bool File::WriteBase (std::string const & fileName, FileType type) std::string rows, columns; if ( HeaderInternal->GetFileType() == ACR_LIBIDO) { - SetToLibido(); - //rows = HeaderInternal->GetEntryByNumber(0x0028, 0x0010); - //columns = HeaderInternal->GetEntryByNumber(0x0028, 0x0011); - - //HeaderInternal->SetEntryByNumber(columns, 0x0028, 0x0010); - //HeaderInternal->SetEntryByNumber(rows , 0x0028, 0x0011); + SetWriteToLibido(); } // ----------------- End of Special Patch ---------------- @@ -722,11 +730,13 @@ bool File::WriteBase (std::string const & fileName, FileType type) if ( HeaderInternal->GetFileType() == ACR_LIBIDO ) { - RestoreFromLibido(); - //HeaderInternal->SetEntryByNumber(rows , 0x0028, 0x0010); - //HeaderInternal->SetEntryByNumber(columns, 0x0028, 0x0011); + RestoreWriteFromLibido(); } // ----------------- End of Special Patch ---------------- + + RestoreWrite(); + + fp1->close (); delete fp1; @@ -761,23 +771,82 @@ void File::SetPixelData(uint8_t* data) } } -void File::SetToRAW() +void File::SetWriteToNative() { +// Nothing to do } -void File::SetToRGB() +void File::SetWriteToDecompressed() { +// if (( !HeaderInternal->HasLUT() ) || (!PixelConverter->BuildRGBImage())) + if(HeaderInternal->HasLUT() && PixelConverter->BuildRGBImage()) + { + SetWriteToRGB(); + } + else + { + ValEntry* photInt = CopyValEntry(0x0028,0x0004); + photInt->SetValue("MONOCHROME1 "); + photInt->SetLength(12); + + BinEntry* pixel = CopyBinEntry(GetHeader()->GetGrPixel(),GetHeader()->GetNumPixel()); + pixel->SetValue(GDCM_BINLOADED); + pixel->SetBinArea(PixelConverter->GetDecompressed(),false); + pixel->SetLength(PixelConverter->GetDecompressedSize()); + + Archive->Push(photInt); + Archive->Push(pixel); + } +/* else + { + SetWriteToRGB(); + } */ +} + +void File::SetWriteToRGB() +{ + if(PixelConverter->BuildRGBImage()) + { + ValEntry* spp = CopyValEntry(0x0028,0x0002); + spp->SetValue("3 "); + spp->SetLength(2); + + ValEntry* photInt = CopyValEntry(0x0028,0x0004); + photInt->SetValue("RGB "); + photInt->SetLength(4); + + ValEntry* planConfig = CopyValEntry(0x0028,0x0006); + planConfig->SetValue("0 "); + planConfig->SetLength(2); + + BinEntry* pixel = CopyBinEntry(GetHeader()->GetGrPixel(),GetHeader()->GetNumPixel()); + pixel->SetValue(GDCM_BINLOADED); + pixel->SetBinArea(PixelConverter->GetRGB(),false); + pixel->SetLength(PixelConverter->GetRGBSize()); + + Archive->Push(spp); + Archive->Push(photInt); + Archive->Push(planConfig); + Archive->Push(pixel); + } + else + { + SetWriteToDecompressed(); + } } -void File::Restore() +void File::RestoreWrite() { + Archive->Restore(0x0028,0x0002); + Archive->Restore(0x0028,0x0004); + Archive->Restore(0x0028,0x0006); + Archive->Restore(GetHeader()->GetGrPixel(),GetHeader()->GetNumPixel()); } -void File::SetToLibido() +void File::SetWriteToLibido() { ValEntry *oldRow = dynamic_cast(HeaderInternal->GetDocEntryByNumber(0x0028, 0x0010)); ValEntry *oldCol = dynamic_cast(HeaderInternal->GetDocEntryByNumber(0x0028, 0x0011)); - if( oldRow && oldCol ) { @@ -797,10 +866,47 @@ void File::SetToLibido() } } -void File::RestoreFromLibido() +void File::RestoreWriteFromLibido() +{ + Archive->Restore(0x0028,0x0010); + Archive->Restore(0x0028,0x0011); +} + +ValEntry* File::CopyValEntry(uint16_t group,uint16_t element) +{ + DocEntry* oldE = HeaderInternal->GetDocEntryByNumber(group, element); + ValEntry* newE; + + if(oldE) + { + newE = new ValEntry(oldE->GetDictEntry()); + newE->Copy(oldE); + } + else + { + newE = GetHeader()->NewValEntryByNumber(group,element); + } + + return(newE); +} + +BinEntry* File::CopyBinEntry(uint16_t group,uint16_t element) { - Archive->Restore(0x0028, 0x0010); - Archive->Restore(0x0028, 0x0011); + DocEntry* oldE = HeaderInternal->GetDocEntryByNumber(group, element); + BinEntry* newE; + + if(oldE) + { + newE = new BinEntry(oldE->GetDictEntry()); + newE->Copy(oldE); + } + else + { + newE = GetHeader()->NewBinEntryByNumber(group,element); + } + + + return(newE); } //----------------------------------------------------------------------------- diff --git a/src/gdcmFile.h b/src/gdcmFile.h index 4a1ffa52..f5ba8119 100644 --- a/src/gdcmFile.h +++ b/src/gdcmFile.h @@ -3,8 +3,8 @@ Program: gdcm Module: $RCSfile: gdcmFile.h,v $ Language: C++ - Date: $Date: 2004/11/23 09:13:26 $ - Version: $Revision: 1.72 $ + Date: $Date: 2004/11/23 11:14:13 $ + Version: $Revision: 1.73 $ Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de l'Image). All rights reserved. See Doc/License.txt or @@ -108,12 +108,16 @@ public: protected: bool WriteBase(std::string const& fileName, FileType type); - void SetToRAW(); - void SetToRGB(); - void Restore(); + void SetWriteToNative(); + void SetWriteToDecompressed(); + void SetWriteToRGB(); + void RestoreWrite(); - void SetToLibido(); - void RestoreFromLibido(); + void SetWriteToLibido(); + void RestoreWriteFromLibido(); + + ValEntry* CopyValEntry(uint16_t group,uint16_t element); + BinEntry* CopyBinEntry(uint16_t group,uint16_t element); private: void Initialise(); @@ -139,7 +143,7 @@ private: /// Wether already parsed or not bool Parsed; - + /// Utility pixel converter PixelConvert* PixelConverter; -- 2.48.1