Changeset 1072 for trunk/src/proj_field.m
- Timestamp:
- Jan 17, 2020, 8:13:53 PM (5 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/proj_field.m
r1071 r1072 999 999 end 1000 1000 PlaneAngle=(pi/180)*ObjectData.Angle; 1001 if PlaneAngle==0 1002 PlaneAngle=[0 0]; 1003 end 1001 1004 % om=norm(PlaneAngle);%norm of rotation angle in radians 1002 1005 % OmAxis=PlaneAngle/om; %unit vector marking the rotation axis … … 1009 1012 % norm_plane(3)=OmAxis(3)*coeff+cos_om; 1010 1013 1011 M1=[cos(PlaneAngle(1)) sin(PlaneAngle(1)) 0;-sin(PlaneAngle(1)) cos(PlaneAngle(1)) 0;0 0 1];1014 M1=[cos(PlaneAngle(1)) -sin(PlaneAngle(1)) 0;sin(PlaneAngle(1)) cos(PlaneAngle(1)) 0;0 0 1]; 1012 1015 M=M1; 1013 1016 if checkM2 1014 M2=[1 0 0;0 cos(PlaneAngle(2)) sin(PlaneAngle(2));0 -sin(PlaneAngle(2)) cos(PlaneAngle(2))];1015 M=M 2*M1;% first rotate in the x,y plane with angle PlaneAngle(1), then slant around the new x axis0 with angle PlaneAngle(2)1017 M2=[1 0 0;0 cos(PlaneAngle(2)) -sin(PlaneAngle(2));0 sin(PlaneAngle(2)) cos(PlaneAngle(2))]; 1018 M=M1*M2;% first rotate in the x,y plane with angle PlaneAngle(1), then slant around the new x axis0 with angle PlaneAngle(2) 1016 1019 end 1017 1020 norm_plane=M*[0 0 1]'; … … 1038 1041 end 1039 1042 InterpMesh=min(DX,DY);%mesh used for interpolation in a slanted plane 1040 % if strcmp(ObjectData.Type,'plane_z')1041 % InterpMesh=10*InterpMesh;%TODO: temporary, to shorten computation1042 % end1043 1043 1044 1044 %% extrema along each axis … … 1126 1126 % end 1127 1127 icell_grid=[];% field cell index which defines the grid 1128 if ~strcmp(ObjectData.ProjMode,'projection')&& ~strcmp(ObjectData.Type,'plane_z')% TODO:rationalize 1129 %% define the new coordinates in case of interpolation on a imposed grid 1130 if ~testYMin 1131 errormsg='min Y value not defined for the projection grid';return 1132 end 1133 if ~testYMax 1134 errormsg='max Y value not defined for the projection grid';return 1135 end 1136 if ~testXMin 1137 errormsg='min X value not defined for the projection grid';return 1138 end 1139 if ~testXMax 1140 errormsg='max X value not defined for the projection grid';return 1141 end 1142 else 1128 if strcmp(ObjectData.ProjMode,'projection') 1143 1129 %% case of a grid requested by the input field 1144 1130 for icell=1:numel(CellInfo)% TODO: recalculate coordinates here to get the bounds in the rotated coordinates … … 1162 1148 end 1163 1149 end 1164 if ~isempty(find(check_grid ))% if a grid is requested by the input field1150 if ~isempty(find(check_grid,1))% if a grid is requested by the input field 1165 1151 if isempty(icell_grid)% if the grid is not given by cell #icell_grid 1166 1152 if ~isfield(FieldData,'XMax') … … 1169 1155 end 1170 1156 end 1171 end 1172 if ~isempty(find(check_grid))||~strcmp(ObjectData.ProjMode,'projection')%no existing gridded data used 1157 else 1158 %% define the new coordinates in case of interpolation on a imposed grid 1159 if ~testYMin 1160 errormsg='min Y value not defined for the projection grid';return% %%%%%%%%%%%%%%%% A REVOIR 1161 1162 end 1163 if ~testYMax 1164 errormsg='max Y value not defined for the projection grid';return 1165 end 1166 if ~testXMin 1167 errormsg='min X value not defined for the projection grid';return 1168 end 1169 if ~testXMax 1170 errormsg='max X value not defined for the projection grid';return 1171 end 1172 end 1173 if ~isempty(find(check_grid,1))||~strcmp(ObjectData.ProjMode,'projection')%no existing gridded data used 1173 1174 if isempty(icell_grid)||~strcmp(ObjectData.ProjMode,'projection')%no existing gridded data used 1174 1175 AYName='coord_y'; 1175 1176 AXName='coord_x'; 1176 if strcmp(ObjectData.ProjMode,'projection')||strcmp(ObjectData.Type,'plane _z')1177 if strcmp(ObjectData.ProjMode,'projection')||strcmp(ObjectData.Type,'plane') 1177 1178 ProjData.coord_y=[FieldData.YMin FieldData.YMax];%note that if projection is done on a grid, the Min and Max along each direction must have been defined 1178 1179 ProjData.coord_x=[FieldData.XMin FieldData.XMax]; … … 1472 1473 end 1473 1474 1474 if isequal(ProjMode{icell},'projection')% && (~testangle || test90y || test90x)1475 if strcmp(ProjMode{icell},'projection')% && (~testangle || test90y || test90x) 1475 1476 if NbDim==2 && ~testXMin && ~testXMax && ~testYMin && ~testYMax% no range restriction 1476 1477 ListVarName=[ListVarName FieldData.ListVarName(VarIndex)]; … … 1653 1654 if isfield(FieldData,'VarAttribute')&&length(FieldData.VarAttribute)>=ivar 1654 1655 VarAttribute{length(ListVarName)+nbcoord}=FieldData.VarAttribute{ivar}; 1655 end ;1656 end 1656 1657 ProjData.(FFName)=isnan(ProjData.(VarName));%detact NaN (points outside the interpolation range) 1657 1658 ProjData.(VarName)(ProjData.(FFName))=0; %set to 0 the NaN data … … 1661 1662 VarDimName=[VarDimName {DimCell}]; 1662 1663 VarAttribute{numel(ListVarName)}.Role='errorflag'; 1663 elseif ~testangle 1664 elseif ~testangle % 3Dcase without change of angle 1664 1665 % unstructured z coordinate 1665 1666 test_sup=(Coord{1}>=ObjectData.Coord(1,3)); … … 1683 1684 % determine the boundaries of the projected field, 1684 1685 % first find the 8 summits of the initial volume in the 1685 PlaneAngle=ObjectData.Angle*pi/180; 1686 PlaneAngle=[0 0 0];% default 1687 PlaneAngle(1:numel(ObjectData.Angle))=ObjectData.Angle*pi/180; 1686 1688 % new coordinates 1687 1689 Coord{1}=FieldData.(FieldData.ListVarName{CellInfo{icell}.CoordIndex(1)});%initial z coordinates 1688 1690 Coord{2}=FieldData.(FieldData.ListVarName{CellInfo{icell}.CoordIndex(2)});%initial y coordinates 1689 1691 Coord{3}=FieldData.(FieldData.ListVarName{CellInfo{icell}.CoordIndex(3)});%initial x coordinates 1690 summit=zeros(3,8);% initialize summit coordinates1691 summit(1,1:4)=[Coord{3}(1) Coord{3}(end) Coord{3}(1) Coord{3}(end)];%square1692 summit(2,1:4)=[Coord{2}(1) Coord{2}(1) Coord{2}(end) Coord{2}(end)];% square at z= Coord{1}(1)1693 summit(1:2,5:8)=summit(1:2,1:4);1694 summit(3,:)=[Coord{1}(1)*ones(1,4) Coord{1}(end)*ones(1,4)];1695 %Mrot_inv=rodrigues(-PlaneAngle);1696 newsummit=zeros(3,8);% initialize the rotated summit coordinates1692 % summit=zeros(3,8);% initialize summit coordinates 1693 % summit(1,1:4)=[Coord{3}(1) Coord{3}(end) Coord{3}(1) Coord{3}(end)];%square 1694 % summit(2,1:4)=[Coord{2}(1) Coord{2}(1) Coord{2}(end) Coord{2}(end)];% square at z= Coord{1}(1) 1695 % summit(1:2,5:8)=summit(1:2,1:4); 1696 % summit(3,:)=[Coord{1}(1)*ones(1,4) Coord{1}(end)*ones(1,4)]; 1697 % %Mrot_inv=rodrigues(-PlaneAngle); 1698 % newsummit=zeros(3,8);% initialize the rotated summit coordinates 1697 1699 ObjectData.Coord=ObjectData.Coord';% set ObjectData.Coord as a vertical vector 1698 1700 if size(ObjectData.Coord,1)<3 … … 1700 1702 end 1701 1703 1702 M1=[cos(PlaneAngle(1)) sin(PlaneAngle(1)) 0;-sin(PlaneAngle(1)) cos(PlaneAngle(1)) 0;0 0 1];1703 M2=[1 0 0;0 cos(PlaneAngle(2)) sin(PlaneAngle(2));0 -sin(PlaneAngle(2)) cos(PlaneAngle(2))];1704 M=M2*M1;1704 % M1=[cos(PlaneAngle(1)) sin(PlaneAngle(1)) 0;-sin(PlaneAngle(1)) cos(PlaneAngle(1)) 0;0 0 1]; 1705 % M2=[1 0 0;0 cos(PlaneAngle(2)) sin(PlaneAngle(2));0 -sin(PlaneAngle(2)) cos(PlaneAngle(2))]; 1706 % M=M1*M2; 1705 1707 M_inv=inv(M); 1706 1708 1707 for isummit=1:8% TODO: introduce a function for rotation of n points (to use also for scattered data) 1708 newsummit(:,isummit)=M*(summit(:,isummit)-(ObjectData.Coord)); 1709 end 1710 coord_x_proj=min(newsummit(1,:)):InterpMesh: max(newsummit(1,:));% set of coordinqtes in the projection plane 1711 coord_y_proj=min(newsummit(2,:)):InterpMesh: max(newsummit(2,:)); 1712 coord_z_proj=-width:width; 1709 % for isummit=1:8% TODO: introduce a function for rotation of n points (to use also for scattered data) 1710 % newsummit(:,isummit)=M*(summit(:,isummit)-(ObjectData.Coord)); 1711 % end 1712 % coord_x_proj=min(newsummit(1,:)):InterpMesh: max(newsummit(1,:));% set of coordinqtes in the projection plane 1713 % coord_y_proj=min(newsummit(2,:)):InterpMesh: max(newsummit(2,:)); 1714 % coord_z_proj=-width:width; 1715 coord_x_proj=ObjectData.RangeX(1):InterpMesh:ObjectData.RangeX(2);% set of coordinqtes in the projection plane 1716 coord_y_proj=ObjectData.RangeY(1):InterpMesh:ObjectData.RangeY(2); 1717 coord_z_proj=-floor(ObjectData.RangeInterp/InterpMesh):InterpMesh:floor(ObjectData.RangeInterp/InterpMesh); 1713 1718 %Mrot=rodrigues(PlaneAngle);% inverse rotation matrix 1714 Origin=M_inv*[coord_x_proj(1);coord_y_proj(1);coord_z_proj(1)]+ObjectData.Coord;1719 %Origin=M_inv*[coord_x_proj(1);coord_y_proj(1);coord_z_proj(1)]+ObjectData.Coord; 1715 1720 npx=numel(coord_x_proj); 1716 1721 npy=numel(coord_y_proj); … … 1722 1727 iX=[coord_x_proj(end)-coord_x_proj(1);0;0]/(npx-1); 1723 1728 iY=[0;coord_y_proj(end)-coord_y_proj(1);0]/(npy-1); 1729 if npz==1 1730 iZ=[0;0;0]; 1731 else 1724 1732 iZ=[0;0;coord_z_proj(end)-coord_z_proj(1)]/(npz-1); 1733 end 1725 1734 % iX(1:2)=[cosphi -sinphi;sinphi cosphi]*iX(1:2); 1726 1735 % iY(1:2)=[-cosphi -sinphi;sinphi cosphi]*iY(1:2); … … 1731 1740 1732 1741 [Grid_x,Grid_y,Grid_z]=meshgrid(0:npx-1,0:npy-1,0:npz-1); 1742 %[Grid_x,Grid_y,Grid_z]=meshgrid(0:npz-1,0:npy-1,0:npx-1); 1733 1743 if ismatrix(Grid_x)% add a singleton in case of a single z value 1734 1744 Grid_x=shiftdim(Grid_x,-1); … … 1736 1746 Grid_z=shiftdim(Grid_z,-1); 1737 1747 end 1738 XI=O rigin(1)+ix(1)*Grid_x+iy(1)*Grid_y+iz(1)*Grid_z;1739 YI=O rigin(2)+ix(2)*Grid_x+iy(2)*Grid_y+iz(2)*Grid_z;1740 ZI=O rigin(3)+ix(3)*Grid_x+iy(3)*Grid_y+iz(3)*Grid_z;1741 [X,Y,Z]=meshgrid(Coord{3},Coord{2},Coord{1});% mesh in theinitial coordinates1748 XI=ObjectData.Coord(1)+ix(1)*Grid_x+iy(1)*Grid_y+iz(1)*Grid_z; 1749 YI=ObjectData.Coord(2)+ix(2)*Grid_x+iy(2)*Grid_y+iz(2)*Grid_z; 1750 ZI=ObjectData.Coord(3)+ix(3)*Grid_x+iy(3)*Grid_y+iz(3)*Grid_z; 1751 % [X,Y,Z]=meshgrid(Coord{3},Coord{2},Coord{1});% grid of initial coordinates 1742 1752 for ivar=VarIndex 1743 1753 VarName=FieldData.ListVarName{ivar}; … … 1745 1755 VarDimName=[VarDimName {{'coord_y','coord_x'}}]; 1746 1756 VarAttribute{length(ListVarName)}=FieldData.VarAttribute{ivar}; %reproduce the variable attributes 1747 FieldData.(VarName)=permute(FieldData.(VarName),[2 3 1]); 1757 FieldData.(VarName)=permute(FieldData.(VarName),[2 3 1]); %coordinate permutation needed to use interp3 1758 indexnan=isnan(FieldData.(VarName)); 1759 FieldData.(VarName)(indexnan)=0;%set to zero the undefined values 1748 1760 ProjData.coord_x=coord_x_proj; 1749 1761 ProjData.coord_y=coord_y_proj; 1750 ProjData.(VarName)=interp3( X,Y,Z,double(FieldData.(VarName)),XI,YI,ZI,'*linear');1751 ProjData.(VarName)=nanmean(ProjData.(VarName), 3);1762 ProjData.(VarName)=interp3(Coord{3},Coord{2},Coord{1},double(FieldData.(VarName)),ZI,YI,XI,'*linear'); 1763 ProjData.(VarName)=nanmean(ProjData.(VarName),1); 1752 1764 ProjData.(VarName)=squeeze(ProjData.(VarName)); 1753 1765 end
Note: See TracChangeset
for help on using the changeset viewer.