Break ModelNode Rendering After Repeated Camera Reset and Zoom

Hi all,

As shown below, my code resets the camera and performs zoom operations.

layoutManager = slicer.app.layoutManager()

threeDWidget = layoutManager.threeDWidget("View1")
threeDView = threeDWidget.threeDView()
threeDView.rotateToViewAxis(3) 
threeDView.resetFocalPoint()
threeDView.resetCamera()

cameraNode = slicer.modules.cameras.logic().GetViewActiveCameraNode(threeDView.mrmlViewNode())
cameraNode.GetCamera().Zoom(1.25)

However, when used this codes repeatedly, the render of the modelNode becomes distorted, as seen in the example.

aa

I would greatly appreciate any insights into what might be causing this issue.

Hi Tae Young -

I’m not sure what this would be - possibly zbuffer resolution changes due to clipping planes or something.

It would be great if you could convert this into a simple to reproduce script that anyone could paste into their python console to replicate and experiment with. That is, use the methods in slicer.util to download and load an example model and then apply your manipulations in a loop to replicate the appearance changes you see. Such a script can help you and everyone explore what you are seeing.

Hello,

What version of slicer are you using ?
I had a similar issue with version 5.4 but it was fixed when I upgraded to 5.6.

Hi!

I tested this in various version 5.1, 5.6, and 5.7
All versions show same issues to me ,

I don’t see any distortion. Are you referring to the noise appering on the surface?

I’ve tried your script on some models that I have and could not reproduce what you show in the screenshot. Could you share a model (upload somewhere and post the link here) that demonstrates this problem?

I share the code that illustrates the issue. I believe the problem only occurs in flat interpolation with (modeNode.GetDisplayNode().SetInterpolation(0) → flat interpolation).

cylinder = vtk.vtkCylinderSource()
cylinder.SetHeight(60)
cylinder.SetRadius(20)
cylinder.SetResolution(50)

node = slicer.mrmlScene.AddNewNodeByClass("vtkMRMLModelNode")
node.SetPolyDataConnection(cylinder.GetOutputPort())
node.CreateDefaultDisplayNodes()
node.GetDisplayNode().SetColor(1,1,1)
node.GetDisplayNode().SetInterpolation(0)


################################################################

for i in range(50):
    layoutManager = slicer.app.layoutManager()

    threeDWidget = layoutManager.threeDWidget("View1")
    threeDView = threeDWidget.threeDView()
    threeDView.rotateToViewAxis(3) 
    threeDView.resetFocalPoint()
    threeDView.resetCamera()

    cameraNode = slicer.modules.cameras.logic().GetViewActiveCameraNode(threeDView.mrmlViewNode())
    cameraNode.GetCamera().Zoom(1.25)

By zooming in by 1.25x 50 times, you completely messed up your camera.

You moved it out 10 kilometers away from the focal point:

>>> cam.GetDistance()
13302319.57321041

The model is still filling the field of view because you also reduced the field of view 1/10000th of a degree:

>>> cam.GetViewAngle()
0.00027403155699954446

I would recommend you to just not do this. Instead, set up your camera in a reasonable way, similarly to how you would set up a camera in real world. You can have the camera maybe a few meters away from the patient, but not try to look at the patient from a distance of 10+ kilometers, as you will run into numerical precision issues.

1 Like