How to write contour sequence to DICOM file

Questions regarding the DCMRT library, a DCMTK add-on that implements support for the various DICOM Radiation Therapy (RT) IODs

Moderator: Moderator Team

Post Reply
Message
Author
nbeck
Posts: 12
Joined: Fri, 2022-10-28, 12:56

How to write contour sequence to DICOM file

#1 Post by nbeck »

Hello!

I am trying to create a DICOM file containing an RT structure set with a contour sequence, unsuccessfully so far. I found some helpful posts in this forum, so I combined the example code from How to add DRTContourSequence::Item to an DRTROIContourSequence::Item and How to write Dcm file for RT Structure Set and came up with the following:

Code: Select all

DRTStructureSetIOD structureSet;
DRTROIContourSequence& roiContourSequence           = structureSet.getROIContourSequence();
DRTROIContourSequence::Item* roiContourSequenceItem = NULL;

// add new item
roiContourSequence.addItem(roiContourSequenceItem);

if (roiContourSequenceItem != NULL)
{
	DRTContourSequence& contourSequence           = roiContourSequenceItem->getContourSequence();
	DRTContourSequence::Item* contourSequenceItem = NULL;

	// also add a new item to the nested sub-sequence
	contourSequence.addItem(contourSequenceItem);

	if (roiContourSequenceItem != NULL)
	{
		// set contour data (dummy values)
		contourSequenceItem->setContourData("100\\200\\146\\101\\201\\147");
	}
}
DcmFileFormat rtFileformat;
DcmDataset* rtDataset = rtFileformat.getDataset();
structureSet.write(*rtDataset);
// save file
std::string filename{"test_RTStruct.dcm"};
rtFileformat.saveFile(filename.c_str(), EXS_LittleEndianExplicit);
This executes without any errors, but the file that is created doesn't seem to contain the sequence data.

What am I missing here?

J. Riesmeier
DCMTK Developer
Posts: 2546
Joined: Tue, 2011-05-03, 14:38
Location: Oldenburg, Germany
Contact:

Re: How to write contour sequence to DICOM file

#2 Post by J. Riesmeier »

Mandatory data elements are missing. You should have checked the return value of structureSet.write() and also looked at the logger...

Here is an improved version of your sample code:

Code: Select all

DRTStructureSetIOD structureSet;
structureSet.setStudyInstanceUID("1.2.3.4");
structureSet.setSeriesInstanceUID("1.2.3.4.5");
structureSet.setSOPInstanceUID("1.2.3.4.5.6");
structureSet.setModality("RTSTRUCT");
structureSet.setStructureSetLabel("TEST");

// TODO: add further mandatory data elements

DRTROIContourSequence& roiContourSequence           = structureSet.getROIContourSequence();
DRTROIContourSequence::Item* roiContourSequenceItem = NULL;

// add new item
if (roiContourSequence.addItem(roiContourSequenceItem).good())
{
    DRTContourSequence& contourSequence           = roiContourSequenceItem->getContourSequence();
    DRTContourSequence::Item* contourSequenceItem = NULL;

    // add mandatory data elements
    roiContourSequenceItem->setReferencedROINumber("1");

    // also add a new item to the nested sub-sequence
    if (contourSequence.addItem(contourSequenceItem).good())
    {
        contourSequenceItem->setContourGeometricType("POINT");
        contourSequenceItem->setNumberOfContourPoints("2");
        // set contour data (dummy values)
        DCMRT_INFO("set contour data: " << contourSequenceItem->setContourData("100\\200\\146\\101\\201\\147").text());
    }
}
DcmFileFormat rtFileformat;
if (structureSet.write(*rtFileformat.getDataset()).good())
{
    // save file
    DCMRT_INFO("save dataset to file: " << rtFileformat.saveFile("test_RTStruct.dcm", EXS_LittleEndianExplicit).text());
}

nbeck
Posts: 12
Joined: Fri, 2022-10-28, 12:56

Re: How to write contour sequence to DICOM file

#3 Post by nbeck »

Thank you for the clarification. I wasn't aware that DRTStructureSetIOD checks the data before writing it.

I did try to set all necessary fields, but I wanted to post a minimal example here. Apparently I missed some vital field. And you are right, I should have checked the log for details.

Anyway, in the meantime I have already re-written my code to generate the RT-Structure Set files using "pure" DCMTK, i.e. without DCMRT, so the problem is solved.

Thanks again!

Post Reply

Who is online

Users browsing this forum: No registered users and 0 guests