Last active
March 22, 2021 08:59
-
-
Save JulesGorny/1cf5786ba23d65bfd7e6 to your computer and use it in GitHub Desktop.
How to open a DICOMDIR file and retrieve the DICOM files.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Open the DICOMDIR File | |
QString DICOMDIR_folder = "C:/Folder1/Folder2"; | |
const char *fileName = "C:/Folder1/Folder2/DICOMDIR"; | |
DcmDicomDir dicomdir(fileName); | |
//Retrieve root node | |
DcmDirectoryRecord *root = &dicomdir.getRootRecord(); | |
//Prepare child elements | |
DcmDirectoryRecord *rootTest = new DcmDirectoryRecord(*root); | |
DcmDirectoryRecord *PatientRecord = NULL; | |
DcmDirectoryRecord *StudyRecord = NULL; | |
DcmDirectoryRecord *SeriesRecord = NULL; | |
DcmDirectoryRecord *image = NULL; | |
if(rootTest == NULL || rootTest->nextSub(PatientRecord) == NULL) | |
std::cout << "It looks like the selected file does not have the expected format." << std::endl; | |
else | |
{ | |
while ((PatientRecord = root->nextSub(PatientRecord)) != NULL) | |
{ | |
while ((StudyRecord = PatientRecord->nextSub(StudyRecord)) != NULL) | |
{ | |
while ((SeriesRecord = StudyRecord->nextSub(SeriesRecord)) != NULL) | |
{ | |
while ((image = SeriesRecord->nextSub(image)) != NULL) | |
{ | |
const char *sName; | |
//Retrieve the file name | |
image->findAndGetString(DCM_ReferencedFileID, sName); | |
//If a file is selected | |
if(sName != "") | |
{ | |
//sName is the path for the file from the DICOMDIR file | |
//You need to create the absolute path to use the DICOM file | |
//Here you can do different tests (does the file exists ? for example) | |
//Treat the dicom file | |
} | |
} | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment