GDCM:获取标签值

GDCM: getting tag value

我正在尝试读取和写入 dicom 文件的属性值。 界面应该是这样的:

// 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);

FAQ of GDCM 提供了一些关于如何获取属性值的很好的示例,但这些示例并不像我想的那样工作。

以下是我对这些示例的问题。

  1. 如何将属性值转换为其类型?

    if( header.FindDataElement( Tag(0x2, 0x13 ) )
         DataElement &de = header.GetDataElement( Tag(0x2, 0x13) );
    
  2. 属性值是数组怎么办?

     sf=gdcm.StringFilter()
     sf.SetFile(r.GetFile())
     print sf.ToStringPair(gdcm.Tag(0x0028,0x0010))
    
  3. 其实我很喜欢下面的解决方案。但这是否意味着我必须为每个属性编写一个接口?

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

如有任何建议,我们将不胜感激。

您已在 GDCM 邮件列表中发布了准确的 copy/paste 消息:

我已经在这里回答了你的问题:

为方便起见,这里又是:

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<>.