forked from joe8767/SymmetryPlain
-
Notifications
You must be signed in to change notification settings - Fork 0
/
readWRL2Tuples.m
89 lines (80 loc) · 2.3 KB
/
readWRL2Tuples.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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
function [ vertex, faces3p, faces4p] = readWRL2Tuples(filename)
% 读取gavaDB中的人脸数据
% vertex: 顶点
% faces3p: 三角面片
% faces4p: 四边形面片
fp = fopen(filename, 'r');
if fp == -1
fclose all;
str = sprintf('Cannot open file %s \n', filename);
% errordlg(str);
error(str);
return;
end
% skip the head
lineStr = fgetl(fp);
while isempty(strfind(lineStr, 'point'))
lineStr = fgetl(fp);
end
% read points
points = [];
while true
lineStr = fgetl(fp);
if ~isempty(strfind(lineStr, ']'))
break;
end
pointStr = regexp(lineStr, ' ', 'split');
point1 = pointStr{1};
point2 = pointStr{2};
point3 = pointStr{3};
%remove the comma
point3 = point3(1:end-1);
point1 = str2double(point1);
point2 = str2double(point2);
point3 = str2double(point3);
points = [points; [point1, point2, point3] ];
end
%% read faces
% coordIndex
% skip the head
lineStr = fgetl(fp);
while isempty(strfind(lineStr, 'coordIndex'))
lineStr = fgetl(fp);
end
faces4p = [];
faces3p = [];
while true
lineStr = fgetl(fp);
faceStr = regexp(lineStr, ',', 'split');
if ~isempty(strfind(lineStr, ']'))
break;
end
faceLen = length(faceStr);
% neglect the missing lines
if faceLen == 6
face1 = faceStr{1};
face2 = faceStr{2};
face3 = faceStr{3};
face4 = faceStr{4};
face1 = str2double(face1);
face2 = str2double(face2);
face3 = str2double(face3);
face4 = str2double(face4);
faces4p = [faces4p; [face1, face2, face3, face4]];
elseif faceLen == 5 || faceLen == 4 % triple tuple
% faceLen
face1 = faceStr{1};
face2 = faceStr{2};
face3 = faceStr{3};
face1 = str2double(face1);
face2 = str2double(face2);
face3 = str2double(face3);
faces3p = [faces3p; [face1, face2, face3]];
else
faceLen
end
end
size(points);
size(faces4p);
vertex = points;
end