Unable to read DRTImage

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: 8
Joined: Fri, 2022-10-28, 12:56

Unable to read DRTImage

#1 Post by nbeck »

Hello,

I tried to read an RT image using DRTImage::read(DcmItem *dataset). However, this fails even though I am fairly confident that the data is valid.

Looking at the code, I noticed that DRTImage::read() appears to call DRTImageIOD::read() with the argument *format_.getDataset() although format_ hasn't been set.

Code: Select all

OFCondition DRTImage::read(DcmItem *dataset)
{
    /* get rid of the old image before we mess with its dataset */
    reset();

    dataset_ = dataset;
    OFCondition cond = DRTImageIOD::read(*format_.getDataset());
    if (cond.good())
    {
        image_ = new DicomImage(&format_,
                EXS_Unknown, CIF_MayDetachPixelData);
    }
    else
        clear();
    return cond;
}
So I changed the argument to *dataset. But reading still fails with the error "W: SOPClassUID (0008,0016) absent in SOPCommonModule (type 1)" .

Stepping through the code in the debuger I noticed that DRTImage::read first sets the member dataset_ to dataset before calling DRTImageIOD::read, which in turn calls clear(). This method is overriden in DRTImage

Code: Select all

void DRTImage::clear()
{
    reset();
    DRTImageIOD::clear();
}
finally, reset() deletes the dataset:

Code: Select all


void DRTImage::reset()
{
    delete image_;
    delete dataset_;
    format_.clear();
    image_ = NULL;
    dataset_ = NULL;
}
Therefore, the subsequent call to checkDatasetForReading fails.

I suggest to move the assignemt of dataset_ after the call to read, i.e.

Code: Select all

OFCondition DRTImage::read(DcmItem *dataset)
{
    /* get rid of the old image before we mess with its dataset */
    reset();

    //dataset_ = dataset;
    OFCondition cond = DRTImageIOD::read(*dataset);
    if (cond.good())
    {
        dataset_ = dataset;
        image_ = new DicomImage(dataset,
                EXS_Unknown, CIF_MayDetachPixelData);
    }
    else
        clear();
    return cond;
}
Let me know what you think about this.

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

Re: Unable to read DRTImage

#2 Post by J. Riesmeier »

Thank you for your report and detailed analysis. It seems that no one ever used this method before - including the author of this class :?

The version I would propose is the following:

Code: Select all

OFCondition DRTImage::read(DcmItem *dataset)
{
    /* get rid of the old image before we mess with its dataset */
    reset();

    if (dataset == NULL)
        return EC_IllegalCall;

    OFCondition cond = DRTImageIOD::read(*dataset);
    if (cond.good())
    {
        dataset_ = dataset;
        image_ = new DicomImage(dataset_, EXS_Unknown, CIF_MayDetachPixelData);
    }
    else
        clear();
    return cond;
}
Of course, error handling could be further improved, e.g. by checking the return value of "image_->getStatus()", but at least the above version should do what it is supposed to do.

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

Re: Unable to read DRTImage

#3 Post by nbeck »

Yes, that looks good to me. Checking for NULL is definitely a good idea.
Thank you for your report and detailed analysis. It seems that no one ever used this method before - including the author of this class :?
I was also surprised that nobody had found this issue until now. Probably everyone else just loads data from a file.

We probably aren't going to use this class in our software, but I wanted to report it anyway.

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

Re: Unable to read DRTImage

#4 Post by J. Riesmeier »

Thank you for the feedback. I've just committed the required changes to the internal "testing" branch of the DCMTK. The changes should be visible in the public git repository soon.

Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest