[390c2f]: / Cobiveco / functions / mmgReadMesh.m

Download this file

32 lines (22 with data), 659 Bytes

 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
function mesh = mmgReadMesh(filename)
fid = fopen(filename, 'r');
if ~fid
error('Could not open %s for reading.', filename);
end
str = fgets(fid);
while str ~= -1
if startsWith(str,'Vertices')
N = str2double(fgets(fid));
points = fscanf(fid,'%f %f %f %d',[4 N])';
elseif startsWith(str,'Tetrahedra')
N = str2double(fgets(fid));
cells = fscanf(fid,'%d %d %d %d %d',[5 N])';
end
str = fgets(fid);
end
fclose(fid);
mesh.points = points(:,1:3);
mesh.cells = int32(cells(:,1:4));
mesh.cellData.class = uint8(cells(:,5));
mesh.cellTypes = repmat(uint8(10), size(cells,1), 1);
end