DCMTK create GSPS object with multiple image references

 

Howto: Create GSPS object with multiple image references

Here's an example that shows how to create a GSPS object with annotations and multiple image references:

 

#include "dcmtk/config/osconfig.h"
#include "dcmtk/dcmpstat/dvpstat.h"
#include "dcmtk/dcmpstat/dvpsgr.h"
 
int main(int argc, char *argv[])
{
    if (argc < 2)
    {
        COUT << "syntax usage: tstgsps <gsps-output> <image-input> ..." << OFendl;
        return 1;
    }
 
    DcmFileFormat imageFile;
    DVPresentationState pstate;
 
    /* load and process image input files */
    for (int i = 2; i < argc; i++)
    {
        if (imageFile.loadFile(argv[i]).good())
        {
            if (i == 2)
            {
                /* create default GSPS object from first image */
                if (pstate.createFromImage(*imageFile.getDataset()).bad())
                    CERR << "Error: cannot create GSPS object from first image" << OFendl;
                /* attach the first image (required for graphical annotations!)*/
                if (pstate.attachImage(imageFile.getDataset(), OFFalse).bad())
                    CERR << "Error: cannot attach first image to GSPS object" << OFendl;
            }
            /* add further image references to GSPS object */
            else if (pstate.addImageReference(*imageFile.getDataset()).bad())
                CERR << "Error: cannot add image reference #" << (i -1) << OFendl;
        } else
            CERR << "Error: cannot load file '" << argv[i] << "'" << OFendl;
    }
 
    /* add graphical annotation, create a new layer first ...  */
    if (pstate.addGraphicLayer("MEASUREMENT").good())
    {
        /* ... and then a graphic object */
        DVPSGraphicObject *graphic = pstate.addGraphicObject(pstate.getGraphicLayerIndex("MEASUREMENT"));
        if (graphic != NULL)
        {
            const Float32 data[] = {100, 100, 250, 250};
            graphic->setGraphicType(DVPST_polyline);
            graphic->setData(2, data, DVPSA_pixels);
        } else
           CERR << "Error: cannot create graphic object" << OFendl;
    } else
        CERR << "Error: cannot add graphic layer" << OFendl;
 
    DcmFileFormat gspsFile;
    /* save GSPS object first to a DICOM data set ... */
    if (pstate.write(*gspsFile.getDataset(), OFTrue).good())
    {
        /* ... and then to a DICOM file */
        if (gspsFile.saveFile(argv[1], EXS_LittleEndianExplicit).bad())
            CERR << "Error: cannot save file '" << argv[1] << "'" << OFendl;
    } else
        CERR << "Error: cannot write GSPS object to data set" << OFendl;
 
    return 0;
}

 

------------------------------------------------------------------

柳北风儿

http://qimo601.iteye.com

转载:http://support.dcmtk.org/wiki/dcmtk/howto/gspsannotations

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值