From d92357eba92c1e3b13172b58db4cd67289896fb1 Mon Sep 17 00:00:00 2001 From: malaterre Date: Wed, 10 Nov 2004 18:27:23 +0000 Subject: [PATCH] ENH: Commiting 1/2 patch from Jean Michel Rouet, for better DICOM writting support --- src/gdcmDocEntry.cxx | 9 +++++++-- src/gdcmDocument.cxx | 7 +++++-- src/gdcmFile.cxx | 6 +++--- src/gdcmHeader.cxx | 8 ++++---- src/gdcmPixelConvert.cxx | 6 +++--- src/gdcmSQItem.cxx | 16 ++++++++-------- src/gdcmUtil.cxx | 37 +++++++++++++++++++++++++++++++++++-- src/gdcmUtil.h | 6 ++++-- 8 files changed, 69 insertions(+), 26 deletions(-) diff --git a/src/gdcmDocEntry.cxx b/src/gdcmDocEntry.cxx index 46b77b93..5dfb6a3a 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/09 22:15:36 $ - Version: $Revision: 1.30 $ + Date: $Date: 2004/11/10 18:27:23 $ + Version: $Revision: 1.31 $ Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de l'Image). All rights reserved. See Doc/License.txt or @@ -43,6 +43,11 @@ DocEntry::DocEntry(DictEntry* in) DicomDict = in; SetKey( in->GetKey( ) ); Offset = 0 ; // To avoid further missprinting + + // init some variables + ReadLength = 0; + UsableLength = 0; + PrintLevel = 0; } //----------------------------------------------------------------------------- diff --git a/src/gdcmDocument.cxx b/src/gdcmDocument.cxx index f2c4fb95..df8bd9fc 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/10 16:13:18 $ - Version: $Revision: 1.120 $ + Date: $Date: 2004/11/10 18:27:23 $ + Version: $Revision: 1.121 $ Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de l'Image). All rights reserved. See Doc/License.txt or @@ -186,6 +186,8 @@ Document::Document() : ElementSet(-1) SetMaxSizeLoadEntry(MAX_SIZE_LOAD_ELEMENT_VALUE); Initialise(); + SwapCode = 0; + Filetype = ExplicitVR; PrintLevel = 1; // 'Medium' print level by default } @@ -416,6 +418,7 @@ FileType Document::GetFileType() */ std::ifstream* Document::OpenFile() { + if (Filename.length() == 0) return 0; if(Fp) { dbg.Verbose( 0, diff --git a/src/gdcmFile.cxx b/src/gdcmFile.cxx index 6276a5bc..955e0989 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/05 21:23:46 $ - Version: $Revision: 1.152 $ + Date: $Date: 2004/11/10 18:27:23 $ + Version: $Revision: 1.153 $ Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de l'Image). All rights reserved. See Doc/License.txt or @@ -513,7 +513,7 @@ uint8_t* File::GetDecompressed() // The decompressed image migth not be loaded yet: std::ifstream* fp = HeaderInternal->OpenFile(); PixelConverter->ReadAndDecompressPixelData( fp ); - HeaderInternal->CloseFile(); + if(fp) HeaderInternal->CloseFile(); decompressed = PixelConverter->GetDecompressed(); if ( ! decompressed ) { diff --git a/src/gdcmHeader.cxx b/src/gdcmHeader.cxx index 13e90a3e..bf44c55c 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/09 21:55:55 $ - Version: $Revision: 1.199 $ + Date: $Date: 2004/11/10 18:27:23 $ + Version: $Revision: 1.200 $ Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de l'Image). All rights reserved. See Doc/License.txt or @@ -373,12 +373,12 @@ float Header::GetZSpacing() // we assume slices join together // (no overlapping, no interslice gap) // if they don't, we're fucked up - return atof( strSliceThickness.c_str() ); + return (float)atof( strSliceThickness.c_str() ); } } else { - return atof( strSpacingBSlices.c_str() ); + return (float)atof( strSpacingBSlices.c_str() ); } } diff --git a/src/gdcmPixelConvert.cxx b/src/gdcmPixelConvert.cxx index 73ca0e8b..cf3c240a 100644 --- a/src/gdcmPixelConvert.cxx +++ b/src/gdcmPixelConvert.cxx @@ -3,8 +3,8 @@ Program: gdcm Module: $RCSfile: gdcmPixelConvert.cxx,v $ Language: C++ - Date: $Date: 2004/11/10 16:22:02 $ - Version: $Revision: 1.28 $ + Date: $Date: 2004/11/10 18:27:23 $ + Version: $Revision: 1.29 $ Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de l'Image). All rights reserved. See Doc/License.txt or @@ -902,7 +902,7 @@ void PixelConvert::GrabInformationsFromHeader( Header* header ) } } - header->CloseFile(); + if(fp) header->CloseFile(); } /** diff --git a/src/gdcmSQItem.cxx b/src/gdcmSQItem.cxx index d7c29e5e..166fd40a 100644 --- a/src/gdcmSQItem.cxx +++ b/src/gdcmSQItem.cxx @@ -3,8 +3,8 @@ Program: gdcm Module: $RCSfile: gdcmSQItem.cxx,v $ Language: C++ - Date: $Date: 2004/11/04 15:08:50 $ - Version: $Revision: 1.35 $ + Date: $Date: 2004/11/10 18:27:23 $ + Version: $Revision: 1.36 $ Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de l'Image). All rights reserved. See Doc/License.txt or @@ -109,13 +109,13 @@ void SQItem::Write(std::ofstream* fp, FileType filetype) binary_write( *fp, item[j]); // fffe e000 ffff ffff } - for (ListDocEntry::iterator i = DocEntries.begin(); - i != DocEntries.end(); - ++i) + for (ListDocEntry::iterator it = DocEntries.begin(); + it != DocEntries.end(); + ++it) { // we skip delimitors (start and end one) because // we force them as 'no length' - if ( (*i)->GetGroup() == 0xfffe ) + if ( (*it)->GetGroup() == 0xfffe ) { continue; } @@ -123,12 +123,12 @@ void SQItem::Write(std::ofstream* fp, FileType filetype) // Fix in order to make some MR PHILIPS images e-film readable // see gdcmData/gdcm-MR-PHILIPS-16-Multi-Seq.dcm: // we just *always* ignore spurious fffe|0000 tag ! - if ( (*i)->GetGroup() == 0xfffe && (*i)->GetElement() == 0x0000 ) + if ( (*it)->GetGroup() == 0xfffe && (*it)->GetElement() == 0x0000 ) { break; // FIXME : continue; ?!? } - (*i)->Write(fp, filetype); + (*it)->Write(fp, filetype); } //we force the writting of an 'Item Delimitation' item diff --git a/src/gdcmUtil.cxx b/src/gdcmUtil.cxx index ebb8191d..d0359f8b 100644 --- a/src/gdcmUtil.cxx +++ b/src/gdcmUtil.cxx @@ -3,8 +3,8 @@ Program: gdcm Module: $RCSfile: gdcmUtil.cxx,v $ Language: C++ - Date: $Date: 2004/11/05 20:23:14 $ - Version: $Revision: 1.60 $ + Date: $Date: 2004/11/10 18:27:24 $ + Version: $Revision: 1.61 $ Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de l'Image). All rights reserved. See Doc/License.txt or @@ -19,6 +19,11 @@ #include "gdcmUtil.h" #include "gdcmDebug.h" +// For GetCurrentDate, GetCurrentTime +#include +#include +#include + #include //only included in implementation file #include //only included in implementation file @@ -210,6 +215,34 @@ std::string Util::DicomString(const char* s) return r; } +/** + * \ingroup Util + * \brief Get the current date of the system in a dicom string + */ +std::string Util::GetCurrentDate() +{ + char tmp[512]; + time_t tloc; + time (&tloc); + strftime(tmp,512,"%Y%m%d", localtime(&tloc) ); + return tmp; +} + +/** + * \ingroup Util + * \brief Get the current time of the system in a dicom string + */ +std::string Util::GetCurrentTime() +{ + char tmp[512]; + time_t tloc; + time (&tloc); + strftime(tmp,512,"%H%M%S", localtime(&tloc) ); + return tmp; +} + + + /** * \ingroup Util * \brief Create a /DICOM/ string: diff --git a/src/gdcmUtil.h b/src/gdcmUtil.h index 110a7fad..76436936 100644 --- a/src/gdcmUtil.h +++ b/src/gdcmUtil.h @@ -3,8 +3,8 @@ Program: gdcm Module: $RCSfile: gdcmUtil.h,v $ Language: C++ - Date: $Date: 2004/11/09 11:21:32 $ - Version: $Revision: 1.41 $ + Date: $Date: 2004/11/10 18:27:24 $ + Version: $Revision: 1.42 $ Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de l'Image). All rights reserved. See Doc/License.txt or @@ -48,6 +48,8 @@ public: static std::string NormalizePath(std::string const & name); static std::string GetPath(std::string const &fullName); static std::string GetName(std::string const &fullName); + static std::string GetCurrentDate(); + static std::string GetCurrentTime(); static std::string DicomString(const char* s, size_t l); static std::string DicomString(const char* s); -- 2.48.1