SetInterpolationToFlat do not work

I am using SetInterpolationToFlat, but I find it do not work.

The code to reproduce my question is:

import vtkmodules.all as vtk

nodes = [
    [ 3.56000000e+02,  2.56000000e+02,  0.00000000e+00],
    [ 1.56000000e+02,  1.56000000e+02,  1.22464676e-14],
    [ 1.56000000e+02,  2.06000000e+02, -8.66025391e+01],
    [ 1.56000000e+02,  3.06000000e+02, -8.66025391e+01],
    [ 1.56000000e+02,  3.56000000e+02, -2.44929351e-14],
    [ 1.56000000e+02,  3.06000000e+02,  8.66025391e+01],
    [ 1.56000000e+02,  2.06000000e+02,  8.66025391e+01]
]

elem = [
    [4, 0, 5, 3],
    [1, 2, 6, 0],
    [2, 5, 0, 3],
    [2, 5, 6, 0]
]


polydata = vtk.vtkPolyData()

points = vtk.vtkPoints()

for p in nodes:
    points.InsertNextPoint(p[0], p[1], p[2])

polys = vtk.vtkCellArray()
for e in elem:
    polys.InsertNextCell(len(e), list(e))

polydata.SetPoints(points)
polydata.SetPolys(polys)

mapper = vtk.vtkPolyDataMapper()
mapper.SetInputData(polydata)
actor = vtk.vtkActor()
actor.SetMapper(mapper)
actor.GetProperty().LightingOff()
actor.GetProperty().SetInterpolationToFlat()
actor.GetProperty().SetOpacity(0.3)

renderer = vtk.vtkRenderer()
renderer.AddActor(actor)
renWin = vtk.vtkRenderWindow()
renWin.AddRenderer(renderer)
iren = vtk.vtkRenderWindowInteractor()
iren.SetRenderWindow(renWin)
iren.Initialize()
iren.Start()

The result is:

I hope the following result:

Ang suggestion is appreciated~~~

Hi!
SetInterpolationToFlat is working correctly - it uses flat shading per-face, so each triangle is flat-shaded, but different triangles are shaded differently depending on the light.

What I think you want is to use only ambient lighting for your actor/model. If you take a look at the SpecularSpheres example, it shows how to set ambient, diffuse and specular terms on an actor. Set Ambient to 1, and diffuse and specular to 0, and set the color you want, and then experiment!

HTH,
Aron

Thank you very much for so detail answer.

It seems that you want to turn off shading. You can achieve that by calling actor.GetProperty().ShadingOff().

@Aron_Helser Unfortunately, setting value for ambient/diffuse/specular do not work.

actor.GetProperty().SetAmbient(1)
actor.GetProperty().SetDiffuse(0)
actor.GetProperty().SetSpecular(0)

Unfortunately, it do not work.

I think your elem is wrong… should be

elem = [[6, 5, 4, 3, 2, 1], [0, 1, 2], [0, 2, 3], [0, 3, 4], [0, 4, 5], [0, 5, 6], [0, 6, 1]]

With

actor.GetProperty().LightingOff()

Eg.

from vedo import Cone
cone = Cone(res=6).c('white').alpha(0.3)
#cone = vedo.Mesh([nodes, elem])
cone.lighting("off")
print(cone.points(), cone.faces())
cone.show(bg='black')

Screenshot from 2022-12-01 18-05-43

Actually, the elem is not generated from vtkConeSource.