File: demo_cgalmesher.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 (51 lines) | stat: -rw-r--r-- 1,567 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
% This example calls cgalmesher to mesh a segmented
% brain volume. The segmentation was done by FreeSurfer
% and there are 41 different types of tissues. Each tissue
% type is labeled by a unique integer.

fprintf(1, 'loading segmented brain image...\n');
for i = 1:256
    img = imread('brain_seg.tif', i);
    brain(:, :, i) = img;
end
brain = uint8(brain);

% call cgalmesher to mesh the segmented volume
% this will take 30 seconds on an Intel P4 2.4GHz PC

fprintf(1, 'meshing the segmented brain (this may take a few minutes) ...\n');

[node, elem, face] = v2m(brain, [], 2, 100, 'cgalmesh');

figure;
hs = plotmesh(node, face, 'y>100');

axis equal;
title('cross-cut view of the generated surface mesh');

% find the sub-region number 3, it happens to be the right-hemisphere
% cerebellum white matter. Use volface to extract the white matter surface.

fprintf(1, 'extracting the right-hemisphere cerebellum white matter surface\n');

LHwhitemat = elem(find(elem(:, 5) == 5), :);
wmsurf = volface(LHwhitemat(:, 1:4));

figure;
hs = plotmesh(node, wmsurf);
axis equal;
title('pre-smoothed cerebellum white matter surface');

fprintf(1, 'performing mesh smoothing on the white matter surface\n');

[no, el] = removeisolatednode(node, wmsurf);
wmno = sms(no(:, 1:3), el, 3, 0.5);

figure;
hs = plotmesh(wmno, el);
axis equal;
title('smoothed cerebellum white matter surface of the right-hemisphere');

fprintf(1, 'generate volumetric mesh from the smoothed cerebellum white matter surface \n');

[wmnode, wmelem, wmface] = s2m(wmno(:, 1:3), el(:, 1:3), 1, 200);