ParaView/Simple ParaView 3 Python Filters: Difference between revisions
From KitwarePublic
< ParaView
Jump to navigationJump to search
No edit summary |
No edit summary |
||
Line 39: | Line 39: | ||
newData.InsertNextValue(h) | newData.InsertNextValue(h) | ||
pdo.GetCellData().AddArray(newData) | pdo.GetCellData().AddArray(newData) | ||
# This filter flips the tetrahedra (useful, if you have different convention of | # This filter flips the tetrahedra (useful, if you have different convention of |
Revision as of 15:49, 5 December 2007
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 computes the radius h of the tetrahedra in an unstructured mesh: # Adapted by Johan Jansson (jjan@csc.kth.se) from math import * pdi = self.GetInput() pdo = self.GetOutput() newData = paraview.vtkDoubleArray() newData.SetName("h") 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)) c = [0.0, 0.0, 0.0] h = paraview.vtkTetra.Circumsphere(p1,p2,p3,p4,c) # VTK actually computes the square h = sqrt(h) newData.InsertNextValue(h) 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 )