[vtkusers] Set vertex normals ?

Ronald Levine rl at quantcomp.com
Sat Oct 24 02:32:56 EDT 2015


Thanks, David, but that doesn't do the entire trick for me.

I'll paste below a simplified version of my code, using a triangle strip of
just 4 points in place of my very large data set of numerous triangle
strips.   Note that this produces a black triangle strip, no matter how you
interactively rotate it.    However, if you comment out the line 
pointData.SetNormals(normals)
then you get a nice flat shaded rendering, two-sided, using the default head
light.
Or, if you restore that line and change the actor to SetInterpolationFlat(),
again you get nice flat shading.  
This as run on Windows 7, Python 2.7.10

Thanks if you can tell me what's missing in the code.

Ronald


from vtk import *
points = vtkPoints()
normals = vtkFloatArray()
normals.SetNumberOfComponents(3)
normals.SetNumberOfTuples(4)
points.InsertNextPoint( (0.,1.,0.))
points.InsertNextPoint( (0.,0.,0.))
points.InsertNextPoint( (1.,1.,0.))
points.InsertNextPoint( (1.,0.,0.))
normals.InsertNextTuple3(0.,0.,1.)
normals.InsertNextTuple3(0.,0.,1.)
normals.InsertNextTuple3(0.,0.,1.)
normals.InsertNextTuple3(0.,0.,1.)


cells = vtkCellArray()
ts = vtkTriangleStrip()
ts.GetPointIds().SetNumberOfIds(4)
ts.GetPointIds().SetId(0,0)
ts.GetPointIds().SetId(1,1)
ts.GetPointIds().SetId(2,2)
ts.GetPointIds().SetId(3,3)  
cells.InsertNextCell(ts)
    
polydata = vtkPolyData()
polydata.SetPoints(points)
polydata.SetStrips(cells)
pointData = polydata.GetPointData()
pointData.SetNormals(normals)
  
tsmapper = vtkDataSetMapper()
tsmapper.SetInputData(polydata)

tsactor = vtkActor()
tsactor.SetMapper(tsmapper)
tsactor.GetProperty().SetDiffuseColor(.3,.7,1)
tsactor.GetProperty().SetInterpolationToGouraud()
 
ren = vtk.vtkRenderer()
renWin = vtk.vtkRenderWindow()
renWin.AddRenderer(ren)
renWin.SetSize(600, 600)
iren = vtk.vtkRenderWindowInteractor()
iren.SetRenderWindow(renWin)

ren.SetBackground(.1, .2, .4)
ren.AddActor(tsactor)
ren.ResetCamera()
ren.GetActiveCamera().Dolly(-8)

# Render the scene and start interaction.
iren.Initialize()
renWin.Render()
iren.Start()
  
    
     




--
View this message in context: http://vtk.1045678.n5.nabble.com/Set-vertex-normals-tp5734525p5734546.html
Sent from the VTK - Users mailing list archive at Nabble.com.


More information about the vtkusers mailing list