c++gdcm

GDCM: getting tag value


I am trying to read and write the attribute values of a dicom file. The interfaces shall be something like this:

// only need to support std::string, int, float, float*, etc.
template<class T>
T getTagValue(const DataSet& ds, const Tag& tag);

template<class T>
void setTagValue(DataSet& ds, const Tag& tag, const T& value);

The FAQ of GDCM gives some great examples of how to get an attribute value, but these examples don't work like what I thought.

Here are my questions about these examples.

  1. how can I convert the attribute value to its type?

    if( header.FindDataElement( Tag(0x2, 0x13 ) )
         DataElement &de = header.GetDataElement( Tag(0x2, 0x13) );
    
  2. What if the attribute value is an array?

     sf=gdcm.StringFilter()
     sf.SetFile(r.GetFile())
     print sf.ToStringPair(gdcm.Tag(0x0028,0x0010))
    
  3. Actually, I really like the following solution. But does this means that I have to write an interface for EVERY attribute?

     const DataSet &ds = file.GetDataSet();
     Attribute<0x0020,0x0032> at;
     at.Set( ds );
     if( at.GetValue() == 0.0 ) exit(1);
    

Any suggestions will be grateful.


Solution

  • You've posted an exact copy/paste message on the GDCM mailing list:

    And I've answered your question here:

    For convenience here it is again:

    gdcm::Attribute is really only meant for people dealing with specific attribute. If you do not now the Tag ahead of time and only the underlying type of the Data Element, then have a look at gdcm::Element<>.