Using `vtkStructuredGrid` in Slicer


Just wondering does Slicer support vtkStructuredGrid? I can’t find any information on that

Working directly with structured grids could be hard because I think most VTK filters and mappers do not support it.

Would you like to manage images with varying spacing? Slicer supports that via storing an image with uniform spacing and applying a non-linear transform that moves each slice to the correct physical location.

You can also convert your structured grid to an unstructured grid (volumetric mesh) with scalar value associated with each point. Cross-sections can be displayed in slice views and outer surface (some internal surfaces as well, if clipping planes are used) can be displayed in 3D views.

1 Like

Thank you for response,

I’m still struggling with volumetric data that is arbitrary spaced in the XY plane but has uniform Z spacings
Even vtkStructuredGrid is not a good choice for me.

Didn’t think about that, probably I need to investigate nonlinear transformations.

Unstructured grid is a possible solution but has a drawback that it consumes RAM. I think I will implement that for visualizing relatively small datasets (I also like vtkExplicitStructuredGrid but that is not a nearest task).

But for general case when the data is pretty big I created custom dataset vtkRaisedGrid that stores only XY points (triangulated with vtkDelaunay2D) and Z spacings vector. I guess it is partly implicit grid. To display the data in Slicer I interpolate point scalars on vtkImageData via vtkProbeFilter. It takes some time to do that but I hope when working in release mode with TBB enabled the perfomance will be few times higher.

The problem has arised when I started testing it on real data and I’ve got some bugs when probing my custom dataset on vtkImageData:

I’ve looked to the source code of vtkProbeFilter and it seems that when probing on vtkImageData it works very efficiently: for each cell of source data it probes all cells (or points I don’t remember) of image data that are within that source cell. Most likely the problem is in my implementation of my dataset or the way vtkDelaunay2D works.

If the topology of your data set is the same as an image volume (you can index points using IJK coordinates) and just geometry is different (the physical coordinate of each point is arbitrary) then using an image data with a warping transform should work well. You can specify physical location of each point using a vtkOrientedGridTransform.

1 Like

Thank you for the help,

Unfortunately in general case I can’t use IJK indexing. I will keep in mind vtkOrientedGridTransform

But I have found bug in my custom vtk dataset: the method MyDataset::GetCell() that is supposed to be thread safe was not that. So I fixed that and now vtk probing from my dataset on vtkImageData works pretty fast with TBB enabled.

Also I implemented loading my data using vtkUnstructuredGrid.
If the actual size of my data (scalar values) is 20 Mb, then Clipping Planes (from Models module) is very slow (probably 30-40 sec to clip) in DEBUG mode. Though that is not the primary task for now, I mostly rely on vtkImageData

Performance in debug mode can be 10-100x slower, so don’t make any judgement based on debug-mode tests. Nevertheless, if you have dense data then resampling on a regular grid (resulting in a vtkImageData) makes a lot of sense, as it can make processing and visualization magnitudes faster.

1 Like