I would like to create and access a DICOMDIR file. What would be the preferred way?
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:
OFCondition status = dicomdir.createNewDicomDir();
while ( /* there are files */ )
dicomdir.addDicomFile( /* current filename */ );
status = dicomdir.writeDicomDir();
cerr << "Error: cannot write DICOMDIR (" << status.text() << ")" << endl;
cerr << "Error: cannot create DICOMDIR (" << status.text() << ")" << endl;
A more comprehensive example is provided as part of the command line tool "dcmgpdir".
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()
Since the class DicomDirInterface also relies on these classes and methods you should check its implementation for a working example.