MedicalViewerSeriesStack Class

Summary

The MedicalViewerSeriesStack represents a stack of images.

Syntax
C#
VB
C++
public class MedicalViewerSeriesStack 
  
Public Class MedicalViewerSeriesStack  
            public ref class MedicalViewerSeriesStack  

Remarks

This class is used for the output of the MedicalViewerSeriesManager.Sort method, which holds a sorted stack. Each image in the stack is sorted based on its actual real world position so it is displayed correctly. This also makes it easier for the 3D toolkit to create an accurate 3D object.

Example
C#
VB
using Leadtools; 
using Leadtools.Dicom; 
using Leadtools.Medical3D; 
using Leadtools.Codecs; 
using Leadtools.MedicalViewer; 
using Leadtools.ImageProcessing; 
using Leadtools.ImageProcessing.Core; 
using Leadtools.ImageProcessing.Color; 
using Leadtools.Annotations.Engine; 
using Leadtools.Annotations.Designers; 
 
class MedicalViewerSeriesManagerFrom : Form 
{ 
   DicomElement _studyElement; 
   DicomElement _seriesElement; 
   MedicalViewerSeriesManager _seriesManager; 
   MedicalViewerSeriesManager _seriesManager512; 
   List<MedicalViewerImageData> _imageDataList; 
   double[] doubleArray; 
   DicomElement patientElement; 
   string referenceUID; 
   DicomElement imageElement; 
   MedicalViewer _medicalViewer; 
 
   public MedicalViewerSeriesManagerFrom() 
   { 
 
   } 
 
   void MedicalViewerSeriesManagerFrom_SizeChanged(object sender, EventArgs e) 
   { 
      _medicalViewer.Size = new Size(this.ClientRectangle.Right, this.ClientRectangle.Bottom); 
   } 
 
   public MedicalViewerSeriesManagerFrom(MedicalViewerSeriesManager output) 
   { 
      RasterCodecs _codecs = new RasterCodecs(); 
 
      this.SizeChanged += new EventHandler(MedicalViewerSeriesManagerFrom_SizeChanged); 
 
      // Create the medical viewer and adjust the size and the location. 
      _medicalViewer = new MedicalViewer(1, 2); 
      _medicalViewer.Location = new Point(0, 0); 
      _medicalViewer.Size = new Size(this.ClientRectangle.Right, this.ClientRectangle.Bottom); 
 
      _seriesManager = output; 
 
      MedicalViewerMultiCell cell = new MedicalViewerMultiCell(null, true, 1, 1); 
 
      int index; 
      int count = output.Stacks[0].Items.Count; 
      CodecsImageInfo codecsInformation; 
 
      MedicalViewerImageInformation[] imageInformation = new MedicalViewerImageInformation[count]; 
 
      for (index = 0; index < count; index++) 
      { 
         codecsInformation = _codecs.GetInformation((string)(output.Stacks[0].Items[index].Data), true); 
 
         imageInformation[index] = new MedicalViewerImageInformation(); 
         imageInformation[index].ImageHeight = codecsInformation.Width; 
         imageInformation[index].ImageWidth = codecsInformation.Width; 
         imageInformation[index].XResolution = codecsInformation.XResolution; 
         imageInformation[index].YResolution = codecsInformation.YResolution; 
      } 
 
      cell.FramesRequested += new EventHandler<MedicalViewerRequestedFramesInformationEventArgs>(cell_FramesRequested); 
      FormClosing += new FormClosingEventHandler(MedicalViewerSeriesManagerFrom_FormClosing); 
      cell.EnableLowMemoryUsage(2, count, imageInformation); 
 
      _medicalViewer.Cells.Add(cell); 
 
 
      cell.PixelSpacing = output.Stacks[0].PixelSpacing; 
      cell.ImageOrientation = output.Stacks[0].Items[0].ImageOrientationArray; 
      cell.FrameOfReferenceUID = output.Stacks[0].Items[0].FrameOfReferenceUID; 
 
      for (index = 0; index < count; index++) 
      { 
         cell.SetImagePosition(index, output.Stacks[0].Items[index].ImagePosition, (index == count - 1)); 
      } 
 
 
      // add some actions that will be used to change the properties of the images inside the control. 
      cell.AddAction(MedicalViewerActionType.WindowLevel); 
      cell.AddAction(MedicalViewerActionType.Alpha); 
      cell.AddAction(MedicalViewerActionType.Offset); 
      cell.AddAction(MedicalViewerActionType.Stack); 
 
      // assign the added actions to a mouse button, meaning that when the user clicks and drags the mouse button, the associated action will be activated. 
      cell.SetAction(MedicalViewerActionType.WindowLevel, MedicalViewerMouseButtons.Left, MedicalViewerActionFlags.Active); 
      cell.SetAction(MedicalViewerActionType.Alpha, MedicalViewerMouseButtons.Middle, MedicalViewerActionFlags.Active); 
      cell.SetAction(MedicalViewerActionType.Offset, MedicalViewerMouseButtons.Right, MedicalViewerActionFlags.Active); 
      cell.SetAction(MedicalViewerActionType.Stack, MedicalViewerMouseButtons.Wheel, MedicalViewerActionFlags.Active); 
 
      // adjust some properties of the cell and add some tags. 
      _medicalViewer.Cells[0].SetTag(2, MedicalViewerTagAlignment.TopLeft, MedicalViewerTagType.UserData, "EX. ID 230-36-5448"); 
      _medicalViewer.Cells[0].SetTag(4, MedicalViewerTagAlignment.TopLeft, MedicalViewerTagType.Frame); 
      _medicalViewer.Cells[0].SetTag(6, MedicalViewerTagAlignment.TopLeft, MedicalViewerTagType.Scale); 
      _medicalViewer.Cells[0].SetTag(2, MedicalViewerTagAlignment.BottomLeft, MedicalViewerTagType.WindowLevelData); 
      _medicalViewer.Cells[0].SetTag(1, MedicalViewerTagAlignment.BottomLeft, MedicalViewerTagType.FieldOfView); 
      _medicalViewer.Cells[0].SetTag(1, MedicalViewerTagAlignment.BottomLeft, MedicalViewerTagType.UserData, "Echo number = " + output.Stacks[0].EchoNumber.ToString()); 
 
      Controls.Add(_medicalViewer); 
      _medicalViewer.Dock = DockStyle.Fill; 
   } 
 
   void cell_FramesRequested(object sender, MedicalViewerRequestedFramesInformationEventArgs e) 
   { 
      MedicalViewerMultiCell cell = (MedicalViewerMultiCell)(sender); 
      RasterCodecs _codecs = new RasterCodecs(); 
      int i; 
      RasterImage image; 
      string fileName; 
 
      if (e.RequestedFramesIndexes.Length > 0) 
      { 
         fileName = (string)(_seriesManager.Stacks[0].Items[e.RequestedFramesIndexes[0]].Data); 
         image = _codecs.Load(fileName); 
      } 
      else 
         return; 
 
      for (i = 1; i < e.RequestedFramesIndexes.Length; i++) 
      { 
         fileName = (string)(_seriesManager.Stacks[0].Items[e.RequestedFramesIndexes[i]].Data); 
         image.AddPage(_codecs.Load(fileName)); 
      } 
 
      cell.SetRequestedImage(image, e.RequestedFramesIndexes, MedicalViewerSetImageOptions.Insert); 
   } 
 
   void  MedicalViewerSeriesManagerFrom_FormClosing(object sender, FormClosingEventArgs e) 
   { 
   } 
 
   // Find the study using the Study instance UID, and return it's DicomElement if the study is found 
   private DicomElement FindStudy(DicomDataSet ds, string studyInstanceUID) 
   { 
      // get the parent element. 
      DicomElement patientElement = ds.GetFirstKey(null, true); 
      DicomElement studyElement = null; 
      DicomElement studyInformationElement = null; 
      string studyID; 
 
      studyElement = ds.GetChildKey(patientElement); 
      studyElement = ds.GetChildElement(studyElement, true); 
 
      while (studyElement != null) 
      { 
         studyInformationElement = ds.FindFirstElement(studyElement, DicomTag.StudyInstanceUID, true); 
 
         if (studyInformationElement != null) 
         { 
            studyID = ds.GetConvertValue(studyInformationElement); 
 
            if (studyID == studyInstanceUID) 
               return studyInformationElement; 
         } 
 
         studyElement = ds.GetNextKey(studyElement, true); 
         studyElement = ds.GetChildElement(studyElement, true); 
      } 
      return null; 
   } 
 
   // Find the series using the Series instance UID, and return it's DicomElement if the series is found 
   private DicomElement FindSeries(DicomDataSet ds, DicomElement studyElement, string seriesInstanceUID) 
   { 
      DicomElement seriesElement = null; 
      DicomElement seriesInformationElement = null; 
      string seriesID; 
 
      seriesElement = ds.GetChildKey(studyElement); 
      seriesElement = ds.GetChildElement(seriesElement, true); 
 
      while (seriesElement != null) 
      { 
         seriesInformationElement = ds.FindFirstElement(seriesElement, 
                                                        DicomTag.SeriesInstanceUID, 
                                                        true); 
 
         if (seriesInformationElement != null) 
         { 
            seriesID = ds.GetConvertValue(seriesInformationElement); 
 
            if (seriesID == seriesInstanceUID) 
               return seriesInformationElement; 
         } 
 
         seriesElement = ds.GetNextKey(seriesElement, true); 
         seriesElement = ds.GetChildElement(seriesElement, true); 
      } 
      return null; 
   } 
 
   // return the first frame file name of the series. 
   private string GetFirstImageName(DicomDataSet ds, DicomElement seriesElement, string directoryPath, out DicomElement imageElement) 
   { 
      DicomElement imageIDElement = null; 
 
      imageElement = ds.GetChildKey(seriesElement); 
      imageElement = ds.GetChildElement(imageElement, true); 
 
      while (imageElement != null) 
      { 
         imageIDElement = ds.FindFirstElement(imageElement, 
                                            DicomTag.ReferencedFileID, 
                                            true); 
 
         if (imageIDElement != null) 
         { 
            return directoryPath + "\\" + ds.GetConvertValue(imageIDElement); 
         } 
 
 
      } 
 
      return ""; 
   } 
 
   // return the next frame file name of the series. 
   private string GetNextImageName(DicomDataSet ds, string directoryPath, ref DicomElement imageElement) 
   { 
      DicomElement nextImageElement = null; 
 
      imageElement = ds.GetNextKey(imageElement, true); 
      imageElement = ds.GetChildElement(imageElement, true); 
 
      while (imageElement != null) 
      { 
         nextImageElement = ds.FindFirstElement(imageElement, 
                                            DicomTag.ReferencedFileID, 
                                            true); 
 
         if (imageElement != null) 
         { 
            DicomElement echoElement = ds.FindFirstElement(imageElement, 
                                              DicomTag.EchoNumber, 
                                              true); 
 
            return directoryPath + "\\" + ds.GetConvertValue(nextImageElement); 
         } 
      } 
 
      return ""; 
   } 
 
 
   private bool AddImageToImageArray(DicomDataSet ds, int index, string imagePath, out int echoNumber) 
   { 
      echoNumber = -1; 
 
      MedicalViewerImageData imageData = new MedicalViewerImageData(); 
 
      patientElement = ds.FindFirstElement(null, 
                                           DicomTag.ImagePositionPatient, 
                                           true); 
 
      doubleArray = ds.GetDoubleValue(patientElement, 0, 3); 
 
      imageData.ImagePosition = Point3D.FromDoubleArray(doubleArray); 
      imageData.Data = imagePath; 
 
      imageData.EchoNumber = echoNumber; 
 
      patientElement = ds.FindFirstElement(null, 
                                          DicomTag.FrameOfReferenceUID, 
                                          true); 
 
      referenceUID = ds.GetConvertValue(patientElement); 
 
      imageData.FrameOfReferenceUID = referenceUID; 
 
      patientElement = ds.FindFirstElement(null, 
                                          DicomTag.ImageOrientationPatient, 
                                          true); 
 
      imageData.ImageOrientation = ds.GetConvertValue(patientElement); 
 
      patientElement = ds.FindFirstElement(null, 
                                           DicomTag.PixelSpacing, 
                                           true); 
 
      doubleArray = ds.GetDoubleValue(patientElement, 0, 2); 
      imageData.PixelSpacing = new Point2D((float)doubleArray[0], (float)doubleArray[1]); 
 
      _imageDataList.Add(imageData); 
 
      return true; 
 
   } 
 
   public MedicalViewerSeriesManager LoadJamesHead() 
   { 
      DicomEngine.Startup(); 
      DicomDataSet ds = new DicomDataSet(); 
      ds.Load(Path.Combine(LEAD_VARS.JamesCTDir , "DICOMDIR"), DicomDataSetLoadFlags.None); 
      string directoryPath = LEAD_VARS.JamesCTDir;///*LeadtoolsExamples.Common.ImagesPath.Path*/ Path.Combine(LEAD_VARS.ImagesDir, @"\Miller James-CT Head full Study\"); 
 
      string studyInstanceUID = "1.3.12.2.1107.5.1.4.50772.30000009122208074910900000022"; 
      string seriesInstanceUID = "1.3.12.2.1107.5.1.4.50772.30000009122208215356200001997"; 
 
      _studyElement = FindStudy(ds, studyInstanceUID); 
      _seriesElement = FindSeries(ds, _studyElement, seriesInstanceUID); 
 
      int count = 256; 
 
      _seriesManager = new MedicalViewerSeriesManager(); 
      _imageDataList = new List<MedicalViewerImageData>(); 
 
 
      DicomDataSet dicomDataSet; 
 
      int imageIndex; 
      string imagePath; 
      int echoNumber = 0; 
      imagePath = GetFirstImageName(ds, _seriesElement, directoryPath, out imageElement); 
      for (imageIndex = 0; imageIndex < count; imageIndex++) 
      { 
         try 
         { 
            dicomDataSet = new DicomDataSet(); 
            dicomDataSet.Load(imagePath, DicomDataSetLoadFlags.None); 
            AddImageToImageArray(dicomDataSet, imageIndex, imagePath, out echoNumber); 
            dicomDataSet.Dispose(); 
 
            imagePath = GetNextImageName(ds, directoryPath, ref imageElement); 
 
         } 
         catch (System.Exception exception) 
         { 
            System.Diagnostics.Debug.Assert(false, exception.Message); 
            throw; 
         } 
      } 
 
 
 
      _seriesManager.Sort(_imageDataList); 
      DicomEngine.Shutdown(); 
 
      return _seriesManager; 
   } 
 
 
   public MedicalViewerSeriesManager LoadJamesHead512() 
   { 
      DicomEngine.Startup(); 
      DicomDataSet ds = new DicomDataSet(); 
      ds.Load(Path.Combine(LEAD_VARS.JamesCTDir, "DICOMDIR"), DicomDataSetLoadFlags.None); 
      string directoryPath = LEAD_VARS.JamesCTDir; 
 
      string studyInstanceUID = "1.3.12.2.1107.5.1.4.50772.30000009122208074910900000022"; 
      string seriesInstanceUID = "1.3.12.2.1107.5.1.4.50772.30000009122208215356200002254"; 
 
      _studyElement = FindStudy(ds, studyInstanceUID); 
      _seriesElement = FindSeries(ds, _studyElement, seriesInstanceUID); 
 
      int count = 512; 
 
      _seriesManager512 = new MedicalViewerSeriesManager(); 
      _imageDataList = new List<MedicalViewerImageData>(); 
 
 
      DicomDataSet dicomDataSet; 
 
      int imageIndex; 
      string imagePath; 
      int echoNumber = 0; 
      imagePath = GetFirstImageName(ds, _seriesElement, directoryPath, out imageElement); 
      for (imageIndex = 0; imageIndex < count; imageIndex++) 
      { 
         try 
         { 
            dicomDataSet = new DicomDataSet(); 
            dicomDataSet.Load(imagePath, DicomDataSetLoadFlags.None); 
            AddImageToImageArray(dicomDataSet, imageIndex, imagePath, out echoNumber); 
            dicomDataSet.Dispose(); 
 
            imagePath = GetNextImageName(ds, directoryPath, ref imageElement); 
 
         } 
         catch (System.Exception exception) 
         { 
            System.Diagnostics.Debug.Assert(false, exception.Message); 
            throw; 
         } 
      } 
 
 
 
      _seriesManager512.Sort(_imageDataList); 
      DicomEngine.Shutdown(); 
 
      return _seriesManager512; 
   } 
 
} 
 
 
 
MedicalViewerSeriesManagerFrom GetMedicalControlForReverseExample() 
{ 
   MedicalViewerSeriesManagerFrom form = new MedicalViewerSeriesManagerFrom(); 
   MedicalViewerSeriesManager output = form.LoadJamesHead(); 
 
   return new MedicalViewerSeriesManagerFrom(output); 
} 
//  
public void MedicalViewerSeriesManagerLoadingExample() 
{ 
   MedicalViewerSeriesManagerFrom myForm = GetMedicalControlForReverseExample(); 
   myForm.ShowDialog(); 
} 
 
static class LEAD_VARS 
{ 
   public const string ImagesDir = @"C:\Users\Public\Documents\LEADTOOLS Images"; 
} 
Imports Leadtools 
Imports Leadtools.Dicom 
Imports Leadtools.Medical3D 
Imports Leadtools.Codecs 
Imports Leadtools.MedicalViewer 
Imports Leadtools.Annotations.Engine 
Imports Leadtools.Annotations.Designers 
Imports Leadtools.ImageProcessing.Core 
 
Private Class MedicalViewerSeriesManagerFrom : Inherits Form 
   Private _studyElement As DicomElement 
   Private _seriesElement As DicomElement 
   Private _seriesManager As MedicalViewerSeriesManager 
   Private _seriesManager512 As MedicalViewerSeriesManager 
   Private _imageDataList As List(Of MedicalViewerImageData) 
   Private doubleArray As Double() 
   Private patientElement As DicomElement 
   Private referenceUID As String 
   Private imageElement As DicomElement 
   Private _medicalViewer As MedicalViewer 
 
   Public Sub New() 
   End Sub 
 
   Private Sub MedicalViewerSeriesManagerFrom_SizeChanged(ByVal sender As Object, ByVal e As EventArgs) 
      _medicalViewer.Size = New Size(Me.ClientRectangle.Right, Me.ClientRectangle.Bottom) 
   End Sub 
 
   Public Sub New(ByVal output As MedicalViewerSeriesManager) 
      Dim _codecs As RasterCodecs = New RasterCodecs() 
 
      AddHandler SizeChanged, AddressOf MedicalViewerSeriesManagerFrom_SizeChanged 
 
      ' Create the medical viewer and adjust the size and the location. 
      _medicalViewer = New MedicalViewer(1, 2) 
      _medicalViewer.Location = New Point(0, 0) 
      _medicalViewer.Size = New Size(Me.ClientRectangle.Right, Me.ClientRectangle.Bottom) 
 
      _seriesManager = output 
 
      Dim cell As MedicalViewerMultiCell = New MedicalViewerMultiCell(Nothing, True, 1, 1) 
 
      Dim index As Integer 
      Dim count As Integer = output.Stacks(0).Items.Count 
      Dim codecsInformation As CodecsImageInfo 
 
      Dim imageInformation As MedicalViewerImageInformation() = New MedicalViewerImageInformation(count - 1) {} 
 
      index = 0 
      Do While index < count 
         codecsInformation = _codecs.GetInformation(CStr(output.Stacks(0).Items(index).Data), True) 
 
         imageInformation(index) = New MedicalViewerImageInformation() 
         imageInformation(index).ImageHeight = codecsInformation.Width 
         imageInformation(index).ImageWidth = codecsInformation.Width 
         imageInformation(index).XResolution = codecsInformation.XResolution 
         imageInformation(index).YResolution = codecsInformation.YResolution 
         index += 1 
      Loop 
 
      AddHandler cell.FramesRequested, AddressOf cell_FramesRequested 
      AddHandler FormClosing, AddressOf MedicalViewerSeriesManagerFrom_FormClosing 
      cell.EnableLowMemoryUsage(2, count, imageInformation) 
 
      _medicalViewer.Cells.Add(cell) 
 
 
      cell.PixelSpacing = output.Stacks(0).PixelSpacing 
      cell.ImageOrientation = output.Stacks(0).Items(0).ImageOrientationArray 
      cell.FrameOfReferenceUID = output.Stacks(0).Items(0).FrameOfReferenceUID 
 
      index = 0 
      Do While index < count 
         cell.SetImagePosition(index, output.Stacks(0).Items(index).ImagePosition, (index = count - 1)) 
         index += 1 
      Loop 
 
 
      ' add some actions that will be used to change the properties of the images inside the control. 
      cell.AddAction(MedicalViewerActionType.WindowLevel) 
      cell.AddAction(MedicalViewerActionType.Alpha) 
      cell.AddAction(MedicalViewerActionType.Offset) 
      cell.AddAction(MedicalViewerActionType.Stack) 
 
      ' assign the added actions to a mouse button, meaning that when the user clicks and drags the mouse button, the associated action will be activated. 
      cell.SetAction(MedicalViewerActionType.WindowLevel, MedicalViewerMouseButtons.Left, MedicalViewerActionFlags.Active) 
      cell.SetAction(MedicalViewerActionType.Alpha, MedicalViewerMouseButtons.Middle, MedicalViewerActionFlags.Active) 
      cell.SetAction(MedicalViewerActionType.Offset, MedicalViewerMouseButtons.Right, MedicalViewerActionFlags.Active) 
      cell.SetAction(MedicalViewerActionType.Stack, MedicalViewerMouseButtons.Wheel, MedicalViewerActionFlags.Active) 
 
      ' adjust some properties of the cell and add some tags. 
      _medicalViewer.Cells(0).SetTag(2, MedicalViewerTagAlignment.TopLeft, MedicalViewerTagType.UserData, "EX. ID 230-36-5448") 
      _medicalViewer.Cells(0).SetTag(4, MedicalViewerTagAlignment.TopLeft, MedicalViewerTagType.Frame) 
      _medicalViewer.Cells(0).SetTag(6, MedicalViewerTagAlignment.TopLeft, MedicalViewerTagType.Scale) 
      _medicalViewer.Cells(0).SetTag(2, MedicalViewerTagAlignment.BottomLeft, MedicalViewerTagType.WindowLevelData) 
      _medicalViewer.Cells(0).SetTag(1, MedicalViewerTagAlignment.BottomLeft, MedicalViewerTagType.FieldOfView) 
      _medicalViewer.Cells(0).SetTag(1, MedicalViewerTagAlignment.BottomLeft, MedicalViewerTagType.UserData, "Echo number = " & output.Stacks(0).EchoNumber.ToString()) 
 
      Controls.Add(_medicalViewer) 
      _medicalViewer.Dock = DockStyle.Fill 
   End Sub 
 
   Private Sub cell_FramesRequested(ByVal sender As Object, ByVal e As MedicalViewerRequestedFramesInformationEventArgs) 
      Dim cell As MedicalViewerMultiCell = CType(sender, MedicalViewerMultiCell) 
      Dim _codecs As RasterCodecs = New RasterCodecs() 
      Dim i As Integer 
      Dim image As RasterImage 
      Dim fileName As String 
 
      If e.RequestedFramesIndexes.Length > 0 Then 
         fileName = CStr(_seriesManager.Stacks(0).Items(e.RequestedFramesIndexes(0)).Data) 
         image = _codecs.Load(fileName) 
      Else 
         Return 
      End If 
 
      i = 1 
      Do While i < e.RequestedFramesIndexes.Length 
         fileName = CStr(_seriesManager.Stacks(0).Items(e.RequestedFramesIndexes(i)).Data) 
         image.AddPage(_codecs.Load(fileName)) 
         i += 1 
      Loop 
 
      cell.SetRequestedImage(image, e.RequestedFramesIndexes, MedicalViewerSetImageOptions.Insert) 
   End Sub 
 
   Private Sub MedicalViewerSeriesManagerFrom_FormClosing(ByVal sender As Object, ByVal e As FormClosingEventArgs) 
   End Sub 
 
   ' Find the study using the Study instance UID, and return it's DicomElement if the study is found 
   Private Function FindStudy(ByVal ds As DicomDataSet, ByVal studyInstanceUID As String) As DicomElement 
      ' get the parent element. 
      Dim patientElement As DicomElement = ds.GetFirstKey(Nothing, True) 
      Dim studyElement As DicomElement = Nothing 
      Dim studyInformationElement As DicomElement = Nothing 
      Dim studyID As String 
 
      studyElement = ds.GetChildKey(patientElement) 
      studyElement = ds.GetChildElement(studyElement, True) 
 
      Do While Not studyElement Is Nothing 
         studyInformationElement = ds.FindFirstElement(studyElement, DicomTag.StudyInstanceUID, True) 
 
         If Not studyInformationElement Is Nothing Then 
            studyID = ds.GetConvertValue(studyInformationElement) 
 
            If studyID = studyInstanceUID Then 
               Return studyInformationElement 
            End If 
         End If 
 
         studyElement = ds.GetNextKey(studyElement, True) 
         studyElement = ds.GetChildElement(studyElement, True) 
      Loop 
      Return Nothing 
   End Function 
 
   ' Find the series using the Series instance UID, and return it's DicomElement if the series is found 
   Private Function FindSeries(ByVal ds As DicomDataSet, ByVal studyElement As DicomElement, ByVal seriesInstanceUID As String) As DicomElement 
      Dim seriesElement As DicomElement = Nothing 
      Dim seriesInformationElement As DicomElement = Nothing 
      Dim seriesID As String 
 
      seriesElement = ds.GetChildKey(studyElement) 
      seriesElement = ds.GetChildElement(seriesElement, True) 
 
      Do While Not seriesElement Is Nothing 
         seriesInformationElement = ds.FindFirstElement(seriesElement, DicomTag.SeriesInstanceUID, True) 
 
         If Not seriesInformationElement Is Nothing Then 
            seriesID = ds.GetConvertValue(seriesInformationElement) 
 
            If seriesID = seriesInstanceUID Then 
               Return seriesInformationElement 
            End If 
         End If 
 
         seriesElement = ds.GetNextKey(seriesElement, True) 
         seriesElement = ds.GetChildElement(seriesElement, True) 
      Loop 
      Return Nothing 
   End Function 
 
   ' return the first frame file name of the series. 
   Private Function GetFirstImageName(ByVal ds As DicomDataSet, ByVal seriesElement As DicomElement, ByVal directoryPath As String, <System.Runtime.InteropServices.Out()> ByRef imageElement As DicomElement) As String 
      Dim imageIDElement As DicomElement = Nothing 
 
      imageElement = ds.GetChildKey(seriesElement) 
      imageElement = ds.GetChildElement(imageElement, True) 
 
      Do While Not imageElement Is Nothing 
         imageIDElement = ds.FindFirstElement(imageElement, DicomTag.ReferencedFileID, True) 
 
         If Not imageIDElement Is Nothing Then 
            Return directoryPath & "\" & ds.GetConvertValue(imageIDElement) 
         End If 
 
 
      Loop 
 
      Return "" 
   End Function 
 
   ' return the next frame file name of the series. 
   Private Function GetNextImageName(ByVal ds As DicomDataSet, ByVal directoryPath As String, ByRef imageElement As DicomElement) As String 
      Dim nextImageElement As DicomElement = Nothing 
 
      imageElement = ds.GetNextKey(imageElement, True) 
      imageElement = ds.GetChildElement(imageElement, True) 
 
      Do While Not imageElement Is Nothing 
         nextImageElement = ds.FindFirstElement(imageElement, DicomTag.ReferencedFileID, True) 
 
         If Not imageElement Is Nothing Then 
            Dim echoElement As DicomElement = ds.FindFirstElement(imageElement, DicomTag.EchoNumber, True) 
 
            Return directoryPath & "\" & ds.GetConvertValue(nextImageElement) 
         End If 
      Loop 
 
      Return "" 
   End Function 
 
 
   Private Function AddImageToImageArray(ByVal ds As DicomDataSet, ByVal index As Integer, ByVal imagePath As String, <System.Runtime.InteropServices.Out()> ByRef echoNumber As Integer) As Boolean 
      echoNumber = -1 
 
      Dim imageData As MedicalViewerImageData = New MedicalViewerImageData() 
 
      patientElement = ds.FindFirstElement(Nothing, DicomTag.ImagePositionPatient, True) 
 
      doubleArray = ds.GetDoubleValue(patientElement, 0, 3) 
 
      imageData.ImagePosition = Point3D.FromDoubleArray(doubleArray) 
      imageData.Data = imagePath 
 
      imageData.EchoNumber = echoNumber 
 
      patientElement = ds.FindFirstElement(Nothing, DicomTag.FrameOfReferenceUID, True) 
 
      referenceUID = ds.GetConvertValue(patientElement) 
 
      imageData.FrameOfReferenceUID = referenceUID 
 
      patientElement = ds.FindFirstElement(Nothing, DicomTag.ImageOrientationPatient, True) 
 
      imageData.ImageOrientation = ds.GetConvertValue(patientElement) 
 
      patientElement = ds.FindFirstElement(Nothing, DicomTag.PixelSpacing, True) 
 
      doubleArray = ds.GetDoubleValue(patientElement, 0, 2) 
      imageData.PixelSpacing = New Point2D(CSng(doubleArray(0)), CSng(doubleArray(1))) 
 
      _imageDataList.Add(imageData) 
 
      Return True 
 
   End Function 
 
   Public Function LoadJamesHead() As MedicalViewerSeriesManager 
      DicomEngine.Startup() 
      Dim ds As DicomDataSet = New DicomDataSet() 
      'INSTANT VB NOTE: Embedded comments are not maintained by Instant VB 
      'ORIGINAL LINE: ds.Load(/*LeadtoolsExamples.Common.ImagesPath.Path*/@"\\pc202\readwritefolder\DICOM Dataset\DICOM Volume datasets" + "\\Miller James-CT Head full Study\\DICOMDIR", DicomDataSetLoadFlags.None); 
      ds.Load(Path.Combine(LEAD_VARS.ImagesDir, "Miller James-CT Head full Study\DICOMDIR"), DicomDataSetLoadFlags.None) 
      'INSTANT VB NOTE: Embedded comments are not maintained by Instant VB 
      'ORIGINAL LINE: string directoryPath = /*LeadtoolsExamples.Common.ImagesPath.Path*/ @"\\pc202\readwritefolder\DICOM Dataset\DICOM Volume datasets" + "\\Miller James-CT Head full Study\\"; 
      Dim directoryPath As String = Path.Combine(LEAD_VARS.ImagesDir, "\Miller James-CT Head full Study\") 
 
      Dim studyInstanceUID As String = "1.3.12.2.1107.5.1.4.50772.30000009122208074910900000022" 
      Dim seriesInstanceUID As String = "1.3.12.2.1107.5.1.4.50772.30000009122208215356200001997" 
 
      _studyElement = FindStudy(ds, studyInstanceUID) 
      _seriesElement = FindSeries(ds, _studyElement, seriesInstanceUID) 
 
      Dim count As Integer = 256 
 
      _seriesManager = New MedicalViewerSeriesManager() 
      _imageDataList = New List(Of MedicalViewerImageData)() 
 
 
      Dim dicomDataSet As DicomDataSet 
 
      Dim imageIndex As Integer 
      Dim imagePath As String 
      Dim echoNumber As Integer = 0 
      imagePath = GetFirstImageName(ds, _seriesElement, directoryPath, imageElement) 
      imageIndex = 0 
      Do While imageIndex < count 
         Try 
            dicomDataSet = New DicomDataSet() 
            dicomDataSet.Load(imagePath, DicomDataSetLoadFlags.None) 
            AddImageToImageArray(dicomDataSet, imageIndex, imagePath, echoNumber) 
            dicomDataSet.Dispose() 
 
            imagePath = GetNextImageName(ds, directoryPath, imageElement) 
 
         Catch exception As System.Exception 
            System.Diagnostics.Debug.Assert(False, exception.Message) 
            Throw 
         End Try 
         imageIndex += 1 
      Loop 
 
 
 
      _seriesManager.Sort(_imageDataList) 
      DicomEngine.Shutdown() 
 
      Return _seriesManager 
   End Function 
 
   Public Function LoadJamesHead512() As MedicalViewerSeriesManager 
      DicomEngine.Startup() 
      Dim ds As DicomDataSet = New DicomDataSet() 
      ds.Load(Path.Combine(LEAD_VARS.JamesCTDir, "DICOMDIR"), DicomDataSetLoadFlags.None) 
      Dim directoryPath As String = LEAD_VARS.JamesCTDir 
 
      Dim studyInstanceUID As String = "1.3.12.2.1107.5.1.4.50772.30000009122208074910900000022" 
      Dim seriesInstanceUID As String = "1.3.12.2.1107.5.1.4.50772.30000009122208215356200002254" 
 
      _studyElement = FindStudy(ds, studyInstanceUID) 
      _seriesElement = FindSeries(ds, _studyElement, seriesInstanceUID) 
 
      Dim count As Integer = 512 
 
      _seriesManager512 = New MedicalViewerSeriesManager() 
      _imageDataList = New List(Of MedicalViewerImageData)() 
 
 
      Dim dicomDataSet As DicomDataSet 
 
      Dim imageIndex As Integer 
      Dim imagePath As String 
      Dim echoNumber As Integer = 0 
      imagePath = GetFirstImageName(ds, _seriesElement, directoryPath, imageElement) 
      imageIndex = 0 
      Do While imageIndex < count 
         Try 
            dicomDataSet = New DicomDataSet() 
            dicomDataSet.Load(imagePath, DicomDataSetLoadFlags.None) 
            AddImageToImageArray(dicomDataSet, imageIndex, imagePath, echoNumber) 
            dicomDataSet.Dispose() 
 
            imagePath = GetNextImageName(ds, directoryPath, imageElement) 
 
         Catch exception As System.Exception 
            System.Diagnostics.Debug.Assert(False, exception.Message) 
            Throw 
         End Try 
         imageIndex += 1 
      Loop 
 
 
 
      _seriesManager512.Sort(_imageDataList) 
      DicomEngine.Shutdown() 
 
      Return _seriesManager512 
   End Function 
End Class 
 
Private Function GetMedicalControlForReverseExample() As MedicalViewerSeriesManagerFrom 
   Dim form As MedicalViewerSeriesManagerFrom = New MedicalViewerSeriesManagerFrom() 
   Dim output As MedicalViewerSeriesManager = form.LoadJamesHead() 
 
   Return New MedicalViewerSeriesManagerFrom(output) 
End Function 
'  
<TestMethod()> _ 
Public Sub MedicalViewerSeriesManagerLoadingExample() 
   Dim myForm As MedicalViewerSeriesManagerFrom = GetMedicalControlForReverseExample() 
   myForm.ShowDialog() 
End Sub 
 
Public NotInheritable Class LEAD_VARS 
   Public Const ImagesDir As String = "C:\Users\Public\Documents\LEADTOOLS Images" 
End Class 

Requirements

Target Platforms

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

Leadtools.MedicalViewer Assembly