From: regrain Date: Thu, 25 Nov 2004 13:12:02 +0000 (+0000) Subject: * src/gdcmDocument.[h|cxx] : set the Transfert Syntax values to the header X-Git-Tag: Version1.0.bp~567 X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=commitdiff_plain;h=8da9df62c47908e7b9a67238a6c12b92ba6cae7a;p=gdcm.git * src/gdcmDocument.[h|cxx] : set the Transfert Syntax values to the header file, to be accessed by other files (like gdcmFile). Remove commented code. Move the change of the header to the gdcmFile, using the DocEntryArchive * src/gdcmHeader.[h|cxx] : the write is completely made in the Header. To be sure of that (and simplify calls), the Write of the header now gets a file name and not a file pointer (std::ifstream). * src/gdcmFile.[h|cxx] : apply the write file type to the header, using the DocEntryArchive. Remove all open of the written file -- BeNours --- diff --git a/ChangeLog b/ChangeLog index f582ac92..2a5ed92a 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,14 @@ +2004-11-25 Benoit Regrain + * src/gdcmDocument.[h|cxx] : set the Transfert Syntax values to the header + file, to be accessed by other files (like gdcmFile). Remove commented + code. Move the change of the header to the gdcmFile, using the + DocEntryArchive + * src/gdcmHeader.[h|cxx] : the write is completely made in the Header. + To be sure of that (and simplify calls), the Write of the header now + gets a file name and not a file pointer (std::ifstream). + * src/gdcmFile.[h|cxx] : apply the write file type to the header, using the + DocEntryArchive. Remove all open of the written file + 2004-11-25 Benoit Regrain * vtk/vtkGdcmReader.cxx : compilation bug fix for the vtk part diff --git a/src/gdcmDocument.cxx b/src/gdcmDocument.cxx index 73c7ecf7..48a0a32d 100644 --- a/src/gdcmDocument.cxx +++ b/src/gdcmDocument.cxx @@ -3,8 +3,8 @@ Program: gdcm Module: $RCSfile: gdcmDocument.cxx,v $ Language: C++ - Date: $Date: 2004/11/25 10:24:34 $ - Version: $Revision: 1.138 $ + Date: $Date: 2004/11/25 13:12:02 $ + Version: $Revision: 1.139 $ Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de l'Image). All rights reserved. See Doc/License.txt or @@ -36,41 +36,6 @@ namespace gdcm { -static const char *TransferSyntaxStrings[] = { - // Implicit VR Little Endian - "1.2.840.10008.1.2", - // Implicit VR Little Endian DLX G.E? - "1.2.840.113619.5.2", - // Explicit VR Little Endian - "1.2.840.10008.1.2.1", - // Deflated Explicit VR Little Endian - "1.2.840.10008.1.2.1.99", - // Explicit VR Big Endian - "1.2.840.10008.1.2.2", - // JPEG Baseline (Process 1) - "1.2.840.10008.1.2.4.50", - // JPEG Extended (Process 2 & 4) - "1.2.840.10008.1.2.4.51", - // JPEG Extended (Process 3 & 5) - "1.2.840.10008.1.2.4.52", - // JPEG Spectral Selection, Non-Hierarchical (Process 6 & 8) - "1.2.840.10008.1.2.4.53", - // JPEG Full Progression, Non-Hierarchical (Process 10 & 12) - "1.2.840.10008.1.2.4.55", - // JPEG Lossless, Non-Hierarchical (Process 14) - "1.2.840.10008.1.2.4.57", - // JPEG Lossless, Hierarchical, First-Order Prediction (Process 14, [Selection Value 1]) - "1.2.840.10008.1.2.4.70", - // JPEG 2000 Lossless - "1.2.840.10008.1.2.4.90", - // JPEG 2000 - "1.2.840.10008.1.2.4.91", - // RLE Lossless - "1.2.840.10008.1.2.5", - // Unknown - "Unknown Transfer Syntax" -}; - //----------------------------------------------------------------------------- // Refer to Document::CheckSwap() const unsigned int Document::HEADER_LENGTH_TO_READ = 256; @@ -497,34 +462,6 @@ void Document::Write(std::ofstream* fp, FileType filetype) fp->write("DICM", 4); } - if (filetype == ImplicitVR) - { - std::string ts = - Util::DicomString( TransferSyntaxStrings[ImplicitVRLittleEndian] ); - ReplaceOrCreateByNumber(ts, 0x0002, 0x0010); - - /// \todo Refer to standards on page 21, chapter 6.2 - /// "Value representation": values with a VR of UI shall be - /// padded with a single trailing null - /// in the following case we have to padd manually with a 0 - - SetEntryLengthByNumber(18, 0x0002, 0x0010); - } - - if (filetype == ExplicitVR) - { - std::string ts = - Util::DicomString( TransferSyntaxStrings[ExplicitVRLittleEndian] ); - ReplaceOrCreateByNumber(ts, 0x0002, 0x0010); //LEAK - - /// \todo Refer to standards on page 21, chapter 6.2 - /// "Value representation": values with a VR of UI shall be - /// padded with a single trailing null - /// Dans le cas suivant on doit pader manuellement avec un 0 - - SetEntryLengthByNumber(20, 0x0002, 0x0010); - } - /** * \todo rewrite later, if really usefull * - 'Group Length' element is optional in DICOM @@ -538,7 +475,6 @@ void Document::Write(std::ofstream* fp, FileType filetype) */ ElementSet::Write(fp, filetype); // This one is recursive - } /** @@ -1437,9 +1373,6 @@ void Document::ParseDES(DocEntrySet *set, long offset, } //////////////////// BinEntry or UNKOWN VR: -/* BinEntry* newBinEntry = - new BinEntry( newDocEntry->GetDictEntry() ); //LEAK - newBinEntry->Copy( newDocEntry );*/ BinEntry* newBinEntry = new BinEntry( newDocEntry ); //LEAK // When "this" is a Document the Key is simply of the @@ -2569,7 +2502,7 @@ bool Document::CheckSwap() // representation of a 32 bits integer. Hence the following dirty // trick : s32 = *((uint32_t *)(entCur)); - + switch( s32 ) { case 0x00040000 : diff --git a/src/gdcmDocument.h b/src/gdcmDocument.h index c36efc15..411d7d31 100644 --- a/src/gdcmDocument.h +++ b/src/gdcmDocument.h @@ -3,8 +3,8 @@ Program: gdcm Module: $RCSfile: gdcmDocument.h,v $ Language: C++ - Date: $Date: 2004/11/24 11:17:47 $ - Version: $Revision: 1.62 $ + Date: $Date: 2004/11/25 13:12:02 $ + Version: $Revision: 1.63 $ Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de l'Image). All rights reserved. See Doc/License.txt or @@ -60,6 +60,41 @@ enum TransferSyntaxType { UnknownTS }; +static const char *TransferSyntaxStrings[] = { + // Implicit VR Little Endian + "1.2.840.10008.1.2", + // Implicit VR Little Endian DLX G.E? + "1.2.840.113619.5.2", + // Explicit VR Little Endian + "1.2.840.10008.1.2.1", + // Deflated Explicit VR Little Endian + "1.2.840.10008.1.2.1.99", + // Explicit VR Big Endian + "1.2.840.10008.1.2.2", + // JPEG Baseline (Process 1) + "1.2.840.10008.1.2.4.50", + // JPEG Extended (Process 2 & 4) + "1.2.840.10008.1.2.4.51", + // JPEG Extended (Process 3 & 5) + "1.2.840.10008.1.2.4.52", + // JPEG Spectral Selection, Non-Hierarchical (Process 6 & 8) + "1.2.840.10008.1.2.4.53", + // JPEG Full Progression, Non-Hierarchical (Process 10 & 12) + "1.2.840.10008.1.2.4.55", + // JPEG Lossless, Non-Hierarchical (Process 14) + "1.2.840.10008.1.2.4.57", + // JPEG Lossless, Hierarchical, First-Order Prediction (Process 14, [Selection Value 1]) + "1.2.840.10008.1.2.4.70", + // JPEG 2000 Lossless + "1.2.840.10008.1.2.4.90", + // JPEG 2000 + "1.2.840.10008.1.2.4.91", + // RLE Lossless + "1.2.840.10008.1.2.5", + // Unknown + "Unknown Transfer Syntax" +}; + //----------------------------------------------------------------------------- /** * \brief Derived by both Header and DicomDir diff --git a/src/gdcmFile.cxx b/src/gdcmFile.cxx index 60c86429..4921affd 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/25 10:24:34 $ - Version: $Revision: 1.163 $ + Date: $Date: 2004/11/25 13:12:02 $ + Version: $Revision: 1.164 $ Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de l'Image). All rights reserved. See Doc/License.txt or @@ -17,6 +17,7 @@ =========================================================================*/ #include "gdcmFile.h" +#include "gdcmDocument.h" #include "gdcmDebug.h" #include "gdcmUtil.h" #include "gdcmBinEntry.h" @@ -396,14 +397,22 @@ uint8_t* File::GetLutRGBA() */ bool File::WriteBase (std::string const & fileName, FileType type) { - std::ofstream* fp1 = new std::ofstream(fileName.c_str(), - std::ios::out | std::ios::binary); - if (fp1 == NULL) + switch(type) { - dbg.Verbose(2, "Failed to open (write) File: " , fileName.c_str()); - return false; + case ImplicitVR: + SetWriteFileTypeToImplicitVR(); + break; + case ExplicitVR: + SetWriteFileTypeToExplicitVR(); + break; + case ACR: + SetWriteFileTypeToACR(); + break; + case ACR_LIBIDO: + SetWriteFileTypeToACRLibido(); + break; } - + switch(WriteMode) { case WMODE_NATIVE : @@ -431,10 +440,10 @@ bool File::WriteBase (std::string const & fileName, FileType type) }*/ // ----------------- End of Special Patch ---------------- - bool check=CheckWriteIntegrity(); + bool check = CheckWriteIntegrity(); if(check) { - HeaderInternal->Write(fp1,type); + check = HeaderInternal->Write(fileName,type); } // -------------------------------------------------------------- @@ -449,9 +458,7 @@ bool File::WriteBase (std::string const & fileName, FileType type) // ----------------- End of Special Patch ---------------- RestoreWrite(); - - fp1->close(); - delete fp1; + RestoreWriteFileType(); return check; } @@ -468,21 +475,38 @@ bool File::CheckWriteIntegrity() { if(Pixel_Data) { + int numberBitsAllocated = HeaderInternal->GetBitsAllocated(); + if ( numberBitsAllocated == 0 || numberBitsAllocated == 12 ) + { + numberBitsAllocated = 16; + } + + int decSize = HeaderInternal->GetXSize() + * HeaderInternal->GetYSize() + * HeaderInternal->GetZSize() + * ( numberBitsAllocated / 8 ) + * HeaderInternal->GetSamplesPerPixel(); + int rgbSize = decSize; + if( HeaderInternal->HasLUT() ) + rgbSize = decSize * 3; + switch(WriteMode) { case WMODE_NATIVE : break; case WMODE_DECOMPRESSED : - if(GetImageDataRawSize()!=ImageDataSize) + if( decSize!=ImageDataSize ) { - std::cerr<<"RAW : "<Restore(0x0028,0x1203); } +void File::SetWriteFileTypeToACR() +{ + Archive->Push(0x0002,0x0010); +} + +void File::SetWriteFileTypeToACRLibido() +{ + SetWriteFileTypeToACR(); +} + +void File::SetWriteFileTypeToExplicitVR() +{ + std::string ts = + Util::DicomString( TransferSyntaxStrings[ExplicitVRLittleEndian] ); + + ValEntry* tss = CopyValEntry(0x0002,0x0010); + tss->SetValue(ts); + tss->SetLength(ts.length()); + + Archive->Push(tss); +} + +void File::SetWriteFileTypeToImplicitVR() +{ + std::string ts = + Util::DicomString( TransferSyntaxStrings[ImplicitVRLittleEndian] ); + + ValEntry* tss = CopyValEntry(0x0002,0x0010); + tss->SetValue(ts); + tss->SetLength(ts.length()); +} + +void File::RestoreWriteFileType() +{ + Archive->Restore(0x0002,0x0010); +} + void File::SetWriteToLibido() { ValEntry *oldRow = dynamic_cast(HeaderInternal->GetDocEntryByNumber(0x0028, 0x0010)); diff --git a/src/gdcmFile.h b/src/gdcmFile.h index cf48b6d1..02eaae75 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/25 10:24:34 $ - Version: $Revision: 1.76 $ + Date: $Date: 2004/11/25 13:12:02 $ + Version: $Revision: 1.77 $ Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de l'Image). All rights reserved. See Doc/License.txt or @@ -111,6 +111,12 @@ protected: void SetWriteToRGB(); void RestoreWrite(); + void SetWriteFileTypeToACR(); + void SetWriteFileTypeToACRLibido(); + void SetWriteFileTypeToExplicitVR(); + void SetWriteFileTypeToImplicitVR(); + void RestoreWriteFileType(); + void SetWriteToLibido(); void RestoreWriteFromLibido(); @@ -126,7 +132,6 @@ private: void SetPixelData(uint8_t* data); private: - // members variables: /// Header to use to load the file diff --git a/src/gdcmHeader.cxx b/src/gdcmHeader.cxx index 84aea4d3..8371f3ce 100644 --- a/src/gdcmHeader.cxx +++ b/src/gdcmHeader.cxx @@ -3,8 +3,8 @@ Program: gdcm Module: $RCSfile: gdcmHeader.cxx,v $ Language: C++ - Date: $Date: 2004/11/23 17:12:25 $ - Version: $Revision: 1.205 $ + Date: $Date: 2004/11/25 13:12:02 $ + Version: $Revision: 1.206 $ Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de l'Image). All rights reserved. See Doc/License.txt or @@ -102,8 +102,16 @@ Header::~Header () * @param filetype Type of the File to be written * (ACR-NEMA, ExplicitVR, ImplicitVR) */ -void Header::Write(std::ofstream* fp,FileType filetype) +bool Header::Write(std::string fileName,FileType filetype) { + std::ofstream* fp = new std::ofstream(fileName.c_str(), + std::ios::out | std::ios::binary); + if (fp == NULL) + { + dbg.Verbose(2, "Failed to open (write) File: " , fileName.c_str()); + return false; + } + // Bits Allocated if ( GetEntryByNumber(0x0028,0x0100) == "12") { @@ -164,6 +172,11 @@ void Header::Write(std::ofstream* fp,FileType filetype) } } Document::Write(fp,filetype); + + fp->close(); + delete fp; + + return true; } //----------------------------------------------------------------------------- diff --git a/src/gdcmHeader.h b/src/gdcmHeader.h index d7d7d870..cbd36527 100644 --- a/src/gdcmHeader.h +++ b/src/gdcmHeader.h @@ -3,8 +3,8 @@ Program: gdcm Module: $RCSfile: gdcmHeader.h,v $ Language: C++ - Date: $Date: 2004/11/16 05:03:35 $ - Version: $Revision: 1.93 $ + Date: $Date: 2004/11/25 13:12:02 $ + Version: $Revision: 1.94 $ Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de l'Image). All rights reserved. See Doc/License.txt or @@ -172,7 +172,7 @@ public: /// Read (used in File) void SetImageDataSize(size_t expectedSize); - void Write(std::ofstream* fp, FileType filetype); + bool Write(std::string fileName, FileType filetype); /// Initialize DICOM header when none void InitializeDefaultHeader();