Skip to content
/ Slicer Public
forked from Slicer/Slicer

Commit

Permalink
BUG: Fix rebuild of Endoscopy flythrough when modifying the input curve
Browse files Browse the repository at this point in the history
This commit addresses an issue introduced during the integration of the pull request
associated with commit 717fd6f (ENH: Add support for managing orientation keyframes
in Endoscopy).

The logic that was inadvertently removed is now reinstated to prevent unintended modification
events triggered by changes to the input curve. The variable "ignoreInputCurveModified"
is reintroduced to manage and prevent a second modification event.

Additionally, this commit addresses typos in comments.

Co-authored-by: Jean-Christophe Fillion-Robin <jchris.fillionr@kitware.com>
  • Loading branch information
Leengit and jcfr committed Nov 28, 2023
1 parent 5661f8e commit c8599af
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 @@ -79,6 +79,7 @@ def __init__(self, parent=None):
self.timer = qt.QTimer()
self.timer.setInterval(20)
self.timer.connect("timeout()", self.flyToNext)
self.ignoreInputCurveModified = 0

self.cameraNode = None
self.inputCurve = None
Expand Down Expand Up @@ -341,7 +342,11 @@ def enableOrDisableCreateButton(self):

def onInputCurveModified(self, observer, eventid):
"""If the input curve was changed we need to repopulate the keyframe UI"""
pass
if not self.ignoreInputCurveModified:
if self.logic:
# We are going to have rebuild the EndoscopyLogic later
self.logic.cleanup()
self.logic = None

def onCreatePathButtonClicked(self):
"""Connected to 'Use this curve'` button. It allows to:
Expand All @@ -351,6 +356,7 @@ def onCreatePathButtonClicked(self):
- go to start of the path
"""
inputCurve = self.inputCurveSelector.currentNode()
self.ignoreInputCurveModified += 1

if self.logic:
self.logic.cleanup()
Expand All @@ -361,7 +367,7 @@ def onCreatePathButtonClicked(self):
# Update frame slider range
self.frameSlider.maximum = max(0, numberOfControlPoints - 2)

# Create a cursor so that the user can see where the fly through is progressing.
# Create a cursor so that the user can see where the flythrough is progressing.
self.createCursor()

# Hide the cursor, model and inputCurve from the main 3D view
Expand All @@ -378,6 +384,8 @@ def onCreatePathButtonClicked(self):
self.flythroughCollapsibleButton.enabled = enable
self.advancedCollapsibleButton.enabled = enable

self.ignoreInputCurveModified -= 1

# Initialize to the start of the path
self.flyTo(0)

Expand Down Expand Up @@ -542,9 +550,11 @@ def saveCameraOrientations(self, cameraOrientations):
# Rather than a length-zero or length-two string representing an empty dictionary, clear the string.
cameraOrientationsString = None

self.ignoreInputCurveModified += 1
self.inputCurve.SetAttribute(
EndoscopyLogic.NODE_PATH_CAMERA_ORIENTATIONS_ATTRIBUTE_NAME, cameraOrientationsString,
)
self.ignoreInputCurveModified -= 1
if self.logic:
self.logic.cameraOrientations = cameraOrientations

Expand All @@ -561,6 +571,9 @@ def cameraOrientationsIsCorrectType(self, convertedCameraOrientations):
)

def flyToNext(self):
if self.logic is None:
# We invalidated self.logic due to an intervening user modification of the input. We need it now.
self.logic = EndoscopyLogic(self.inputCurve)
currentStep = int(self.frameSlider.value)
nextStep = currentStep + self.skip + 1
if nextStep > self.logic.resampledCurve.GetNumberOfControlPoints() - 2:
Expand All @@ -570,9 +583,12 @@ def flyToNext(self):
def flyTo(self, resampledCurvePointIndex):
"""Apply the resampledCurvePointIndex-th step in the path to the global camera"""

if self.logic is None:
# We invalidated self.logic due to an intervening user modification of the input. We need it now.
self.logic = EndoscopyLogic(self.inputCurve)

if (
self.logic is None
or self.logic.resampledCurve is None
self.logic.resampledCurve is None
or not 0 <= resampledCurvePointIndex < self.logic.resampledCurve.GetNumberOfControlPoints()
):
return
Expand Down Expand Up @@ -769,7 +785,7 @@ def setControlPoints(self, inputCurve: slicer.vtkMRMLMarkupsCurveNode) -> bool:

# Find a plane that approximately includes the points of the resampled curve,
# so that we can use its normal to define the "up" direction. This is somewhat
# nonsensical if self.numberOfResampledCurveControlPoints < 3, but proceed anyway.
# nonsensical if self.resampledCurve.GetNumberOfControlPoints() < 3, but proceed anyway.
_, self.planeNormal = EndoscopyLogic.planeFit(points.T)

# Interpolate the user-supplied orientations to compute (and assign) an orientation to every control point of
Expand Down

0 comments on commit c8599af

Please sign in to comment.