image thumbnail

meshplot: Fast FE mesh visualization using VTK (OpenGL)

version 1.0.0 (476 KB) by Carlos Souto
A function for visualizing finite element meshes with optional nodal scalar fields using Python and VTK (OpenGL). Code is documented.

10 Downloads

Updated 10 Sep 2021

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 (2021). meshplot: Fast FE mesh visualization using VTK (OpenGL) (https://www.mathworks.com/matlabcentral/fileexchange/99024-meshplot-fast-fe-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!