# How to stabilize the first view（position/focus/ViewUp）

**URL:** <https://discourse.slicer.org/t/how-to-stabilize-the-first-view-position-focus-viewup/31419>\
**Category:** Community\
**Tags:** extensions-manager\
**Created:** [August 29, 2023, 9:45am UTC](https://discourse.slicer.org/t/how-to-stabilize-the-first-view-position-focus-viewup/31419 "2023-08-29T09:45:19Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![slicer365](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/slicer365/32/67549_2.png) [@slicer365](https://discourse.slicer.org/u/slicer365)\
**Post date:** [August 29, 2023, 9:45am UTC](https://discourse.slicer.org/t/how-to-stabilize-the-first-view-position-focus-viewup/31419/1 "2023-08-29T09:45:19Z")

</div>

I used the Endoscopy module to create a first-view analog navigation,

and to demonstrate, I’m using a point as a guide,

when I move this point, the 3D view suddenly changes, especially when the position of the point moves to the left or right.

The following is part of the code, which mainly adds an observer to the selected point, then obtains the position of the point in real time, and takes the latest two positions as the camera position and focus position, and the viewUp position is fixed.

I mainly hope it can turn smoothly.

I know this is caused by a change in the vector direction of the camera position and focus, so I want to find a solution.

```auto
    def addPos(self,caller,event):
        position=[0,0,0]
        transNode=self.ui.markSelector.currentNode()
        
        transNode.GetNthControlPointPosition(0, position)
        
        self.transList.append(position)
        if len(self.transList)>2:
            self.transList=self.transList[-2:]
        
            cameraPosition = self.transList[0]
 
            wasModified = self.cameraNode.StartModify()
           
            self.camera.SetPosition(cameraPosition)
            focalPointPosition = self.transList[1]
            
            self.camera.SetFocalPoint(*focalPointPosition)
            self.camera.OrthogonalizeViewUp()
           #self.camera.SetViewUp()
           
            self.cameraNode.EndModify(wasModified)
            self.cameraNode.ResetClippingRange()

    def startNav(self):
    
        navNode=self.ui.markSelector.currentNode()

        if navNode:
        
            navNode.AddObserver(slicer.vtkMRMLMarkupsNode.PointModifiedEvent,self.addPos)
        else:
            pass

```

[https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/1/5/158d15a61dc0f40d839a0f4037cd07bb8c82fb9f.mp4](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/1/5/158d15a61dc0f40d839a0f4037cd07bb8c82fb9f.mp4)

---

<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:** [August 31, 2023, 7:53pm UTC](https://discourse.slicer.org/t/how-to-stabilize-the-first-view-position-focus-viewup/31419/2 "2023-08-31T19:53:39Z")

</div>

It looks like something else is also trying to set the view. Maybe if you can create a fully self-contained example script it would help.

---

<div class="post-metadata">

**Author:** ![slicer365](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/slicer365/32/67549_2.png) [@slicer365](https://discourse.slicer.org/u/slicer365)\
**Post date:** [September 2, 2023, 12:50am UTC](https://discourse.slicer.org/t/how-to-stabilize-the-first-view-position-focus-viewup/31419/3 "2023-09-02T00:50:24Z")

</div>

Thank you, Mr Pieper, I solved the problem.

The problem is caused by the camera position being too close to the focus position.

I increased the distance between the camera and the focus, and it looked much more stable.

Although it’s still a little shaky.

[https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/e/3/e35db7be0a974a9f933eb534e86cd9294c02750d.mp4](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/e/3/e35db7be0a974a9f933eb534e86cd9294c02750d.mp4)
