Skip to content

Commit 94e52ab

Browse files
WIP
1 parent 268716a commit 94e52ab

File tree

1 file changed

+21
-1
lines changed

1 file changed

+21
-1
lines changed

OpenLIFULib/OpenLIFULib/simulation.py

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
from vtk.util import numpy_support
66
import slicer
77
from slicer import vtkMRMLScalarVolumeNode
8-
from OpenLIFULib.coordinate_system_utils import get_RAS2IJK
8+
from OpenLIFULib.coordinate_system_utils import get_RAS2IJK, get_xxx2ras_matrix
99
from OpenLIFULib.lazyimport import xarray_lz
1010

1111
if TYPE_CHECKING:
@@ -76,3 +76,23 @@ def make_xarray_in_transducer_coords_from_volume(volume_node:vtkMRMLScalarVolume
7676
attrs={'vtkMRMLNodeID':volume_node.GetID(),}
7777
)
7878
return volume_resampled_dataarray
79+
80+
def make_xarray_in_LPS_from_volume(volume_node:vtkMRMLScalarVolumeNode) -> "xarray.DataArray":
81+
"""Convert a volume node into a DataArray in LPS coordinates. There is no resampling."""
82+
# Here are the coordinate systems involved:
83+
# ras : The slicer world RAS coordinate system
84+
# lps: The slicer world LPS coordinate system
85+
# IJK : the volume node's underlying data array indices, which will also be the indices of the ouput DataArray
86+
ras2IJK = get_RAS2IJK(volume_node)
87+
lps2ras = get_xxx2ras_matrix('L', 'P', 'S')
88+
lps2IJK = ras2IJK @ lps2ras
89+
90+
# TODO: use lps2IJK to construct coords below
91+
92+
volume_resampled_dataarray = xarray_lz().DataArray(
93+
slicer.util.arrayFromVolume(volume_node).transpose((2,1,0)), # the array indices come in KJI rather than IJK so we permute them
94+
coords=coords,
95+
name=volume_node.GetName(),
96+
attrs={'vtkMRMLNodeID':volume_node.GetID(),}
97+
)
98+
return volume_resampled_dataarray

0 commit comments

Comments
 (0)