Render time in Slicer vs in python code

I am trying to generate DRR of a CT using python code. I am also using Slicer to get an idea of the approximate idea of the transfer function.

I observered that just ther rendering part of my code (only the line renWin.Render()) takes about 4 seconds while the Slicer rendering seems almost instantaneous.

Am I missing something over here?
Please let me know any additional information that you need. I am not exactly sure what all is required to debug this.

Tejas (2.7 KB)

It could be the data type of the image data. Some DICOM readers convert CT data to float, which might slow down the GPU. I’m fairly certain that Slicer would use short or ushort for DICOM CT. If the data is float, then check the range to see if you can safely cast to ushort.

1 Like

Damn David! You rock! That worked like a charm! My rendering time went to 0.8 secs from 4.1 secs just by changing double to short.

Thanks a lot :slight_smile:

Wow, I did not know that this could make such a difference. I would be interested in what your rendering pipeline looks like @tzodge. Are you using vtkGPUVolumeRayCastMapper?

The reason I’m asking is that we are doing rendering of float data in our application, but hearing this I’m wondering whether we should possibly convert to ushort prior to rendering (our data range would permit it).

Hey Elvis I won’t be able to share the entire codebase as it’s a funded project. But I can share the specific code snippet.

I am doing some processing in numpy and then converting the voccels back into vtkImageData. This is how I do it :). Hope it helps.

def imageData_from_voccel_numpy(imageData, voccel_np):
    depthArray = numpy_to_vtk(voccel_np.flatten(order='F'), deep=True, array_type=vtk.VTK_SHORT)
    return imageData  

Also, I am using vtkSmartVolumeMapper. I found that for my case, changing volume mapper did not significanlty affect the renderring time.

Thanks @tzodge, if you’re using vtkSmartVolumeMapper that probably means it’ll use a vtkGPUVolumeRayCastMapper under the hood if a GPU is available.

I think I’ll do some experiments with converting to short in our application.

1 Like