# import des different composants necessaires
import vtk
from vtk import *
import math
from math import *

nbpoints = 8
pointCoord = range(nbpoints)
pointCoord[0] = (0.0,0.0,0.0)
pointCoord[1] = (0.3,0.1,1.0)
pointCoord[2] = (0.7,0.1,-0.2)
pointCoord[3] = (0.5,1.2,1.1)
pointCoord[4] = (0.9,2.0,-0.3)
pointCoord[5] = (1.5,2.5,1.4)
pointCoord[6] = (0.2,3.4,-1.2)
pointCoord[7] = (2.0,4.0,-1.2)


ptData = range(nbpoints)
ptData[0] = 1.0
ptData[1] = 1.2
ptData[2] = 1.6
ptData[3] = 2.0
ptData[4] = 2.5
ptData[5] = 3.4
ptData[6] = 5.7
ptData[7] = 7.0

VTK_TETRA = 10
VTK_TRIANGLE = 5
VTK_LINE = 3
VTK_VERTEX = 1

vug = vtkUnstructuredGrid()
points = vtkPoints()
points.SetNumberOfPoints(nbpoints)

data = vtkFloatArray()
data.SetName("Some data")
data.SetNumberOfTuples(1)
data.SetNumberOfValues(nbpoints)

for i in range(nbpoints):
  points.SetPoint(i,pointCoord[i])

for i in range(nbpoints):
  data.InsertTuple1(i,ptData[i])
  
idList = vtkIdList()
idList.InsertNextId(0)
idList.InsertNextId(1)
idList.InsertNextId(2)
idList.InsertNextId(3)
vug.InsertNextCell(VTK_TETRA, idList)

idList = vtkIdList()
idList.InsertNextId(0)
idList.InsertNextId(2)
idList.InsertNextId(3)
idList.InsertNextId(4)
vug.InsertNextCell(VTK_TETRA, idList)

idList = vtkIdList()
idList.InsertNextId(3)
idList.InsertNextId(4)
idList.InsertNextId(5)
vug.InsertNextCell(VTK_TRIANGLE, idList)

idList = vtkIdList()
idList.InsertNextId(5)
idList.InsertNextId(6)
vug.InsertNextCell(VTK_LINE, idList)

idList = vtkIdList()
idList.InsertNextId(7)
vug.InsertNextCell(VTK_VERTEX, idList)

vug.SetPoints(points)
vug.GetPointData().SetScalars(data)