How to add DRTContourSequence::Item to an DRTROIContourSequence::Item

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
IThirunarayanan
Posts: 12
Joined: Thu, 2021-03-18, 08:57

How to add DRTContourSequence::Item to an DRTROIContourSequence::Item

#1 Post by IThirunarayanan » Wed, 2021-04-21, 00:46

Hello dcmtk team,

Can you please provide an example to set the contour sequences in the DRTROIContourSequence::Item of DRTStructureSetIOD? With the below strategy, when I return to main(), rtStruct.getROIContourSequence().getItem(0) results in default empty DRTContourSequence::Item and the value set from populateRoiContourSequence is lost. I understand that in my example contourSequence is local to populateRoiContourSequence and so goes out of scope when we come back to main, but the behavior is the same when I assign from main as well. Thanks for your help.

main()
{
DRTStructureSetIOD rtStruct;
populateRoiContourSequence(rtStruct);
}

populateRoiContourSequence(DRTStructureSetIOD & rtStruct)
{
auto roiContourSequence = rtStruct.getROIContourSequence();
DRTContourSequence::Item contourSequence;
string points = "100\\200\\146\\101\\200\\146"; // Some dummy point values
contourSequence.setContourData(points)
// Set all required other contourSequence attributes
auto contourSequencePtr = &contourSequence;
auto status = roiContourSequence.getContourSequence().addItem(contourSequencePtr);
}

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

Re: How to add DRTContourSequence::Item to an DRTROIContourSequence::Item

#2 Post by J. Riesmeier » Mon, 2021-04-26, 15:47

You have to create an item in both the ROI Contour Sequence and the Contour Sequence. Also the pointer parameter of the addItem() method is an output parameter, i.e. the pointer to the created item is returned.

I just wrote a little test program to be added to the "dcmrt/tests" collection of test cases. My first draft looks like the following:

Code: Select all

#include "dcmtk/config/osconfig.h"    /* make sure OS specific configuration is included first */

#include "dcmtk/ofstd/oftest.h"
#include "dcmtk/dcmrt/drtstrct.h"


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

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

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

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

        if (roiContourSequenceItem != NULL)
        {
            // set contour data (dummy values)
            OFCHECK(contourSequenceItem->setContourData("100\\200\\146\\101\\201\\147").good());
        }
    }

    // check if contour data was set correctly
    OFVector<Float64> contourData;
    OFCHECK(structureSet.getROIContourSequence().getItem(0).getContourSequence().getItem(0).getContourData(contourData).good());
    OFCHECK_EQUAL(contourData.size(), 6);
    if (contourData.size() >= 6)
    {
        OFCHECK_EQUAL(contourData.at(0), 100);
        OFCHECK_EQUAL(contourData.at(1), 200);
        OFCHECK_EQUAL(contourData.at(2), 146);
        OFCHECK_EQUAL(contourData.at(3), 101);
        OFCHECK_EQUAL(contourData.at(4), 201);
        OFCHECK_EQUAL(contourData.at(5), 147);
    }
}

IThirunarayanan
Posts: 12
Joined: Thu, 2021-03-18, 08:57

Re: How to add DRTContourSequence::Item to an DRTROIContourSequence::Item

#3 Post by IThirunarayanan » Mon, 2021-04-26, 16:59

Thank you. I didn't realize that the pointer to addItem was a return parameter.

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

Re: How to add DRTContourSequence::Item to an DRTROIContourSequence::Item

#4 Post by J. Riesmeier » Mon, 2021-04-26, 17:21

Maybe, it was not very obvious that the item is created internally, so I extended the API documentation of addItem() and insertItem() in this respect. This change will be visible in the public DCMTK git repository once I recreate the automatically generated classes of "dcmrt".


Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest