1#!/usr/bin/env python
2
3import vtk
4import sys
5
6def CheckFilter(inputDS):
7    numOrigCells = inputDS.GetNumberOfCells()
8    ghostArray = vtk.vtkUnsignedCharArray()
9    ghostArray.SetNumberOfTuples(numOrigCells)
10    ghostArray.SetName(vtk.vtkDataSetAttributes.GhostArrayName())
11    ghostArray.Fill(0)
12
13    inputDS.GetCellData().AddArray(ghostArray)
14
15    removeGhosts = vtk.vtkRemoveGhosts()
16    removeGhosts.SetInputDataObject(inputDS)
17    removeGhosts.Update()
18
19    outPD = removeGhosts.GetOutput()
20
21    if outPD.GetNumberOfCells() != numOrigCells:
22        print("Should have the same amount of cells but did not", outPD.GetNumberOfCells(), numOrigCells)
23        sys.exit(1)
24
25    ghostArray.SetValue(0, 1)
26    ghostArray.Modified()
27    removeGhosts.Modified()
28    removeGhosts.Update()
29
30    if outPD.GetNumberOfCells() != numOrigCells-1:
31        print("Should have had one less cell but did not", outPD.GetNumberOfCells(), numOrigCells)
32        sys.exit(1)
33
34
35# =================== testing polydata ========================
36
37disk = vtk.vtkDiskSource()
38disk.SetRadialResolution(2)
39disk.SetCircumferentialResolution(9)
40
41disk.Update()
42
43CheckFilter(disk.GetOutput())
44
45# =================== testing unstructured grid ========================
46
47cellTypeSource = vtk.vtkCellTypeSource()
48cellTypeSource.SetBlocksDimensions(4, 5, 6)
49
50cellTypeSource.Update()
51
52CheckFilter(cellTypeSource.GetOutput())
53
54print("SUCCESS")
55sys.exit(0)
56