Switch to unified view

a b/Cobiveco/functions/mmgReadMesh.m
1
function mesh = mmgReadMesh(filename)
2
3
fid = fopen(filename, 'r');
4
if ~fid
5
    error('Could not open %s for reading.', filename);
6
end
7
8
str = fgets(fid);
9
while str ~= -1
10
    
11
    if startsWith(str,'Vertices')
12
        N = str2double(fgets(fid));
13
        points = fscanf(fid,'%f %f %f %d',[4 N])';
14
        
15
    elseif startsWith(str,'Tetrahedra')
16
        N = str2double(fgets(fid));
17
        cells = fscanf(fid,'%d %d %d %d %d',[5 N])';
18
        
19
    end
20
    
21
    str = fgets(fid);
22
end
23
24
fclose(fid);
25
26
mesh.points = points(:,1:3);
27
mesh.cells = int32(cells(:,1:4));
28
mesh.cellData.class = uint8(cells(:,5));
29
mesh.cellTypes = repmat(uint8(10), size(cells,1), 1);
30
31
end