-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathexample_ProjBD_Mesh2D.m
63 lines (49 loc) · 1.62 KB
/
example_ProjBD_Mesh2D.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
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Code implementing the paper "Large-Scale Bounded Distortion Mappings".
% Disclaimer: The code is provided as-is for academic use only and without any guarantees.
% Please contact the author to report any bugs.
% Written by Shahar Kovalsky (http://www.wisdom.weizmann.ac.il/~shaharko/)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% init
rng(1)
clear
addpath('mex');
%% parameters
n = 100; % problem size
sigma = .3; % noise level (for initial map)
K = 1.5; % conformal distortion bound
lb = -1; % lower bound on SVs (-1 = disabled)
ub = -1; % upper bound on SVs (-1 = disabled)
iter_max = 1000; % maximal number of BD projection iterations
tol_err = 1e-10; % tolerance for stopping BD projection iterations
use_weighted_metric = false; % use a weighted metric?
%% generate problem
% generate regular mesh
[x, y] = ndgrid(1:n,1:n);
V = [x(:), y(:)];
F = delaunay(V);
% some constants
dim = size(F,2)-1;
n_vert = size(V,1);
n_tri = size(F,1);
% initial map
x0 = V + sigma*randn(n_vert,dim);
% setup linear constraints (fix centroid)
eq_lhs = kron(eye(dim),ones(1,n_vert))/n_vert;
eq_rhs = eq_lhs*colStack(x0);
%% solve problem
% setup BD solver
solver_bd = SolverProjectorBD(F, V, eq_lhs, eq_rhs, K, lb, ub, x0, SolverProjectorModeEnum.Tangent, use_weighted_metric);
% plot initial map
figure;
solver_bd.visualize();
title('Initial Map');
hA(1) = gca;
% run solver
solver_bd.solve(iter_max, tol_err); % solve BD projection
% plot output map
figure;
solver_bd.visualize();
title('Output Map');
hA(2) = gca;
linkaxes(hA);