From 9dbe212216f9fe1e2594c0030a9763b00b71eea8 Mon Sep 17 00:00:00 2001 From: Shelly Belsky Date: Tue, 22 Oct 2024 17:51:25 -0400 Subject: [PATCH] BUG: Fix off-by-one bug in end frame for 3D registration The UI slider in the 3DHierarchicalRegistration module for the range of frames to be registered implies that the selected interval is inclusive of the end frame, which is evident also in the number of frames in the initialized transform sequence. However, the registration used to be run on all frames except the last one, so the last frame in the resulting transform sequence was always left as the initialized identity. This commit fixes this off-by-one bug in the frames being registered. --- .../Hierarchical3DRegistration.py | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/Hierarchical3DRegistration/Hierarchical3DRegistration.py b/Hierarchical3DRegistration/Hierarchical3DRegistration.py index 5317e2f..a26d288 100644 --- a/Hierarchical3DRegistration/Hierarchical3DRegistration.py +++ b/Hierarchical3DRegistration/Hierarchical3DRegistration.py @@ -305,15 +305,13 @@ def updateFrameSlider(self, CTSelectorNode: slicer.vtkMRMLNode): """Updates the slider and spin boxes when a new sequence is selected.""" if self.logic.autoscoperLogic.IsSequenceVolume(CTSelectorNode): numNodes = CTSelectorNode.GetNumberOfDataNodes() - self.ui.frameSlider.maximum = numNodes - self.ui.startFrame.maximum = numNodes - self.ui.endFrame.maximum = numNodes - self.ui.endFrame.value = numNodes + maxFrame = numNodes - 1 elif CTSelectorNode is None: - self.ui.frameSlider.maximum = 0 - self.ui.startFrame.maximum = 0 - self.ui.endFrame.maximum = 0 - self.ui.endFrame.value = 0 + maxFrame = 0 + self.ui.frameSlider.maximum = maxFrame + self.ui.startFrame.maximum = maxFrame + self.ui.endFrame.maximum = maxFrame + self.ui.endFrame.value = maxFrame def onInitHierarchyButton(self): """UI Button for initializing the hierarchy transforms.""" @@ -500,7 +498,7 @@ def registerSequence( try: self.isRunning = True - for idx in range(startFrame, endFrame): + for idx in range(startFrame, endFrame + 1): nodeList = [rootNode] for node in nodeList: slicer.app.processEvents() @@ -527,7 +525,7 @@ def registerSequence( node.dataNode.SetAndObserveTransformNodeID(node.getTransform(idx).GetID()) - if idx != endFrame - 1: # Unless its the last frame + if idx != endFrame: # Unless it's the last frame rootNode.copyTransformToNextFrame(idx) finally: self.isRunning = False