Warning, /utils/matlab/cs_grid/split_C_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 [v6t] = split_C_cub(v3d,kad)
0002 % [v6t] = split_C_cub(v3d,[kad])
0003 %---------------------------------------------
0004 % split 2d/3d arrays V, center, to 2d/3d x 6 faces
0005 % and (kad=1): add 1 column + 1 row <== at the begining !!!
0006 % => output is v6t(ny+1,ny+1,[nr],6)
0007 % and (kad=2): add also 1 column + 1 row <== at the end !!!
0008 % => output is v6t(ny+2,ny+2,[nr],6)
0009 %----------------------------------------------
4ec37fd829 Jean*0010 % Written by jmc@mit.edu, 2005.
0011
896b20e91e Jean*0012 if nargin < 2, kad=1; end
0013 if kad~=0 & kad~=1 & kad~=2, fprintf('kad= %f => Bad value',kad); return;end
4ec37fd829 Jean*0014 %------------------------------
0015 dims=size(v3d); n1h=dims(1); n2h=dims(2);
0016 if length(dims) == 2, nr=1; else nr=prod(dims(3:end)); end
0017 if n1h == 6*n2h, nc=n2h;
0018 v3d=permute(reshape(v3d,[nc 6 nc nr]),[1 3 2 4]);
0019 elseif n1h*6 == n2h, nc=n1h;
0020 v3d=reshape(v3d,[nc nc 6 nr]);
0021 else
0022 error([' input var size: ',int2str(n1h),' x ',int2str(n2h),' does not fit regular cube !']);
0023 end
0024 ncp=nc+1 ; n2p=nc+2; nye=nc+kad;
896b20e91e Jean*0025 %--
0026 %=================================================================
0027
0028 %- split on to 6 tiles with overlap in i+1 & j+1 :
0029 v6t=zeros(nye,nye,6,nr);
0030
0031 if kad == 0,
4ec37fd829 Jean*0032 v6t=v3d;
896b20e91e Jean*0033 else
4ec37fd829 Jean*0034 v6t(2:ncp,2:ncp,:,:)=v3d(1:nc,1:nc,:,:);
896b20e91e Jean*0035
0036 %- add overlap in i=1 & j=1 :
0037
4ec37fd829 Jean*0038 v6t(1,[2:ncp], 1,:)=v6t([ncp:-1:2],ncp,5,:);
0039 v6t(1,[2:ncp], 3,:)=v6t([ncp:-1:2],ncp,1,:);
0040 v6t(1,[2:ncp], 5,:)=v6t([ncp:-1:2],ncp,3,:);
0041 v6t(1,[2:ncp], 2,:)=v6t(ncp,[2:ncp],1,:);
0042 v6t(1,[2:ncp], 4,:)=v6t(ncp,[2:ncp],3,:);
0043 v6t(1,[2:ncp], 6,:)=v6t(ncp,[2:ncp],5,:);
896b20e91e Jean*0044
4ec37fd829 Jean*0045 v6t([1:ncp],1, 1,:)=v6t([1:ncp],ncp,6,:);
0046 v6t([1:ncp],1, 3,:)=v6t([1:ncp],ncp,2,:);
0047 v6t([1:ncp],1, 5,:)=v6t([1:ncp],ncp,4,:);
0048 v6t([2:ncp],1, 2,:)=v6t(ncp,[ncp:-1:2],6,:);
0049 v6t([2:ncp],1, 4,:)=v6t(ncp,[ncp:-1:2],2,:);
0050 v6t([2:ncp],1, 6,:)=v6t(ncp,[ncp:-1:2],4,:);
0051 v6t(1,1,2,:)=v6t(ncp,2,1,:);
0052 v6t(1,1,4,:)=v6t(ncp,2,3,:);
0053 v6t(1,1,6,:)=v6t(ncp,2,5,:);
896b20e91e Jean*0054
0055 end
0056
0057 %- add overlap in i=ny+1 & j=ny+1 :
0058 if kad == 2,
4ec37fd829 Jean*0059 v6t(n2p,[1:ncp], 1,:)=v6t(2,[1:ncp],2,:);
0060 v6t(n2p,[1:ncp], 3,:)=v6t(2,[1:ncp],4,:);
0061 v6t(n2p,[1:ncp], 5,:)=v6t(2,[1:ncp],6,:);
0062 v6t(n2p,[2:n2p], 2,:)=v6t([ncp:-1:1],2,4,:);
0063 v6t(n2p,[2:n2p], 4,:)=v6t([ncp:-1:1],2,6,:);
0064 v6t(n2p,[2:n2p], 6,:)=v6t([ncp:-1:1],2,2,:);
896b20e91e Jean*0065 v6t(n2p,n2p,1,:)=v6t(2,2,3,:);
0066 v6t(n2p,n2p,3,:)=v6t(2,2,5,:);
0067 v6t(n2p,n2p,5,:)=v6t(2,2,1,:);
4ec37fd829 Jean*0068 v6t(n2p,1,2,:)=v6t(ncp,1,6,:);
0069 v6t(n2p,1,4,:)=v6t(ncp,1,2,:);
0070 v6t(n2p,1,6,:)=v6t(ncp,1,4,:);
896b20e91e Jean*0071
0072 v6t([1:n2p],n2p, 2,:)=v6t([1:n2p],2,3,:);
0073 v6t([1:n2p],n2p, 4,:)=v6t([1:n2p],2,5,:);
0074 v6t([1:n2p],n2p, 6,:)=v6t([1:n2p],2,1,:);
4ec37fd829 Jean*0075 v6t([2:n2p],n2p, 1,:)=v6t(2,[ncp:-1:1],3,:);
0076 v6t([2:n2p],n2p, 3,:)=v6t(2,[ncp:-1:1],5,:);
0077 v6t([2:n2p],n2p, 5,:)=v6t(2,[ncp:-1:1],1,:);
0078 v6t(1,n2p,1,:)=v6t(1,ncp,5,:);
0079 v6t(1,n2p,3,:)=v6t(1,ncp,1,:);
0080 v6t(1,n2p,5,:)=v6t(1,ncp,3,:);
896b20e91e Jean*0081
0082 end
0083
0084 %- Put back to standard shape:
0085 v6t=permute(v6t,[1 2 4 3]);
0086 if length(dims) == 2,
0087 v6t=squeeze(v6t);
0088 else
0089 v6t=reshape(v6t,[nye nye dims(3:end) 6]);
0090 end
0091
0092 return