|
5 | 5 | from vtk.util import numpy_support |
6 | 6 | import slicer |
7 | 7 | 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 |
9 | 9 | from OpenLIFULib.lazyimport import xarray_lz |
10 | 10 |
|
11 | 11 | if TYPE_CHECKING: |
@@ -76,3 +76,23 @@ def make_xarray_in_transducer_coords_from_volume(volume_node:vtkMRMLScalarVolume |
76 | 76 | attrs={'vtkMRMLNodeID':volume_node.GetID(),} |
77 | 77 | ) |
78 | 78 | 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