File: readgts.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 (43 lines) | stat: -rw-r--r-- 1,075 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
function [node, elem, edges, edgemap] = readgts(fname)
%
% [node,elem,edges,edgemap]=readgts(fname)
%
% read GNU Triangulated Surface files (GTS)
%
% author: Qianqian Fang, <q.fang at neu.edu>
% date: 2008/03/28
%
% input:
%    fname: name of the OFF data file
%
% output:
%    node: node coordinates of the mesh
%    elem: list of elements of the surface mesh
%    edges: the edge list section in the GTS file (optional)
%    edgemap: the face section (in terms of edge indices) in the GTS file
%             (optional)
%
% -- this function is part of iso2mesh toolbox (http://iso2mesh.sf.net)
%

node = [];
elem = [];
fid = fopen(fname, 'rb');
line = fgetl(fid);
dim = sscanf(line, '%d', 3);
node   = fscanf(fid, '%f', [3, dim(1)])';
edges  = fscanf(fid, '%d', [2, dim(2)])';
edgemap = fscanf(fid, '%d', [3, dim(3)])';
fclose(fid);

edget = edges';
len = size(edgemap, 1);
elem = reshape(edget(:, edgemap'), 6, len)';
try
    for i = 1:len
        elem(i, 1:3) = unique(elem(i, :));
    end
catch
    error(sprint('invalid GTS face, id=%d\n', i));
end
elem = elem(:, 1:3);