formatting your DICOM dump

All other questions regarding DCMTK

Moderator: Moderator Team

Post Reply
Message
Author
markw
Posts: 84
Joined: Mon, 2005-01-17, 01:08

formatting your DICOM dump

#1 Post by markw »

Hi all,

I've been using the dicom dump sample app to print all the tags in a dicom file to a stream. I was wondering if there was a way to hook into the print() function so that for each tag encountered I can extract the group/element#, value, etc into a structure so I can format them nicely in a list instead of dumping to a text file.

I see DcmDataset::print() calls DcmObject::print() to do it, but how does DcmObject::print() call any of its own functions like DcmObject::printInfoLineStart() that do the actual writing? (I don't see where it is calling those)

Thanks for any pointers

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 »

See the overloaded definitions of the print() method in various classes derived from DcmObject, e.g. DcmByteString::print, DcmDataset::print, DcmFileFormat::print, DcmItem::print, DcmMetaInfo::print, DcmPixelData::print, DcmPixelSequence::print, DcmPixelItem::print, DcmSequenceOfItems::print, DcmAttributeTag::print, DcmFloatingPointDouble::print, DcmFloatingPointSingle::print, DcmOtherByteOtherWord::print, DcmSignedLong::print, DcmSignedShort::print, DcmUniqueIdentifier::print, DcmUnsignedLong::print, DcmUnsignedShort::print. All (or at least most) of these would have to be modified, which shows that custom formatting was not what the original author of these methods had in mind.

Jörg Riesmeier
ICSMED DICOM Services
ICSMED DICOM Services
Posts: 2217
Joined: Fri, 2004-10-29, 21:38
Location: Oldenburg, Germany

#3 Post by Jörg Riesmeier »

If you still want to create your own "dump format" you should probably use the "flags" parameter of the print() methods. Btw, there are already two "print flags" defined in class DCMTypes (PF_shortenLongTagValues and PF_showTreeStructure). However, the second one (PF_showTreeStructure) is still experimental and, therefore, not (yet) available as an "dcmdump" command line option.

markw
Posts: 84
Joined: Mon, 2005-01-17, 01:08

#4 Post by markw »

Thank you Marco and Jorg for the heads up, I see what you mean. For the time being I chose to only alter printInfoLineStart() and printInfoLineEnd() in DcmObject. I reformatted the way the info is printed to the stream so I can parse it in memory to get the items I want to stuff into my list.

Ideally I could have passed a vector of tag structures to the print functions so it could just fill that in for each tag read, but I'll leave that for a braver day!

Thanks,
Mark

Jörg Riesmeier
ICSMED DICOM Services
ICSMED DICOM Services
Posts: 2217
Joined: Fri, 2004-10-29, 21:38
Location: Oldenburg, Germany

#5 Post by Jörg Riesmeier »

Why do you use the print() method at all? If you want to fill a list with all elements you should rather traverse the dataset tree (see Google Groups).

markw
Posts: 84
Joined: Mon, 2005-01-17, 01:08

#6 Post by markw »

Hi Jorg,

I checked out the google groups and found a code snippet posted by dcmtk regarding this. It seems to work ok:

Code: Select all

DcmStack stack; 
DcmObject *dobject = NULL; 
DcmElement *delem = NULL; 
OFCondition status = dfile.nextObject(stack, OFTrue); 

while (status.good()) {

    dobject = stack.top(); 
    // use dobject to get VR, len, group/elem tags, this is fine.

    delem = (DcmElement *)dobject;
    DcmVR dvr(dobject->getVR());

    if (delem->valueLoaded()) {
        if (strcmp(dvr.getVRName(), "CS") == 0) {
            char *psz;
            delem->getString(psz);
        }
        else if (dvr.getVRName(), "US") == 0) {
            Uint16 us;
            delem->getUint16(us);
        }
        // etc.
    }
}
If I try getting any of the tag values solely as a string array, I always get excepetions. Once I switch on the VR of the tag, I can extract the tag info with an appropriate method. But is there a better/easier way to do that instead of strcmp() every tag? I thought getString() worked for any tag type.

Thanks,
Mark

Jörg Riesmeier
ICSMED DICOM Services
ICSMED DICOM Services
Posts: 2217
Joined: Fri, 2004-10-29, 21:38
Location: Oldenburg, Germany

#7 Post by Jörg Riesmeier »

DcmElement::getOFString() and DcmElement::getOFStringArray() should work for all VRs. However, you should be careful with huge amounts of binary data (e.g. pixel data). getString() only returns a reference to the internally stored C string and, therefore, only works for VRs which are based on character strings.

markw
Posts: 84
Joined: Mon, 2005-01-17, 01:08

#8 Post by markw »

Hi Jorg,

I see that throughout my dumps I get some items that look like:

Code: Select all

Group/element    length      VR       TagName
FFFE  E000            182        na           Item
FFFE  E000          140288     na           Item
It is on these elements that I will get the exceptions. If I check for VR of 'na' to skip those, then the dump works nicely.

Thank you very much for all your help,
Mark

Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest