Efficient use of vtkPolyDataNormals to show smooth surfaces

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?

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!

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

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)

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

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.

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.

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.

Ok, thank you very much!