meshplot: Fast FEM mesh visualization using VTK (OpenGL)

A function for visualizing finite element meshes with optional nodal scalar fields using Python and VTK (OpenGL). Code is documented.
168 Downloads
Updated 31 Mar 2022

View License

A function for visualizing finite element meshes with optional nodal scalar fields using Python and VTK (OpenGL). Code is documented.
Requirments:
1) Python. You can install Python from https://www.python.org/downloads/.
2) VTK (Python package). Once Python is installed, you can install the VTK package by running the command pip install vtk from the command prompt.
Note: if pip install vtk does not work, you may have a Python version that is too recent and VTK may not yet be available for your version (install an older version of Python to proceed).
You can call meshplot like so:
% plot the mesh only
meshplot(nodes, elements);
% plot the mesh with a nodal scalar field
meshplot(nodes, elements, scalars);
% plot the mesh with a nodal scalar field and specify the scalar range
meshplot(nodes, elements, scalars, [100 400]);
% specify optional arguments
meshplot(nodes, elements, scalars, 'ShowLines', false, 'Colormap', jet(32), 'Title', 'Stress (MPa)');
nodes is a n-by-3 matrix containing the (x, y, z) coordinates of each node, where n is the number of nodes.
nodes = [
x1, y1, z1
x2, y2, z2
...
xn, yn, zn
];
elements is a 1D struct array containing the element data with the following fields:
  • elements(i).NodeIndices: a vector containing the node indices (connectivity) of the i-th element.
  • elements(i).CellType: the VTK cell type (vtkCellType.VTK_QUAD, vtkCellType.VTK_TETRA, etc.); see vtkCellType.m for the full list.
% (example) defining the 5th element
elements(5).NodeIndices = [14, 2, 15, 213];
elements(5).CellType = vtkCellType.VTK_QUAD;
scalars (optional) is a vector with length n containing the values of the nodal scalar field, where n is the number of nodes.
scalars = [v1, v2, ..., vn];

Cite As

Carlos Souto (2024). meshplot: Fast FEM mesh visualization using VTK (OpenGL) (https://www.mathworks.com/matlabcentral/fileexchange/99024-meshplot-fast-fem-mesh-visualization-using-vtk-opengl), MATLAB Central File Exchange. Retrieved .

MATLAB Release Compatibility
Created with R2021a
Compatible with any release
Platform Compatibility
Windows macOS Linux
Tags Add Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!
Version Published Release Notes
1.0.1

Title change.

1.0.0