Slicer Segmentation inverted normals for closed surface representation

Thibault_Pelletier
Thu, 07 Mar 2024 07:46:39 +0000
Development

Hi everyone,

We have recently noticed a problem when exporting STL and OBJ from segmentations in Slicer. Depending on the Volume’s affine, the generated normals can point inside instead of outside.

This doesn’t cause any problems for Slicer’s rendering as backface culling is disabled, but it can cause multiple problems including when trying to perform boolean operations or exporting to other softwares.

The problem is easily reproducible by creating a sphere brush segmentation in the following volumes :

import numpy as np
inverted_volume = slicer.mrmlScene.AddNewNodeByClass("vtkMRMLScalarVolumeNode")
inverted_volume.SetName("InvertedVolume")
inverted_volume.CreateDefaultDisplayNodes()

m = np.eye(4)
m[0,0] = -1
m[1,1] = -1
m[2,2] = -1
inverted_volume.SetIJKToRASMatrix(slicer.util.vtkMatrixFromArray(m))
inverted_volume.SetSpacing([1, 1, 1])
slicer.util.updateVolumeFromArray(inverted_volume, np.zeros((256,256,256)))


not_inverted_volume = slicer.mrmlScene.AddNewNodeByClass("vtkMRMLScalarVolumeNode")
not_inverted_volume.SetName("NotInvertedVolume")
not_inverted_volume.CreateDefaultDisplayNodes()

m = np.eye(4)
m[0,0] = -1
m[1,1] = -1
not_inverted_volume.SetIJKToRASMatrix(slicer.util.vtkMatrixFromArray(m))
not_inverted_volume.SetSpacing([1, 1, 1])
slicer.util.updateVolumeFromArray(not_inverted_volume, np.zeros((256,256,256)))

Exporting to STL and displaying the face orientation in Blender yields the following results :

@jcfr and @lassoan what do you think of this issue?

Best,
Thibault

5 posts - 2 participants