LDicomDS::FindFirstDescendant

Summary

Returns a pointer to the first descendant of pParent with the specified tag.

Syntax

#include "Ltdic.h"

pDICOMELEMENT LDicomDS::FindFirstDescendant(pParent, nTag, bNextLevelOnly)

Parameters

pDICOMELEMENT pParent

Pointer to a parent DICOMELEMENT structure within the Data Set.

L_UINT32 nTag

Tag that specifies the item to find. For a list of default tag values, refer to Data Element Tag Constants.

L_BOOL 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 the next levels.

Returns

Value Meaning
!NULL A pointer to a DICOMELEMENT structure that contains the first item in the Data Set with the specified tag.
NULL An item with the specified tag was not 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. 

 

findfirstdescendant.png

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.

Sample 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.

Sample 2

bNextLevelOnly TRUE

pParent points to element 2

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

Sample 3

bNextLevelOnly TRUE

pParent points to element 4

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

Sample 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.

Sample 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.

Sample 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.

Sample 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 will also help you find elements in the Data Set with a specific tag:

LDicomDS::FindLastElement

LDicomDS::FindPrevElement

LDicomDS::FindNextElement

LDicomDS::FindFirstElement

LDicomDS::FindFirstDescendant

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

LDicomDS::FindModule

LDicomDS::FindIndexModule

Required DLLs and Libraries

Platforms

Win32, x64

See Also

Functions

Topics

Example

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

L_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_INT LDicomDS_FindFirstDescendantExample() 
{ 
   L_TCHAR *pszFile = MAKE_IMAGE_PATH(TEXT("image1.dcm")); 
   LDicomDS ds; 
   L_UINT16 uRet = ds.LoadDS(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 = ds.FindFirstDescendant(NULL, TAG_CODE_VALUE, FALSE); 
   while (pElement != NULL) 
   { 
      DisplayElementValue(ds, pElement); 
      pElement = ds.FindNextDescendant(NULL, pElement, FALSE); 
   } 
 
   // For the next examples, we need the two parent sequences that contain the code items 
   pDICOMELEMENT pElementAnatomicRegionSequence = ds.FindFirstDescendant(NULL, TAG_ANATOMIC_REGION_SEQUENCE, TRUE); 
   pDICOMELEMENT pElementPatientOrientationCodeSequence = ds.FindFirstDescendant(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 = ds.FindFirstDescendant(pElementAnatomicRegionSequence, TAG_CODE_VALUE, TRUE); 
   while (pElement != NULL) 
   { 
      DisplayElementValue(ds, pElement); 
      pElement = ds.FindNextDescendant(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 = ds.FindFirstDescendant(pElementAnatomicRegionSequence, TAG_CODE_VALUE, FALSE); 
   while (pElement != NULL) 
   { 
      DisplayElementValue(ds, pElement); 
      pElement = ds.FindNextDescendant(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 = ds.FindFirstDescendant(pElementPatientOrientationCodeSequence, TAG_CODE_VALUE, FALSE); 
   while (pElement != NULL) 
   { 
      DisplayElementValue(ds, pElement); 
      pElement = ds.FindNextDescendant(pElementPatientOrientationCodeSequence, pElement, FALSE); 
   } 
 
   OutputDebugString(TEXT("Finished")); 
 
   return DICOM_SUCCESS; 
} 

Help Version 22.0.2022.12.7
Products | Support | Contact Us | Intellectual Property Notices
© 1991-2023 LEAD Technologies, Inc. All Rights Reserved.

LEADTOOLS DICOM C++ Class Library Help
Products | Support | Contact Us | Intellectual Property Notices
© 1991-2023 LEAD Technologies, Inc. All Rights Reserved.