-
Notifications
You must be signed in to change notification settings - Fork 1
/
AuMeshContraction.m
76 lines (60 loc) · 1.75 KB
/
AuMeshContraction.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
function outMesh = AuMeshContraction(inMesh)
% outMesh = AUMeshContraction(inMesh)
% Contracts a mesh's geometry using the method by Au et al. SIGGRAPH 2008.
% Variables:
% outMesh - contracted mesh.
% inMesh - input mesh structure.
%
% David Pickup 2013
MaxWl = 2048;
MaxWh = 10000;
nTris = size(inMesh.TRIV,1);
nVerts = numel(inMesh.X);
% Get mesh surface area.
[TotalArea,AreaFace] = meshSurfaceArea(inMesh);
AverageArea = TotalArea / nTris;
% Initialise weights.
Wh = ones(nVerts,1);
% Wl = ones(nVerts,1).*3;
Wl = ones(nVerts,1).*((10^(-3)) * sqrt(AverageArea));
% Initialise contracted vertices.
outMesh = inMesh;
verts = [outMesh.X,outMesh.Y,outMesh.Z];
meanRatio = 0;
for i = 1:20
L = laplaceBeltrami(inMesh);
A = [sparse(1:nVerts, 1:nVerts, Wl)*L;sparse(1:nVerts, 1:nVerts, Wh)];
B = [zeros(size(verts));sparse(1:nVerts, 1:nVerts, Wh)*verts];
verts = A\B;
inMesh.X = verts(:,1);
inMesh.Y = verts(:,2);
inMesh.Z = verts(:,3);
Wl = 3.0*Wl;
Wl(Wl>MaxWl) = MaxWl;
[TotalAreaNew,AreaFaceNew] = meshSurfaceArea(inMesh);
totalRatio = TotalAreaNew/TotalArea;
ratio = neighbourhoodAreaRatio(AreaFace, AreaFaceNew, inMesh.TRIV, nVerts);
meanRatio = mean(ratio);
if isnan(meanRatio) || meanRatio==Inf || totalRatio <= 0.01
if isnan(meanRatio)
'NaN'
elseif meanRatio==Inf
'Inf'
else
outMesh = inMesh;
end
break;
end
outMesh = inMesh;
Wh = Wh .* sqrt(ratio);
Wh(Wh>MaxWh) = MaxWh;
X = find(AreaFaceNew == 0);
if numel(X) > 0
[int2str(numel(X)) ' degenerate faces.']
break;
end
% visualiseMesh(inMesh);
AreaFace = AreaFaceNew;
end
[int2str(i) ' iterations.']
return;