Get a tag and all subtags from an element in DcmDataset

All other questions regarding DCMTK

Moderator: Moderator Team

Post Reply
Message
Author
phreak
Posts: 4
Joined: Fri, 2005-07-29, 00:13

Get a tag and all subtags from an element in DcmDataset

#1 Post by phreak »

Hi,

I'm trying to make my DICOM file reader read tags such that I can obtain a tag and all its sub-tags information based on a tag description. For example, say I'm interested in a particular tag that has a bunch of subtags nested in it. When I say

...

Code: Select all

DcmDataset dataSet = fileformat.getDataset();

// findTag supposedly will have child tags in the data set.
DcmTag findTag( ... ); 
OFString tagString;
dataSet->findAndGetOFString(findTag,  tagString);
This will only give me the values in the findTag if a corresponding tag occurs in dataSet. What I want to be able to do is get the data from that tag and any child tags that findTag might have. Is there a simple way to do this? I tried using findAndGetOFStringArray, but I can't determine how many strings are in there, and it doesn't seem to give me what I want. Anyways, any pointers in the right direction would be most helpful.

Thanks!

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

#2 Post by Jörg Riesmeier »

I'm not sure that I really understand what you want. However, in case you want to iterate over all elements of a dataset or item see this posting.

wrgben
Posts: 20
Joined: Thu, 2005-01-06, 10:53

#3 Post by wrgben »

What do you mean by "subtag"? The only concept I can think of which is vaguely related to "subtags" is to do with Sequences, in which case you can use findAndGetSequenceItem or findAndGetSequence.

phreak
Posts: 4
Joined: Fri, 2005-07-29, 00:13

#4 Post by phreak »

So basically, I am trying to find out how to find the existence of a "group" of subtags, and determine how many groups there are within a sequence. For example, lets say we have the following DICOM file (contents):

Code: Select all

...

(0018,6011) SQ (Sequence with explicit length #=1)      # 140, 1 SequenceOfUltrasoundRegions
  (fffe,e000) na (Item with explicit length #=11)         # 132, 1 Item
    (0018,6012) US 1                                        #   2, 1 RegionSpatialFormat
    (0018,6014) US 1                                        #   2, 1 RegionDataType
    (0018,6016) UL 2                                        #   4, 1 RegionFlags
    (0018,6018) UL 84                                       #   4, 1 RegionLocationMinX0
    (0018,601a) UL 98                                       #   4, 1 RegionLocationMinY0
    (0018,601c) UL 1009                                     #   4, 1 RegionLocationMaxX1
    (0018,601e) UL 758                                      #   4, 1 RegionLocationMaxY1
    (0018,6024) US 3                                        #   2, 1 PhysicalUnitsXDirection
    (0018,6026) US 3                                        #   2, 1 PhysicalUnitsYDirection
    (0018,602c) FD 0.00663887                               #   8, 1 PhysicalDeltaX
    (0018,602e) FD 0.00663887                               #   8, 1 PhysicalDeltaY
  (fffe,e00d) na (ItemDelimitationItem for re-encoding)   #   0, 0 ItemDelimitationItem
(fffe,e0dd) na (SequenceDelimitationItem for re-encod.) #   0, 0 SequenceDelimitationItem

...

From this, we can see that tag 0018, 6011 has one sequence of 11 items. So, I want to query my DcmDataset in some fashion with tag 0018, 6011 and get the number "1", indicating that tag 0018, 6011 has 1 sequence of tags associated with it. Is there a simple way to do this that I'm overlooking?

Sorry my lingo is off, DICOM is a bit new to me. So "subtag" is not the correct term? Should I have used the term "sequence" instead?

Thanks in advance...

wrgben
Posts: 20
Joined: Thu, 2005-01-06, 10:53

#5 Post by wrgben »

(0018, 6011) *is* the sequence. There is a simple way to determine if the sequence exists:

Code: Select all

DcmItem *ditem = NULL;
OFCondition ret = dset->findAndGetSequenceItem(DCM_SequenceOfUltrasoundRegions,ditem);
If ditem is not NULL, then the sequence exists. You can then search ditem with the findAndGet... methids to find the tags in the sequence

Thomas Wilkens
DCMTK Developer
Posts: 117
Joined: Tue, 2004-11-02, 17:21
Location: Oldenburg, Germany
Contact:

#6 Post by Thomas Wilkens »

You are using some DICOM terms in the wrong way. From your post it is clear that you dont really know what a sequence attribute is. Here's a short explanation:
  • A special case among the DICOM data types is the sequence („Sequence of Items“, SQ), which can be used to create hierarchical data structures
  • Attribute value is an order list of so-called „Items“
  • An item is a frame structure containing a complete DICOM data set
    Therefore, the value of a sequence is a list of DICOM data sets which again may contain sequences, and so on.
  • Most of the time, all items of a sequence have the same structure (analogy: an array of structs in C/C++)
  • There are a few sequences, though, where each item may have a different structure.
So actually, when you look at this

Code: Select all

(0018,6011) SQ (Sequence with explicit length #=1)      # 140, 1 SequenceOfUltrasoundRegions
  (fffe,e000) na (Item with explicit length #=11)         # 132, 1 Item
    (0018,6012) US 1                                        #   2, 1 RegionSpatialFormat
    (0018,6014) US 1                                        #   2, 1 RegionDataType
    (0018,6016) UL 2                                        #   4, 1 RegionFlags
    (0018,6018) UL 84                                       #   4, 1 RegionLocationMinX0
    (0018,601a) UL 98                                       #   4, 1 RegionLocationMinY0
    (0018,601c) UL 1009                                     #   4, 1 RegionLocationMaxX1
    (0018,601e) UL 758                                      #   4, 1 RegionLocationMaxY1
    (0018,6024) US 3                                        #   2, 1 PhysicalUnitsXDirection
    (0018,6026) US 3                                        #   2, 1 PhysicalUnitsYDirection
    (0018,602c) FD 0.00663887                               #   8, 1 PhysicalDeltaX
    (0018,602e) FD 0.00663887                               #   8, 1 PhysicalDeltaY
  (fffe,e00d) na (ItemDelimitationItem for re-encoding)   #   0, 0 ItemDelimitationItem
(fffe,e0dd) na (SequenceDelimitationItem for re-encod.) #   0, 0 SequenceDelimitationItem 
you could say that
  • (0018,6011) is a sequence attribute
  • this sequence attribute contains one item
  • this one item contains (a dataset that consists of) 11 attributes
In order to make the notion of a sequence clear to you, here is another example of a sequence:

Code: Select all

(0018,6011) SQ (Sequence with explicit length #=2)      # 140, 1 SequenceOfUltrasoundRegions
  (fffe,e000) na (Item with explicit length #=11)         # 132, 1 Item
    (0018,6012) US 1                                        #   2, 1 RegionSpatialFormat
    (0018,6014) US 1                                        #   2, 1 RegionDataType
    (0018,6016) UL 2                                        #   4, 1 RegionFlags
    (0018,6018) UL 84                                       #   4, 1 RegionLocationMinX0
    (0018,601a) UL 98                                       #   4, 1 RegionLocationMinY0
    (0018,601c) UL 1009                                     #   4, 1 RegionLocationMaxX1
    (0018,601e) UL 758                                      #   4, 1 RegionLocationMaxY1
    (0018,6024) US 3                                        #   2, 1 PhysicalUnitsXDirection
    (0018,6026) US 3                                        #   2, 1 PhysicalUnitsYDirection
    (0018,602c) FD 0.00663887                               #   8, 1 PhysicalDeltaX
    (0018,602e) FD 0.00663887                               #   8, 1 PhysicalDeltaY
  (fffe,e00d) na (ItemDelimitationItem for re-encoding)   #   0, 0 ItemDelimitationItem
  (fffe,e000) na (Item with explicit length #=11)         # 132, 1 Item
    (0018,6012) US 1                                        #   2, 1 RegionSpatialFormat
    (0018,6014) US 1                                        #   2, 1 RegionDataType
    (0018,6016) UL 2                                        #   4, 1 RegionFlags
    (0018,6018) UL 74                                       #   4, 1 RegionLocationMinX0
    (0018,601a) UL 88                                       #   4, 1 RegionLocationMinY0
    (0018,601c) UL 1019                                     #   4, 1 RegionLocationMaxX1
    (0018,601e) UL 768                                      #   4, 1 RegionLocationMaxY1
    (0018,6024) US 3                                        #   2, 1 PhysicalUnitsXDirection
    (0018,6026) US 3                                        #   2, 1 PhysicalUnitsYDirection
    (0018,602c) FD 0.00763887                               #   8, 1 PhysicalDeltaX
    (0018,602e) FD 0.00763887                               #   8, 1 PhysicalDeltaY
  (fffe,e00d) na (ItemDelimitationItem for re-encoding)   #   0, 0 ItemDelimitationItem
(fffe,e0dd) na (SequenceDelimitationItem for re-encod.) #   0, 0 SequenceDelimitationItem 
For this sequence you could say that
  • (0018,6011) is a sequence attribute
  • this sequence attribute contains two items
  • these two items each contain (a dataset that consists of) 11 attributes
(Regarding sequences, look at part 3 of the DICOM standard in any IOD description. Attributes inside a sequence are labeled with the ">" character.)

Now regarding your question: Actually I think you would like to query the number of items within a sequence attribute. (In the first example above, this query would return "1", in the second example above, this query would return "2".) You can easiliy do this, see the following example:

Code: Select all

  DcmSequenceOfItems *sequenceElement;
  ...
  // if the sequence contains exactly one empty item
  if( sequenceElement->card() == 1 )
  {
    // if the first item of the sequence element is empty
    if( sequenceElement->getItem(0)->card() == 0 )
    {
      // do something
        ...
    }
    else
    {
      // do something else if the first item of the sequence is not empty
      ...
    }
  }
I hope this answers your question.

Post Reply

Who is online

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