-
Notifications
You must be signed in to change notification settings - Fork 0
/
write_off.m
53 lines (43 loc) · 963 Bytes
/
write_off.m
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
function write_off(filename, vertex, face, renormalize);
% write_off - write a mesh to a OFF file
%
% write_off(filename, vertex, face);
%
% vertex must be of size [n,3]
% face must be of size [p,3]
%
% Copyright (c) 2003 Gabriel Peyré
if nargin<4
renormalize = 0;
end
if size(vertex,2)~=3
vertex=vertex';
end
if size(vertex,2)~=3
error('vertex does not have the correct format.');
end
if renormalize==1
m = mean(vertex);
s = std(vertex);
for i=1:3
vertex(:,i) = (vertex(:,i)-m(i))/s(i);
end
end
if size(face,2)~=3
face=face';
end
if size(face,2)~=3
error('face does not have the correct format.');
end
fid = fopen(filename,'wt');
if( fid==-1 )
error('Can''t open the file.');
return;
end
% header
fprintf(fid, 'OFF\n');
fprintf(fid, '%d %d 0\n', size(vertex,1), size(face,1));
% write the points & faces
fprintf(fid, '%f %f %f\n', vertex');
fprintf(fid, '3 %d %d %d\n', face'-1);
fclose(fid);