-
Notifications
You must be signed in to change notification settings - Fork 4
/
Deform2DFinite.m
94 lines (72 loc) · 2.28 KB
/
Deform2DFinite.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
%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% 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 Deform2DFinite < Deform2D
%DEFOR2DMFINITE
properties
se = []
constrSolver = []
mode = [];
end
methods
function obj = Deform2DFinite(mesh, beta, mode_lrigid_or_conf)
%% Constructor
obj = obj@Deform2D(mesh, beta);
obj.mode = mode_lrigid_or_conf;
if mode_lrigid_or_conf,
obj.name = 'lARAP';
else
obj.name = 'ASAP';
end
end
function init(obj, hidxs)
%% Setup element permutation opertor P
mesh = obj.mesh;
%% Setup material behaviour term
if ~obj.mode,
%% conformal <=> as-similar-as-possible
Mwq = eye(4) - 0.5 .* [1, 0, 0,1;
0, 1,-1,0;
0,-1, 1,0;
1, 0, 0,1];
Mq = blockfill(4,4,mesh.nt,repmat(Mwq,1,mesh.nt));
%% Setup integrated / smoothed system
E = Mq*mesh.GGP;
en = size(E,1) / mesh.nt;
obj.se = obj.smootherf(mesh,obj.beta, en, 2,1);
obj.se.updateLHS(E);
else
%% linearized rotations
Mwq = 1.0 .* [1, 0, 0,0;
0,1/2,1/2,0;
0,1/2,1/2,0;
0, 0, 0,1];
Mwr = [1;0;0;1];
Mq = blockfill(4,4,mesh.nt,repmat(Mwq,1,mesh.nt));
%% Setup integrated / smoothed system
E = Mq*mesh.GGP;
b = repmat(Mwr,mesh.nt,1);
en = size(E,1) / mesh.nt;
obj.se = obj.smootherf(mesh,obj.beta, en, 2,1);
obj.se.updateLHS(E);
obj.se.updateRHS(b);
end
%% Setup solver
% constrained handle indices
obj.hidxs = hidxs;
cidxs = reshape([(hidxs-1)*2+1; (hidxs-1)*2+2],1,[]);
obj.constrSolver = obj.csolverf(obj.se.AAs,cidxs,obj.se.bbs);
end
function [converged,u] = deform(obj, hcoords, ~)
converged = true; u = [];
if(isempty(obj.hidxs)), return; end
u = obj.constrSolver.solve(reshape(hcoords,[],1));
obj.mesh.p = reshape(u,2,[]);
end
end
end