X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=blobdiff_plain;ds=inline;f=src%2FgdcmDocument.cxx;h=6080c6efacdc4a04216473e9e0050088582034de;hb=00b6e0ddcbdbd41252e03732783f65efe5f52526;hp=bf4d3d49f0025c3bda9496ec3f857e13a7a1407b;hpb=7ff15fb586545665e6dcdbf2ee03aa5f89fdd790;p=gdcm.git diff --git a/src/gdcmDocument.cxx b/src/gdcmDocument.cxx index bf4d3d49..6080c6ef 100644 --- a/src/gdcmDocument.cxx +++ b/src/gdcmDocument.cxx @@ -3,8 +3,8 @@ Program: gdcm Module: $RCSfile: gdcmDocument.cxx,v $ Language: C++ - Date: $Date: 2004/06/23 16:34:36 $ - Version: $Revision: 1.31 $ + Date: $Date: 2004/06/25 19:37:05 $ + 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 @@ -74,9 +74,9 @@ const unsigned int gdcmDocument::HEADER_LENGTH_TO_READ = 256; // Refer to gdcmDocument::SetMaxSizeLoadEntry() -const unsigned int gdcmDocument::MAX_SIZE_LOAD_ELEMENT_VALUE = 4096; +const unsigned int gdcmDocument::MAX_SIZE_LOAD_ELEMENT_VALUE = 0x7fffffff;// 4096; -const unsigned int gdcmDocument::MAX_SIZE_PRINT_ELEMENT_VALUE = 64; +const unsigned int gdcmDocument::MAX_SIZE_PRINT_ELEMENT_VALUE = 0x7fffffff;//64; //----------------------------------------------------------------------------- // Constructor / Destructor @@ -126,8 +126,8 @@ gdcmDocument::gdcmDocument(std::string const & inFilename, long l=ParseDES( this, beg, lgt, false); // le Load sera fait a la volee (void)l; //is l used anywhere ? - - rewind(fp); + + rewind(fp); // Load 'non string' values @@ -144,7 +144,7 @@ gdcmDocument::gdcmDocument(std::string const & inFilename, } //FIXME later : how to use it? LoadEntryVoidArea(0x0028,0x3006); //LUT Data (CTX dependent) - + CloseFile(); // -------------------------------------------------------------- @@ -516,8 +516,8 @@ bool gdcmDocument::CloseFile(void) { * (ACR-NEMA, ExplicitVR, ImplicitVR) * \return Always true. */ -bool gdcmDocument::WriteF(FileType filetype) { -/// \todo +void gdcmDocument::Write(FILE* fp,FileType filetype) { +/// /// ============== /// The stuff is rewritten using the SeQuence based /// tree-like stucture (cf : Print ) @@ -530,8 +530,8 @@ bool gdcmDocument::WriteF(FileType filetype) { /// WARNING : Si on veut ecrire du DICOM V3 a partir d'un DcmHeader ACR-NEMA /// no way (check : FileType est un champ de gdcmDocument ...) /// a moins de se livrer a un tres complique ajout des champs manquants. - /// faire un CheckAndCorrectHeader (?) - + /// faire un CheckAndCorrectHeader (?) + if (filetype == gdcmImplicitVR) { std::string implicitVRTransfertSyntax = UI1_2_840_10008_1_2; @@ -571,11 +571,10 @@ bool gdcmDocument::WriteF(FileType filetype) { * if ( filetype == ACR) * UpdateGroupLength(true,ACR); */ - - gdcmElementSet::Write(fp,filetype); + + gdcmElementSet::Write(fp,filetype); - /// WriteEntries(fp,type); // old stuff - return true; + // return true; } /** @@ -657,7 +656,7 @@ gdcmBinEntry * gdcmDocument::ReplaceOrCreateByNumber( guint16 Elem) { gdcmDocEntry* a; - gdcmBinEntry* b; + gdcmBinEntry* b = 0; a = GetDocEntryByNumber( Group, Elem); if (a == NULL) { a =NewBinEntryByNumber(Group, Elem); @@ -968,7 +967,31 @@ void *gdcmDocument::LoadEntryVoidArea(guint16 Group, guint16 Elem) delete[] a; return NULL; } - + return a; +} +/** + * \brief Loads (from disk) the element content + * when a string is not suitable + * @param Element Entry whose voidArea is going to be loaded + */ +void *gdcmDocument::LoadEntryVoidArea(gdcmBinEntry *Element) +{ + size_t o =(size_t)Element->GetOffset(); + fseek(fp, o, SEEK_SET); + size_t l = Element->GetLength(); + char* a = new char[l]; + if(!a) { + dbg.Verbose(0, "gdcmDocument::LoadEntryVoidArea cannot allocate a"); + return NULL; + } + Element->SetVoidArea((void *)a); + /// \todo check the result + size_t l2 = fread(a, 1, l ,fp); + if(l != l2) + { + delete[] a; + return NULL; + } return a; } @@ -1066,7 +1089,7 @@ void gdcmDocument::UpdateShaEntries(void) { */ gdcmDocEntry* gdcmDocument::GetDocEntryByNumber(guint16 group, guint16 element) { - TagKey key = gdcmDictEntry::TranslateToKey(group, element); + TagKey key = gdcmDictEntry::TranslateToKey(group, element); if ( ! tagHT.count(key)) return NULL; return tagHT.find(key)->second; @@ -1175,7 +1198,7 @@ long gdcmDocument::ParseDES(gdcmDocEntrySet *set, long offset, long l_max, bool gdcmBinEntry *bn; gdcmSeqEntry *sq; VRKey vr; - unsigned long l; + unsigned long l = 0; int depth; depth = set->GetDepthLevel(); @@ -1226,7 +1249,7 @@ long gdcmDocument::ParseDES(gdcmDocEntrySet *set, long offset, long l_max, bool if (NewDocEntry->GetGroup() == 0x7fe0 && NewDocEntry->GetElement() == 0x0010 ) { - if (NewDocEntry->GetLength()==0xffffffff) + if (NewDocEntry->GetReadLength()==0xffffffff) { // Broken US.3405.1.dcm Parse7FE0(); // to skip the pixels @@ -1364,11 +1387,11 @@ void gdcmDocument::LoadDocEntry(gdcmDocEntry *Entry) // The elements whose length is bigger than the specified upper bound // are not loaded. Instead we leave a short notice of the offset of // the element content and it's length. - + + std::ostringstream s; if (length > MaxSizeLoadEntry) { if (gdcmBinEntry* BinEntryPtr = dynamic_cast< gdcmBinEntry* >(Entry) ) - { - std::ostringstream s; + { s << "gdcm::NotLoaded (BinEntry)"; s << " Address:" << (long)Entry->GetOffset(); s << " Length:" << Entry->GetLength(); @@ -1377,17 +1400,16 @@ void gdcmDocument::LoadDocEntry(gdcmDocEntry *Entry) } // to be sure we are at the end of the value ... fseek(fp,(long)Entry->GetOffset()+(long)Entry->GetLength(),SEEK_SET); - return; - // Be carefull : a BinEntry IS_A ValEntry ... + return; + // Be carefull : a BinEntry IS_A ValEntry ... if (gdcmValEntry* ValEntryPtr = dynamic_cast< gdcmValEntry* >(Entry) ) { - std::ostringstream s; s << "gdcm::NotLoaded. (ValEntry)"; s << " Address:" << (long)Entry->GetOffset(); s << " Length:" << Entry->GetLength(); s << " x(" << std::hex << Entry->GetLength() << ")"; ValEntryPtr->SetValue(s.str()); - } + } // to be sure we are at the end of the value ... fseek(fp,(long)Entry->GetOffset()+(long)Entry->GetLength(),SEEK_SET); return; @@ -1395,9 +1417,12 @@ void gdcmDocument::LoadDocEntry(gdcmDocEntry *Entry) // When we find a BinEntry not very much can be done : if (gdcmBinEntry* BinEntryPtr = dynamic_cast< gdcmBinEntry* >(Entry) ) { - LoadEntryVoidArea (BinEntryPtr->GetGroup(),BinEntryPtr->GetElement()); - return; - } + + LoadEntryVoidArea(BinEntryPtr); + s << "gdcm::Loaded (BinEntry)"; + BinEntryPtr->SetValue(s.str()); + return; + } // Any compacter code suggested (?) @@ -1448,7 +1473,7 @@ void gdcmDocument::LoadDocEntry(gdcmDocEntry *Entry) // We need an additional byte for storing \0 that is not on disk std::string NewValue(length,0); item_read = fread(&(NewValue[0]), (size_t)length, (size_t)1, fp); - if (gdcmValEntry* ValEntry = dynamic_cast< gdcmValEntry* >(Entry) ) { + if (gdcmValEntry* ValEntry = dynamic_cast< gdcmValEntry* >(Entry) ) { if ( item_read != 1 ) { dbg.Verbose(1, "gdcmDocument::LoadElementValue","unread element value"); ValEntry->SetValue("gdcm::UnRead"); @@ -1460,9 +1485,9 @@ void gdcmDocument::LoadDocEntry(gdcmDocEntry *Entry) else ValEntry->SetValue(NewValue); } else { - // fusible - std::cout << "Should have a ValEntry, here !" << std::endl; - } + // fusible + std::cout << "Should have a ValEntry, here !" << std::endl; + } }