I’m a beginner of VTK. I want to display the volume data of a lung which will be changed using some volume deformation algorithm.
Frist, I use one thread to open the vtk context, and another thread to perform deformation. The problem is how to update the vtk render results when the volume is changed by another thread. We use a timer just like the demo ‘calldata’(https://lorensen.github.io/VTKExamples/site/Cxx/Interaction/CallData/). In the callback function, I first check if the volume data is modified by the other thread. Only the volumedata changed, we try to update the image.
Second, I introduce the way I used. I use vtkProgrammableSource and source->SetExecuteMethod(update_volume, source). The function “update_volume” will copy data from the other thread. In the callback function which last paragraph mentioned,
when need to update, the program will execute “program_source->Modified()” and “vtkRenderWindowInteractor->render()”.
My problem is that the function “render” is two slow and will cost 13 seconds.Do you have other way to achieve this effect？
This is my Pseudocode.
We would be happy to help, but you would need to be much more specific about what you do and what would you like to achieve.
Thank you. I re-describe my problem. This may be more specific.
My method is very similar to the demo ‘calldata’. The difference is that I use the ProgrammableSource and the demo use a customized class ‘vtkMyTestFilter’. Moreover, the demo just cout the current number . It doesn’t change the data and show how to update the image.
You cannot modify a VTK object from another thread while rendering it on another. You need to use synchronization objects to block the rendering thread while updating it from the processing thread, otherwise your application will crash or behave unpredictably.
I don’t know how you use vtkProgrammableSource to apply deformtion field, but there are much simpler and faster ways. For example, you can use vtkImageReslice filter to deform volumes and vtkTransformPolyDataFilter to deform surface meshes.
The method I’m using currently is that updating the data in programmable source and render again along the pipline ‘source->mapper->volume->renderer->renderwindow’. The time is same as the time first render in the main function spends. Now I want to know if it is very slow that rendering a volume(dims: 512*512*383) spends 9.4 seconds using vtkGPUVolumeRayCastMapper(NVIDIA TITAN X). If this process cannot be faster, I will try to take other methods to deform the image.
Rendering should not take more than a few ten milliseconds, but maybe even less than that. Most probably your programmable filter is really slow. Instead, use a filter developed for that specific task. You can use vtkImageReslice filter to deform an image.
I will try to use vtkImageReslice to deform the image. But I’m still confused that why I render a volume so slowly.Can you run this demo(https://lorensen.github.io/VTKExamples/site/Cxx/Medical/MedicalDemo4/)? In this demo, I spend 2.65s. If I replace ‘vtkFixedPointVolumeRayCastMapper’ with ‘vtkGPUVolumeRayCastMapper’ , the time will become 0.75s .
So I want to know what is the normal time.
Thank you Andras.
Assuming that you work with average-size volumes (few-hundred voxels along each axis, 8/16-bit integer) image warping may take several seconds on CPU; and volume transfer to GPU and rendering on GPU should take a few ten milliseconds. If you want to warp images more quickly then you can implement it on the GPU by customizing shader code in the GPU mapper (you don’t even need to modify VTK, as it supports very flexible shader replacements).
See the bottom video here for an example: https://www.na-mic.org/wiki/Project_Week_25/Next_Generation_GPU_Volume_Rendering