X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=blobdiff_plain;f=src%2FgdcmDocument.cxx;h=b7c00a192b03676da7c9d1fb56432def85ca1e2b;hb=43d88e7ca1386013ee755c4eee3dc0519d335ec3;hp=16adce6fa9f73eb7c9a63c7058b7094c6276c464;hpb=8a806c5653d7832005f2c6f658cf8b5fa612f656;p=gdcm.git diff --git a/src/gdcmDocument.cxx b/src/gdcmDocument.cxx index 16adce6f..b7c00a19 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/09/17 13:11:16 $ - Version: $Revision: 1.81 $ + Date: $Date: 2004/09/23 10:17:26 $ + 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 @@ -116,7 +116,7 @@ gdcmDocument::gdcmDocument( std::string const & filename ) std::string PhotometricInterpretation = GetEntryByNumber(0x0028,0x0004); if( PhotometricInterpretation == "PALETTE COLOR " ) { - LoadEntryVoidArea(0x0028,0x1200); // gray LUT + LoadEntryBinArea(0x0028,0x1200); // gray LUT /// FIXME FIXME FIXME /// The tags refered by the three following lines used to be CORRECTLY /// defined as having an US Value Representation in the public @@ -132,19 +132,19 @@ gdcmDocument::gdcmDocument( std::string const & filename ) /// also used as gdcmBinEntry, which requires the proper conversion, /// - OW, and hence loaded as gdcmBinEntry, but afterwards also used /// as gdcmValEntry, which requires the proper conversion. - LoadEntryVoidArea(0x0028,0x1201); // R LUT - LoadEntryVoidArea(0x0028,0x1202); // G LUT - LoadEntryVoidArea(0x0028,0x1203); // B LUT + LoadEntryBinArea(0x0028,0x1201); // R LUT + LoadEntryBinArea(0x0028,0x1202); // G LUT + LoadEntryBinArea(0x0028,0x1203); // B LUT // Segmented Red Palette Color LUT Data - LoadEntryVoidArea(0x0028,0x1221); + LoadEntryBinArea(0x0028,0x1221); // Segmented Green Palette Color LUT Data - LoadEntryVoidArea(0x0028,0x1222); + LoadEntryBinArea(0x0028,0x1222); // Segmented Blue Palette Color LUT Data - LoadEntryVoidArea(0x0028,0x1223); + LoadEntryBinArea(0x0028,0x1223); } //FIXME later : how to use it? - LoadEntryVoidArea(0x0028,0x3006); //LUT Data (CTX dependent) + LoadEntryBinArea(0x0028,0x3006); //LUT Data (CTX dependent) CloseFile(); @@ -538,13 +538,10 @@ bool gdcmDocument::CloseFile() void gdcmDocument::Write(FILE* fp,FileType filetype) { /// \todo move the following lines (and a lot of others, to be written) - /// to a future function CheckAndCorrectHeader - - /// 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 (?) - + /// to a future function CheckAndCorrectHeader + /// (necessary if user wants to write a DICOM V3 file + /// starting from an ACR-NEMA (V2) gdcmHeader + if (filetype == gdcmImplicitVR) { std::string implicitVRTransfertSyntax = UI1_2_840_10008_1_2; @@ -587,72 +584,6 @@ void gdcmDocument::Write(FILE* fp,FileType filetype) } -/** - * \brief Modifies the value of a given Header Entry (Dicom Element) - * when it exists. Create 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 - * \return pointer to the modified/created Header Entry (NULL when creation - * failed). - */ - -/* -gdcmValEntry * gdcmDocument::ReplaceOrCreateByNumber( - std::string const & value, - uint16_t group, - uint16_t elem ) -{ - gdcmValEntry* valEntry = 0; - gdcmDocEntry* currentEntry = GetDocEntryByNumber( group, elem); - - if (!currentEntry) - { - // The entry wasn't present and we simply create the required ValEntry: - currentEntry = NewDocEntryByNumber(group, elem); - if (!currentEntry) - { - dbg.Verbose(0, "gdcmDocument::ReplaceOrCreateByNumber: call to" - " NewDocEntryByNumber failed."); - return NULL; - } - valEntry = new gdcmValEntry(currentEntry); - if ( !AddEntry(valEntry)) - { - dbg.Verbose(0, "gdcmDocument::ReplaceOrCreateByNumber: AddEntry" - " failed allthough this is a creation."); - } - } - else - { - valEntry = dynamic_cast< gdcmValEntry* >(currentEntry); - if ( !valEntry ) // Euuuuh? It wasn't a ValEntry - // then we change it to a ValEntry ? - // Shouldn't it be considered as an error ? - { - // We need to promote the gdcmDocEntry to a gdcmValEntry: - valEntry = new gdcmValEntry(currentEntry); - if (!RemoveEntry(currentEntry)) - { - dbg.Verbose(0, "gdcmDocument::ReplaceOrCreateByNumber: removal" - " of previous DocEntry failed."); - return NULL; - } - if ( !AddEntry(valEntry)) - { - dbg.Verbose(0, "gdcmDocument::ReplaceOrCreateByNumber: adding" - " promoted ValEntry failed."); - return NULL; - } - } - } - - SetEntryByNumber(value, group, elem); - - return valEntry; -} -*/ - /** * \brief Modifies the value of a given Header Entry (Dicom Element) * when it exists. Create it with the given value when unexistant. @@ -662,13 +593,7 @@ gdcmValEntry * gdcmDocument::ReplaceOrCreateByNumber( * @param VR V(alue) R(epresentation) of the Entry -if private Entry- * \return pointer to the modified/created Header Entry (NULL when creation * failed). - */ - - // TODO : write something clever, using default value for VR - // to avoid code duplication - // (I don't know how to tell NewDocEntryByNumber - // that ReplaceOrCreateByNumber was called with a default value) - + */ gdcmValEntry * gdcmDocument::ReplaceOrCreateByNumber( std::string const & value, uint16_t group, @@ -741,14 +666,14 @@ gdcmValEntry * gdcmDocument::ReplaceOrCreateByNumber( /* * \brief Modifies the value of a given Header Entry (Dicom Element) * when it exists. Create it with the given value when unexistant. - * @param voidArea (binary) value to be set + * @param binArea (binary) value to be set * @param Group Group number of the Entry * @param Elem Element number of the Entry * \return pointer to the modified/created Header Entry (NULL when creation * failed). */ gdcmBinEntry * gdcmDocument::ReplaceOrCreateByNumber( - void *voidArea, + uint8_t* binArea, int lgth, uint16_t group, uint16_t elem, @@ -769,7 +694,7 @@ gdcmBinEntry * gdcmDocument::ReplaceOrCreateByNumber( if (!dictEntry) { - currentEntry = NewDocEntryByNumber(group, elem,VR); + currentEntry = NewDocEntryByNumber(group, elem, VR); } else { @@ -812,7 +737,7 @@ gdcmBinEntry * gdcmDocument::ReplaceOrCreateByNumber( } } - SetEntryByNumber(voidArea, lgth, group, elem); + SetEntryByNumber(binArea, lgth, group, elem); return binEntry; } @@ -923,7 +848,6 @@ std::string gdcmDocument::GetEntryVRByName(TagName const & tagName) return elem->GetVR(); } - /** * \brief Searches within Header Entries (Dicom Elements) parsed with * the public and private dictionaries @@ -1059,12 +983,12 @@ bool gdcmDocument::SetEntryByNumber(std::string const & content, * \brief Accesses an existing gdcmDocEntry (i.e. a Dicom Element) * through it's (group, element) and modifies it's content with * the given value. - * @param content new value (void *) to substitute with + * @param content new value (void * -> uint8_t*) to substitute with * @param lgth new value length * @param group group number of the Dicom Element to modify * @param element element number of the Dicom Element to modify */ -bool gdcmDocument::SetEntryByNumber(void *content, +bool gdcmDocument::SetEntryByNumber(uint8_t*content, int lgth, uint16_t group, uint16_t element) @@ -1084,8 +1008,9 @@ bool gdcmDocument::SetEntryByNumber(void *content, } */ gdcmBinEntry* a = (gdcmBinEntry *)TagHT[key]; - a->SetVoidArea(content); + a->SetBinArea(content); a->SetLength(lgth); + a->SetValue(GDCM_BINLOADED); return true; } @@ -1145,7 +1070,7 @@ size_t gdcmDocument::GetEntryOffsetByNumber(uint16_t group, uint16_t elem) * @param elem element number of the Entry * @return Pointer to the 'non string' area */ -void * gdcmDocument::GetEntryVoidAreaByNumber(uint16_t group, uint16_t elem) +void * gdcmDocument::GetEntryBinAreaByNumber(uint16_t group, uint16_t elem) { gdcmDocEntry* entry = GetDocEntryByNumber(group, elem); if (!entry) @@ -1153,7 +1078,7 @@ void * gdcmDocument::GetEntryVoidAreaByNumber(uint16_t group, uint16_t elem) dbg.Verbose(1, "gdcmDocument::GetDocEntryByNumber: no entry"); return 0; } - return ((gdcmBinEntry *)entry)->GetVoidArea(); + return ((gdcmBinEntry *)entry)->GetBinArea(); } /** @@ -1162,7 +1087,7 @@ void * gdcmDocument::GetEntryVoidAreaByNumber(uint16_t group, uint16_t elem) * @param group group number of the Entry * @param elem element number of the Entry */ -void* gdcmDocument::LoadEntryVoidArea(uint16_t group, uint16_t elem) +void* gdcmDocument::LoadEntryBinArea(uint16_t group, uint16_t elem) { gdcmDocEntry *docElement = GetDocEntryByNumber(group, elem); if ( !docElement ) @@ -1172,10 +1097,10 @@ void* gdcmDocument::LoadEntryVoidArea(uint16_t group, uint16_t elem) size_t o =(size_t)docElement->GetOffset(); fseek(Fp, o, SEEK_SET); size_t l = docElement->GetLength(); - char* a = new char[l]; + uint8_t* a = new uint8_t[l]; if(!a) { - dbg.Verbose(0, "gdcmDocument::LoadEntryVoidArea cannot allocate a"); + dbg.Verbose(0, "gdcmDocument::LoadEntryBinArea cannot allocate a"); return NULL; } size_t l2 = fread(a, 1, l , Fp); @@ -1185,30 +1110,29 @@ void* gdcmDocument::LoadEntryVoidArea(uint16_t group, uint16_t elem) return NULL; } /// \todo Drop any already existing void area! JPR - if( !SetEntryVoidAreaByNumber( a, group, elem ) ); + if( !SetEntryBinAreaByNumber( a, group, elem ) ); { - dbg.Verbose(0, "gdcmDocument::LoadEntryVoidArea setting failed."); + dbg.Verbose(0, "gdcmDocument::LoadEntryBinArea setting failed."); } - 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 + * @param element Entry whose binArea is going to be loaded */ -void *gdcmDocument::LoadEntryVoidArea(gdcmBinEntry *element) +void *gdcmDocument::LoadEntryBinArea(gdcmBinEntry *element) { size_t o =(size_t)element->GetOffset(); fseek(Fp, o, SEEK_SET); size_t l = element->GetLength(); - char* a = new char[l]; + uint8_t* a = new uint8_t[l]; if( !a ) { - dbg.Verbose(0, "gdcmDocument::LoadEntryVoidArea cannot allocate a"); + dbg.Verbose(0, "gdcmDocument::LoadEntryBinArea cannot allocate a"); return NULL; } - element->SetVoidArea((void *)a); + element->SetBinArea((uint8_t*)a); /// \todo check the result size_t l2 = fread(a, 1, l , Fp); if( l != l2 ) @@ -1227,7 +1151,7 @@ void *gdcmDocument::LoadEntryVoidArea(gdcmBinEntry *element) * @param element Element number of the searched Dicom Element * @return */ -bool gdcmDocument::SetEntryVoidAreaByNumber(void * area, +bool gdcmDocument::SetEntryBinAreaByNumber(uint8_t* area, uint16_t group, uint16_t element) { @@ -1238,7 +1162,7 @@ bool gdcmDocument::SetEntryVoidAreaByNumber(void * area, } if ( gdcmBinEntry* binEntry = dynamic_cast(currentEntry) ) { - binEntry->SetVoidArea( area ); + binEntry->SetBinArea( area ); return true; } return true; @@ -1474,6 +1398,7 @@ long gdcmDocument::ParseDES(gdcmDocEntrySet *set, // hierarchy and the Key is simply of the form ( group, elem )... if (gdcmDocument* dummy = dynamic_cast< gdcmDocument* > ( set ) ) { + (void)dummy; newValEntry->SetKey( newValEntry->GetKey() ); } // ...but when "set" is a gdcmSQItem, we are inserting this new @@ -1514,6 +1439,7 @@ long gdcmDocument::ParseDES(gdcmDocEntrySet *set, // form ( group, elem )... if (gdcmDocument* dummy = dynamic_cast< gdcmDocument* > ( set ) ) { + (void)dummy; newBinEntry->SetKey( newBinEntry->GetKey() ); } // but when "this" is a SQItem, we are inserting this new @@ -1578,6 +1504,7 @@ long gdcmDocument::ParseDES(gdcmDocEntrySet *set, // level of one: if (gdcmDocument* dummy = dynamic_cast< gdcmDocument* > ( set ) ) { + (void)dummy; newSeqEntry->SetDepthLevel( 1 ); newSeqEntry->SetKey( newSeqEntry->GetKey() ); } @@ -1743,9 +1670,9 @@ void gdcmDocument::LoadDocEntry(gdcmDocEntry* entry) // When we find a BinEntry not very much can be done : if (gdcmBinEntry* binEntryPtr = dynamic_cast< gdcmBinEntry* >(entry) ) { - s << "gdcm::Loaded (BinEntry)"; + s << GDCM_BINLOADED; binEntryPtr->SetValue(s.str()); - LoadEntryVoidArea(binEntryPtr); // last one, not to erase length ! + LoadEntryBinArea(binEntryPtr); // last one, not to erase length ! return; } @@ -3068,12 +2995,12 @@ void gdcmDocument::BuildFlatHashTableRecurse( TagDocEntryHT& builtHT, * a Dicom header will need to dig in the gdcm internals (which * implies exposing all the internal data structures to the API). * In order to avoid this burden to the user, \ref BuildFlatHashTable - * recursively builds a temporary hash table, which olds all the + * recursively builds a temporary hash table, which holds all the * Dicom entries in a flat structure (a \ref TagDocEntryHT i.e. a * std::map<>). * \warning Of course there is NO integrity constrain between the - * returned \ref TagDocEntryHT and the \ref gdcmElemenSet used - * to build it. Hence if the underlying \ref gdcmElemenSet is + * returned \ref TagDocEntryHT and the \ref gdcmElementSet used + * to build it. Hence if the underlying \ref gdcmElementSet is * altered, then it is the caller responsability to invoke * \ref BuildFlatHashTable again... * @return The flat std::map<> we juste build.