Skip to content

Commit 1d4b31d

Browse files
1978 fix sform issue in omniverse nifti to mesh function (#1979)
Fixes #1978 . ### Description A few sentences describing the changes proposed in this pull request. ### Checks <!--- Put an `x` in all the boxes that apply, and remove the not applicable items --> - [ ] Avoid including large-size files in the PR. - [ ] Clean up long text outputs from code cells in the notebook. - [ ] For security purposes, please check the contents and remove any sensitive info such as user names and private key. - [ ] Ensure (1) hyperlinks and markdown anchors are working (2) use relative paths for tutorial repo files (3) put figure and graphs in the `./figure` folder - [ ] Notebook runs automatically `./runner.sh -t <path to .ipynb file>` Signed-off-by: Yiheng Wang <[email protected]> Co-authored-by: YunLiu <[email protected]>
1 parent 826c451 commit 1d4b31d

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

modules/omniverse/utility.py

+15-2
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)