Usage of volumetric meshes

Hi everyone,

I am quite new to 3D slicer and haven’t figured out many of the function yet.
I found this blog post on volumetric mesh support and I would like to experiment with its capabilities.

Can someone might give me an explanation on how I get such a volumentric mesh? I always end up with an normal surface mesh.

Thank you,
Julian


Slicer version: 4.7.0-2017-06-26 r26137

There are several extensions that advertise the capability of generating a volume mesh, but I don’t know whether they are functional and/or maintained.

https://www.slicer.org/wiki/Documentation/Nightly/Extensions/CleaverExtension
https://www.slicer.org/wiki/Documentation/Nightly/Extensions/PBNRR

There are well-established tools outside of Slicer that can be used for volumetric mesh generation, such as TetGen and CGAL:

http://wias-berlin.de/software/tetgen/

Specifically for generating volumetric meshes from image data, you can look at iso2mesh, although it is not self-contained and you will need matlab/octave (I personally do not have any experience with this package):

http://iso2mesh.sourceforge.net/cgi-bin/index.cgi

and CGAL (there is a section of the manual of generating meshes from labeled image data, I don’t know if they provide any ready to use command line tools):

http://doc.cgal.org/latest/Mesh_3/index.html

Hi Julian,

I thought I would share my experience that I have had lately with volumetric meshing and include the problems I am having

I tried using cleaver with limited success. I had a lot of trouble with the extension initially. After I spoke with Andras Lasso I was able to get the meshing working. The main thing I did to get cleaver to work with my data was to create a label map with a value of 75 on the inside and -75 on the outside. I used simple filters to do the shifting and scaling.

2 notes on using cleaver: 1) the mesh did not contain tetrahedra as far as I could tell. Instead it contained 4 triangles representing the faces instead of tetrahedra. 2) the mesh was not aligned in physical space with the volumes.

The method I am currently working with is using vtkDataSetTriangleFilter with something like the following at the python interpreter

>>> import vtk
>>> dstFilter = vtk.vtkDataSetTriangleFilter()
>>> croppedScan = getNode("croppedScan")
>>> dstFilter.SetInputData(croppedScan.GetImageData())
>>> dstFilter.Update()
>>> mesh = dstFilter.GetOutput()
>>> modelNode = slicer.vtkMRMLModelNode()
>>> modelNode.SetAndObserveMesh(mesh)
>>> slicer.mrmlScene.AddNode(modelNode)

This creates a solid rectangular prism mesh, where each voxel is split into several tets. The nodes are labeled with the intensity of the scan.I was able to cut out regions of the mesh based on the intensity at the nodes using vtkThreshold.

I am having trouble labeling the tetrahedra with intensity. I wrote the following function to label the tetrahedra with intensity. After this processing step the meshes show up as having zero cells in the Models module. Further they are not visualized in the 3D scene. The vtk files written from these models appear to have the cell data. Does anyone have any thought on how to go about labeling tets in Slicer that allows visualization? Is there some problem with my approach?

def sampleNodeScalarOntoCellScalar(mesh):
    """

    :type mesh: vtkUnstructuredGrid
    """
    idList = vtk.vtkIdList()
    cells = mesh.GetCells()
    nCell = cells.GetNumberOfCells()

    scanIntensity = vtk.vtkFloatArray()
    scanIntensity.SetNumberOfComponents(1)
    scanIntensity.SetNumberOfValues(nCell)

    for cellIndex in range(nCell):
        mesh.GetCellPoints(cellIndex, idList)
        scalarArray = mesh.GetPointData().GetArray(0)
        meanScalar = 0
        numPoints = idList.GetNumberOfIds()
        for pointIndex in range(numPoints):
            meanScalar = meanScalar + scalarArray.GetValue(idList.GetId(pointIndex))


        meanScalar = meanScalar / numPoints
        scanIntensity.SetValue(cellIndex, meanScalar)

    mesh.GetCellData().SetScalars(scanIntensity)
    return scanIntensity

Thanks for the help!

Michael

1 Like

Have you tried the new Cleaver library? Does it still write volumetric meshes like this?

This is a bug in the CLI modules in the Cleaver extension. We did not see this before, because Slicer could not load volumetric meshes. It should be very easy to fix, but I would do it only after upgrading Cleaver extension to use latest Cleaver library.

To see if it is an error in how you are setting scalar data or how Slicer displays it, you can compute some scalars and verify visualization in Paraview, then save to file, load the file into Slicer, and see if it is displayed correctly. If you want to color by cells instead of by points then set cell array instead of point array (there was a small bug that prevented cell scalar display in Slicer, I’ll commit a fix for that later today).

@Michael_Hardisty I’ve added Segment Mesher extension that can generate volumetric meshes using Cleaver2 or Tetgen. See a bit more details in this topic: Convert 3D slicer into 3D solid body

Thanks for follow up. This enhancement should be helpful to our group.

Dear Michael,
Can you please post the screen shots of how you successfully got the tetrahedral mesh for geometry of interest.

Does it produces cube always even if the segmented label is provided and you want tetrahedral mesh for only that portion of image?

Regards,
Saima

Hi Saima,

I looked back at my notes and I don’t have any screenshots. We’ve moved in a different direction on this project. The vtk based method is essentially possible with code snippet in the thread. Are you referring to one of the other methods I had tried? Which method are you referring to? I am happy to help and can reproduce what I had done but want to make sure that I understand which method you are trying to use.

Michael

Dear Michael,
Thank you for your reply.

The problem is to get the volumetric mesh of brain from the cubic mesh generated through using segment mesher. The brain is inside the cube.

How do I achieve this?

How did you use the threshold to cut the unwanted regions of mesh based on intensity values?
how to get the intensity values?

Thank you

Regards,
Saima Safdar