forked from patnr/FM
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathTS_line.m
executable file
·79 lines (56 loc) · 1.41 KB
/
TS_line.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
% One dimensional fm2d
%% Setup
clear all;
close all;
% Add path of functions
addpath('./functions');
% Number of grid nodes in each direction
n = 100;
m = 1;
% Domain dimensions
Lx = 100;
Ly = 20;
% Dxyz
dx = Lx/n;
dy = Ly/m;
Dxyz = [dx dy];
% Speed map
F = ones(m,n);
% F = ones(m,n) + 4*rand(m,n);
% Source points
SPs = [0 10]';
%% Calculate Fast-marching solutions
T1 = fm(F,SPs,Dxyz,'impl','C++');
T2 = fm(F,SPs,Dxyz,'impl','Matlab');
% T2 = fm(F,SPs,Dxyz,'impl','noHeap');
%% Calculate exact answer
% Calculate grid node positions
[xx yy] = fmMeshGrid([n m], Dxyz);
% Calculate one time/distance map for each SP
Texa = zeros(m,n,size(SPs,2));
for iter=1:size(SPs,2)
Texa(:,:,iter) = ...
sqrt((xx-SPs(1,iter)).^2 + (yy-SPs(2,iter)).^2);
end
Texa = min(Texa,[],3);
%% Calculate error
rel_errors = (T1-Texa)./(Texa);
per_pixel_rel_error = sum(abs(rel_errors(:)))/(m*n);
display(per_pixel_rel_error);
%% Plots
figure(1);
subplot(2,2,1);
imshow(T1,[],'Init','fit','XD',[1 Lx],'YD',[1 Ly]);
title('Fast marching solution');
subplot(2,2,2);
imshow(T2,[],'Init','fit','XD',[1 Lx],'YD',[1 Ly]);
title('Fast marching solution 2');
subplot(2,2,3);
imshow(Texa,[],'Init','fit','XD',[1 Lx],'YD',[1 Ly]);
title('Exact solution');
colorbar('Position', [.01 .1 .05 .8]);
subplot(2,2,4);
imshow(rel_errors,[],'Init','fit','XD',[1 Lx],'YD',[1 Ly]);
title('Relative errors');
colorbar('Position', [.9 .1 .05 .8]);
colormap(hot());