Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ENH: Added checkbox to register fixed volume to itself #8

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 25 additions & 3 deletions SequenceRegistration/SequenceRegistration.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ def setup(self):
self.registrationInProgress = False
self.logic = SequenceRegistrationLogic()
self.logic.logCallback = self.addLog

# JU 08/05/2024: Initialise the registerFixedVolumeToItself flag:
self.registerFixedVolumeToItself = False

#
# Parameters Area
Expand Down Expand Up @@ -133,6 +136,16 @@ def setup(self):
self.sequenceFixedItemIndexWidget.setToolTip("Set the frame of the input sequence to use as the fixed volume (that all other volumes will be registered to.")
advancedFormLayout.addRow("Fixed frame index:", self.sequenceFixedItemIndexWidget)

#
# JU 08/05/2024: Added the option to register the fixed volume to itself (to replicate filters applied during processing steps)
# default behaviour for the checkbox is FALSE (i.e. unchecked)
self.registerFixedVolumeToItselfCheckBox = qt.QCheckBox(" ")
self.registerFixedVolumeToItselfCheckBox.checked = False
label = qt.QLabel("Register Fixed volume to itself:")
label.setToolTip("Select to run the registration algorithm to the fixed volume.")
self.registerFixedVolumeToItselfCheckBox.setToolTip("Register Fixed volume to itself.")
advancedFormLayout.addRow(label, self.registerFixedVolumeToItselfCheckBox)

# Sequence start index
self.sequenceStartItemIndexWidget = ctk.ctkSliderWidget()
self.sequenceStartItemIndexWidget.minimum = 0
Expand Down Expand Up @@ -235,6 +248,8 @@ def setup(self):
self.showDetailedLogDuringExecutionCheckBox.connect("toggled(bool)", self.onShowLogToggled)
# Check if user selects to create a new preset
self.registrationPresetSelector.connect("activated(int)", self.onCreatePresetPressed)
# JU 08/05/2024 connect the register-to-itself checkbox:
self.registerFixedVolumeToItselfCheckBox.connect("toggled(bool)", self.onRegisterToItselfToggled)


# Add vertical spacer
Expand Down Expand Up @@ -436,10 +451,11 @@ def onApplyButton(self):
endFrameIndex = int(self.sequenceEndItemIndexWidget.value)
self.logic.elastixLogic.setCustomElastixBinDir(self.customElastixBinDirSelector.currentPath)
self.logic.logStandardOutput = self.showDetailedLogDuringExecutionCheckBox.checked
# JU 08/05/2024: Appended input argument self.registerFixedVolumeToItself
self.logic.registerVolumeSequence(self.inputSelector.currentNode(),
self.outputVolumesSelector.currentNode(), self.outputTransformSelector.currentNode(),
fixedFrameIndex, self.registrationPresetSelector.currentIndex, computeMovingToFixedTransform,
startFrameIndex, endFrameIndex)
startFrameIndex, endFrameIndex, self.registerFixedVolumeToItself)
except Exception as e:
print(e)
self.addLog("Error: {0}".format(str(e)))
Expand Down Expand Up @@ -468,6 +484,10 @@ def onShowRegistrationParametersDatabaseFolder(self):
def onShowLogToggled(self, toggle):
self.logic.elastixLogic.logStandardOutput = toggle

# JU 08/05/2024 connect the register-to-itself to the logic component:
def onRegisterToItselfToggled(self, toggle):
self.registerFixedVolumeToItself = toggle

#
# SequenceRegistrationLogic
#
Expand Down Expand Up @@ -500,8 +520,9 @@ def findBrowserForSequence(self, sequenceNode):
return browserNode
return None

# JU 08/05/2024: Appended input argument registerFixedVolumeToItself with default value FALSE
def registerVolumeSequence(self, inputVolSeq, outputVolSeq, outputTransformSeq, fixedVolumeItemNumber, presetIndex, computeMovingToFixedTransform = True,
startFrameIndex=None, endFrameIndex=None):
startFrameIndex=None, endFrameIndex=None, registeredFixedToItself=False):
"""
computeMovingToFixedTransform: if True then moving->fixed else fixed->moving transforms are computed
"""
Expand Down Expand Up @@ -557,7 +578,8 @@ def registerVolumeSequence(self, inputVolSeq, outputVolSeq, outputTransformSeq,
sequencesModule.logic().UpdateProxyNodesFromSequences(movingSeqBrowser)
movingVolume = movingSeqBrowser.GetProxyNode(inputVolSeq)

if movingVolumeItemNumber != fixedVolumeItemNumber:
# JU 08/05/2024: Include the registered-to-itself flag value as part of the logic evaluation:
if (movingVolumeItemNumber != fixedVolumeItemNumber) | registeredFixedToItself:
self.elastixLogic.registerVolumes(
fixedVolume, movingVolume,
outputVolumeNode = outputVol,
Expand Down