View Shear with vtkGPUVolumeRayCastMapper

I’m working on a vtk application which generates oblique views (by turning parallel projection on and setting view shear in the camera) and discovered that vtkGPUVolumeRayCastMapper does not appear to handle cameras with view shear, resulting in a rendered oblique view which seems to cast rays in the wrong direction. I tracked the issue down to vtkOpenGLGPUVolumeRayCastMapper::SetCameraShaderParameters. In this method, a projection direction is passed to the shader. Currently, the code calls vtkCamera::GetDirectionOfProjection to get this value. However, this value stored in the camera does not get updated when view shear is set on the camera, so the view plane normal that is calculated from view shear does not line up with the direction of projection.

I changed the following lines in vtkOpenGLGPUVolumeRayCastMapper::SetCameraShaderParameters from:

cam->GetDirectionOfProjection(dir);
vtkInternal::ToFloat(dir[0], dir[1], dir[2], fvalue3);

to:

cam->GetViewPlaneNormal(dir);
vtkInternal::ToFloat(-dir[0], -dir[1], -dir[2], fvalue3);

This appeared to fix the issue and my oblique views were being generated correctly. It is worth noting that the vtkFixedPointVolumeRayCastMapper does not exhibit this same issue.

I wanted to bring this issue to the attention of the group in the hopes that a fix could be implemented in a future release.

Cheers,
Matt

Normally you don’t need to have shear in the view to show oblique views. What would you like to achieve?

Oblique projection is a type of parallel projection in which the projectors intersect the projection plane at an oblique angle (shear), as opposed to an orthographic projection, which has no shear. So, in my case, I need to set a shear angle, or I end up with an orthographic projection. I’m not aware of a better way in VTK to accomplish this.

Do you mean you would like to do software-based keystone correction? You can capture the rendered image in a vtkImageData and distort as needed. The advantage is that in this case you are not limited to simple linear distortions but you can project to arbitrarily curved surfaces.