LEADTOOLS Medical Send comments on this topic. | Back to Introduction - All Topics | Help Version 17.0.3.22
Working With Reference Lines

In this tutorial, you will learn how to display a reference line in the Medical Viewer Cells.

  1. Open Visual Studio 2005 or later.
  2. From File menu > choose Project.
  3. The new project dialog appears.
  4. From project types, expand the Other languages node, and click on the Visual C# node.
  5. From the template list on the left side of the dialog, choose Windows Forms Application.
  6. Type the project name as "Working With Reference Lines" in the Project Name field, and then choose OK.
  7. Select OK to create the project.
  8. From View menu > choose Solution explorer.
  9. On the Solution explorer tree, right click on the References node and select Add Reference.
  10. On the Add Reference dialog, select the Browse tab, and add the following dll's:
    • Leadtools.dll
    • Leadtools.Codecs.dll
    • Leadtools.MedicalViewer.dll
    • Leadtools.Medical3D.dll
    • Leadtools.Dicom.dll
    • Leadtools.Codecs.Cmp.dll
  11. Switch to Form1 code view (right-click Form1 in the solution explorer then select View Code ) and add the following lines at the beginning of the file:
    [Visual Basic]
                Imports Leadtools
                Imports Leadtools.Codecs
                Imports Leadtools.MedicalViewer
                Imports Leadtools.Medical3D
                Imports Leadtools.Dicom
                
    
    [C#]
                using Leadtools;
                using Leadtools.Codecs;
                using Leadtools.MedicalViewer;
                using Leadtools.Medical3D;
                using Leadtools.Dicom;
                
    
  12. In Form1, create a new method InitClass(). Add the following code in the InitClass() method:
    [Visual Basic]
                Private Sub InitClass()
                   RasterSupport.Unlock(RasterSupportType.Dicom, " Your Dicom Key")
                   RasterSupport.Unlock(RasterSupportType.Medical, "Your Medical Key")
                   RasterSupport.Unlock(RasterSupportType.Medical3d, "Your Medical 3D Key")
                   
                   ' Create a new instance of the Codecs class, which will be used to load the images.
                   Dim _codecs As RasterCodecs = New RasterCodecs()
                   ' Create a new instance of the Medical Viewer. The layout will be divided to 2X2.
                   Dim viewer As MedicalViewer = New MedicalViewer(2, 2)
                   ' Fit the view to the whole form
                   viewer.Dock = DockStyle.Fill
                   ' Add the viewer to the form
                   Controls.Add(viewer)
                End Sub
                
    
    [C#]
                void InitClass()
                {
                   RasterSupport.Unlock(RasterSupportType.Dicom, " Your Dicom Key");
                   RasterSupport.Unlock(RasterSupportType.Medical, "Your Medical Key");
                   RasterSupport.Unlock(RasterSupportType.Medical3d, "Your Medical 3D Key");
                   
                   // Create a new instance of the Codecs class, which will be used to load the images.
                   RasterCodecs _codecs = new RasterCodecs();
                   // Create a new instance of the Medical Viewer. The layout will be divided to 2X2.
                   MedicalViewer viewer = new MedicalViewer(2, 2);
                   // Fit the view to the whole form
                   viewer.Dock = DockStyle.Fill;
                   // Add the viewer to the form
                   Controls.Add(viewer);
                }
                
    

    Note: For more information on how to acquire the above unlock keys, please contact LEAD Technologies support.

  13. Call the InitClass method from inside the Form1 constructor and place the call after InitializeComponent();
  14. Run the program and you will see a 2x2 layout.
  15. Note: For the next step, you will need to have a DICOMDIR file. We provide DICOMDIR sample files which can be downloaded from here. For more information on building 3D objects from a DICOMDIR, please see Loading a DICOMDIR To Create a 3D Object.

    Note: If you encounter an "Invalid File Format" or "Feature Not Supported" exception, please refer to the topic Invalid File Format/Feature Not Supported.

    Download the sample DICOMDIR and uncompress the contents to the folder: C:\Leadtools_DICOMDIR.

  16. Add the following code to the Form1 class. This code is for loading the images from the DICOMDIR, sorting them and extracting all the useful information:
    [Visual Basic]
                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 output As MedicalViewerSeriesManager
                ' 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
                ' This will load the dicom data set information and save it into a new instance of the class MedicalViewerImageData.
                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)))
                  patientElement = ds.FindFirstElement(Nothing, DicomTag.InstanceNumber, True)
                  If Not patientElement Is Nothing Then
                    imageData.InstanceNumber = Convert.ToInt32(ds.GetConvertValue(patientElement))
                  End If
                  patientElement = ds.FindFirstElement(Nothing, DicomTag.InstanceCreationTime, True)
                  If Not patientElement Is Nothing Then
                    imageData.CaptureTime = Convert.ToDateTime(ds.GetConvertValue(patientElement))
                  End If
                  _imageDataList.Add(imageData)
                  Return True
                End Function
                Public Function Load_James_CT_Localizer() As MedicalViewerSeriesManager
                  Dim fileName As String = "C:\Leadtools_DICOMDIR\Miller James\"
                  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.30000009122208074910900000023"
                  Return LoadSeries(fileName, studyInstanceUID, seriesInstanceUID, 1)
                End Function
                Public Function Load_James_CT() As MedicalViewerSeriesManager
                  Dim fileName As String = "C:\Leadtools_DICOMDIR\Miller James\"
                  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"
                  Return LoadSeries(fileName, studyInstanceUID, seriesInstanceUID, 256)
                End Function
                ' this will load the series specified by the seriesInstanceUID and studyInstanceUID from the file specified in fileName
                Private Function LoadSeries(ByVal fileName As String, ByVal studyInstanceUID As String, ByVal seriesInstanceUID As String, ByVal count As Integer) As MedicalViewerSeriesManager
                  DicomEngine.Startup()
                  Dim ds As DicomDataSet = New DicomDataSet()
                  ds.Load(fileName &"DICOMDIR", DicomDataSetLoadFlags.None)
                  Dim directoryPath As String = fileName
                  ' Here the program will search for the study with the specified studyInstanceUID.
                  _studyElement = FindStudy(ds, studyInstanceUID)
                  ' Here the program will search for the series with the specified seriesInstanceUID.
                  _seriesElement = FindSeries(ds, _studyElement, seriesInstanceUID)
                  ' create a new instance of the MedicalViewerSeriesManager which will be used to sort the images, in order to create the correct 3D object.
                  _seriesManager = New MedicalViewerSeriesManager()
                  ' create a an array of MedicalViewerImageData. this class will be used to save the frame information. these information will be used to sort the images.
                  _imageDataList = New List(Of MedicalViewerImageData)()
                  Dim dicomDataSet As DicomDataSet
                  Dim imageIndex As Integer
                  Dim imagePath As String
                  Dim echoNumber As Integer = 0
                  ' Now the program will go through each frame in the series
                  imagePath = GetFirstImageName(ds, _seriesElement, directoryPath, imageElement)
                  imageIndex = 0
                  Do While imageIndex < count
                    Try
                       ' each image in the series will be loaded.
                       dicomDataSet = New DicomDataSet()
                       dicomDataSet.Load(imagePath, DicomDataSetLoadFlags.None)
                       ' The program will load it's information and save it into a new instance of the class MedicalViewerImageData.
                       AddImageToImageArray(dicomDataSet, imageIndex, imagePath, echoNumber)
                       dicomDataSet.Dispose()
                       ' go to the next image.
                       imagePath = GetNextImageName(ds, directoryPath, imageElement)
                    Catch exception As System.Exception
                       System.Diagnostics.Debug.Assert(False, exception.Message)
                       Throw
                    End Try
                     imageIndex += 1
                  Loop
                  ' sort the images, based on its data.
                  _seriesManager.Sort(_imageDataList)
                  DicomEngine.Shutdown()
                  Return _seriesManager
                End Function
                Private Sub LoadLocalizer(ByVal cell As MedicalViewerMultiCell)
                  ' start up the codes, which allows loading various images.
                  Dim _codecs As RasterCodecs = New RasterCodecs()
                  ' Load the CT localizer.
                  output = Load_James_CT_Localizer()
                  cell.Image = _codecs.Load(CStr(output.Localizers(0).LocalizerData.Data), 0, CodecsLoadByteOrder.BgrOrGrayOrRomm, 1, 1)
                  ' the following three lines are important to set. otherwise, wrong reference line restuls may occur.
                  ' set the image position of the localizer.
                  cell.SetImagePosition(0, _seriesManager.Localizers(0).LocalizerData.ImagePosition, True)
                  ' set the image orientation of the localizer.
                  cell.ImageOrientation = _seriesManager.Localizers(0).LocalizerData.ImageOrientationArray
                  ' set the pixel spacing of the localizer.
                  cell.PixelSpacing = _seriesManager.Localizers(0).LocalizerData.PixelSpacing
                  ' set the frame reference UID of the localizer. This will create a reference line between the series and the localizer if they have the same reference UID
                  cell.FrameOfReferenceUID = _seriesManager.Localizers(0).LocalizerData.FrameOfReferenceUID
                End Sub
                Private Sub Load2DCell(ByVal cell As MedicalViewerMultiCell)
                  ' start up the codes, which allows loading various images.
                  Dim _codecs As RasterCodecs = New RasterCodecs()
                  ' Load the CT DICOMDIR and return arranged stack of images.
                  output = Load_James_CT()
                  ' loop through the images and add them one by one to the final image
                  Dim image As RasterImage = Nothing
                  Dim depth As Integer = output.Stacks(0).Items.Count
                  Dim index As Integer
                  index = 0
                  Do While index < depth
                    If image Is Nothing Then
                       image = _codecs.Load(CStr(output.Stacks(0).Items(index).Data), 0, CodecsLoadByteOrder.BgrOrGrayOrRomm, 1, 1)
                    Else
                       image.AddPage(_codecs.Load(CStr(output.Stacks(0).Items(index).Data), 0, CodecsLoadByteOrder.BgrOrGrayOrRomm, 1, 1))
                    End If
                     index += 1
                  Loop
                  cell.Image = image
                  ' the following lines are important to set. otherwise, wrong reference line results may occur.
                  index = 0
                  Do While index < depth
                    ' set the image position of the each frame.
                    cell.SetImagePosition(index, _seriesManager.Stacks(0).Items(index).ImagePosition, False)
                     index += 1
                  Loop
                  ' set the image orientation of the series, this is set once, since all the frames must have the same orientation value.
                  cell.ImageOrientation = _seriesManager.Stacks(0).Items(0).ImageOrientationArray
                  ' set the pixel spacing of the series, this is set once, since all the frames must have the same pixel spacing value.
                  cell.PixelSpacing = _seriesManager.Stacks(0).Items(0).PixelSpacing
                  ' set the frame reference UID of the series. This will create a reference line between the series and the localizer if they have the same reference UID
                  cell.FrameOfReferenceUID = _seriesManager.Stacks(0).Items(0).FrameOfReferenceUID
                End Sub
                
    
    [C#]
                DicomElement _studyElement;
                DicomElement _seriesElement;
                MedicalViewerSeriesManager _seriesManager;
                List<MedicalViewerImageData> _imageDataList;
                double[] doubleArray;
                DicomElement patientElement;
                string referenceUID;
                DicomElement imageElement;
                MedicalViewerSeriesManager output;
                // 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 "";
                }
                // This will load the dicom data set information and save it into a new instance of the class MedicalViewerImageData.
                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]);
                   patientElement = ds.FindFirstElement(null,
                                                       DicomTag.InstanceNumber,
                                                       true);
                   if (patientElement != null)
                      imageData.InstanceNumber = Convert.ToInt32(ds.GetConvertValue(patientElement));
                   patientElement = ds.FindFirstElement(null,
                                                       DicomTag.InstanceCreationTime,
                                                       true);
                   if (patientElement != null)
                      imageData.CaptureTime = Convert.ToDateTime(ds.GetConvertValue(patientElement));
                   _imageDataList.Add(imageData);
                   return true;
                }
                public MedicalViewerSeriesManager Load_James_CT_Localizer()
                {
                   string fileName = @"C:\Leadtools_DICOMDIR\Miller James\";
                   string studyInstanceUID = "1.3.12.2.1107.5.1.4.50772.30000009122208074910900000022";
                   string seriesInstanceUID = "1.3.12.2.1107.5.1.4.50772.30000009122208074910900000023";
                   return LoadSeries(fileName, studyInstanceUID, seriesInstanceUID, 1);
                }
                public MedicalViewerSeriesManager Load_James_CT()
                {
                   string fileName = @"C:\Leadtools_DICOMDIR\Miller James\";
                   string studyInstanceUID = "1.3.12.2.1107.5.1.4.50772.30000009122208074910900000022";
                   string seriesInstanceUID = "1.3.12.2.1107.5.1.4.50772.30000009122208215356200001997";
                   return LoadSeries(fileName, studyInstanceUID, seriesInstanceUID, 256);
                }
                // this will load the series specified by the seriesInstanceUID and studyInstanceUID from the file specified in fileName
                private MedicalViewerSeriesManager LoadSeries(string fileName, string studyInstanceUID, string seriesInstanceUID, int count)
                {
                   DicomEngine.Startup();
                   DicomDataSet ds = new DicomDataSet();
                   ds.Load(fileName + "DICOMDIR", DicomDataSetLoadFlags.None);
                   string directoryPath = fileName;
                   // Here the program will search for the study with the specified studyInstanceUID.
                   _studyElement = FindStudy(ds, studyInstanceUID);
                   // Here the program will search for the series with the specified seriesInstanceUID.
                   _seriesElement = FindSeries(ds, _studyElement, seriesInstanceUID);
                   // create a new instance of the MedicalViewerSeriesManager which will be used to sort the images, in order to create the correct 3D object.
                   _seriesManager = new MedicalViewerSeriesManager();
                   // create a an array of MedicalViewerImageData. this class will be used to save the frame information. these information will be used to sort the images.
                   _imageDataList = new List<MedicalViewerImageData>();
                   DicomDataSet dicomDataSet;
                   int imageIndex;
                   string imagePath;
                   int echoNumber = 0;
                   // Now the program will go through each frame in the series
                   imagePath = GetFirstImageName(ds, _seriesElement, directoryPath, out imageElement);
                   for (imageIndex = 0; imageIndex < count; imageIndex++)
                   {
                      try
                      {
                         // each image in the series will be loaded.
                         dicomDataSet = new DicomDataSet();
                         dicomDataSet.Load(imagePath, DicomDataSetLoadFlags.None);
                         // The program will load it's information and save it into a new instance of the class MedicalViewerImageData.
                         AddImageToImageArray(dicomDataSet, imageIndex, imagePath, out echoNumber);
                         dicomDataSet.Dispose();
                         // go to the next image.
                         imagePath = GetNextImageName(ds, directoryPath, ref imageElement);
                      }
                      catch (System.Exception exception)
                      {
                         System.Diagnostics.Debug.Assert(false, exception.Message);
                         throw;
                      }
                   }
                   // sort the images, based on its data.
                   _seriesManager.Sort(_imageDataList);
                   DicomEngine.Shutdown();
                   return _seriesManager;
                }
                void LoadLocalizer(MedicalViewerMultiCell cell)
                {
                   // start up the codes, which allows loading various images.
                   RasterCodecs _codecs = new RasterCodecs();
                   // Load the CT localizer.
                   output = Load_James_CT_Localizer();
                   cell.Image = _codecs.Load((string)output.Localizers[0].LocalizerData.Data, 0, CodecsLoadByteOrder.BgrOrGrayOrRomm, 1, 1);
                   // the following three lines are important to set. otherwise, wrong reference line restuls may occur.
                   // set the image position of the localizer.
                   cell.SetImagePosition(0, _seriesManager.Localizers[0].LocalizerData.ImagePosition, true);
                   // set the image orientation of the localizer.
                   cell.ImageOrientation = _seriesManager.Localizers[0].LocalizerData.ImageOrientationArray;
                   // set the pixel spacing of the localizer.
                   cell.PixelSpacing = _seriesManager.Localizers[0].LocalizerData.PixelSpacing;
                   // set the frame reference UID of the localizer. This will create a reference line between the series and the localizer if they have the same reference UID
                   cell.FrameOfReferenceUID = _seriesManager.Localizers[0].LocalizerData.FrameOfReferenceUID;
                }
                void Load2DCell(MedicalViewerMultiCell cell)
                {
                   // start up the codes, which allows loading various images.
                   RasterCodecs _codecs = new RasterCodecs();
                   // Load the CT DICOMDIR and return arranged stack of images.
                   output = Load_James_CT();
                   // loop through the images and add them one by one to the final image
                   RasterImage image = null;
                   int depth = output.Stacks[0].Items.Count;
                   int index;
                   for (index = 0; index < depth; index++)
                   {
                      if (image == null)
                      {
                         image = _codecs.Load((string)output.Stacks[0].Items[index].Data, 0, CodecsLoadByteOrder.BgrOrGrayOrRomm, 1, 1);
                      }
                      else
                         image.AddPage(_codecs.Load((string)output.Stacks[0].Items[index].Data, 0, CodecsLoadByteOrder.BgrOrGrayOrRomm, 1, 1));
                   }
                   cell.Image = image;
                   // the following lines are important to set. otherwise, wrong reference line results may occur.
                   for (index = 0; index < depth; index++)
                   {
                      // set the image position of the each frame.
                      cell.SetImagePosition(index, _seriesManager.Stacks[0].Items[index].ImagePosition, false);
                   }
                   // set the image orientation of the series, this is set once, since all the frames must have the same orientation value.
                   cell.ImageOrientation = _seriesManager.Stacks[0].Items[0].ImageOrientationArray;
                   // set the pixel spacing of the series, this is set once, since all the frames must have the same pixel spacing value.
                   cell.PixelSpacing = _seriesManager.Stacks[0].Items[0].PixelSpacing;
                   // set the frame reference UID of the series. This will create a reference line between the series and the localizer if they have the same reference UID
                   cell.FrameOfReferenceUID = _seriesManager.Stacks[0].Items[0].FrameOfReferenceUID;
                }
                
    
  17. Add the following at the end of the InitClass() method (this will create a new cell and fill it with a specified series:
    [Visual Basic]
                ' Create the cell that will hold the stack of images.
                Dim cell As MedicalViewerMultiCell = New MedicalViewerMultiCell()
                ' Load the stack of images.
                Load2DCell(cell)
                
    
    [C#]
                // Create the cell that will hold the stack of images.
                MedicalViewerMultiCell cell = new MedicalViewerMultiCell();
                // Load the stack of images.
                Load2DCell(cell);
                
    
  18. Add the following at the end of the InitClass() method (this will create a new cell and fill it with a single frame which is called a localizer):
    [Visual Basic]
                ' Create the cell that will hold the localizer.
                Dim localizerCell As MedicalViewerMultiCell = New MedicalViewerMultiCell()
                ' load the localizer
                LoadLocalizer(localizerCell)
                
    
    [C#]
                // Create the cell that will hold the localizer.
                MedicalViewerMultiCell localizerCell = new MedicalViewerMultiCell();
                // load the localizer
                LoadLocalizer(localizerCell);
                
    
  19. Now add both cells (the series cell and the localizer cell to the MedicalViewer), to do this add the following at the end of the InitClass():
    [Visual Basic]
                ' Add the multi frame cell above to the MedicalViewer.
                viewer.Cells.Add(cell)
                ' Add the localizer cell above to the MedicalViewer.
                viewer.Cells.Add(localizerCell)
                
    
    [C#]
                // Add the multi frame cell above to the MedicalViewer.
                viewer.Cells.Add(cell);
                // Add the localizer cell above to the MedicalViewer.
                viewer.Cells.Add(localizerCell);
                
    
  20. Finaly, you need to enable the reference line for both cell, to do this, simply add the following lines at the end of your InitClass() method:
    [Visual Basic]
                ' enable the reference line in the localizer image.
                cell.ReferenceLine.Enabled = True
                ' enable the reference line in the stack image.
                localizerCell.ReferenceLine.Enabled = True
                
    
    [C#]
                // enable the reference line in the localizer image.
                cell.ReferenceLine.Enabled = true;
                // enable the reference line in the stack image.
                localizerCell.ReferenceLine.Enabled = true;
                
    
  21. If you run the program now you will see two cells, one has a verical line drawn on it, and the other have a horizontal line drawn on it.