Creating and Saving a 3D Mesh Tutorial

This tutorial teaches you how to create a 3D object, which then can be converted to a mesh and saved.

  1. Start with the project you created in Creating A 3D Object.
  2. Run the program now and you will see a 2x2 layout with one of the slots filled with a 3D object. This 3D object is rendered using the VRT (Volume Rendering Technique).
  3. Convert the 3D object into a mesh. This is done by changing the volume type to SSD (Shaded Surface display). Add the following line at the end of the InitClass() method:

    VB
    ' Change the volume type of the rendered object to SSD 
    control3D.ObjectsContainer.VolumeType = Medical3DVolumeType.SSD 
    C#
    // Change the volume type of the rendered object to SSD 
    control3D.ObjectsContainer.VolumeType = Medical3DVolumeType.SSD; 

  4. You may want to add the following code before step (3) above as converting the object to mesh can be a time-consumer process.

    VB
    this.Show() 
    this.Update() 
    C#
    this.Show(); 
    this.Update(); 

  5. Now you have created a 3D Mesh. To change the surface, use the Medical3DObject.Slab.IsoThreshold property.

  6. Save the mesh. To save the mesh, simply add this line at the end of the InitClass() method:

    VB
    // Save the mesh under the name TestMesh. 
    control3D.ObjectsContainer.Objects[0].SSD.SaveMesh("C:\TestMesh.x") 
    C#
    // Save the mesh to a file 
    control3D.ObjectsContainer.Objects[0].SSD.SaveMesh(@"C:\TestMesh.x"); 

    Note: If you open C:\ through Windows Explorer, you will notice the mesh was saved as “TestMesh.x”.

  7. The initClass() method should look as follows:

    VB
    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 3D control that will hold the 3D object. 
         Dim control3D As Medical3DControl = New Medical3DControl() 
         control3D.AddAction(MedicalViewerActionType.WindowLevel) 
         control3D.SetAction(MedicalViewerActionType.WindowLevel, MedicalViewerMouseButtons.Left, MedicalViewerActionFlags.Active) 
         Dim object3D As Medical3DObject = New Medical3DObject() 
         ' Add the newly created 3D object to the control. 
         control3D.ObjectsContainer.Objects.Add(object3D) 
         object3D.Image = _codecs.Load("C:\Users\Public\Documents\LEADTOOLS Images\image1.dcm") 
         ' Add the cell above to the MedicalViewer. 
         viewer.Cells.Add(control3D) 
         Controls.Add(viewer) 
                          
         Me.Show() 
         Me.Update() 
                          
         ' Change the volume type of the rendered object to SSD 
         control3D.ObjectsContainer.VolumeType = Medical3DVolumeType.SSD 
                          
         ' Save the mesh to a file 
         control3D.ObjectsContainer.Objects(0).SSD.SaveMesh("C:\TestMesh.x") 
    End Sub 
    C#
    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 3D control that will hold the 3D object. 
         Medical3DControl control3D = new Medical3DControl(); 
         control3D.AddAction(MedicalViewerActionType.WindowLevel); 
         control3D.SetAction(MedicalViewerActionType.WindowLevel, MedicalViewerMouseButtons.Left, MedicalViewerActionFlags.Active); 
         Medical3DObject object3D = new Medical3DObject(); 
         // Add the newly created 3D object to the control. 
         control3D.ObjectsContainer.Objects.Add(object3D); 
         object3D.Image = _codecs.Load(@"C:\Users\Public\Documents\LEADTOOLS Images\image1.dcm"); 
         // Add the cell above to the MedicalViewer. 
         viewer.Cells.Add(control3D); 
         Controls.Add(viewer); 
                          
         this.Show(); 
         this.Update(); 
                          
         // Change the volume type of the rendered object to SSD 
         control3D.ObjectsContainer.VolumeType = Medical3DVolumeType.SSD; 
                          
         // Save the mesh to a file 
         control3D.ObjectsContainer.Objects[0].SSD.SaveMesh(@"C:\TestMesh.x"); 
    } 

  8. Run the program and you should see a 2X2 layout with one of the slots filled with a 3D object. The 3D object is rendered using the SSD (Shaded Surface display).

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.

Help Version 20.0.2020.4.3
Products | Support | Contact Us | Intellectual Property Notices
© 1991-2020 LEAD Technologies, Inc. All Rights Reserved.

LEADTOOLS Imaging, Medical, and Document