[vtk] flipped normals question

Ron Inbar rinbar at netvision.net.il
Wed Oct 6 07:30:54 EDT 1999


Randy,

OpenGL transforms normals using the transposed inverse of the vertex
transformation matrix.  If we ignore the translation (which is meaningless
for normals) and just look at the reflection, then the normal transformation
turns out to be identical to the vertex transformation (footnote 1).  So
what happens to the normals under your transformation is that their
z-coordinate is reversed, but they are *not* flipped unless you flip them
explicitly.

On the other hand, the vertex transformation makes the polygons reverse
their *sense*, just as when you look at a clock in the mirror it seems to be
going counter-clockwise.  What this means is that polygons which used to
face the front before the transformation now face back.

The net effect of the flipped faces and unflipped normals is polygons that
have their normals pointing backward.

The best solution to this unhealthy situation, in my opinion, would be to
use vtkReverseSense with ReverseCellsOn and ReverseNormalsOff.  You would
have to split your pipeline as follows:

coneSource ---> coneMapper
     |
reverseSense
     |
coneFlipMapper
    |
coneFlipActor

If you don't want to change your pipeline, you can also do it in the
graphics sub-system as follows:
* Visualization Pipeline remains the same as before (no vtkPolyDataNormals,
vtkReverseSense, or anything of this sort)
* Back Face Culling On, so you can see the polygons despite the reversed
senses.
* Two Sided Lighting On, to make OpenGL flip the normals in lighting
calculations.

What you did in your Tcl script is to flip the normals twice: once by VTK
and once by OpenGL's two-sided lighting.  That left the normals unchanged,
i.e., facing backward, and the lighting calculations yielded zero, i.e.,
unlit.

Ron

-------
(1) It doesn't always turn out this way.  For example, if your vertex
transformation does some shearing, then the normals are transformed
differently.  The key mathematical term here is "duality".

----- Original Message -----
From: Randy Heiland <heiland at ncsa.uiuc.edu>
To: <vtkusers at gsao.med.ge.com>
Sent: éåí øáéòé 06 àå÷èåáø 1999 00:05
Subject: [vtk] flipped normals question


> When I apply a vtkTransform with a negative Scale component to an Actor,
it
> seems to "lose its normals" (ever have days like that?) -- at least the
> transformed actor isn't lit (but you can see it by going into wireframe).
>
> Included is a simple Python script; below it, a similar Tcl script where
I've
> tried introducing flipped normals, etc..  What am I missing?
>
> thanks,
> --Randy
>
> ----------------------------------------------------------
> #!/usr/local/bin/python
>
> from libVTKCommonPython import *
> from libVTKGraphicsPython import *
>
> ren = vtkRenderer()
> renWin = vtkRenderWindow()
> renWin.AddRenderer(ren)
> renWin.SetSize(300,300)
> iren = vtkRenderWindowInteractor()
> iren.SetRenderWindow(renWin)
>
> cone = vtkConeSource()
> cone.SetResolution(8)
> coneMapper = vtkPolyDataMapper()
> coneMapper.SetInput(cone.GetOutput())
>
> coneActor = vtkActor()
> coneActor.SetMapper(coneMapper)
>
> xform=vtkTransform()
> xform.Identity()
> xform.Translate(2,0,0)
> xform.Scale(1,1,-1)
>
> coneFlipActor = vtkActor()
> coneFlipActor.SetMapper(coneMapper)
> coneFlipActor.GetProperty().SetColor(1,0,0)
> coneFlipActor.SetUserMatrix(xform.GetMatrix())
>
> ren.AddActor(coneActor)
> ren.AddActor(coneFlipActor)
>
>
> # enable user interface interactor
> iren.Initialize()
>
> iren.Start()
> ----------------------------------------------------------
>
> catch {load vtktcl}
> # user interface command widget
> source ../../examplesTcl/vtkInt.tcl
>
>
> # create a rendering window and renderer
> vtkRenderer ren1
>   ren1 TwoSidedLightingOn
>
> vtkRenderWindow renWin
>     renWin AddRenderer ren1
> vtkRenderWindowInteractor iren
>     iren SetRenderWindow renWin
>
> # create an actor and give it cone geometry
> vtkConeSource cone
>   cone SetResolution 8
> vtkPolyDataMapper coneMapper
>   coneMapper SetInput [cone GetOutput]
> vtkActor coneActor
>   coneActor SetMapper coneMapper
>
> vtkTransform xform
>   xform Identity
>   xform Translate 2 0 0
>   xform Scale 1 1 -1
>
> vtkCleanPolyData cleaner
>   cleaner SetInput [cone GetOutput]
> #  coneFlipActor SetMapper coneMapper
>   coneFlipActor SetMapper flipMapper
>   [coneFlipActor GetProperty] SetColor 1 0 0
>   coneFlipActor SetUserMatrix [xform GetMatrix]
>   [coneFlipActor GetProperty] BackfaceCullingOff
>
> # assign actors to the renderer
> ren1 AddActor coneActor
> ren1 AddActor coneFlipActor
>
> # enable user interface interactor
> iren SetUserMethod {wm deiconify .vtkInteract}
> iren Initialize
>
> # prevent the tk window from showing up then start the event loop
> wm withdraw .
>
> vtkPolyDataNormals normals
> #  normals SetInput [cone GetOutput]
>   normals SetInput [cleaner GetOutput]
>   normals FlipNormalsOn
>
> vtkPolyDataMapper flipMapper
>   flipMapper SetInput [normals GetOutput]
>
>
> vtkActor coneFlipActor
>
>
>
> --------------------------------------------------------------------------
---
> This is the private VTK discussion list.  Please keep messages on-topic.
> Check the FAQ at: <http://www.automatrix.com/cgi-bin/vtkfaq>
> To UNSUBSCRIBE, send message body containing "unsubscribe vtkusers" to
> <majordomo at gsao.med.ge.com>.  For help, send message body containing
> "info vtkusers" to the same address.     Live long and prosper.
> --------------------------------------------------------------------------
---
>
>



-----------------------------------------------------------------------------
This is the private VTK discussion list.  Please keep messages on-topic.
Check the FAQ at: <http://www.automatrix.com/cgi-bin/vtkfaq>
To UNSUBSCRIBE, send message body containing "unsubscribe vtkusers" to
<majordomo at gsao.med.ge.com>.  For help, send message body containing
"info vtkusers" to the same address.     Live long and prosper.
-----------------------------------------------------------------------------




More information about the vtkusers mailing list