# SetInterpolationToFlat do not work

**URL:** https://discourse.vtk.org/t/setinterpolationtoflat-do-not-work/10015
**Category:** Support
**Created:** [November 30, 2022, 8:00am UTC](https://discourse.vtk.org/t/setinterpolationtoflat-do-not-work/10015 "2022-11-30T08:00:22Z")
**Posts on this page:** 8
**Page:** 1

<div class="post-metadata">

### Author: ![zhang-qiang-github](https://discourse.vtk.org/user_avatar/discourse.vtk.org/zhang-qiang-github/32/2519_2.png) [@zhang-qiang-github](https://discourse.vtk.org/u/zhang-qiang-github)
#### Post date: [November 30, 2022, 8:00am UTC](https://discourse.vtk.org/t/setinterpolationtoflat-do-not-work/10015/1 "2022-11-30T08:00:22Z")

</div>

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

The code to reproduce my question is:

```python
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:

 ![image](https://discourse.vtk.org/uploads/default/original/2X/1/1136cf4512957236152df0fe026f3a7e5ab31fa8.png)

I hope the following result:

 ![image](https://discourse.vtk.org/uploads/default/original/2X/4/4fcc2f3d629fd9c7d7e39015873a23f07bcfe43d.png)

Ang suggestion is appreciated~~~

---

<div class="post-metadata">

### Author: ![Aron\_Helser](https://discourse.vtk.org/user_avatar/discourse.vtk.org/aron_helser/32/14_2.png) [@Aron\_Helser](https://discourse.vtk.org/u/Aron_Helser)
#### Post date: [November 30, 2022, 2:41pm UTC](https://discourse.vtk.org/t/setinterpolationtoflat-do-not-work/10015/2 "2022-11-30T14:41:18Z")

</div>

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](https://gitlab.kitware.com/vtk/vtk/blob/479bc209c9c2c32a478c9e33e7677baa8574fcb8/Examples/Rendering/Cxx/SpecularSpheres.cxx) 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

---

<div class="post-metadata">

### Author: ![zhang-qiang-github](https://discourse.vtk.org/user_avatar/discourse.vtk.org/zhang-qiang-github/32/2519_2.png) [@zhang-qiang-github](https://discourse.vtk.org/u/zhang-qiang-github)
#### Post date: [November 30, 2022, 3:11pm UTC](https://discourse.vtk.org/t/setinterpolationtoflat-do-not-work/10015/3 "2022-11-30T15:11:16Z")

</div>

Thank you very much for so detail answer.

---

<div class="post-metadata">

### Author: ![lassoan](https://discourse.vtk.org/user_avatar/discourse.vtk.org/lassoan/32/50_2.png) [@lassoan](https://discourse.vtk.org/u/lassoan)
#### Post date: [November 30, 2022, 6:45pm UTC](https://discourse.vtk.org/t/setinterpolationtoflat-do-not-work/10015/4 "2022-11-30T18:45:16Z")

</div>

It seems that you want to turn off shading. You can achieve that by calling [actor.GetProperty().ShadingOff()](https://vtk.org/doc/nightly/html/classvtkProperty.html#a353608d2020e428b55e7f44bfeb21d98).

---

<div class="post-metadata">

### Author: ![zhang-qiang-github](https://discourse.vtk.org/user_avatar/discourse.vtk.org/zhang-qiang-github/32/2519_2.png) [@zhang-qiang-github](https://discourse.vtk.org/u/zhang-qiang-github)
#### Post date: [December 1, 2022, 1:44am UTC](https://discourse.vtk.org/t/setinterpolationtoflat-do-not-work/10015/5 "2022-12-01T01:44:56Z")

</div>

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

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

```

---

<div class="post-metadata">

### Author: ![zhang-qiang-github](https://discourse.vtk.org/user_avatar/discourse.vtk.org/zhang-qiang-github/32/2519_2.png) [@zhang-qiang-github](https://discourse.vtk.org/u/zhang-qiang-github)
#### Post date: [December 1, 2022, 1:45am UTC](https://discourse.vtk.org/t/setinterpolationtoflat-do-not-work/10015/6 "2022-12-01T01:45:37Z")

</div>

> [@lassoan](#):
>
> You can achieve that by calling [actor.GetProperty().ShadingOff()](https://vtk.org/doc/nightly/html/classvtkProperty.html#a353608d2020e428b55e7f44bfeb21d98).

Unfortunately, it do not work.

---

<div class="post-metadata">

### Author: ![marcomusy](https://discourse.vtk.org/user_avatar/discourse.vtk.org/marcomusy/32/95_2.png) [@marcomusy](https://discourse.vtk.org/u/marcomusy)
#### Post date: [December 1, 2022, 5:17pm UTC](https://discourse.vtk.org/t/setinterpolationtoflat-do-not-work/10015/7 "2022-12-01T17:17:44Z")

</div>

I think your `elem` is wrong… should be

```python
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

```python
actor.GetProperty().LightingOff()

```

Eg.

```python
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](https://discourse.vtk.org/uploads/default/original/2X/0/0f9de2ea46fa57a540ee2fd186b7ace447a8e4bd.png)

---

<div class="post-metadata">

### Author: ![zhang-qiang-github](https://discourse.vtk.org/user_avatar/discourse.vtk.org/zhang-qiang-github/32/2519_2.png) [@zhang-qiang-github](https://discourse.vtk.org/u/zhang-qiang-github)
#### Post date: [December 6, 2022, 1:43am UTC](https://discourse.vtk.org/t/setinterpolationtoflat-do-not-work/10015/8 "2022-12-06T01:43:45Z")

</div>

Actually, the `elem` is not generated from `vtkConeSource`.
