This tutorial teaches you how to to use the cut-plane and double cut-plane features to generate a slice out of a stack of images.
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.
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;
Private Sub InitClass() RasterSupport.SetLicense(RasterSupportType.Dicom, " Your Dicom Key") RasterSupport.SetLicense(RasterSupportType.Medical, "Your Medical Key") RasterSupport.SetLicense(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 ' 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[C#]
void InitClass() { RasterSupport.SetLicense(RasterSupportType.Dicom, " Your Dicom Key"); RasterSupport.SetLicense(RasterSupportType.Medical, "Your Medical Key"); RasterSupport.SetLicense(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; // 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.
Show() Update()[C#]
Show(); Update();
AddHandler cell.Data3DRequested, AddressOf Of MedicalViewerData3DRequestedEventArgs[C#]
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 SubC#
void cell_Data3DRequested(object sender, MedicalViewerData3DRequestedEventArgs e) { e.Succeed = Medical3DEngine.Provide3DInformation(e); }
AddHandler cell.Data3DFrameRequested, AddressOf Of MedicalViewer3DFrameRequestedEventArgs[C#]
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[C#]
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); }
' 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)[C#]
// 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.
Dim doubleCutLine As MedicalViewerDoublePlaneCutLine = new MedicalViewerDoublePlaneCutLine(firstCutLineCell, secondCutLineCell)[C#]
MedicalViewerDoublePlaneCutLine doubleCutLine = new MedicalViewerDoublePlaneCutLine(firstCutLineCell, secondCutLineCell);
cell.ReferenceLine.DoubleCutLines.Add(doubleCutLine)[C#]
cell.ReferenceLine.DoubleCutLines.Add(doubleCutLine);
Public Sub New() InitializeComponent() InitClass() End Sub Private Sub InitClass() RasterSupport.SetLicense(RasterSupportType.Dicom, " Your Dicom Key") RasterSupport.SetLicense(RasterSupportType.Medical, "Your Medical Key") RasterSupport.SetLicense(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 ' 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[C#]
public Form1() { InitializeComponent(); InitClass(); } void InitClass() { RasterSupport.SetLicense(RasterSupportType.Dicom, " Your Dicom Key"); RasterSupport.SetLicense(RasterSupportType.Medical, "Your Medical Key"); RasterSupport.SetLicense(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; // 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); }
Note: For more information on how to acquire the above unlock keys, please contact LEAD Technologies support.
Note: To view higher quality images, 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.