FAQ #30: How do I create and access a DICOMDIR file?

Frequently Asked Questions regarding DCMTK

Moderator: FAQ Team

Post Reply
Jörg Riesmeier
Posts: 2217
Joined: Fri, 2004-10-29, 21:38
Location: Oldenburg, Germany

FAQ #30: How do I create and access a DICOMDIR file?

#1 Post by Jörg Riesmeier » Thu, 2004-11-11, 12:14

:?: 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:

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;
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.

Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest