Surface model turns black under transformation

When I reflect a model node using a linear transform node that has a reflection, the visualization of it in 3D unexpectedly turns black. I gather from other posts and LLM consultation that this is because a transform with negative determinant turns the model “inside-out”. The surface normals are properly reflected, but the clockwise/counterclockwise sense of which side of a surface facet is the “front” is reversed by the reflection. Thus when the renderer is trying to figure out how to light a facet, the surface normal for the “front” actually points out the “back” of the facet, and this results in no color or light at that facet, it’s just black (note that this is somehow different than just flipping the normal vectors, in which case you would see the backface color lighting rather than black). The proper way to address this is to apply a vtkReverseSense() filter, which flips the facet orientation back the other way around. My suggestion is that Slicer should do this sense reversal under transformation with negative determinant automatically. I think that even relatively sophisticated users used to applying all sorts of transformations to all sorts of MRML nodes will find the current behavior surprising and undesirable. Is there any use case where a user would actually want their transform to make their surface unlightable in this way?

Background context: I am constructing a heatmap of a brain structure in a standardized coordinate system for something like a probabilistic atlas of its location. Since there is bilateral symmetry in the brain, I am reflecting all of the left side structures to the right to make a combined map with a “lateral” coordinate rather than a R/L coordinate. I was surprised and confused when some of the models turned black and were impervious to lighting changes. I realized that it was all of the reflected versions that were like this and I spent a lot of time trying to figure out what was different before coming across the explanation above. The typical experience of applying transforms to nodes in Slicer is that they “just work”, but in this case it felt like it broke the models in a way that was not easy to understand.

Yes, I can see how this is unexpected and could be automatically detected and fixed. It would mean that in the models displayable manager we’d check the transform and add the reverse sense filter as you suggest. I know people worked on mirroring applications in the past but I don’t recall if anything ever made it as an extension; something that simplified the whole process using landmarks and planes and also handled the visualization would probably be easiest if people are doing this a lot.

In case it helps, there’a Flip Normals option in the Surface Toolbox that can do this. Also a mirror, which might do what you need.

1 Like

Thanks for the response! Surface Toolbox does indeed handle this properly in the “Mirror” function, and internally, all it does is detect whether the transformation has negative determinant, and if so, applies vtkReverseSense(). Now that I know what the issue is, it is straightforward to correct; I just had trouble figuring it out, and it would be nice (and seems like it would be appropriate) if this were handled in the model’s displayable manager, as you suggest. Is there a good place I can suggest this change (e.g. github issue)?

Yes, a github issue make sense. We could also move this to the Feature Requests category so people could vote in support of the idea (just did that).

1 Like

Thanks! I added a github issue as well referencing this discussion: https://github.com/Slicer/Slicer/issues/9018