# Break ModelNode Rendering After Repeated Camera Reset and Zoom

**URL:** <https://discourse.slicer.org/t/break-modelnode-rendering-after-repeated-camera-reset-and-zoom/38321>\
**Category:** Development\
**Created:** [September 11, 2024, 7:14am UTC](https://discourse.slicer.org/t/break-modelnode-rendering-after-repeated-camera-reset-and-zoom/38321 "2024-09-11T07:14:56Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![park](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/park/32/5717_2.png) [@park](https://discourse.slicer.org/u/park)\
**Post date:** [September 11, 2024, 7:14am UTC](https://discourse.slicer.org/t/break-modelnode-rendering-after-repeated-camera-reset-and-zoom/38321/1 "2024-09-11T07:14:56Z")

</div>

Hi all,

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

```auto
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](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/5/a/5aad8fdc73cc6219326da977e8d0960bf9b58ad9.png)

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

---

<div class="post-metadata">

**Author:** ![pieper](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/pieper/32/8_2.png) [@pieper](https://discourse.slicer.org/u/pieper)\
**Post date:** [September 11, 2024, 2:16pm UTC](https://discourse.slicer.org/t/break-modelnode-rendering-after-repeated-camera-reset-and-zoom/38321/2 "2024-09-11T14:16:08Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Matteboo](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/matteboo/32/66548_2.png) [@Matteboo](https://discourse.slicer.org/u/Matteboo)\
**Post date:** [September 11, 2024, 2:25pm UTC](https://discourse.slicer.org/t/break-modelnode-rendering-after-repeated-camera-reset-and-zoom/38321/3 "2024-09-11T14:25:58Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![park](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/park/32/5717_2.png) [@park](https://discourse.slicer.org/u/park)\
**Post date:** [September 11, 2024, 2:30pm UTC](https://discourse.slicer.org/t/break-modelnode-rendering-after-repeated-camera-reset-and-zoom/38321/4 "2024-09-11T14:30:41Z")

</div>

Hi!

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

---

<div class="post-metadata">

**Author:** ![lassoan](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/lassoan/32/13_2.png) [@lassoan](https://discourse.slicer.org/u/lassoan)\
**Post date:** [September 11, 2024, 9:11pm UTC](https://discourse.slicer.org/t/break-modelnode-rendering-after-repeated-camera-reset-and-zoom/38321/5 "2024-09-11T21:11:06Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![park](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/park/32/5717_2.png) [@park](https://discourse.slicer.org/u/park)\
**Post date:** [September 13, 2024, 1:53am UTC](https://discourse.slicer.org/t/break-modelnode-rendering-after-repeated-camera-reset-and-zoom/38321/6 "2024-09-13T01:53:14Z")

</div>

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

```auto
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)

```

---

<div class="post-metadata">

**Author:** ![lassoan](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/lassoan/32/13_2.png) [@lassoan](https://discourse.slicer.org/u/lassoan)\
**Post date:** [September 13, 2024, 4:23am UTC](https://discourse.slicer.org/t/break-modelnode-rendering-after-repeated-camera-reset-and-zoom/38321/7 "2024-09-13T04:23:51Z")

</div>

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:

```python
>>> 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:

```python
>>> 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.
