-
Notifications
You must be signed in to change notification settings - Fork 4
/
Deform2DARAP.m
115 lines (85 loc) · 2.58 KB
/
Deform2DARAP.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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% Smoothed Quadratic Energies on Meshes
%% J. Martinez Esturo, C. Rössl, and H. Theisel
%%
%% ACM Transactions on Graphics 2014
%%
%% Copyright J. Martinez Esturo 2014 (MIT License)
%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
classdef Deform2DARAP < Deform2D
%DEFORM2DARAP
properties
se = []
constrSolver = []
def_finite = []
itmax = []
end
methods
function obj = Deform2DARAP(mesh, beta, itmax)
%% Constructor
obj = obj@Deform2D(mesh, beta);
obj.itmax = itmax;
obj.name = 'ARAP';
end
function init(obj, hidxs)
%% Setup finite deformation operator (some redundant computations atm...)
mesh = obj.mesh;
obj.def_finite = Deform2DFinite(mesh, obj.beta, false);
obj.def_finite.csolverf = obj.csolverf;
obj.def_finite.init(hidxs);
%% Initialize local / global iteration
% global smoothed energy is just a poisson system
en = size(mesh.GP,1) / mesh.nt;
obj.se = obj.smootherf(mesh,obj.beta, en, 1,1);
obj.se.updateLHS(mesh.GP);
%% Setup global solver
% constrained handle indices
obj.hidxs = hidxs;
obj.constrSolver = obj.csolverf(obj.se.AAs,obj.hidxs,[]);
end
function [converged,u] = deform(obj, hcoords, itn)
converged = true; u = [];
if(isempty(obj.hidxs)), return; end
if itn == 1,
%% initialize with linearized finite deformation
obj.def_finite.deform(hcoords, itn);
converged = false;
u=[];
else
%% local / global iteration
mesh = obj.mesh;
%% local: find best rotation per triangle deformation gradient
x = reshape(mesh.p,[],1);
F = mesh.GGP*x;
if false,
% matlab svd
R = zeros(2,2*obj.mesh.nt);
for t=1:mesh.nt,
[U,S,V] = svd(reshape(F((4*(t-1)+1):(4*t),1),2,2));
L = U*V';
if S(1,1)*S(2,2) < 0,
L = -1.*L;
end
R(:,(2*(t-1)+1):(2*t)) = L;
end
else
% mex svd
F = reshape(F,2,[]);
opt.fast2D = false;
R = polardecomp(F, opt);
end
%% global: fit deformation to these gradients
% reshape rotations to columnwise blocks
R = blockreshape(R',2,1,mesh.nt)';
obj.se.updateRHS(R);
u = obj.constrSolver.solve(hcoords', obj.se.bbs);
mesh.p = u';
if itn == obj.itmax,
converged = true;
else
converged = false;
end
end
end
end
end