ParaView/Simple ParaView 3 Python Filters

From KitwarePublic
< ParaView
Revision as of 13:08, 20 June 2007 by Blloyd (talk | contribs) (Example Usage of Python Programmable Filter, added by B. Lloyd)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigationJump to search

Examples of Filters Programmed using the Python Programmable Filter

It would be nice, if you have written a possibly useful pp-filter, if you would add the code to this page. Here are some simple examples.

# This filter computes the volume of the tetrahedra in an unstructured mesh:
pdi = self.GetInput()
pdo = self.GetOutput()
newData = paraview.vtkDoubleArray()
newData.SetName("Volume")
numTets = pdi.GetNumberOfCells()
for i in range(0, numTets):
       cell = pdi.GetCell(i)
       p1 = pdi.GetPoint(cell.GetPointId(0))
       p2 = pdi.GetPoint(cell.GetPointId(1))
       p3 = pdi.GetPoint(cell.GetPointId(2))
       p4 = pdi.GetPoint(cell.GetPointId(3))
       volume = -paraview.vtkTetra.ComputeVolume(p1,p2,p3,p4)
       newData.InsertNextValue(volume)
pdo.GetCellData().AddArray(newData)


# This filter flips the tetrahedra (useful, if you have different convention of 
# tet orientation than VTK, and wish to use the vtkMeshQuality filter).
pdi = self.GetInput()
pdo = self.GetOutput()
numTets = pdi.GetNumberOfCells()
newcells = paraview.vtkCellArray()
for i in range(0, numTets):
       cell = pdi.GetCell(i)
       i1 = cell.GetPointId(0)
       i2 = cell.GetPointId(1)
       i3 = cell.GetPointId(2)
       i4 = cell.GetPointId(3)
       newcells.InsertNextCell(4)
       newcells.InsertCellPoint(i1)
       newcells.InsertCellPoint(i2)
       newcells.InsertCellPoint(i4)
       newcells.InsertCellPoint(i3)
pdo.SetCells( 10, newcells )