function [xi,yi,zi] = mincurvi(xb,yb,zb,xi,yi,n) % MINCURVI Interpolation by minimum curvature method. % ZI = MINCURVI(X,Y,Z,XI,YI) Interpolates values Z % at known at points with coordinates X, Y to % values ZI at points with coordinates XI, YI % using minimum curvature method. % % For large number of known points it divides % the domain into subdomains using the adaptive % QUADTREE procedure. % MINCURVI(X,Y,Z,XI,YI,[NB ND NMAX]) also allows % to specify several parameters of quadtree % division: % NB - max. number of points in one block % ND - "depopulation" threshold - if number of % points in a block is less than ND is is % considered "depopulated" and its own "secondary" % neighbours are used for interpolation. % NMAX - max. number of points below which domain % is not divided into blocks. % Default values [NB ND NMAX] = [32 8 400]. % % XI can be a row vector, in which case it specifies % a matrix with constant columns. Similarly, YI can % be a column vector and it specifies a matrix with % constant rows. % [XI,YI,ZI] = MINCURVI(...) also returns matrices % XI, YI formed from input vectors XI,YI in the way % described above. % % See also GRIDDATA, OBJMAP, QUADTREE. % Method used in MINCURVI is similar to that of % used in GRIDDATA. However MINCURVI is much more % memory-efficient for large number of points and % more robust since it uses mean and slope removal % (program DETREND2). % Copyright (c) 1995 by Kirill K. Pankratov % kirill@plume.mit.edu % 05/25/95, 09/15/95 % Defaults and parameters ............... n_dflt = [32 8]; % Default for max. number of % points in elementary block and % "depopulation" threshold nmax = 400; % Default for max. number of points % not to be divided into blocks verbose = 1; % Verbosity (shows number of blocks % processed is_scale = 1; % Scale variables % Handle input .......................... if nargin==0, help mincurvi, return, end if nargin==1 if strcmp(xb,'info'), more on, type mapinfo, more off, return, end end if nargin<5 error(' Not enough input arguments') end if nargin<6, n = n_dflt; end if n==[], n = n_dflt; end n = max(n,1); if length(n)==1, n(2) = ceil(n(1)/4); end if length(n)>=3, nmax = n(3); end n = n(:)'; n(1:2) = fliplr(sort(n(1:2))); % Check input coordinates and make matrices XI, YI % if necessary [msg,xb,yb,zb,xi,yi] = xyzchk(xb,yb,zb,xi,yi); if length(msg)>0, error(msg); end % Check for coincident points ................ [r,zb] = uniquept([xb(:) yb(:)],zb(:)); xb = r(:,1); yb = r(:,2); % Scales ............... if is_scale xsc = max(xb)-min(xb); ysc = max(yb)-min(yb); xb = xb/xsc; xi = xi/xsc; yb = yb/ysc; yi = yi/ysc; end % Calculate quadtree divison into blocks and % related objects [x,y,s,nb,lb,ind,bx,by,Na,Lx,Ly,Sp,npb] = ... mkblocks(xb,yb,xi,yi,n(1),nmax); zb = zb(:); % Mask for underpopulated blocks ....... isup = npb