Read private tags from a file with implicit VR

All other questions regarding DCMTK

Moderator: Moderator Team

Post Reply
Message
Author
Bojan
Posts: 11
Joined: Mon, 2013-04-22, 09:52

Read private tags from a file with implicit VR

#1 Post by Bojan »

Hi,

Is there a way to read a value of the private tag from a file with implicit VR without recompiling DCMTK with that tag in private.dic?

Can I just specify how the tag should be read? Or can I add that tag to the global dictionary in runtime?

I tried just specifying the tag's VR like this:

Code: Select all

OFString tempString;
dataset->findAndGetOFString(DcmTag(0x2929, 0x3701, EVR_IS), tempString);
But it doesn't give the correct value.

I also tried adding the tag to the global dictionary before calling findAndGetOFString(), like this:

Code: Select all

DcmDataDictionary &dict = dcmDataDict.wrlock();
dict.addEntry(new DcmDictEntry(0x2929, 0x3701, EVR_IS, "MY ELEMENT NAME", 0, 1, nullptr, true, "MY PRIVATE CREATOR"));
dcmDataDict.unlock();
But that didn't help.

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

Re: Read private tags from a file with implicit VR

#2 Post by J. Riesmeier »

Is there a way to read a value of the private tag from a file with implicit VR without recompiling DCMTK with that tag in private.dic?
Yes, of course, it is. This is explained in the documentation: http://support.dcmtk.org/docs/file_datadict.html

Also see this HOWTO for your further questions.

Bojan
Posts: 11
Joined: Mon, 2013-04-22, 09:52

Re: Read private tags from a file with implicit VR

#3 Post by Bojan »

Thanks for the answer.

Yes, I need something along the lines of the example from that HOWTO. But the example doesn't show how the private tags are read from the file and that's the part that doesn't work for me.

My understanding is that following code should print out "123", but it prints "31" i.e. it doesn't read the string value correctly. Can you please point me to what I am doing wrong? I tried to make the code as shorter as possible but still complete:

Code: Select all

#include "dcmtk/config/osconfig.h"
#include "dcmtk/dcmdata/dctk.h"

#define PRIVATE_CREATOR_NAME "MY PRIVATE CREATOR NAME"

#define TEST_ELEMENT_TAG 0x2929, 0x3709
#define TEST_ELEMENT_NAME "Test Element Name"
#define TEST_ELEMENT DcmTag(TEST_ELEMENT_TAG, "IS")

int main()
{
	DcmDataDictionary &dict = dcmDataDict.wrlock();
	dict.addEntry(new DcmDictEntry(TEST_ELEMENT_TAG, EVR_IS, TEST_ELEMENT_NAME, 1, 1, "private", OFTrue, PRIVATE_CREATOR_NAME));
	dcmDataDict.unlock();

	DcmFileFormat inFile;
	nFile.loadFile("c:\\2.dcm");
	DcmDataset *dataset = inFile.getDataset();

	dataset->putAndInsertString(TEST_ELEMENT, "123");

	inFile.saveFile("c:\\2_edit.dcm");
	inFile.loadFile("c:\\2_edit.dcm");

	dataset = inFile.getDataset();

	OFString tempString;
	dataset->findAndGetOFString(TEST_ELEMENT, tempString);
	std::cout << tempString.c_str() << std::endl;

    return 0;
}
None of the functions return error. I removed the checks here to make the code short.



Also, I think there's an error in the HOWTO example:

Code: Select all

#define PRV_PrivateElement1  DcmTag(PRIVATE_ELEMENT1_TAG, PRIVATE_CREATOR_NAME)
Should be:

Code: Select all

#define PRV_PrivateElement1  DcmTag(PRIVATE_ELEMENT1_TAG, "LO")

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

Re: Read private tags from a file with implicit VR

#4 Post by J. Riesmeier »

First of all, make sure that the private data element is declared correctly within the dataset you want to read, i.e. that there is a private crteator element with the correct tag and element value! I don't think so (at least your example does not should this).
Also, I think there's an error in the HOWTO example:
Are you referring to the third code example? Did you read the text before this example? It only works with a version of the DCMTK that is newer than the last release (3.6.0), i.e. you need a current development snapshot.

Bojan
Posts: 11
Joined: Mon, 2013-04-22, 09:52

Re: Read private tags from a file with implicit VR

#5 Post by Bojan »

As usual, the problem was the lack of knowledge of standard, not the library. Adding the private creator element solved the problem. Thank you very much!
Did you read the text before this example?
I obviously didn't. Sorry about that.

Bojan
Posts: 11
Joined: Mon, 2013-04-22, 09:52

Re: Read private tags from a file with implicit VR

#6 Post by Bojan »

One more question: Can DCMTK help me decode the values of elements with private tags when the private creator element is missing (even though that's not by the standard)?

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

Re: Read private tags from a file with implicit VR

#7 Post by J. Riesmeier »

You have to insert the missing Private Creator element (if known) before retrieving the private data, because the private tag itself is not unique.

Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot], Google [Bot] and 1 guest