Store structure in private tag

All other questions regarding DCMTK

Moderator: Moderator Team

Post Reply
Message
Author
AlreadyGoogled
Posts: 17
Joined: Wed, 2005-01-26, 16:43

Store structure in private tag

#1 Post by AlreadyGoogled »

Hello,

Is it possible to store a block of data as a private tag using dcmtk? I need to store a structure someplace in the file for later reference. Something like the following pseudocode:

Code: Select all

    struct SOMETHING {
        int x;
        int y;
        string strData1;
        string strData2;
    };

    SOMETHING test;

    DcmFileFormat dcm;
    dcm.getDataset()->putAndInsert(0x3333, 0x0001, test);
    dcm.save(...);



    // Later on, recover the saved structure.
    SOMETHING test;

    DcmFileFormat dcm;
    dcm.getDataset()->findAndGet(0x3333, 0x0001, test);
Any ways of going about this?

Thanks as always,
Mark[/code]
________
BAJA
Last edited by AlreadyGoogled on Sun, 2011-02-13, 00:32, edited 1 time in total.

Marco Eichelberg
OFFIS DICOM Team
OFFIS DICOM Team
Posts: 1445
Joined: Tue, 2004-11-02, 17:22
Location: Oldenburg, Germany
Contact:

#2 Post by Marco Eichelberg »

Yes, it is possible to store a block of data in a private tag, both in DICOM and with DCMTK. You need to write a function/method that serializes your private data into a stream of bytes and another function that reads this stream of bytes back. I would recommend that you should not use memcpy or the like for this purpose, because otherwise the solution will be highly non-portable. Once you have a block of bytes, you can store that as a private attribute. Using VR=OB for private attributes will help to avoid problems with byte ordering and Implicit VR and is usually the best choice. Note that you can not use attribute (3333,0001) for private data. Read the corresponding section in DICOM part 5 until you understand how the concept of reservation elements in (gggg,00ee) "blocks" a range of attributes in (gggg,eexx). Otherwise your dataset will not be well-formed and you run the risk of trying to parse other people's private tags into your own structure, which is highly likely of getting you in trouble.

AlreadyGoogled
Posts: 17
Joined: Wed, 2005-01-26, 16:43

#3 Post by AlreadyGoogled »

Hi Marco,

Thanks for the reply - actually I am a bit confused now as to how to set the data in the private tag. Suppose I have a function to serialize the structure into a stream of bytes like so:

Code: Select all

    SOMETHING s;
    string strSerialized = s.serialize();
How do I actually go about setting it as VR OB in a private tag? I can only set the tags with the insert string method:

Code: Select all

    dcm.getDataset().putAndInsertString(priv_elem_tag, strSerialized.c_str());
But that only works for the first 64 characters of the data. What's the right way to go about setting it?

Thanks
________
Homemade Vaporizer
Last edited by AlreadyGoogled on Sun, 2011-02-13, 00:32, edited 1 time in total.

Marco Eichelberg
OFFIS DICOM Team
OFFIS DICOM Team
Posts: 1445
Joined: Tue, 2004-11-02, 17:22
Location: Oldenburg, Germany
Contact:

#4 Post by Marco Eichelberg »

First of all, a string is not an appropriate container for a stream of bytes, because any zero byte will end the string as returned by c_str(). Secondly, for raw data, use the OB Value representation and the putAndInsertUint8Array() method:

Code: Select all

unsigned long count = 4096; /* length of buffer */
Uint8 *buffer = new Uint8[length]; 
/* do something to fill the buffer with your private data */
/* ... */
OFCondition result = dcm.getDataset().putAndInsertUint8Array(DcmTag(0x0009,0x1000,EVR_OB), buffer, length);
delete[] buffer;

Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest