将dicom标记转换为c++中gdcm中的字符串名称

Convert a dicom tag to its string name in gdcm in C++

本文关键字:gdcm 字符串 c++ dicom 转换      更新时间:2023-10-16

给定一个gdcm标签,例如gdcm::Tag(0x0010,0x0010),如何将其转换为相应的标签名称字符串,在这种情况下,c++中的"PatientsName" ?

这是我在一个基于Qt的应用程序中使用GDCM所做的:

QString duDicomDictionary::getTagName( const gdcm::Tag & tag )
{
    QString retVal;
    const gdcm::Global& g = gdcm::Global::GetInstance();
    const gdcm::Dicts &dicts = g.GetDicts();
    const gdcm::Dict &pubdict = dicts.GetPublicDict();
    gdcm::DictEntry ent = pubdict.GetDictEntry(tag);
    if (ent.GetVR() != gdcm::VR::INVALID ) {
        retVal = QString::fromStdString(ent.GetName());
    }
    return retVal;
}

此代码仅适用于公共组。

要获得我使用的私有组(在我填充私有字典之后):

QString duDicomDictionary::getTagName( const gdcm::PrivateTag & tag )
{
    QString retVal;
    const gdcm::Global& g = gdcm::Global::GetInstance();
    const gdcm::Dicts &dicts = g.GetDicts();
    const gdcm::PrivateDict &privdict = dicts.GetPrivateDict();
    gdcm::DictEntry ent = privdict.GetDictEntry(tag);
    if (ent.GetVR() != gdcm::VR::INVALID ) {
        retVal = QString::fromStdString(ent.GetName());
    }
    else
    {
        ent = g_privateDict.GetDictEntry(tag);
        if (ent.GetVR() != gdcm::VR::INVALID ) {
            retVal = QString::fromStdString(ent.GetName());
        }
    }
    return retVal;
}