This tutorial teaches you how to use the cut-plane and double cut-plane features to generate a slice out of a stack of images.
On the Add Reference dialog, select the Browse tab, and add the following dll's.
Note: If you do not intend to load a DICOM file, then you do not need to add Leadtools.Dicom.dll.
Note: If you encounter an "Invalid File Format" or "Feature Not Supported" exception, please refer to the topic Invalid File Format/Feature Not Supported.
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:
Imports Leadtools
Imports Leadtools.Codecs
Imports Leadtools.MedicalViewer
Imports Leadtools.Medical3D
Imports Leadtools.Dicom
using Leadtools;
using Leadtools.Codecs;
using Leadtools.MedicalViewer;
using Leadtools.Medical3D;
using Leadtools.Dicom;
In Form1 create a new method InitClass()
Write the following in the InitClass() method:
Private Sub InitClass()
Dim MY_LICENSE_FILE As String = "d:\temp\TestLic.lic"
' Unlock DICOM support
Dim MY_DicomDEVELOPER_KEY As String = "xyz123abc"
RasterSupport.SetLicense(MY_LICENSE_FILE, MY_DicomDEVELOPER_KEY);
' Unlock Medical support
Dim MY_MedicalDEVELOPER_KEY As String = "abc123xyz"
RasterSupport.SetLicense(MY_LICENSE_FILE, MY_MedicalDEVELOPER_KEY);
' Unlock Medical 3D support
Dim MY_3DDEVELOPER_KEY As String = "123xyzabc"
RasterSupport.SetLicense(MY_LICENSE_FILE, MY_3DDEVELOPER_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
' Create the cell that will hold the stack of images.
Dim cell As MedicalViewerMultiCell = New MedicalViewerMultiCell()
' Add the cell above to the MedicalViewer.
viewer.Cells.Add(cell)
cell.Image = _codecs.Load("C:\Users\Public\Documents\LEADTOOLS Images\image1.dcm")
' Add the viewer as a child to the form.
Me.Controls.Add(viewer)
End Sub
void InitClass()
{
string MY_LICENSE_FILE = "d:\\temp\\TestLic.lic";
// Unlock DICOM support
string MY_DicomDEVELOPER_KEY = "xyz123abc";
RasterSupport.SetLicense(MY_LICENSE_FILE, MY_DicomDEVELOPER_KEY);
// Unlock Medical support
string MY_MedicalDEVELOPER_KEY = "abc123xyz";
RasterSupport.SetLicense(MY_LICENSE_FILE, MY_MedicalDEVELOPER_KEY);
// Unlock Medical 3D support
string MY_3DDEVELOPER_KEY = "123xyzabc";
RasterSupport.SetLicense(MY_LICENSE_FILE, MY_3DDEVELOPER_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;
// Create the cell that will hold the stack of images.
MedicalViewerMultiCell cell = new MedicalViewerMultiCell();
// Add the cell above to the MedicalViewer.
viewer.Cells.Add(cell);
cell.Image = _codecs.Load(@"C:\Users\Public\Documents\LEADTOOLS Images\image1.dcm");
// Add the viewer as a child to the form.
this.Controls.Add(viewer);
}
Note: You may need to change the above path to point to "image1.dcm" located in the LEADTOOLS images directory.
Call the InitClass method from inside the Form1 constructor, and place the call after InitializeComponent();
Add the following lines to the bottom of the InitClass function. This is necessary to view the progress bar:
Show()
Update()
Show();
Update();
Register two events before using the cut-line feature. The two events are:
Data3DRequested: Add the following line to the bottom of the InitClass Method:
AddHandler cell.Data3DRequested, AddressOf Of MedicalViewerData3DRequestedEventArgs
cell.Data3DRequested += new EventHandler<MedicalViewerData3DRequestedEventArgs>(cell_Data3DRequested);
Make the event handler procedure look as shown below:
Private Sub cell_Data3DRequested(ByVal sender As Object, ByVal e As MedicalViewerData3DRequestedEventArgs)
e.Succeed = Medical3DEngine.Provide3DInformation(e)
End Sub
C#
void cell_Data3DRequested(object sender, MedicalViewerData3DRequestedEventArgs e)
{
e.Succeed = Medical3DEngine.Provide3DInformation(e);
}
Data3DFrameRequested: Add the following line to the bottom of the InitClass method:
AddHandler cell.Data3DFrameRequested, AddressOf Of MedicalViewer3DFrameRequestedEventArgs
cell.Data3DFrameRequested += new EventHandler<MedicalViewer3DFrameRequestedEventArgs>(cell_Data3DFrameRequested);
Make the event handler procedure look like as shown below (You may need to change the file name based on the file name you chose in the previous steps):
Private Sub cell_Data3DFrameRequested(ByVal sender As Object, ByVal e As MedicalViewer3DFrameRequestedEventArgs)
' Create a new instance of the Codecs class, which will be used to load the images.
Dim _codecs As RasterCodecs = New RasterCodecs()
' This line loads the image with the desired frame index (e.ImageIndex) and assigns it to the argument parameter Image.
e.Image = _codecs.Load("C:\Users\Public\Documents\LEADTOOLS Images\image1.dcm", 0, CodecsLoadByteOrder.BgrOrGray, e.ImageIndex + 1, e.ImageIndex + 1)
End Sub
void cell_Data3DFrameRequested(object sender, MedicalViewer3DFrameRequestedEventArgs e)
{
// Create a new instance of the Codecs class, which will be used to load the images.
RasterCodecs _codecs = new RasterCodecs();
// This line loads the image with the desired frame index (e.ImageIndex) and assigns it to the argument parameter Image.
e.Image = _codecs.Load(@"C:\Users\Public\Documents\LEADTOOLS Images\image1.dcm", 0, CodecsLoadByteOrder.BgrOrGray, e.ImageIndex + 1, e.ImageIndex + 1);
}
Add a cut-line or a double cut-line. For this demonstration, let us add a double cut-line as follows:
Create two new instances of the MedicalViewerCell and add it to the MedicalViewer. To do this, add the following lines to the bottom of the InitClass method:
' Creating a double cut-line: The double cut-line consist of two cut-lines. For each one, you will need to create a cell.
MedicalViewerCell firstCutLineCell = new MedicalViewerCell()
MedicalViewerCell secondCutLineCell = new MedicalViewerCell()
' add both of the instances to the MedicalViewer instance.
viewer.Cells.Add(firstCutLineCell)
viewer.Cells.Add(secondCutLineCell)
// Creating a double cut-line: The double cut-line consist of two cut-lines. For each one, you will need to create a cell.
MedicalViewerCell firstCutLineCell = new MedicalViewerCell();
MedicalViewerCell secondCutLineCell = new MedicalViewerCell();
// add both of the instances to the MedicalViewer instance.
viewer.Cells.Add(firstCutLineCell);
viewer.Cells.Add(secondCutLineCell);
These instances will be used to view the double cut-lines output images.
Create a new instance of the MedicalViewerDoublePlaneCutLine and add the two cells above through the constructor parameters. To do this, add the following line at the bottom of the InitClass method:
Dim doubleCutLine As MedicalViewerDoublePlaneCutLine = new MedicalViewerDoublePlaneCutLine(firstCutLineCell, secondCutLineCell)
MedicalViewerDoublePlaneCutLine doubleCutLine = new MedicalViewerDoublePlaneCutLine(firstCutLineCell, secondCutLineCell);
Finally, add the MedicalViewerDoublePlaneCutLine object created above to the DoubleCutLine collection of the cell with the stack of images. To do this, add the following line at the bottom of the InitClass method:
cell.ReferenceLine.DoubleCutLines.Add(doubleCutLine)
cell.ReferenceLine.DoubleCutLines.Add(doubleCutLine);
Your main class should now look like below:
Public Sub New()
InitializeComponent()
InitClass()
End Sub
Private Sub InitClass()
Dim MY_LICENSE_FILE As String = "d:\temp\TestLic.lic"
' Unlock DICOM support
Dim MY_DicomDEVELOPER_KEY As String = "xyz123abc"
RasterSupport.SetLicense(MY_LICENSE_FILE, MY_DicomDEVELOPER_KEY);
' Unlock Medical support
Dim MY_MedicalDEVELOPER_KEY As String = "abc123xyz"
RasterSupport.SetLicense(MY_LICENSE_FILE, MY_MedicalDEVELOPER_KEY);
' Unlock Medical 3D support
Dim MY_3DDEVELOPER_KEY As String = "123xyzabc"
RasterSupport.SetLicense(MY_LICENSE_FILE, MY_3DDEVELOPER_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
' Create the cell that will hold the stack of images.
Dim cell As MedicalViewerMultiCell = New MedicalViewerMultiCell()
' Add the cell above to the MedicalViewer.
viewer.Cells.Add(cell)
cell.Image = _codecs.Load("C:\Users\Public\Documents\LEADTOOLS Images\image1.dcm")
' Add the viewer as a child to the form.
Me.Controls.Add(viewer)
Show()
Update()
AddHandler cell.Data3DRequested, AddressOf Of MedicalViewerData3DRequestedEventArgs
AddHandler cell.Data3DFrameRequested, AddressOf Of MedicalViewer3DFrameRequestedEventArgs
' Creating a double cut-line: The double cut-line consist of two cut-lines. For each one, you will need to create a cell.
Dim firstCutLineCell As MedicalViewerCell = New MedicalViewerCell()
Dim secondCutLineCell As MedicalViewerCell = New MedicalViewerCell()
' add both of the instances to the MedicalViewer instance.
viewer.Cells.Add(firstCutLineCell)
viewer.Cells.Add(secondCutLineCell)
Dim doubleCutLine As MedicalViewerDoublePlaneCutLine = New MedicalViewerDoublePlaneCutLine(firstCutLineCell, secondCutLineCell)
cell.ReferenceLine.DoubleCutLines.Add(doubleCutLine)
End Sub
Private Sub cell_Data3DRequested(ByVal sender As Object, ByVal e As MedicalViewerData3DRequestedEventArgs)
e.Succeed = Medical3DEngine.Provide3DInformation(e)
End Sub
Private Sub cell_Data3DFrameRequested(ByVal sender As Object, ByVal e As MedicalViewer3DFrameRequestedEventArgs)
' Create a new instance of the Codecs class, which will be used to load the images.
Dim _codecs As RasterCodecs = New RasterCodecs()
' This line loads the image with the desired frame index (e.ImageIndex) and assigns it to the argument parameter Image.
e.Image = _codecs.Load("C:\Users\Public\Documents\LEADTOOLS Images\image1.dcm", 0, CodecsLoadByteOrder.BgrOrGray, e.ImageIndex + 1, e.ImageIndex + 1)
End Sub
public Form1()
{
InitializeComponent();
InitClass();
}
void InitClass()
{
string MY_LICENSE_FILE = "d:\\temp\\TestLic.lic";
// Unlock DICOM support
string MY_DicomDEVELOPER_KEY = "xyz123abc";
RasterSupport.SetLicense(MY_LICENSE_FILE, MY_DicomDEVELOPER_KEY);
// Unlock Medical support
string MY_MedicalDEVELOPER_KEY = "abc123xyz";
RasterSupport.SetLicense(MY_LICENSE_FILE, MY_MedicalDEVELOPER_KEY);
// Unlock Medical 3D support
string MY_3DDEVELOPER_KEY = "123xyzabc";
RasterSupport.SetLicense(MY_LICENSE_FILE, MY_3DDEVELOPER_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;
// Create the cell that will hold the stack of images.
MedicalViewerMultiCell cell = new MedicalViewerMultiCell();
// Add the cell above to the MedicalViewer.
viewer.Cells.Add(cell);
cell.Image = _codecs.Load(@"C:\Users\Public\Documents\LEADTOOLS Images\image1.dcm");
// Add the viewer as a child to the form.
this.Controls.Add(viewer);
Show();
Update();
cell.Data3DRequested += new EventHandler<MedicalViewerData3DRequestedEventArgs>(cell_Data3DRequested);
cell.Data3DFrameRequested += new EventHandler<MedicalViewer3DFrameRequestedEventArgs>(cell_Data3DFrameRequested);
// Creating a double cut-line: The double cut-line consist of two cut-lines. For each one, you will need to create a cell.
MedicalViewerCell firstCutLineCell = new MedicalViewerCell();
MedicalViewerCell secondCutLineCell = new MedicalViewerCell();
// add both of the instances to the MedicalViewer instance.
viewer.Cells.Add(firstCutLineCell);
viewer.Cells.Add(secondCutLineCell);
MedicalViewerDoublePlaneCutLine doubleCutLine = new MedicalViewerDoublePlaneCutLine(firstCutLineCell, secondCutLineCell);
cell.ReferenceLine.DoubleCutLines.Add(doubleCutLine);
}
void cell_Data3DRequested(object sender, MedicalViewerData3DRequestedEventArgs e)
{
e.Succeed = Medical3DEngine.Provide3DInformation(e);
}
void cell_Data3DFrameRequested(object sender, MedicalViewer3DFrameRequestedEventArgs e)
{
// Create a new instance of the Codecs class, which will be used to load the images.
RasterCodecs _codecs = new RasterCodecs();
// This line loads the image with the desired frame index (e.ImageIndex) and assigns it to the argument parameter Image.
e.Image = _codecs.Load(@"C:\Users\Public\Documents\LEADTOOLS Images\image1.dcm", 0, CodecsLoadByteOrder.BgrOrGray, e.ImageIndex + 1, e.ImageIndex + 1);
}
Run the application. If you did everything correctly, you should see three cells: One with a cross line (the double cut-line) and the two cells that represent the generated images.
Note: For more information on how to acquire the above unlock keys, please contact LEAD Technologies support.
Note: Now you will need to have DICOMDIR files for the next step. You can download a sample from our site. Download the file from here (Download chest_ct_compressed_subset_for_3d_tutorial.zip), and extract the file to "C:\Leadtools_DICOMDIR". For more information on building 3D objects from a DICOMDIR, please see Loading a DICOMDIR To Create a 3D Object.