Changeset 1112 for trunk/src/transform_field
- Timestamp:
- Jan 26, 2022, 7:37:21 PM (3 years ago)
- Location:
- trunk/src/transform_field
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/transform_field/phys.m
r1107 r1112 55 55 DataOut=DataIn;%default first output field 56 56 if nargin>=2 % nargin =nbre of input variables 57 Calib{1}=[]; 57 58 if isfield(XmlData,'GeometryCalib') 58 59 Calib{1}=XmlData.GeometryCalib; 59 else 60 Calib{1}=[]; 60 end 61 Slice{1}=Calib{1}; 62 if isfield(XmlData,'Slice') 63 Slice{1}=XmlData.Slice; 61 64 end 62 65 if nargin>=3 %two input fields 63 66 DataOut_1=DataIn_1;%default second output field 64 if nargin>=4 && isfield(XmlData_1,'GeometryCalib') 65 Calib{2}=XmlData_1.GeometryCalib; 66 else 67 Calib{2}=Calib{1}; 67 Calib{2}=Calib{1}; 68 if nargin>=4 69 if isfield(XmlData_1,'GeometryCalib') 70 Calib{2}=XmlData_1.GeometryCalib; 71 end 72 Slice{2}=Calib{2}; 73 if isfield(XmlData_1,'Slice') 74 Slice{2}=XmlData_1.Slice; 75 end 68 76 end 69 77 end … … 71 79 72 80 %% get the z index defining the section plane 81 ZIndex=1; 73 82 if isfield(DataIn,'ZIndex')&&~isempty(DataIn.ZIndex)&&~isnan(DataIn.ZIndex) 74 83 ZIndex=DataIn.ZIndex; 75 else76 ZIndex=1;77 84 end 78 85 … … 82 89 if ~isempty(Calib{1}) 83 90 if isfield(Calib{1},'CalibrationType')&& isfield(Calib{1},'CoordUnit') && isfield(DataIn,'CoordUnit')&& strcmp(DataIn.CoordUnit,'pixel') 84 DataOut=phys_1(DataIn,Calib{1}, ZIndex);% transform coordinates and velocity components91 DataOut=phys_1(DataIn,Calib{1},Slice{1},ZIndex);% transform coordinates and velocity components 85 92 %case of images or scalar: in case of two input fields, we need to project the transform on the same regular grid 86 93 if isfield(DataIn,'A') && isfield(DataIn,'Coord_x') && ~isempty(DataIn.Coord_x) && isfield(DataIn,'Coord_y')&&... … … 94 101 95 102 %% document the selected plane position and angle if relevant 96 if checktransform && isfield( Calib{1},'SliceCoord')&&size(Calib{1}.SliceCoord,1)>=ZIndex97 DataOut.PlaneCoord= Calib{1}.SliceCoord(ZIndex,:);% transfer the slice position corresponding to index ZIndex98 if isfield( Calib{1},'SliceAngle') % transfer the slice rotation angles99 if isequal(size( Calib{1}.SliceAngle,1),1)% case of a unique angle100 DataOut.PlaneAngle= Calib{1}.SliceAngle;103 if checktransform && isfield(Slice{1},'SliceCoord')&&size(Slice{1}.SliceCoord,1)>=ZIndex 104 DataOut.PlaneCoord=Slice{1}.SliceCoord(ZIndex,:);% transfer the slice position corresponding to index ZIndex 105 if isfield(Slice{1},'SliceAngle') % transfer the slice rotation angles 106 if isequal(size(Slice{1}.SliceAngle,1),1)% case of a unique angle 107 DataOut.PlaneAngle=Slice{1}.SliceAngle; 101 108 else % case of multiple planes with different angles: select the plane with index ZIndex 102 DataOut.PlaneAngle= Calib{1}.SliceAngle(ZIndex,:);109 DataOut.PlaneAngle=Slice{1}.SliceAngle(ZIndex,:); 103 110 end 104 111 end … … 113 120 end 114 121 if isfield(Calib{2},'CalibrationType')&&isfield(Calib{2},'CoordUnit') && isfield(DataIn_1,'CoordUnit')&& strcmp(DataIn_1.CoordUnit,'pixel') 115 DataOut_1=phys_1(DataOut_1,Calib{2}, ZIndex);116 if isfield( Calib{1},'SliceCoord')117 if ~(isfield( Calib{2},'SliceCoord') && isequal(Calib{2}.SliceCoord,Calib{1}.SliceCoord))122 DataOut_1=phys_1(DataOut_1,Calib{2},Slice{2},ZIndex); 123 if isfield(Slice{2},'SliceCoord') 124 if ~(isfield(Slice{2},'SliceCoord') && isequal(Slice{2}.SliceCoord,Slice{1}.SliceCoord)) 118 125 DataOut_1.Txt='different plane positions for the two input fields'; 119 126 return 120 127 end 121 128 DataOut_1.PlaneCoord=DataOut.PlaneCoord;% same plane position for the two input fields 122 if isfield( Calib{1},'SliceAngle')123 if ~(isfield( Calib{2},'SliceAngle') && isequal(Calib{2}.SliceAngle,Calib{1}.SliceAngle))129 if isfield(Slice{1},'SliceAngle') 130 if ~(isfield(Slice{2},'SliceAngle') && isequal(Slice{2}.SliceAngle,Slice{1}.SliceAngle)) 124 131 DataOut_1.Txt='different plane angles for the two input fields'; 125 132 return … … 131 138 ~isempty(DataIn_1.Coord_y)&&length(DataIn_1.A)>1 132 139 iscalar=iscalar+1; 133 Calib{iscalar}=Calib{2};140 % Calib{iscalar}=Calib{2}; 134 141 A{iscalar}=DataIn_1.A; 135 142 end … … 163 170 %------------------------------------------------ 164 171 %--- transform a single field 165 function DataOut=phys_1(Data,Calib, ZIndex)172 function DataOut=phys_1(Data,Calib,Slice,ZIndex) 166 173 %------------------------------------------------ 167 174 %% set default output … … 171 178 %% transform X,Y coordinates for velocity fields (transform of an image or scalar done in phys_ima) 172 179 if isfield(Data,'X') &&isfield(Data,'Y')&&~isempty(Data.X) && ~isempty(Data.Y) 173 [DataOut.X,DataOut.Y]=phys_XYZ(Calib, Data.X,Data.Y,ZIndex);180 [DataOut.X,DataOut.Y]=phys_XYZ(Calib,Slice,Data.X,Data.Y,ZIndex); 174 181 Dt=1; %default 175 182 if isfield(Data,'dt')&&~isempty(Data.dt) … … 180 187 end 181 188 if isfield(Data,'U')&&isfield(Data,'V')&&~isempty(Data.U) && ~isempty(Data.V) 182 [XOut_1,YOut_1]=phys_XYZ(Calib, Data.X-Data.U/2,Data.Y-Data.V/2,ZIndex);183 [XOut_2,YOut_2]=phys_XYZ(Calib, Data.X+Data.U/2,Data.Y+Data.V/2,ZIndex);189 [XOut_1,YOut_1]=phys_XYZ(Calib,Slice,Data.X-Data.U/2,Data.Y-Data.V/2,ZIndex); 190 [XOut_2,YOut_2]=phys_XYZ(Calib,Slice,Data.X+Data.U/2,Data.Y+Data.V/2,ZIndex); 184 191 DataOut.U=(XOut_2-XOut_1)/Dt; 185 192 DataOut.V=(YOut_2-YOut_1)/Dt; … … 213 220 % estimate the Jacobian matrix DXpx/DXphys 214 221 for ip=1:length(Data.X) 215 [Xp1,Yp1]=phys_XYZ(Calib, Data.X(ip)+0.5,Data.Y(ip),ZIndex);216 [Xm1,Ym1]=phys_XYZ(Calib, Data.X(ip)-0.5,Data.Y(ip),ZIndex);217 [Xp2,Yp2]=phys_XYZ(Calib, Data.X(ip),Data.Y(ip)+0.5,ZIndex);218 [Xm2,Ym2]=phys_XYZ(Calib, Data.X(ip),Data.Y(ip)-0.5,ZIndex);222 [Xp1,Yp1]=phys_XYZ(Calib,Slice,Data.X(ip)+0.5,Data.Y(ip),ZIndex); 223 [Xm1,Ym1]=phys_XYZ(Calib,Slice,Data.X(ip)-0.5,Data.Y(ip),ZIndex); 224 [Xp2,Yp2]=phys_XYZ(Calib,Slice,Data.X(ip),Data.Y(ip)+0.5,ZIndex); 225 [Xm2,Ym2]=phys_XYZ(Calib,Slice,Data.X(ip),Data.Y(ip)-0.5,ZIndex); 219 226 %Jacobian matrix DXpphys/DXpx 220 227 DjXi(1,1)=(Xp1-Xm1); -
trunk/src/transform_field/phys_polar.m
r1107 r1112 78 78 Data=DataIn; %default output 79 79 if isfield(Data,'CoordUnit') 80 Data=rmfield(Data,'CoordUnit');80 Data=rmfield(Data,'CoordUnit'); 81 81 end 82 82 Data.ListVarName = {}; … … 85 85 DataCell{1}=DataIn; 86 86 Calib{1}=[]; 87 Slice{1}=[]; 87 88 DataCell{2}=[];%default 88 89 checkpixel(1)=0; 89 if isfield(DataCell{1},'CoordUnit')&& strcmp(DataCell{1}.CoordUnit,'pixel') 90 if isfield(DataCell{1},'CoordUnit')&& strcmp(DataCell{1}.CoordUnit,'pixel') 90 91 checkpixel(1)=1; 91 92 end … … 94 95 Calib{1}=XmlData.GeometryCalib; 95 96 end 97 Slice{1}=Calib{1}; 98 if isfield(XmlData,'Slice') 99 Slice{1}=XmlData.Slice; 100 end 96 101 Calib{2}=Calib{1}; 102 Slice{2}=Slice{1}; 97 103 else 98 104 Data.Txt='wrong input: need two or four structures'; … … 101 107 if nargin==4% case of two input fields 102 108 checkpixel(2)=0; 103 if isfield(DataCell{2},'CoordUnit')&& strcmp(DataCell{2}.CoordUnit,'pixel') 104 checkpixel(2)=1;105 end109 if isfield(DataCell{2},'CoordUnit')&& strcmp(DataCell{2}.CoordUnit,'pixel') 110 checkpixel(2)=1; 111 end 106 112 DataCell{2}=DataIn_1;%default 107 113 if isfield(XmlData_1,'GeometryCalib')&& ~isempty(XmlData_1.GeometryCalib) && checkpixel(2) 108 114 Calib{2}=XmlData_1.GeometryCalib; 115 end 116 if isfield(XmlData_1,'Slice') 117 Slice{2}=XmlData_1.Slice; 109 118 end 110 119 nbinput=2; … … 218 227 if ~isempty(Calib{ifield}) 219 228 [X,Y,Z,DataCell{ifield}.(UName),DataCell{ifield}.(VName)]=... 220 phys_XYUV(DataCell{ifield},Calib{ifield}, ZIndex);229 phys_XYUV(DataCell{ifield},Calib{ifield},Slice{ifield},ZIndex); 221 230 end 222 231 end … … 304 313 ZInd(nbgrid)=ZIndex; 305 314 Calib_new{nbgrid}=Calib{ifield}; 315 Slice_new{nbgrid}=Slice{ifield}; 306 316 end 307 317 if isfield(CellInfo{icell},'VarIndex_vector_x')&& isfield(CellInfo{icell},'VarIndex_vector_y') … … 325 335 Calib_new{nbgrid+1}=Calib{ifield}; 326 336 Calib_new{nbgrid+2}=Calib{ifield}; 337 Slice_new{nbgrid+1}=Calib{ifield}; 338 Slice_new{nbgrid+2}=Calib{ifield}; 327 339 nbgrid=nbgrid+2; 328 340 nbvar=nbvar+2; … … 335 347 %% tranform cartesian to polar coordinates for gridded data 336 348 if nbgrid~=0 337 [A,Data.radius,Data.theta]=phys_Ima_polar(A,coord_x,coord_y,Calib_new, ZInd,origin_xy,radius_offset,angle_offset,angle_scale);349 [A,Data.radius,Data.theta]=phys_Ima_polar(A,coord_x,coord_y,Calib_new,Slice_new,ZInd,origin_xy,radius_offset,angle_offset,angle_scale); 338 350 for icell=1:numel(A) 339 351 if icell<=numel(A)-1 && check_vector(icell)==1 && check_vector(icell+1)==1 %transform u,v into polar coordinates … … 373 385 %------------------------------------------------ 374 386 %--- transform a single field into phys coordiantes 375 function [X,Y,Z,U,V]=phys_XYUV(Data,Calib, ZIndex)387 function [X,Y,Z,U,V]=phys_XYUV(Data,Calib,Slice,ZIndex) 376 388 %------------------------------------------------ 377 389 %% set default output … … 385 397 %% transform X,Y coordinates for velocity fields (transform of an image or scalar done in phys_ima) 386 398 if isfield(Data,'X') &&isfield(Data,'Y')&&~isempty(Data.X) && ~isempty(Data.Y) 387 [X,Y,Z]=phys_XYZ(Calib, Data.X,Data.Y,ZIndex);399 [X,Y,Z]=phys_XYZ(Calib,Slice,Data.X,Data.Y,ZIndex); 388 400 Dt=1; %default 389 401 if isfield(Data,'dt')&&~isempty(Data.dt) … … 394 406 end 395 407 if isfield(Data,'U')&&isfield(Data,'V')&&~isempty(Data.U) && ~isempty(Data.V) 396 [XOut_1,YOut_1]=phys_XYZ(Calib, Data.X-Data.U/2,Data.Y-Data.V/2,ZIndex);397 [XOut_2,YOut_2]=phys_XYZ(Calib, Data.X+Data.U/2,Data.Y+Data.V/2,ZIndex);408 [XOut_1,YOut_1]=phys_XYZ(Calib,Slice,Data.X-Data.U/2,Data.Y-Data.V/2,ZIndex); 409 [XOut_2,YOut_2]=phys_XYZ(Calib,Slice,Data.X+Data.U/2,Data.Y+Data.V/2,ZIndex); 398 410 U=(XOut_2-XOut_1)/Dt; 399 411 V=(YOut_2-YOut_1)/Dt; … … 404 416 % tranform gridded field into polar coordiantes on a regular polar grid, 405 417 % transform to phys coordiantes if requested by calibration input 406 function [A_out,radius,theta]=phys_Ima_polar(A,coord_x,coord_y,CalibIn, ZIndex,origin_xy,radius_offset,angle_offset,angle_scale)418 function [A_out,radius,theta]=phys_Ima_polar(A,coord_x,coord_y,CalibIn,SliceIn,ZIndex,origin_xy,radius_offset,angle_offset,angle_scale) 407 419 rcorner=[]; 408 420 thetacorner=[]; … … 420 432 % transform edges into phys coordinates if requested 421 433 if ~isempty(CalibIn{icell}) 422 [x_edge,y_edge]=phys_XYZ(CalibIn{icell}, x_edge,y_edge,ZIndex(icell));% physical coordinates of the image edge434 [x_edge,y_edge]=phys_XYZ(CalibIn{icell},SliceIn{icell},x_edge,y_edge,ZIndex(icell));% physical coordinates of the image edge 423 435 end 424 436
Note: See TracChangeset
for help on using the changeset viewer.