L_DicomFindFirstDescendant

#include "Ltdic.h"

L_LTDIC_API pDICOMELEMENT L_DicomFindFirstDescendant(hDS, pParent, nTag, bNextLevelOnly)

HDICOMDS hDS;

a DICOM handle

pDICOMELEMENT pParent;

pointer to a DICOMELEMENT structure

L_UINT32 nTag;

tag that indicates the element to find

L_BOOL bNextLevelOnly;

flag that indicates how to evaluate the Data Set

Returns a pointer to the first item in the Data Set with the specified tag.

Parameter Description
hDS A DICOM handle.
pParent Pointer to a parent DICOMELEMENT structure within the Data Set.
nTag Tag that specifies the item to find. For a list of default tag values, refer to Data Element Tag Constants.
bNextLevelOnly Flag that indicates how the Data Set will be evaluated. Possible values are:
  Value Meaning
  TRUE Search for items in the next level only.
  FALSE Search for items recursively in all of the next levels

Returns

!NULL

A pointer to a DICOMELEMENT structure that contains the first item in the Data Set with the specified tag.

NULL

No item with the specified tag was found.

Comments

This function finds the first descendant of the Parent element (i.e. pParent) that has a DICOM tag equivalent to the nTag argument.

 The diagram below represents DICOM elements stored in a DICOM dataset. 

Behavior when bNextLevelOnly is TRUE:

Returns the first item on the next level of pParent with that has tag equivalent to nTag.  Elements included in the search include child elements in the next level only.

Example 1

bNextLevelOnly TRUE

pParent points to element 1

Searches elements 2, 8, 11, 12 and returns the first element that has a tag of nTag.

Example 2

bNextLevelOnly TRUE

pParent points to element 2

Searches elements 3, 4, 7 and returns the first element that has a tag of nTag.

Example 3

bNextLevelOnly TRUE

pParent points to element 4

Searches nodes 5, 6 and returns the first element that has a tag of nTag.

Example 4

bNextLevelOnly TRUE

pParent points to element 11

Returns NULL.

Behavior when bNextLevelOnly is FALSE:

Returns the first item that has tag equivalent to nTag using a pre-order search algorithm rooted at pParent.

Example 5

bNextLevelOnly FALSE 

pParent points to element 1

Searches elements 1, 2, 3, 4, 5, 6, 7,  8, 9, 10, 11, 12 and returns the first element that has a tag of nTag.

Example 6

bNextLevelOnly FALSE 

pParent points to element 2

Searches elements 3, 4, 5, 6, 7 and returns the first element that has a tag of nTag.

Example 7

bNextLevelOnly FALSE 

pParent points to element 4

Searches elements 5, 6 and returns the first element that has a tag of nTag.

The following functions can also help you find elements in the Data Set having a specific tag:

L_DicomFindNextDescendant

L_DicomFindFirstElement

L_DicomFindLastElement

L_DicomFindPrevElement

L_DicomFindNextElement

The following functions can help you find specific modules in the Data Set:

L_DicomFindModule

L_DicomFindIndexModule

Required DLLs and Libraries

LTDIC

For a listing of the exact DLLs and Libraries needed, based on the toolkit version, refer to Files To Be Included With Your Application

Platforms

Win32, x64, Linux.

See Also

Functions:

L_DicomFindLastElement, L_DicomFindPrevElement, L_DicomFindNextElement, L_DicomFindModule, L_DicomFindIndexModule

Topics:

Working with Data Sets

Example

This example displays searches for TAG_CODE_VALUE values in 'image1.dcm' using the FindFirstDescendant() and FindNextDescendant() methods.

#define MAKE_IMAGE_PATH(pFileName) TEXT("C:\\Users\\Public\\Documents\\LEADTOOLS Images\\")pFileName 
void DisplayElementValue(LDicomDS &ds, pDICOMELEMENT pElement) 
{ 
   if (pElement != NULL) 
   { 
      L_TCHAR szMsg[200] = {0}; 
      L_TCHAR *szValue = ds.GetStringValue(pElement, 0, 1); 
      wsprintf(szMsg, TEXT("*** %s\n"), szValue); 
      OutputDebugString(szMsg); 
   } 
} 
L_LTDICTEX_API L_INT DicomFindFirstDescendantExample() 
{ 
   L_TCHAR *pszFile = MAKE_IMAGE_PATH(TEXT("image1.dcm")); 
   LDicomDS ds; 
   HDICOMDS hDS = L_DicomCreateDS(NULL); 
   L_UINT16 uRet = L_DicomLoadDS(hDS, pszFile, 0); 
   assert(uRet == DICOM_SUCCESS); 
   // Example 1: 
   // Find all occurrences of TAG_CODE_VALUE in the dataset, searching recursively 
   // Output should be: 
   //    T-A2000 
   //    F-10450 
   OutputDebugString(TEXT("Example 1\n")); 
   pDICOMELEMENT pElement = L_DicomFindFirstDescendant(hDS, NULL, TAG_CODE_VALUE, FALSE); 
   while (pElement != NULL) 
   { 
      DisplayElementValue(ds, pElement); 
      pElement = L_DicomFindNextDescendant(hDS, NULL, pElement, FALSE); 
   } 
   // For the next examples, we need the two parent sequences that contain the code items 
   pDICOMELEMENT pElementAnatomicRegionSequence = L_DicomFindFirstDescendant(hDS, NULL, TAG_ANATOMIC_REGION_SEQUENCE, TRUE); 
   pDICOMELEMENT pElementPatientOrientationCodeSequence = L_DicomFindFirstDescendant(hDS, NULL, TAG_PATIENT_ORIENTATION_CODE_SEQUENCE, TRUE); 
   assert(pElementAnatomicRegionSequence != NULL); 
   assert(pElementPatientOrientationCodeSequence != NULL); 
   // Example 2: 
   // Find all occurrences of TAG_CODE_VALUE with (0028,2218) Anatomic Region Sequence as pParent 
   // Search only the next level 
   // Output should be empty, because TAG_CODE_VALUE are not at next level 
   OutputDebugString(TEXT("Example 2\n")); 
   pElement = L_DicomFindFirstDescendant(hDS, pElementAnatomicRegionSequence, TAG_CODE_VALUE, TRUE); 
   while (pElement != NULL) 
   { 
      DisplayElementValue(ds, pElement); 
      pElement = L_DicomFindNextDescendant(hDS, pElementAnatomicRegionSequence, pElement, TRUE); 
   } 
   // Example 3: 
   // Find all occurrences of TAG_CODE_VALUE with (0028,2218) Anatomic Region Sequence as pParent 
   // Search recursively 
   // Output should be 
   //    T-A2000 
   OutputDebugString(TEXT("Example 3\n")); 
   pElement = L_DicomFindFirstDescendant(hDS, pElementAnatomicRegionSequence, TAG_CODE_VALUE, FALSE); 
   while (pElement != NULL) 
   { 
      DisplayElementValue(ds, pElement); 
      pElement = L_DicomFindNextDescendant(hDS, pElementAnatomicRegionSequence, pElement, FALSE); 
   } 
   // Example 4: 
   // Find all occurrences of TAG_CODE_VALUE with (0028,2218) Anatomic Region Sequence as pParent 
   // Search recursively 
   // Output should be 
   //    F-10450 
   OutputDebugString(TEXT("Example 4\n")); 
   pElement = L_DicomFindFirstDescendant(hDS, pElementPatientOrientationCodeSequence, TAG_CODE_VALUE, FALSE); 
   while (pElement != NULL) 
   { 
      DisplayElementValue(ds, pElement); 
      pElement = L_DicomFindNextDescendant(hDS, pElementPatientOrientationCodeSequence, pElement, FALSE); 
   } 
   L_DicomFreeDS(hDS); 
   OutputDebugString(TEXT("Finished")); 
   return DICOM_SUCCESS; 
} 

Products | Support | Contact Us | Copyright Notices
© 1991-2017 LEAD Technologies, Inc. All Rights Reserved.
LEADTOOLS DICOM C API Help
Click or drag to resize