-
Notifications
You must be signed in to change notification settings - Fork 29
Expand file tree
/
Copy pathload_off_file.m
More file actions
41 lines (36 loc) · 909 Bytes
/
load_off_file.m
File metadata and controls
41 lines (36 loc) · 909 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
32
33
34
35
36
37
38
39
40
41
% --------------------------------------------------------
% ObjectNet3D
% Copyright (c) 2016 CVGL Stanford University
% Licensed under The MIT License [see LICENSE for details]
% Written by Yu Xiang
% --------------------------------------------------------
% load the vertices and faces of an .off file
function [v,f] = load_off_file(filename)
v = [];
f = [];
fid = fopen(filename, 'r');
line = fgetl(fid);
if strcmp(line, 'OFF') == 0
error('Wrong format .off file!\n');
end
line = fgetl(fid);
num = sscanf(line, '%f', 3);
nv = num(1);
nf = num(2);
v = zeros(nv,3);
f = zeros(nf,3);
for i = 1:nv
line = fgetl(fid);
v(i,:) = sscanf(line, '%f', 3);
end
for i = 1:nf
line = fgetl(fid);
fsize = sscanf(line, '%f', 1);
if fsize ~= 3
printf('Face contains more than 3 vertices!\n');
end
temp = sscanf(line, '%f', 4);
f(i,:) = temp(2:4);
end
f = f + 1;
fclose(fid);