multi vtkVolume rendering problem

Hi, vtk experts.
My app can render a vtkVolume from a CT Image, which contain brain vessel and bone. As the first 2 pictures shows, the vessel and bone can be rendered correctly alone. If the two volumes have been rendered(set visibility true) at the same time, the result of rendering is NOT correct. As the 3rd picture shows, the vessel can be seen from outside the bone. It should not been seen outside from the bone. I use vtkGPUVolumeRayCastMapper in VTK 8.2.0. The bone vtkVolume is added first and then the vessel one is added. Can anyone give me some advice? Thanks in advance.

You need to use a single GPU volume mapper with multi-volume input for correct rendering of multiple volumes. It is somewhat tricky to set it up (see https://gitlab.kitware.com/vtk/vtk/-/issues/17325 and https://gitlab.kitware.com/vtk/vtk/-/issues/17302), but it works very nicely overall. You can see what workarounds we had to implement to make it work in 3D Slicer, or if your goal is to just visualize multiple 3D volumes from C++ or Python or using end-user GUI then you can use 3D Slicer as is.

Thanks for your advice. I have used vtkMultiVolume as the following code.

vtkSmartPointer<vtkGPUVolumeRayCastMapper> volumeMapper = vtkSmartPointer<vtkGPUVolumeRayCastMapper>::New();
volumeMapper->SetInputConnection(0, reader->GetOutputPort());
volumeMapper->SetInputConnection(1, reader->GetOutputPort());
volumeMapper->UseJitteringOn();

vtkSmartPointer<vtkMultiVolume> multiVolume = vtkSmartPointer<vtkMultiVolume>::New();
multiVolume->SetMapper(volumeMapper);

multiVolume->SetVolume(vesselVtkVolume, 0);
multiVolume->SetVolume(boneVtkVolume, 1);

renderer->AddVolume(multiVolume);

As the scene shows, the two volumes can render at the same time. But the color seems to be wrong, like light is not correct. Is there something I have not consider?

multi_volume3

The video you attached shows that renderer provides some output but I cannot guess what inputs you provided and what output you expected, so it is not helpful in identifying any issues. If you provide complete code and data (you can use public data sets) then we might be able to have a closer look.

Does multi-volume rendering of the same data work as expected in 3D Slicer? If it does, then you can copy over all the necessary code that works around bugs in the VTK multi-volume renderer to your code or use Slicer as is. Or, you could fix the issues in VTK.

I will try the same data in 3D Slicer later. The output I expect is like that the first two pictures show. The multi-volume I get seems to have no shading, like that the vtkVolumeProperty has been set ShadeOff(). I have tried to set the properties to vtkMultiVolume and also tried to set them to vtkVolume, but I get the same result as the viedo shows.

multiVolume->GetProperty()->ShadeOn();
multiVolume->GetProperty()->SetInterpolationTypeToLinear();
multiVolume->GetProperty()->SetAmbient(0.2);
multiVolume->GetProperty()->SetDiffuse(1.0);
multiVolume->GetProperty()->SetSpecular(0.0);
multiVolume->GetProperty()->SetSpecularPower(1.0);
multiVolume->GetProperty()->SetScalarOpacityUnitDistance(0.8919);

If I set only one volume for the vtkMultiVolume (using SetVolume()), I can get the correct bone or vessel shading as the first two pictures shows.

We added shading to multi-volume rendering 6 months ago, so it was not included in VTK-8.2. It is in 3D Slicer’s VTK 8.2 branch (because we got the multi-VR shading merged into VTK master but then backported the commit). So, you can either use that branch, or backport the commit to your own VTK fork, or upgrade to VTK9.

I test my app with VTK9 (the lastest master version, the release version 9.0.1 does not support). It works with the rendering result I want. The multi-volume shading looks not very smooth comparing to the single volume and I will check my code to improve it. Thanks!

multi_volume_vtk9

Hi, Harrison!
Recently I researched multi-volume rendering.
I use vtkGPUVolumeRayCastMapper in VTK 9.1.0.
When I used the method of vtkMultiVolume, the position and focus of the light are fixed.
I hope the light to move with the camera when I use the method of vtkMultiVolume.
Could you give me some advice? Thanks in advance.

1 Like