1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107
|
/*
*
* Copyright (C) 2012-2023, OFFIS e.V.
* All rights reserved. See COPYRIGHT file for details.
*
* This software and supporting documentation were developed by
*
* OFFIS e.V.
* R&D Division Health
* Escherweg 2
* D-26121 Oldenburg, Germany
*
*
* Module: dcmrt
*
* Author: Uli Schlachter
*
* Purpose: Mid-Level API for RT Image objects
*
*/
#include "dcmtk/config/osconfig.h" /* make sure OS specific configuration is included first */
#include "dcmtk/dcmrt/drmimage.h"
DRTImage::DRTImage()
: format_()
, dataset_(NULL)
, image_(NULL)
{
}
DRTImage::~DRTImage()
{
reset();
}
void DRTImage::reset()
{
delete image_;
delete dataset_;
format_.clear();
image_ = NULL;
dataset_ = NULL;
}
void DRTImage::clear()
{
reset();
DRTImageIOD::clear();
}
OFCondition DRTImage::loadFile(const OFFilename &filename,
const E_FileReadMode readMode,
const E_TransferSyntax readXfer)
{
/* get rid of the old image before we mess with its dataset */
reset();
OFCondition cond = format_.loadFile(filename, readXfer, EGL_noChange,
DCM_MaxReadLength, readMode);
if (cond.good())
{
cond = DRTImageIOD::read(*format_.getDataset());
if (cond.good())
{
image_ = new DicomImage(&format_, format_.getDataset()->getOriginalXfer(),
CIF_MayDetachPixelData);
}
}
if (cond.bad())
clear();
return cond;
}
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;
}
OFCondition DRTImage::getOutputData(OFVector<Uint8>& result, const unsigned long frame)
{
result.clear();
if (image_ == NULL)
return RT_EC_UnsupportedValue;
// For now we can only do 8 bit gray
const int bits = 8;
const unsigned long size = image_->getOutputDataSize(bits);
result.resize(size);
return statusToCondition(image_->getOutputData(&result[0], size, bits, frame));
}
|