From: regrain Date: Fri, 19 Nov 2004 18:49:38 +0000 (+0000) Subject: * src/gdcmDocEntry.cxx : remove the copy of the DictEntry... there isn't X-Git-Tag: Version1.0.bp~580 X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=commitdiff_plain;h=3c25b6a04715c20b3680bca5447b4f10add258fd;p=gdcm.git * src/gdcmDocEntry.cxx : remove the copy of the DictEntry... there isn't correct to copy it. The DictEntry is specified at the DocEntry creation, then, it musn't change in the time. * src/gdcmDocEntryArchive.[h|cxx] : new class. It's goal is to change the header correctly. At this time, the change is only made for the first level of the Document. In the future, it might consider sequences. The change is made by replacing a DocEntry by an other that is created outside the class. The old value is kept. When we restore the header status, the added DocEntry is deleted and replaced by the old value. * src/gdcmElementSet.h : Set the DocEntryArchive like friend. * src/gdcmFile.[h|cxx] : Use the gdcmDocEntryArchive. Add methods to set the write type to explicit VR, implicit VR or ACR. Add methods to set the write mode to native, decompressed or RGB (but not used at this time) -- BeNours --- diff --git a/ChangeLog b/ChangeLog index dc6b458a..4c0d5b36 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,18 @@ +2004-11-19 Benoit Regrain + * src/gdcmDocEntry.cxx : remove the copy of the DictEntry... there isn't + correct to copy it. The DictEntry is specified at the DocEntry creation, + then, it musn't change in the time. + * src/gdcmDocEntryArchive.[h|cxx] : new class. It's goal is to change the + header correctly. At this time, the change is only made for the first + level of the Document. In the future, it might consider sequences. + The change is made by replacing a DocEntry by an other that is created + outside the class. The old value is kept. When we restore the header + status, the added DocEntry is deleted and replaced by the old value. + * src/gdcmElementSet.h : Set the DocEntryArchive like friend. + * src/gdcmFile.[h|cxx] : Use the gdcmDocEntryArchive. Add methods to + set the write type to explicit VR, implicit VR or ACR. Add methods to set + the write mode to native, decompressed or RGB (but not used at this time) + 2004-11-15 Benoit Regrain * src/gdcmSeqEntry.cxx : add initialisation of variable SeqTerm * src/gdcmDocument.cxx : add delete of DocEntry's to remove some memory leaks diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 97dad5ea..b52f680a 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -25,6 +25,7 @@ SET(libgdcm_la_SOURCES gdcmDictSet.cxx gdcmDirList.cxx gdcmDocEntry.cxx + gdcmDocEntryArchive.cxx gdcmDocEntrySet.cxx gdcmDocument.cxx gdcmElementSet.cxx diff --git a/src/gdcmDocEntry.cxx b/src/gdcmDocEntry.cxx index 5dfb6a3a..9a1f4112 100644 --- a/src/gdcmDocEntry.cxx +++ b/src/gdcmDocEntry.cxx @@ -3,8 +3,8 @@ Program: gdcm Module: $RCSfile: gdcmDocEntry.cxx,v $ Language: C++ - Date: $Date: 2004/11/10 18:27:23 $ - Version: $Revision: 1.31 $ + Date: $Date: 2004/11/19 18:49:39 $ + Version: $Revision: 1.32 $ Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de l'Image). All rights reserved. See Doc/License.txt or @@ -246,7 +246,7 @@ uint32_t DocEntry::GetFullLength() */ void DocEntry::Copy (DocEntry* e) { - DicomDict = e->DicomDict; +// DicomDict = e->DicomDict; UsableLength = e->UsableLength; ReadLength = e->ReadLength; ImplicitVR = e->ImplicitVR; diff --git a/src/gdcmDocEntryArchive.cxx b/src/gdcmDocEntryArchive.cxx new file mode 100644 index 00000000..8ee46339 --- /dev/null +++ b/src/gdcmDocEntryArchive.cxx @@ -0,0 +1,142 @@ +/*========================================================================= + + Program: gdcm + Module: $RCSfile: gdcmDocEntryArchive.cxx,v $ + Language: C++ + Date: $Date: 2004/11/19 18:49:39 $ + Version: $Revision: 1.1 $ + + Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de + l'Image). All rights reserved. See Doc/License.txt or + http://www.creatis.insa-lyon.fr/Public/Gdcm/License.html for details. + + This software is distributed WITHOUT ANY WARRANTY; without even + the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + PURPOSE. See the above copyright notices for more information. + +=========================================================================*/ + +#include "gdcmDocEntryArchive.h" +#include "gdcmDebug.h" + +#include + +namespace gdcm +{ +//----------------------------------------------------------------------------- +/** + * \brief Constructor + */ +DocEntryArchive::DocEntryArchive(Header *header): + HeaderHT(header->TagHT) +{ +} + +//----------------------------------------------------------------------------- +/** + * \brief Destructor + */ +DocEntryArchive::~DocEntryArchive() +{ + ClearArchive(); +} + +//----------------------------------------------------------------------------- +// Print +/** + * \brief Print all + * @param os The output stream to be written to. + */ +void DocEntryArchive::Print(std::ostream &os) +{ +} + +//----------------------------------------------------------------------------- +// Public +/** + * \brief Replace in the Header a DocEntry by the new DocEntry. The last + * DocEntry is kept in archieve + * @param newEntry New entry to substitute to an other entry of the Header + * @return FALSE when an other DocEntry is already archieved with the same + * generalized key, TRUE otherwise + */ +bool DocEntryArchive::Push(DocEntry *newEntry) +{ + if(!newEntry) + return(false); + + uint16_t gr = newEntry->GetDictEntry()->GetGroup(); + uint16_t elt = newEntry->GetDictEntry()->GetElement(); + std::string key = DictEntry::TranslateToKey(gr,elt); + + if( Archive.find(key)==Archive.end() ) + { + // Save the old DocEntry if any + TagDocEntryHT::iterator it = HeaderHT.find(key); + if( it!=HeaderHT.end() ) + Archive[key] = it->second; + else + Archive[key] = NULL; + + // Set the new DocEntry + HeaderHT[key] = newEntry; + + return(true); + } + return(false); +} + +/** + * \brief Restore in the Header the DocEntry that have the generalized key. + * The old entry is destroyed. + * @param key Key of the DocEntry to restore + * @return FALSE when the generalized key isn't in the archieve, + * TRUE otherwise + */ +bool DocEntryArchive::Restore(uint16_t group,uint16_t element) +{ + std::string key=DictEntry::TranslateToKey(group,element); + + TagDocEntryHT::iterator restoreIt=Archive.find(key); + if( restoreIt!=Archive.end() ) + { + TagDocEntryHT::iterator restorePos = HeaderHT.find(key); + if( restoreIt!=HeaderHT.end() ) + delete restorePos->second; + + if( Archive[key] ) + HeaderHT[key] = Archive[key]; + else + HeaderHT.erase(restorePos); + + Archive.erase(restoreIt); + + return(true); + } + return(false); +} + +/** + * \brief Remove all DocEntry that are in the archive. The entries aren't + * restored but only destroyed. + */ +void DocEntryArchive::ClearArchive(void) +{ + for(TagDocEntryHT::iterator it = Archive.begin(); + it!=Archive.end(); + ++it) + { + delete it->second; + } + Archive.clear(); +} + +//----------------------------------------------------------------------------- +// Protected + +//----------------------------------------------------------------------------- +// Private + +//----------------------------------------------------------------------------- + +} // end namespace gdcm diff --git a/src/gdcmDocEntryArchive.h b/src/gdcmDocEntryArchive.h new file mode 100644 index 00000000..99bdaea4 --- /dev/null +++ b/src/gdcmDocEntryArchive.h @@ -0,0 +1,59 @@ +/*========================================================================= + + Program: gdcm + Module: $RCSfile: gdcmDocEntryArchive.h,v $ + Language: C++ + Date: $Date: 2004/11/19 18:49:39 $ + Version: $Revision: 1.1 $ + + Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de + l'Image). All rights reserved. See Doc/License.txt or + http://www.creatis.insa-lyon.fr/Public/Gdcm/License.html for details. + + This software is distributed WITHOUT ANY WARRANTY; without even + the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + PURPOSE. See the above copyright notices for more information. + +=========================================================================*/ + +#ifndef GDCMDOCENTRYARCHIVE_H +#define GDCMDOCENTRYARCHIVE_H + +#include "gdcmCommon.h" +#include "gdcmHeader.h" + +namespace gdcm +{ + +//----------------------------------------------------------------------------- +/* + * /brief Container + * + * It's goal is to change the Header correctly. At this time, the change is + * only made for the first level of the Document. In the future, it might + * consider sequences. + * The change is made by replacing a DocEntry by an other that is created + * outside the class. The old value is kept. When we restore the header + * status, the added DocEntry is deleted and replaced by the old value. + */ +class GDCM_EXPORT DocEntryArchive +{ +public: + DocEntryArchive(Header *header); + ~DocEntryArchive(); + + void Print(std::ostream &os = std::cout); + + bool Push(DocEntry *newEntry); + bool Restore(uint16_t group,uint16_t element); + + void ClearArchive(void); + +private: + TagDocEntryHT &HeaderHT; + TagDocEntryHT Archive; +}; +} // end namespace gdcm + +//----------------------------------------------------------------------------- +#endif diff --git a/src/gdcmElementSet.h b/src/gdcmElementSet.h index c1da9457..926bec2c 100644 --- a/src/gdcmElementSet.h +++ b/src/gdcmElementSet.h @@ -3,8 +3,8 @@ Program: gdcm Module: $RCSfile: gdcmElementSet.h,v $ Language: C++ - Date: $Date: 2004/10/25 04:47:43 $ - Version: $Revision: 1.21 $ + Date: $Date: 2004/11/19 18:49:39 $ + Version: $Revision: 1.22 $ Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de l'Image). All rights reserved. See Doc/License.txt or @@ -61,6 +61,7 @@ private: friend class Document; friend class DicomDir; //For accessing private TagHT + friend class DocEntryArchive; //For accessing private TagHT }; } // end namespace gdcm //----------------------------------------------------------------------------- diff --git a/src/gdcmFile.cxx b/src/gdcmFile.cxx index 837df465..94c6efcb 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/16 16:20:23 $ - Version: $Revision: 1.157 $ + Date: $Date: 2004/11/19 18:49:39 $ + Version: $Revision: 1.158 $ 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,11 @@ File::File(std::string const & filename ) */ void File::Initialise() { + WriteMode = WMODE_NATIVE; + WriteType = WTYPE_IMPL_VR; PixelConverter = NULL; //just in case + Archive = NULL; + if ( HeaderInternal->IsReadable() ) { ImageDataSizeRaw = ComputeDecompressedPixelDataSizeFromHeader(); @@ -90,7 +94,10 @@ void File::Initialise() PixelConverter = new PixelConvert; PixelConverter->GrabInformationsFromHeader( HeaderInternal ); + + Archive = new DocEntryArchive( HeaderInternal ); } + SaveInitialValues(); } @@ -101,6 +108,15 @@ void File::Initialise() */ File::~File() { + if( PixelConverter ) + { + delete PixelConverter; + } + if( Archive ) + { + delete Archive; + } + if( SelfHeader ) { delete HeaderInternal; @@ -108,10 +124,6 @@ File::~File() HeaderInternal = 0; DeleteInitialValues(); - if( PixelConverter ) - { - delete PixelConverter; - } } /** @@ -120,7 +132,6 @@ File::~File() */ void File::SaveInitialValues() { - PixelRead = -1; // no ImageData read yet. LastAllocatedPixelDataLength = 0; Pixel_Data = 0; @@ -489,12 +500,6 @@ uint8_t* File::GetImageDataRaw () } // We say the value *is* loaded. -/* GetHeader()->SetEntryByNumber( GDCM_BINLOADED, - GetHeader()->GetGrPixel(), GetHeader()->GetNumPixel()); - - // will be 7fe0, 0010 in standard cases - GetHeader()->SetEntryBinAreaByNumber( decompressed, - GetHeader()->GetGrPixel(), GetHeader()->GetNumPixel());*/ SetPixelData(decompressed); PixelRead = 1; // PixelRaw @@ -582,7 +587,8 @@ bool File::WriteRawData(std::string const & fileName) bool File::WriteDcmImplVR (std::string const & fileName) { - return WriteBase(fileName, ImplicitVR); + SetWriteTypeToDcmImplVR(); + return Write(fileName); } /** @@ -595,7 +601,8 @@ bool File::WriteDcmImplVR (std::string const & fileName) bool File::WriteDcmExplVR (std::string const & fileName) { - return WriteBase(fileName, ExplicitVR); + SetWriteTypeToDcmExplVR(); + return Write(fileName); } /** @@ -614,7 +621,22 @@ bool File::WriteDcmExplVR (std::string const & fileName) bool File::WriteAcr (std::string const & fileName) { - return WriteBase(fileName, ACR); + SetWriteTypeToAcr(); + return Write(fileName); +} + +bool File::Write(std::string const& fileName) +{ + switch(WriteType) + { + case WTYPE_IMPL_VR: + return WriteBase(fileName,ImplicitVR); + case WTYPE_EXPL_VR: + return WriteBase(fileName,ExplicitVR); + case WTYPE_ACR: + return WriteBase(fileName,ACR); + } + return(false); } //----------------------------------------------------------------------------- @@ -664,11 +686,12 @@ bool File::WriteBase (std::string const & fileName, FileType type) std::string rows, columns; if ( HeaderInternal->GetFileType() == ACR_LIBIDO) { - rows = HeaderInternal->GetEntryByNumber(0x0028, 0x0010); - columns = HeaderInternal->GetEntryByNumber(0x0028, 0x0011); + SetToLibido(); + //rows = HeaderInternal->GetEntryByNumber(0x0028, 0x0010); + //columns = HeaderInternal->GetEntryByNumber(0x0028, 0x0011); - HeaderInternal->SetEntryByNumber(columns, 0x0028, 0x0010); - HeaderInternal->SetEntryByNumber(rows , 0x0028, 0x0011); + //HeaderInternal->SetEntryByNumber(columns, 0x0028, 0x0010); + //HeaderInternal->SetEntryByNumber(rows , 0x0028, 0x0011); } // ----------------- End of Special Patch ---------------- @@ -699,8 +722,9 @@ bool File::WriteBase (std::string const & fileName, FileType type) if ( HeaderInternal->GetFileType() == ACR_LIBIDO ) { - HeaderInternal->SetEntryByNumber(rows , 0x0028, 0x0010); - HeaderInternal->SetEntryByNumber(columns, 0x0028, 0x0011); + RestoreFromLibido(); + //HeaderInternal->SetEntryByNumber(rows , 0x0028, 0x0010); + //HeaderInternal->SetEntryByNumber(columns, 0x0028, 0x0011); } // ----------------- End of Special Patch ---------------- fp1->close (); @@ -719,6 +743,9 @@ uint8_t* File::GetLutRGBA() //----------------------------------------------------------------------------- // Private +/** + * \brief Set the pixel datas in the good entry of the Header + */ void File::SetPixelData(uint8_t* data) { GetHeader()->SetEntryByNumber( GDCM_BINLOADED, @@ -734,6 +761,48 @@ void File::SetPixelData(uint8_t* data) } } +void File::SetToRAW() +{ +} + +void File::SetToRGB() +{ +} + +void File::Restore() +{ +} + +void File::SetToLibido() +{ + ValEntry *oldRow = dynamic_cast(HeaderInternal->GetDocEntryByNumber(0x0028, 0x0010)); + ValEntry *oldCol = dynamic_cast(HeaderInternal->GetDocEntryByNumber(0x0028, 0x0011)); + + + if( oldRow && oldCol ) + { + std::string rows, columns; + + ValEntry *newRow=new ValEntry(oldRow->GetDictEntry()); + ValEntry *newCol=new ValEntry(oldCol->GetDictEntry()); + + newRow->Copy(oldCol); + newCol->Copy(oldRow); + + newRow->SetValue(oldCol->GetValue()); + newCol->SetValue(oldRow->GetValue()); + + Archive->Push(newRow); + Archive->Push(newCol); + } +} + +void File::RestoreFromLibido() +{ + Archive->Restore(0x0028, 0x0010); + Archive->Restore(0x0028, 0x0011); +} + //----------------------------------------------------------------------------- } // end namespace gdcm diff --git a/src/gdcmFile.h b/src/gdcmFile.h index 7c08ed37..c03b0fcd 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/16 16:20:23 $ - Version: $Revision: 1.69 $ + Date: $Date: 2004/11/19 18:49:39 $ + Version: $Revision: 1.70 $ Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de l'Image). All rights reserved. See Doc/License.txt or @@ -22,6 +22,7 @@ #include "gdcmCommon.h" #include "gdcmHeader.h" #include "gdcmPixelConvert.h" +#include "gdcmDocEntryArchive.h" namespace gdcm { @@ -33,6 +34,21 @@ namespace gdcm */ class GDCM_EXPORT File { +public: + typedef enum + { + WMODE_NATIVE, + WMODE_DECOMPRESSED, + WMODE_RGB, + } TWriteMode; + + typedef enum + { + WTYPE_IMPL_VR, + WTYPE_EXPL_VR, + WTYPE_ACR, + } TWriteType; + public: File( Header* header ); File( std::string const& filename ); @@ -65,6 +81,7 @@ public: bool WriteDcmImplVR(std::string const& fileName); bool WriteDcmExplVR(std::string const& fileName); bool WriteAcr (std::string const& fileName); + bool Write(std::string const& fileName); virtual bool SetEntryByNumber(std::string const& content, uint16_t group, uint16_t element) @@ -73,10 +90,31 @@ public: return true; } uint8_t* GetLutRGBA(); - + + // Write mode + void SetWriteModeToNative() { SetWriteMode(WMODE_NATIVE); }; + void SetWriteModeToDecompressed() { SetWriteMode(WMODE_DECOMPRESSED); }; + void SetWriteModeToRGB() { SetWriteMode(WMODE_RGB); }; + void SetWriteMode(TWriteMode mode) { WriteMode = mode; }; + TWriteMode GetWriteMode() { return WriteMode; }; + + // Write format + void SetWriteTypeToDcmImplVR() { SetWriteType(WTYPE_EXPL_VR); }; + void SetWriteTypeToDcmExplVR() { SetWriteType(WTYPE_EXPL_VR); }; + void SetWriteTypeToAcr() { SetWriteType(WTYPE_ACR); }; + void SetWriteType(TWriteType format) { WriteType = format; }; + TWriteType GetWriteType() { return WriteType; }; + protected: bool WriteBase(std::string const& fileName, FileType type); + void SetToRAW(); + void SetToRGB(); + void Restore(); + + void SetToLibido(); + void RestoreFromLibido(); + private: void Initialise(); @@ -105,6 +143,13 @@ private: /// Utility pixel converter PixelConvert* PixelConverter; + // Utility header archive + DocEntryArchive *Archive; + + // Write variables + TWriteMode WriteMode; + TWriteType WriteType; + /// FIXME // --------------- Will be moved to a PixelData class //