<div dir="ltr">Hi Ignatio,<div><br></div><div>The bottom row in a linear transform matrix should always be 0, 0, 0, 1.</div><div>A matrix in which any row or column is all zeros is a singular matrix.</div><div><br></div><div>When you apply a transformation that flips the data inside-out, the</div><div>windings of the polygons and the directions of the normals are reversed.</div><div>This is a mathematical fact, so to speak, and is not specific to VTK.</div><div>The filter vtkReverseSense can be used to reverse the normals and</div><div>the polygon windings in order to make lighting work properly again.</div><div><br></div><div>You can check whether a matrix has a flip by computing the determinant.</div><div>If the determinant is negative, there is a flip. If the determinant is zero,</div><div>the matrix is singular and should not be used (the behavior of the VTK</div><div>transform filters is pretty much undefined for singular matrices).</div><div><br></div><div>The rotation around Z should work fine, so I'm not sure what the problem</div><div>is there. Try again after setting the bottom row of the matrix to 0, 0, 0, 1.</div><div><br></div><div>Cheers,</div><div> - David</div><div><br><div class="gmail_extra"><br><div class="gmail_quote">On Thu, Feb 1, 2018 at 12:02 PM, Ignacio Fernández Galván via vtkusers <span dir="ltr"><<a href="mailto:vtkusers@vtk.org" target="_blank">vtkusers@vtk.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">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:<br>
<br>
#=============================<wbr>===================<br>
import vtk<br>
<br>
renderer = vtk.vtkRenderer()<br>
render_window = vtk.vtkRenderWindow()<br>
render_window.AddRenderer(rend<wbr>erer)<br>
interactor = vtk.vtkRenderWindowInteractor(<wbr>)<br>
interactor.SetInteractorStyle(<wbr>vtk.vtkInteractorStyleTrackbal<wbr>lCamera())<br>
render_window.SetInteractor(in<wbr>teractor)<br>
interactor.Initialize()<br>
renderer.SetBackground(0.2,0.2<wbr>,0.2)<br>
<br>
sphere = vtk.vtkSphereSource()<br>
sphere.SetThetaResolution(20)<br>
sphere.SetPhiResolution(20)<br>
<br>
transform = vtk.vtkTransform()<br>
# no-op<br>
transform.SetMatrix([1,0,0,0,0<wbr>,1,0,0,0,0,1,0,0,0,0,0])<br>
# invert x axis<br>
transform.SetMatrix([-1,0,0,0,<wbr>0,1,0,0,0,0,1,0,0,0,0,0])<br>
# invert x and y axes<br>
transform.SetMatrix([-1,0,0,0,<wbr>0,-1,0,0,0,0,1,0,0,0,0,0])<br>
# 90-degree z rotation<br>
transform.SetMatrix([0,1,0,0,-<wbr>1,0,0,0,0,0,1,0,0,0,0,0])<br>
<br>
t_sphere = vtk.vtkTransformFilter()<br>
t_sphere.SetTransform(transfor<wbr>m)<br>
t_sphere.SetInputConnection(sp<wbr>here.GetOutputPort())<br>
<br>
sphere_mapper = vtk.vtkPolyDataMapper()<br>
#sphere_mapper.SetInputConnect<wbr>ion(sphere.GetOutputPort())<br>
sphere_mapper.SetInputConnecti<wbr>on(t_sphere.GetOutputPort())<br>
sphere_actor = vtk.vtkActor()<br>
sphere_actor.SetMapper(sphere_<wbr>mapper)<br>
sphere_actor.GetProperty().Set<wbr>Color(1,1,1)<br>
renderer.AddActor(sphere_actor<wbr>)<br>
<br>
renderer.ResetCamera()<br>
render_window.Render()<br>
interactor.Start()<br>
#=============================<wbr>===================<br>
<br>
Using the first (no-op) transform is fine, of course.<br>
<br>
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.<br>
<br>
Then I try inverting the y axis too, that should put things back to normal. And indeed it does, apparently.<br>
<br>
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!<br>
<br>
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<br>
<br>
Thanks,<br>
Ignacio<br></blockquote></div></div></div></div>