From: jpr Date: Tue, 11 Apr 2006 16:03:26 +0000 (+0000) Subject: Remove useless accesses to the Dicom Dictionnary std::map X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=commitdiff_plain;h=17ebda2271dd65565f512e835546b22c22ebbbb0;p=gdcm.git Remove useless accesses to the Dicom Dictionnary std::map --- diff --git a/src/gdcmArgMgr.cxx b/src/gdcmArgMgr.cxx index 172cb7d2..0aebf378 100644 --- a/src/gdcmArgMgr.cxx +++ b/src/gdcmArgMgr.cxx @@ -3,8 +3,8 @@ Program: gdcm Module: $RCSfile: gdcmArgMgr.cxx,v $ Language: C++ - Date: $Date: 2006/01/26 18:34:13 $ - Version: $Revision: 1.20 $ + Date: $Date: 2006/04/11 16:03:26 $ + Version: $Revision: 1.21 $ Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de l'Image). All rights reserved. See Doc/License.txt or @@ -99,8 +99,13 @@ namespace gdcm } /* Set labels to upper-case (labels are not case sensitive ) *********/ + char *secu; for ( i=0; i //----------------------------------------------------------------------------- @@ -157,6 +157,8 @@ struct DicomElement unsigned short int Group; /// Dicom Element number unsigned short int Elem; + /// Value Representation + VRKey VR; /// value (coded as a std::string) of the Element std::string Value; }; diff --git a/src/gdcmDataEntry.cxx b/src/gdcmDataEntry.cxx index abdbf5a9..0c517865 100644 --- a/src/gdcmDataEntry.cxx +++ b/src/gdcmDataEntry.cxx @@ -3,8 +3,8 @@ Program: gdcm Module: $RCSfile: gdcmDataEntry.cxx,v $ Language: C++ - Date: $Date: 2006/03/31 07:52:23 $ - Version: $Revision: 1.35 $ + Date: $Date: 2006/04/11 16:03:26 $ + 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 @@ -43,8 +43,9 @@ uint32_t DataEntry::MaxSizePrintEntry = MAX_SIZE_PRINT_ELEMENT_VALUE; * \brief Constructor for a given DictEntry * @param e Pointer to existing dictionary entry */ -DataEntry::DataEntry(DictEntry *e) - : DocEntry(e) +DataEntry::DataEntry(uint16_t group,uint16_t elem, + VRKey const &vr) + : DocEntry(group,elem,vr) { State = STATE_LOADED; Flag = FLAG_NONE; @@ -58,7 +59,8 @@ DataEntry::DataEntry(DictEntry *e) * @param e Pointer to existing Doc entry */ DataEntry::DataEntry(DocEntry *e) - : DocEntry(e->GetDictEntry()) + //: DocEntry(e->GetDictEntry()) + : DocEntry(e->GetGroup(),e->GetElement(), e->GetVR() ) { Flag = FLAG_NONE; BinArea = 0; @@ -255,7 +257,7 @@ double DataEntry::GetValue(const uint32_t &id) const /** * \brief Checks if the multiplicity of the value follows Dictionary VM */ -bool DataEntry::IsValueCountValid() const +bool DataEntry::IsValueCountValid() /*const*/ { uint32_t vm; const std::string &strVM = GetVM(); @@ -414,7 +416,7 @@ void DataEntry::SetString(std::string const &value) } else { - if( value.size() > 0 ) + //if( value.size() > 0 ) // when user sets a string to 0, *do* the job. { size_t l = value.size(); SetLength(l + l%2); @@ -422,7 +424,7 @@ void DataEntry::SetString(std::string const &value) memcpy(BinArea, value.c_str(), l); if (l%2) BinArea[l] = '\0'; - } + } } State = STATE_LOADED; } @@ -495,7 +497,7 @@ std::string const &DataEntry::GetString() const else { StrArea.append((const char *)BinArea,GetLength()); - // to avoid gdcm propagate oddities in lengthes + // to avoid gdcm to propagate oddities in lengthes if ( GetLength()%2) StrArea.append(" ",1); } @@ -555,9 +557,9 @@ void DataEntry::WriteContent(std::ofstream *fp, FileType filetype) uint8_t *data = BinArea; //safe notation size_t l = GetLength(); - gdcmDebugMacro("in DataEntry::WriteContent " << GetKey() << " AtomicLength: " - << Global::GetVR()->GetAtomicElementLength(this->GetVR() ) // << " BinArea in :" << &BinArea - ); +// gdcmDebugMacro("in DataEntry::WriteContent " << GetKey() << " AtomicLength: " +// << Global::GetVR()->GetAtomicElementLength(this->GetVR() ) // << " BinArea in :" << &BinArea +// ); if (BinArea) // the binArea was *actually* loaded { #if defined(GDCM_WORDS_BIGENDIAN) || defined(GDCM_FORCE_BIGENDIAN_EMULATION) diff --git a/src/gdcmDataEntry.h b/src/gdcmDataEntry.h index 0464c372..1b9aba72 100644 --- a/src/gdcmDataEntry.h +++ b/src/gdcmDataEntry.h @@ -3,8 +3,8 @@ Program: gdcm Module: $RCSfile: gdcmDataEntry.h,v $ Language: C++ - Date: $Date: 2006/03/01 09:29:29 $ - Version: $Revision: 1.13 $ + Date: $Date: 2006/04/11 16:03:26 $ + Version: $Revision: 1.14 $ Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de l'Image). All rights reserved. See Doc/License.txt or @@ -40,10 +40,13 @@ class GDCM_EXPORT DataEntry : public DocEntry public: /// \brief Contructs a DataEntry with a RefCounter from DictEntry - static DataEntry *New(DictEntry *e) {return new DataEntry(e);} +// static DataEntry *New(DictEntry *e) {return new DataEntry(e);} /// \brief Contructs a DataEntry with a RefCounter from DocEntry static DataEntry *New(DocEntry *d) {return new DataEntry(d);} - +/// \brief Contructs a DataEntry with a RefCounter from elementary items + static DataEntry *New(uint16_t group,uint16_t elem, VRKey const &vr) + {return new DataEntry(group,elem,vr);} + // Print void Print(std::ostream &os = std::cout, std::string const &indent = ""); @@ -64,7 +67,7 @@ public: void SetValue(const uint32_t &id,const double &val); double GetValue(const uint32_t &id) const; uint32_t GetValueCount() const; - bool IsValueCountValid() const; + bool IsValueCountValid() /*const*/; // GetVM may update the pointer DicomDict void SetString(std::string const &value); std::string const &GetString() const; @@ -107,7 +110,7 @@ public: // Flags /// \brief sets the 'pixel data flag' void SetFlag(const TValueFlag &flag) { Flag = flag; } - /// \brief returns the 'pixel data flag' + /// \brief returns the 'pixel data flag' const TValueFlag &GetFlag() const { return Flag; } /// \brief true id Entry is a Pixel Data entry bool IsPixelData() { return (Flag &FLAG_PIXELDATA) != 0; } @@ -124,8 +127,9 @@ public: bool GetDSValue(std::vector &valueVector); protected: - DataEntry(DictEntry *e); - DataEntry(DocEntry *d); + // DataEntry(DictEntry *e); + DataEntry(DocEntry *d); + DataEntry(uint16_t group,uint16_t elem,VRKey const &vr); ~DataEntry(); // Methods : diff --git a/src/gdcmDebug.h b/src/gdcmDebug.h index 4f5462c3..dbc9a06c 100644 --- a/src/gdcmDebug.h +++ b/src/gdcmDebug.h @@ -3,8 +3,8 @@ Program: gdcm Module: $RCSfile: gdcmDebug.h,v $ Language: C++ - Date: $Date: 2006/01/03 14:28:53 $ - Version: $Revision: 1.53 $ + Date: $Date: 2006/04/11 16:03:26 $ + Version: $Revision: 1.54 $ Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de l'Image). All rights reserved. See Doc/License.txt or @@ -210,7 +210,7 @@ private: // No NDEBUG test to always have a return of warnings !!! // -> Rien compris! JPRx #define gdcmLogBodyMacro(obj, msg) \ -{ \ +{ \ if( Debug::GetLogFlag() ) \ gdcmMessageBodyMacro(gdcm::CMD_LOG,obj,msg,""); \ } diff --git a/src/gdcmDefaultDicts.cxx.in b/src/gdcmDefaultDicts.cxx.in index 21d39605..9e7b4397 100644 --- a/src/gdcmDefaultDicts.cxx.in +++ b/src/gdcmDefaultDicts.cxx.in @@ -3,8 +3,8 @@ Program: gdcm Module: $RCSfile: gdcmDefaultDicts.cxx.in,v $ Language: C++ - Date: $Date: 2005/10/20 15:24:08 $ - Version: $Revision: 1.11 $ + Date: $Date: 2006/04/11 16:03:26 $ + Version: $Revision: 1.12 $ Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de l'Image). All rights reserved. See Doc/License.txt or @@ -76,6 +76,8 @@ typedef struct const char *type; unsigned short group; unsigned short element; + //VRKey vr; + const char *vr; const char *value; } ELEMENT; @@ -93,7 +95,7 @@ void FillDefaultDIRDict(DicomDirElement *dde) while( e.type != 0 ) { - // Force to use the string comparision operator == + // Force to use the string comparison operator == strType = e.type; if( strType == "metaElem" ) type = DD_META; @@ -110,6 +112,7 @@ void FillDefaultDIRDict(DicomDirElement *dde) elem.Group = e.group; elem.Elem = e.element; + elem.VR = e.vr; elem.Value = e.value; dde->AddEntry( type, elem); e = dataElement[++i]; diff --git a/src/gdcmDicomDir.cxx b/src/gdcmDicomDir.cxx index 2ca54af0..6812b76f 100644 --- a/src/gdcmDicomDir.cxx +++ b/src/gdcmDicomDir.cxx @@ -3,8 +3,8 @@ Program: gdcm Module: $RCSfile: gdcmDicomDir.cxx,v $ Language: C++ - Date: $Date: 2006/02/16 20:06:13 $ - Version: $Revision: 1.186 $ + Date: $Date: 2006/04/11 16:03:26 $ + Version: $Revision: 1.187 $ Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de l'Image). All rights reserved. See Doc/License.txt or @@ -962,9 +962,10 @@ void DicomDir::SetElement(std::string const &path, DicomDirType type, { tmpGr = it->Group; tmpEl = it->Elem; - dictEntry = GetPubDict()->GetEntry(tmpGr, tmpEl); - - entry = DataEntry::New( dictEntry ); + //dictEntry = GetPubDict()->GetEntry(tmpGr, tmpEl); + //entry = DataEntry::New( dictEntry ); + + entry = DataEntry::New(tmpGr, tmpEl, GDCM_VRUNKNOWN); /// \todo : modify dicomelements file, to store VR entry->SetOffset(0); // just to avoid further missprinting if ( header ) diff --git a/src/gdcmDicomDirElement.cxx b/src/gdcmDicomDirElement.cxx index d0bc124b..537d7df8 100644 --- a/src/gdcmDicomDirElement.cxx +++ b/src/gdcmDicomDirElement.cxx @@ -3,8 +3,8 @@ Program: gdcm Module: $RCSfile: gdcmDicomDirElement.cxx,v $ Language: C++ - Date: $Date: 2005/11/04 15:29:59 $ - Version: $Revision: 1.42 $ + Date: $Date: 2006/04/11 16:03:26 $ + Version: $Revision: 1.43 $ Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de l'Image). All rights reserved. See Doc/License.txt or @@ -50,10 +50,10 @@ DicomDirElement::DicomDirElement() else { char buff[1024]; + char buff2[1024]; std::string strType; DicomElement elem; DicomDirType type; - while (!from.eof()) { from >> std::ws; @@ -80,14 +80,20 @@ DicomDirElement::DicomDirElement() if ( type!=DD_UNKNOWN ) { - from >> std::hex >> elem.Group >> elem.Elem; + from >> std::hex >> elem.Group >> elem.Elem;// >> elem.VR; + from.getline(buff2, 1024, '"'); + from >> std::ws; + from.getline(buff2, 1024, '"'); + elem.VR[0] = buff2[0]; + elem.VR[1] = buff2[1]; + from >> std::ws; from.getline(buff, 1024, '"'); from >> std::ws; from.getline(buff, 1024, '"'); elem.Value = buff; - + AddEntry(type, elem); } from.getline(buff, 1024, '\n'); @@ -147,13 +153,15 @@ bool DicomDirElement::AddEntry(DicomDirType type, DicomElement const &elem) * @param type Element type (DD_PATIENT, DD_STUDY, DD_SERIE, DD_IMAGE) * @param group Group number of the entry to be added * @param elem Element number of the entry to be added + * @param vr Value Representation of the entry to be added */ void DicomDirElement::AddDicomDirElement(DicomDirType type, - uint16_t group, uint16_t elem) + uint16_t group, uint16_t elem, VRKey vr) { DicomElement el; el.Group = group; el.Elem = elem; + el.VR = vr; el.Value = ""; AddEntry(type, el); } @@ -174,7 +182,6 @@ void DicomDirElement::Print(std::ostream &os,std::string const &) { std::ostringstream s; std::list::iterator it; - //char greltag[10]; //group element tag TagKey greltag; s << "Meta Elements :"< @@ -125,7 +126,7 @@ public: // Only one instance of ddElem void AddDicomDirElement(DicomDirType type, - uint16_t group, uint16_t elem); + uint16_t group, uint16_t elem, VRKey vr); protected: DicomDirElement(); diff --git a/src/gdcmDicomDirObject.cxx b/src/gdcmDicomDirObject.cxx index 1625584c..4013716b 100644 --- a/src/gdcmDicomDirObject.cxx +++ b/src/gdcmDicomDirObject.cxx @@ -3,8 +3,8 @@ Program: gdcm Module: $RCSfile: gdcmDicomDirObject.cxx,v $ Language: C++ - Date: $Date: 2005/10/25 09:22:15 $ - Version: $Revision: 1.23 $ + Date: $Date: 2006/04/11 16:03:26 $ + Version: $Revision: 1.24 $ Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de l'Image). All rights reserved. See Doc/License.txt or @@ -57,17 +57,18 @@ void DicomDirObject::FillObject(ListDicomDirMetaElem const &elemList) { // FillObject fills up the SQItem that will be connected to the right place ListDicomDirMetaElem::const_iterator it; - uint16_t tmpGr,tmpEl; - DictEntry *dictEntry; + //uint16_t tmpGr,tmpEl; + //DictEntry *dictEntry; DataEntry *entry; // for all the Elements found in they own part of the DicomDir dict. for(it = elemList.begin(); it != elemList.end(); ++it) { - tmpGr = it->Group; - tmpEl = it->Elem; - dictEntry = Global::GetDicts()->GetDefaultPubDict()->GetEntry(tmpGr,tmpEl); - entry = DataEntry::New(dictEntry); + //tmpGr = it->Group; + //tmpEl = it->Elem; + //dictEntry = Global::GetDicts()->GetDefaultPubDict()->GetEntry(tmpGr,tmpEl); + //entry = DataEntry::New(dictEntry); + entry = DataEntry::New(it->Group, it->Elem, it->VR ); entry->SetOffset(0); // just to avoid further missprinting entry->SetString(it->Value); diff --git a/src/gdcmDicomEntry.cxx b/src/gdcmDicomEntry.cxx index ef260fba..9afd602c 100644 --- a/src/gdcmDicomEntry.cxx +++ b/src/gdcmDicomEntry.cxx @@ -3,8 +3,8 @@ Program: gdcm Module: $RCSfile: gdcmDicomEntry.cxx,v $ Language: C++ - Date: $Date: 2005/10/21 07:38:57 $ - Version: $Revision: 1.3 $ + Date: $Date: 2006/04/11 16:03:26 $ + Version: $Revision: 1.4 $ Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de l'Image). All rights reserved. See Doc/License.txt or @@ -17,12 +17,12 @@ =========================================================================*/ #include "gdcmDicomEntry.h" -#include "gdcmDebug.h" -#include "gdcmUtil.h" +//#include "gdcmDebug.h" +//#include "gdcmUtil.h" -#include // for std::ios::left, ... +//#include // for std::ios::left, ... #include -#include // for sprintf +//#include // for sprintf namespace gdcm { @@ -37,8 +37,9 @@ namespace gdcm DicomEntry::DicomEntry(const uint16_t &group,const uint16_t &elem, const VRKey &vr) { - Tag.SetGroup(group); - Tag.SetElement(elem); + //Tag.SetGroupElement(group); + //Tag.SetElement(elem); + Tag.SetGroupElement(group,elem); VR = vr; } @@ -51,20 +52,6 @@ DicomEntry::~DicomEntry() //----------------------------------------------------------------------------- // Public -/** - * \brief concatenates 2 uint16_t (supposed to be a Dicom group number - * and a Dicom element number) - * @param group the Dicom group number used to build the tag - * @param elem the Dicom element number used to build the tag - * @return the built tag - */ -TagKey DicomEntry::TranslateToKey(uint16_t group, uint16_t elem) -{ - // according to 'Purify', TranslateToKey is one of the most - // time consuming methods. - // Let's try to shorten it ! - return TagKey(group,elem); -} //----------------------------------------------------------------------------- // Protected diff --git a/src/gdcmDicomEntry.h b/src/gdcmDicomEntry.h index 6f843b58..513c2d9c 100644 --- a/src/gdcmDicomEntry.h +++ b/src/gdcmDicomEntry.h @@ -3,8 +3,8 @@ Program: gdcm Module: $RCSfile: gdcmDicomEntry.h,v $ Language: C++ - Date: $Date: 2005/11/28 15:30:04 $ - Version: $Revision: 1.9 $ + Date: $Date: 2006/04/11 16:03:26 $ + Version: $Revision: 1.10 $ Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de l'Image). All rights reserved. See Doc/License.txt or @@ -68,7 +68,8 @@ public: const TagKey &GetKey() const { return Tag; } // Key creation - static TagKey TranslateToKey(uint16_t group, uint16_t elem); + static TagKey TranslateToKey(uint16_t group, uint16_t elem) + { return TagKey(group,elem); } protected: DicomEntry(const uint16_t &group,const uint16_t &elt, diff --git a/src/gdcmDict.cxx b/src/gdcmDict.cxx index 1af0d6b5..6d20d5eb 100644 --- a/src/gdcmDict.cxx +++ b/src/gdcmDict.cxx @@ -3,8 +3,8 @@ Program: gdcm Module: $RCSfile: gdcmDict.cxx,v $ Language: C++ - Date: $Date: 2005/11/05 13:25:26 $ - Version: $Revision: 1.83 $ + Date: $Date: 2006/04/11 16:03:26 $ + Version: $Revision: 1.84 $ 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 @@ Dict::Dict( ) */ Dict::Dict(std::string const &filename) { - + gdcmDebugMacro( "in Dict::Dict, filename =[" << filename << "]" ); std::ifstream from( filename.c_str() ); if ( !from ) { @@ -57,6 +57,8 @@ Dict::Dict(std::string const &filename) } else { + gdcmDebugMacro( "in Dict::Dict, DoTheLoadingJob filename =[" + << filename << "]" ); DoTheLoadingJob(from); Filename = filename; } @@ -160,7 +162,10 @@ bool Dict::AddEntry(DictEntry *newEntry) * @param newEntry new entry (overwrites any previous one with same tag) * @return false if Dicom Element doesn't exist */ -bool Dict::ReplaceEntry(DictEntry *newEntry) + + /* seems to be useless + +bool Dict::ReplaceEntry(DictEntry *newEntry) // seems to be useless { const TagKey &key = newEntry->GetKey(); if ( RemoveEntry(key) ) @@ -171,7 +176,7 @@ bool Dict::ReplaceEntry(DictEntry *newEntry) } return false; } - +*/ /** * \brief removes an already existing Dicom Dictionary Entry, * identified by its Tag @@ -183,8 +188,8 @@ bool Dict::RemoveEntry(TagKey const &key) TagKeyHT::const_iterator it = KeyHt.find(key); if ( it != KeyHt.end() ) { - it->second->Unregister(); - KeyHt.erase(key); + it->second->Unregister(); // delete the entry + KeyHt.erase(key); // remove pointer from HTable return true; } @@ -215,9 +220,11 @@ void Dict::ClearEntry() // we assume all the pointed DictEntries are already cleaned-up // when we clean KeyHt. TagKeyHT::const_iterator it; + for(it = KeyHt.begin();it!=KeyHt.end();++it) - it->second->Unregister(); - KeyHt.clear(); + it->second->Unregister(); // delete the entry + KeyHt.clear(); // remove all the entries from HTable + } /** @@ -322,19 +329,23 @@ void Dict::DoTheLoadingJob(std::ifstream &from) */ void Dict::Print(std::ostream &os, std::string const & ) { - os << "Dict file name : " << Filename << std::endl; + os << "Dict file name : [" << Filename << "]" << std::endl; std::ostringstream s; for (TagKeyHT::iterator tag = KeyHt.begin(); tag != KeyHt.end(); ++tag) - { + { +std::cout << tag->second->GetKey() << " " << tag->second->GetName() + << std::endl; s << "Entry : "; s << "(" << tag->second->GetKey() << ") = " << std::dec; s << tag->second->GetVR() << ", "; s << tag->second->GetVM() << ", "; s << tag->second->GetName() << "." << std::endl; + } os << s.str(); + } //----------------------------------------------------------------------------- diff --git a/src/gdcmDict.h b/src/gdcmDict.h index b460bf78..0e86bedf 100644 --- a/src/gdcmDict.h +++ b/src/gdcmDict.h @@ -3,8 +3,8 @@ Program: gdcm Module: $RCSfile: gdcmDict.h,v $ Language: C++ - Date: $Date: 2005/11/28 16:31:23 $ - Version: $Revision: 1.48 $ + Date: $Date: 2006/04/11 16:03:26 $ + Version: $Revision: 1.49 $ Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de l'Image). All rights reserved. See Doc/License.txt or @@ -61,7 +61,7 @@ public: // Entries bool AddEntry(DictEntry *newEntry); - bool ReplaceEntry(DictEntry *newEntry); + // bool ReplaceEntry(DictEntry *newEntry); // useless ? bool RemoveEntry (TagKey const &key); bool RemoveEntry (uint16_t group, uint16_t elem); void ClearEntry(); diff --git a/src/gdcmDocEntry.cxx b/src/gdcmDocEntry.cxx index c076fcc0..1760277a 100644 --- a/src/gdcmDocEntry.cxx +++ b/src/gdcmDocEntry.cxx @@ -3,8 +3,8 @@ Program: gdcm Module: $RCSfile: gdcmDocEntry.cxx,v $ Language: C++ - Date: $Date: 2006/03/22 13:19:25 $ - Version: $Revision: 1.82 $ + Date: $Date: 2006/04/11 16:03:26 $ + Version: $Revision: 1.83 $ Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de l'Image). All rights reserved. See Doc/License.txt or @@ -23,7 +23,7 @@ #include "gdcmGlobal.h" #include "gdcmUtil.h" #include "gdcmDebug.h" - +#include "gdcmDictSet.h" #include // for std::ios::left, ... #include @@ -34,23 +34,22 @@ namespace gdcm // Constructor / Destructor /** * \brief Constructor from a given DictEntry - * @param in Pointer to existing dictionary entry + * @param group Group number + * @param elem Element number + * @param vr VR */ -DocEntry::DocEntry(DictEntry *in) +DocEntry::DocEntry(uint16_t group, uint16_t elem, VRKey const &vr) { ImplicitVR = false; - DicomDict = in; + DicomDict = 0; Offset = 0 ; // To avoid further missprinting // init some variables ReadLength = 0; Length = 0; - gdcmAssertMacro(DicomDict); - DicomDict->Register(); - - VR = in->GetVR(); - Key = in->GetKey(); + VR = vr; + Key.SetGroupElem(group,elem); } /** @@ -58,9 +57,11 @@ DocEntry::DocEntry(DictEntry *in) */ DocEntry::~DocEntry() { - gdcmAssertMacro(DicomDict); - - DicomDict->Unregister(); + if (DicomDict) + { + gdcmAssertMacro(DicomDict); + DicomDict->Unregister(); + } } //----------------------------------------------------------------------------- @@ -80,7 +81,7 @@ void DocEntry::WriteContent(std::ofstream *fp, FileType filetype) VRKey vr = GetVR(); uint16_t elem = GetElement(); uint32_t lgth = GetLength(); - + if ( group == 0xfffe && elem == 0x0000 ) { // Fix in order to make some MR PHILIPS images e-film readable @@ -108,7 +109,7 @@ void DocEntry::WriteContent(std::ofstream *fp, FileType filetype) // Special case of delimiters: if (group == 0xfffe) - { + { // Delimiters have NO Value Representation // Hence we skip writing the VR. // @@ -121,7 +122,6 @@ void DocEntry::WriteContent(std::ofstream *fp, FileType filetype) binary_write(*fp, ff); return; } - uint16_t zero = 0; uint16_t shortLgr = (uint16_t)lgth; @@ -129,13 +129,11 @@ void DocEntry::WriteContent(std::ofstream *fp, FileType filetype) { // GDCM_VRUNKNOWN was stored in the Entry VR; // deal with Entry as if TS were Implicit VR - binary_write(*fp, lgth); } else { binary_write(*fp, vr.str()); - // See PS 3.5-2004 page 33, 36 if ( (vr == "SQ") || (vr == "OB") || (vr == "OW") || (vr == "OF") || (vr == "UN") || (vr == "UT") ) @@ -173,6 +171,39 @@ void DocEntry::WriteContent(std::ofstream *fp, FileType filetype) } } +/// \brief Returns the 'Name' '(e.g. "Patient's Name") found in the Dicom +/// Dictionnary of the current Dicom Header Entry +std::string const &DocEntry::GetName() +{ + if (DicomDict == 0) + DicomDict = + Global::GetDicts()->GetDefaultPubDict()->GetEntry(Key[0],Key[1]); + if (DicomDict == 0) + return GDCM_UNKNOWN; + else + { + DicomDict->Register(); + return DicomDict->GetName(); + } +} + + /// \brief Returns the 'Value Multiplicity' (e.g. "1", "6", "1-n", "3-n"), + /// found in the Dicom entry or in the Dicom Dictionnary + /// of the current Dicom entry +std::string const &DocEntry::GetVM() +{ + if (DicomDict == 0) + DicomDict = + Global::GetDicts()->GetDefaultPubDict()->GetEntry(Key[0],Key[1]); + if (DicomDict == 0) + return GDCM_UNKNOWN; + else + { + DicomDict->Register(); + return DicomDict->GetVM(); + } +} + /** * \brief Gets the full length of the elementary DocEntry (not only value * length) depending on the VR. diff --git a/src/gdcmDocEntry.h b/src/gdcmDocEntry.h index b4133703..950cc1d8 100644 --- a/src/gdcmDocEntry.h +++ b/src/gdcmDocEntry.h @@ -3,8 +3,8 @@ Program: gdcm Module: $RCSfile: gdcmDocEntry.h,v $ Language: C++ - Date: $Date: 2006/03/22 13:19:25 $ - Version: $Revision: 1.61 $ + Date: $Date: 2006/04/11 16:03:26 $ + Version: $Revision: 1.62 $ Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de l'Image). All rights reserved. See Doc/License.txt or @@ -48,11 +48,11 @@ public: DictEntry * GetDictEntry() { return DicomDict; } /// Returns the Dicom Group number of the current Dicom entry - const uint16_t GetGroup() const { return Key.GetGroup(); } + const uint16_t GetGroup() const { return Key[0]; } //const uint16_t &GetGroup() const { return DicomDict->GetGroup(); } /// Returns the Dicom Element number of the current Dicom entry - const uint16_t GetElement() const { return Key.GetElement();} + const uint16_t GetElement() const { return Key[1];} //const uint16_t &GetElement() const { return DicomDict->GetElement();} /// Returns the 'key' of the current Dicom entry @@ -61,7 +61,7 @@ public: /// \brief Returns the 'Name' '(e.g. "Patient's Name") found in the Dicom /// Dictionnary of the current Dicom Header Entry - std::string const &GetName() const { return DicomDict->GetName(); } + std::string const &GetName(); /// \brief Returns the 'Value Representation' (e.g. "PN" : Person Name, /// "SL" : Signed Long), found in the Dicom header or in the Dicom @@ -72,11 +72,12 @@ public: /// \brief Returns the 'Value Multiplicity' (e.g. "1", "6", "1-n", "3-n"), /// found in the Dicom entry or in the Dicom Dictionnary /// of the current Dicom entry - std::string const &GetVM() const { return DicomDict->GetVM(); } + std::string const &GetVM(); /// Sets the 'Value Multiplicity' of the current Dicom entry - void SetVM( TagName const &v) { DicomDict->SetVM(v); } - + //void SetVM( TagName const &v) { DicomDict->SetVM(v); } + void SetVM( TagName &v) { std::cout << "-----------------FIXME : SetVM "; } + /// \brief Returns offset (since the beginning of the file, including /// the File Preamble, if any) of the value of the current Dicom entry /// \warning offset of the *value*, not of the Dicom entry @@ -128,12 +129,13 @@ public: /// \brief Tells us if the VR of the current Dicom entry is Unknown /// @return true if the VR is unknown - bool IsVRUnknown() const { return DicomDict->IsVRUnknown(); } +// bool IsVRUnknown() const { return DicomDict->IsVRUnknown(); } + bool IsVRUnknown() const { return VR == GDCM_VRUNKNOWN; } /// \brief Tells us if the VM of the current Dicom entry is Unknown /// @return true if the VM is unknown - bool IsVMUnknown() const { return DicomDict->IsVMUnknown(); } - +// bool IsVMUnknown() const { return DicomDict->IsVMUnknown(); } + bool IsVMUnknown() { return GetVM() == GDCM_UNKNOWN; } bool IsItemDelimitor(); bool IsItemStarter(); bool IsSequenceDelimitor(); @@ -141,7 +143,8 @@ public: virtual void Copy(DocEntry *doc); protected: - DocEntry(DictEntry*); + // DocEntry(DictEntry*); + DocEntry(uint16_t group, uint16_t elem, VRKey const &vr); virtual ~DocEntry(); /// \brief pointer to the underlying Dicom dictionary element diff --git a/src/gdcmDocEntryArchive.cxx b/src/gdcmDocEntryArchive.cxx index c82a1e96..b8bb023b 100644 --- a/src/gdcmDocEntryArchive.cxx +++ b/src/gdcmDocEntryArchive.cxx @@ -3,8 +3,8 @@ Program: gdcm Module: $RCSfile: gdcmDocEntryArchive.cxx,v $ Language: C++ - Date: $Date: 2005/10/24 16:00:47 $ - Version: $Revision: 1.17 $ + Date: $Date: 2006/04/11 16:03:26 $ + 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 @@ -56,12 +56,17 @@ bool DocEntryArchive::Push(DocEntry *newEntry) if ( !newEntry ) return false; - uint16_t group = newEntry->GetDictEntry()->GetGroup(); - uint16_t elem = newEntry->GetDictEntry()->GetElement(); - TagKey key = DictEntry::TranslateToKey(group,elem); + //uint16_t group = newEntry->GetDictEntry()->GetGroup(); + //uint16_t elem = newEntry->GetDictEntry()->GetElement(); + //TagKey key = DictEntry::TranslateToKey(group,elem); + TagKey key = newEntry->GetKey(); + if ( Archive.find(key) == Archive.end() ) { + uint16_t group = newEntry->GetGroup(); + uint16_t elem = newEntry->GetElement(); + // Save the old DocEntry if any DocEntry *old = ArchFile->GetDocEntry(group, elem); Archive[key] = old; @@ -89,8 +94,8 @@ bool DocEntryArchive::Push(DocEntry *newEntry) */ bool DocEntryArchive::Push(uint16_t group, uint16_t elem) { - TagKey key = DictEntry::TranslateToKey(group, elem); - + //TagKey key = DictEntry::TranslateToKey(group, elem); + TagKey key(group, elem); if ( Archive.find(key)==Archive.end() ) { // Save the old DocEntry if any @@ -117,8 +122,8 @@ bool DocEntryArchive::Push(uint16_t group, uint16_t elem) */ bool DocEntryArchive::Restore(uint16_t group, uint16_t elem) { - TagKey key=DictEntry::TranslateToKey(group, elem); - + //TagKey key=DictEntry::TranslateToKey(group, elem); + TagKey key(group, elem); TagDocEntryHT::iterator restoreIt=Archive.find(key); if ( restoreIt!=Archive.end() ) { diff --git a/src/gdcmDocEntrySet.cxx b/src/gdcmDocEntrySet.cxx index 7be85dff..05a55249 100644 --- a/src/gdcmDocEntrySet.cxx +++ b/src/gdcmDocEntrySet.cxx @@ -3,8 +3,8 @@ Program: gdcm Module: $RCSfile: gdcmDocEntrySet.cxx,v $ Language: C++ - Date: $Date: 2006/03/22 13:19:25 $ - Version: $Revision: 1.71 $ + Date: $Date: 2006/04/11 16:03:26 $ + Version: $Revision: 1.72 $ Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de l'Image). All rights reserved. See Doc/License.txt or @@ -205,7 +205,7 @@ bool DocEntrySet::SetEntryBinArea(uint8_t *content, int lgth, DataEntry *entry) /** * \brief Modifies the value of a given Doc Entry (Dicom Element) - * when it exists. Create it with the given value when unexistant. + * when it exists. Creates it with the given value when unexistant. * @param value (string) Value to be set * @param group Group number of the Entry * @param elem Element number of the Entry @@ -219,7 +219,7 @@ DataEntry *DocEntrySet::InsertEntryString(std::string const &value, { DataEntry *dataEntry = 0; DocEntry *currentEntry = GetDocEntry( group, elem ); - + VRKey localVR = vr; if (currentEntry) { dataEntry = dynamic_cast(currentEntry); @@ -239,19 +239,35 @@ DataEntry *DocEntrySet::InsertEntryString(std::string const &value, } } } + + else // the 'currentEntry' was not found + { + if ( vr == GDCM_VRUNKNOWN ) // user didn't specify a VR. + // Probabely he trusts the Dicom Dict ! + { + DictEntry *e = + Global::GetDicts()->GetDefaultPubDict()->GetEntry(group, elem); + if ( e ) + { + localVR = e->GetVR(); + e->Register(); // ?? JPRx + } + } + } // Create a new dataEntry if necessary if ( !dataEntry ) { - dataEntry = NewDataEntry( group, elem, vr ); + dataEntry = NewDataEntry( group, elem, localVR ); if ( !AddEntry(dataEntry) ) { - gdcmWarningMacro("AddEntry failed although this is a creation."); + gdcmWarningMacro("AddEntry " << dataEntry->GetKey() + << " failed although this is a creation."); dataEntry->Delete(); return NULL; } - dataEntry->Delete(); + dataEntry->Delete(); // ?!? JPRx } // Set the dataEntry value @@ -398,6 +414,7 @@ bool DocEntrySet::CheckIfEntryExist(uint16_t group, uint16_t elem ) return GetDocEntry(group,elem)!=NULL; } + /** * \brief Build a new DataEntry from all the low level arguments. * Check for existence of dictionary entry, and build @@ -410,10 +427,8 @@ bool DocEntrySet::CheckIfEntryExist(uint16_t group, uint16_t elem ) DataEntry *DocEntrySet::NewDataEntry(uint16_t group,uint16_t elem, VRKey const &vr) { - DictEntry *dictEntry = GetDictEntry(group, elem, vr); - DataEntry *newEntry = DataEntry::New(dictEntry); - dictEntry->Unregister(); // GetDictEntry register it + DataEntry *newEntry = DataEntry::New(group,elem,vr); if (!newEntry) { gdcmWarningMacro( "Failed to allocate DataEntry for (" @@ -433,10 +448,11 @@ DataEntry *DocEntrySet::NewDataEntry(uint16_t group,uint16_t elem, */ SeqEntry* DocEntrySet::NewSeqEntry(uint16_t group, uint16_t elem) { - DictEntry *dictEntry = GetDictEntry(group, elem, "SQ"); + //DictEntry *dictEntry = GetDictEntry(group, elem, "SQ"); - SeqEntry *newEntry = SeqEntry::New( dictEntry ); - dictEntry->Unregister(); // GetDictEntry register it + //SeqEntry *newEntry = SeqEntry::New( dictEntry ); + SeqEntry *newEntry = SeqEntry::New( group,elem ); + //dictEntry->Unregister(); // GetDictEntry register it if (!newEntry) { gdcmWarningMacro( "Failed to allocate SeqEntry for (" @@ -462,7 +478,7 @@ DictEntry *DocEntrySet::GetDictEntry(uint16_t group,uint16_t elem) { DictEntry *found = 0; /// \todo store the DefaultPubDict somwhere, in order not to access the HTable - /// every time ! + /// every time ! --> Done! Dict *pubDict = Global::GetDicts()->GetDefaultPubDict(); if (!pubDict) { @@ -477,66 +493,6 @@ DictEntry *DocEntrySet::GetDictEntry(uint16_t group,uint16_t elem) return found; } -/** - * \brief Searches [both] the public [and the shadow dictionary (when they - * exist)] for the presence of the DictEntry with given - * group and element, and creates a new virtual DictEntry if necessary - * @param group group number of the searched DictEntry - * @param elem element number of the searched DictEntry - * @param vr V(alue) R(epresentation) to use, if necessary - * @return Corresponding DictEntry when it exists, NULL otherwise. - * \remarks The returned DictEntry is registered - */ -DictEntry *DocEntrySet::GetDictEntry(uint16_t group, uint16_t elem, - VRKey const &vr) -{ - DictEntry *dictEntry = GetDictEntry(group,elem); - DictEntry *goodEntry = dictEntry; - VRKey goodVR = vr; - TagName vm; - if (elem == 0x0000) - goodVR="UL"; - - if ( goodEntry ) - { - if ( goodVR != goodEntry->GetVR() - && goodVR != GDCM_VRUNKNOWN ) - { - gdcmWarningMacro("For (" << std::hex << group << "|" - << elem << "), found VR : [" << vr << "]" - << " expected: [" << goodEntry->GetVR() << "]" ) ; - // avoid confusing further validator with "FIXME" VM - // when possible - vm = dictEntry->GetVM(); - goodEntry = NULL; - } - dictEntry->Unregister(); - } - else - { - vm = "FIXME"; - } - // Create a new virtual DictEntry if necessary - if (!goodEntry) - { - if (dictEntry) - { - - goodEntry = DictEntry::New(group, elem, goodVR, vm, - dictEntry->GetName() ); - } - else - { - goodEntry = DictEntry::New(group, elem, goodVR); - } - } - else - { - goodEntry->Register(); - } - return goodEntry; -} - //----------------------------------------------------------------------------- // Private diff --git a/src/gdcmDocEntrySet.h b/src/gdcmDocEntrySet.h index d2a5f485..a9c98e42 100644 --- a/src/gdcmDocEntrySet.h +++ b/src/gdcmDocEntrySet.h @@ -3,8 +3,8 @@ Program: gdcm Module: $RCSfile: gdcmDocEntrySet.h,v $ Language: C++ - Date: $Date: 2005/11/30 08:48:17 $ - Version: $Revision: 1.67 $ + Date: $Date: 2006/04/11 16:03:26 $ + 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 @@ -121,8 +121,8 @@ protected: // DictEntry related utilities DictEntry *GetDictEntry(uint16_t group, uint16_t elem); - DictEntry *GetDictEntry(uint16_t group, uint16_t elem, - VRKey const &vr); + // DictEntry *GetDictEntry(uint16_t group, uint16_t elem, + // VRKey const &vr); /// To be able to backtrack (Private Sequence, Implicit VR related pb) DocEntry *PreviousDocEntry; diff --git a/src/gdcmDocument.cxx b/src/gdcmDocument.cxx index 06a91f83..d2991e70 100644 --- a/src/gdcmDocument.cxx +++ b/src/gdcmDocument.cxx @@ -3,8 +3,8 @@ Program: gdcm Module: $RCSfile: gdcmDocument.cxx,v $ Language: C++ - Date: $Date: 2006/03/14 12:09:18 $ - Version: $Revision: 1.345 $ + Date: $Date: 2006/04/11 16:03:26 $ + Version: $Revision: 1.346 $ Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de l'Image). All rights reserved. See Doc/License.txt or @@ -695,7 +695,6 @@ void Document::WriteContent(std::ofstream *fp, FileType filetype) fp->write(filePreamble, 128); fp->write("DICM", 4); } - /* * \todo rewrite later, if really usefull * - 'Group Length' element is optional in DICOM @@ -1053,7 +1052,7 @@ void Document::ParseDES(DocEntrySet *set, long offset, bool delim_mode_intern = delim_mode; bool first = true; gdcmDebugMacro( "Enter in ParseDES, delim-mode " << delim_mode - << " at offset " << std::hex << "0x(" << offset << ")" ); + << " at offset " << std::hex << "0x(" << offset << ")" ); while (true) { @@ -1063,10 +1062,10 @@ void Document::ParseDES(DocEntrySet *set, long offset, // Uncomment to track the bug /* if( Debug::GetDebugFlag() ) - std::cout << std::dec <<"(long)(Fp->tellg()) " << (long)(Fp->tellg()) + std::cout << std::dec <<"(long)(Fp->tellg()) " << (long)(Fp->tellg()) // in Debug mode << std::hex << " 0x(" <<(long)(Fp->tellg()) << ")" << std::endl; -*/ - +*/ + // if ( !delim_mode && ((long)(Fp->tellg())-offset) >= l_max) // Once per DocEntry if ( !delim_mode ) // 'and then' doesn't exist in C++ :-( if ( ((long)(Fp->tellg())-offset) >= l_max) // Once per DocEntry, when no delim mode @@ -1232,7 +1231,6 @@ void Document::ParseDES(DocEntrySet *set, long offset, l, delim_mode_intern); gdcmDebugMacro( "Exit from ParseSQ, delim " << delim_mode_intern); - } if ( !set->AddEntry( newSeqEntry ) ) { @@ -1593,7 +1591,9 @@ uint32_t Document::FindDocEntryLengthOBOrOW() VRKey Document::FindDocEntryVR() { if ( Filetype != ExplicitVR ) + { return GDCM_VRUNKNOWN; + } // Delimiters (0xfffe), are not explicit VR ... if ( CurrentGroup == 0xfffe ) @@ -1620,7 +1620,7 @@ VRKey Document::FindDocEntryVR() if ( !CheckDocEntryVR(vr) ) { /* - std::cout << "================================================================Unknown VR" +// std::cout << "================================================================Unknown VR" << std::hex << "0x(" << (unsigned int)vr[0] << "|" << (unsigned int)vr[1] << ")" << "for : " << CurrentGroup @@ -2052,7 +2052,7 @@ void Document::SwitchByteSwapCode() * \brief during parsing, Header Elements too long are not loaded in memory * @param newSize new size */ -void Document::SetMaxSizeLoadEntry(long newSize) +void Document::SetMaxSizeLoadEntry(long newSize) { if ( newSize < 0 ) { @@ -2071,7 +2071,7 @@ void Document::SetMaxSizeLoadEntry(long newSize) * (read the 'Group Number', the 'Element Number', * gets the Dict Entry * gets the VR, gets the length, gets the offset value) - * @return On succes : the newly created DocEntry, NULL on failure. + * @return On succes : the newly created DocEntry, NULL on failure. */ DocEntry *Document::ReadNextDocEntry() { @@ -2082,11 +2082,11 @@ DocEntry *Document::ReadNextDocEntry() } catch ( FormatError ) { - // We reached the EOF (or an error occured) therefore + // We reached the EOF (or an error occured) therefore // header parsing has to be considered as finished. return 0; } - + // In 'true DICOM' files Group 0002 is always little endian if ( HasDCMPreamble ) { @@ -2094,11 +2094,10 @@ DocEntry *Document::ReadNextDocEntry() HandleOutOfGroup0002(CurrentGroup, CurrentElem); else // Sometimes file contains groups of tags with reversed endianess. - HandleBrokenEndian(CurrentGroup, CurrentElem); + HandleBrokenEndian(CurrentGroup, CurrentElem); } - + VRKey vr = FindDocEntryVR(); - VRKey realVR = vr; if ( vr == GDCM_VRUNKNOWN ) @@ -2107,6 +2106,11 @@ DocEntry *Document::ReadNextDocEntry() { realVR = "UL"; // must be UL } + else if (CurrentGroup == 0xfffe) // Don't get DictEntry for Delimitors + { + realVR = "UL"; + } + // 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) @@ -2121,11 +2125,11 @@ DocEntry *Document::ReadNextDocEntry() */ else { - DictEntry *dictEntry = GetDictEntry(CurrentGroup,CurrentElem); + DictEntry *dictEntry = GetDictEntry(CurrentGroup,CurrentElem);//only when ImplicitVR if ( dictEntry ) { realVR = dictEntry->GetVR(); - dictEntry->Unregister(); + dictEntry->Unregister(); // GetDictEntry registered it } } } @@ -2133,8 +2137,10 @@ DocEntry *Document::ReadNextDocEntry() DocEntry *newEntry; //if ( Global::GetVR()->IsVROfSequence(realVR) ) if (realVR == "SQ") + { newEntry = NewSeqEntry(CurrentGroup, CurrentElem); - else + } + else { newEntry = NewDataEntry(CurrentGroup, CurrentElem, realVR); static_cast(newEntry)->SetState(DataEntry::STATE_NOTLOADED); @@ -2146,14 +2152,14 @@ DocEntry *Document::ReadNextDocEntry() { // We thought this was explicit VR, but we end up with an // implicit VR tag. Let's backtrack. - if ( newEntry->GetGroup() != 0xfffe ) + + //if ( newEntry->GetGroup() != 0xfffe ) + if (CurrentGroup != 0xfffe ) { - std::string msg; int offset = Fp->tellg();//Only when heuristic for Explicit/Implicit was wrong - msg = Util::Format( - "Entry (%04x,%04x) at x(%x) should be Explicit VR\n", - newEntry->GetGroup(), newEntry->GetElement(), offset ); - gdcmWarningMacro( msg.c_str() ); + + gdcmWarningMacro("Entry (" << newEntry->GetKey() << ") at x(" + << offset << ") should be Explicit VR"); } } newEntry->SetImplicitVR(); diff --git a/src/gdcmFile.cxx b/src/gdcmFile.cxx index 6d45581b..4ccb1e7a 100644 --- a/src/gdcmFile.cxx +++ b/src/gdcmFile.cxx @@ -3,8 +3,8 @@ Program: gdcm Module: $RCSfile: gdcmFile.cxx,v $ Language: C++ - Date: $Date: 2006/03/29 16:13:00 $ - Version: $Revision: 1.317 $ + Date: $Date: 2006/04/11 16:03:26 $ + Version: $Revision: 1.318 $ Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de l'Image). All rights reserved. See Doc/License.txt or @@ -216,6 +216,11 @@ bool File::DoTheLoadingJob( ) // The changed DictEntry will have // - a correct PixelVR OB or OW) // - the name to "Pixel Data" + + //==>Take it easy! + //==> Just change the VR ! + +/* DataEntry *oldEntry = dynamic_cast(entry); if (oldEntry) { @@ -229,21 +234,34 @@ bool File::DoTheLoadingJob( ) // Change only made if usefull if ( PixelVR != oldEntry->GetVR() ) - { - DictEntry* newDict = DictEntry::New(GrPixel,NumPixel, - PixelVR,"1","Pixel Data"); - - DataEntry *newEntry = DataEntry::New(newDict); - newDict->Delete(); - newEntry->Copy(entry); - newEntry->SetBinArea(oldEntry->GetBinArea(),oldEntry->IsSelfArea()); - oldEntry->SetSelfArea(false); - - RemoveEntry(oldEntry); - AddEntry(newEntry); - newEntry->Delete(); + { + //DictEntry* newDict = DictEntry::New(GrPixel,NumPixel, + // PixelVR,"1","Pixel Data"); + //DataEntry *newEntry = DataEntry::New(newDict); + //newDict->Delete(); + //newEntry->Copy(entry); + //newEntry->SetBinArea(oldEntry->GetBinArea(),oldEntry->IsSelfArea()); + //oldEntry->SetSelfArea(false); + + //RemoveEntry(oldEntry); + //AddEntry(newEntry); + //newEntry->Delete(); + } } +*/ + VRKey PixelVR; + // 8 bits allocated is a 'O Bytes' , as well as 24 (old ACR-NEMA RGB) + // more than 8 (i.e 12, 16) is a 'O Words' + if ( GetBitsAllocated() == 8 || GetBitsAllocated() == 24 ) + PixelVR = "OB"; + else + PixelVR = "OW"; + // Change only made if usefull + if ( PixelVR != entry->GetVR() ) + { + entry->SetVR(PixelVR); + } } return true; } @@ -1539,7 +1557,7 @@ bool File::Write(std::string fileName, FileType writetype) // no (GrPixel, NumPixel) element std::string s_lgPix = Util::Format("%d", i_lgPix+12); s_lgPix = Util::DicomString( s_lgPix.c_str() ); - InsertEntryString(s_lgPix,GrPixel, 0x0000); + InsertEntryString(s_lgPix,GrPixel, 0x0000, "UL"); } } Document::WriteContent(fp, writetype); diff --git a/src/gdcmFileHelper.cxx b/src/gdcmFileHelper.cxx index 7e7be8e5..12bfe7cf 100644 --- a/src/gdcmFileHelper.cxx +++ b/src/gdcmFileHelper.cxx @@ -4,8 +4,8 @@ Module: $RCSfile: gdcmFileHelper.cxx,v $ Language: C++ - Date: $Date: 2006/03/29 16:09:48 $ - Version: $Revision: 1.98 $ + Date: $Date: 2006/04/11 16:03:26 $ + Version: $Revision: 1.99 $ Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de l'Image). All rights reserved. See Doc/License.txt or @@ -661,6 +661,9 @@ bool FileHelper::WriteAcr (std::string const &fileName) */ bool FileHelper::Write(std::string const &fileName) { + + CheckMandatoryElements(); //called once, here ! + bool flag = false; DocEntry *e; switch(WriteType) @@ -671,7 +674,7 @@ bool FileHelper::Write(std::string const &fileName) case Unknown: // should never happen; ExplicitVR is the default value case ExplicitVR: - + // User should ask gdcm to write an image in Explicit VR mode // only when he is sure *all* the VR of *all* the DataElements is known. // i.e : when there are *only* Public Groups @@ -680,10 +683,11 @@ bool FileHelper::Write(std::string const &fileName) // Let's just *dream* about it; *never* trust a user ! // We turn to Implicit VR if at least the VR of one element is unknown. + e = FileInternal->GetFirstEntry(); while (e != 0) { - if (e->GetVR() == " ") + if (e->GetVR() == " ") { SetWriteTypeToDcmImplVR(); SetWriteFileTypeToImplicitVR(); @@ -698,7 +702,9 @@ bool FileHelper::Write(std::string const &fileName) SetWriteFileTypeToExplicitVR(); } break; - + + SetWriteFileTypeToExplicitVR(); // to see JPRx + break; case ACR: case ACR_LIBIDO: // NOTHING is done here just for LibIDO. @@ -708,7 +714,8 @@ bool FileHelper::Write(std::string const &fileName) // (shame on him !) // We add Recognition Code (RET) if ( ! FileInternal->GetDataEntry(0x0008, 0x0010) ) - FileInternal->InsertEntryString("ACR-NEMA V1.0 ", 0x0008, 0x0010); + FileInternal->InsertEntryString("ACR-NEMA V1.0 ", + 0x0008, 0x0010, "LO"); SetWriteFileTypeToACR(); // SetWriteFileTypeToImplicitVR(); // ACR IS implicit VR ! break; @@ -718,9 +725,7 @@ bool FileHelper::Write(std::string const &fileName) SetWriteFileTypeToJPEG(); break; } - - CheckMandatoryElements(); - + // -------------------------------------------------------------- // Special Patch to allow gdcm to re-write ACR-LibIDO formated images // @@ -757,9 +762,10 @@ bool FileHelper::Write(std::string const &fileName) check = FileInternal->Write(fileName,WriteType); } - RestoreWrite(); - RestoreWriteFileType(); - RestoreWriteMandatory(); + RestoreWrite(); + // RestoreWriteFileType(); + // RestoreWriteMandatory(); + // -------------------------------------------------------------- // Special Patch to allow gdcm to re-write ACR-LibIDO formated images @@ -845,7 +851,7 @@ void FileHelper::SetWriteToRaw() } else { - DataEntry *photInt = CopyDataEntry(0x0028,0x0004); + DataEntry *photInt = CopyDataEntry(0x0028,0x0004,"CS"); if (FileInternal->HasLUT() ) { photInt->SetString("PALETTE COLOR "); @@ -890,13 +896,13 @@ void FileHelper::SetWriteToRGB() { PixelReadConverter->BuildRGBImage(); - DataEntry *spp = CopyDataEntry(0x0028,0x0002); + DataEntry *spp = CopyDataEntry(0x0028,0x0002,"US"); spp->SetString("3 "); - DataEntry *planConfig = CopyDataEntry(0x0028,0x0006); + DataEntry *planConfig = CopyDataEntry(0x0028,0x0006,"US"); planConfig->SetString("0 "); - DataEntry *photInt = CopyDataEntry(0x0028,0x0004); + DataEntry *photInt = CopyDataEntry(0x0028,0x0004,"CS"); photInt->SetString("RGB "); if ( PixelReadConverter->GetRGB() ) @@ -947,13 +953,13 @@ void FileHelper::SetWriteToRGB() // samples per pixels = 1 (in the read file) if ( FileInternal->GetBitsAllocated()==24 ) { - DataEntry *bitsAlloc = CopyDataEntry(0x0028,0x0100); + DataEntry *bitsAlloc = CopyDataEntry(0x0028,0x0100,"US"); bitsAlloc->SetString("8 "); - DataEntry *bitsStored = CopyDataEntry(0x0028,0x0101); + DataEntry *bitsStored = CopyDataEntry(0x0028,0x0101,"US"); bitsStored->SetString("8 "); - DataEntry *highBit = CopyDataEntry(0x0028,0x0102); + DataEntry *highBit = CopyDataEntry(0x0028,0x0102,"US"); highBit->SetString("7 "); Archive->Push(bitsAlloc); @@ -976,8 +982,10 @@ void FileHelper::SetWriteToRGB() */ void FileHelper::RestoreWrite() { + Archive->Restore(0x0028,0x0002); Archive->Restore(0x0028,0x0004); + Archive->Restore(0x0028,0x0006); Archive->Restore(GetFile()->GetGrPixel(),GetFile()->GetNumPixel()); @@ -997,7 +1005,6 @@ void FileHelper::RestoreWrite() // For the Palette Color Lookup Table UID Archive->Restore(0x0028,0x1203); - // group 0002 may be pushed out for ACR-NEMA writting purposes Archive->Restore(0x0002,0x0000); Archive->Restore(0x0002,0x0001); @@ -1009,6 +1016,7 @@ void FileHelper::RestoreWrite() Archive->Restore(0x0002,0x0016); Archive->Restore(0x0002,0x0100); Archive->Restore(0x0002,0x0102); + } /** @@ -1040,7 +1048,7 @@ void FileHelper::SetWriteFileTypeToJPEG() std::string ts = Util::DicomString( Global::GetTS()->GetSpecialTransferSyntax(TS::JPEGBaselineProcess1) ); - DataEntry *tss = CopyDataEntry(0x0002,0x0010); + DataEntry *tss = CopyDataEntry(0x0002,0x0010,"UI"); tss->SetString(ts); Archive->Push(tss); @@ -1055,7 +1063,7 @@ void FileHelper::SetWriteFileTypeToExplicitVR() std::string ts = Util::DicomString( Global::GetTS()->GetSpecialTransferSyntax(TS::ExplicitVRLittleEndian) ); - DataEntry *tss = CopyDataEntry(0x0002,0x0010); + DataEntry *tss = CopyDataEntry(0x0002,0x0010,"UI"); tss->SetString(ts); Archive->Push(tss); tss->Delete(); @@ -1069,7 +1077,7 @@ void FileHelper::SetWriteFileTypeToImplicitVR() std::string ts = Util::DicomString( Global::GetTS()->GetSpecialTransferSyntax(TS::ImplicitVRLittleEndian) ); - DataEntry *tss = CopyDataEntry(0x0002,0x0010); + DataEntry *tss = CopyDataEntry(0x0002,0x0010,"UI"); tss->SetString(ts); Archive->Push(tss); tss->Delete(); @@ -1095,9 +1103,12 @@ void FileHelper::SetWriteToLibido() { std::string rows, columns; - DataEntry *newRow=DataEntry::New(oldRow->GetDictEntry()); - DataEntry *newCol=DataEntry::New(oldCol->GetDictEntry()); - + //DataEntry *newRow=DataEntry::New(oldRow->GetDictEntry()); + //DataEntry *newCol=DataEntry::New(oldCol->GetDictEntry()); + + DataEntry *newRow=DataEntry::New(0x0028, 0x0010, "US"); + DataEntry *newCol=DataEntry::New(0x0028, 0x0011, "US"); + newRow->Copy(oldCol); newCol->Copy(oldRow); @@ -1111,7 +1122,7 @@ void FileHelper::SetWriteToLibido() newCol->Delete(); } - DataEntry *libidoCode = CopyDataEntry(0x0008,0x0010); + DataEntry *libidoCode = CopyDataEntry(0x0008,0x0010,"LO"); libidoCode->SetString("ACRNEMA_LIBIDO_1.1"); Archive->Push(libidoCode); libidoCode->Delete(); @@ -1127,7 +1138,7 @@ void FileHelper::SetWriteToNoLibido() { if ( recCode->GetString() == "ACRNEMA_LIBIDO_1.1" ) { - DataEntry *libidoCode = CopyDataEntry(0x0008,0x0010); + DataEntry *libidoCode = CopyDataEntry(0x0008,0x0010,"LO"); libidoCode->SetString(""); Archive->Push(libidoCode); libidoCode->Delete(); @@ -1156,11 +1167,10 @@ void FileHelper::RestoreWriteOfLibido() * @param group Group number of the Entry * @param elem Element number of the Entry * @param vr Value Representation of the Entry - * FIXME : what is it used for? * \return pointer to the new Bin Entry (NULL when creation failed). */ DataEntry *FileHelper::CopyDataEntry(uint16_t group, uint16_t elem, - const TagName &vr) + const VRKey &vr) { DocEntry *oldE = FileInternal->GetDocEntry(group, elem); DataEntry *newE; @@ -1171,7 +1181,8 @@ DataEntry *FileHelper::CopyDataEntry(uint16_t group, uint16_t elem, if ( oldE ) { - newE = DataEntry::New(oldE->GetDictEntry()); + //newE = DataEntry::New(oldE->GetDictEntry()); + newE = DataEntry::New(group, elem, vr); newE->Copy(oldE); } else @@ -1378,7 +1389,7 @@ void FileHelper::CheckMandatoryElements() // Create them if not found // Always modify the value // Push the entries to the archive. - CopyMandatoryEntry(0x0002,0x0000,"0"); + CopyMandatoryEntry(0x0002,0x0000,"0","UL"); DataEntry *e_0002_0001 = CopyDataEntry(0x0002,0x0001, "OB"); e_0002_0001->SetBinArea((uint8_t*)Util::GetFileMetaInformationVersion(), @@ -1390,41 +1401,90 @@ void FileHelper::CheckMandatoryElements() if ( ContentType == FILTERED_IMAGE || ContentType == UNMODIFIED_PIXELS_IMAGE) { // we keep the original 'Media Storage SOP Class UID', we default it if missing - CheckMandatoryEntry(0x0002,0x0002,"1.2.840.10008.5.1.4.1.1.7"); + CheckMandatoryEntry(0x0002,0x0002,"1.2.840.10008.5.1.4.1.1.7","UI"); } else { // It's *not* an image comming straight from a source. We force // 'Media Storage SOP Class UID' --> [Secondary Capture Image Storage] - CopyMandatoryEntry(0x0002,0x0002,"1.2.840.10008.5.1.4.1.1.7"); + CopyMandatoryEntry(0x0002,0x0002,"1.2.840.10008.5.1.4.1.1.7","UI"); } // 'Media Storage SOP Instance UID' - CopyMandatoryEntry(0x0002,0x0003,sop); + CopyMandatoryEntry(0x0002,0x0003,sop,"UI"); // 'Implementation Class UID' // FIXME : in all examples we have, 0x0002,0x0012 is not so long : // seems to be Root UID + 4 digits (?) - CopyMandatoryEntry(0x0002,0x0012,Util::CreateUniqueUID()); + CopyMandatoryEntry(0x0002,0x0012,Util::CreateUniqueUID(),"UI"); // 'Implementation Version Name' std::string version = "GDCM "; version += Util::GetVersion(); - CopyMandatoryEntry(0x0002,0x0013,version); + CopyMandatoryEntry(0x0002,0x0013,version,"SH"); } // --------------------- For DataSet --------------------- + + if ( ContentType != USER_OWN_IMAGE) // when it's not a user made image + { + + gdcmDebugMacro( "USER_OWN_IMAGE (1)"); + // If 'SOP Class UID' exists ('true DICOM' image) + // we create the 'Source Image Sequence' SeqEntry + // to hold informations about the Source Image + + DataEntry *e_0008_0016 = FileInternal->GetDataEntry(0x0008, 0x0016); + if ( e_0008_0016 ) + { + // Create 'Source Image Sequence' SeqEntry +// SeqEntry *sis = SeqEntry::New ( +// Global::GetDicts()->GetDefaultPubDict()->GetEntry(0x0008, 0x2112) ); + SeqEntry *sis = SeqEntry::New (0x0008, 0x2112); + SQItem *sqi = SQItem::New(1); + // (we assume 'SOP Instance UID' exists too) + // create 'Referenced SOP Class UID' +// DataEntry *e_0008_1150 = DataEntry::New( +// Global::GetDicts()->GetDefaultPubDict()->GetEntry(0x0008, 0x1150) ); + DataEntry *e_0008_1150 = DataEntry::New(0x0008, 0x1150, "UI"); + e_0008_1150->SetString( e_0008_0016->GetString()); + sqi->AddEntry(e_0008_1150); + e_0008_1150->Delete(); + + // create 'Referenced SOP Instance UID' + DataEntry *e_0008_0018 = FileInternal->GetDataEntry(0x0008, 0x0018); +// DataEntry *e_0008_1155 = DataEntry::New( +// Global::GetDicts()->GetDefaultPubDict()->GetEntry(0x0008, 0x1155) ); + DataEntry *e_0008_1155 = DataEntry::New(0x0008, 0x1155, "UI"); + e_0008_1155->SetString( e_0008_0018->GetString()); + sqi->AddEntry(e_0008_1155); + e_0008_1155->Delete(); + + sis->AddSQItem(sqi,1); + sqi->Delete(); + + // temporarily replaces any previous 'Source Image Sequence' + Archive->Push(sis); + sis->Delete(); + + // FIXME : is 'Image Type' *really* depending on the presence of 'SOP Class UID'? + if ( ContentType == FILTERED_IMAGE) + // the user *knows* he just modified the pixels + // the image is no longer an 'Original' one + CopyMandatoryEntry(0x0008,0x0008,"DERIVED\\PRIMARY","CS"); + } + } if ( ContentType == FILTERED_IMAGE || ContentType == UNMODIFIED_PIXELS_IMAGE) { // we keep the original 'Media Storage SOP Class UID', we default it if missing (it should be present !) - CheckMandatoryEntry(0x0008,0x0016,"1.2.840.10008.5.1.4.1.1.7"); + CheckMandatoryEntry(0x0008,0x0016,"1.2.840.10008.5.1.4.1.1.7","UI"); } else { // It's *not* an image comming straight from a source. We force // 'Media Storage SOP Class UID' --> [Secondary Capture Image Storage] - CopyMandatoryEntry(0x0008,0x0016,"1.2.840.10008.5.1.4.1.1.7"); + CopyMandatoryEntry(0x0008,0x0016,"1.2.840.10008.5.1.4.1.1.7", "UI"); } // Push out 'LibIDO-special' entries, if any @@ -1437,7 +1497,7 @@ void FileHelper::CheckMandatoryElements() // - we're gonna write the image as Bits Stored = 16 if ( FileInternal->GetEntryString(0x0028,0x0100) == "12") { - CopyMandatoryEntry(0x0028,0x0100,"16"); + CopyMandatoryEntry(0x0028,0x0100,"16","US"); } // Check if user wasn't drunk ;-) @@ -1447,7 +1507,7 @@ void FileHelper::CheckMandatoryElements() int nbBitsAllocated = FileInternal->GetBitsAllocated(); if ( nbBitsAllocated == 0 || nbBitsAllocated > 32) { - CopyMandatoryEntry(0x0028,0x0100,"16"); + CopyMandatoryEntry(0x0028,0x0100,"16","US"); gdcmWarningMacro("(0028,0100) changed from " << nbBitsAllocated << " to 16 for consistency purpose"); nbBitsAllocated = 16; @@ -1458,7 +1518,7 @@ void FileHelper::CheckMandatoryElements() { s.str(""); s << nbBitsAllocated; - CopyMandatoryEntry(0x0028,0x0101,s.str()); + CopyMandatoryEntry(0x0028,0x0101,s.str(),"US"); gdcmWarningMacro("(0028,0101) changed from " << nbBitsStored << " to " << nbBitsAllocated << " for consistency purpose" ); @@ -1472,7 +1532,7 @@ void FileHelper::CheckMandatoryElements() { s.str(""); s << nbBitsStored - 1; - CopyMandatoryEntry(0x0028,0x0102,s.str()); + CopyMandatoryEntry(0x0028,0x0102,s.str(),"US"); gdcmWarningMacro("(0028,0102) changed from " << highBitPosition << " to " << nbBitsAllocated-1 << " for consistency purpose"); @@ -1483,7 +1543,7 @@ void FileHelper::CheckMandatoryElements() { pixelSpacing = "1.0\\1.0"; // if missing, Pixel Spacing forced to "1.0\1.0" - CopyMandatoryEntry(0x0028,0x0030,pixelSpacing); + CopyMandatoryEntry(0x0028,0x0030,pixelSpacing,"DS"); } // 'Imager Pixel Spacing' : defaulted to 'Pixel Spacing' @@ -1491,65 +1551,21 @@ void FileHelper::CheckMandatoryElements() if ( ContentType != USER_OWN_IMAGE) // we write it only when we are *sure* the image comes from // an imager (see also 0008,0x0064) - CheckMandatoryEntry(0x0018,0x1164,pixelSpacing); + CheckMandatoryEntry(0x0018,0x1164,pixelSpacing,"DS"); // Samples Per Pixel (type 1) : default to grayscale - CheckMandatoryEntry(0x0028,0x0002,"1"); + CheckMandatoryEntry(0x0028,0x0002,"1","US"); // --- Check UID-related Entries --- - - - if ( ContentType != USER_OWN_IMAGE) // when it's not a user made image - { - // If 'SOP Class UID' exists ('true DICOM' image) - // we create the 'Source Image Sequence' SeqEntry - // to hold informations about the Source Image - - DataEntry *e_0008_0016 = FileInternal->GetDataEntry(0x0008, 0x0016); - if ( e_0008_0016 ) - { - // Create 'Source Image Sequence' SeqEntry - SeqEntry *sis = SeqEntry::New ( - Global::GetDicts()->GetDefaultPubDict()->GetEntry(0x0008, 0x2112) ); - SQItem *sqi = SQItem::New(1); - // (we assume 'SOP Instance UID' exists too) - // create 'Referenced SOP Class UID' - DataEntry *e_0008_1150 = DataEntry::New( - Global::GetDicts()->GetDefaultPubDict()->GetEntry(0x0008, 0x1150) ); - e_0008_1150->SetString( e_0008_0016->GetString()); - sqi->AddEntry(e_0008_1150); - e_0008_1150->Delete(); - - // create 'Referenced SOP Instance UID' - DataEntry *e_0008_0018 = FileInternal->GetDataEntry(0x0008, 0x0018); - DataEntry *e_0008_1155 = DataEntry::New( - Global::GetDicts()->GetDefaultPubDict()->GetEntry(0x0008, 0x1155) ); - e_0008_1155->SetString( e_0008_0018->GetString()); - sqi->AddEntry(e_0008_1155); - e_0008_1155->Delete(); - - sis->AddSQItem(sqi,1); - sqi->Delete(); - - // temporarily replaces any previous 'Source Image Sequence' - Archive->Push(sis); - sis->Delete(); - // FIXME : is 'Image Type' *really* depending on the presence of 'SOP Class UID'? - if ( ContentType == FILTERED_IMAGE) - // the user *knows* he just modified the pixels - // the image is no longer an 'Original' one - CopyMandatoryEntry(0x0008,0x0008,"DERIVED\\PRIMARY"); - } - } - // At the end, not to overwrite the original ones, // needed by 'Referenced SOP Instance UID', 'Referenced SOP Class UID' // 'SOP Instance UID' - CopyMandatoryEntry(0x0008,0x0018,sop); + CopyMandatoryEntry(0x0008,0x0018,sop,"UI"); if ( ContentType == USER_OWN_IMAGE) { + gdcmDebugMacro( "USER_OWN_IMAGE (2)"); // Conversion Type. // Other possible values are : // See PS 3.3, Page 408 @@ -1563,7 +1579,7 @@ void FileHelper::CheckMandatoryElements() // DRW = Drawing // SYN = Synthetic Image - CheckMandatoryEntry(0x0008,0x0064,"SYN"); // Why not? + CheckMandatoryEntry(0x0008,0x0064,"SYN","CS"); // Why not? } /* if ( ContentType == CREATED_IMAGE) @@ -1580,20 +1596,20 @@ void FileHelper::CheckMandatoryElements() // Instance Creation Date const std::string &date = Util::GetCurrentDate(); - CopyMandatoryEntry(0x0008,0x0012,date); + CopyMandatoryEntry(0x0008,0x0012,date,"DA"); // Instance Creation Time const std::string &time = Util::GetCurrentTime(); - CopyMandatoryEntry(0x0008,0x0013,time); + CopyMandatoryEntry(0x0008,0x0013,time,"TM"); // Study Date - CheckMandatoryEntry(0x0008,0x0020,date); + CheckMandatoryEntry(0x0008,0x0020,date,"DA"); // Study Time - CheckMandatoryEntry(0x0008,0x0030,time); + CheckMandatoryEntry(0x0008,0x0030,time,"TM"); // Accession Number //CopyMandatoryEntry(0x0008,0x0050,""); - CheckMandatoryEntry(0x0008,0x0050,""); + CheckMandatoryEntry(0x0008,0x0050,"","SH"); // ----- Add Mandatory Entries if missing --- @@ -1611,7 +1627,7 @@ void FileHelper::CheckMandatoryElements() // keeping the same 'Study Instance UID' for various images // The user may add images to a 'Manufacturer Study', // adding new Series to an already existing Study - CheckMandatoryEntry(0x0020,0x000d,Util::CreateUniqueUID()); + CheckMandatoryEntry(0x0020,0x000d,Util::CreateUniqueUID(),"UI"); // 'Serie Instance UID' // Keep the value if exists @@ -1619,16 +1635,16 @@ void FileHelper::CheckMandatoryElements() // keeping the same 'Serie Instance UID' for various images // The user shouldn't add any image to a 'Manufacturer Serie' // but there is no way no to prevent him for doing that - CheckMandatoryEntry(0x0020,0x000e,Util::CreateUniqueUID()); + CheckMandatoryEntry(0x0020,0x000e,Util::CreateUniqueUID(),"UI"); // Study ID - CheckMandatoryEntry(0x0020,0x0010,""); + CheckMandatoryEntry(0x0020,0x0010,"","SH"); // Series Number - CheckMandatoryEntry(0x0020,0x0011,""); + CheckMandatoryEntry(0x0020,0x0011,"","IS"); // Instance Number - CheckMandatoryEntry(0x0020,0x0013,""); + CheckMandatoryEntry(0x0020,0x0013,"","IS"); // Patient Orientation // Can be computed from (0020|0037) : Image Orientation (Patient) @@ -1636,36 +1652,36 @@ void FileHelper::CheckMandatoryElements() std::string ori = o->GetOrientation ( FileInternal ); o->Delete(); if (ori != "\\" && ori != GDCM_UNFOUND) - CheckMandatoryEntry(0x0020,0x0020,ori); + CheckMandatoryEntry(0x0020,0x0020,ori,"CS"); else - CheckMandatoryEntry(0x0020,0x0020,""); + CheckMandatoryEntry(0x0020,0x0020,"","CS"); // Default Patient Position to HFS - CheckMandatoryEntry(0x0018,0x5100,"HFS"); + CheckMandatoryEntry(0x0018,0x5100,"HFS","CS"); // Modality : if missing we set it to 'OTher' - CheckMandatoryEntry(0x0008,0x0060,"OT"); + CheckMandatoryEntry(0x0008,0x0060,"OT","CS"); // Manufacturer : if missing we set it to 'GDCM Factory' - CheckMandatoryEntry(0x0008,0x0070,"GDCM Factory"); + CheckMandatoryEntry(0x0008,0x0070,"GDCM Factory","LO"); // Institution Name : if missing we set it to 'GDCM Hospital' - CheckMandatoryEntry(0x0008,0x0080,"GDCM Hospital"); + CheckMandatoryEntry(0x0008,0x0080,"GDCM Hospital","LO"); // Patient's Name : if missing, we set it to 'GDCM^Patient' - CheckMandatoryEntry(0x0010,0x0010,"GDCM^Patient"); + CheckMandatoryEntry(0x0010,0x0010,"GDCM^Patient","PN"); // Patient ID - CheckMandatoryEntry(0x0010,0x0020,""); + CheckMandatoryEntry(0x0010,0x0020,"","LO"); // Patient's Birth Date : 'type 2' entry -> must exist, value not mandatory - CheckMandatoryEntry(0x0010,0x0030,""); + CheckMandatoryEntry(0x0010,0x0030,"","DA"); // Patient's Sex :'type 2' entry -> must exist, value not mandatory - CheckMandatoryEntry(0x0010,0x0040,""); + CheckMandatoryEntry(0x0010,0x0040,"","CS"); // Referring Physician's Name :'type 2' entry -> must exist, value not mandatory - CheckMandatoryEntry(0x0008,0x0090,""); + CheckMandatoryEntry(0x0008,0x0090,"","PN"); /* // Deal with element 0x0000 (group length) of each group. @@ -1688,29 +1704,32 @@ void FileHelper::CheckMandatoryElements() } -void FileHelper::CheckMandatoryEntry(uint16_t group,uint16_t elem,std::string value) +void FileHelper::CheckMandatoryEntry(uint16_t group,uint16_t elem,std::string value,const VRKey &vr ) { DataEntry *entry = FileInternal->GetDataEntry(group,elem); if ( !entry ) { - entry = DataEntry::New(Global::GetDicts()->GetDefaultPubDict()->GetEntry(group,elem)); + //entry = DataEntry::New(Global::GetDicts()->GetDefaultPubDict()->GetEntry(group,elem)); + entry = DataEntry::New(group,elem,vr); entry->SetString(value); Archive->Push(entry); entry->Delete(); - } + } } -void FileHelper::SetMandatoryEntry(uint16_t group,uint16_t elem,std::string value) +/// \todo : what is it used for ? (FileHelper::SetMandatoryEntry) +void FileHelper::SetMandatoryEntry(uint16_t group,uint16_t elem,std::string value,const VRKey &vr) { - DataEntry *entry = DataEntry::New(Global::GetDicts()->GetDefaultPubDict()->GetEntry(group,elem)); + //DataEntry *entry = DataEntry::New(Global::GetDicts()->GetDefaultPubDict()->GetEntry(group,elem)); + DataEntry *entry = DataEntry::New(group,elem,vr); entry->SetString(value); Archive->Push(entry); entry->Delete(); } -void FileHelper::CopyMandatoryEntry(uint16_t group,uint16_t elem,std::string value) +void FileHelper::CopyMandatoryEntry(uint16_t group,uint16_t elem,std::string value,const VRKey &vr) { - DataEntry *entry = CopyDataEntry(group,elem); + DataEntry *entry = CopyDataEntry(group,elem,vr); entry->SetString(value); Archive->Push(entry); entry->Delete(); diff --git a/src/gdcmFileHelper.h b/src/gdcmFileHelper.h index 86bf7c61..fe5f725f 100644 --- a/src/gdcmFileHelper.h +++ b/src/gdcmFileHelper.h @@ -3,8 +3,8 @@ Program: gdcm Module: $RCSfile: gdcmFileHelper.h,v $ Language: C++ - Date: $Date: 2006/03/29 16:09:48 $ - Version: $Revision: 1.41 $ + Date: $Date: 2006/04/11 16:03:26 $ + 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 @@ -21,6 +21,7 @@ #include "gdcmDebug.h" #include "gdcmRefCounter.h" +#include "gdcmVRKey.h" #include "gdcmFile.h" namespace gdcm @@ -191,11 +192,14 @@ protected: void RestoreWriteOfLibido(); DataEntry *CopyDataEntry(uint16_t group, uint16_t elem, - const TagName &vr = GDCM_VRUNKNOWN); + const VRKey &vr = GDCM_VRUNKNOWN); void CheckMandatoryElements(); - void CheckMandatoryEntry(uint16_t group, uint16_t elem, std::string value); - void SetMandatoryEntry(uint16_t group, uint16_t elem, std::string value); - void CopyMandatoryEntry(uint16_t group, uint16_t elem, std::string value); + void CheckMandatoryEntry(uint16_t group, uint16_t elem, std::string value, + const VRKey &vr = GDCM_VRUNKNOWN); + void SetMandatoryEntry(uint16_t group, uint16_t elem, std::string value, + const VRKey &vr = GDCM_VRUNKNOWN); + void CopyMandatoryEntry(uint16_t group, uint16_t elem, std::string value, + const VRKey &vr = GDCM_VRUNKNOWN); void RestoreWriteMandatory(); private: diff --git a/src/gdcmMacro.h b/src/gdcmMacro.h index 5798178f..edbcf2d8 100644 --- a/src/gdcmMacro.h +++ b/src/gdcmMacro.h @@ -3,8 +3,8 @@ Program: gdcm Module: $RCSfile: gdcmMacro.h,v $ Language: C++ - Date: $Date: 2005/11/28 15:20:34 $ - Version: $Revision: 1.3 $ + Date: $Date: 2006/04/11 16:03:26 $ + Version: $Revision: 1.4 $ Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de l'Image). All rights reserved. See Doc/License.txt or @@ -20,13 +20,13 @@ #define GDCMMACRO_H //----------------------------------------------------------------------------- -#define gdcmTypeMacro(type) \ - private : \ +#define gdcmTypeMacro(type) \ + private : \ type(type &); /* Not implemented */ \ type &operator=(type &) /* Not implemented */ -#define gdcmNewMacro(type) \ - public : \ +#define gdcmNewMacro(type) \ + public : \ static type *New() {return new type(); } /* Not implemented */ //----------------------------------------------------------------------------- diff --git a/src/gdcmRefCounter.h b/src/gdcmRefCounter.h index cafb7849..bb036b7f 100644 --- a/src/gdcmRefCounter.h +++ b/src/gdcmRefCounter.h @@ -3,8 +3,8 @@ Program: gdcm Module: $RCSfile: gdcmRefCounter.h,v $ Language: C++ - Date: $Date: 2005/11/28 15:20:34 $ - Version: $Revision: 1.9 $ + Date: $Date: 2006/04/11 16:03:26 $ + Version: $Revision: 1.10 $ Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de l'Image). All rights reserved. See Doc/License.txt or @@ -20,6 +20,8 @@ #define GDCMREFCOUNTER_H #include "gdcmBase.h" +//#include "gdcmDebug.h" +#include namespace gdcm { @@ -47,9 +49,10 @@ public: /// \remarks It decrements the reference counting void Unregister() { +//std::cout <<"================Unreg " << typeid(*this).name() << std::endl; RefCount--; if(RefCount<=0) - delete this; + delete this; } /// \brief Get the reference counting /// \return Reference count diff --git a/src/gdcmSeqEntry.cxx b/src/gdcmSeqEntry.cxx index 5e7113f6..9ce89bbc 100644 --- a/src/gdcmSeqEntry.cxx +++ b/src/gdcmSeqEntry.cxx @@ -3,8 +3,8 @@ Program: gdcm Module: $RCSfile: gdcmSeqEntry.cxx,v $ Language: C++ - Date: $Date: 2006/02/16 20:06:15 $ - Version: $Revision: 1.65 $ + Date: $Date: 2006/04/11 16:03:26 $ + Version: $Revision: 1.66 $ Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de l'Image). All rights reserved. See Doc/License.txt or @@ -30,12 +30,14 @@ namespace gdcm { //----------------------------------------------------------------------------- +// Constructor / Destructor + // Constructor / Destructor /** * \brief Constructor from a given SeqEntry */ -SeqEntry::SeqEntry( DictEntry *e ) - : DocEntry(e) +SeqEntry::SeqEntry( uint16_t group,uint16_t elem ) + : DocEntry(group, elem, "SQ") { Length = 0; ReadLength = 0xffffffff; @@ -51,7 +53,8 @@ SeqEntry::SeqEntry( DictEntry *e ) * @param depth depth level of the current Seq entry */ SeqEntry::SeqEntry( DocEntry *e, int depth ) - : DocEntry( e->GetDictEntry() ) + //: DocEntry( e->GetDictEntry() ) + : DocEntry( e->GetGroup(), e->GetElement(), e->GetVR() ) { Length = 0; ReadLength = 0xffffffff; diff --git a/src/gdcmSeqEntry.h b/src/gdcmSeqEntry.h index 3e9c8c83..a54e3b34 100644 --- a/src/gdcmSeqEntry.h +++ b/src/gdcmSeqEntry.h @@ -3,8 +3,8 @@ Program: gdcm Module: $RCSfile: gdcmSeqEntry.h,v $ Language: C++ - Date: $Date: 2006/02/16 20:06:15 $ - Version: $Revision: 1.40 $ + Date: $Date: 2006/04/11 16:03:26 $ + Version: $Revision: 1.41 $ Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de l'Image). All rights reserved. See Doc/License.txt or @@ -43,10 +43,13 @@ class GDCM_EXPORT SeqEntry : public DocEntry public: /// \brief Contructs a SeqEntry with a RefCounter from DictEntry - static SeqEntry *New(DictEntry *e) {return new SeqEntry(e);} + //static SeqEntry *New(DictEntry *e) {return new SeqEntry(e);} /// \brief Contructs a SeqEntry with a RefCounter from DocEntry static SeqEntry *New(DocEntry *d, int depth) {return new SeqEntry(d,depth);} - +/// \brief Contructs a SeqEntry with a RefCounter from elementary values + static SeqEntry *New(uint16_t group,uint16_t elem, VRKey const &vr = GDCM_VRUNKNOWN) + {return new SeqEntry(group,elem);} + void Print(std::ostream &os = std::cout, std::string const &indent = "" ); void WriteContent(std::ofstream *fp, FileType filetype); uint32_t ComputeFullLength(); @@ -76,8 +79,9 @@ public: protected: private: - SeqEntry( DictEntry *e); + //SeqEntry( DictEntry *e); SeqEntry( DocEntry *d, int depth ); + SeqEntry( uint16_t group, uint16_t elem ); ~SeqEntry(); // Variables diff --git a/src/gdcmSerieHelper.cxx b/src/gdcmSerieHelper.cxx index 9cd3df5f..f52fefd9 100644 --- a/src/gdcmSerieHelper.cxx +++ b/src/gdcmSerieHelper.cxx @@ -3,8 +3,8 @@ Program: gdcm Module: $RCSfile: gdcmSerieHelper.cxx,v $ Language: C++ - Date: $Date: 2006/03/30 17:19:24 $ - Version: $Revision: 1.50 $ + Date: $Date: 2006/04/11 16:03:26 $ + Version: $Revision: 1.51 $ Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de l'Image). All rights reserved. See Doc/License.txt or @@ -19,7 +19,7 @@ #include "gdcmSerieHelper.h" #include "gdcmDirList.h" #include "gdcmFile.h" -#include "gdcmDictEntry.h" // for TranslateToKey +//#include "gdcmDictEntry.h" // for TranslateToKey : no more ! #include "gdcmDebug.h" #include "gdcmUtil.h" diff --git a/src/gdcmTagKey.h b/src/gdcmTagKey.h index 2d32f443..d569db44 100644 --- a/src/gdcmTagKey.h +++ b/src/gdcmTagKey.h @@ -3,8 +3,8 @@ Program: gdcm Module: $RCSfile: gdcmTagKey.h,v $ Language: C++ - Date: $Date: 2005/11/08 09:35:44 $ - Version: $Revision: 1.10 $ + Date: $Date: 2006/04/11 16:03:26 $ + Version: $Revision: 1.11 $ Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de l'Image). All rights reserved. See Doc/License.txt or @@ -32,7 +32,7 @@ namespace gdcm class TagKey { public : - TagKey(uint16_t gr, uint16_t elt) { tag[0] = gr;tag[1] = elt;} + TagKey(uint16_t group, uint16_t elem) { tag[0] = group;tag[1] = elem;} TagKey() { tag[0] = tag[1] = 0x0000;} friend std::ostream& operator<<(std::ostream& _os, const TagKey &_val); @@ -43,13 +43,18 @@ public : sprintf(res,"%04x|%04x",tag[0],tag[1]); return std::string(res); } - + ///\brief sets the Group Number for the TagKey void SetGroup(uint16_t group) { tag[0] = group; } uint16_t GetGroup() const { return tag[0]; } - void SetElement(uint16_t elem) { tag[1] = elem; } + ///\brief sets the Element Number for the TagKey + void SetElement(uint16_t elem) { tag[1] = elem; } uint16_t GetElement() const { return tag[1]; } + ///\brief sets the Group Number and Element Number for the TagKey + void SetGroupElem(uint16_t group, uint16_t elem) + { tag[0] = group;tag[1] = elem; } + TagKey &operator=(const TagKey &_val) { tag[0] = _val.tag[0];