Skip to content
/ Slicer Public
forked from Slicer/Slicer

Commit

Permalink
ENH: Update EndoscopyLogic to support saving camera view angle
Browse files Browse the repository at this point in the history
  • Loading branch information
jcfr committed Dec 8, 2023
1 parent a418b96 commit 58fafb5
Showing 1 changed file with 21 additions and 5 deletions.
26 changes: 21 additions & 5 deletions Modules/Scripted/Endoscopy/Endoscopy.py
Original file line number Diff line number Diff line change
Expand Up @@ -301,12 +301,14 @@ def setInputCurve(self, newInputCurve):
"""Set and observe a curve node."""

if self.inputCurve is not None:
self.removeObserver(self.inputCurve, vtk.vtkCommand.ModifiedEvent, self.updateWidgetFromMRML)
self.removeObserver(self.inputCurve, slicer.vtkMRMLMarkupsNode.PointModifiedEvent, self.onInputCurveControlPointModified)
self.removeObserver(self.inputCurve, slicer.vtkMRMLMarkupsNode.PointEndInteractionEvent, self.onInputCurveControlPointEndInteraction)

self.inputCurve = newInputCurve

if newInputCurve is not None:
self.addObserver(self.inputCurve, vtk.vtkCommand.ModifiedEvent, self.updateWidgetFromMRML)
self.addObserver(self.inputCurve, slicer.vtkMRMLMarkupsNode.PointModifiedEvent, self.onInputCurveControlPointModified)
self.addObserver(self.inputCurve, slicer.vtkMRMLMarkupsNode.PointEndInteractionEvent, self.onInputCurveControlPointEndInteraction)

Expand Down Expand Up @@ -342,7 +344,9 @@ def updateWidgetFromMRML(self, *_unused):
self.cameraNodeSelector.setCurrentNode(cameraNode)

if cameraNode:
self.viewAngleSlider.value = cameraNode.GetViewAngle()
viewAngle = EndoscopyLogic.getCameraViewAngleFromInputCurve(self.inputCurve)
self.viewAngleSlider.value = viewAngle
cameraNode.GetCamera().SetViewAngle(viewAngle)

numberOfControlPoints = self.logic.getNumberOfControlPoints()

Expand Down Expand Up @@ -388,10 +392,7 @@ def frameDelaySliderValueChanged(self, newValue):
self.timer.interval = newValue

def viewAngleSliderValueChanged(self, newValue):
cameraNode = EndoscopyLogic.getCameraFromInputCurve(self.inputCurve)
if not cameraNode:
return
cameraNode.GetCamera().SetViewAngle(newValue)
EndoscopyLogic.setInputCurveCameraViewAngle(self.inputCurve, newValue)

def setPlaybackEnabled(self, play):
if play:
Expand Down Expand Up @@ -586,6 +587,8 @@ def flyToNext():
"""

NODE_PATH_CAMERA_ORIENTATIONS_ATTRIBUTE_NAME = "Endoscopy.Path.CameraOrientations"
NODE_PATH_VIEW_ANGLE_ATTRIBUTE_NAME = "Endoscopy.Path.ViewAngle"
DEFAULT_CAMERA_VIEW_ANGLE = 30.0

def __init__(self, dl=0.5):
self.dl = dl # desired world space step size (in mm)
Expand Down Expand Up @@ -834,6 +837,19 @@ def getCameraFromInputCurve(inputCurve):
return None
return inputCurve.GetNodeReference("Camera")

@staticmethod
def setInputCurveCameraViewAngle(inputCurve, viewAngle):
if not inputCurve:
return
inputCurve.SetAttribute(EndoscopyLogic.NODE_PATH_VIEW_ANGLE_ATTRIBUTE_NAME, str(viewAngle))

@staticmethod
def getCameraViewAngleFromInputCurve(inputCurve):
if not inputCurve:
return
value = inputCurve.GetAttribute(EndoscopyLogic.NODE_PATH_VIEW_ANGLE_ATTRIBUTE_NAME)
return float(value if value is not None else EndoscopyLogic.DEFAULT_CAMERA_VIEW_ANGLE)

@staticmethod
def createTransformFromInputCurve(inputCurve):
if not inputCurve:
Expand Down

0 comments on commit 58fafb5

Please sign in to comment.