# vtkPolyData with vtkTetra

**URL:** https://discourse.vtk.org/t/vtkpolydata-with-vtktetra/1355
**Category:** Support
**Created:** [July 16, 2019, 4:04pm UTC](https://discourse.vtk.org/t/vtkpolydata-with-vtktetra/1355 "2019-07-16T16:04:18Z")
**Posts on this page:** 3
**Page:** 1

<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: [July 16, 2019, 4:04pm UTC](https://discourse.vtk.org/t/vtkpolydata-with-vtktetra/1355/1 "2019-07-16T16:04:18Z")

</div>

In this slightly modified version of this [example](https://cmake.org/Wiki/VTK/Examples/Python/GeometricObjects/Display/Tetrahedron):

```python
import vtk

points = vtk.vtkPoints()
points.InsertNextPoint(0, 0, 0)
points.InsertNextPoint(1, 0, 0)
points.InsertNextPoint(1, 1, 0)
points.InsertNextPoint(0, 1, 1)

points.InsertNextPoint(2, 2, 2)
points.InsertNextPoint(3, 2, 2)
points.InsertNextPoint(3, 3, 2)
points.InsertNextPoint(2, 3, 3)

# The first tetrahedron
data1 = vtk.vtkUnstructuredGrid()
data1.SetPoints(points)

tetra = vtk.vtkTetra()

tetra.GetPointIds().SetId(0, 0)
tetra.GetPointIds().SetId(1, 1)
tetra.GetPointIds().SetId(2, 2)
tetra.GetPointIds().SetId(3, 3)

cellArray = vtk.vtkCellArray()
cellArray.InsertNextCell(tetra)
data1.SetCells(vtk.VTK_TETRA, cellArray)

# The second tetrahedron
#data2 = vtk.vtkUnstructuredGrid() ########## <---
data2 = vtk.vtkPolyData()
data2.SetPoints(points)

tetra = vtk.vtkTetra()

tetra.GetPointIds().SetId(0, 4)
tetra.GetPointIds().SetId(1, 5)
tetra.GetPointIds().SetId(2, 6)
tetra.GetPointIds().SetId(3, 7)

cellArray = vtk.vtkCellArray()
cellArray.InsertNextCell(tetra)
#data2.SetCells(vtk.VTK_TETRA, cellArray) ########## <---
data2.SetPolys(cellArray)

# Create a mapper and actor
mapper1 = vtk.vtkDataSetMapper()
mapper1.SetInputData(data1)

actor1 = vtk.vtkActor()
actor1.SetMapper(mapper1)

# Create a mapper and actor
mapper2 = vtk.vtkDataSetMapper()
mapper2.SetInputData(data2)

actor2 = vtk.vtkActor()
actor2.SetMapper(mapper2)

# Create a renderer, render window, and interactor
renderer = vtk.vtkRenderer()
renderWindow = vtk.vtkRenderWindow()
renderWindow.AddRenderer(renderer)
renderWindowInteractor = vtk.vtkRenderWindowInteractor()
renderWindowInteractor.SetRenderWindow(renderWindow)

# Add the actor to the scene
renderer.AddActor(actor1)
renderer.AddActor(actor2)
renderer.SetBackground(.3, .6, .3) # Background color green

# Render and interact
renderWindow.Render()
renderWindowInteractor.Start()

```

No nerror message but the tetrahedron is not visualized correctly (it’s like one face is missing in the lower tetrahedron) whereas using `vtkUnstructuredGrid` instead of `vtkPolyData` it looks ok.  
Shouldn’t the two behave the same in this example?  
Thanks a lot

 ![image](https://discourse.vtk.org/uploads/default/original/1X/98bb7184aa2123cefce666d7a24564f8ed21892b.png)

---

<div class="post-metadata">

### Author: ![Michael](https://discourse.vtk.org/user_avatar/discourse.vtk.org/michael/32/16_2.png) [@Michael](https://discourse.vtk.org/u/Michael)
#### Post date: [July 17, 2019, 8:35am UTC](https://discourse.vtk.org/t/vtkpolydata-with-vtktetra/1355/2 "2019-07-17T08:35:54Z")

</div>

This is probably an issue with the orientation of the base of the tetra.  
Try to swap index 1 and index 2 of the points:

```
tetra.GetPointIds().SetId(0, 4)
tetra.GetPointIds().SetId(1, 6) // <--
tetra.GetPointIds().SetId(2, 5) // <--
tetra.GetPointIds().SetId(3, 7)
```

---

<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: [July 17, 2019, 10:50am UTC](https://discourse.vtk.org/t/vtkpolydata-with-vtktetra/1355/3 "2019-07-17T10:50:18Z")

</div>

Even when swapping I get the same:  
 ![Screenshot%20from%202019-07-17%2012-31-16](https://discourse.vtk.org/uploads/default/original/1X/4139f743bbef03cde571ffc7fe9b20838d7f67b6.png)

`print(data2)` gives:

vtkPolyData (0x55adc58a4380)  
Debug: Off  
Modified Time: 504  
Reference Count: 1  
Registered Events: (none)  
Information: 0x55adc58a4500  
Data Released: False  
Global Release Data: Off  
UpdateTime: 0  
Field Data:  
Debug: Off  
Modified Time: 287  
Reference Count: 1  
Registered Events: (none)  
Number Of Arrays: 0  
Number Of Components: 0  
Number Of Tuples: 0  
Number Of Points: 8  
Number Of Cells: 1  
…

But I see from documentation that vtkTetra is not supported as cell type  
[https://vtk.org/doc/nightly/html/classvtkPolyData.html](https://vtk.org/doc/nightly/html/classvtkPolyData.html)  
_“The actual cell types (vtkCellType.h) supported by vtkPolyData are: vtkVertex, vtkPolyVertex, vtkLine, vtkPolyLine, vtkTriangle, vtkQuad, vtkPolygon, and vtkTriangleStrip.”_
