Export Volume Rendering as stack of PNG's. NOT stl's

Hi @pieper and @lassoan. My cs student (gunnar) and I have been returning to the work descibed in this thread earlier.

We are working to include multiple volumes and imported models to be sliced through SlicerFab. We’ve made progress and are so close but have a few questions:

-Can we transfer all models into volumes to interact with the volume display node?
-Should we add logic to also slice through models? If so how do we control the clipping plane through the python loadable modules? Your previous advise got use close but then we ran into uncharted territory finding the clipping plan module.
-Is there a display node that can hold both Models and Volumes?

Any thoughts?

Hi @Nicholas.jacobson -

I haven’t tried, but I’d say it depends on exactly what kind of models and what you want them to look like. You can load most models as segmentations, and then export them as labelmaps (Segmentations module) and convert those to scalar volumes (Volumes module). this would make them uniform slabs at each slice. If they are made different colors (different transfer functions) they could work with the multivolume renderer with the bitmap generator approach. This would be a very general solution I think.

As you can see in one of the screenshots above you can clip a slice through a model, but the interior is hollow and this may not be what you want. Better to do the multivolume approach I think.

No, these are distinct at the level we are discussing here.

If you have a specific example of a scene you are trying to print maybe we can give other suggestions.

Hi @pieper -
I am Nicks student working on getting this bitmap Generator working. I been hitting my head against the wall trying to figure out the right method for turning a model into a volume, here are the lines of code I have written in an attempt to do so:

self.delayDisplay('0')
modelNode = slicer.mrmlScene.GetFirstNodeByClass("vtkMRMLModelNode")

referenceVolumeNode = slicer.mrmlScene.AddNewNodeByClass("vtkMRMLScalarVolumeNode")
# Convert model to labelmap
seg = slicer.mrmlScene.AddNewNodeByClass("vtkMRMLSegmentationNode")
seg.SetReferenceImageGeometryParameterFromVolumeNode(referenceVolumeNode)
slicer.modules.segmentations.logic().ImportModelToSegmentationNode(modelNode, seg)
# seg.CreateBinaryLabelmapRepresentation()
outputLabelmapVolumeNode = slicer.mrmlScene.AddNewNodeByClass("vtkMRMLLabelMapVolumeNode")
slicer.modules.segmentations.logic().ExportVisibleSegmentsToLabelmapNode(seg, outputLabelmapVolumeNode, referenceVolumeNode)

slicer.modules.volumes.logic().CreateScalarVolumeFromVolume(slicer.mrmlScene, referenceVolumeNode, outputLabelmapVolumeNode)

slicer.mrmlScene.RemoveNode(outputLabelmapVolumeNode)

If you see anything wrong or know of a better way, please let me know.

This creates an empty volume node, but what you need is a reference volume that defines the geometry of the grid that you want to use to sample the STL model (e.g. the orientation, spacing, and dimensions of the resulting image data). You can either load an existing volume, or specify one programmatically like this. Otherwise I think the code should work.

Hi @pieper-
I have gone down a few rabbit hole and was looking if you have any advices, I was successfully able to turn a model into a segmentation into a scalar volume. I was wondering with this tool is there a programmatic way to merge all visible volumes into one volume and process that one volume through the bit map generator.

Thank you ahead of time

Yes, if you have the files as vtkImageData and they are the same geometry you can use vtkImageBlend or vtkImageMathematics to generate composite outputs. If they are different geometry you can make MRML nodes for them and use Slicer’s CLIs either to resample them, or do do math like add, mask, multiply etc. Hope that’s clear - if not can describe how you envision the result when you merge the volumes and maybe we can give more specific advice.