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.
- Open Visual Studio 2005 or later.
- From the File menu > choose Project.
- The new project dialog appears.
- From project types, expand Other languages node, and click on the Visual C# node.
- From the template list on the left side of the dialog, choose Windows Forms Application.
- Type the project name as "Creating Two Slices Out Of An Image Stack" in the Project Name field, and then choose OK.
- Select OK to create the project.
- From View menu > choose Solution explorer.
- On the Solution explorer tree, right click on the References node and select Add Reference.
- 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
Note: If you do not intend to load a DICOM file, then you don 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:
[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;
- In Form1 create a new method InitClass()
- Write the following 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 ' 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.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; // 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();
- If you run the program now, you will see a 2x2 layout with one slot filled with a multi-frame image.
- Add the following lines to the bottom of the InitClass function. This is necessary to view the progress bar:
[Visual Basic]Show() Update()
[C#]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:
[Visual Basic]AddHandler cell.Data3DRequested, AddressOf Of MedicalViewerData3DRequestedEventArgs
[C#]cell.Data3DRequested += new EventHandler<MedicalViewerData3DRequestedEventArgs>(cell_Data3DRequested);
Make the event handler procedure look as shown below:
[Visual Basic]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:
[Visual Basic]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):
[Visual Basic]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); }
-
Data3DRequested: Add the following line to the bottom of the InitClass Method:
- 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:
[Visual Basic]' 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. - 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:
[Visual Basic]Dim doubleCutLine As MedicalViewerDoublePlaneCutLine = new MedicalViewerDoublePlaneCutLine(firstCutLineCell, secondCutLineCell)
[C#]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:
[Visual Basic]cell.ReferenceLine.DoubleCutLines.Add(doubleCutLine)
[C#]cell.ReferenceLine.DoubleCutLines.Add(doubleCutLine);
- 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:
- Your main class should now look like below:
[Visual Basic]Public Sub New() InitializeComponent() InitClass() End Sub 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 ' 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.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; // 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: 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.