Finds the first descendant of a parentElement with the specified tag.
public Leadtools.Dicom.DicomElement FindFirstDescendant(Leadtools.Dicom.DicomElement parentElement,long tag,bool nextLevelOnly)
Public Function FindFirstDescendant( _ByVal parentElement As Leadtools.Dicom.DicomElement, _ByVal tag As Long, _ByVal nextLevelOnly As Boolean _) As Leadtools.Dicom.DicomElement
public:Leadtools.Dicom.DicomElement^ FindFirstDescendant(Leadtools.Dicom.DicomElement^ parentElement,int64 tag,bool nextLevelOnly)
parentElement
a parent item in the Data Set.
tag
tag for the item to find.
nextLevelOnly
if set to true, search for items in the next level only; otherwise, search for items recursively in all of the next levels.
The first item in the Data Set with the specified Tag, or a null reference (Nothing in VB) if an item with the specified Tag was not found.
This method finds the first descendant of the parentElement element that has a DICOM tag equivalent to the specified tag.
The diagram below represents DICOM elements stored in a DICOM dataset.
Behavior when nextLevelOnly is true
Returns the first item on the next level of parentElement with that has tag equivalent to tag. Elements included in the search include child elements in the next level only.
Example 1
nextLevelOnly is true
parentElement points to element 1
Searches elements 2, 8, 11, 12 and returns the first element that has a tag of tag.
Example 2 nextLevelOnly is true
parentElement points to element 2
Searches elements 3, 4, 7 and returns the first element that has a tag of tag.
Example 3
nextLevelOnly is true
parentElement points to element 4
Searches nodes 5, 6 and returns the first element that has a tag of tag.
Example 4
nextLevelOnly is true
parentElement points to element 11
Returns null
Behavior when nextLevelOnly is false:
Returns the first item that has a tag equivalent to tag using a pre-order search algorithm rooted at the parentElement.
Example 5
nextLevelOnly is false
parentElement 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 tag.
Example 6
nextLevelOnly is false
parentElement points to element 2
Searches elements 3, 4, 5, 6, 7 and returns the first element that has a tag of tag.
Example 7
nextLevelOnly is false
parentElement points to element 4
Searches elements 5, 6 and returns the first element that has a tag of tag.
To find elements in the Data Set with a specific Tag, use the following methods:
To find specific modules in the Data Set, use the following methods:
This example displays searches for TAG_CODE_VALUE values in 'image1.dcm' using the FindFirstDescendant() and FindNextDescendant() methods.
using Leadtools;using Leadtools.Dicom;//////void DisplayElementValue(DicomDataSet ds, DicomElement element){if (element != null){string value = ds.GetStringValue(element, 0);Console.WriteLine(value);}}private void DicomFindFirstDescendantTest(){string file = Path.Combine(LEAD_VARS.ImagesDir, "IMAGE1.dcm");DicomDataSet ds = new DicomDataSet();ds.Load(file, DicomDataSetLoadFlags.None);// Example 1:// Find all occurrences of TAG_CODE_VALUE in the dataset, searching recursively// Output should be:// T-A2000// F-10450Console.WriteLine("Example 1");DicomElement element = ds.FindFirstDescendant(null, DicomTag.CodeValue, false);while (element != null){DisplayElementValue(ds, element);element = ds.FindNextDescendant(null, element, false);}// For the next examples, we need the two parent sequences that contain the code itemsDicomElement elementAnatomicRegionSequence = ds.FindFirstDescendant(null, DicomTag.AnatomicRegionSequence, true);DicomElement elementPatientOrientationCodeSequence = ds.FindFirstDescendant(null, DicomTag.PatientOrientationCodeSequence, true);Debug.Assert(elementAnatomicRegionSequence != null);Debug.Assert(elementPatientOrientationCodeSequence != 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 levelConsole.WriteLine("Example 2");element = ds.FindFirstDescendant(elementAnatomicRegionSequence, DicomTag.CodeValue, true);while (element != null){DisplayElementValue(ds, element);element = ds.FindNextDescendant(elementAnatomicRegionSequence, element, true);}// Example 3:// Find all occurrences of TAG_CODE_VALUE with (0028,2218) Anatomic Region Sequence as pParent// Search recursively// Output should be// T-A2000Console.WriteLine("Example 3");element = ds.FindFirstDescendant(elementAnatomicRegionSequence, DicomTag.CodeValue, false);while (element != null){DisplayElementValue(ds, element);element = ds.FindNextDescendant(elementAnatomicRegionSequence, element, false);}// Example 4:// Find all occurrences of TAG_CODE_VALUE with (0028,2218) Anatomic Region Sequence as pParent// Search recursively// Output should be// F-10450Console.WriteLine("Example 4");element = ds.FindFirstDescendant(elementPatientOrientationCodeSequence, DicomTag.CodeValue, false);while (element != null){DisplayElementValue(ds, element);element = ds.FindNextDescendant(elementPatientOrientationCodeSequence, element, false);}Console.WriteLine("Finished");}///static class LEAD_VARS{public const string ImagesDir = @"C:\Users\Public\Documents\LEADTOOLS Images";}
Imports LeadtoolsImports Leadtools.Dicom''''''Private Sub DisplayElementValue(ByVal ds As DicomDataSet, ByVal element As DicomElement)If element IsNot Nothing ThenDim value As String = ds.GetStringValue(element, 0)Console.WriteLine(value)End IfEnd SubPrivate Sub DicomFindFirstDescendantTest()Dim file As String = Path.Combine(LEAD_VARS.ImagesDir, "IMAGE1.dcm")Dim ds As New DicomDataSet()ds.Load(file, DicomDataSetLoadFlags.None)' Example 1:' Find all occurrences of TAG_CODE_VALUE in the dataset, searching recursively' Output should be:' T-A2000' F-10450Console.WriteLine("Example 1")Dim element As DicomElement = ds.FindFirstDescendant(Nothing, DicomTag.CodeValue, False)Do While element IsNot NothingDisplayElementValue(ds, element)element = ds.FindNextDescendant(Nothing, element, False)Loop' For the next examples, we need the two parent sequences that contain the code itemsDim elementAnatomicRegionSequence As DicomElement = ds.FindFirstDescendant(Nothing, DicomTag.AnatomicRegionSequence, True)Dim elementPatientOrientationCodeSequence As DicomElement = ds.FindFirstDescendant(Nothing, DicomTag.PatientOrientationCodeSequence, True)Debug.Assert(elementAnatomicRegionSequence IsNot Nothing)Debug.Assert(elementPatientOrientationCodeSequence IsNot Nothing)' 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 levelConsole.WriteLine("Example 2")element = ds.FindFirstDescendant(elementAnatomicRegionSequence, DicomTag.CodeValue, True)Do While element IsNot NothingDisplayElementValue(ds, element)element = ds.FindNextDescendant(elementAnatomicRegionSequence, element, True)Loop' Example 3:' Find all occurrences of TAG_CODE_VALUE with (0028,2218) Anatomic Region Sequence as pParent' Search recursively' Output should be' T-A2000Console.WriteLine("Example 3")element = ds.FindFirstDescendant(elementAnatomicRegionSequence, DicomTag.CodeValue, False)Do While element IsNot NothingDisplayElementValue(ds, element)element = ds.FindNextDescendant(elementAnatomicRegionSequence, element, False)Loop' Example 4:' Find all occurrences of TAG_CODE_VALUE with (0028,2218) Anatomic Region Sequence as pParent' Search recursively' Output should be' F-10450Console.WriteLine("Example 4")element = ds.FindFirstDescendant(elementPatientOrientationCodeSequence, DicomTag.CodeValue, False)Do While element IsNot NothingDisplayElementValue(ds, element)element = ds.FindNextDescendant(elementPatientOrientationCodeSequence, element, False)LoopConsole.WriteLine("Finished")End Sub'''Public NotInheritable Class LEAD_VARSPublic Const ImagesDir As String = "C:\Users\Public\Documents\LEADTOOLS Images"End Class
|
Products |
Support |
Feedback: FindFirstDescendant Method - Leadtools.Dicom |
Introduction |
Help Version 19.0.2017.6.16
|

Raster .NET | C API | C++ Class Library | JavaScript HTML5
Document .NET | C API | C++ Class Library | JavaScript HTML5
Medical .NET | C API | C++ Class Library | JavaScript HTML5
Medical Web Viewer .NET
Your email has been sent to support! Someone should be in touch! If your matter is urgent please come back into chat.
Chat Hours:
Monday - Friday, 8:30am to 6pm ET
Thank you for your feedback!
Please fill out the form again to start a new chat.
All agents are currently offline.
Chat Hours:
Monday - Friday
8:30AM - 6PM EST
To contact us please fill out this form and we will contact you via email.