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

Ignacio Fernández Galván jellby at yahoo.com
Thu Feb 1 14:02:47 EST 2018


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


More information about the vtkusers mailing list