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:
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.
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:
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:
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;