File: demo_helloworld.m

package info (click to toggle)
octave-iso2mesh 1.9.8%2Bds-2
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 11,128 kB
  • sloc: cpp: 11,982; ansic: 10,158; sh: 365; makefile: 59
file content (74 lines) | stat: -rw-r--r-- 1,836 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Hello World - The "getting started" example of iso2mesh
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

% In this example, we illustrate the basic mesh density and precision
% controls in iso2mesh.

%% the first step is to load a binary or gray-scale image

hw = imread('helloworld.png');

% now we stack the image and form a binary volume

hw3d = 1 - repmat(hw, [1 1 50]);

%% create 3D mesh          |--------> threshold at v=0.7
[node, elem, face] = v2m(hw3d, 0.7, 5, 40);
%                             |  |-> maximum volume
%                             |----> maximum surface triangle size

figure;
subplot(211);
plotmesh(node, face);
axis equal;
view(90, 60);
subplot(212);
plotmesh(node, elem, 'z<20');
axis equal;
view(90, 60);

% mesh with denser surface    |----> surface triangle size is now 2
[node, elem, face] = v2m(hw3d, 0.7, 2, 40);

figure;
subplot(211);
plotmesh(node, face);
axis equal;
view(90, 60);
subplot(212);
plotmesh(node, elem, 'z<20');
axis equal;
view(90, 60);

%% create 3D mesh from gray-scale image to get smoother boundary
hw = imread('helloworld_gray.png');
hw3d = 255 - repmat(hw, [1 1 50]);
[node, elem, face] = v2m(hw3d, 128, 2, 40);

figure;
subplot(211);
plotmesh(node, face);
axis equal;
view(90, 60);
subplot(212);
plotmesh(node, elem, 'z<20');
axis equal;
view(90, 60);

%% create 3D mesh from gray-scale image with advanced distbound control
clear opt;
opt.radbound = 4;       % set surface triangle maximum size
opt.distbound = 0.2;    % set max distance that deviates from the level-set
opt.autoregion = 1;
[node, elem, face] = v2m(hw3d, 128, opt, 40);

figure;
subplot(211);
plotmesh(node, face);
axis equal;
view(90, 60);
subplot(212);
plotmesh(node, elem, 'z<20');
axis equal;
view(90, 60);