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