Skip to content

Commit 8a1cc0e

Browse files
fix
Signed-off-by: Yiheng Wang <[email protected]>
1 parent b702677 commit 8a1cc0e

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

modules/omniverse/utility.py

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,13 @@ def convert_to_mesh(
3838
reader.SetFileName(segmentation_path)
3939
reader.Update()
4040

41+
nifti_transform_matrix = reader.GetSFormMatrix()
42+
if nifti_transform_matrix is None or nifti_transform_matrix.IsIdentity():
43+
nifti_transform_matrix = vtk.vtkMatrix4x4()
44+
45+
nifti_transform = vtk.vtkTransform()
46+
nifti_transform.SetMatrix(nifti_transform_matrix)
47+
4148
label_values = {label_value: None} if isinstance(label_value, int) else label_value
4249
if len(label_values.keys()) > 1:
4350
renderer = vtk.vtkRenderer()
@@ -98,15 +105,21 @@ def convert_to_mesh(
98105
decimatedNormals.ConsistencyOn()
99106
decimatedNormals.Update()
100107

101-
# Step 7: convert to LPS
108+
# Step 7: Apply NIFTI SForm transform
109+
nifti_transformer = vtk.vtkTransformPolyDataFilter()
110+
nifti_transformer.SetTransform(nifti_transform)
111+
nifti_transformer.SetInputConnection(decimatedNormals.GetOutputPort())
112+
nifti_transformer.Update()
113+
114+
# Step 8: convert to LPS (apply after NIFTI transform)
102115
ras2lps = vtk.vtkMatrix4x4()
103116
ras2lps.SetElement(0, 0, -1)
104117
ras2lps.SetElement(1, 1, -1)
105118
ras2lpsTransform = vtk.vtkTransform()
106119
ras2lpsTransform.SetMatrix(ras2lps)
107120
transformer = vtk.vtkTransformPolyDataFilter()
108121
transformer.SetTransform(ras2lpsTransform)
109-
transformer.SetInputConnection(decimatedNormals.GetOutputPort())
122+
transformer.SetInputConnection(nifti_transformer.GetOutputPort())
110123
transformer.Update()
111124

112125
if len(label_values.keys()) > 1:

0 commit comments

Comments
 (0)