possible to export vtkvolume??

Dear All,

My 【object】to render a vtkvolume, take several snapshots accoring to renderer’s difference camera settings.

My 【requirement】is that, whenever I input a camera setting, I will get a snapshot immediatelly.

I noticed that processing from vtkimage to vtkvolume takes quite a long time, but vtkrenderer, vtkrenderwindow and export to PNG image take short amount of time. So, I think that if vtkvolume could be stored on local disk, then whenever I need to export PNG image, just simply read vtkvolume, render and done. The keypoint is that vtkvolume (vtkimage with light, opacity, shade and so on) could be saved on local disk. :upside_down_face:

I did research on this forum and internet, but could not find any method or examples to achieve this.
Please give me advice or suggestions. Any help is appreciated.
Thanks in advance!!

P.S.
Then I tried one other【method】, but it did not worke well. Here is what I have done:
use vtkVRMLExporter to export one bunch of renderer and renderwindow to a .wrl file on local disk, and in order to take snapshot, just read this .wrl file using vtkVRMLImporter, recover the render scene, and export PNG. But this method seems not working for vtkvolume (it works for vtkactor though), since I kept on getting NO ACTORS FOUND error

2023-08-09 11:00:40.580 ( 9.474s) [ ] vtkVRMLExporter.cxx:99 ERR| vtkVRMLExporter (000001A96A591070): no actors found for writing VRML file.

Please

The first rendering takes longer because the raycast mapper allocate and initializes some data structures, uploads the image to the GPU (if you use GPU mapper) or computes image gradient and space leaping data (if you use CPU mapper). It would be very hard if impossible to make these significantly farther by caching some data on the disk.

Instead, you can complete eliminate the long initial rendering time for subsequent rendering requests by keeping the rendering pipeline (do not edit the rendering process) until all the rendering results are generated. If the rendering parameters are coming from an external process then you can use some inter-process communication (such as web requests) to get the inputs and send back the results.

1 Like

Dear Dr @lassoan.
Thank you so much again!!
I tested your method, and it works!
Also the results testified your statement.

My test code is as following:

# get vtkvolume prepared before vtkrender
def compute_volume( vtk_image, vtk_mapper_settings ): 	 
    return vtk_volume

# input this vtkvolume and one camera configuration, and outputs one PNGimage
def image_snapshot( vtk_volume, camera ): 
    return PNGimage

if  __name__ == '__main__':
    vtk_volume = compute_volume( vtk_image, vtk_mapper_settings )
    list_cameras = [ camera1, camera2, camera3 ]

    for camera_i in list_cameras: # loop through all cameras
        image_snapshot( vtk_volume,  camera_i )

Time used for each function in for loop.
image

As it can be seen, the first rendering takes longer time than the rest (exactly as your statement).

1 Like