[356] | 1 | %'tps_eval': calculate the thin plate spline (tps) interpolation at a set of points |
---|
[434] | 2 | % see tps_coeff.m for more information and test_tps.m for an example |
---|
[356] | 3 | %------------------------------------------------------------------------ |
---|
| 4 | % function EM = tps_eval(dsites,ctrs) |
---|
| 5 | %------------------------------------------------------------------------ |
---|
[811] | 6 | % OUTPUT: |
---|
| 7 | % EM: Mx(N+s) matrix representing the contributions at the M sites |
---|
[356] | 8 | % from unit sources located at each of the N centers, + (s+1) columns |
---|
| 9 | % representing the contribution of the linear gradient part. |
---|
[434] | 10 | % use : U_interp=EM*U_tps |
---|
[356] | 11 | % |
---|
[811] | 12 | % INPUT: |
---|
| 13 | % dsites: Mxs matrix representing the postions of the M 'observation' sites, with s the space dimension |
---|
| 14 | % ctrs: Nxs matrix representing the postions of the N centers, sources of the tps, |
---|
[356] | 15 | % |
---|
[811] | 16 | % RELATED FUNCTIONS: |
---|
| 17 | % tps_coeff, tps_eval_dxy |
---|
| 18 | % tps_coeff_field, set_subdomains, filter_tps, calc_field |
---|
[246] | 19 | |
---|
[809] | 20 | %======================================================================= |
---|
[924] | 21 | % Copyright 2008-2016, LEGI UMR 5519 / CNRS UGA G-INP, Grenoble, France |
---|
[809] | 22 | % http://www.legi.grenoble-inp.fr |
---|
| 23 | % Joel.Sommeria - Joel.Sommeria (A) legi.cnrs.fr |
---|
| 24 | % |
---|
| 25 | % This file is part of the toolbox UVMAT. |
---|
| 26 | % |
---|
| 27 | % UVMAT is free software; you can redistribute it and/or modify |
---|
| 28 | % it under the terms of the GNU General Public License as published |
---|
| 29 | % by the Free Software Foundation; either version 2 of the license, |
---|
| 30 | % or (at your option) any later version. |
---|
| 31 | % |
---|
| 32 | % UVMAT is distributed in the hope that it will be useful, |
---|
| 33 | % but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
| 34 | % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
| 35 | % GNU General Public License (see LICENSE.txt) for more details. |
---|
| 36 | %======================================================================= |
---|
| 37 | |
---|
[356] | 38 | function EM = tps_eval(dsites,ctrs) |
---|
| 39 | [M,s] = size(dsites); [N,s] = size(ctrs); |
---|
| 40 | EM = zeros(M,N); |
---|
| 41 | |
---|
| 42 | % calculate distance matrix: accumulate sum of squares of coordinate differences |
---|
| 43 | % The ndgrid command produces two MxN matrices: |
---|
| 44 | % Dsite, consisting of N identical columns (each containing |
---|
| 45 | % the d-th coordinate of the M data sites) |
---|
| 46 | % Ctrs, consisting of M identical rows (each containing |
---|
| 47 | % the d-th coordinate of the N centers) |
---|
| 48 | for d=1:s |
---|
| 49 | [Dsites,Ctrs] = ndgrid(dsites(:,d),ctrs(:,d)); |
---|
| 50 | EM = EM + (Dsites-Ctrs).^2;%EM=square of distance matrices |
---|
| 51 | end |
---|
| 52 | |
---|
| 53 | % calculate tps |
---|
| 54 | np=find(EM~=0); |
---|
| 55 | EM(np) = EM(np).*log(EM(np))/2;%= tps formula r^2 log(r) (EM=r^2) |
---|
| 56 | |
---|
| 57 | % add linear gradient part: |
---|
[809] | 58 | EM = [EM ones(M,1) dsites]; |
---|