我正在使用DCMTK库
开发一个快速的DICOM查看器
,并且我正在遵循this link中提供的示例.
对于任何标签 ID,API
的缓冲区始终返回 null,例如:DCM_PatientName
。
但是 findAndGetOFString() API
工作正常,但仅以 ASCII
返回标记的第一个字符,这是该 API 应该如何工作的吗?
有人可以告诉我为什么以前的 API 缓冲区为空吗?
DicomImage API
也有同样的问题。
Snippet 1:
DcmFileFormat fileformat;
OFCondition status = fileformat.loadFile(test_data_file_path.toStdString().c_str());
if (status.good())
{
OFString patientName;
char* name;
if (fileformat.getDataset()->findAndGetOFString(DCM_PatientName, patientName).good())
{
name = new char[patientName.length()];
strcpy(name, patientName.c_str());
}
else
{
qDebug() << "Error: cannot access Patient's Name!";
}
}
else
{
qDebug() << "Error: cannot read DICOM file (" << status.text() << ")";
}
在上面的代码片段中,name
的 ASCII 值是“50”,实际名称是“PATIENT”。
Snippet 2:
DcmFileFormat file_format;
OFCondition status = file_format.loadFile(test_data_file_path.toStdString().c_str());
std::shared_ptr<DcmDataset> dataset(file_format.getDataset());
qDebug() << "\nInformation extracted from DICOM file: \n";
const char* buffer = nullptr;
DcmTagKey key = DCM_PatientName;
dataset->findAndGetString(key,buffer);
std::string tag_value = buffer;
qDebug() << "Patient name: " << tag_value.c_str();
在上面的代码片段中,缓冲区为空。它不读取名称。
注意:
This is only a sample. I am just playing around the APIs for learning purpose.
最佳答案
以下示例方法从 DcmDataset 对象读取患者姓名:
std::string getPatientName(DcmDataset& dataset)
{
// Get the tag's value in ofstring
OFString ofstring;
OFCondition condition = dataset.findAndGetOFString(DCM_PatientName, ofstring);
if(condition.good())
{
// Tag found. Put it in a std::string and return it
return std::string(ofstring.c_str());
}
// Tag not found
return ""; // or throw if you need the tag
}
关于c++ - DCMTK 中的 findAndGetString() 为标签返回 null,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46036364/