File: TestCellArray.py

package info (click to toggle)
vtk9 9.3.0%2Bdfsg1-4
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 267,116 kB
  • sloc: cpp: 2,195,914; ansic: 285,452; python: 104,858; sh: 4,061; yacc: 4,035; java: 3,977; xml: 2,771; perl: 2,189; lex: 1,762; objc: 153; makefile: 150; javascript: 90; tcl: 59
file content (81 lines) | stat: -rwxr-xr-x 1,924 bytes parent folder | download | duplicates (4)
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)