Skip to content

Commit 00014a0

Browse files
Update transducer absolute path info handling
This updates SlicerOpenLIFU to work with the change introduced in OpenwaterHealth/OpenLIFU-python@611ff30 which was part of the work for OpenwaterHealth/OpenLIFU-python#218
1 parent 52ad950 commit 00014a0

File tree

2 files changed

+13
-14
lines changed

2 files changed

+13
-14
lines changed

OpenLIFUData/OpenLIFUData.py

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1492,10 +1492,7 @@ def load_session(self, subject_id, session_id) -> None:
14921492
# === Load transducer ===
14931493

14941494
transducer_openlifu = self.db.load_transducer(session_openlifu.transducer_id)
1495-
if transducer_openlifu.registration_surface_filename or transducer_openlifu.transducer_body_filename:
1496-
transducer_abspaths_info = self.db.get_transducer_absolute_filepaths(session_openlifu.transducer_id)
1497-
else:
1498-
transducer_abspaths_info = {}
1495+
transducer_abspaths_info = self.db.get_transducer_absolute_filepaths(session_openlifu.transducer_id)
14991496
newly_loaded_transducer = self.load_transducer_from_openlifu(
15001497
transducer = transducer_openlifu,
15011498
transducer_abspaths_info = transducer_abspaths_info,
@@ -1596,12 +1593,13 @@ def load_transducer_from_file(self, filepath:str) -> None:
15961593
transducer = openlifu_lz().Transducer.from_file(filepath)
15971594
transducer_parent_dir = Path(filepath).parent
15981595

1599-
transducer_abspaths_info = {key: transducer_parent_dir.joinpath(filename)
1600-
for key, filename in {
1601-
'transducer_body_abspath': transducer.transducer_body_filename,
1602-
'registration_surface_abspath': transducer.registration_surface_filename
1603-
}.items() if filename
1604-
}
1596+
transducer_abspaths_info = {
1597+
key: transducer_parent_dir.joinpath(filename) if filename else None
1598+
for key, filename in [
1599+
('transducer_body_abspath', transducer.transducer_body_filename),
1600+
('registration_surface_abspath', transducer.registration_surface_filename),
1601+
]
1602+
}
16051603

16061604
self.load_transducer_from_openlifu(transducer, transducer_abspaths_info)
16071605

OpenLIFULib/OpenLIFULib/transducer.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from typing import Optional, TYPE_CHECKING, Callable, Any
22
import numpy as np
3+
from pathlib import Path
34
import vtk
45
import slicer
56
from slicer import (
@@ -74,8 +75,8 @@ def initialize_from_openlifu_transducer(
7475
shNode.SetItemParent(shNode.GetItemByDataNode(model_node), parentFolderItem)
7576
model_node.CreateDefaultDisplayNodes() # toggles the "eyeball" on
7677

77-
if 'transducer_body_abspath' in transducer_abspaths_info:
78-
if transducer.transducer_body_filename != transducer_abspaths_info['transducer_body_abspath'].name:
78+
if transducer_abspaths_info['transducer_body_abspath'] is not None:
79+
if transducer.transducer_body_filename != Path(transducer_abspaths_info['transducer_body_abspath']).name:
7980
raise ValueError("The filename provided in 'transducer_body_abspath' does not match the file specified in the Transducer object")
8081
body_model_node = slicer.util.loadModel(transducer_abspaths_info['transducer_body_abspath'])
8182
body_model_node.SetName(f"{slicer_transducer_name}-body")
@@ -84,8 +85,8 @@ def initialize_from_openlifu_transducer(
8485
else:
8586
body_model_node = None
8687

87-
if 'registration_surface_abspath' in transducer_abspaths_info:
88-
if transducer.registration_surface_filename != transducer_abspaths_info['registration_surface_abspath'].name:
88+
if transducer_abspaths_info['registration_surface_abspath'] is not None:
89+
if transducer.registration_surface_filename != Path(transducer_abspaths_info['registration_surface_abspath']).name:
8990
raise ValueError("The filename provided in 'registration_surface_abspath' does not match the file specified in the Transducer object")
9091
surface_model_node = slicer.util.loadModel(transducer_abspaths_info['registration_surface_abspath'])
9192
shNode.SetItemParent(shNode.GetItemByDataNode(surface_model_node), parentFolderItem)

0 commit comments

Comments
 (0)