L_DicomFindFirstDescendant

#include "Ltdic.h"

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

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

Parameters

HDICOMDS hDS

A DICOM handle.

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

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.

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:

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

Required DLLs and Libraries

Platforms

Win32, x64, Linux.

See Also

Functions

Topics

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(HDICOMDS hDS, pDICOMELEMENT pElement) 
{ 
   if (pElement != NULL) 
   { 
      L_TCHAR szMsg[200] = { 0 }; 
      L_TCHAR *szValue = L_DicomGetStringValue(hDS, pElement, 0, 1); 
      wsprintf(szMsg, TEXT("*** %s\n"), szValue); 
      OutputDebugString(szMsg); 
   } 
} 
 
L_INT DicomFindFirstDescendantExample() 
{ 
   L_TCHAR *pszFile = MAKE_IMAGE_PATH(TEXT("image1.dcm")); 
   HDICOMDS hDS = L_DicomCreateDS(NULL); 
   L_UINT16 uRet = L_DicomLoadDS(hDS, pszFile, 0); 
   UNREFERENCED_PARAMETER(uRet); 
   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(hDS, 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(hDS, 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(hDS, 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(hDS, pElement); 
      pElement = L_DicomFindNextDescendant(hDS, pElementPatientOrientationCodeSequence, pElement, FALSE); 
   } 
   L_DicomFreeDS(hDS); 
   OutputDebugString(TEXT("Finished")); 
   return DICOM_SUCCESS; 
} 

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

LEADTOOLS DICOM C API Help