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.
how can I convert the attribute value to its type?
if( header.FindDataElement( Tag(0x2, 0x13 ) ) DataElement &de = header.GetDataElement( Tag(0x2, 0x13) );
What if the attribute value is an array?
sf=gdcm.StringFilter() sf.SetFile(r.GetFile()) print sf.ToStringPair(gdcm.Tag(0x0028,0x0010))
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.