X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=blobdiff_plain;f=src%2FgdcmDocument.cxx;h=a454f9b1d985c11bd883f02068ca020834ff1ea0;hb=ed0cb816b9fbe45a5dfead3f7d95194e0cbbd3a4;hp=73486bc72fbed3adddd83fb5b0690717769e7856;hpb=038a3b7f67769dc20b4c46f3c9dcad7cc63d1161;p=gdcm.git diff --git a/src/gdcmDocument.cxx b/src/gdcmDocument.cxx index 73486bc7..a454f9b1 100644 --- a/src/gdcmDocument.cxx +++ b/src/gdcmDocument.cxx @@ -3,8 +3,8 @@ Program: gdcm Module: $RCSfile: gdcmDocument.cxx,v $ Language: C++ - Date: $Date: 2005/01/18 08:01:41 $ - Version: $Revision: 1.195 $ + Date: $Date: 2005/01/19 10:30:51 $ + Version: $Revision: 1.199 $ Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de l'Image). All rights reserved. See Doc/License.txt or @@ -35,9 +35,11 @@ #include // For nthos: -#if defined(_MSC_VER) || defined(__BORLANDC__) +#if defined(_MSC_VER) || defined(__BORLANDC__) || defined(__MINGW32__) #include -#else +#endif + +#ifdef CMAKE_HAVE_NETINET_IN_H #include #endif @@ -137,7 +139,7 @@ Document::Document( std::string const &filename ) : ElementSet(-1) // we switch lineNumber and columnNumber // std::string RecCode; - RecCode = GetEntry(0x0008, 0x0010); // recognition code + RecCode = GetEntry(0x0008, 0x0010); // recognition code (RET) if (RecCode == "ACRNEMA_LIBIDO_1.1" || RecCode == "CANRME_AILIBOD1_1." ) // for brain-damaged softwares // with "little-endian strings" @@ -257,7 +259,7 @@ bool Document::IsReadable() if( TagHT.empty() ) { - gdcmVerboseMacro( "No tags in internal hash table."); + gdcmVerboseMacro( "No tag in internal hash table."); return false; } @@ -407,7 +409,7 @@ bool Document::CloseFile() Fp = 0; } - return true; //FIXME how do we detect a non-close ifstream ? + return true; //FIXME how do we detect a non-closed ifstream ? } /** @@ -511,8 +513,8 @@ ValEntry *Document::ReplaceOrCreate(std::string const &value, * when it exists. Create it with the given value when unexistant. * A copy of the binArea is made to be kept in the Document. * @param binArea (binary) value to be set - * @param Group Group number of the Entry - * @param Elem Element number of the Entry + * @param group Group number of the Entry + * @param elem Element number of the Entry * @param vr V(alue) R(epresentation) of the Entry -if private Entry- * \return pointer to the modified/created Header Entry (NULL when creation * failed). @@ -618,7 +620,6 @@ SeqEntry *Document::ReplaceOrCreate( uint16_t group, uint16_t elem) } } } - // Create a new seqEntry if necessary if (!seqEntry) { @@ -632,7 +633,6 @@ SeqEntry *Document::ReplaceOrCreate( uint16_t group, uint16_t elem) return NULL; } } - return seqEntry; } @@ -777,7 +777,7 @@ bool Document::SetEntry(uint8_t*content, int lgth, * @param content new value (string) to substitute with * @param entry Entry to be modified */ -bool Document::SetEntry(std::string const &content,ValEntry *entry) +bool Document::SetEntry(std::string const &content, ValEntry *entry) { if(entry) { @@ -837,8 +837,8 @@ void *Document::GetEntryBinArea(uint16_t group, uint16_t elem) } /** - * \brief Loads (from disk) the element content - * when a string is not suitable + * \brief Loads (from disk) the element content + * when a string is not suitable * @param group group number of the Entry * @param elem element number of the Entry */ @@ -857,8 +857,8 @@ void Document::LoadEntryBinArea(uint16_t group, uint16_t elem) } /** - * \brief Loads (from disk) the element content - * when a string is not suitable + * \brief Loads (from disk) the element content + * when a string is not suitable * @param elem Entry whose binArea is going to be loaded */ void Document::LoadEntryBinArea(BinEntry *elem) @@ -877,7 +877,7 @@ void Document::LoadEntryBinArea(BinEntry *elem) uint8_t *a = new uint8_t[l]; if( !a ) { - gdcmVerboseMacro( "Cannot allocate a"); + gdcmVerboseMacro( "Cannot allocate BinEntry content"); return; } @@ -921,11 +921,7 @@ void Document::LoadEntryBinArea(BinEntry *elem) }*/ /** - * \brief retrieves a Dicom Element (the first one) using (group, element) - * \warning (group, element) IS NOT an identifier inside the Dicom Header - * if you think it's NOT UNIQUE, check the count number - * and use iterators to retrieve ALL the Dicoms Elements within - * a given couple (group, element) + * \brief retrieves a Dicom Element using (group, element) * @param group Group number of the searched Dicom Element * @param elem Element number of the searched Dicom Element * @return @@ -989,9 +985,34 @@ BinEntry *Document::GetBinEntry(uint16_t group, uint16_t elem) } /** - * \brief Loads the element while preserving the current - * underlying file position indicator as opposed to - * to LoadDocEntry that modifies it. + * \brief Same as \ref Document::GetDocEntry except it only + * returns a result when the corresponding entry is of type + * SeqEntry. + * @param group Group number of the searched Dicom Element + * @param elem Element number of the searched Dicom Element + * @return When present, the corresponding SeqEntry. + */ +SeqEntry *Document::GetSeqEntry(uint16_t group, uint16_t elem) +{ + DocEntry *currentEntry = GetDocEntry(group, elem); + if ( !currentEntry ) + { + return 0; + } + if ( SeqEntry *entry = dynamic_cast(currentEntry) ) + { + return entry; + } + gdcmVerboseMacro( "Unfound SeqEntry."); + + return 0; +} + + +/** + * \brief Loads the element while preserving the current + * underlying file position indicator as opposed to + * LoadDocEntry that modifies it. * @param entry Header Entry whose value will be loaded. * @return */ @@ -1106,7 +1127,7 @@ void Document::ParseDES(DocEntrySet *set, long offset, { if ( newBinEntry ) { - if ( ! Global::GetVR()->IsVROfBinaryRepresentable(vr) ) + if ( Filetype == ExplicitVR && ! Global::GetVR()->IsVROfBinaryRepresentable(vr) ) { ////// Neither ValEntry NOR BinEntry: should mean UNKOWN VR gdcmVerboseMacro( std::hex << newDocEntry->GetGroup() @@ -1118,9 +1139,8 @@ void Document::ParseDES(DocEntrySet *set, long offset, //////////////////// BinEntry or UNKOWN VR: // When "this" is a Document the Key is simply of the // form ( group, elem )... - if (/*Document *dummy =*/ dynamic_cast< Document* > ( set ) ) + if ( dynamic_cast< Document* > ( set ) ) { - //(void)dummy; newBinEntry->SetKey( newBinEntry->GetKey() ); } // but when "this" is a SQItem, we are inserting this new @@ -1145,9 +1165,8 @@ void Document::ParseDES(DocEntrySet *set, long offset, /////////////////////// ValEntry // When "set" is a Document, then we are at the top of the // hierarchy and the Key is simply of the form ( group, elem )... - if (/*Document *dummy =*/ dynamic_cast< Document* > ( set ) ) + if ( dynamic_cast< Document* > ( set ) ) { - //(void)dummy; newValEntry->SetKey( newValEntry->GetKey() ); } // ...but when "set" is a SQItem, we are inserting this new @@ -1650,6 +1669,9 @@ void Document::FindDocEntryLength( DocEntry *entry ) // on Data elements "Implicit and Explicit VR Data Elements shall // not coexist in a Data Set and Data Sets nested within it".] // Length is on 4 bytes. + + // Well ... group 0002 is always coded in 'Explicit VR Litle Endian' + // even if Transfer Syntax is 'Implicit VR ...' FixDocEntryFoundLength( entry, ReadInt32() ); return; @@ -2291,8 +2313,6 @@ bool Document::CheckSwap() } } - - /** * \brief Change the Byte Swap code. */ @@ -2343,7 +2363,6 @@ void Document::SetMaxSizeLoadEntry(long newSize) */ void Document::SetMaxSizePrintEntry(long newSize) { - //DOH !! This is exactly SetMaxSizeLoadEntry FIXME FIXME if ( newSize < 0 ) { return; @@ -2388,7 +2407,6 @@ void Document::HandleBrokenEndian(uint16_t &group, uint16_t &elem) /** * \brief Accesses the info from 0002,0010 : Transfer Syntax and TS - * else 1. * @return The full Transfer Syntax Name (as opposed to Transfer Syntax UID) */ std::string Document::GetTransferSyntaxName() @@ -2436,6 +2454,13 @@ void Document::HandleOutOfGroup0002(uint16_t &group, uint16_t &elem) return; } + // Group 0002 is always 'Explicit ...' enven when Transfer Syntax says 'Implicit ..." + + if ( Global::GetTS()->GetSpecialTransferSyntax(ts) == TS::ImplicitVRLittleEndian ) + { + Filetype = ImplicitVR; + } + // FIXME Strangely, this works with //'Implicit VR Transfer Syntax (GE Private) if ( Global::GetTS()->GetSpecialTransferSyntax(ts) == TS::ExplicitVRBigEndian ) @@ -2444,7 +2469,7 @@ void Document::HandleOutOfGroup0002(uint16_t &group, uint16_t &elem) << GetTransferSyntaxName() << "]" ); SwitchByteSwapCode(); group = SwapShort(group); - elem = SwapShort(elem); + elem = SwapShort(elem); } } }