Lighting question

Randall Hopper aa8vb at yahoo.com
Mon May 15 12:03:28 EDT 2000


Last week I was experimenting with methods to build 3D (thick) half
cylinders using VTK primitives.  This one (attached), which uses
differences of implicit cylinders, produces some odd lighting behavior I
don't understand.

As you can see, up top I request that VTK have the light follow the camera.
Either this isn't happening, or there is something odd about the lighting
properties associated with the outside of the cylinder.

Any thoughts?

Thanks,

Randall


-- 
Randall Hopper
aa8vb at yahoo.com
-------------- next part --------------
#!/usr/bin/env python
"""
  DisplayCylinder.py : Create a cylinder using an implicit function

"""      


from libVTKCommonPython import *
from libVTKGraphicsPython import *
from libVTKImagingPython import *

banana = ( 0.8900, 0.8100, 0.3400 )
peacock = ( 0.2000, 0.6300, 0.7900 )

#------------------------------------------------------------------------------

# Create the RenderWindow, Renderer, and Interactor
#
ren = vtkRenderer()
ren_win = vtkRenderWindow()
ren_win.AddRenderer( ren )

# Create interactor
iren = vtkRenderWindowInteractor()
iren.SetRenderWindow( ren_win )
iren.LightFollowCameraOn()

# Change interactor style
style = vtkInteractorStyleTrackball()
iren.SetInteractorStyle( style )
style.SetTrackballModeToTrackball()

#------------------------------------------------------------------------------

# Create a "thick" cylinder by differencing two implicit cylinders
cyl = vtkCylinder()
cyl.SetRadius( 1.0 )

cyl2 = vtkCylinder()
cyl2.SetRadius( 0.9 )

bool = vtkImplicitBoolean()
bool.SetOperationTypeToDifference()
bool.AddFunction( cyl )
bool.AddFunction( cyl2 )

sample = vtkSampleFunction()
sample.SetImplicitFunction( bool )
sample.SetModelBounds( -1.1, 1.1, -1.0, 1.0, -1.1, 1.1 )
sample.CappingOn()
sample.ComputeNormalsOn()

iso = vtkContourFilter()
iso.SetInput( sample.GetOutput() )
iso.SetValue( 0, 0.0 )

reverse = vtkReverseSense()
reverse.SetInput( iso.GetOutput() )
reverse.ReverseNormalsOn()

#------------------------------------------------------------------------------

cyl_trans = vtkTransform()
cyl_trans.Identity()
cyl_trans.RotateY( 45 )
cyl_trans.RotateX( 70 )

cyl_trans_filter = vtkTransformPolyDataFilter()
cyl_trans_filter.SetInput( reverse.GetOutput() )
cyl_trans_filter.SetTransform( cyl_trans )

mapper = vtkPolyDataMapper()
mapper.SetInput( cyl_trans_filter.GetOutput() )
mapper.ScalarVisibilityOff()

back = vtkProperty()
back.SetDiffuseColor( banana )

actor = vtkLODActor()
actor.SetMapper( mapper )
actor.SetBackfaceProperty( back )
actor.GetProperty().SetDiffuseColor( peacock )

ren.AddActor( actor )

ren.SetBackground( .8, .8, 2 )

ren_win.SetPosition( 0, 0 )
ren_win.SetSize( 640, 480 )

camera = ren.GetActiveCamera()
camera.Zoom(2)

#light = vtkLight()
#light.SetPosition( 10,0,0 )
#light.SetFocalPoint( 0,0,0 )
#ren.AddLight( light )

lights = ren.GetLights()
lights.InitTraversal()
while 1:
   light = lights.GetNextItem()
   if not light: break
   print light

ren_win.Render()

# enable user interface interactor
iren.Initialize()
iren.Start()


More information about the vtkusers mailing list