# Efficient use of vtkPolyDataNormals to show smooth surfaces

**URL:** https://discourse.vtk.org/t/efficient-use-of-vtkpolydatanormals-to-show-smooth-surfaces/10635
**Category:** Support
**Tags:** python
**Created:** [February 7, 2023, 9:51am UTC](https://discourse.vtk.org/t/efficient-use-of-vtkpolydatanormals-to-show-smooth-surfaces/10635 "2023-02-07T09:51:39Z")
**Posts on this page:** 7
**Page:** 1

<div class="post-metadata">

### Author: ![sotodela](https://discourse.vtk.org/user_avatar/discourse.vtk.org/sotodela/32/6513_2.png) [@sotodela](https://discourse.vtk.org/u/sotodela)
#### Post date: [February 7, 2023, 9:51am UTC](https://discourse.vtk.org/t/efficient-use-of-vtkpolydatanormals-to-show-smooth-surfaces/10635/1 "2023-02-07T09:51:39Z")

</div>

Hi,

I am using vtkLookupTable() and vtkUnsignedCharArray() to re-color a mesh. The Array that contains the colors is modified several times interactively. The problem I have is that to show the actor with a smooth surface I am using vtkPolyDataNormals, as shown below, but I have to create vtkPolydataNormals() everytime I need to recolor the actor. I can create the mapper only once and modify it but it has not been possible to do the same with the vtkPolydataNormals().  
Is there a way to achieve a smooth surface in an efficient manner?

```auto
def Recolor_Actor(self, mesh):
        normals = vtkPolyDataNormals()
        normals.SetInputData(mesh)
        normals.SetFeatureAngle(80)
        normals.AutoOrientNormalsOn()
        normals.Update()
        self.mapper.SetInputData(normals.GetOutput())
        self.mapper.ScalarVisibilityOn()
        actor.SetMapper(self.mapper)

```

Thanks!

---

<div class="post-metadata">

### Author: ![dgobbi](https://discourse.vtk.org/user_avatar/discourse.vtk.org/dgobbi/32/18_2.png) [@dgobbi](https://discourse.vtk.org/u/dgobbi)
#### Post date: [February 7, 2023, 1:09pm UTC](https://discourse.vtk.org/t/efficient-use-of-vtkpolydatanormals-to-show-smooth-surfaces/10635/2 "2023-02-07T13:09:31Z")

</div>

Re-applying vtkPolyDataNormals shouldn’t be necessary. Can you show the code where you apply the lookup table?

---

<div class="post-metadata">

### Author: ![sotodela](https://discourse.vtk.org/user_avatar/discourse.vtk.org/sotodela/32/6513_2.png) [@sotodela](https://discourse.vtk.org/u/sotodela)
#### Post date: [February 7, 2023, 1:27pm UTC](https://discourse.vtk.org/t/efficient-use-of-vtkpolydatanormals-to-show-smooth-surfaces/10635/3 "2023-02-07T13:27:45Z")

</div>

Hi, thank you for you reply, this in an example of where I apply the lookup table:

```
        lut = self.CreateLUTtable(self.min, self.max)

        self.colors_init.SetNumberOfComponents(3)
        self.colors_init.Fill(255)

        for h in range(self.radius_list.GetNumberOfIds()):
            dcolor = 3 * [0.0]
            index_id = self.radius_list.GetId(h)
            lut.GetColor(self.efieldnorms[index_id], dcolor)
            color = 3 * [0.0]
            for j in range(0, 3):
                color[j] = int(255.0 * dcolor[j])
            self.colors_init.InsertTuple(index_id, color)
        mesh.GetPointData().SetScalars(self.colors_init)
        self.Recolor_Actor(mesh)

```

---

<div class="post-metadata">

### Author: ![dgobbi](https://discourse.vtk.org/user_avatar/discourse.vtk.org/dgobbi/32/18_2.png) [@dgobbi](https://discourse.vtk.org/u/dgobbi)
#### Post date: [February 7, 2023, 2:00pm UTC](https://discourse.vtk.org/t/efficient-use-of-vtkpolydatanormals-to-show-smooth-surfaces/10635/4 "2023-02-07T14:00:25Z")

</div>

You can apply the lookup table with the mapper instead of changing the mesh dataset:

```python
mapper.SetLookupTable(lut)
mapper.SetScalarRange(self.min, self.max)

```

Changing the appearance of the dataset via the mapper and/or actor is always more efficient than modifying the dataset itself. Modifying the dataset always requires that downstream filters have to re-execute.

To be more clear, what I’m saying is that the mesh scalars should be the `efieldnorms`, not the colors. The coloring can be applied (very efficiently) by the mapper.

---

<div class="post-metadata">

### Author: ![sotodela](https://discourse.vtk.org/user_avatar/discourse.vtk.org/sotodela/32/6513_2.png) [@sotodela](https://discourse.vtk.org/u/sotodela)
#### Post date: [February 7, 2023, 2:16pm UTC](https://discourse.vtk.org/t/efficient-use-of-vtkpolydatanormals-to-show-smooth-surfaces/10635/5 "2023-02-07T14:16:06Z")

</div>

Hi,

Ok thank you! I will look into it. I just found examples using the LUT this way, since I am just coloring a circle that moves interactively on the surface of the mesh.

---

<div class="post-metadata">

### Author: ![dgobbi](https://discourse.vtk.org/user_avatar/discourse.vtk.org/dgobbi/32/18_2.png) [@dgobbi](https://discourse.vtk.org/u/dgobbi)
#### Post date: [February 7, 2023, 2:24pm UTC](https://discourse.vtk.org/t/efficient-use-of-vtkpolydatanormals-to-show-smooth-surfaces/10635/6 "2023-02-07T14:24:55Z")

</div>

The mapper applies the LUT to the whole mesh, not just part of the mesh. So if you’re only recoloring part of the mesh, then what I suggested will not work.

Instead, you can generate the normals _before_ recoloring the mesh, instead of after. The `vtkPolyDataNormals` filter can be used on meshes that have no scalars.

---

<div class="post-metadata">

### Author: ![sotodela](https://discourse.vtk.org/user_avatar/discourse.vtk.org/sotodela/32/6513_2.png) [@sotodela](https://discourse.vtk.org/u/sotodela)
#### Post date: [February 7, 2023, 2:28pm UTC](https://discourse.vtk.org/t/efficient-use-of-vtkpolydatanormals-to-show-smooth-surfaces/10635/7 "2023-02-07T14:28:41Z")

</div>

Ok, thank you very much!
