demo07 of Im2mesh package
demo07 - Function plotMeshes
Note
I suggest familiarizing yourself with Im2mesh_GUI before learning Im2mesh package. With graphical user interface, Im2mesh_GUI will help you better understand the workflow and parameters of Im2mesh package. No need to install any MATLAB toolboxes when running this demo. Initialize
Before we start, please set folder "Im2mesh_Matlab" as your current folder of MATLAB.
Set default image size (optional).
x = 250; y = 250; width = 300; height = 300;
set(groot, 'DefaultFigurePosition', [x,y,width,height])
% set(groot, 'DefaultFigurePosition', 'factory')
Function im2mesh use a mesh generator called MESH2D (developed by Darren Engwirda). We can use the following command to add the folder 'mesh2d-master' to the path of MATLAB.
addpath(genpath('mesh2d-master'))
Overview
We will demostrate function plotMeshes in this demo.
There are 4 typical usage of function plotMeshes
% plotMeshes( vert, ele );
% plotMeshes( vert, ele, tnum );
% plotMeshes( vert, ele, tnum, color );
% plotMeshes( vert,ele,tnum, color, opt )
The meanings of the input arguments are as follows:
color: Color code for selecting colormap. Interger. Value: 0-10. Default value: 0
0: grayscale, 1: lines, 2: parula, 3: turbo, 4: jet, 5: hot, 6: cool, 7: summer, 8: winter, 9: bone, 10: pink.
opt: a structure array. It is the extra options for plotMeshes. It stores extra parameter settings for plotMeshes.
opt.mode: display mode. Value: 1 or 2.
opt.wid: line width of the plotted edges. Default value: 0.5
opt.alpha: edge line transparency. It's a scalar value in range [0,1]. Default value: 0.5
opt.beta: brightness adjustment of colormap. [-1, 1]. Default value: 0
opt.tf_gs: Boolean value. Whether to use graphics smoothing when plotting. Default value: 1
opt.q_thresh: threshold for mesh quality. Those elements with mesh quality lower than opt.q_thresh will be highlighted. Default value: 0
Import image
if size(im,3) == 3; im = rgb2gray( im ); end
imshow( im,'InitialMagnification','fit' );
Generate mesh
[ vert, tria, tnum, vert2, tria2 ] = im2mesh( im, opt );
Refine triangulation...
-------------------------------------------------------
|ITER.| |CDT1(X)| |CDT2(X)|
-------------------------------------------------------
9 128 110
10 128 223
17 163 449
Refine triangulation...
-------------------------------------------------------
|ITER.| |CDT1(X)| |CDT2(X)|
-------------------------------------------------------
10 275 110
18 299 110
20 307 855
30 324 2209
33 324 2215
Smooth triangulation...
-------------------------------------------------------
|ITER.| |MOVE(X)| |DTRI(X)|
-------------------------------------------------------
10 64 2193
Plot mesh
plotMeshes( vert, tria, tnum )
Select colormap
plotMeshes( vert,tria,tnum, color )
Set display mode
When opt.mode=1, plot faces and edges. Slower.
When opt.mode=2, plot edges only. Faster.
Default value: 1
plotMeshes( vert,tria,tnum, color, opt )
Other settings
When the mesh data is huge, I usually set 'opt.alpha' to 0.2-0.3.
plotMeshes( vert,tria,tnum, color, opt )
Highlight low quality elements
Those elements with mesh quality lower than 'opt.q_thresh' will be highlighted.
You can set color to 0 to faciliate the visualization.
plotMeshes( vert,tria,tnum, color, opt )
set(groot, 'DefaultFigurePosition', 'factory')