Warning, /utils/matlab/cs_grid/split_Z_cub.m is written in an unsupported language. File is not indexed.
view on githubraw file Latest commit 4ec37fd8 on 2023-10-03 22:00:32 UTC
896b20e91e Jean*0001 function [z6t] = split_Z_cub(z3d)
0002 % [z6t] = split_Z_cub(z3d)
0003 %---------------------------------------------
0004 % split 2d/3d arrays z3d to 2d/3d x 6 faces
0005 % and add 1 column + 1 row
0006 % => output is z6t(nc+1,nc+1,[nr],6)
4ec37fd829 Jean*0007 % input is either z3d(nc*nc*6+2,*): compact format including the 2 missing corners
0008 % or z3d(nc,nc*6,*) : compact format without the 2 missing corners
0009 % or z3d(nc*6,nc,*) : original format, no missing corners
0010 % last 2 cases => use the average value (from the 3 neighbours) for the 2 missing corners
896b20e91e Jean*0011 %----------------------------------------------
4ec37fd829 Jean*0012 % Written by jmc@mit.edu, 2005.
0013
896b20e91e Jean*0014 dims=size(z3d); nDim=length(dims);
0015 %fprintf(' nDim= %i , dims:',nDim);fprintf(' %i',dims);fprintf('\n');
0016
0017 nc=fix((dims(1)-2)/6); nc=fix(sqrt(abs(nc)));
0018 if dims(1) == nc*nc*6+2,
0019 nr=dims(2); if nDim > 2, nr=prod(dims(2:end)); end
4ec37fd829 Jean*0020 nPg=nc*nc*6; nPts=nPg+2; dims=[nPts 1 dims(2:end)];
896b20e91e Jean*0021 z3d=reshape(z3d,[nPts nr]);
4ec37fd829 Jean*0022 zzC=z3d(nPg+1:nPg+2,:);
0023 z3d=reshape(z3d(1:nPg,:),[nc nc 6 nr]);
0024 elseif dims(1) == 6*dims(2) | dims(1)*6 == dims(2),
0025 nc=min(dims(1),dims(2));
896b20e91e Jean*0026 if nDim == 2, nr=1; else nr=prod(dims(3:end)); end
4ec37fd829 Jean*0027 nPg=nc*nc*6; nPts=nPg+2;
896b20e91e Jean*0028 zzC=zeros(2,nr);
4ec37fd829 Jean*0029 if dims(2) == nc,
0030 z3d=permute(reshape(z3d,[nc 6 nc nr]),[1 3 2 4]);
0031 else
0032 z3d=reshape(z3d,[nc nc 6 nr]);
0033 end
896b20e91e Jean*0034 else
0035 fprintf(' Error in split_Z_cub: bad input dimensions :');
0036 fprintf(' %i',dims); fprintf('\n');
4ec37fd829 Jean*0037 z6t=0; return
896b20e91e Jean*0038 end
0039
0040 %=================================================================
0041
4ec37fd829 Jean*0042 z3d=permute(z3d,[1 2 4 3]);
896b20e91e Jean*0043 ncp=nc+1; z6t=zeros(ncp,ncp,nr,6);
0044
0045 %-- split on to 6 faces:
0046 z6t([1:nc],[1:nc],:,:)=z3d;
0047
0048 %-- add overlap in i+1 & j+1 :
0049 z6t(ncp,[1:nc], :,1)=z3d(1,[1:nc],:,2);
0050 z6t(ncp,[2:ncp],:,2)=z3d([nc:-1:1],1,:,4);
0051 z6t(ncp,[1:nc], :,3)=z3d(1,[1:nc],:,4);
0052 z6t(ncp,[2:ncp],:,4)=z3d([nc:-1:1],1,:,6);
0053 z6t(ncp,[1:nc], :,5)=z3d(1,[1:nc],:,6);
0054 z6t(ncp,[2:ncp],:,6)=z3d([nc:-1:1],1,:,2);
4ec37fd829 Jean*0055
896b20e91e Jean*0056 z6t([2:ncp],ncp,:,1)=z3d(1,[nc:-1:1],:,3);
0057 z6t([1:nc], ncp,:,2)=z3d([1:nc],1,:,3);
0058 z6t([2:ncp],ncp,:,3)=z3d(1,[nc:-1:1],:,5);
0059 z6t([1:nc], ncp,:,4)=z3d([1:nc],1,:,5);
0060 z6t([2:ncp],ncp,:,5)=z3d(1,[nc:-1:1],:,1);
4ec37fd829 Jean*0061 z6t([1:nc], ncp,:,6)=z3d([1:nc],1,:,1);
896b20e91e Jean*0062
0063 %----------------------------------------------------
0064
0065 %-- missing corners :
0066 if dims(1) ~= nPts,
0067 %- use the average value (from the 3 neighbours)
0068 zzC(1,:)=z3d(1,nc,:,1)+z3d(1,nc,:,3)+z3d(1,nc,:,5);
0069 zzC(2,:)=z3d(nc,1,:,2)+z3d(nc,1,:,4)+z3d(nc,1,:,6);
0070 zzC=zzC/3;
0071 fprintf('split_Z_cub: fills 2 missing corners with local mean value\n');
0072 end
0073 %- 1rst (nPg+1) = N.W corner of face 1
0074 z6t(1,ncp,:,1)=zzC(1,:);
0075 z6t(1,ncp,:,3)=zzC(1,:);
0076 z6t(1,ncp,:,5)=zzC(1,:);
0077 %- 2nd (nPg+2) = S.E corner of face 2
0078 z6t(ncp,1,:,2)=zzC(2,:);
0079 z6t(ncp,1,:,4)=zzC(2,:);
0080 z6t(ncp,1,:,6)=zzC(2,:);
0081
0082 if nDim > 2,
0083 z6t=reshape(z6t,[ncp ncp dims(3:end) 6]);
0084 else
0085 z6t=squeeze(z6t);
0086 end
0087
0088 return