generated from usnistgov/opensource-repo
-
Notifications
You must be signed in to change notification settings - Fork 1
/
inc2cum.m
87 lines (70 loc) · 2.55 KB
/
inc2cum.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
function [ucum,nan_mask] = inc2cum(u,dm,m,option)
%Convert incremental FIDIC/FIDVC displacement to cumulative displacements
% Inputs:
% -----------------------------------------------------------------------
% u: displacement field vector calculated from FIDIC/FIDVC.
% Format: cell array, which is a 2D/3D vector (components in x,y,z)
% per each time point (units are in voxels)
% u{time}{1} = displacement in x-direction at t=time of size MxNxP
% u{time}{2} = displacement in y-direction at t=time of size MxNxP
% if 3D:
% u{time}{3} = displacement in z-direction at t=time of size MxNxP
% dm: Spacing between grid points in 'u.' Currently unused since the
% full mesh is passed too.
% m: meshgrid from DIC
% option: Interpolation method
%
% Outputs:
% u: Cumulative displacement in the same format as input
%If used please cite:
% Landauer, A.K., Patel, M., Henann, D.L. et al. Exp Mech (2018).
% https://doi.org/10.1007/s11340-018-0377-4
%% Parse Inputs
% Change order of dimension 1 and 2 and replace edge nans.
for i = 1:length(u)
nan_mask{i}{1} = u{i}{1}./u{i}{1};
nan_mask{i}{2} = u{i}{2}./u{i}{2};
tempU = inpaint_nans(u{i}{2});
u{i}{2} = inpaint_nans(u{i}{1});
u{i}{1} = tempU;
end
clear tempU
% Find number of dimensions
nDim = length(size(u{1}{1})); %2D or 3D
%% Start inc to cum
% Create reference and deformed grid at t=0
% sizeU = num2cell(size(u{1}{1}));
% for i = 1:nDim
% sizeU{i} = 1:dm:dm*sizeU{i};
% end
% [refGrid{1:length(sizeU)}] = ndgrid(sizeU{:}); % reference grid
refGrid = m;
defGrid = refGrid; %Deformed grid is same as refGrid at t=0;
% Convert inc to cum at all time points
for t = 1:length(u)
% For each dimensions
for i = 1:nDim
if t==1
udef{i} = u{t}{i};
else
% Find u at deformed grid points
udef{i} = interpn(refGrid{:},u{t}{i},defGrid{:},option,NaN);
end
end
for i = 1:nDim
% Update deformed grid points
defGrid{i} = defGrid{i} + udef{i};
% Calculate cumulative u from deformed grid points
ucum{t}{i} = defGrid{i} - refGrid{i};
end
end
% Revert back u to original format (Change order of dimension 1 and 2.)
for i = 1:length(ucum)
tempU = ucum{i}{2};
ucum{i}{2} = ucum{i}{1};
ucum{i}{1} = tempU;
ucum{i}{3} = sqrt(ucum{i}{1}.^2 + ucum{i}{2}.^2);
ucum{i}{1} = nan_mask{i}{1}.*ucum{i}{1};
ucum{i}{2} = nan_mask{i}{2}.*ucum{i}{2};
end
end