Extract Cell types from mesh in Paraview

It is often usefull to select cells by their type for visualization in Paraview. Visualizing boundary layer meshes for example or extracting the surface elements of a mesh can be done by using the following script in the Programmable filter of Paraview.

input = self.GetUnstructuredGridInput()
output = self.GetUnstructuredGridOutput();

# copy all curent data
output.GetPointData().PassData(input.GetPointData())
output.GetCellData().PassData(input.GetCellData())

# create an array holding the VTK cell type id of each element
cellTypes = vtk.vtkUnsignedCharArray()
cellTypes.DeepCopy(input.GetCellTypesArray())
cellTypes.SetName("Cell Types")
output.GetCellData().AddArray(cellTypes)

Even simpler you can import this file (export_cell_types.cpd) from the menu Tools>Manage Custom Filters… > Import.

[Read More]