c++gdcm

How to access "group, element" string from a gdcm::Tag


I wish to extract all the top level tags from a DICOM image file and output them to a file using C++. I want to output the tag string, e.g. "0020,000D", value of the tag and description. I can get the second two using the following code but how to I get the tag string? I can't seem to find any obvious function.

for (gdcm::DataSet::ConstIterator it = ds.Begin(); it!=ds.End(); ++it) {
    const gdcm::DataElement& elem = *it;
    if (elem.GetVR() != gdcm::VR::SQ) {
        const gdcm::Tag& tag = elem.GetTag();
        auto pair = sf.ToStringPair(tag); // Gives description and value.
                                          // How to get "####,####"?
    }
}

Thanks for any help. Paul


Solution

  • You can either use the default friend:

    std::ostream &  operator<< (std::ostream &_os, const Tag &_val)
    

    For example:

    std::cout << tag << std::endl;
    

    Or using the deprecated API:

    [std::string    PrintAsPipeSeparatedString () const][1]