[587] | 1 | %'set_subdomains': sort a set of points defined by scattered coordinates in subdomains, as needed for tps interpolation |
---|
| 2 | %------------------------------------------------------------------------ |
---|
[651] | 3 | % [SubRange,NbCentre,IndSelSubDomain] =set_subdomains(Coord,SubDomainNbPoint) |
---|
[587] | 4 | % |
---|
| 5 | % OUTPUT: |
---|
| 6 | % SubRange(NbCoord,NbSubdomain,2): range (min, max) of the coordinates x and y respectively, for each subdomain |
---|
[651] | 7 | % NbCentre(NbSubdomain): number of source points for each subdomain |
---|
[587] | 8 | % IndSelSubDomain(SubDomainNbPointMax,NbSubdomain): set of indices of the input point array |
---|
[651] | 9 | % selected in each subdomain, =0 beyond NbCentre points |
---|
[587] | 10 | % |
---|
| 11 | % INPUT: |
---|
| 12 | % coord=[X Y]: matrix whose first column is the x coordinates of the input data points, the second column the y coordinates |
---|
| 13 | % SubdomainNbPoint: estimated number of data points whished for each subdomain |
---|
| 14 | |
---|
[651] | 15 | function [SubRange,NbCentre,IndSelSubDomain] =set_subdomains(Coord,SubDomainNbPoint) |
---|
[587] | 16 | |
---|
| 17 | %% adjust subdomain decomposition |
---|
| 18 | NbVec=size(Coord,1); |
---|
| 19 | NbCoord=size(Coord,2); |
---|
| 20 | MinCoord=min(Coord,[],1); |
---|
| 21 | MaxCoord=max(Coord,[],1); |
---|
| 22 | Range=MaxCoord-MinCoord; |
---|
| 23 | AspectRatio=Range(2)/Range(1); |
---|
| 24 | NbSubDomain=NbVec/SubDomainNbPoint; |
---|
| 25 | NbSubDomainX=max(floor(sqrt(NbSubDomain/AspectRatio)),1); |
---|
| 26 | NbSubDomainY=max(floor(sqrt(NbSubDomain*AspectRatio)),1); |
---|
| 27 | NbSubDomain=NbSubDomainX*NbSubDomainY; |
---|
| 28 | Siz(1)=Range(1)/NbSubDomainX;%width of subdomains |
---|
| 29 | Siz(2)=Range(2)/NbSubDomainY;%height of subdomains |
---|
| 30 | CentreX=linspace(MinCoord(1)+Siz(1)/2,MaxCoord(1)-Siz(1)/2,NbSubDomainX); |
---|
| 31 | CentreY=linspace(MinCoord(2)+Siz(2)/2,MaxCoord(2)-Siz(2)/2,NbSubDomainY); |
---|
| 32 | [CentreX,CentreY]=meshgrid(CentreX,CentreY); |
---|
| 33 | CentreY=reshape(CentreY,1,[]);% Y positions of subdomain centres |
---|
| 34 | CentreX=reshape(CentreX,1,[]);% X positions of subdomain centres |
---|
| 35 | |
---|
| 36 | %% default output |
---|
| 37 | SubRange=zeros(NbCoord,2,NbSubDomain);%initialise the positions of subdomains |
---|
[651] | 38 | NbCentre=zeros(1,NbSubDomain);%number of interpolated values per subdomain, =0 by default |
---|
[587] | 39 | %Coord_tps=zeros(NbVec,NbCoord,NbSubDomain);% default positions of the tps source= initial positions of the good vectors sorted by subdomain |
---|
| 40 | check_empty=zeros(1,NbSubDomain); |
---|
| 41 | |
---|
| 42 | %% adjust subdomains |
---|
| 43 | for isub=1:NbSubDomain |
---|
| 44 | SubRange(1,:,isub)=[CentreX(isub)-0.55*Siz(1) CentreX(isub)+0.55*Siz(1)]; |
---|
| 45 | SubRange(2,:,isub)=[CentreY(isub)-0.55*Siz(2) CentreY(isub)+0.55*Siz(2)]; |
---|
| 46 | IndSel_previous=[]; |
---|
| 47 | IndSel=0; |
---|
| 48 | while numel(IndSel)>numel(IndSel_previous) %increase the subdomain if it contains less than SubDomainNbPoint/4 sources |
---|
| 49 | IndSel_previous=IndSel; |
---|
| 50 | IndSel=find(Coord(:,1)>=SubRange(1,1,isub) & Coord(:,1)<=SubRange(1,2,isub) & Coord(:,2)>=SubRange(2,1,isub) & Coord(:,2)<=SubRange(2,2,isub)); |
---|
| 51 | % if no source in the subdomain, skip the subdomain |
---|
| 52 | if isempty(IndSel) |
---|
| 53 | check_empty(isub)=1; |
---|
| 54 | break |
---|
| 55 | % if too few selected sources, increase the subrange for next iteration |
---|
| 56 | elseif numel(IndSel)<SubDomainNbPoint/4 && ~isequal( IndSel,IndSel_previous); |
---|
| 57 | SubRange(:,1,isub)=SubRange(:,1,isub)-Siz'/4; |
---|
| 58 | SubRange(:,2,isub)=SubRange(:,2,isub)+Siz'/4; |
---|
| 59 | else |
---|
| 60 | break |
---|
| 61 | end |
---|
| 62 | end |
---|
[651] | 63 | NbCentre(isub)=numel(IndSel); |
---|
| 64 | IndSelSubDomain(1:numel(IndSel),isub)=IndSel; |
---|
[587] | 65 | end |
---|
| 66 | |
---|
| 67 | |
---|
| 68 | %% remove empty subdomains |
---|
| 69 | ind_empty=find(check_empty); |
---|
| 70 | if ~isempty(ind_empty) |
---|
| 71 | SubRange(:,:,ind_empty)=[]; |
---|
[651] | 72 | NbCentre(ind_empty)=[]; |
---|
[587] | 73 | IndSelSubDomain(:,ind_empty)=[]; |
---|
| 74 | end |
---|
| 75 | |
---|
| 76 | |
---|