LEADTOOLS Medical (Leadtools.MedicalViewer assembly)

SetOffset(Int32,Double,Double) Method

Show in webframe





A zero-based index of the sub-cell that contains the image that will have its offset changed.
The x coordinates that represents the new position of the image.
The y coordinates that represents the new position of the image.
Translates the image position according to the provided X and Y values.
Syntax
public void SetOffset( 
   int subCellIndex,
   double x,
   double y
)
'Declaration
 
Public Overloads Sub SetOffset( _
   ByVal subCellIndex As Integer, _
   ByVal x As Double, _
   ByVal y As Double _
) 
'Usage
 
Dim instance As MedicalViewerMultiCell
Dim subCellIndex As Integer
Dim x As Double
Dim y As Double
 
instance.SetOffset(subCellIndex, x, y)

            

            
public:
void SetOffset( 
   int subCellIndex,
   double x,
   double y
) 

Parameters

subCellIndex
A zero-based index of the sub-cell that contains the image that will have its offset changed.
x
The x coordinates that represents the new position of the image.
y
The y coordinates that represents the new position of the image.
Remarks
Example
        Imports Leadtools
        Imports Leadtools.Dicom
        Imports Leadtools.Medical3D
        Imports Leadtools.Codecs
        Imports Leadtools.MedicalViewer
        Imports Leadtools.Annotations
        Imports Leadtools.ImageProcessing.Core

        Private Class MedicalViewerWindowLevelAndOffsetForm : Inherits Form
            Private _medicalViewer As MedicalViewer
            Private _seriesManager As MedicalViewerSeriesManager
            Private windowLevelWidth As Integer
            Private windowLevelCenter As Integer
            Private offsetX As Double
            Private offsetY As Double


            Private Sub MedicalViewer_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)
                DicomEngine.Startup()
                Dim _codecs As RasterCodecs = New RasterCodecs()

                AddHandler SizeChanged, AddressOf MedicalViewer_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 MedicalViewerLocalizer_FormClosing
                cell.EnableLowMemoryUsage(2, count, imageInformation)
                cell.FitImageToCell = False

                ' add some actions that will be used to change the properties of the images inside the control.
                cell.AddAction(MedicalViewerActionType.WindowLevel)
                cell.AddAction(MedicalViewerActionType.Offset)

                ' 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.Offset, MedicalViewerMouseButtons.Right, MedicalViewerActionFlags.Active)

                cell.ReferenceLine.Enabled = True
                cell.ReferenceLine.Color = Color.Yellow
                cell.ShowCellBoundaries = True
                AddHandler cell.CellMouseClick, AddressOf cell_ResetCellMouseClick

                _medicalViewer.Cells.Add(cell)
                ' 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)

                cell.PixelSpacing = output.Stacks(0).PixelSpacing

                index = 0
                Do While index < count
                    cell.SetImagePosition(index, output.Stacks(0).Items(index).ImagePosition, (index = count - 1))
                    index += 1
                Loop
                cell.ImageOrientation = output.Stacks(0).Items(0).ImageOrientationArray
                cell.FrameOfReferenceUID = output.Stacks(0).Items(0).FrameOfReferenceUID

                cell.ScaleType = MedicalViewerScaleType.Dynamic

                cell.ActiveSubCell = cell.PageCount \ 2

                windowLevelWidth = cell.GetWindowLevelWidth(cell.ActiveSubCell)
                windowLevelCenter = cell.GetWindowLevelCenter(cell.ActiveSubCell)
                Dim point As Point2D = cell.GetOffset(cell.ActiveSubCell)
                offsetX = point.X
                offsetY = point.Y


                Controls.Add(_medicalViewer)
                _medicalViewer.Dock = DockStyle.Fill
                DicomEngine.Shutdown()
            End Sub

            Private Sub MedicalViewerLocalizer_FormClosing(ByVal sender As Object, ByVal e As FormClosingEventArgs)
            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

            Public ReadOnly Property Viewer() As MedicalViewer
                Get
                    Return _medicalViewer
                End Get
            End Property
            Private Sub cell_ResetCellMouseClick(ByVal sender As Object, ByVal e As MedicalViewerCellMouseEventArgs)
                If e.Button = MouseButtons.Middle Then
                    Dim cell As MedicalViewerMultiCell = (CType(sender, MedicalViewerMultiCell))

                    cell.SetWindowLevel(cell.ActiveSubCell, windowLevelWidth, windowLevelCenter)
                    cell.SetOffset(cell.ActiveSubCell, offsetX, offsetY)
                End If
            End Sub

        End Class
        Private Function GetMedicalViewerWindowLevelAndOffsetForm() As MedicalViewerWindowLevelAndOffsetForm
            MessageBox.Show("Left click to window level. " & Constants.vbLf & " right click to offset " & Constants.vbLf & " middle click to reset")
            Dim form As MedicalViewerSeriesManagerFrom = New MedicalViewerSeriesManagerFrom()
            Dim output As MedicalViewerSeriesManager = form.LoadJamesHead()

            Return New MedicalViewerWindowLevelAndOffsetForm(output)
        End Function

        ' This example changes the default window level value by decrease the width by 100. Then resets the images based on the new value.

        Public Sub MedicalViewerWindowLevelAndOffsetExample()
            Dim myForm As MedicalViewerWindowLevelAndOffsetForm = GetMedicalViewerWindowLevelAndOffsetForm()
            Dim medicalViewer As MedicalViewer = myForm.Viewer

            myForm.ShowDialog()
        End Sub      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;

      class MedicalViewerWindowLevelAndOffsetForm : Form
      {
         private MedicalViewer _medicalViewer;
         private MedicalViewerSeriesManager _seriesManager;
         private int width;
         private int center;
         private double offsetX;
         private double offsetY;


         void MedicalViewerLocalizer_SizeChanged(object sender, EventArgs e)
         {
            _medicalViewer.Size = new Size(this.ClientRectangle.Right, this.ClientRectangle.Bottom);
         }

         public MedicalViewerWindowLevelAndOffsetForm(MedicalViewerSeriesManager output)
         {
            DicomEngine.Startup();
            RasterCodecs _codecs = new RasterCodecs();

            this.SizeChanged += new EventHandler(MedicalViewerLocalizer_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(MedicalViewerLocalizer_FormClosing);
            cell.EnableLowMemoryUsage(2, count, imageInformation);
            cell.FitImageToCell = false;

            // add some actions that will be used to change the properties of the images inside the control.
            cell.AddAction(MedicalViewerActionType.WindowLevel);
            cell.AddAction(MedicalViewerActionType.Offset);

            // 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.Offset, MedicalViewerMouseButtons.Right, MedicalViewerActionFlags.Active);

            cell.ReferenceLine.Enabled = true;
            cell.ReferenceLine.Color = Color.Yellow;
            cell.ShowCellBoundaries = true;
            cell.CellMouseClick += new EventHandler<MedicalViewerCellMouseEventArgs>(cell_ResetCellMouseClick);

            _medicalViewer.Cells.Add(cell);
            // 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);

            cell.PixelSpacing = output.Stacks[0].PixelSpacing;

            for (index = 0; index < count; index++)
            {
               cell.SetImagePosition(index, output.Stacks[0].Items[index].ImagePosition, (index == count - 1));
            }
            cell.ImageOrientation = output.Stacks[0].Items[0].ImageOrientationArray;
            cell.FrameOfReferenceUID = output.Stacks[0].Items[0].FrameOfReferenceUID;

            cell.ScaleType = MedicalViewerScaleType.Dynamic;

            cell.ActiveSubCell = cell.PageCount / 2;

            width = cell.GetWindowLevelWidth(cell.ActiveSubCell);
            center = cell.GetWindowLevelCenter(cell.ActiveSubCell);
            Point2D point = cell.GetOffset(cell.ActiveSubCell);
            offsetX = point.X;
            offsetY = point.Y;


            Controls.Add(_medicalViewer);
            _medicalViewer.Dock = DockStyle.Fill;
            DicomEngine.Shutdown();
         }

         void MedicalViewerLocalizer_FormClosing(object sender, FormClosingEventArgs e)
         {
         }

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

         public MedicalViewer Viewer
         {
            get { return _medicalViewer; }
         }
         void cell_ResetCellMouseClick(object sender, MedicalViewerCellMouseEventArgs e)
         {
            if (e.Button == MouseButtons.Middle)
            {
               MedicalViewerMultiCell cell = ((MedicalViewerMultiCell)sender);
               cell.SetWindowLevel(cell.ActiveSubCell, width, center);
               cell.SetOffset(cell.ActiveSubCell, offsetX, offsetY);
            }
         }

      }
      MedicalViewerWindowLevelAndOffsetForm GetMedicalViewerWindowLevelAndOffsetForm()
      {
         MessageBox.Show("Left click to window level. \n right click to offset \n middle click to reset");
         MedicalViewerSeriesManagerFrom form = new MedicalViewerSeriesManagerFrom();
         MedicalViewerSeriesManager output = form.LoadJamesHead();

         return new MedicalViewerWindowLevelAndOffsetForm(output);
      }

      // This example changes the default window level value by decrease the width by 100. Then resets the images based on the new value.

      public void MedicalViewerWindowLevelAndOffsetExample()
      {
         MedicalViewerWindowLevelAndOffsetForm myForm = GetMedicalViewerWindowLevelAndOffsetForm();
         MedicalViewer medicalViewer = myForm.Viewer;

         myForm.ShowDialog();
      }
        Imports Leadtools
        Imports Leadtools.Dicom
        Imports Leadtools.Medical3D
        Imports Leadtools.Codecs
        Imports Leadtools.MedicalViewer
        Imports Leadtools.Annotations
        Imports Leadtools.ImageProcessing.Core

        Private Class MedicalViewerWindowLevelAndOffsetForm : Inherits Form
            Private _medicalViewer As MedicalViewer
            Private _seriesManager As MedicalViewerSeriesManager
            Private windowLevelWidth As Integer
            Private windowLevelCenter As Integer
            Private offsetX As Double
            Private offsetY As Double


            Private Sub MedicalViewer_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)
                DicomEngine.Startup()
                Dim _codecs As RasterCodecs = New RasterCodecs()

                AddHandler SizeChanged, AddressOf MedicalViewer_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 MedicalViewerLocalizer_FormClosing
                cell.EnableLowMemoryUsage(2, count, imageInformation)
                cell.FitImageToCell = False

                ' add some actions that will be used to change the properties of the images inside the control.
                cell.AddAction(MedicalViewerActionType.WindowLevel)
                cell.AddAction(MedicalViewerActionType.Offset)

                ' 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.Offset, MedicalViewerMouseButtons.Right, MedicalViewerActionFlags.Active)

                cell.ReferenceLine.Enabled = True
                cell.ReferenceLine.Color = Color.Yellow
                cell.ShowCellBoundaries = True
                AddHandler cell.CellMouseClick, AddressOf cell_ResetCellMouseClick

                _medicalViewer.Cells.Add(cell)
                ' 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)

                cell.PixelSpacing = output.Stacks(0).PixelSpacing

                index = 0
                Do While index < count
                    cell.SetImagePosition(index, output.Stacks(0).Items(index).ImagePosition, (index = count - 1))
                    index += 1
                Loop
                cell.ImageOrientation = output.Stacks(0).Items(0).ImageOrientationArray
                cell.FrameOfReferenceUID = output.Stacks(0).Items(0).FrameOfReferenceUID

                cell.ScaleType = MedicalViewerScaleType.Dynamic

                cell.ActiveSubCell = cell.PageCount \ 2

                windowLevelWidth = cell.GetWindowLevelWidth(cell.ActiveSubCell)
                windowLevelCenter = cell.GetWindowLevelCenter(cell.ActiveSubCell)
                Dim point As Point2D = cell.GetOffset(cell.ActiveSubCell)
                offsetX = point.X
                offsetY = point.Y


                Controls.Add(_medicalViewer)
                _medicalViewer.Dock = DockStyle.Fill
                DicomEngine.Shutdown()
            End Sub

            Private Sub MedicalViewerLocalizer_FormClosing(ByVal sender As Object, ByVal e As FormClosingEventArgs)
            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

            Public ReadOnly Property Viewer() As MedicalViewer
                Get
                    Return _medicalViewer
                End Get
            End Property
            Private Sub cell_ResetCellMouseClick(ByVal sender As Object, ByVal e As MedicalViewerCellMouseEventArgs)
                If e.Button = MouseButtons.Middle Then
                    Dim cell As MedicalViewerMultiCell = (CType(sender, MedicalViewerMultiCell))

                    cell.SetWindowLevel(cell.ActiveSubCell, windowLevelWidth, windowLevelCenter)
                    cell.SetOffset(cell.ActiveSubCell, offsetX, offsetY)
                End If
            End Sub

        End Class
        Private Function GetMedicalViewerWindowLevelAndOffsetForm() As MedicalViewerWindowLevelAndOffsetForm
            MessageBox.Show("Left click to window level. " & Constants.vbLf & " right click to offset " & Constants.vbLf & " middle click to reset")
            Dim form As MedicalViewerSeriesManagerFrom = New MedicalViewerSeriesManagerFrom()
            Dim output As MedicalViewerSeriesManager = form.LoadJamesHead()

            Return New MedicalViewerWindowLevelAndOffsetForm(output)
        End Function

        ' This example changes the default window level value by decrease the width by 100. Then resets the images based on the new value.

        Public Sub MedicalViewerWindowLevelAndOffsetExample()
            Dim myForm As MedicalViewerWindowLevelAndOffsetForm = GetMedicalViewerWindowLevelAndOffsetForm()
            Dim medicalViewer As MedicalViewer = myForm.Viewer

            myForm.ShowDialog()
        End Sub      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;

      class MedicalViewerWindowLevelAndOffsetForm : Form
      {
         private MedicalViewer _medicalViewer;
         private MedicalViewerSeriesManager _seriesManager;
         private int width;
         private int center;
         private double offsetX;
         private double offsetY;


         void MedicalViewerLocalizer_SizeChanged(object sender, EventArgs e)
         {
            _medicalViewer.Size = new Size(this.ClientRectangle.Right, this.ClientRectangle.Bottom);
         }

         public MedicalViewerWindowLevelAndOffsetForm(MedicalViewerSeriesManager output)
         {
            DicomEngine.Startup();
            RasterCodecs _codecs = new RasterCodecs();

            this.SizeChanged += new EventHandler(MedicalViewerLocalizer_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(MedicalViewerLocalizer_FormClosing);
            cell.EnableLowMemoryUsage(2, count, imageInformation);
            cell.FitImageToCell = false;

            // add some actions that will be used to change the properties of the images inside the control.
            cell.AddAction(MedicalViewerActionType.WindowLevel);
            cell.AddAction(MedicalViewerActionType.Offset);

            // 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.Offset, MedicalViewerMouseButtons.Right, MedicalViewerActionFlags.Active);

            cell.ReferenceLine.Enabled = true;
            cell.ReferenceLine.Color = Color.Yellow;
            cell.ShowCellBoundaries = true;
            cell.CellMouseClick += new EventHandler<MedicalViewerCellMouseEventArgs>(cell_ResetCellMouseClick);

            _medicalViewer.Cells.Add(cell);
            // 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);

            cell.PixelSpacing = output.Stacks[0].PixelSpacing;

            for (index = 0; index < count; index++)
            {
               cell.SetImagePosition(index, output.Stacks[0].Items[index].ImagePosition, (index == count - 1));
            }
            cell.ImageOrientation = output.Stacks[0].Items[0].ImageOrientationArray;
            cell.FrameOfReferenceUID = output.Stacks[0].Items[0].FrameOfReferenceUID;

            cell.ScaleType = MedicalViewerScaleType.Dynamic;

            cell.ActiveSubCell = cell.PageCount / 2;

            width = cell.GetWindowLevelWidth(cell.ActiveSubCell);
            center = cell.GetWindowLevelCenter(cell.ActiveSubCell);
            Point2D point = cell.GetOffset(cell.ActiveSubCell);
            offsetX = point.X;
            offsetY = point.Y;


            Controls.Add(_medicalViewer);
            _medicalViewer.Dock = DockStyle.Fill;
            DicomEngine.Shutdown();
         }

         void MedicalViewerLocalizer_FormClosing(object sender, FormClosingEventArgs e)
         {
         }

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

         public MedicalViewer Viewer
         {
            get { return _medicalViewer; }
         }
         void cell_ResetCellMouseClick(object sender, MedicalViewerCellMouseEventArgs e)
         {
            if (e.Button == MouseButtons.Middle)
            {
               MedicalViewerMultiCell cell = ((MedicalViewerMultiCell)sender);
               cell.SetWindowLevel(cell.ActiveSubCell, width, center);
               cell.SetOffset(cell.ActiveSubCell, offsetX, offsetY);
            }
         }

      }
      MedicalViewerWindowLevelAndOffsetForm GetMedicalViewerWindowLevelAndOffsetForm()
      {
         MessageBox.Show("Left click to window level. \n right click to offset \n middle click to reset");
         MedicalViewerSeriesManagerFrom form = new MedicalViewerSeriesManagerFrom();
         MedicalViewerSeriesManager output = form.LoadJamesHead();

         return new MedicalViewerWindowLevelAndOffsetForm(output);
      }

      // This example changes the default window level value by decrease the width by 100. Then resets the images based on the new value.

      public void MedicalViewerWindowLevelAndOffsetExample()
      {
         MedicalViewerWindowLevelAndOffsetForm myForm = GetMedicalViewerWindowLevelAndOffsetForm();
         MedicalViewer medicalViewer = myForm.Viewer;

         myForm.ShowDialog();
      }
      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;

      class MedicalViewerWindowLevelAndOffsetForm : Form
      {
         private MedicalViewer _medicalViewer;
         private MedicalViewerSeriesManager _seriesManager;
         private int width;
         private int center;
         private double offsetX;
         private double offsetY;


         void MedicalViewerLocalizer_SizeChanged(object sender, EventArgs e)
         {
            _medicalViewer.Size = new Size(this.ClientRectangle.Right, this.ClientRectangle.Bottom);
         }

         public MedicalViewerWindowLevelAndOffsetForm(MedicalViewerSeriesManager output)
         {
            DicomEngine.Startup();
            RasterCodecs _codecs = new RasterCodecs();

            this.SizeChanged += new EventHandler(MedicalViewerLocalizer_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(MedicalViewerLocalizer_FormClosing);
            cell.EnableLowMemoryUsage(2, count, imageInformation);
            cell.FitImageToCell = false;

            // add some actions that will be used to change the properties of the images inside the control.
            cell.AddAction(MedicalViewerActionType.WindowLevel);
            cell.AddAction(MedicalViewerActionType.Offset);

            // 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.Offset, MedicalViewerMouseButtons.Right, MedicalViewerActionFlags.Active);

            cell.ReferenceLine.Enabled = true;
            cell.ReferenceLine.Color = Color.Yellow;
            cell.ShowCellBoundaries = true;
            cell.CellMouseClick += new EventHandler<MedicalViewerCellMouseEventArgs>(cell_ResetCellMouseClick);

            _medicalViewer.Cells.Add(cell);
            // 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);

            cell.PixelSpacing = output.Stacks[0].PixelSpacing;

            for (index = 0; index < count; index++)
            {
               cell.SetImagePosition(index, output.Stacks[0].Items[index].ImagePosition, (index == count - 1));
            }
            cell.ImageOrientation = output.Stacks[0].Items[0].ImageOrientationArray;
            cell.FrameOfReferenceUID = output.Stacks[0].Items[0].FrameOfReferenceUID;

            cell.ScaleType = MedicalViewerScaleType.Dynamic;

            cell.ActiveSubCell = cell.PageCount / 2;

            width = cell.GetWindowLevelWidth(cell.ActiveSubCell);
            center = cell.GetWindowLevelCenter(cell.ActiveSubCell);
            Point2D point = cell.GetOffset(cell.ActiveSubCell);
            offsetX = point.X;
            offsetY = point.Y;


            Controls.Add(_medicalViewer);
            _medicalViewer.Dock = DockStyle.Fill;
            DicomEngine.Shutdown();
         }

         void MedicalViewerLocalizer_FormClosing(object sender, FormClosingEventArgs e)
         {
         }

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

         public MedicalViewer Viewer
         {
            get { return _medicalViewer; }
         }
         void cell_ResetCellMouseClick(object sender, MedicalViewerCellMouseEventArgs e)
         {
            if (e.Button == MouseButtons.Middle)
            {
               MedicalViewerMultiCell cell = ((MedicalViewerMultiCell)sender);
               cell.SetWindowLevel(cell.ActiveSubCell, width, center);
               cell.SetOffset(cell.ActiveSubCell, offsetX, offsetY);
            }
         }

      }
      MedicalViewerWindowLevelAndOffsetForm GetMedicalViewerWindowLevelAndOffsetForm()
      {
         MessageBox.Show("Left click to window level. \n right click to offset \n middle click to reset");
         MedicalViewerSeriesManagerFrom form = new MedicalViewerSeriesManagerFrom();
         MedicalViewerSeriesManager output = form.LoadJamesHead();

         return new MedicalViewerWindowLevelAndOffsetForm(output);
      }

      // This example changes the default window level value by decrease the width by 100. Then resets the images based on the new value.

      public void MedicalViewerWindowLevelAndOffsetExample()
      {
         MedicalViewerWindowLevelAndOffsetForm myForm = GetMedicalViewerWindowLevelAndOffsetForm();
         MedicalViewer medicalViewer = myForm.Viewer;

         myForm.ShowDialog();
      }
Requirements

Target Platforms

See Also

Reference

MedicalViewerMultiCell Class
MedicalViewerMultiCell Members
Overload List

 

 


Products | Support | Contact Us | Copyright Notices
© 2006-2014 All Rights Reserved. LEAD Technologies, Inc.

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