[VTK.js] Render volume as separate, togglable surfaces

I have a Niftii file for a head model that I read and convert to a vtkImage. I render this volume as a surface using ImageMarchingCubes, WindowedSincPolyDataFilter and PolyDataNormals since I need to apply smoothing. All of this works as expected, and when I apply transparency to the actor I can see separate surfaces for the different tissue types of the brain (bone, white matter, grey matter, …).

What I want to be able to do right now is use toggles to show and hide these different types of tissue. Every tissue type will have a toggle and depending on what toggles are active, the render window will render the active tissue types as a surface.

The way I see it, I need different actors where every actor has image data representing one of the tissue types. Currently I can get this working by creating a loop based on the range of the image data’s scalar values, and for every iteration (that corresponds to a scalar value and thus a tissue type) create new image data by taking the original image data’s scalar values and removing the values that do not correspond to the current iteration’s value. For example, take the following scalar values:
[0, 1, 2, 3, 4, 5]
I take the range ([0, 5]), loop through this range, and create new scalar values for every iteration. For the iteration with index 1 I end up with the following array:
[0, 1, 0, 0, 0, 0]

This works but, as you can imagine, is very slow since I have to replace values in an array containing over 3 million values for a total of 6 times AND afterwards smooth the created volumes. I feel like there’s a better way to do this but I cannot figure it out. Can anyone point me in the right direction?


The VTK version of ImageMarchingCubes supports multiple isocontours, but the vtk.js one does not yet support such. If you are loading remote data and can preprocess, then I would preprocess your volumes into surfaces and serve them to the viewer. Otherwise, if you are looking to extract surfaces purely on the client, then it may be useful to see if VTK’s ImageMarchingCubes implementation with multiple iso values can at least speed up that portion of the process.

Hi @Forrest

Thank you for your reply. Preprocessing remotely seems like a good way forward, so I’ll look into that. I’ll also check if there’s an issue on Github to add support for multiple isocontours and/or what the progress is on that.