X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=blobdiff_plain;ds=sidebyside;f=src%2FgdcmDataEntry.cxx;h=78f186c59b3f9f45ac7c13143ba78e09a5917367;hb=76ac46b16fd92d0fb444f786d4946424d9029315;hp=3504fee1ee98e9a52cf5eb43a5bab9f25151cc43;hpb=8e7d7cb974953d9bc78b905451de7ca72887dc58;p=gdcm.git diff --git a/src/gdcmDataEntry.cxx b/src/gdcmDataEntry.cxx index 3504fee1..78f186c5 100644 --- a/src/gdcmDataEntry.cxx +++ b/src/gdcmDataEntry.cxx @@ -3,8 +3,8 @@ Program: gdcm Module: $RCSfile: gdcmDataEntry.cxx,v $ Language: C++ - Date: $Date: 2007/08/29 15:30:48 $ - Version: $Revision: 1.47 $ + Date: $Date: 2011/03/29 07:36:00 $ + Version: $Revision: 1.57 $ Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de l'Image). All rights reserved. See Doc/License.txt or @@ -30,6 +30,11 @@ #include // for atof #include // for isdigit #endif +#include // memcpy +#include // atof + +// Could be defined like MAX_SIZE_LOAD_ELEMENT_VALUE +#define GDCM_MAX_LENGTH_TO_CONVERT_TO_HEXA 8 namespace GDCM_NAME_SPACE { @@ -52,9 +57,10 @@ DataEntry::DataEntry(uint16_t group,uint16_t elem, State = STATE_LOADED; Flag = FLAG_NONE; - StrArea = 0; - BinArea = 0; - SelfArea = true; + StrArea = 0; + StrHexaArea = 0; + BinArea = 0; + SelfArea = true; } /** @@ -67,7 +73,7 @@ DataEntry::DataEntry(DocEntry *e) { Flag = FLAG_NONE; BinArea = 0; - + SelfArea = true; Copy(e); @@ -79,12 +85,8 @@ DataEntry::DataEntry(DocEntry *e) DataEntry::~DataEntry () { DeleteBinArea(); - } -//----------------------------------------------------------------------------- -// Print - //----------------------------------------------------------------------------- // Public /** @@ -127,6 +129,99 @@ void DataEntry::CopyBinArea( uint8_t *area, uint32_t length ) } } +/** + * \brief Checks wether the current DataEntry contains number(s) + */ + +bool DataEntry::IsNumerical() +{ + const VRKey &vr = GetVR(); + + return + vr == "DS" || + vr == "FL" || + vr == "FD" || + vr == "IS" || + vr == "SH" || + vr == "SL" || + vr == "SS" || + vr == "UI" || + vr == "UL" || + vr == "US" ; +} + +/** + * \brief Gets a std::vector of 'double' holding the value(s) of any 'numerical' DataEntry + * @param valueVector std::vector double of value(s) + * \return false if VR not "a 'numerical" one + */ + bool DataEntry::GetNumerical(std::vector &valueVector) + { + valueVector.clear(); + + if (!IsNumerical()) // never trust a user ! + return false; + + const VRKey &vr = GetVR(); + int loop; + if (vr == "IS" || vr == "DS") + { + /// \todo rewrite the whole method, in order *not to use* std::string ! + std::vector tokens; + + Util::Tokenize ( GetString().c_str(), tokens, "\\" ); + + int nbValues= tokens.size(); + if (nbValues == 0) + return false; + + if (vr == "DS") + for (loop=0; loopappend((const char *)BinArea,GetLength()); // to avoid gdcm to propagate oddities in lengthes if ( GetLength()%2) - StrArea->append(" ",1); } + StrArea->append(" ",1); + } return *StrArea; } +/** + * \brief returns an hexadecimal representation of the DataEntry value + */ +std::string const &DataEntry::GetHexaRepresentation() const +{ + static std::ostringstream s2; + const VRKey &vr = GetVR(); + + s2.str(""); + if (!StrHexaArea) + StrHexaArea = new std::string(); + else + *StrHexaArea=""; + if( !BinArea ) + return *StrHexaArea; + // When short integer(s) are stored, convert the following (n * 2) characters + // as a displayable string, the values being separated by a back-slash + + s2 << std::hex; + + if( vr == "US" ) + { + uint16_t *data=(uint16_t *)BinArea; + for (unsigned int i=0; i < GetValueCount(); i++) + { + s2 << std::setw( 2 ) << std::setfill( '0' ); + if( i!=0 ) + s2 << '\\'; + s2 << data[i]; + } + *StrHexaArea=s2.str(); + } + else if (vr == "SS" ) + { + int16_t *data=(int16_t *)BinArea; + for (unsigned int i=0; i < GetValueCount(); i++) + { + s2 << std::setw( 4 ) << std::setfill( '0' ); + if( i!=0 ) + s2 << '\\'; + s2 << data[i]; + } + *StrHexaArea=s2.str(); + } // See above comment on multiple short integers (mutatis mutandis). + else if( vr == "UL" ) + { + uint32_t *data=(uint32_t *)BinArea; + for (unsigned int i=0; i < GetValueCount(); i++) + { + s2 << std::setw( 4 ) << std::setfill( '0' ); + if( i!=0 ) + s2 << '\\'; + s2 << data[i]; + } + *StrHexaArea=s2.str(); + } + else if( vr == "SL" ) + { + int32_t *data=(int32_t *)BinArea; + for (unsigned int i=0; i < GetValueCount(); i++) + { + s2 << std::setw( 4 ) << std::setfill( '0' ); + if( i!=0 ) + s2 << '\\'; + s2 << data[i]; + } + *StrHexaArea=s2.str(); + } + else if( vr == "FL" ) + { + unsigned char *toto=(unsigned char *)BinArea; + for (unsigned int i=0; i < GetValueCount(); i++) + { + s2.str(""); + if( i!=0 ) + s2 << '\\'; + unsigned int a4; + for(int iif=0; iif<4; iif++) + { + a4=toto[iif]; + s2 << a4; + } + } + *StrHexaArea=s2.str(); + } + else if( vr == "FD" ) + { + //double *data=(double *)BinArea; + unsigned char *toto=(unsigned char *)BinArea; + for (unsigned int i=0; i < GetValueCount(); i++) + { + s2.str(""); + if( i!=0 ) + s2 << '\\'; + //s2 << data[i]; + + unsigned int a4; + for(int iid=0; iid<8; iid++) + { + a4=toto[iid]; + s2 << a4; + } + + } + *StrHexaArea=s2.str(); + } + else + { + unsigned int l = (Length > GDCM_MAX_LENGTH_TO_CONVERT_TO_HEXA) ? GDCM_MAX_LENGTH_TO_CONVERT_TO_HEXA : Length; + uint8_t *data=(uint8_t *)BinArea; + for (unsigned int i=0; i < l; i++) + { + if( i!=0 ) + s2 << '\\'; + s2 << std::setw( 2 ) << (int)(data[i]); + } + if (Length > 16) + s2 << "\\..."; + *StrHexaArea=s2.str(); + } + return *StrHexaArea; +} /** * \brief Copies all the attributes from an other DocEntry @@ -654,6 +875,7 @@ uint32_t DataEntry::ComputeFullLength() //----------------------------------------------------------------------------- // Protected + /// \brief Creates a DataEntry owned BinArea /// (remove previous one if any and relevant StrArea if any) void DataEntry::NewBinArea( ) @@ -677,6 +899,11 @@ void DataEntry::DeleteBinArea(void) delete StrArea; StrArea = 0; } + if (StrHexaArea) + { + delete StrHexaArea; + StrHexaArea = 0; + } } //----------------------------------------------------------------------------- @@ -691,7 +918,9 @@ void DataEntry::DeleteBinArea(void) */ void DataEntry::Print(std::ostream &os, std::string const & ) { - os << "D "; + //os << "D "; + + // First, Print the common part (vr [length offset] name). DocEntry::Print(os); uint16_t g = GetGroup(); @@ -710,7 +939,7 @@ void DataEntry::Print(std::ostream &os, std::string const & ) if( vr == "US" || vr == "SS" || vr == "UL" || vr == "SL" || vr == "FL" || vr == "FD") - s << " [" << GetString() << "]"; + s << " [" << GetString() << "] =0x(" << GetHexaRepresentation() << ")"; else { if(Global::GetVR()->IsVROfStringRepresentable(vr)) @@ -749,7 +978,7 @@ void DataEntry::Print(std::ostream &os, std::string const & ) else { s << " [" << GDCM_BINLOADED << ";" - << "length = " << GetLength() << "]"; + << "length = " << GetLength() << "] =0x(" << GetHexaRepresentation() << ")"; } } }