LEADTOOLS Medical (Leadtools.MedicalViewer assembly) Send comments on this topic. | Back to Introduction - All Topics | Help Version 17.0.3.31
MedicalViewerSeriesStack Class
See Also  Members  
Leadtools.MedicalViewer Namespace : MedicalViewerSeriesStack Class



The MedicalViewerSeriesStack represents a stack of images.

Object Model

MedicalViewerSeriesStack ClassPoint2D Structure

Syntax

Visual Basic (Declaration) 
Public Class MedicalViewerSeriesStack 
Visual Basic (Usage)Copy Code
Dim instance As MedicalViewerSeriesStack
C# 
public class MedicalViewerSeriesStack 
C++/CLI 
public ref class MedicalViewerSeriesStack 

Example

///

Visual BasicCopy Code
Private Class MedicalViewerSeriesManagerFrom : Inherits Form
      Private _studyElement As DicomElement
      Private _seriesElement As DicomElement
      Private _seriesManager 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 action 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 click and drag the mouse button, the associated action will be activated.
         cell.SetAction(MedicalViewerActionType.WindowLevel, MedicalViewerMouseButtons.Left, MedicalViewerActionFlags.Active Or MedicalViewerActionFlags.RealTime)
         cell.SetAction(MedicalViewerActionType.Alpha, MedicalViewerMouseButtons.Middle, MedicalViewerActionFlags.Active Or MedicalViewerActionFlags.RealTime)
         cell.SetAction(MedicalViewerActionType.Offset, MedicalViewerMouseButtons.Right, MedicalViewerActionFlags.Active Or MedicalViewerActionFlags.RealTime)
         cell.SetAction(MedicalViewerActionType.Stack, MedicalViewerMouseButtons.Wheel, MedicalViewerActionFlags.Active Or MedicalViewerActionFlags.RealTime)

         ' adjust some properties to 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
   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
   ' 

   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
C#Copy Code
class MedicalViewerSeriesManagerFrom : Form
   {
      DicomElement _studyElement;
      DicomElement _seriesElement;
      MedicalViewerSeriesManager _seriesManager;
      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 action 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 click and drag the mouse button, the associated action will be activated.
         cell.SetAction(MedicalViewerActionType.WindowLevel, MedicalViewerMouseButtons.Left, MedicalViewerActionFlags.Active | MedicalViewerActionFlags.RealTime);
         cell.SetAction(MedicalViewerActionType.Alpha, MedicalViewerMouseButtons.Middle, MedicalViewerActionFlags.Active | MedicalViewerActionFlags.RealTime);
         cell.SetAction(MedicalViewerActionType.Offset, MedicalViewerMouseButtons.Right, MedicalViewerActionFlags.Active | MedicalViewerActionFlags.RealTime);
         cell.SetAction(MedicalViewerActionType.Stack, MedicalViewerMouseButtons.Wheel, MedicalViewerActionFlags.Active | MedicalViewerActionFlags.RealTime);

         // adjust some properties to 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.ImagesDir,"\\Miller James-CT Head full Study\\DICOMDIR"), DicomDataSetLoadFlags.None);
         string directoryPath = /*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;
      }
   }

   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";
}

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.

Inheritance Hierarchy

System.Object
   Leadtools.MedicalViewer.MedicalViewerSeriesStack

Requirements

Target Platforms: Microsoft .NET Framework 2.0, Windows 2000, Windows XP, Windows Server 2003 family, Windows Server 2008 family, Windows Vista, Windows 7

See Also

Leadtools.MedicalViewer requires a Medical Imaging license and unlock key. For more information, refer to: Imaging Pro/Document/Medical Features