-
Notifications
You must be signed in to change notification settings - Fork 0
/
dispMesh.m
97 lines (86 loc) · 2.53 KB
/
dispMesh.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
89
90
91
92
93
94
95
96
97
function dispMesh (shp, tl, color, alpha, normal, name)
% Note, shp has nx3 elements and tl has mx3 elements
% Note, If saveMesh activated, mesh is saved as obj file format
saveMesh = true;
dispNormal = true;
if nargin < 4
alpha = 1;
end
if nargin < 5
dispNormal = false;
saveMesh = false;
end
if nargin < 6
saveMesh = false;
end
FV.vertices = shp;
FV.faces = tl;
if size(color,1) < 2
patch(FV, 'facecolor', color, 'edgecolor', 'none', 'vertexnormalsmode', 'auto', 'FaceAlpha', alpha);
else
patch(FV, 'FaceVertexCData',color,'facecolor', 'interp', 'edgecolor', 'none', 'vertexnormalsmode', 'auto', 'FaceAlpha', alpha);
end
camlight('headlight');
lighting phong;
material dull;
axis vis3d
axis equal;
% title(name);
if dispNormal
figure,
ncolor = (normal+1)/2;
patch(FV, 'FaceVertexCData',ncolor,'facecolor', 'interp', 'edgecolor', 'none', 'vertexnormalsmode', 'auto');
camlight('headlight');
lighting phong;
material dull;
axis vis3d
axis equal;
end
if saveMesh
write_obj_file(shp, tl, normal, sprintf('%s%s',name,'.obj'));
frpintf('Mesh file %s is saved\n', name);
end
end
%% Deprecated (From Basel Face Model)
% function dispFace (shp, tl, rp)
% % if size(shp,1) > size(shp,2)
% % shp = shp';
% % end
% if size(shp,2) == 1
% shp = reshape(shp, [ 3 prod(size(shp))/3 ])';
% end
%
% set(gcf, 'Renderer', 'opengl');
% % fig_pos = get(gcf, 'Position');
% % fig_pos(3) = rp.width;
% % fig_pos(4) = rp.height;
% % set(gcf, 'Position', fig_pos);
% set(gcf, 'ResizeFcn', @resizeCallback);
%
% mesh_h = trimesh(tl, shp(:, 1), shp(:, 3), shp(:, 2),...
% 'Edgecolor', 'none', 'FaceColor', 'interp', 'FaceVertexCData', ...
% repmat(rp.color, [size(shp,1),1]),'FaceLighting', 'phong');
%
% % set(gca, ...
% % 'DataAspectRatio', [ 1 1 1 ], ...
% % 'PlotBoxAspectRatio', [ 1 1 1 ], ...
% % 'Units', 'pixels', ...
% % 'GridLineStyle', 'none', ...
% % 'Position', [ 0 0 fig_pos(3) fig_pos(4) ], ...
% % 'Visible', 'off', 'box', 'off', ...
% % 'Projection', 'perspective' ...
% % );
%
% % set(gcf, 'Color', [ 0 0 0 ]);
% view(180 + rp.phi * 180 / pi, 0);
%
% material([.5, .5, .1 1 ])
% camlight('headlight');
%
% function resizeCallback (obj, eventdata)
%
% fig = gcbf;
% fig_pos = get(fig, 'Position');
%
% axis = findobj(get(fig, 'Children'), 'Tag', 'Axis.Head');
% set(axis, 'Position', [ 0 0 fig_pos(3) fig_pos(4) ]);