When I have an image placed exactly in the XY plane, and I view it from the z-axis. It disappears if there is nothing else in the scene. If I add some other actor, then it does render it. What I’ve noticed is that if I zoom out a lot, it becomes visible again. Is it clipping the image? Thanks in advanced.
Example of it not working:
It might be the near and far clipping planes. How did you set up the camera? Please post your code if you can.
Hello Mr. Gobbi! Here you go:
mRenderWindow = vtkSmartPointer<vtkGenericOpenGLRenderWindow>::New();
mRenderer = vtkSmartPointer<vtkRenderer>::New();
mInteractor = vtkSmartPointer<QVTKInteractor>::New();
mInteractorStyle = vtkSmartPointer<vtkInteractorStyleTrackballCamera>::New();
// mWidget is a QVTKOpenGLWidget
mMapper = vtkSmartPointer<vtkImageSliceMapper>::New();
mActor = vtkSmartPointer<vtkImageActor>::New();
mTransform = vtkSmartPointer<vtkTransform>::New();
// mImageData is vtkImageData with dimensions 143, 205, 165
// This is how I change the slice being rendered.
What I’ve noticed is that it doesn’t do it for the first slice:
Slice 0 (front view):
Slice 31 (at an angle, front view is completely gone):
Yes, I’m sure now that it’s a near/far clipping plane issue.
If you do not set up the camera yourself, then VTK will automatically set up the camera based on the actor bounds during the first render. For vtkImageActor, the bounds are set from the DisplayExtent of the actor. Since the DisplayExtent is a single slice, this causes the near and far clipping planes to be very tightly positioned in front of and behind the slice.
There are certain interactions that cause the interactor to reset the clipping planes (I can’t recall which), but it’s very easy for at least part of the vtkImageActor to move beyond the clipping planes. There are two work-arounds for this:
Set up the camera yourself before the first render, and set the clipping range to be large enough to contain the whole image from any angle.
Use vtkOutlineFilter to create a frame around the image data (use the image data as the input to vtkOutlineFilter, and for the outline actor, use the same UserTransform as for the image actor). This extra actor will cause VTK to initialize the near/far clipping to better values. You can make it transparent if you don’t actually want it to be visible.
Thanks for the suggestion. I tried doing the second one, but once I make the frame invisible, the clipping problem returns
In terms of the first suggestion, would I have to compute the clipping plane based on the position of the camera with respect to the visuals? I sometimes also render other objects along the image (and in some scenarios, multiple images). Would one require to also compute the clipping range when the user zooms in and out?
Try an opacity of 0.005. Regarding the camera, you can look through the VTK examples e.g. https://lorensen.github.io/VTKExamples/site/Cxx/VisualizationAlgorithms/CarotidFlow/
Okay, thank you. I will try these and see what works best. At least I know what the issue is.