[vtkusers] Applying a transform to polydata affects lighting... weirdly

Andras Lasso lasso at queensu.ca
Thu Feb 1 14:23:54 EST 2018


If you apply a linear transform that has a negative determinant to a polydata, then you essentially turn your mesh inside out, so you have to invert the direction of your surface normal vectors.

Andras

-----Original Message-----
From: vtkusers [mailto:vtkusers-bounces at vtk.org] On Behalf Of Ignacio Fernández Galván via vtkusers
Sent: Thursday, February 1, 2018 2:03 PM
To: vtkusers at vtk.org
Subject: [vtkusers] Applying a transform to polydata affects lighting... weirdly

If I apply a nontrivial transformation to polydata, the resulting lighting is completely different from the original. A python example is worth a thousand words:

#================================================
import vtk

renderer = vtk.vtkRenderer()
render_window = vtk.vtkRenderWindow()
render_window.AddRenderer(renderer)
interactor = vtk.vtkRenderWindowInteractor()
interactor.SetInteractorStyle(vtk.vtkInteractorStyleTrackballCamera())
render_window.SetInteractor(interactor)
interactor.Initialize()
renderer.SetBackground(0.2,0.2,0.2)

sphere = vtk.vtkSphereSource()
sphere.SetThetaResolution(20)
sphere.SetPhiResolution(20)

transform = vtk.vtkTransform()
# no-op
transform.SetMatrix([1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,0])
# invert x axis
transform.SetMatrix([-1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,0])
# invert x and y axes
transform.SetMatrix([-1,0,0,0,0,-1,0,0,0,0,1,0,0,0,0,0])
# 90-degree z rotation
transform.SetMatrix([0,1,0,0,-1,0,0,0,0,0,1,0,0,0,0,0])

t_sphere = vtk.vtkTransformFilter()
t_sphere.SetTransform(transform)
t_sphere.SetInputConnection(sphere.GetOutputPort())

sphere_mapper = vtk.vtkPolyDataMapper()
#sphere_mapper.SetInputConnection(sphere.GetOutputPort())
sphere_mapper.SetInputConnection(t_sphere.GetOutputPort())
sphere_actor = vtk.vtkActor()
sphere_actor.SetMapper(sphere_mapper)
sphere_actor.GetProperty().SetColor(1,1,1)
renderer.AddActor(sphere_actor)

renderer.ResetCamera()
render_window.Render()
interactor.Start()
#================================================

Using the first (no-op) transform is fine, of course.

The second just inverts the x axis, and that results in a black sphere. 
Fair enough, I'm "inverting" the object, so maybe it's inside out.

Then I try inverting the y axis too, that should put things back to normal. And indeed it does, apparently.

Perhaps what's needed is a proper rotation/shearing, with no reflection component. I try the fourth, which is a pretty innocent 90-degree rotation around the z axis, no inversion, no deformation. But lo, now the light moves with the object!

Am I missing something or doing something wrong? Any fix or workaround? 
This is with with both VTK 5.8.0 and 8.1.0

Thanks,
Ignacio
_______________________________________________
Powered by https://na01.safelinks.protection.outlook.com/?url=www.kitware.com&data=02%7C01%7Classo%40queensu.ca%7C3eac21bb1aa6419e895708d569a6730c%7C51b39b56515f4e0e9e3854a0cd5d4b39%7C1%7C0%7C636531085972703324&sdata=kpgc6%2BFBPbKt9ypsqRxrbzgZN9L0%2FF1RLF9VEdUNVBU%3D&reserved=0

Visit other Kitware open-source projects at https://na01.safelinks.protection.outlook.com/?url=http%3A%2F%2Fwww.kitware.com%2Fopensource%2Fopensource.html&data=02%7C01%7Classo%40queensu.ca%7C3eac21bb1aa6419e895708d569a6730c%7C51b39b56515f4e0e9e3854a0cd5d4b39%7C1%7C0%7C636531085972703324&sdata=nrucaSSzeJwFu491GC0cwv7T%2BE84JTYzn6vpc4VVuLQ%3D&reserved=0

Please keep messages on-topic and check the VTK FAQ at: https://na01.safelinks.protection.outlook.com/?url=http%3A%2F%2Fwww.vtk.org%2FWiki%2FVTK_FAQ&data=02%7C01%7Classo%40queensu.ca%7C3eac21bb1aa6419e895708d569a6730c%7C51b39b56515f4e0e9e3854a0cd5d4b39%7C1%7C0%7C636531085972703324&sdata=ckqmaKl8sg1%2FWlNaklFPjtUnXfODoQX8Pc7xKNWJlc8%3D&reserved=0

Search the list archives at: https://na01.safelinks.protection.outlook.com/?url=http%3A%2F%2Fmarkmail.org%2Fsearch%2F%3Fq%3Dvtkusers&data=02%7C01%7Classo%40queensu.ca%7C3eac21bb1aa6419e895708d569a6730c%7C51b39b56515f4e0e9e3854a0cd5d4b39%7C1%7C0%7C636531085972703324&sdata=J5XUVtbz0QKglvA2LT9deBMN2XWsVDr9MAqECbojOEg%3D&reserved=0

Follow this link to subscribe/unsubscribe:
https://na01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fvtk.org%2Fmailman%2Flistinfo%2Fvtkusers&data=02%7C01%7Classo%40queensu.ca%7C3eac21bb1aa6419e895708d569a6730c%7C51b39b56515f4e0e9e3854a0cd5d4b39%7C1%7C0%7C636531085972703324&sdata=bNiRpY8G2sE5S%2Fic3bZGL4gSuyo2Uo%2BIhREu9Hx9sVE%3D&reserved=0


More information about the vtkusers mailing list