Skip to content

Commit

Permalink
BUG: Fix off-by-one bug in end frame for 3D registration
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
sbelsk authored and jcfr committed Nov 21, 2024
1 parent 54d8daa commit 9dbe212
Showing 1 changed file with 8 additions and 10 deletions.
18 changes: 8 additions & 10 deletions Hierarchical3DRegistration/Hierarchical3DRegistration.py
Original file line number Diff line number Diff line change
Expand Up @@ -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."""
Expand Down Expand Up @@ -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()
Expand All @@ -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
Expand Down

0 comments on commit 9dbe212

Please sign in to comment.