X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=blobdiff_plain;f=src%2FgdcmElValSet.cxx;h=429888d12ed04f9fc32c6d5ccbe4a748f36837ce;hb=fdef18c217469cc507704db6d686ce195e82e4ce;hp=d9e8c39d34f029d759563ce880ad0d72986b3ed2;hpb=f04b9ef9bad66e1847e8139db9cd4126e4340301;p=gdcm.git diff --git a/src/gdcmElValSet.cxx b/src/gdcmElValSet.cxx index d9e8c39d..429888d1 100644 --- a/src/gdcmElValSet.cxx +++ b/src/gdcmElValSet.cxx @@ -3,14 +3,22 @@ #include "gdcmUtil.h" #include "gdcmElValSet.h" #include "gdcmTS.h" -#include +#ifdef GDCM_NO_ANSI_STRING_STREAM +# include +# define ostringstream ostrstream +# else +# include +#endif + gdcmElValSet::~gdcmElValSet() { for (TagElValueHT::iterator tag = tagHt.begin(); tag != tagHt.end(); ++tag) { gdcmElValue* EntryToDelete = tag->second; if ( EntryToDelete ) delete EntryToDelete; + tag->second=NULL; } + tagHt.clear(); // Since Add() adds symetrical in both tagHt and NameHt we can // assume all the pointed gdcmElValues are already cleaned-up when @@ -18,15 +26,6 @@ gdcmElValSet::~gdcmElValSet() { NameHt.clear(); } -TagElValueHT & gdcmElValSet::GetTagHt(void) { - return tagHt; -} - - -ListTag & gdcmElValSet::GetListElem(void) { - return listElem; -} - /** * \ingroup gdcmElValSet * \brief @@ -63,10 +62,11 @@ int gdcmElValSet::CheckIfExistByNumber(guint16 Group, guint16 Elem ) { void gdcmElValSet::Print(std::ostream & os) { size_t o; - short int g, e; + unsigned short int g, e; TSKey v; std::string d2; gdcmTS * ts = gdcmGlobal::GetTS(); + std::ostringstream s; for (TagElValueHT::iterator tag = tagHt.begin(); tag != tagHt.end(); @@ -76,66 +76,66 @@ void gdcmElValSet::Print(std::ostream & os) { v = tag->second->GetValue(); o = tag->second->GetOffset(); d2 = _CreateCleanString(v); // replace non printable characters by '.' - - os << tag->first << ": "; - os << " lgr : " << tag->second->GetLength(); - os << ", Offset : " << o; - os << " x(" << std::hex << o << std::dec << ") "; - os << "\t[" << tag->second->GetVR() << "]"; - os << "\t[" << tag->second->GetName() << "]"; - os << "\t[" << d2 << "]"; - + + s << tag->first << ": "; + s << " lgr : " <second->GetLength(); + s << ",\t Offset : " << o; + s << " x(" << std::hex << o << std::dec << ") "; + s << "\t[" << tag->second->GetVR() << "]"; + s << "\t[" << tag->second->GetName() << "]"; + s << "\t[" << d2 << "]"; + // Display the UID value (instead of displaying the rough code) if (g == 0x0002) { // Some more to be displayed ? if ( (e == 0x0010) || (e == 0x0002) ) - os << " ==>\t[" << ts->GetValue(v) << "]"; + s << " ==>\t[" << ts->GetValue(v) << "]"; } else { if (g == 0x0008) { if ( (e == 0x0016) || (e == 0x1150) ) - os << " ==>\t[" << ts->GetValue(v) << "]"; + s << " ==>\t[" << ts->GetValue(v) << "]"; } } - os << std::endl; + s << std::endl; } + - std::cout << "----------------------------------------------" << std::endl; - - //for (ListTag::iterator i = listElem.begin(); - - char tag[9]; + guint32 lgth; + char greltag[10]; //group element tag - for (std::list::iterator i = listElem.begin(); + for (ListTag::iterator i = listElem.begin(); i != listElem.end(); ++i){ - sprintf(tag,"%04x|%04x",(*i)->GetGroup(),(*i)->GetElement()); g = (*i)->GetGroup(); e = (*i)->GetElement(); v = (*i)->GetValue(); o = (*i)->GetOffset(); + sprintf(greltag,"%04x|%04x",g,e); d2 = _CreateCleanString(v); // replace non printable characters by '.' - //os << std::hex <GetLength(); - os << ", Offset : " << o; - os << " x(" << std::hex << o << std::dec << ") "; - os << "\t[" << (*i)->GetVR() << "]"; - os << "\t[" << (*i)->GetName() << "]"; - os << "\t[" << d2 << "]"; + s << greltag << ": lgth : "; + lgth = (*i)->GetReadLength(); + if ( lgth == 0xffffffff) + s << std::hex << lgth << std::dec ; + else + s << lgth; + s << ",\t Offset : " << o; + s << " x(" << std::hex << o << std::dec << ") "; + s << "\t[" << (*i)->GetVR() << "]"; + s << "\t[" << (*i)->GetName() << "]"; + s << "\t[" << d2 << "]"; // Display the UID value (instead of displaying the rough code) if (g == 0x0002) { // Any more to be displayed ? if ( (e == 0x0010) || (e == 0x0002) ) - os << " ==>\t[" << ts->GetValue(v) << "]"; + s << " ==>\t[" << ts->GetValue(v) << "]"; } else { if (g == 0x0008) { if ( (e == 0x0016) || (e == 0x1150) ) - os << " ==>\t[" << ts->GetValue(v) << "]"; + s << " ==>\t[" << ts->GetValue(v) << "]"; } } - os << std::endl; - + s << std::endl; } - + os<SetLength(lgr); - - - return 1; } @@ -435,9 +432,14 @@ void gdcmElValSet::UpdateGroupLength(bool SkipSequence, FileType type) { /** * \ingroup gdcmElValSet - * \brief - * @param type - * @param _fp + * \brief writes on disc according to the requested format + * \ (ACR-NEMA, DICOM, RAW) the image + * \ warning does NOT add the missing elements in the header : + * \ it's up to the user doing it ! + * \ (function CheckHeaderCoherence to be written) + * @param type type of the File to be written + * (ACR-NEMA, DICOM, RAW) + * @param _fp already open file pointer * @return */ void gdcmElValSet::WriteElements(FileType type, FILE * _fp) { @@ -449,6 +451,10 @@ void gdcmElValSet::WriteElements(FileType type, FILE * _fp) { guint16 val_uint16; std::vector tokens; + + // TODO : use listElem to iterate, not TagHt! + // pb : gdcmElValSet.Add does NOT update listElem + // find a trick in STL to do it, at low cost ! void *ptr; @@ -465,8 +471,6 @@ void gdcmElValSet::WriteElements(FileType type, FILE * _fp) { val = tag2->second->GetValue().c_str(); vr = tag2->second->GetVR(); - // std::cout << "Tag "<< std::hex << gr << " " << el << std::endl; - if ( type == ACR ) { if (gr < 0x0008) continue; // ignore pure DICOM V3 groups if (gr %2) continue; // ignore shadow groups