Convert unstructured grid model to volume

Hi,
I tried loading the volumetric mesh (vtkUnstructuredGrid) by using both the interface Load Data as Volume and using “slicer.util.loadVolume(’/path/to/file’)” on the Python interactor to no avail. Slicer simply doesn’t load it up. However, loading it as Model would always work. How do I load it as Volume?

Here’s a sample unstructuredgrid below:


vtk DataFile Version 3.0

2D scalar data
ASCII

DATASET UNSTRUCTURED_GRID
POINTS 18 float
0 0 2
1 0 2
1 1 2
0 1 2
2 0 2
3 0 2
3 1 2
2 1 2
4 5 6
2 2 4
4 4 4
6 5 2
7 2 4
3 4 2
2 4 6
1 3 5
2 9 8
8 7 5

CELLS 4 44
10 0 1 2 8 9 4 5 13 12 11
10 0 2 3 15 16 4 6 1 17 10
10 1 4 2 9 10 11 12 13 14 16
10 9 8 7 6 5 4 3 2 1 0

CELL_TYPES 4
24
24
24
24

Surface and volumetric meshes are represented in Slicer as model nodes. You can convert a volumetric mesh to volume by sampling the mesh at each voxel using vtkProbeFilter. Here is a complete example of how to do that: https://github.com/lassoan/SlicerNotebooks/blob/master/UnstructuredGridToVolume.ipynb

4 Likes

I was able to make it work thanks to your help. One thing I noticed was that the vtkUnstructuredGrid mesh must have CELL_DATA and POINT_DATA for Slicer to work correctly. I’m a beginner at vtk in general, so I guess my question would be which part of your code requires those two pieces of data? Or does volumetric mesh in general needs to have those in Slicer? I was able to generate volumes without those in vtkpython on conda and Paraview. Thanks a lot Andras!

1 Like

Maybe vtkProbeFilter specifically needs cell or point data (I don’t think you need both). You can convert between point and cell data as needed using vtkPointDataToCellData and vtkCellDataToPointData.

hi this page has been taken down. would you mind reuploading it, im having a similar issue

A post was split to a new topic: Convert mesh to volume