Writing a Polydatamapper to vtk

Hi All,

The following code creates polygons from point and adds polygons. I eventually write this appended data to a vtk file. I want to color these polygons to a specific RGB color so that when I load the vtk file in Paraview glance, I can see the colors instead of solid colors. I have checked several examples on and I learned that the way to assign colors is to use a lookuptable and a mapper. Now the question is, Can I write a mapper to a vtk file or I should not think about mappers at all in this case?

def create_polygon(points):
    """Create a vtk Polygon from a list of points.
    The point will have to be in an order. This function cannot be used to create a
    polygon with holes.

        points: A list of points. Here, each point is a list of X, Y, and Z cordinate.

        A tuple with two elements.
        - vtk_points: A list of vtk point objects
        - vtk_polygon: A vtk polygon object created from the points provided.

    vtk_points = vtk.vtkPoints()
    vtk_polygon = vtk.vtkPolygon()

    for point in points:

    for i in range(len(points)):
        vtk_polygon.GetPointIds().SetId(i, i)

    return vtk_points, vtk_polygon

def create_polygons(points_lst):
    """Create a vtk object with multiple vtk polygons.
        points_lst: A list of lists of points. Here, each point is a list of X, Y, 
            and Z cordinate.

        A vtk object that has multiple vtk polygons.

    vtk_polydata_lst = []

    for i in range(len(points_lst)):
        # Create a list of vtk polydata objects with polygons
        vtk_points, vtk_polygon = create_polygon(points_lst[i])
        vtk_polygons = vtk.vtkCellArray()

        vtk_polydata = vtk.vtkPolyData()


    # Create a vtk object with multiple polygons
    vtk_polydata_extended = vtk.vtkAppendPolyData()

    for i in range(len(vtk_polydata_lst)):


    return vtk_polydata_extended

I wouldn’t use lookup tables, but would add an array of scalar values to the cells. You can add several different scalar arrays, and set one of them as the default. Paraview (and glance) will then use that to colour the cells, and you can switch between the different data sets to get different colouring options.

Hey @Euan,
That sounds very promising. I know how to assign scalars to celldata. However, I don’t know how to set them as Default so that when I load them in Paraview, the file can be loaded with the scalar rather than the solid color. Can you share how I can do that please?