For the creation of a DICOMDIR an easy to use wrapper class has been introduced with DCMTK 3.5.3. The following example from the toolkit's documentation shows how to use the class DicomDirInterface:
Code: Select all
DicomDirInterface dicomdir;
OFCondition status = dicomdir.createNewDicomDir();
if (status.good())
{
while ( /* there are files */ )
dicomdir.addDicomFile( /* current filename */ );
status = dicomdir.writeDicomDir();
if (status.bad())
cerr << "Error: cannot write DICOMDIR (" << status.text() << ")" << endl;
} else
cerr << "Error: cannot create DICOMDIR (" << status.text() << ")" << endl;
In order to access particular records of a DICOMDIR one needs to use a different approach:
DICOMDIR files can be read through class DcmDicomDir. This class has a constructor to which the path and filename ("DICOMDIR") can be passed. The individual records are accessed through class DcmDirectoryRecord. These two classes maintain a "logical" view of the DICOMDIR contents, i.e. you can browse through the logical tree structure and don't need to resolve the byte offsets that create the logical linking on top of the physical sequence structure within the DICOMDIR file.
So basically, follow these steps:
- create an instance of class DcmDicomDir
- get the root of the DICOMDIR tree using DcmDicomDir::getRootRecord()
- navigate through the tree using DcmDirectoryRecord::nextSub()
- the type of each record can be determined using DcmDirectoryRecord::getRecordType()