1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81
|
#!/usr/bin/env python
import os
from vtkmodules.vtkCommonCore import (
vtkIdList,
vtkPoints,
)
from vtkmodules.vtkCommonDataModel import vtkUnstructuredGrid
from vtkmodules.vtkIOXML import (
vtkXMLUnstructuredGridReader,
vtkXMLUnstructuredGridWriter,
)
from vtkmodules.util.misc import vtkGetTempDir
VTK_TEMP_DIR = vtkGetTempDir()
filename = VTK_TEMP_DIR + '/TestCellArray.vtu'
ugrid = vtkUnstructuredGrid()
pts = vtkPoints()
ugrid.SetPoints(pts)
ugrid.Allocate(10)
for i in range(10):
pts.InsertNextPoint(i, i, i)
ids = [i]
ugrid.InsertNextCell(1, 1, ids) # a vertex
writer = vtkXMLUnstructuredGridWriter()
writer.SetInputDataObject(ugrid)
writer.SetFileName(filename)
writer.Write()
reader = vtkXMLUnstructuredGridReader()
reader.SetFileName(filename)
reader.Update()
readergrid = reader.GetOutput()
copygrid = readergrid.NewInstance()
copygrid.DeepCopy(readergrid)
pts = copygrid.GetPoints()
#o.SetPoints(pts)
pt = [1, 2, 3]
idlist = vtkIdList()
idlist.SetNumberOfIds(1)
for i in range(5):
newpt = [10+i, 10+i, 10+i]
pts.InsertNextPoint(newpt)
iii = [copygrid.GetNumberOfPoints()-1]
copygrid.InsertNextCell(1, 1, iii)
copygrid.GetCellPoints(copygrid.GetNumberOfCells()-1, idlist)
if copygrid.GetNumberOfPoints() != 15 or copygrid.GetNumberOfCells() != 15:
print ("ERROR: incorrect number of points and or cells")
import sys
sys.exit(1)
count = 0
ci = copygrid.NewCellIterator()
# Now we verify that each vertex has the proper point (the cell id should be the point id)
while ci.IsDoneWithTraversal() == False:
id = ci.GetCellId()
ids = ci.GetPointIds()
copygrid.GetCellPoints(id, idlist)
if ids.GetId(0) != idlist.GetId(0) or idlist.GetId(0) != count:
print ("ERROR: incorrect cell points ", count, id, ids.GetId(0), idlist.GetId(0))
import sys
sys.exit(1)
count = count+1
ci.GoToNextCell()
ci.UnRegister(None)
ci = None
os.remove(filename)
|