Skip to content

ENH: Load combined scale and translation transforms to generated PVs #139

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

Merged
merged 1 commit into from
Nov 20, 2024
Merged
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
15 changes: 11 additions & 4 deletions AutoscoperM/AutoscoperM.py
Original file line number Diff line number Diff line change
Expand Up @@ -595,6 +595,7 @@ def onLoadPV(self):
volumeSubDir = self.ui.tiffSubDir.text
transformSubDir = self.ui.tfmSubDir.text

# Check number of generated scale and translation transform files matches the number of volumes
vols = glob.glob(os.path.join(mainOutputDir, volumeSubDir, "*.tif"))
tfms_t = glob.glob(os.path.join(mainOutputDir, transformSubDir, "*_t.tfm"))
tfms_scale = glob.glob(os.path.join(mainOutputDir, transformSubDir, "*_scale.tfm"))
Expand All @@ -610,11 +611,14 @@ def onLoadPV(self):
)
return

# check 3 transform files have been generated (translation, scale and combined)
# and load only the combined scale and translation transform for each generated partial volume
for i in range(len(vols)):
nodeName = os.path.splitext(os.path.basename(vols[i]))[0]
volumeNode = slicer.util.loadVolume(vols[i])
translationTransformFileName = os.path.join(mainOutputDir, transformSubDir, f"{nodeName}_t.tfm")
scaleTranformFileName = os.path.join(mainOutputDir, transformSubDir, f"{nodeName}_scale.tfm")
transformFileName = os.path.join(mainOutputDir, transformSubDir, f"{nodeName}.tfm")
if not os.path.exists(translationTransformFileName):
raise ValueError(
f"Failed to load partial volume {nodeName}: "
Expand All @@ -625,11 +629,14 @@ def onLoadPV(self):
f"Failed to load partial volume {nodeName}: "
"Corresponding scaling transform file {scaleTranformFileName} not found"
)
translationNode = slicer.util.loadTransform(translationTransformFileName)
scaleNode = slicer.util.loadTransform(scaleTranformFileName)
if not os.path.exists(transformFileName):
raise ValueError(
f"Failed to load partial volume {nodeName}: "
"Corresponding combined transform file {transformFileName} not found"
)
transformNode = slicer.util.loadTransform(transformFileName)

volumeNode.SetAndObserveTransformNodeID(scaleNode.GetID())
scaleNode.SetAndObserveTransformNodeID(translationNode.GetID())
volumeNode.SetAndObserveTransformNodeID(transformNode.GetID())
self.logic.showVolumeIn3D(volumeNode)

slicer.util.messageBox("Success!")
Expand Down
Loading