From 66c8b2ef6c096d675afb963778604ed7ae72a78c Mon Sep 17 00:00:00 2001 From: jpr Date: Thu, 26 Jul 2007 08:36:49 +0000 Subject: [PATCH] We are no longer cheated by Elem belonging to group 0x0002, located inside a Sequence, when we ReWrite as Implicit VR. Thx to Mathieu for reporting the pb. --- src/gdcmDataEntry.cxx | 12 +++++++----- src/gdcmDataEntry.h | 7 ++++--- src/gdcmDicomDir.cxx | 8 ++++---- src/gdcmDicomDirMeta.cxx | 10 ++++++---- src/gdcmDicomDirMeta.h | 6 +++--- src/gdcmDicomDirPatient.cxx | 10 +++++----- src/gdcmDicomDirPatient.h | 6 +++--- src/gdcmDicomDirSerie.cxx | 12 ++++++------ src/gdcmDicomDirSerie.h | 6 +++--- src/gdcmDicomDirStudy.cxx | 12 ++++++------ src/gdcmDicomDirStudy.h | 6 +++--- src/gdcmDicomDirVisit.h | 5 ++--- src/gdcmDocEntry.cxx | 13 ++++++++----- src/gdcmDocEntry.h | 7 ++++--- src/gdcmDocEntrySet.h | 11 ++++++----- src/gdcmDocument.cxx | 16 ++++++++-------- src/gdcmElementSet.cxx | 27 +++++++++++++++++++++------ src/gdcmElementSet.h | 7 ++++--- src/gdcmFileHelper.cxx | 6 +++--- src/gdcmSQItem.cxx | 11 ++++++----- src/gdcmSQItem.h | 6 +++--- src/gdcmSeqEntry.cxx | 14 +++++++------- src/gdcmSeqEntry.h | 6 +++--- 23 files changed, 125 insertions(+), 99 deletions(-) diff --git a/src/gdcmDataEntry.cxx b/src/gdcmDataEntry.cxx index b46b6e77..182d7391 100644 --- a/src/gdcmDataEntry.cxx +++ b/src/gdcmDataEntry.cxx @@ -3,8 +3,8 @@ Program: gdcm Module: $RCSfile: gdcmDataEntry.cxx,v $ Language: C++ - Date: $Date: 2007/06/04 13:40:01 $ - Version: $Revision: 1.43 $ + Date: $Date: 2007/07/26 08:36:49 $ + Version: $Revision: 1.44 $ Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de l'Image). All rights reserved. See Doc/License.txt or @@ -544,13 +544,15 @@ void DataEntry::Copy(DocEntry *doc) } /** - * \brief Writes the 'value' area of a DataEntry + * \brief Writes the 'common part' + the 'value' area of a DataEntry * @param fp already open ofstream pointer * @param filetype type of the file (ACR, ImplicitVR, ExplicitVR, ...) */ -void DataEntry::WriteContent(std::ofstream *fp, FileType filetype) +void DataEntry::WriteContent(std::ofstream *fp, FileType filetype, + bool insideMetaElements) { - DocEntry::WriteContent(fp, filetype); + // writes the 'common part' + DocEntry::WriteContent(fp, filetype, insideMetaElements); if ( GetGroup() == 0xfffe ) { diff --git a/src/gdcmDataEntry.h b/src/gdcmDataEntry.h index d06093a9..2bae50a1 100644 --- a/src/gdcmDataEntry.h +++ b/src/gdcmDataEntry.h @@ -3,8 +3,8 @@ Program: gdcm Module: $RCSfile: gdcmDataEntry.h,v $ Language: C++ - Date: $Date: 2007/07/04 10:40:56 $ - Version: $Revision: 1.17 $ + Date: $Date: 2007/07/26 08:36:49 $ + Version: $Revision: 1.18 $ Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de l'Image). All rights reserved. See Doc/License.txt or @@ -51,7 +51,8 @@ public: void Print(std::ostream &os = std::cout, std::string const &indent = ""); // Write - virtual void WriteContent(std::ofstream *fp, FileType filetype); + virtual void WriteContent(std::ofstream *fp, FileType filetype, + bool insideMetaElements ); uint32_t ComputeFullLength(); // Set/Get data diff --git a/src/gdcmDicomDir.cxx b/src/gdcmDicomDir.cxx index 5a6a91c9..a6aa0ad9 100644 --- a/src/gdcmDicomDir.cxx +++ b/src/gdcmDicomDir.cxx @@ -3,8 +3,8 @@ Program: gdcm Module: $RCSfile: gdcmDicomDir.cxx,v $ Language: C++ - Date: $Date: 2007/05/23 14:18:08 $ - Version: $Revision: 1.193 $ + Date: $Date: 2007/07/26 08:36:49 $ + Version: $Revision: 1.194 $ Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de l'Image). All rights reserved. See Doc/License.txt or @@ -492,7 +492,7 @@ bool DicomDir::Write(std::string const &fileName) binary_write( *fp, "DICM"); DicomDirMeta *ptrMeta = GetMeta(); - ptrMeta->WriteContent(fp, ExplicitVR); + ptrMeta->WriteContent(fp, ExplicitVR, true); // force writing 0004|1220 [SQ ], that CANNOT exist within DicomDirMeta for(i=0;i<6;++i) @@ -504,7 +504,7 @@ bool DicomDir::Write(std::string const &fileName) cc != Patients.end(); ++cc ) { - (*cc)->WriteContent( fp, ExplicitVR ); + (*cc)->WriteContent( fp, ExplicitVR, false ); } // force writing Sequence Delimitation Item diff --git a/src/gdcmDicomDirMeta.cxx b/src/gdcmDicomDirMeta.cxx index 8dfdb628..37c66051 100644 --- a/src/gdcmDicomDirMeta.cxx +++ b/src/gdcmDicomDirMeta.cxx @@ -3,8 +3,8 @@ Program: gdcm Module: $RCSfile: gdcmDicomDirMeta.cxx,v $ Language: C++ - Date: $Date: 2007/05/23 14:18:08 $ - Version: $Revision: 1.37 $ + Date: $Date: 2007/07/26 08:36:49 $ + Version: $Revision: 1.38 $ Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de l'Image). All rights reserved. See Doc/License.txt or @@ -56,7 +56,8 @@ DicomDirMeta::~DicomDirMeta() * @param filetype type of the file (ImplicitVR, ExplicitVR, ...) * @return */ -void DicomDirMeta::WriteContent(std::ofstream *fp, FileType filetype) +void DicomDirMeta::WriteContent(std::ofstream *fp, FileType filetype, + bool insideMetaElements) { // 'File Meta Information Version' @@ -84,7 +85,8 @@ void DicomDirMeta::WriteContent(std::ofstream *fp, FileType filetype) i!= DocEntries.end(); ++i) { - (*i)->WriteContent(fp, filetype); + // true : we are in MetaElements + (*i)->WriteContent(fp, filetype, true); } } diff --git a/src/gdcmDicomDirMeta.h b/src/gdcmDicomDirMeta.h index dc467107..e7f8e26f 100644 --- a/src/gdcmDicomDirMeta.h +++ b/src/gdcmDicomDirMeta.h @@ -3,8 +3,8 @@ Program: gdcm Module: $RCSfile: gdcmDicomDirMeta.h,v $ Language: C++ - Date: $Date: 2007/05/23 14:18:08 $ - Version: $Revision: 1.22 $ + Date: $Date: 2007/07/26 08:36:49 $ + Version: $Revision: 1.23 $ Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de l'Image). All rights reserved. See Doc/License.txt or @@ -37,7 +37,7 @@ public: static DicomDirMeta *New(bool empty=false) {return new DicomDirMeta(empty);} virtual void Print(std::ostream &os = std::cout, std::string const &indent = "" ); - virtual void WriteContent(std::ofstream *fp, FileType t); + virtual void WriteContent(std::ofstream *fp, FileType t, bool insideMetaElements); int ComputeGroup0002Length( ); protected: diff --git a/src/gdcmDicomDirPatient.cxx b/src/gdcmDicomDirPatient.cxx index 616d182c..0e2e577a 100644 --- a/src/gdcmDicomDirPatient.cxx +++ b/src/gdcmDicomDirPatient.cxx @@ -3,8 +3,8 @@ Program: gdcm Module: $RCSfile: gdcmDicomDirPatient.cxx,v $ Language: C++ - Date: $Date: 2007/05/23 14:18:08 $ - Version: $Revision: 1.41 $ + Date: $Date: 2007/07/26 08:36:49 $ + 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 @@ -57,15 +57,15 @@ DicomDirPatient::~DicomDirPatient() * @param fp ofstream to write to * @param t Type of the File (explicit VR, implicitVR, ...) */ -void DicomDirPatient::WriteContent(std::ofstream *fp, FileType t) +void DicomDirPatient::WriteContent(std::ofstream *fp, FileType t, bool insideMetaElements) { - DicomDirObject::WriteContent(fp, t); + DicomDirObject::WriteContent(fp, t, false); for(ListDicomDirStudy::iterator cc = Studies.begin(); cc!= Studies.end(); ++cc ) { - (*cc)->WriteContent( fp, t ); + (*cc)->WriteContent( fp, t, false ); } } diff --git a/src/gdcmDicomDirPatient.h b/src/gdcmDicomDirPatient.h index 74345d8b..9b6dfaa9 100644 --- a/src/gdcmDicomDirPatient.h +++ b/src/gdcmDicomDirPatient.h @@ -3,8 +3,8 @@ Program: gdcm Module: $RCSfile: gdcmDicomDirPatient.h,v $ Language: C++ - Date: $Date: 2007/05/23 14:18:08 $ - Version: $Revision: 1.31 $ + Date: $Date: 2007/07/26 08:36:49 $ + 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 @@ -42,7 +42,7 @@ public: static DicomDirPatient *New(bool empty=false) {return new DicomDirPatient(empty);} void Print(std::ostream &os = std::cout, std::string const &indent = "" ); - void WriteContent(std::ofstream *fp, FileType t); + void WriteContent(std::ofstream *fp, FileType t, bool insideMetaElements); // Patient methods /// \brief Adds a new gdcmDicomDirStudy to the Patient diff --git a/src/gdcmDicomDirSerie.cxx b/src/gdcmDicomDirSerie.cxx index 97bd2594..1fe41dc3 100644 --- a/src/gdcmDicomDirSerie.cxx +++ b/src/gdcmDicomDirSerie.cxx @@ -3,8 +3,8 @@ Program: gdcm Module: $RCSfile: gdcmDicomDirSerie.cxx,v $ Language: C++ - Date: $Date: 2007/05/23 14:18:08 $ - Version: $Revision: 1.43 $ + Date: $Date: 2007/07/26 08:36:49 $ + Version: $Revision: 1.44 $ Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de l'Image). All rights reserved. See Doc/License.txt or @@ -58,21 +58,21 @@ DicomDirSerie::~DicomDirSerie() * @param fp ofstream to write to * @param t Type of the File (explicit VR, implicitVR, ...) */ -void DicomDirSerie::WriteContent(std::ofstream *fp, FileType t) +void DicomDirSerie::WriteContent(std::ofstream *fp, FileType t, bool insideMetaElements) { - DicomDirObject::WriteContent(fp, t); + DicomDirObject::WriteContent(fp, t, false); for(ListDicomDirImage::iterator cc = Images.begin(); cc!= Images.end(); ++cc ) { - (*cc)->WriteContent( fp, t ); + (*cc)->WriteContent( fp, t, false ); } for(ListDicomDirPrivate::iterator cc2 = Privates.begin(); cc2!= Privates.end(); ++cc2 ) { - (*cc2)->WriteContent( fp, t ); + (*cc2)->WriteContent( fp, t, false); } } diff --git a/src/gdcmDicomDirSerie.h b/src/gdcmDicomDirSerie.h index e1f535ae..e2fa2e8f 100644 --- a/src/gdcmDicomDirSerie.h +++ b/src/gdcmDicomDirSerie.h @@ -3,8 +3,8 @@ Program: gdcm Module: $RCSfile: gdcmDicomDirSerie.h,v $ Language: C++ - Date: $Date: 2007/05/23 14:18:08 $ - Version: $Revision: 1.34 $ + Date: $Date: 2007/07/26 08:36:49 $ + Version: $Revision: 1.35 $ Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de l'Image). All rights reserved. See Doc/License.txt or @@ -43,7 +43,7 @@ public: static DicomDirSerie *New(bool empty=false) {return new DicomDirSerie(empty);} void Print( std::ostream &os = std::cout, std::string const &indent = "" ); - void WriteContent( std::ofstream *fp, FileType t ); + void WriteContent( std::ofstream *fp, FileType t, bool insideMetaElements ); // 'Image' methods DicomDirImage *NewImage(); diff --git a/src/gdcmDicomDirStudy.cxx b/src/gdcmDicomDirStudy.cxx index 0353b078..e7f5cef2 100644 --- a/src/gdcmDicomDirStudy.cxx +++ b/src/gdcmDicomDirStudy.cxx @@ -3,8 +3,8 @@ Program: gdcm Module: $RCSfile: gdcmDicomDirStudy.cxx,v $ Language: C++ - Date: $Date: 2007/05/23 14:18:08 $ - Version: $Revision: 1.43 $ + Date: $Date: 2007/07/26 08:36:49 $ + Version: $Revision: 1.44 $ Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de l'Image). All rights reserved. See Doc/License.txt or @@ -58,22 +58,22 @@ DicomDirStudy::~DicomDirStudy() * @param t Type of the File (explicit VR, implicitVR, ...) * @return */ -void DicomDirStudy::WriteContent(std::ofstream *fp, FileType t) +void DicomDirStudy::WriteContent(std::ofstream *fp, FileType t, bool insideMetaElements) { - DicomDirObject::WriteContent(fp, t); + DicomDirObject::WriteContent(fp, t, false); for(ListDicomDirSerie::iterator cc = Series.begin(); cc!= Series.end(); ++cc ) { - (*cc)->WriteContent( fp, t ); + (*cc)->WriteContent( fp, t, false ); } for(ListDicomDirVisit::iterator icc = Visits.begin(); icc!= Visits.end(); ++icc ) { - (*icc)->WriteContent( fp, t ); + (*icc)->WriteContent( fp, t, false ); } } diff --git a/src/gdcmDicomDirStudy.h b/src/gdcmDicomDirStudy.h index d4a82b5a..17b4bb44 100644 --- a/src/gdcmDicomDirStudy.h +++ b/src/gdcmDicomDirStudy.h @@ -3,8 +3,8 @@ Program: gdcm Module: $RCSfile: gdcmDicomDirStudy.h,v $ Language: C++ - Date: $Date: 2007/05/23 14:18:09 $ - Version: $Revision: 1.33 $ + Date: $Date: 2007/07/26 08:36:49 $ + Version: $Revision: 1.34 $ Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de l'Image). All rights reserved. See Doc/License.txt or @@ -49,7 +49,7 @@ public: static DicomDirStudy *New(bool empty=false) {return new DicomDirStudy(empty);} void Print(std::ostream &os = std::cout, std::string const &indent = "" ); - void WriteContent(std::ofstream *fp, FileType t); + void WriteContent(std::ofstream *fp, FileType t, bool insideMetaElements); // 'Serie' methods DicomDirSerie *NewSerie(); diff --git a/src/gdcmDicomDirVisit.h b/src/gdcmDicomDirVisit.h index b4a925ba..1fdc3dc4 100644 --- a/src/gdcmDicomDirVisit.h +++ b/src/gdcmDicomDirVisit.h @@ -3,8 +3,8 @@ Program: gdcm Module: $RCSfile: gdcmDicomDirVisit.h,v $ Language: C++ - Date: $Date: 2007/05/23 14:18:09 $ - Version: $Revision: 1.4 $ + Date: $Date: 2007/07/26 08:36:49 $ + Version: $Revision: 1.5 $ Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de l'Image). All rights reserved. See Doc/License.txt or @@ -37,7 +37,6 @@ public: static DicomDirVisit *New(bool empty=false) {return new DicomDirVisit(empty);} void Print( std::ostream &os = std::cout, std::string const &indent = "" ); - // void WriteContent( std::ofstream *fp, FileType t ); protected: DicomDirVisit(bool empty=false); diff --git a/src/gdcmDocEntry.cxx b/src/gdcmDocEntry.cxx index 2466076d..79103b01 100644 --- a/src/gdcmDocEntry.cxx +++ b/src/gdcmDocEntry.cxx @@ -3,8 +3,8 @@ Program: gdcm Module: $RCSfile: gdcmDocEntry.cxx,v $ Language: C++ - Date: $Date: 2007/07/24 16:17:04 $ - Version: $Revision: 1.89 $ + Date: $Date: 2007/07/26 08:36:49 $ + Version: $Revision: 1.90 $ Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de l'Image). All rights reserved. See Doc/License.txt or @@ -71,7 +71,7 @@ DocEntry::~DocEntry() * @param fp already open ofstream pointer * @param filetype type of the file (ACR, ImplicitVR, ExplicitVR, ...) */ -void DocEntry::WriteContent(std::ofstream *fp, FileType filetype) +void DocEntry::WriteContent(std::ofstream *fp, FileType filetype, bool insideMetaElements) { uint32_t ffff = 0xffffffff; uint16_t group = GetGroup(); @@ -103,7 +103,7 @@ void DocEntry::WriteContent(std::ofstream *fp, FileType filetype) binary_write( *fp, elem); //element number // Dicom V3 group 0x0002 is *always* Explicit VR ! - if ( filetype == ExplicitVR || filetype == JPEG || filetype == JPEG2000 || group == 0x0002 ) + if ( filetype == ExplicitVR || filetype == JPEG || filetype == JPEG2000 || (group == 0x0002 && insideMetaElements) ) { // ----------- Writes the common part : the VR + the length @@ -321,8 +321,11 @@ void DocEntry::Print(std::ostream &os, std::string const & ) s << "[" << vr << "] "; std::string name; - if ( GetElement() == 0x0000 ) + uint16_t e = GetElement(); + if ( e == 0x0000 ) name = "Group Length"; + else if ( GetGroup()%2 == 1 && ( e >= 0x0010 && e <= 0x00ff ) ) + name = "Private Creator"; else { name = GetName(); diff --git a/src/gdcmDocEntry.h b/src/gdcmDocEntry.h index ba4dda21..f5fe3ab2 100644 --- a/src/gdcmDocEntry.h +++ b/src/gdcmDocEntry.h @@ -3,8 +3,8 @@ Program: gdcm Module: $RCSfile: gdcmDocEntry.h,v $ Language: C++ - Date: $Date: 2007/05/23 14:18:09 $ - Version: $Revision: 1.67 $ + Date: $Date: 2007/07/26 08:36:49 $ + Version: $Revision: 1.68 $ Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de l'Image). All rights reserved. See Doc/License.txt or @@ -41,7 +41,8 @@ class GDCM_EXPORT DocEntry : public RefCounter public: virtual void Print (std::ostream &os = std::cout, std::string const &indent = ""); - virtual void WriteContent(std::ofstream *fp, FileType filetype); + virtual void WriteContent(std::ofstream *fp, FileType filetype, + bool insideMetaElements); /// \brief Gets the DicEntry of the current Dicom entry /// @return The DicEntry of the current Dicom entry diff --git a/src/gdcmDocEntrySet.h b/src/gdcmDocEntrySet.h index 73b3ca98..083ec9f8 100644 --- a/src/gdcmDocEntrySet.h +++ b/src/gdcmDocEntrySet.h @@ -3,8 +3,8 @@ Program: gdcm Module: $RCSfile: gdcmDocEntrySet.h,v $ Language: C++ - Date: $Date: 2007/05/23 14:18:09 $ - Version: $Revision: 1.69 $ + Date: $Date: 2007/07/26 08:36:49 $ + 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 @@ -36,8 +36,8 @@ class DictEntry; //----------------------------------------------------------------------------- /** * \brief - * \ref DocEntrySet is an abstract base class for \ref ElementSet - * and \ref SQItem which are both containers for DocEntries. + * \ref DocEntrySet is an abstract base class for \ref ElementSet, \ref SQItem + * which are both containers for DocEntries. * - \ref ElementSet is based on the STL map<> container * (see \ref ElementSet::TagHT) * - \ref SQItem is based on an STL list container (see \ref ListDocEntry). @@ -64,7 +64,8 @@ class GDCM_EXPORT DocEntrySet : public RefCounter public: /// \brief write any type of entry to the entry set - virtual void WriteContent (std::ofstream *fp, FileType filetype) = 0; + virtual void WriteContent (std::ofstream *fp, FileType filetype, + bool insideMetaElements) = 0; /// \brief Remove all Entry of the current set virtual void ClearEntry() = 0; diff --git a/src/gdcmDocument.cxx b/src/gdcmDocument.cxx index 32e52d4a..1370bae8 100644 --- a/src/gdcmDocument.cxx +++ b/src/gdcmDocument.cxx @@ -3,8 +3,8 @@ Program: gdcm Module: $RCSfile: gdcmDocument.cxx,v $ Language: C++ - Date: $Date: 2007/07/11 12:21:01 $ - Version: $Revision: 1.363 $ + Date: $Date: 2007/07/26 08:36:49 $ + Version: $Revision: 1.364 $ Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de l'Image). All rights reserved. See Doc/License.txt or @@ -722,7 +722,7 @@ void Document::WriteContent(std::ofstream *fp, FileType filetype) * --> We don't write the element 0x0000 (group length) */ - ElementSet::WriteContent(fp, filetype); // This one is recursive + ElementSet::WriteContent(fp, filetype, false); // This one is recursive } // ----------------------------------------- @@ -2219,7 +2219,7 @@ DocEntry *Document::ReadNextDocEntry() changeFromUN = false; CurrentGroup = GetInt16(); CurrentElem = GetInt16(); - + // In 'true DICOM' files Group 0002 is always little endian if ( HasDCMPreamble ) { @@ -2244,10 +2244,10 @@ DocEntry *Document::ReadNextDocEntry() realVR = "UL"; } - // Commented out in order not to generate 'Shadow Groups' where some + // Was commented out in order not to generate 'Shadow Groups' where some // Data Elements are Explicit VR and some other ones Implicit VR - // (Stupid MatLab DICOM Reader couldn't read gdcm-written images) - /* + // -> Better we fix the problem at Write time + else if (CurrentGroup%2 == 1 && (CurrentElem >= 0x0010 && CurrentElem <=0x00ff )) { @@ -2255,7 +2255,7 @@ DocEntry *Document::ReadNextDocEntry() // (gggg-0010->00FF where gggg is odd) attributes have to be LO realVR = "LO"; } - */ + else { DictEntry *dictEntry = GetDictEntry(CurrentGroup,CurrentElem);//only when ImplicitVR diff --git a/src/gdcmElementSet.cxx b/src/gdcmElementSet.cxx index ecac10b2..a38db035 100644 --- a/src/gdcmElementSet.cxx +++ b/src/gdcmElementSet.cxx @@ -3,8 +3,8 @@ Program: gdcm Module: $RCSfile: gdcmElementSet.cxx,v $ Language: C++ - Date: $Date: 2007/05/23 14:18:10 $ - Version: $Revision: 1.76 $ + Date: $Date: 2007/07/26 08:36:49 $ + 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 @@ -49,18 +49,32 @@ ElementSet::~ElementSet() * @param fp ofstream to write to * @param filetype ExplicitVR/ImplicitVR/ACR/ACR_LIBIDO/JPEG/JPEG2000/... */ -void ElementSet::WriteContent(std::ofstream *fp, FileType filetype) +void ElementSet::WriteContent(std::ofstream *fp, FileType filetype, bool dummy) { + bool insideMetaElements = false; + bool yetOutsideMetaElements = false; + for (TagDocEntryHT::const_iterator i = TagHT.begin(); i != TagHT.end(); ++i) - { + { + int group = (i->second)->GetGroup(); + + if (yetOutsideMetaElements==false && group == 0x0002) + insideMetaElements = true; + + if (insideMetaElements == true && group != 0x0002) + { + yetOutsideMetaElements = true; + insideMetaElements = false; + } + // depending on the gdcm::Document type // (gdcm::File; gdcm::DicomDir, (more to come ?) // some groups *cannot* be present. // We hereby protect gdcm for writting stupid things // if they were found in the original document. - if ( !MayIWrite( (i->second)->GetGroup() ) ) + if ( !MayIWrite( group ) ) continue; // Skip 'Group Length' element, since it may be wrong. @@ -74,7 +88,8 @@ void ElementSet::WriteContent(std::ofstream *fp, FileType filetype) ||( (filetype == ACR || filetype == ACR_LIBIDO ) && (i->second)->GetGroup() == 0x0008 ) ) ) { - i->second->WriteContent(fp, filetype); + // There are DocEntries, written recursively + i->second->WriteContent(fp, filetype, insideMetaElements ); } } } diff --git a/src/gdcmElementSet.h b/src/gdcmElementSet.h index ec9b90cd..c384044c 100644 --- a/src/gdcmElementSet.h +++ b/src/gdcmElementSet.h @@ -3,8 +3,8 @@ Program: gdcm Module: $RCSfile: gdcmElementSet.h,v $ Language: C++ - Date: $Date: 2007/05/23 14:18:10 $ - Version: $Revision: 1.55 $ + Date: $Date: 2007/07/26 08:36:49 $ + Version: $Revision: 1.56 $ Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de l'Image). All rights reserved. See Doc/License.txt or @@ -45,7 +45,8 @@ public: virtual void Print(std::ostream &os = std::cout, std::string const &indent = "" ); - void WriteContent(std::ofstream *fp, FileType filetype); + void WriteContent(std::ofstream *fp, FileType filetype, + bool insideMetaElements); bool AddEntry(DocEntry *Entry); bool RemoveEntry(DocEntry *EntryToRemove); diff --git a/src/gdcmFileHelper.cxx b/src/gdcmFileHelper.cxx index d652eba7..2f54d3ed 100644 --- a/src/gdcmFileHelper.cxx +++ b/src/gdcmFileHelper.cxx @@ -4,8 +4,8 @@ Module: $RCSfile: gdcmFileHelper.cxx,v $ Language: C++ - Date: $Date: 2007/07/24 16:17:04 $ - Version: $Revision: 1.118 $ + Date: $Date: 2007/07/26 08:36:49 $ + Version: $Revision: 1.119 $ Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de l'Image). All rights reserved. See Doc/License.txt or @@ -2094,7 +2094,7 @@ void FileHelper::ConvertFixGreyLevels(uint8_t *raw, size_t rawSize) //----------------------------------------------------------------------------- /** - * \brief Prints the common part of DataEntry, SeqEntry + * \brief Prints the FileInternal + info on PixelReadConvertor * @param os ostream we want to print in * @param indent (unused) */ diff --git a/src/gdcmSQItem.cxx b/src/gdcmSQItem.cxx index a945413b..c93e630c 100644 --- a/src/gdcmSQItem.cxx +++ b/src/gdcmSQItem.cxx @@ -3,8 +3,8 @@ Program: gdcm Module: $RCSfile: gdcmSQItem.cxx,v $ Language: C++ - Date: $Date: 2007/05/23 14:18:11 $ - Version: $Revision: 1.85 $ + Date: $Date: 2007/07/26 08:36:49 $ + Version: $Revision: 1.86 $ Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de l'Image). All rights reserved. See Doc/License.txt or @@ -54,7 +54,8 @@ SQItem::~SQItem() * @param fp file pointer to an already open file. * @param filetype type of the file (ACR, ImplicitVR, ExplicitVR, ...) */ -void SQItem::WriteContent(std::ofstream *fp, FileType filetype) +void SQItem::WriteContent(std::ofstream *fp, FileType filetype, + bool insideMetaElements) { int j; uint16_t item[4] = { 0xfffe, 0xe000, 0xffff, 0xffff }; @@ -87,8 +88,8 @@ void SQItem::WriteContent(std::ofstream *fp, FileType filetype) // --> makes no difference since the only bugged file we have // contains 'impossible tag' fffe|0000 in last position ! } - - (*it)->WriteContent(fp, filetype); + // false : we are not in MetaElements + (*it)->WriteContent(fp, filetype, false); } //we force the writting of an 'Item Delimitation' item diff --git a/src/gdcmSQItem.h b/src/gdcmSQItem.h index 147643e5..4231f320 100644 --- a/src/gdcmSQItem.h +++ b/src/gdcmSQItem.h @@ -3,8 +3,8 @@ Program: gdcm Module: $RCSfile: gdcmSQItem.h,v $ Language: C++ - Date: $Date: 2007/05/23 14:18:11 $ - Version: $Revision: 1.52 $ + Date: $Date: 2007/07/26 08:36:49 $ + Version: $Revision: 1.53 $ Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de l'Image). All rights reserved. See Doc/License.txt or @@ -47,7 +47,7 @@ public: virtual void Print(std::ostream &os = std::cout, std::string const &indent = "" ); - void WriteContent(std::ofstream *fp, FileType filetype); + void WriteContent(std::ofstream *fp, FileType filetype, bool insideMetaElements); uint32_t ComputeFullLength(); bool AddEntry(DocEntry *Entry); // add to the List diff --git a/src/gdcmSeqEntry.cxx b/src/gdcmSeqEntry.cxx index 684d444d..0e18e40c 100644 --- a/src/gdcmSeqEntry.cxx +++ b/src/gdcmSeqEntry.cxx @@ -3,8 +3,8 @@ Program: gdcm Module: $RCSfile: gdcmSeqEntry.cxx,v $ Language: C++ - Date: $Date: 2007/05/23 14:18:11 $ - Version: $Revision: 1.68 $ + Date: $Date: 2007/07/26 08:36:49 $ + Version: $Revision: 1.69 $ Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de l'Image). All rights reserved. See Doc/License.txt or @@ -80,7 +80,7 @@ SeqEntry::~SeqEntry() * @param fp pointer to an already open file * @param filetype type of the file (ACR, ImplicitVR, ExplicitVR, ...) */ -void SeqEntry::WriteContent(std::ofstream *fp, FileType filetype) +void SeqEntry::WriteContent(std::ofstream *fp, FileType filetype, bool dummy) { uint16_t seq_term_gr = 0xfffe; uint16_t seq_term_el = 0xe0dd; @@ -89,13 +89,13 @@ void SeqEntry::WriteContent(std::ofstream *fp, FileType filetype) // ignore 'Zero length' Sequences if ( GetReadLength() == 0 ) return; - - DocEntry::WriteContent(fp, filetype); + // false : we are not in MetaElements + DocEntry::WriteContent(fp, filetype, false); for(ListSQItem::iterator cc = Items.begin(); cc != Items.end(); ++cc) - { - (*cc)->WriteContent(fp, filetype); + { + (*cc)->WriteContent(fp, filetype, false); } // we force the writting of a Sequence Delimitation item diff --git a/src/gdcmSeqEntry.h b/src/gdcmSeqEntry.h index 778858c6..488b3758 100644 --- a/src/gdcmSeqEntry.h +++ b/src/gdcmSeqEntry.h @@ -3,8 +3,8 @@ Program: gdcm Module: $RCSfile: gdcmSeqEntry.h,v $ Language: C++ - Date: $Date: 2007/05/23 14:18:11 $ - Version: $Revision: 1.43 $ + Date: $Date: 2007/07/26 08:36:49 $ + Version: $Revision: 1.44 $ Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de l'Image). All rights reserved. See Doc/License.txt or @@ -51,7 +51,7 @@ public: {return new SeqEntry(group,elem);} void Print(std::ostream &os = std::cout, std::string const &indent = "" ); - void WriteContent(std::ofstream *fp, FileType filetype); + void WriteContent(std::ofstream *fp, FileType filetype, bool insideMetaElements); uint32_t ComputeFullLength(); void AddSQItem(SQItem *it, int itemNumber); -- 2.45.1