# Bug on vtkPolyData with vtkPolygons visualization?

**URL:** https://discourse.vtk.org/t/bug-on-vtkpolydata-with-vtkpolygons-visualization/14241
**Category:** Development
**Tags:** python
**Created:** [July 15, 2024, 3:56pm UTC](https://discourse.vtk.org/t/bug-on-vtkpolydata-with-vtkpolygons-visualization/14241 "2024-07-15T15:56:35Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![Andreas\_Scalas](https://discourse.vtk.org/user_avatar/discourse.vtk.org/andreas_scalas/32/2233_2.png) [@Andreas\_Scalas](https://discourse.vtk.org/u/Andreas_Scalas)
#### Post date: [July 15, 2024, 3:56pm UTC](https://discourse.vtk.org/t/bug-on-vtkpolydata-with-vtkpolygons-visualization/14241/1 "2024-07-15T15:56:35Z")

</div>

Hi there. I am trying to visualize some polyhedrons using VTK and I am doing so creating a vtkPolyData to which I add some vtkCells based on vtkPoints. The code is the following:

```auto
import vtk 

vertices = [
    (22.139882509829476, 28.506700079888105, 0.0),
    (19.552971637109295, 18.119234152138233, 0.0),
    (22.947173838037997, 19.112513148225844, 0.0),
    (24.09438818367198, 16.30976297799498, 0.0),
    (35.93263211194426, 19.17043448612094, 0.0),
    (36.137064285809174, 17.349102622829378, 0.0),
    (45.29673544713296, 18.913280420936644, 0.0),
    (45.360206936486065, 17.93620888516307, 0.0),
    (51.80617489898577, 18.004265196621418, 0.0),
    (51.49778024479747, 9.14836941473186, 0.0),
    (9.514526572311297, 1.1310951905325055, 0.0),
    (0.322818776126951, 0.0, 0.0),
    (0.0, 3.7754344679415226, 0.0),
    (4.988299750955775, 12.91897120140493, 0.0),
    (9.298819663468748, 33.47617264371365, 0.0),
    (12.619664103258401, 36.90060537587851, 0.0),
    (31.67879309738055, 30.80155537929386, 0.0),
    (29.75210563535802, 26.17147600464523, 0.0),
    (22.139882509829476, 28.506700079888105, 13.178603172302246),
    (19.552971637109295, 18.119234152138233, 13.178603172302246),
    (22.947173838037997, 19.112513148225844, 13.178603172302246),
    (24.09438818367198, 16.30976297799498, 13.178603172302246),
    (35.93263211194426, 19.17043448612094, 13.178603172302246),
    (36.137064285809174, 17.349102622829378, 13.178603172302246),
    (45.29673544713296, 18.913280420936644, 13.178603172302246),
    (45.360206936486065, 17.93620888516307, 13.178603172302246),
    (51.80617489898577, 18.004265196621418, 13.178603172302246),
    (51.49778024479747, 9.14836941473186, 13.178603172302246),
    (9.514526572311297, 1.1310951905325055, 13.178603172302246),
    (0.322818776126951, 0.0, 13.178603172302246),
    (0.0, 3.7754344679415226, 13.178603172302246),
    (4.988299750955775, 12.91897120140493, 13.178603172302246),
    (9.298819663468748, 33.47617264371365, 13.178603172302246),
    (12.619664103258401, 36.90060537587851, 13.178603172302246),
    (31.67879309738055, 30.80155537929386, 13.178603172302246),
    (29.75210563535802, 26.17147600464523, 13.178603172302246)
]

faces = [
    [0, 1, 19, 18, 0],
    [1, 2, 20, 19, 1],
    [2, 3, 21, 20, 2],
    [3, 4, 22, 21, 3],
    [4, 5, 23, 22, 4],
    [5, 6, 24, 23, 5],
    [6, 7, 25, 24, 6],
    [7, 8, 26, 25, 7],
    [8, 9, 27, 26, 8],
    [9, 10, 28, 27, 9],
    [10, 11, 29, 28, 10],
    [11, 12, 30, 29, 11],
    [12, 13, 31, 30, 12],
    [13, 14, 32, 31, 13],
    [14, 15, 33, 32, 14],
    [15, 16, 34, 33, 15],
    [16, 17, 35, 34, 16],
    [17, 0, 18, 35, 17],
    [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 0],
    [18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 18]
]

points = vtk.vtkPoints()
counter = 0
for vertex in vertices:
    points.InsertPoint(counter, [vertex[0], vertex[1], vertex[2]])
    counter += 1

polys = vtk.vtkCellArray()
for face in faces:
    
    polygon = vtk.vtkPolygon()
    counter = 0
    for vertex in face:
        polygon.GetPointIds().InsertNextId(vertex)
        counter += 1
            
        
    polygon.GetPointIds().SetNumberOfIds(counter)
    polys.InsertNextCell(polygon)
polyhedron = vtk.vtkPolyData()
polyhedron.SetPoints(points)
polyhedron.SetPolys(polys)
mapper = vtk.vtkPolyDataMapper()
mapper.SetInputData(polyhedron)
actor = vtk.vtkActor()
actor.SetMapper(mapper)
canvas = vtk.vtkPropAssembly()
renderer = vtk.vtkRenderer()
renderer.SetBackground(1, 1, 1)

canvas.AddPart(actor)

renderer.AddActor(canvas)
render_window = vtk.vtkRenderWindow()
render_window.AddRenderer(renderer)
render_window_interactor = vtk.vtkRenderWindowInteractor()
render_window_interactor.SetRenderWindow(render_window)
render_window.Render()
render_window_interactor.Start()

```

For some reason, this displays the following polyhedron which has serious topological issues:

 ![image](https://discourse.vtk.org/uploads/default/original/2X/b/b02f8cdb079ad00860457ea2e8e689c4f0b62219.png)  
 ![image](https://discourse.vtk.org/uploads/default/original/2X/8/8757e836418752a7b6300b4095eb411443d1d057.png)

Now, I thought that there could be some bug in my code, however if I pass to wireframe visualization the wrong parts simply disappear:

 ![image](https://discourse.vtk.org/uploads/default/original/2X/0/001ec7db2c458f138abad5b7ddacf87a2eb574e2.jpeg)

Can anyone help me? I have vtk 9.3.1 and I am working on Windows with an Anaconda env.

---

<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: [July 15, 2024, 4:53pm UTC](https://discourse.vtk.org/t/bug-on-vtkpolydata-with-vtkpolygons-visualization/14241/2 "2024-07-15T16:53:39Z")

</div>

Polygons must be convex for rendering. Further info:

[https://discourse.vtk.org/t/concave-polygon-issue-with-solid-representation-and-vtkdelaunay2d](https://discourse.vtk.org/t/concave-polygon-issue-with-solid-representation-and-vtkdelaunay2d)
