-
Notifications
You must be signed in to change notification settings - Fork 4
/
showMeshError.m
54 lines (50 loc) · 1.12 KB
/
showMeshError.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
function showMeshError(mesh, ref, name, range, showColorBar)
FV.vertices = mesh.vertices;
FV.faces = mesh.faces;
nverts = size(FV.vertices, 1);
colors = zeros(nverts, 3);
dists = zeros(nverts, 1);
aligned = 1;
if aligned
center1 = zeros(1, 3);
center2 = zeros(1, 3);
else
center1 = mean(mesh.vertices);
center2 = mean(ref.vertices);
end
for i=1:nverts
dists(i) = norm((mesh.vertices(i,:)-center1) - (ref.vertices(i,:)-center2));
end
if nargin < 4
maxDist = max(dists); minDist = 0;
else
maxDist = range(1); minDist = range(2);
end
distDiff = maxDist - minDist;
for i=1:nverts
val = min((dists(i)-minDist) / distDiff, 1.0);
colors(i, :) = interpolate(val);
end
patch(FV, 'FaceVertexCData', colors, 'facecolor', 'interp', 'edgecolor', 'none', ...
'vertexnormalsmode', 'auto');
camlight;
lighting gouraud;
material dull;
axis vis3d;
axis equal;
if nargin < 5
showColorBar = true;
end
if showColorBar
colorbar;
colormap jet(256);
caxis([minDist maxDist]);
end
title(name);
end
function c = interpolate(val)
nrows = 256;
ridx = max(ceil(val*nrows), 1);
cmap = jet(nrows);
c = cmap(ridx,:);
end