[8] | 1 | %'proj_field': projects the field on a projection object
|
---|
| 2 | %--------------------------------------------------------------------------
|
---|
[156] | 3 | % function [ProjData,errormsg]=proj_field(FieldData,ObjectData)
|
---|
[8] | 4 | %
|
---|
| 5 | % OUTPUT:
|
---|
| 6 | % ProjData structure containing the fields of the input field FieldData,
|
---|
| 7 | % transmitted or projected on the object, plus the additional fields
|
---|
| 8 | % .UMax, .UMin, .VMax, .VMin: min and max of velocity components in a domain
|
---|
| 9 | % .UMean,VMean: mean of the velocity components in a domain
|
---|
| 10 | % .AMin, AMax: min and max of a scalar
|
---|
| 11 | % .AMean: mean of a scalar in a domain
|
---|
| 12 | % .NbPix;
|
---|
| 13 | % .DimName= names of the matrix dimensions (matlab cell)
|
---|
| 14 | % .VarName= names of the variables [ProjData.VarName {'A','AMean','AMin','AMax'}];
|
---|
| 15 | % .VarDimNameIndex= dimensions of the variables, indicated by indices in the list .DimName;
|
---|
| 16 | %
|
---|
| 17 | %INPUT
|
---|
| 18 | % ObjectData: structure characterizing the projection object
|
---|
| 19 | % .Style : style of projection object
|
---|
| 20 | % .ProjMode=type of projection ;
|
---|
| 21 | % .CoordType: 'px' or 'phys' type of coordinates defining the object position
|
---|
| 22 | % .Phi angle of rotation (=0 by default)
|
---|
| 23 | % .ProjAngle=angle of projection;
|
---|
| 24 | % .DX,.DY,.DZ=increments along each coordinate
|
---|
| 25 | % .Coord(nbpoints,3): set of coordinates defining the object position;
|
---|
| 26 |
|
---|
| 27 | %FieldData: data of the field to be projected on the projection object, with optional fields
|
---|
| 28 | % .Txt: error message, transmitted to the projection
|
---|
| 29 | % .CoordType: 'px' or 'phys' type of coordinates of the field, must be the same as for the projection object, transmitted
|
---|
| 30 | % .Mesh: typical distance between data points (used for mouse action or display), transmitted
|
---|
| 31 | % .CoordUnit, .TimeUnit, .dt: transmitted
|
---|
| 32 | % standardised description of fields, nc-formated Matlab structure with fields:
|
---|
| 33 | % .ListGlobalAttribute: cell listing the names of the global attributes
|
---|
| 34 | % .Att_1,Att_2... : values of the global attributes
|
---|
| 35 | % .ListVarName: cell listing the names of the variables
|
---|
| 36 | % .VarAttribute: cell of structures s containing names and values of variable attributes (s.name=value) for each variable of .ListVarName
|
---|
| 37 | % .Var1, .Var2....: variables (Matlab arrays) with names listed in .ListVarName
|
---|
| 38 | % The variables are grouped in 'fields', made of a set of variables with common dimensions (using the function find_field_indices)
|
---|
| 39 | % The variable attribute 'Role' is used to define the role for plotting:
|
---|
| 40 | % Role = 'scalar': (default) represents a scalar field
|
---|
| 41 | % = 'coord': represents a set of unstructured coordinates, whose
|
---|
| 42 | % space dimension is given by the last array dimension (called 'nb_dim').
|
---|
| 43 | % = 'coord_x', 'coord_y', 'coord_z': represents a separate set of
|
---|
| 44 | % unstructured coordinate x, y or z
|
---|
| 45 | % = 'vector': represents a vector field whose number of components
|
---|
| 46 | % is given by the last dimension (called 'nb_dim')
|
---|
| 47 | % = 'vector_x', 'vector_y', 'vector_z' :represents the x, y or z component of a vector
|
---|
| 48 | % = 'warnflag' : provides a warning flag about the quality of data in a 'Field', default=0, no warning
|
---|
| 49 | % = 'errorflag': provides an error flag marking false data,
|
---|
| 50 | % default=0, no error. Different non zero values can represent different criteria of elimination.
|
---|
| 51 | %
|
---|
| 52 | % Default role of variables (by name)
|
---|
| 53 | % vector field:
|
---|
| 54 | % .X,.Y: position of the velocity vectors, projected on the object
|
---|
| 55 | % .U, .V, .W: velocity components, projected on the object
|
---|
| 56 | % .C, .CName: scalar associated to the vector
|
---|
| 57 | % .F : equivalent to 'warnflag'
|
---|
| 58 | % .FF: equivalent to 'errorflag'
|
---|
| 59 | % scalar field or image:
|
---|
| 60 | % .AName: name of a scalar (to be calculated from velocity fields after projection), transmitted
|
---|
| 61 | % .A: scalar, projected on the object
|
---|
| 62 | % .AX, .AY: positions for the scalar
|
---|
| 63 | % case of a structured grid: A is a dim 2 matrix and .AX=[first last] (length 2 vector) represents the first and last abscissa of the grid
|
---|
| 64 | % case of an unstructured scalar: A is a vector, AX and AY the corresponding coordinates
|
---|
| 65 | %
|
---|
| 66 | %AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
|
---|
| 67 | % Copyright Joel Sommeria, 2008, LEGI / CNRS-UJF-INPG, sommeria@coriolis-legi.org.
|
---|
| 68 | %AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
|
---|
| 69 | % This file is part of the toolbox UVMAT.
|
---|
| 70 | %
|
---|
| 71 | % UVMAT is free software; you can redistribute it and/or modify
|
---|
| 72 | % it under the terms of the GNU General Public License as published by
|
---|
| 73 | % the Free Software Foundation; either version 2 of the License, or
|
---|
| 74 | % (at your option) any later version.
|
---|
| 75 | %
|
---|
| 76 | % UVMAT is distributed in the hope that it will be useful,
|
---|
| 77 | % but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
| 78 | % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
| 79 | % GNU General Public License (file UVMAT/COPYING.txt) for more details.
|
---|
| 80 | %AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
|
---|
| 81 |
|
---|
[156] | 82 | function [ProjData,errormsg]=proj_field(FieldData,ObjectData)
|
---|
[150] | 83 | errormsg=[];%default
|
---|
[8] | 84 | if isfield(ObjectData,'ProjMode') && (isequal(ObjectData.ProjMode,'none')||isequal(ObjectData.ProjMode,'mask_inside')||isequal(ObjectData.ProjMode,'mask_outside'))
|
---|
| 85 | ProjData=[];
|
---|
| 86 | return
|
---|
| 87 | end
|
---|
| 88 | %introduce default field properties (reading old standards)
|
---|
[158] | 89 | if ~isfield(ObjectData,'Style')||~isfield(ObjectData,'ProjMode')
|
---|
[8] | 90 | ProjData=FieldData;
|
---|
| 91 | return
|
---|
| 92 | end
|
---|
[158] | 93 | if ~isfield(ObjectData,'Coord')
|
---|
| 94 | if strcmp(ObjectData.Style,'plane')
|
---|
| 95 | ObjectData.Coord=[0 0 0];%default
|
---|
| 96 | else
|
---|
| 97 | ProjData=FieldData;
|
---|
| 98 | return
|
---|
| 99 | end
|
---|
| 100 | end
|
---|
| 101 |
|
---|
[8] | 102 | % OBSOLETE
|
---|
| 103 | if isfield(ObjectData,'XMax') && ~isempty(ObjectData.XMax)
|
---|
| 104 | ObjectData.RangeX(1)=ObjectData.XMax;
|
---|
| 105 | end
|
---|
| 106 | if isfield(ObjectData,'XMin') && ~isempty(ObjectData.XMin)
|
---|
| 107 | ObjectData.RangeX(2)=ObjectData.XMin;
|
---|
| 108 | end
|
---|
| 109 | if isfield(ObjectData,'YMax') && ~isempty(ObjectData.YMax)
|
---|
| 110 | ObjectData.RangeY(1)=ObjectData.YMax;
|
---|
| 111 | end
|
---|
| 112 | if isfield(ObjectData,'YMin') && ~isempty(ObjectData.YMin)
|
---|
| 113 | ObjectData.RangeY(2)=ObjectData.YMin;
|
---|
| 114 | end
|
---|
| 115 | if isfield(ObjectData,'ZMax') && ~isempty(ObjectData.ZMax)
|
---|
| 116 | ObjectData.RangeZ(1)=ObjectData.ZMax;
|
---|
| 117 | end
|
---|
| 118 | if isfield(ObjectData,'ZMin') && ~isempty(ObjectData.ZMin)
|
---|
| 119 | ObjectData.RangeZ(2)=ObjectData.ZMin;
|
---|
| 120 | end
|
---|
| 121 | %%%%%%%%%%
|
---|
[77] | 122 | switch ObjectData.Style
|
---|
| 123 | case 'points'
|
---|
[8] | 124 | [ProjData,errormsg]=proj_points(FieldData,ObjectData);
|
---|
[77] | 125 | case {'line','polyline'}
|
---|
[8] | 126 | [ProjData,errormsg] = proj_line(FieldData,ObjectData);
|
---|
[77] | 127 | case {'polygon','rectangle','ellipse'}
|
---|
| 128 | if isequal(ObjectData.ProjMode,'inside')||isequal(ObjectData.ProjMode,'outside')
|
---|
| 129 | [ProjData,errormsg] = proj_patch(FieldData,ObjectData);
|
---|
| 130 | else
|
---|
| 131 | [ProjData,errormsg] = proj_line(FieldData,ObjectData);
|
---|
| 132 | end
|
---|
[8] | 133 | %A FAIRE : GERER MASK
|
---|
[77] | 134 | case 'plane'
|
---|
[8] | 135 | % if isfield(FieldData,'NbDim') & isequal(FieldData.NbDim,3)
|
---|
| 136 | % ProjData= proj_plane3D(FieldData,ObjectData);%
|
---|
| 137 | % else
|
---|
| 138 | [ProjData,errormsg] = proj_plane(FieldData,ObjectData);
|
---|
| 139 | % end
|
---|
[77] | 140 | case 'volume'
|
---|
| 141 | [ProjData,errormsg] = proj_volume(FieldData,ObjectData);
|
---|
[8] | 142 | end
|
---|
| 143 |
|
---|
[158] | 144 |
|
---|
[8] | 145 | %-----------------------------------------------------------------
|
---|
| 146 | %project on a set of points
|
---|
| 147 | function [ProjData,errormsg]=proj_points(FieldData,ObjectData)%%
|
---|
| 148 | %-------------------------------------------------------------------
|
---|
| 149 |
|
---|
| 150 | siz=size(ObjectData.Coord);
|
---|
| 151 | width=0;
|
---|
| 152 | if isfield(ObjectData,'Range')
|
---|
| 153 | width=ObjectData.Range(1,2);
|
---|
| 154 | end
|
---|
[77] | 155 | if isfield(ObjectData,'RangeX')&&~isempty(ObjectData.RangeX)
|
---|
[8] | 156 | width=max(ObjectData.RangeX);
|
---|
| 157 | end
|
---|
[77] | 158 | if isfield(ObjectData,'RangeY')&&~isempty(ObjectData.RangeY)
|
---|
[8] | 159 | width=max(width,max(ObjectData.RangeY));
|
---|
| 160 | end
|
---|
[77] | 161 | if isfield(ObjectData,'RangeZ')&&~isempty(ObjectData.RangeZ)
|
---|
[8] | 162 | width=max(width,max(ObjectData.RangeZ));
|
---|
| 163 | end
|
---|
| 164 | if isequal(ObjectData.ProjMode,'projection')
|
---|
| 165 | if width==0
|
---|
| 166 | errormsg='projection range around points needed';
|
---|
| 167 | return
|
---|
| 168 | end
|
---|
| 169 | elseif ~isequal(ObjectData.ProjMode,'interp')
|
---|
| 170 | errormsg=(['ProjMode option ' ObjectData.ProjMode ' not available in proj_field']);
|
---|
| 171 | return
|
---|
| 172 | end
|
---|
[150] | 173 | [ProjData,errormsg]=proj_heading(FieldData,ObjectData);
|
---|
[8] | 174 | ProjData.NbDim=0;
|
---|
| 175 | %ProjData.ListDimName= {'nb_points'};
|
---|
| 176 | %ProjData.DimValue=siz(1); %nbre of projection points
|
---|
| 177 |
|
---|
| 178 |
|
---|
| 179 | % idimvar=0;
|
---|
| 180 | [CellVarIndex,NbDim,VarTypeCell,errormsg]=find_field_indices(FieldData);
|
---|
| 181 | if ~isempty(errormsg)
|
---|
| 182 | errormsg=['error in proj_field/proj_points:' errormsg];
|
---|
| 183 | return
|
---|
| 184 | end
|
---|
| 185 | %LOOP ON GROUPS OF VARIABLES SHARING THE SAME DIMENSIONS
|
---|
| 186 | % CellVarIndex=cells of variable index arrays
|
---|
| 187 | % ivar_new=0; % index of the current variable in the projected field
|
---|
| 188 | % icoord=0;
|
---|
| 189 | for icell=1:length(CellVarIndex)
|
---|
| 190 | if NbDim(icell)==1
|
---|
| 191 | continue
|
---|
| 192 | end
|
---|
| 193 | VarIndex=CellVarIndex{icell};% indices of the selected variables in the list FieldData.ListVarName
|
---|
| 194 | VarType=VarTypeCell{icell};
|
---|
| 195 | ivar_X=VarType.coord_x;
|
---|
| 196 | ivar_Y=VarType.coord_y;
|
---|
| 197 | ivar_Z=VarType.coord_z;
|
---|
| 198 | % ivar_U=VarType.vector_x;
|
---|
| 199 | % ivar_V=VarType.vector_y;
|
---|
| 200 | % ivar_W=VarType.vector_z;
|
---|
| 201 | % ivar_C=VarType.scalar ;
|
---|
| 202 | ivar_Anc=VarType.ancillary;
|
---|
| 203 | % test_anc=zeros(size(VarIndex));
|
---|
| 204 | test_anc(ivar_Anc)=ones(size(ivar_Anc));
|
---|
| 205 | ivar_F=VarType.warnflag;
|
---|
| 206 | ivar_FF=VarType.errorflag;
|
---|
| 207 | VarIndex([ivar_X ivar_Y ivar_Z ivar_Anc ivar_F ivar_FF])=[];% not projected variables removed frlom list
|
---|
| 208 | if isempty(ivar_X)
|
---|
| 209 | test_grid=1;%test for input data on regular grid (e.g. image)coordinates
|
---|
| 210 |
|
---|
| 211 | else
|
---|
| 212 | if length(ivar_X)>1 | length(ivar_Y)>1 | length(ivar_Z)>1
|
---|
| 213 | errormsg='multiple coordinate input in proj_field.m';
|
---|
| 214 | return
|
---|
| 215 | end
|
---|
| 216 | if length(ivar_Y)~=1
|
---|
| 217 | errormsg='y coordinate not defined in proj_field.m';
|
---|
| 218 | return
|
---|
| 219 | end
|
---|
| 220 | test_grid=0;
|
---|
| 221 | end
|
---|
| 222 | ProjData.ListVarName={'Y','X','NbVal'};
|
---|
| 223 | ProjData.VarDimName={'nb_points','nb_points','nb_points'};
|
---|
| 224 | %ProjData.VarDimIndex={[1],[1],[1]};
|
---|
| 225 | ProjData.VarAttribute{1}.Role='ancillary';
|
---|
| 226 | ProjData.VarAttribute{2}.Role='ancillary';
|
---|
| 227 | ProjData.VarAttribute{3}.Role='ancillary';
|
---|
| 228 | for ivar=VarIndex
|
---|
| 229 | VarName=FieldData.ListVarName{ivar};
|
---|
| 230 | ProjData.ListVarName=[ProjData.ListVarName {VarName}];
|
---|
| 231 | %ProjData.VarDimIndex=[ProjData.VarDimIndex {[1]}];
|
---|
| 232 | ProjData.VarDimName=[ProjData.VarDimName {'nb_points'}];
|
---|
| 233 | end
|
---|
| 234 | if ~test_grid
|
---|
| 235 | eval(['coord_x=FieldData.' FieldData.ListVarName{ivar_X} ';'])
|
---|
| 236 | eval(['coord_y=FieldData.' FieldData.ListVarName{ivar_Y} ';'])
|
---|
| 237 | test3D=0;% TEST 3D CASE : NOT COMPLETED , 3D CASE : NOT COMPLETED
|
---|
| 238 | if length(ivar_Z)==1
|
---|
| 239 | eval(['coord_z=FieldData.' FieldData.ListVarName{ivar_Z} ';'])
|
---|
| 240 | test3D=1;
|
---|
| 241 | end
|
---|
| 242 | if length(ivar_F)>1 | length(ivar_FF)>1
|
---|
[38] | 243 | msgbox_uvmat('ERROR','multiple flag input in proj_field.m')
|
---|
[8] | 244 | return
|
---|
[38] | 245 | end
|
---|
[8] | 246 | for ipoint=1:siz(1)
|
---|
| 247 | Xpoint=ObjectData.Coord(ipoint,:);
|
---|
| 248 | distX=coord_x-Xpoint(1);
|
---|
| 249 | distY=coord_y-Xpoint(2);
|
---|
| 250 | dist=distX.*distX+distY.*distY;
|
---|
| 251 | indsel=find(dist<width*width);
|
---|
| 252 | ProjData.X(ipoint,1)=Xpoint(1);
|
---|
| 253 | ProjData.Y(ipoint,1)=Xpoint(2);
|
---|
| 254 | if isequal(length(ivar_FF),1)
|
---|
| 255 | FFName=FieldData.ListVarName{ivar_FF};
|
---|
| 256 | eval(['FF=FieldData.' FFName '(indsel);'])
|
---|
| 257 | ind_indsel=find(~FF);
|
---|
| 258 | indsel=indsel(ind_indsel);
|
---|
| 259 | end
|
---|
| 260 | ProjData.NbVal(ipoint,1)=length(indsel);
|
---|
| 261 | for ivar=VarIndex
|
---|
| 262 | VarName=FieldData.ListVarName{ivar};
|
---|
| 263 | if isempty(indsel)
|
---|
| 264 | eval(['ProjData.' VarName '(ipoint,1)=NaN;'])
|
---|
| 265 | else
|
---|
| 266 | eval(['Var=FieldData.' VarName '(indsel);'])
|
---|
| 267 | eval(['ProjData.' VarName '(ipoint,1)=mean(Var);'])
|
---|
| 268 | if isequal(ObjectData.ProjMode,'interp')
|
---|
| 269 | eval(['ProjData.' VarName '(ipoint,1)=griddata_uvmat(coord_x(indsel),coord_y(indsel),Var,Xpoint(1),Xpoint(2)))';])
|
---|
| 270 | end
|
---|
| 271 | end
|
---|
| 272 | end
|
---|
| 273 | end
|
---|
| 274 | else
|
---|
| 275 | %DimIndices=FieldData.VarDimIndex{VarIndex(1)};%indices of the dimensions of the first variable (common to all variables in the cell)
|
---|
| 276 | %case of structured coordinates
|
---|
| 277 | if numel(VarType.coord)>=2 & VarType.coord(1:2) > 0;
|
---|
| 278 | AYName=FieldData.ListVarName{VarType.coord(1)};
|
---|
| 279 | AXName=FieldData.ListVarName{VarType.coord(2)};
|
---|
| 280 | eval(['AX=FieldData.' AXName ';']);% set of x positions
|
---|
| 281 | eval(['AY=FieldData.' AYName ';']);% set of y positions
|
---|
| 282 | AName=FieldData.ListVarName{VarIndex(1)};
|
---|
| 283 | eval(['A=FieldData.' AName ';']);% scalar
|
---|
| 284 | npxy=size(A);
|
---|
| 285 |
|
---|
| 286 | % % nbcolor=1; %default
|
---|
| 287 | % for idim=1:length(ListDimName)
|
---|
| 288 | % DimName=ListDimName{idim};
|
---|
| 289 | % if isequal(DimName,'rgb')|isequal(DimName,'nb_coord')|isequal(DimName,'nb_coord_i')
|
---|
| 290 | % nbcolor=npxy(idim);
|
---|
| 291 | % DimIndices(idim)=[];
|
---|
| 292 | % npxy(idim)=[];
|
---|
| 293 | % end
|
---|
| 294 | % if isequal(DimName,'nb_coord_j')% NOTE: CASE OF TENSOR NOT TREATED
|
---|
| 295 | % DimIndices(idim)=[];
|
---|
| 296 | % npxy(idim)=[];
|
---|
| 297 | % end
|
---|
| 298 | % end
|
---|
| 299 | ind_1=find(npxy==1);
|
---|
| 300 | %DimIndices(ind_1)=[]; %suppress singleton dimensions
|
---|
| 301 | % indxy=find(DimVarIndex(DimIndices));%select dimension variables (DimIndices non zero)
|
---|
| 302 | %nb_dim=length(DimIndices)%number of space dimensions
|
---|
| 303 | nb_dim=numel(VarType.coord);
|
---|
| 304 | Coord_z=[];
|
---|
| 305 | Coord_y=[];
|
---|
| 306 | Coord_x=[];
|
---|
| 307 | for idim=1:nb_dim %loop on space dimensions
|
---|
| 308 | test_interp(idim)=0;%test for coordiate interpolation (non regular grid), =0 by default
|
---|
| 309 | test_coord(idim)=0;%test for defined coordinates, =0 by default
|
---|
| 310 | %ivar=DimVarIndex(DimIndices(idim));% index of the variable corresponding to the current dimension
|
---|
| 311 | ivar=VarType.coord(idim);
|
---|
| 312 | % if ~isequal(ivar,0)% a variable corresponds to the current dimension
|
---|
| 313 | eval(['Coord{idim}=FieldData.' FieldData.ListVarName{ivar} ';']) ;% position for the first index
|
---|
| 314 | if numel(Coord{idim})==2
|
---|
| 315 | DCoord_min(idim)= (Coord{idim}(2)-Coord{idim}(1))/(npxy(idim)-1);
|
---|
| 316 | else
|
---|
| 317 | DCoord=diff(Coord{idim});
|
---|
| 318 | DCoord_min(idim)=min(DCoord);
|
---|
| 319 | DCoord_max=max(DCoord);
|
---|
| 320 | test_direct(idim)=DCoord_max>0;% =1 for increasing values, 0 otherwise
|
---|
| 321 | test_direct_min=DCoord_min(idim)>0;% =1 for increasing values, 0 otherwise
|
---|
| 322 | if ~isequal(test_direct(idim),test_direct_min)
|
---|
| 323 | errormsg=['non monotonic dimension variable # ' num2str(idim) ' in proj_field.m'];
|
---|
| 324 | return
|
---|
| 325 | end
|
---|
| 326 | test_interp(idim)=(DCoord_max-DCoord_min(idim))> 0.0001*abs(DCoord_max);% test grid regularity
|
---|
| 327 | test_coord(idim)=1;
|
---|
| 328 | end
|
---|
| 329 | % else % no variable associated with the first dimension, look fo variable attributes Coord_1, _2 or _3
|
---|
| 330 | % Coord_i_str=['Coord_' num2str(idim)];
|
---|
| 331 | % DCoord_min(idim)=1;%default
|
---|
| 332 | % Coord{idim}=[0.5 npxy(idim)];
|
---|
| 333 | % test_direct(idim)=1;
|
---|
| 334 | % end
|
---|
| 335 | end
|
---|
| 336 | DX=DCoord_min(2);
|
---|
| 337 | DY=DCoord_min(1);
|
---|
| 338 | for ipoint=1:siz(1)
|
---|
| 339 | xwidth=width/(abs(DX));
|
---|
| 340 | ywidth=width/(abs(DY));
|
---|
| 341 | i_min=round((ObjectData.Coord(ipoint,1)-Coord{2}(1))/DX+0.5-xwidth); %minimum index of the selected region
|
---|
| 342 | i_min=max(1,i_min);%restrict to field limit
|
---|
| 343 | i_plus=round((ObjectData.Coord(ipoint,1)-Coord{2}(1))/DX+0.5+xwidth);
|
---|
| 344 | i_plus=min(npxy(2),i_plus); %restrict to field limit
|
---|
| 345 | j_min=round((ObjectData.Coord(ipoint,2)-Coord{1}(1))/DY-ywidth+0.5);
|
---|
| 346 | j_min=max(1,j_min);
|
---|
| 347 | j_plus=round((ObjectData.Coord(ipoint,2)-Coord{1}(1))/DY+ywidth+0.5);
|
---|
| 348 | j_plus=min(npxy(1),j_plus);
|
---|
| 349 | ProjData.X(ipoint,1)=ObjectData.Coord(ipoint,1);
|
---|
| 350 | ProjData.Y(ipoint,1)=ObjectData.Coord(ipoint,2);
|
---|
| 351 | i_int=[i_min:i_plus];
|
---|
| 352 | j_int=[j_min:j_plus];
|
---|
| 353 | ProjData.NbVal(ipoint,1)=length(j_int)*length(i_int);
|
---|
| 354 | if isempty(i_int) | isempty(j_int)
|
---|
| 355 | for ivar=VarIndex
|
---|
| 356 | eval(['ProjData.' FieldData.ListVarName{ivar} '(ipoint,:)=NaN;']);
|
---|
| 357 | end
|
---|
| 358 | errormsg=['no data points in the selected projection range ' num2str(width) ];
|
---|
| 359 | else
|
---|
| 360 | %TODO: introduce circle in the selected subregion
|
---|
| 361 | %[I,J]=meshgrid([1:j_int],[1:i_int]);
|
---|
| 362 | for ivar=VarIndex
|
---|
| 363 | eval(['Avalue=FieldData.' FieldData.ListVarName{ivar} '(j_int,i_int,:);']);
|
---|
| 364 | eval(['ProjData.' FieldData.ListVarName{ivar} '(ipoint,:)=mean(mean(Avalue));']);
|
---|
| 365 | end
|
---|
| 366 | end
|
---|
| 367 | end
|
---|
| 368 | end
|
---|
| 369 | end
|
---|
| 370 | end
|
---|
| 371 |
|
---|
| 372 | %-----------------------------------------------------------------
|
---|
| 373 | %project in a patch
|
---|
| 374 | function [ProjData,errormsg]=proj_patch(FieldData,ObjectData)%%
|
---|
| 375 | %-------------------------------------------------------------------
|
---|
[150] | 376 | [ProjData,errormsg]=proj_heading(FieldData,ObjectData);
|
---|
[8] | 377 |
|
---|
| 378 | objectfield=fieldnames(ObjectData);
|
---|
| 379 | widthx=0;
|
---|
| 380 | widthy=0;
|
---|
| 381 | if isfield(ObjectData,'RangeX')&~isempty(ObjectData.RangeX)
|
---|
| 382 | widthx=max(ObjectData.RangeX);
|
---|
| 383 | end
|
---|
| 384 | if isfield(ObjectData,'RangeY')&~isempty(ObjectData.RangeY)
|
---|
| 385 | widthy=max(ObjectData.RangeY);
|
---|
| 386 | end
|
---|
| 387 |
|
---|
| 388 | %A REVOIR, GENERALISER: UTILISER proj_line
|
---|
| 389 | ProjData.NbDim=1;
|
---|
[109] | 390 | %ProjData.ListDimName={};%name of dimension
|
---|
| 391 | %ProjData.DimValue=[];%values of dimension (nbre of vectors)
|
---|
[8] | 392 | ProjData.ListVarName={};
|
---|
| 393 | %ProjData.VarDimIndex={};
|
---|
| 394 | ProjData.VarDimName={};
|
---|
| 395 | if isfield (FieldData,'ListVarAttribute')
|
---|
| 396 | ProjData.ListVarAttribute=FieldData.ListVarAttribute;%list of variable attribute names
|
---|
| 397 | for iattr=1:length(ProjData.ListVarAttribute)%initialization of variable attribute values
|
---|
| 398 | AttrName=ProjData.ListVarAttribute{iattr};
|
---|
| 399 | eval(['ProjData.' AttrName '={};'])
|
---|
| 400 | end;
|
---|
| 401 | end
|
---|
| 402 |
|
---|
| 403 | %group the variables (fields of 'FieldData') in cells of variables with the same dimensions
|
---|
| 404 | testfalse=0;
|
---|
| 405 | ListIndex={};
|
---|
| 406 | % DimVarIndex=0;%initilise list of indices for dimension variables
|
---|
| 407 | idimvar=0;
|
---|
| 408 | [CellVarIndex,NbDim,VarTypeCell,errormsg]=find_field_indices(FieldData);
|
---|
| 409 | if ~isempty(errormsg)
|
---|
| 410 | errormsg=['error in proj_field/proj_patch:' errormsg];
|
---|
| 411 | return
|
---|
| 412 | end
|
---|
| 413 |
|
---|
| 414 | %LOOP ON GROUPS OF VARIABLES SHARING THE SAME DIMENSIONS
|
---|
| 415 | dimcounter=0;
|
---|
| 416 | for icell=1:length(CellVarIndex)
|
---|
| 417 | testX=0;
|
---|
| 418 | testY=0;
|
---|
| 419 | test_Amat=0;
|
---|
| 420 | testfalse=0;
|
---|
| 421 | VarIndex=CellVarIndex{icell};% indices of the selected variables in the list FieldData.ListVarName
|
---|
| 422 | VarType=VarTypeCell{icell};
|
---|
| 423 | % DimIndices=FieldData.VarDimIndex{VarIndex(1)};%indices of the dimensions of the first variable (common to all variables in the cell)
|
---|
| 424 | if NbDim(icell)~=2% proj_patch acts only on fields of space dimension 2
|
---|
| 425 | continue
|
---|
| 426 | end
|
---|
| 427 | testX=~isempty(VarType.coord_x) && ~isempty(VarType.coord_y);
|
---|
| 428 | testfalse=~isempty(VarType.errorflag);
|
---|
| 429 | testproj(VarIndex)=zeros(size(VarIndex));%default
|
---|
| 430 | testproj(VarType.scalar)=1;
|
---|
| 431 | testproj(VarType.vector_x)=1;
|
---|
| 432 | testproj(VarType.vector_y)=1;
|
---|
| 433 | testproj(VarType.vector_z)=1;
|
---|
| 434 | testproj(VarType.image)=1;
|
---|
| 435 | testproj(VarType.color)=1;
|
---|
| 436 | VarIndex=VarIndex(find(testproj(VarIndex)));%select only the projected variables
|
---|
| 437 | if testX %case of unstructured coordinates
|
---|
| 438 | eval(['nbpoint=numel(FieldData.' FieldData.ListVarName{VarIndex(1)} ');'])
|
---|
| 439 | for ivar=[VarIndex VarType.coord_x VarType.coord_y VarType.errorflag]
|
---|
| 440 | VarName=FieldData.ListVarName{ivar};
|
---|
| 441 | eval(['FieldData.' VarName '=reshape(FieldData.' VarName ',nbpoint,1);'])
|
---|
| 442 | end
|
---|
| 443 | XName=FieldData.ListVarName{VarType.coord_x};
|
---|
| 444 | YName=FieldData.ListVarName{VarType.coord_y};
|
---|
| 445 | eval(['coord_x=FieldData.' XName ';'])
|
---|
| 446 | eval(['coord_y=FieldData.' YName ';'])
|
---|
| 447 | end
|
---|
| 448 | if testfalse
|
---|
| 449 | FFName=FieldData.ListVarName{VarType.errorflag};
|
---|
| 450 | eval(['errorflag=FieldData.' FFName ';'])
|
---|
| 451 | end
|
---|
| 452 | % image or 2D matrix
|
---|
| 453 | if numel(VarType.coord)>=2 & VarType.coord(1:2) > 0;
|
---|
| 454 | test_Amat=1;%image or 2D matrix
|
---|
| 455 | AYName=FieldData.ListVarName{VarType.coord(1)};
|
---|
| 456 | AXName=FieldData.ListVarName{VarType.coord(2)};
|
---|
| 457 | eval(['AX=FieldData.' AXName ';'])% x coordinate
|
---|
| 458 | eval(['AY=FieldData.' AYName ';'])% y coordinate
|
---|
| 459 | VarName=FieldData.ListVarName{VarIndex(1)};
|
---|
| 460 | eval(['DimValue=size(FieldData.' VarName ');'])
|
---|
| 461 | testcolor=find(numel(DimValue)==3);
|
---|
| 462 | % errormsg='multicomponent field not projected';
|
---|
| 463 |
|
---|
| 464 | for idim=1:length(DimValue)
|
---|
| 465 | Coord_i_str=['Coord_' num2str(idim)];
|
---|
| 466 | DCoord_min(idim)=1;%default
|
---|
| 467 | Coord{idim}=[0.5 DimValue(idim)];
|
---|
| 468 | test_direct(idim)=1;
|
---|
| 469 | end
|
---|
| 470 | AX=linspace(Coord{2}(1),Coord{2}(2),DimValue(2));
|
---|
| 471 | AY=linspace(Coord{1}(1),Coord{1}(2),DimValue(1)); %TODO : 3D case
|
---|
| 472 | if length(DimValue)==3
|
---|
| 473 | testcolor=1;
|
---|
| 474 | npxy(3)=3;
|
---|
| 475 | else
|
---|
| 476 | testcolor=0;
|
---|
| 477 | npxy(3)=1;
|
---|
| 478 | end
|
---|
| 479 | [Xi,Yi]=meshgrid(AX,AY);
|
---|
| 480 | npxy(1)=length(AY);
|
---|
| 481 | npxy(2)=length(AX);
|
---|
| 482 | Xi=reshape(Xi,npxy(1)*npxy(2),1);
|
---|
| 483 | Yi=reshape(Yi,npxy(1)*npxy(2),1);
|
---|
| 484 | for ivar=1:length(VarIndex)
|
---|
| 485 | VarName=FieldData.ListVarName{VarIndex(ivar)};
|
---|
| 486 | eval(['FieldData.' VarName '=reshape(FieldData.' VarName ',npxy(1)*npxy(2),npxy(3));']); % keep only non false vectors
|
---|
| 487 | end
|
---|
| 488 | end
|
---|
| 489 | %select the indices in the range of action
|
---|
| 490 | testin=[];%default
|
---|
| 491 | if isequal(ObjectData.Style,'rectangle')
|
---|
| 492 | % if ~isfield(ObjectData,'RangeX')|~isfield(ObjectData,'RangeY')
|
---|
| 493 | % errormsg='rectangle half sides RangeX and RangeY needed'
|
---|
| 494 | % return
|
---|
| 495 | % end
|
---|
| 496 | if testX
|
---|
| 497 | distX=abs(coord_x-ObjectData.Coord(1,1));
|
---|
| 498 | distY=abs(coord_y-ObjectData.Coord(1,2));
|
---|
| 499 | testin=distX<widthx & distY<widthy;
|
---|
| 500 | elseif test_Amat
|
---|
| 501 | distX=abs(Xi-ObjectData.Coord(1,1));
|
---|
| 502 | distY=abs(Yi-ObjectData.Coord(1,2));
|
---|
| 503 | testin=distX<widthx & distY<widthy;
|
---|
| 504 | end
|
---|
| 505 | elseif isequal(ObjectData.Style,'polygon')
|
---|
| 506 | if testX
|
---|
| 507 | testin=inpolygon(coord_x,coord_y,ObjectData.Coord(:,1),ObjectData.Coord(:,2));
|
---|
| 508 | elseif test_Amat
|
---|
| 509 | testin=inpolygon(Xi,Yi,ObjectData.Coord(:,1),ObjectData.Coord(:,2));
|
---|
| 510 | else%calculate the scalar
|
---|
| 511 | testin=[]; %A REVOIR
|
---|
| 512 | end
|
---|
| 513 | elseif isequal(ObjectData.Style,'ellipse')
|
---|
| 514 | X2Max=widthx*widthx;
|
---|
| 515 | Y2Max=(widthy)*(widthy);
|
---|
| 516 | if testX
|
---|
| 517 | distX=(coord_x-ObjectData.Coord(1,1));
|
---|
| 518 | distY=(coord_y-ObjectData.Coord(1,2));
|
---|
| 519 | testin=(distX.*distX/X2Max+distY.*distY/Y2Max)<1;
|
---|
| 520 | elseif test_Amat %case of usual 2x2 matrix
|
---|
| 521 | distX=(Xi-ObjectData.Coord(1,1));
|
---|
| 522 | distY=(Yi-ObjectData.Coord(1,2));
|
---|
| 523 | testin=(distX.*distX/X2Max+distY.*distY/Y2Max)<1;
|
---|
| 524 | end
|
---|
| 525 | end
|
---|
| 526 | %selected indices
|
---|
| 527 | if isequal(ObjectData.ProjMode,'outside')
|
---|
| 528 | testin=~testin;
|
---|
| 529 | end
|
---|
| 530 | if testfalse
|
---|
| 531 | testin=testin & (errorflag==0); % keep only non false vectors
|
---|
| 532 | end
|
---|
| 533 | indsel=find(testin);
|
---|
| 534 | for ivar=VarIndex
|
---|
| 535 | if testproj(ivar)
|
---|
| 536 | VarName=FieldData.ListVarName{ivar};
|
---|
| 537 | eval(['ProjData.' VarName 'Mean=mean(mean(double(FieldData.' VarName '(indsel,:))));']); % keep only non false vectors
|
---|
| 538 | eval(['[ProjData.' VarName 'Histo,ProjData.' VarName ']=hist(double(FieldData.' VarName '(indsel,:)),100);']); % keep only non false vectors
|
---|
| 539 | ProjData.ListVarName=[ProjData.ListVarName {VarName} {[VarName 'Histo']} {[VarName 'Mean']}];
|
---|
| 540 | if test_Amat && testcolor
|
---|
| 541 | ProjData.VarDimName=[ProjData.VarDimName {VarName} {{VarName,'rgb'}} {'rgb'}];%{{'nb_point','rgb'}};
|
---|
| 542 | else
|
---|
| 543 | ProjData.VarDimName=[ProjData.VarDimName {VarName} {VarName} {'nbpoint'}];
|
---|
| 544 | end
|
---|
| 545 | end
|
---|
| 546 | end
|
---|
| 547 | % if test_Amat & testcolor
|
---|
| 548 | % %ProjData.ListDimName=[ProjData.ListDimName {'rgb'}];
|
---|
| 549 | % % ProjData.DimValue=[ProjData.DimValue 3];
|
---|
| 550 | % % ProjData.VarDimIndex={[1 2]};
|
---|
| 551 | % ProjData.VarDimName=[ProjData.VarDimName {VarName} {VarName,'rgb'}];%{{'nb_point','rgb'}};
|
---|
| 552 | % ProjData.VarDimName
|
---|
| 553 | % end
|
---|
| 554 | end
|
---|
| 555 |
|
---|
| 556 |
|
---|
| 557 |
|
---|
| 558 | %-----------------------------------------------------------------
|
---|
| 559 | %project on a line
|
---|
| 560 | % AJOUTER flux,circul,error
|
---|
| 561 | function [ProjData,errormsg] = proj_line(FieldData, ObjectData)
|
---|
| 562 | %-----------------------------------------------------------------
|
---|
[150] | 563 | [ProjData,errormsg]=proj_heading(FieldData,ObjectData);%transfer global attributes
|
---|
| 564 | if ~isempty(errormsg)
|
---|
| 565 | return
|
---|
| 566 | end
|
---|
[8] | 567 | ProjData.NbDim=1;
|
---|
| 568 | %initialisation of the input parameters and defaultoutput
|
---|
| 569 | ProjMode='projection';%direct projection on the line by default
|
---|
| 570 | if isfield(ObjectData,'ProjMode'),ProjMode=ObjectData.ProjMode; end;
|
---|
| 571 | ProjAngle=90; %90 degrees projection by default
|
---|
| 572 | if isfield(FieldData,'ProjAngle'),ProjAngle=ObjectData.ProjAngle; end;
|
---|
| 573 | width=0;%default width of the projection band
|
---|
| 574 | if isfield(ObjectData,'Range')&size(ObjectData.Range,2)>=2
|
---|
| 575 | width=abs(ObjectData.Range(1,2));
|
---|
| 576 | end
|
---|
| 577 | if isfield(ObjectData,'RangeY')
|
---|
| 578 | width=max(ObjectData.RangeY);
|
---|
| 579 | end
|
---|
| 580 |
|
---|
| 581 | % default output
|
---|
| 582 | errormsg=[];%default
|
---|
| 583 | Xline=[];
|
---|
| 584 | flux=0;
|
---|
| 585 | circul=0;
|
---|
| 586 | liny=ObjectData.Coord(:,2);
|
---|
| 587 | siz_line=size(ObjectData.Coord);
|
---|
| 588 | if siz_line(1)<2
|
---|
| 589 | return% line needs at least 2 points to be defined
|
---|
| 590 | end
|
---|
| 591 | testfalse=0;
|
---|
| 592 | ListIndex={};
|
---|
| 593 |
|
---|
| 594 | %angles of the polyline and boundaries of action
|
---|
| 595 | dlinx=diff(ObjectData.Coord(:,1));
|
---|
| 596 | dliny=diff(ObjectData.Coord(:,2));
|
---|
| 597 | theta=angle(dlinx+i*dliny);%angle of each segment
|
---|
| 598 | theta(siz_line(1))=theta(siz_line(1)-1);
|
---|
| 599 | % determine a rectangles at +-width from the line (only used for the ProjMode='projection or 'filter')
|
---|
| 600 | if isequal(ProjMode,'projection') || isequal(ProjMode,'filter')
|
---|
| 601 | xsup(1)=ObjectData.Coord(1,1)-width*sin(theta(1));
|
---|
| 602 | xinf(1)=ObjectData.Coord(1,1)+width*sin(theta(1));
|
---|
| 603 | ysup(1)=ObjectData.Coord(1,2)+width*cos(theta(1));
|
---|
| 604 | yinf(1)=ObjectData.Coord(1,2)-width*cos(theta(1));
|
---|
| 605 | for ip=2:siz_line(1)
|
---|
| 606 | xsup(ip)=ObjectData.Coord(ip,1)-width*sin((theta(ip)+theta(ip-1))/2)/cos((theta(ip-1)-theta(ip))/2);
|
---|
| 607 | xinf(ip)=ObjectData.Coord(ip,1)+width*sin((theta(ip)+theta(ip-1))/2)/cos((theta(ip-1)-theta(ip))/2);
|
---|
| 608 | ysup(ip)=ObjectData.Coord(ip,2)+width*cos((theta(ip)+theta(ip-1))/2)/cos((theta(ip-1)-theta(ip))/2);
|
---|
| 609 | yinf(ip)=ObjectData.Coord(ip,2)-width*cos((theta(ip)+theta(ip-1))/2)/cos((theta(ip-1)-theta(ip))/2);
|
---|
| 610 | end
|
---|
| 611 | end
|
---|
| 612 |
|
---|
| 613 | %group the variables (fields of 'FieldData') in cells of variables with the same dimensions
|
---|
| 614 | [CellVarIndex,NbDim,VarTypeCell,errormsg]=find_field_indices(FieldData);
|
---|
| 615 | if ~isempty(errormsg)
|
---|
| 616 | errormsg=['error in proj_field/proj_line:' errormsg];
|
---|
| 617 | return
|
---|
| 618 | end
|
---|
| 619 |
|
---|
| 620 | % loop on variable cells with the same space dimension
|
---|
| 621 | ProjData.ListVarName={};
|
---|
| 622 | ProjData.VarDimName={};
|
---|
| 623 | for icell=1:length(CellVarIndex)
|
---|
| 624 | VarIndex=CellVarIndex{icell};% indices of the selected variables in the list FieldData.ListVarName
|
---|
| 625 | VarType=VarTypeCell{icell}; %types of variables
|
---|
| 626 | if NbDim(icell)~=2% proj_line acts only on fields of space dimension 2, TODO: check 3D case
|
---|
| 627 | continue
|
---|
| 628 | end
|
---|
| 629 | testX=~isempty(VarType.coord_x) && ~isempty(VarType.coord_y);% test for unstructured coordinates
|
---|
| 630 | testU=~isempty(VarType.vector_x) && ~isempty(VarType.vector_y);% test for vectors
|
---|
| 631 | testfalse=~isempty(VarType.errorflag);% test for error flag
|
---|
| 632 | testproj(VarIndex)=zeros(size(VarIndex));% test =1 for simply projected variables, default =0
|
---|
| 633 | %=0 for vector components, treated separately
|
---|
| 634 | testproj(VarType.scalar)=1;
|
---|
| 635 | testproj(VarType.image)=1;
|
---|
| 636 | testproj(VarType.color)=1;
|
---|
| 637 | VarIndex=VarIndex(find(testproj(VarIndex)));%select only the projected variables
|
---|
| 638 | if testU
|
---|
| 639 | VarIndex=[VarIndex VarType.vector_x VarType.vector_y];%append u and v at the end of the list of variables
|
---|
| 640 | end
|
---|
| 641 | %identify vector components
|
---|
| 642 | if testU
|
---|
| 643 | UName=FieldData.ListVarName{VarType.vector_x};
|
---|
| 644 | VName=FieldData.ListVarName{VarType.vector_y};
|
---|
| 645 | eval(['vector_x=FieldData.' UName ';'])
|
---|
| 646 | eval(['vector_y=FieldData.' VName ';'])
|
---|
| 647 | end
|
---|
| 648 | %identify error flag
|
---|
| 649 | if testfalse
|
---|
| 650 | FFName=FieldData.ListVarName{VarType.errorflag};
|
---|
| 651 | eval(['errorflag=FieldData.' FFName ';'])
|
---|
| 652 | end
|
---|
| 653 | % check needed object properties for unstructured positions (position given by the variables with role coord_x, coord_y
|
---|
| 654 | if testX
|
---|
| 655 | if ~isequal(ProjMode,'interp')
|
---|
| 656 | if width==0
|
---|
| 657 | errormsg='range of the projection object is missing';
|
---|
| 658 | return
|
---|
| 659 | else
|
---|
| 660 | lambda=2/(width*width); %smoothing factor used for filter: weight exp(-2) at distance width from the line
|
---|
| 661 | end
|
---|
| 662 | end
|
---|
| 663 | if ~isequal(ProjMode,'projection')
|
---|
| 664 | if isfield(ObjectData,'DX')&~isempty(ObjectData.DX)
|
---|
| 665 | DX=abs(ObjectData.DX);%mesh of interpolation points along the line
|
---|
| 666 | else
|
---|
| 667 | errormsg='DX missing';
|
---|
| 668 | return
|
---|
| 669 | end
|
---|
| 670 | end
|
---|
| 671 | XName= FieldData.ListVarName{VarType.coord_x};
|
---|
| 672 | YName= FieldData.ListVarName{VarType.coord_y};
|
---|
| 673 | eval(['coord_x=FieldData.' XName ';'])
|
---|
| 674 | eval(['coord_y=FieldData.' YName ';'])
|
---|
| 675 | end
|
---|
| 676 | %initiate projection
|
---|
| 677 | for ivar=1:length(VarIndex)
|
---|
| 678 | ProjLine{ivar}=[];
|
---|
| 679 | end
|
---|
| 680 | XLine=[];
|
---|
| 681 | linelengthtot=0;
|
---|
| 682 |
|
---|
| 683 | % circul=0;
|
---|
| 684 | % flux=0;
|
---|
| 685 | %%%%%%% % A FAIRE CALCULER MEAN DES QUANTITES %%%%%%
|
---|
| 686 | %case of unstructured coordinates
|
---|
| 687 | if testX
|
---|
| 688 | for ip=1:siz_line(1)-1 %Loop on the segments of the polyline
|
---|
| 689 | linelength=sqrt(dlinx(ip)*dlinx(ip)+dliny(ip)*dliny(ip));
|
---|
| 690 | %select the vector indices in the range of action
|
---|
| 691 | if testfalse
|
---|
| 692 | flagsel=(errorflag==0); % keep only non false vectors
|
---|
| 693 | else
|
---|
| 694 | flagsel=ones(size(coord_x));
|
---|
| 695 | end
|
---|
| 696 | if isequal(ProjMode,'projection') | isequal(ProjMode,'filter')
|
---|
| 697 | flagsel=flagsel & ((coord_y -yinf(ip))*(xinf(ip+1)-xinf(ip))>(coord_x-xinf(ip))*(yinf(ip+1)-yinf(ip))) ...
|
---|
| 698 | & ((coord_y -ysup(ip))*(xsup(ip+1)-xsup(ip))<(coord_x-xsup(ip))*(ysup(ip+1)-ysup(ip))) ...
|
---|
| 699 | & ((coord_y -yinf(ip+1))*(xsup(ip+1)-xinf(ip+1))>(coord_x-xinf(ip+1))*(ysup(ip+1)-yinf(ip+1))) ...
|
---|
| 700 | & ((coord_y -yinf(ip))*(xsup(ip)-xinf(ip))<(coord_x-xinf(ip))*(ysup(ip)-yinf(ip)));
|
---|
| 701 | end
|
---|
| 702 | indsel=find(flagsel);%indsel =indices of good vectors
|
---|
| 703 | X_sel=coord_x(indsel);
|
---|
| 704 | Y_sel=coord_y(indsel);
|
---|
| 705 | nbvar=0;
|
---|
| 706 | for iselect=1:numel(VarIndex)-2*testU
|
---|
| 707 | VarName=FieldData.ListVarName{VarIndex(iselect)};
|
---|
| 708 | eval(['ProjVar{iselect}=FieldData.' VarName '(indsel);']);%scalar value
|
---|
| 709 | end
|
---|
| 710 | if testU
|
---|
| 711 | ProjVar{numel(VarIndex)-1}=cos(theta(ip))*vector_x(indsel)+sin(theta(ip))*vector_y(indsel);% longitudinal component
|
---|
| 712 | ProjVar{numel(VarIndex)}=-sin(theta(ip))*vector_x(indsel)+cos(theta(ip))*vector_y(indsel);%transverse component
|
---|
| 713 | end
|
---|
| 714 | if isequal(ProjMode,'projection')
|
---|
| 715 | sintheta=sin(theta(ip));
|
---|
| 716 | costheta=cos(theta(ip));
|
---|
| 717 | Xproj=(X_sel-ObjectData.Coord(ip,1))*costheta + (Y_sel-ObjectData.Coord(ip,2))*sintheta; %projection on the line
|
---|
| 718 | [Xproj,indsort]=sort(Xproj);
|
---|
| 719 | for ivar=1:numel(ProjVar)
|
---|
| 720 | if ~isempty(ProjVar{ivar})
|
---|
| 721 | ProjVar{ivar}=ProjVar{ivar}(indsort);
|
---|
| 722 | end
|
---|
| 723 | end
|
---|
| 724 | elseif isequal(ProjMode,'interp') %linear interpolation:
|
---|
| 725 | npoint=floor(linelength/DX)+1;% nbre of points in the profile (interval DX)
|
---|
| 726 | Xproj=[linelength/(2*npoint):linelength/npoint:linelength-linelength/(2*npoint)];
|
---|
| 727 | xreg=cos(theta(ip))*Xproj+ObjectData.Coord(ip,1);
|
---|
| 728 | yreg=sin(theta(ip))*Xproj+ObjectData.Coord(ip,2);
|
---|
| 729 | for ivar=1:numel(ProjVar)
|
---|
| 730 | if ~isempty(ProjVar{ivar})
|
---|
| 731 | ProjVar{ivar}=griddata_uvmat(X_sel,Y_sel,ProjVar{ivar},xreg,yreg);
|
---|
| 732 | end
|
---|
| 733 | end
|
---|
| 734 | elseif isequal(ProjMode,'filter') %filtering
|
---|
| 735 | npoint=floor(linelength/DX)+1;% nbre of points in the profile (interval DX)
|
---|
| 736 | Xproj=[linelength/(2*npoint):linelength/npoint:linelength-linelength/(2*npoint)];
|
---|
| 737 | siz=size(X_sel);
|
---|
| 738 | xregij=cos(theta(ip))*Xproj'*ones(1,siz(2))+ObjectData.Coord(ip,1);
|
---|
| 739 | yregij=sin(theta(ip))*Xproj'*ones(1,siz(2))+ObjectData.Coord(ip,2);
|
---|
| 740 | xij=ones(npoint,1)*X_sel;
|
---|
| 741 | yij=ones(npoint,1)*Y_sel;
|
---|
| 742 | Aij=exp(-lambda*((xij-xregij).*(xij-xregij)+(yij-yregij).*(yij-yregij)));
|
---|
| 743 | norm=ones(1,siz(2))*Aij';
|
---|
| 744 | for ivar=1:numel(ProjVar)
|
---|
| 745 | if ~isempty(ProjVar{ivar})
|
---|
| 746 | ProjVar{ivar}=ProjVar{ivar}*Aij'./norm;
|
---|
| 747 | end
|
---|
| 748 | end
|
---|
| 749 | end
|
---|
| 750 | %prolongate the total record
|
---|
| 751 | for ivar=1:numel(ProjVar)
|
---|
| 752 | if ~isempty(ProjVar{ivar})
|
---|
| 753 | ProjLine{ivar}=[ProjLine{ivar}; ProjVar{ivar}];
|
---|
| 754 | end
|
---|
| 755 | end
|
---|
| 756 | XLine=[XLine ;(Xproj+linelengthtot)];%along line abscissa
|
---|
| 757 | linelengthtot=linelengthtot+linelength;
|
---|
| 758 | % circul=circul+(sum(U_sel))*linelength/npoint;
|
---|
| 759 | % flux=flux+(sum(V_sel))*linelength/npoint;
|
---|
| 760 | end
|
---|
| 761 | ProjData.X=XLine';
|
---|
| 762 | cur_index=1;
|
---|
| 763 | ProjData.ListVarName=[ProjData.ListVarName {XName}];
|
---|
| 764 | ProjData.VarDimName=[ProjData.VarDimName {XName}];
|
---|
| 765 | ProjData.VarAttribute{1}.long_name='abscissa along line';
|
---|
| 766 | for iselect=1:numel(VarIndex)
|
---|
| 767 | VarName=FieldData.ListVarName{VarIndex(iselect)};
|
---|
| 768 | eval(['ProjData.' VarName '=ProjLine{iselect};'])
|
---|
| 769 | ProjData.ListVarName=[ProjData.ListVarName {VarName}];
|
---|
| 770 | ProjData.VarDimName=[ProjData.VarDimName {XName}];
|
---|
| 771 | ProjData.VarAttribute{iselect}=FieldData.VarAttribute{VarIndex(iselect)};
|
---|
[71] | 772 | if strcmp(ProjMode,'projection')
|
---|
| 773 | ProjData.VarAttribute{iselect}.Role='discrete';
|
---|
| 774 | else
|
---|
| 775 | ProjData.VarAttribute{iselect}.Role='continuous';
|
---|
| 776 | end
|
---|
[8] | 777 | end
|
---|
| 778 |
|
---|
| 779 | %case of structured coordinates
|
---|
| 780 | elseif numel(VarType.coord)>=2 & VarType.coord(1:2) > 0;
|
---|
| 781 | if ~isequal(ObjectData.Style,'line')% exclude polyline
|
---|
| 782 | errormsg=['no projection available on ' ObjectData.Style 'for structured coordinates']; %
|
---|
| 783 | else
|
---|
| 784 | test_Amat=1;%image or 2D matrix
|
---|
| 785 | test_interp2=0;%default
|
---|
| 786 | % if ~isempty(VarType.coord_y)
|
---|
| 787 | AYName=FieldData.ListVarName{VarType.coord(1)};
|
---|
| 788 | AXName=FieldData.ListVarName{VarType.coord(2)};
|
---|
| 789 | eval(['AX=FieldData.' AXName ';']);% set of x positions
|
---|
| 790 | eval(['AY=FieldData.' AYName ';']);% set of y positions
|
---|
| 791 | AName=FieldData.ListVarName{VarIndex(1)};
|
---|
| 792 | eval(['A=FieldData.' AName ';']);% scalar
|
---|
| 793 | npxy=size(A);
|
---|
| 794 | npx=npxy(2);
|
---|
| 795 | npy=npxy(1);
|
---|
| 796 | if numel(AX)==2
|
---|
| 797 | DX=(AX(2)-AX(1))/(npx-1);
|
---|
| 798 | else
|
---|
| 799 | DX_vec=diff(AX);
|
---|
| 800 | DX=max(DX_vec);
|
---|
| 801 | DX_min=min(DX_vec);
|
---|
| 802 | if (DX-DX_min)>0.0001*abs(DX)
|
---|
| 803 | test_interp2=1;
|
---|
| 804 | DX=DX_min;
|
---|
| 805 | end
|
---|
| 806 | end
|
---|
| 807 | if numel(AY)==2
|
---|
| 808 | DY=(AY(2)-AY(1))/(npy-1);
|
---|
| 809 | else
|
---|
| 810 | DY_vec=diff(AY);
|
---|
| 811 | DY=max(DY_vec);
|
---|
| 812 | DY_min=min(DY_vec);
|
---|
| 813 | if (DY-DY_min)>0.0001*abs(DY)
|
---|
| 814 | test_interp2=1;
|
---|
| 815 | DY=DY_min;
|
---|
| 816 | end
|
---|
| 817 | end
|
---|
| 818 | AXI=linspace(AX(1),AX(end), npx);%set of x positions for the interpolated input data
|
---|
| 819 | AYI=linspace(AY(1),AY(end), npy);%set of x positions for the interpolated input data
|
---|
| 820 | if isfield(ObjectData,'DX')
|
---|
| 821 | DXY_line=ObjectData.DX;%mesh on the projection line
|
---|
| 822 | else
|
---|
| 823 | DXY_line=sqrt(abs(DX*DY));% mesh on the projection line
|
---|
| 824 | end
|
---|
| 825 | dlinx=ObjectData.Coord(2,1)-ObjectData.Coord(1,1);
|
---|
| 826 | dliny=ObjectData.Coord(2,2)-ObjectData.Coord(1,2);
|
---|
| 827 | linelength=sqrt(dlinx*dlinx+dliny*dliny);
|
---|
| 828 | theta=angle(dlinx+i*dliny);%angle of the line
|
---|
| 829 | if isfield(FieldData,'RangeX')
|
---|
| 830 | XMin=min(FieldData.RangeX);%shift of the origin on the line
|
---|
| 831 | else
|
---|
| 832 | XMin=0;
|
---|
| 833 | end
|
---|
| 834 | eval(['ProjData.' AXName '=linspace(XMin,XMin+linelength,linelength/DXY_line+1);'])%abscissa of the new pixels along the line
|
---|
| 835 | y=linspace(-width,width,2*width/DXY_line+1);%ordintes of the new pixels (coordinate across the line)
|
---|
| 836 | eval(['npX=length(ProjData.' AXName ');'])
|
---|
| 837 | npY=length(y); %TODO: utiliser proj_grid
|
---|
| 838 | eval(['[X,Y]=meshgrid(ProjData.' AXName ',y);'])%grid in the line coordinates
|
---|
| 839 | XIMA=ObjectData.Coord(1,1)+(X-XMin)*cos(theta)-Y*sin(theta);
|
---|
| 840 | YIMA=ObjectData.Coord(1,2)+(X-XMin)*sin(theta)+Y*cos(theta);
|
---|
| 841 | XIMA=(XIMA-AX(1))/DX+1;% index of the original image along x
|
---|
| 842 | YIMA=(YIMA-AY(1))/DY+1;% index of the original image along y
|
---|
| 843 | XIMA=reshape(round(XIMA),1,npX*npY);%indices reorganized in 'line'
|
---|
| 844 | YIMA=reshape(round(YIMA),1,npX*npY);
|
---|
| 845 | flagin=XIMA>=1 & XIMA<=npx & YIMA >=1 & YIMA<=npy;%flagin=1 inside the original image
|
---|
| 846 | ind_in=find(flagin);
|
---|
| 847 | ind_out=find(~flagin);
|
---|
| 848 | ICOMB=(XIMA-1)*npy+YIMA;
|
---|
| 849 | ICOMB=ICOMB(flagin);%index corresponding to XIMA and YIMA in the aligned original image vec_A
|
---|
| 850 | nbcolor=1; %color images
|
---|
| 851 | if numel(npxy)==2
|
---|
| 852 | nbcolor=1;
|
---|
| 853 | elseif length(npxy)==3
|
---|
| 854 | nbcolor=npxy(3);
|
---|
| 855 | else
|
---|
| 856 | errormsg='multicomponent field not projected';
|
---|
| 857 | display(errormsg)
|
---|
| 858 | return
|
---|
| 859 | end
|
---|
| 860 | nbvar=length(ProjData.ListVarName);% number of var from previous cells
|
---|
| 861 | ProjData.ListVarName=[ProjData.ListVarName {AXName}];
|
---|
| 862 | ProjData.VarDimName=[ProjData.VarDimName {AXName}];
|
---|
| 863 | for ivar=VarIndex
|
---|
| 864 | VarName{ivar}=FieldData.ListVarName{ivar};
|
---|
| 865 | if test_interp2% interpolate on new grid
|
---|
| 866 | eval(['FieldData.' VarName{ivar} '=interp2(FieldData.' AXName ',FieldData.' AYName ',FieldData.' VarName{ivar} ',AXI,AYI'');']) %TO TEST
|
---|
| 867 | end
|
---|
| 868 | eval(['vec_A=reshape(squeeze(FieldData.' VarName{ivar} '),npx*npy,nbcolor);']) %put the original image in colum
|
---|
| 869 | if nbcolor==1
|
---|
| 870 | vec_B(ind_in)=vec_A(ICOMB);
|
---|
| 871 | vec_B(ind_out)=zeros(size(ind_out));
|
---|
| 872 | A_out=reshape(vec_B,npY,npX);
|
---|
| 873 | eval(['ProjData.' VarName{ivar} '=((sum(A_out,1)/npY))'';']);
|
---|
| 874 | elseif nbcolor==3
|
---|
| 875 | vec_B(ind_in,[1:3])=vec_A(ICOMB,:);
|
---|
| 876 | vec_B(ind_out,1)=zeros(size(ind_out));
|
---|
| 877 | vec_B(ind_out,2)=zeros(size(ind_out));
|
---|
| 878 | vec_B(ind_out,3)=zeros(size(ind_out));
|
---|
| 879 | A_out=reshape(vec_B,npY,npX,nbcolor);
|
---|
| 880 | eval(['ProjData.' VarName{ivar} '=squeeze(sum(A_out,1)/npY);']);
|
---|
| 881 | end
|
---|
| 882 | ProjData.ListVarName=[ProjData.ListVarName VarName{ivar} ];
|
---|
| 883 | ProjData.VarDimName=[ProjData.VarDimName {AXName}];%to generalize with the initial name of the x coordinate
|
---|
[71] | 884 | ProjData.VarAttribute{ivar}.Role='continuous';% for plot with continuous line
|
---|
[8] | 885 | end
|
---|
| 886 | if testU
|
---|
| 887 | eval(['vector_x =ProjData.' VarName{VarType.vector_x} ';'])
|
---|
| 888 | eval(['vector_y =ProjData.' VarName{VarType.vector_y} ';'])
|
---|
| 889 | eval(['ProjData.' VarName{VarType.vector_x} '=cos(theta)*vector_x+sin(theta)*vector_y;'])
|
---|
| 890 | eval(['ProjData.' VarName{VarType.vector_y} '=-sin(theta)*vector_x+cos(theta)*vector_y;'])
|
---|
| 891 | end
|
---|
| 892 | ProjData.VarAttribute{nbvar+1}.long_name='abscissa along line';
|
---|
| 893 | if nbcolor==3
|
---|
[46] | 894 | ProjData.VarDimName{end}={AXName,'rgb'};
|
---|
[8] | 895 | end
|
---|
| 896 | end
|
---|
| 897 | end
|
---|
| 898 | end
|
---|
| 899 |
|
---|
| 900 | % %shotarter case for horizontal or vertical line (A FAIRE
|
---|
| 901 | % % Rangx=[0.5 npx-0.5];%image coordiantes of corners
|
---|
| 902 | % % Rangy=[npy-0.5 0.5];
|
---|
| 903 | % % if isfield(Calib,'Pxcmx')&isfield(Calib,'Pxcmy')%old calib
|
---|
| 904 | % % Rangx=Rangx/Calib.Pxcmx;
|
---|
| 905 | % % Rangy=Rangy/Calib.Pxcmy;
|
---|
| 906 | % % else
|
---|
| 907 | % % [Rangx]=phys_XYZ(Calib,Rangx,[0.5 0.5],[0 0]);%case of translations without rotation and quadratic deformation
|
---|
| 908 | % % [xx,Rangy]=phys_XYZ(Calib,[0.5 0.5],Rangy,[0 0]);
|
---|
| 909 | % % end
|
---|
| 910 | %
|
---|
| 911 | % % test_scal=0;%default% 3- 'UserData':(get(handles.Tag,'UserData')
|
---|
| 912 |
|
---|
| 913 |
|
---|
| 914 | %-----------------------------------------------------------------
|
---|
| 915 | %project on a plane
|
---|
| 916 | % AJOUTER flux,circul,error
|
---|
| 917 | function [ProjData,errormsg] = proj_plane(FieldData, ObjectData)
|
---|
| 918 | %-----------------------------------------------------------------
|
---|
| 919 |
|
---|
[174] | 920 | %% initialisation of the input parameters of the projection plane
|
---|
[8] | 921 | ProjMode='projection';%direct projection by default
|
---|
| 922 | if isfield(ObjectData,'ProjMode'),ProjMode=ObjectData.ProjMode; end;
|
---|
| 923 |
|
---|
| 924 | %axis origin
|
---|
| 925 | if isempty(ObjectData.Coord)
|
---|
| 926 | ObjectData.Coord(1,1)=0;%origin of the plane set to [0 0] by default
|
---|
| 927 | ObjectData.Coord(1,2)=0;
|
---|
| 928 | ObjectData.Coord(1,3)=0;
|
---|
| 929 | end
|
---|
| 930 |
|
---|
| 931 | %rotation angles
|
---|
| 932 | Phi=0;%default
|
---|
| 933 | Theta=0;
|
---|
| 934 | Psi=0;
|
---|
| 935 | if isfield(ObjectData,'Phi')&& ~isempty(ObjectData.Phi)
|
---|
| 936 | Phi=(pi/180)*ObjectData.Phi;%first Euler angle in radian
|
---|
| 937 | end
|
---|
| 938 | if isfield(ObjectData,'Theta')&& ~isempty(ObjectData.Theta)
|
---|
| 939 | Theta=(pi/180)*ObjectData.Theta;%second Euler angle in radian
|
---|
| 940 | end
|
---|
| 941 | if isfield(ObjectData,'Psi')&& ~isempty(ObjectData.Psi)
|
---|
| 942 | Psi=(pi/180)*ObjectData.Psi;%third Euler angle in radian
|
---|
| 943 | end
|
---|
| 944 |
|
---|
| 945 | %components of the unity vector normal to the projection plane
|
---|
| 946 | NormVec_X=-sin(Phi)*sin(Theta);
|
---|
| 947 | NormVec_Y=cos(Phi)*sin(Theta);
|
---|
| 948 | NormVec_Z=cos(Theta);
|
---|
| 949 |
|
---|
| 950 | %mesh sizes DX and DY
|
---|
| 951 | DX=0;
|
---|
| 952 | DY=0; %default
|
---|
| 953 | if isfield(ObjectData,'DX')&~isempty(ObjectData.DX)
|
---|
| 954 | DX=abs(ObjectData.DX);%mesh of interpolation points
|
---|
| 955 | end
|
---|
| 956 | if isfield(ObjectData,'DY')&~isempty(ObjectData.DY)
|
---|
| 957 | DY=abs(ObjectData.DY);%mesh of interpolation points
|
---|
| 958 | end
|
---|
[109] | 959 | if ~strcmp(ProjMode,'projection') && (DX==0||DY==0)
|
---|
[8] | 960 | errormsg='DX or DY missing';
|
---|
| 961 | display(errormsg)
|
---|
| 962 | return
|
---|
| 963 | end
|
---|
| 964 |
|
---|
| 965 | %extrema along each axis
|
---|
| 966 | testXMin=0;
|
---|
| 967 | testXMax=0;
|
---|
| 968 | testYMin=0;
|
---|
| 969 | testYMax=0;
|
---|
| 970 | if isfield(ObjectData,'RangeX')
|
---|
| 971 | XMin=min(ObjectData.RangeX);
|
---|
| 972 | XMax=max(ObjectData.RangeX);
|
---|
| 973 | testXMin=XMax>XMin;
|
---|
| 974 | testXMax=1;
|
---|
| 975 | end
|
---|
| 976 | if isfield(ObjectData,'RangeY')
|
---|
| 977 | YMin=min(ObjectData.RangeY);
|
---|
| 978 | YMax=max(ObjectData.RangeY);
|
---|
| 979 | testYMin=YMax>YMin;
|
---|
| 980 | testYMax=1;
|
---|
| 981 | end
|
---|
| 982 | width=0;%default width of the projection band
|
---|
| 983 | if isfield(ObjectData,'RangeZ')
|
---|
| 984 | width=max(ObjectData.RangeZ);
|
---|
| 985 | end
|
---|
| 986 |
|
---|
| 987 | % initiate Matlab structure for physical field
|
---|
[150] | 988 | [ProjData,errormsg]=proj_heading(FieldData,ObjectData);
|
---|
[8] | 989 | ProjData.NbDim=2;
|
---|
| 990 | ProjData.ListVarName={};
|
---|
| 991 | ProjData.VarDimName={};
|
---|
[173] | 992 | if ~isequal(DX,0)&& ~isequal(DY,0)
|
---|
| 993 | ProjData.Mesh=sqrt(DX*DY);%define typical data mesh, useful for mouse selection in plots
|
---|
| 994 | elseif isfield(FieldData,'Mesh')
|
---|
| 995 | ProjData.Mesh=FieldData.Mesh;
|
---|
| 996 | end
|
---|
[8] | 997 |
|
---|
| 998 | error=0;%default
|
---|
| 999 | flux=0;
|
---|
| 1000 | testfalse=0;
|
---|
| 1001 | ListIndex={};
|
---|
| 1002 |
|
---|
| 1003 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
---|
[158] | 1004 | %% group the variables (fields of 'FieldData') in cells of variables with the same dimensions
|
---|
[8] | 1005 | %-----------------------------------------------------------------
|
---|
| 1006 | idimvar=0;
|
---|
| 1007 | [CellVarIndex,NbDim,VarTypeCell,errormsg]=find_field_indices(FieldData);
|
---|
| 1008 | if ~isempty(errormsg)
|
---|
| 1009 | errormsg=['error in proj_field/proj_plane:' errormsg];
|
---|
| 1010 | return
|
---|
| 1011 | end
|
---|
[158] | 1012 |
|
---|
| 1013 | % LOOP ON GROUPS OF VARIABLES SHARING THE SAME DIMENSIONS
|
---|
[8] | 1014 | % CellVarIndex=cells of variable index arrays
|
---|
| 1015 | ivar_new=0; % index of the current variable in the projected field
|
---|
| 1016 | icoord=0;
|
---|
| 1017 | nbcoord=0;%number of added coordinate variables brought by projection
|
---|
| 1018 | for icell=1:length(CellVarIndex)
|
---|
| 1019 | if NbDim(icell)<2
|
---|
| 1020 | continue
|
---|
| 1021 | end
|
---|
| 1022 | VarIndex=CellVarIndex{icell};% indices of the selected variables in the list FieldData.ListVarName
|
---|
| 1023 | VarType=VarTypeCell{icell};
|
---|
| 1024 | ivar_X=VarType.coord_x;
|
---|
| 1025 | ivar_Y=VarType.coord_y;
|
---|
| 1026 | ivar_Z=VarType.coord_z;
|
---|
| 1027 | ivar_U=VarType.vector_x;
|
---|
| 1028 | ivar_V=VarType.vector_y;
|
---|
| 1029 | ivar_W=VarType.vector_z;
|
---|
| 1030 | ivar_C=VarType.scalar ;
|
---|
| 1031 | ivar_Anc=VarType.ancillary;
|
---|
| 1032 | test_anc=zeros(size(VarIndex));
|
---|
| 1033 | test_anc(ivar_Anc)=ones(size(ivar_Anc));
|
---|
| 1034 | ivar_F=VarType.warnflag;
|
---|
| 1035 | ivar_FF=VarType.errorflag;
|
---|
| 1036 | testX=~isempty(ivar_X) && ~isempty(ivar_Y);
|
---|
| 1037 | DimCell=FieldData.VarDimName{VarIndex(1)};
|
---|
| 1038 | if ischar(DimCell)
|
---|
| 1039 | DimCell={DimCell};%name of dimensions
|
---|
| 1040 | end
|
---|
[109] | 1041 |
|
---|
[158] | 1042 | %% case of input fields with unstructured coordinates
|
---|
[8] | 1043 | if testX
|
---|
[77] | 1044 | XName=FieldData.ListVarName{ivar_X};
|
---|
| 1045 | YName=FieldData.ListVarName{ivar_Y};
|
---|
[8] | 1046 | eval(['coord_x=FieldData.' XName ';'])
|
---|
| 1047 | eval(['coord_y=FieldData.' YName ';'])
|
---|
| 1048 | if length(ivar_Z)==1
|
---|
[77] | 1049 | ZName=FieldData.ListVarName{ivar_Z};
|
---|
[8] | 1050 | eval(['coord_z=FieldData.' ZName ';'])
|
---|
| 1051 | end
|
---|
| 1052 |
|
---|
| 1053 | % translate initial coordinates
|
---|
| 1054 | coord_x=coord_x-ObjectData.Coord(1,1);
|
---|
| 1055 | coord_y=coord_y-ObjectData.Coord(1,2);
|
---|
| 1056 | if ~isempty(ivar_Z)
|
---|
| 1057 | coord_z=coord_z-ObjectData.Coord(1,3);
|
---|
| 1058 | end
|
---|
| 1059 |
|
---|
| 1060 | % selection of the vectors in the projection range (3D case)
|
---|
| 1061 | if length(ivar_Z)==1 && width > 0
|
---|
| 1062 | %components of the unitiy vector normal to the projection plane
|
---|
| 1063 | fieldZ=NormVec_X*coord_x + NormVec_Y*coord_y+ NormVec_Z*coord_z;% distance to the plane
|
---|
| 1064 | indcut=find(abs(fieldZ) <= width);
|
---|
| 1065 | for ivar=VarIndex
|
---|
[158] | 1066 | VarName=FieldData.ListVarName{ivar};
|
---|
| 1067 | eval(['FieldData.' VarName '=FieldData.' VarName '(indcut);'])
|
---|
[8] | 1068 | % A VOIR : CAS DE VAR STRUCTUREE MAIS PAS GRILLE REGULIERE : INTERPOLER SUR GRILLE REGULIERE
|
---|
| 1069 | end
|
---|
| 1070 | coord_x=coord_x(indcut);
|
---|
| 1071 | coord_y=coord_y(indcut);
|
---|
| 1072 | coord_z=coord_z(indcut);
|
---|
| 1073 | end
|
---|
| 1074 |
|
---|
| 1075 | %rotate coordinates if needed
|
---|
| 1076 | if isequal(Phi,0)
|
---|
| 1077 | coord_X=coord_x;
|
---|
| 1078 | coord_Y=coord_y;
|
---|
| 1079 | if ~isequal(Theta,0)
|
---|
| 1080 | coord_Y=coord_Y *cos(Theta);
|
---|
| 1081 | end
|
---|
| 1082 | else
|
---|
| 1083 | coord_X=(coord_x *cos(Phi) + coord_y* sin(Phi));
|
---|
| 1084 | coord_Y=(-coord_x *sin(Phi) + coord_y *cos(Phi))*cos(Theta);
|
---|
| 1085 | end
|
---|
| 1086 | if ~isempty(ivar_Z)
|
---|
| 1087 | coord_Y=coord_Y+coord_z *sin(Theta);
|
---|
| 1088 | end
|
---|
| 1089 | if ~isequal(Psi,0)
|
---|
| 1090 | coord_X=(coord_X *cos(Psi) - coord_Y* sin(Psi));%A VERIFIER
|
---|
| 1091 | coord_Y=(coord_X *sin(Psi) + coord_Y* cos(Psi));
|
---|
| 1092 | end
|
---|
| 1093 |
|
---|
| 1094 | %restriction to the range of x and y if imposed
|
---|
| 1095 | testin=ones(size(coord_X)); %default
|
---|
| 1096 | testbound=0;
|
---|
| 1097 | if testXMin
|
---|
| 1098 | testin=testin & (coord_X >= XMin);
|
---|
| 1099 | testbound=1;
|
---|
| 1100 | end
|
---|
| 1101 | if testXMax
|
---|
| 1102 | testin=testin & (coord_X <= XMax);
|
---|
| 1103 | testbound=1;
|
---|
| 1104 | end
|
---|
| 1105 | if testYMin
|
---|
| 1106 | testin=testin & (coord_Y >= YMin);
|
---|
| 1107 | testbound=1;
|
---|
| 1108 | end
|
---|
| 1109 | if testYMin
|
---|
| 1110 | testin=testin & (coord_Y <= YMax);
|
---|
| 1111 | testbound=1;
|
---|
| 1112 | end
|
---|
| 1113 | if testbound
|
---|
| 1114 | indcut=find(testin);
|
---|
| 1115 | for ivar=VarIndex
|
---|
| 1116 | VarName=FieldData.ListVarName{ivar};
|
---|
| 1117 | eval(['FieldData.' VarName '=FieldData.' VarName '(indcut);'])
|
---|
| 1118 | end
|
---|
| 1119 | coord_X=coord_X(indcut);
|
---|
| 1120 | coord_Y=coord_Y(indcut);
|
---|
| 1121 | if length(ivar_Z)==1
|
---|
| 1122 | coord_Z=coord_Z(indcut);
|
---|
| 1123 | end
|
---|
| 1124 | end
|
---|
| 1125 | % different cases of projection
|
---|
| 1126 | if isequal(ObjectData.ProjMode,'projection')
|
---|
[42] | 1127 | %the list of dimension
|
---|
[109] | 1128 | %ProjData.ListDimName=[ProjData.ListDimName FieldData.VarDimName(VarIndex(1))];%add the point index to the list of dimensions
|
---|
| 1129 | %ProjData.DimValue=[ProjData.
|
---|
| 1130 | %length(coord_X)];
|
---|
[8] | 1131 | nbvar=0;
|
---|
| 1132 | for ivar=VarIndex %transfer variables to the projection plane
|
---|
| 1133 | VarName=FieldData.ListVarName{ivar};
|
---|
| 1134 | if ivar==ivar_X %x coordinate
|
---|
| 1135 | eval(['ProjData.' VarName '=coord_X;'])
|
---|
| 1136 | elseif ivar==ivar_Y % y coordinate
|
---|
| 1137 | eval(['ProjData.' VarName '=coord_Y;'])
|
---|
| 1138 | elseif isempty(ivar_Z) || ivar~=ivar_Z % other variables (except Z coordinate wyhich is not reproduced)
|
---|
| 1139 | eval(['ProjData.' VarName '=FieldData.' VarName ';'])
|
---|
| 1140 | end
|
---|
| 1141 | if isempty(ivar_Z) || ivar~=ivar_Z
|
---|
| 1142 | ProjData.ListVarName=[ProjData.ListVarName VarName];
|
---|
[42] | 1143 | ProjData.VarDimName=[ProjData.VarDimName DimCell];
|
---|
[8] | 1144 | nbvar=nbvar+1;
|
---|
| 1145 | if isfield(FieldData,'VarAttribute') & length(FieldData.VarAttribute) >=ivar
|
---|
| 1146 | ProjData.VarAttribute{nbvar}=FieldData.VarAttribute{ivar};
|
---|
| 1147 | end
|
---|
| 1148 | end
|
---|
| 1149 | end
|
---|
| 1150 | elseif isequal(ObjectData.ProjMode,'interp')||isequal(ObjectData.ProjMode,'filter')%interpolate data on a regular grid
|
---|
| 1151 | coord_x_proj=[XMin:DX:XMax];
|
---|
| 1152 | coord_y_proj=[YMin:DY:YMax];
|
---|
| 1153 | DimCell={'coord_y','coord_x'};
|
---|
| 1154 | ProjData.ListVarName={'coord_y','coord_x'};
|
---|
| 1155 | ProjData.VarDimName={'coord_y','coord_x'};
|
---|
[77] | 1156 | nbcoord=2;
|
---|
[8] | 1157 | ProjData.coord_y=[YMin YMax];
|
---|
| 1158 | ProjData.coord_x=[XMin XMax];
|
---|
| 1159 | if isempty(ivar_X), ivar_X=0; end;
|
---|
| 1160 | if isempty(ivar_Y), ivar_Y=0; end;
|
---|
| 1161 | if isempty(ivar_Z), ivar_Z=0; end;
|
---|
| 1162 | if isempty(ivar_U), ivar_U=0; end;
|
---|
| 1163 | if isempty(ivar_V), ivar_V=0; end;
|
---|
| 1164 | if isempty(ivar_W), ivar_W=0; end;
|
---|
| 1165 | if isempty(ivar_F), ivar_F=0; end;
|
---|
| 1166 | if isempty(ivar_FF), ivar_FF=0; end;
|
---|
| 1167 | if ~isequal(ivar_FF,0)
|
---|
| 1168 | VarName_FF=FieldData.ListVarName{ivar_FF};
|
---|
| 1169 | eval(['indsel=find(FieldData.' VarName_FF '==0);'])
|
---|
| 1170 | coord_X=coord_X(indsel);
|
---|
| 1171 | coord_Y=coord_Y(indsel);
|
---|
| 1172 | end
|
---|
| 1173 | FF=zeros(1,length(coord_y_proj)*length(coord_x_proj));
|
---|
| 1174 | testFF=0;
|
---|
| 1175 | for ivar=VarIndex
|
---|
[109] | 1176 | VarName=FieldData.ListVarName{ivar};
|
---|
[46] | 1177 | if ~( ivar==ivar_X || ivar==ivar_Y || ivar==ivar_Z || ivar==ivar_F || ivar==ivar_FF || test_anc(ivar)==1)
|
---|
[8] | 1178 | ivar_new=ivar_new+1;
|
---|
| 1179 | ProjData.ListVarName=[ProjData.ListVarName {VarName}];
|
---|
| 1180 | ProjData.VarDimName=[ProjData.VarDimName {DimCell}];
|
---|
[46] | 1181 | if isfield(FieldData,'VarAttribute') && length(FieldData.VarAttribute) >=ivar
|
---|
[8] | 1182 | ProjData.VarAttribute{ivar_new+nbcoord}=FieldData.VarAttribute{ivar};
|
---|
| 1183 | end
|
---|
| 1184 | if ~isequal(ivar_FF,0)
|
---|
| 1185 | eval(['FieldData.' VarName '=FieldData.' VarName '(indsel);'])
|
---|
| 1186 | end
|
---|
[46] | 1187 | eval(['ProjData.' VarName '=griddata_uvmat(double(coord_X),double(coord_Y),double(FieldData.' VarName '),coord_x_proj,coord_y_proj'');'])
|
---|
[8] | 1188 | eval(['varline=reshape(ProjData.' VarName ',1,length(coord_y_proj)*length(coord_x_proj));'])
|
---|
| 1189 | FFlag= isnan(varline); %detect undefined values NaN
|
---|
| 1190 | indnan=find(FFlag);
|
---|
| 1191 | if~isempty(indnan)
|
---|
| 1192 | varline(indnan)=zeros(size(indnan));
|
---|
| 1193 | eval(['ProjData.' VarName '=reshape(varline,length(coord_y_proj),length(coord_x_proj));'])
|
---|
| 1194 | FF(indnan)=ones(size(indnan));
|
---|
| 1195 | testFF=1;
|
---|
| 1196 | end
|
---|
| 1197 | if ivar==ivar_U
|
---|
| 1198 | ivar_U=ivar_new;
|
---|
| 1199 | end
|
---|
| 1200 | if ivar==ivar_V
|
---|
| 1201 | ivar_V=ivar_new;
|
---|
| 1202 | end
|
---|
| 1203 | if ivar==ivar_W
|
---|
| 1204 | ivar_W=ivar_new;
|
---|
| 1205 | end
|
---|
| 1206 | end
|
---|
| 1207 | end
|
---|
| 1208 | if testFF
|
---|
| 1209 | ProjData.FF=reshape(FF,length(coord_y_proj),length(coord_x_proj));
|
---|
| 1210 | ProjData.ListVarName=[ProjData.ListVarName {'FF'}];
|
---|
| 1211 | ProjData.VarDimName=[ProjData.VarDimName {DimCell}];
|
---|
| 1212 | ProjData.VarAttribute{ivar_new+1+nbcoord}.Role='errorflag';
|
---|
| 1213 | end
|
---|
| 1214 | end
|
---|
[158] | 1215 |
|
---|
| 1216 | %% case of input fields defined on a structured grid
|
---|
[8] | 1217 | else
|
---|
[109] | 1218 | AYName=FieldData.ListVarName{VarType.coord(1)};%name of input x coordinate (name preserved on projection)
|
---|
| 1219 | AXName=FieldData.ListVarName{VarType.coord(2)};%name of input y coordinate (name preserved on projection)
|
---|
[8] | 1220 | eval(['AX=FieldData.' AXName ';'])
|
---|
| 1221 | eval(['AY=FieldData.' AYName ';'])
|
---|
[109] | 1222 | VarName=FieldData.ListVarName{VarIndex(1)};%get the first variable of the cell to get the input matrix dimensions
|
---|
| 1223 | eval(['DimValue=size(FieldData.' VarName ');'])%input matrix dimensions
|
---|
[42] | 1224 | ListDimName=FieldData.VarDimName{VarIndex(1)};
|
---|
[8] | 1225 | ProjData.ListVarName=[{AYName} {AXName} ProjData.ListVarName]; %TODO: check if it already exists in Projdata (several cells)
|
---|
| 1226 | ProjData.VarDimName=[{AYName} {AXName} ProjData.VarDimName];
|
---|
| 1227 | nbcolor=1; %default
|
---|
| 1228 | for idim=1:length(ListDimName)
|
---|
| 1229 | DimName=ListDimName{idim};
|
---|
[109] | 1230 | if strcmp(DimName,'rgb')||strcmp(DimName,'nb_coord')||strcmp(DimName,'nb_coord_i')
|
---|
[8] | 1231 | nbcolor=DimValue(idim);
|
---|
| 1232 | DimValue(idim)=[];
|
---|
| 1233 | end
|
---|
| 1234 | if isequal(DimName,'nb_coord_j')% NOTE: CASE OF TENSOR NOT TREATED
|
---|
| 1235 | DimValue(idim)=[];
|
---|
| 1236 | end
|
---|
| 1237 | end
|
---|
| 1238 | ind_1=find(DimValue==1);
|
---|
| 1239 | Coord_z=[];
|
---|
| 1240 | Coord_y=[];
|
---|
| 1241 | Coord_x=[];
|
---|
[174] | 1242 | nb_dim=numel(DimValue);
|
---|
[8] | 1243 | for idim=1:nb_dim %loop on space dimensions
|
---|
| 1244 | test_interp(idim)=0;%test for coordiate interpolation (non regular grid), =0 by default
|
---|
[109] | 1245 | ivar=VarType.coord(idim);% index of the variable corresponding to the current dimension
|
---|
| 1246 | if ~isequal(ivar,0)% a variable corresponds to the dimension #idim
|
---|
| 1247 | eval(['Coord{idim}=FieldData.' FieldData.ListVarName{ivar} ';']) ;% coord values for the input field
|
---|
| 1248 | if numel(Coord{idim})==2 %input array defined on a regular grid
|
---|
| 1249 | DCoord_min(idim)=(Coord{idim}(2)-Coord{idim}(1))/DimValue(idim);
|
---|
| 1250 | else
|
---|
| 1251 | DCoord=diff(Coord{idim});%array of coordinate derivatives for the input field
|
---|
| 1252 | DCoord_min(idim)=min(DCoord);
|
---|
| 1253 | DCoord_max=max(DCoord);
|
---|
| 1254 | % test_direct(idim)=DCoord_max>0;% =1 for increasing values, 0 otherwise
|
---|
[158] | 1255 | if abs(DCoord_max-DCoord_min(idim))>abs(DCoord_max/1000)
|
---|
[109] | 1256 | msgbox_uvmat('ERROR',['non monotonic dimension variable # ' num2str(idim) ' in proj_field.m'])
|
---|
[8] | 1257 | return
|
---|
[109] | 1258 | end
|
---|
| 1259 | test_interp(idim)=(DCoord_max-DCoord_min(idim))> 0.0001*abs(DCoord_max);% test grid regularity
|
---|
| 1260 | end
|
---|
| 1261 | test_direct(idim)=(DCoord_min(idim)>0);
|
---|
| 1262 | else % no variable associated with the dimension #idim, the coordinate value is set equal to the matrix index by default
|
---|
[8] | 1263 | Coord_i_str=['Coord_' num2str(idim)];
|
---|
| 1264 | DCoord_min(idim)=1;%default
|
---|
| 1265 | Coord{idim}=[0.5 DimValue(idim)-0.5];
|
---|
| 1266 | test_direct(idim)=1;
|
---|
| 1267 | end
|
---|
| 1268 | end
|
---|
[109] | 1269 | if DY==0
|
---|
| 1270 | DY=abs(DCoord_min(nb_dim-1));
|
---|
| 1271 | end
|
---|
| 1272 | npY=1+round(abs(Coord{nb_dim-1}(end)-Coord{nb_dim-1}(1))/DY);%nbre of points after interpol
|
---|
| 1273 | if DX==0
|
---|
| 1274 | DX=abs(DCoord_min(nb_dim));
|
---|
| 1275 | end
|
---|
| 1276 | npX=1+round(abs(Coord{nb_dim}(end)-Coord{nb_dim}(1))/DX);%nbre of points after interpol
|
---|
| 1277 | for idim=[1:nb_dim]
|
---|
| 1278 | if test_interp(idim)
|
---|
| 1279 | DimValue(idim)=1+round(abs(Coord{idim}(end)-Coord{idim}(1))/abs(DCoord_min(idim)));%nbre of points after possible interpolation on a regular gri
|
---|
[8] | 1280 | end
|
---|
[109] | 1281 | end
|
---|
| 1282 | Coord_y=linspace(Coord{nb_dim-1}(1),Coord{nb_dim-1}(end),npY);
|
---|
| 1283 | test_direct_y=test_direct(nb_dim-1);
|
---|
| 1284 | Coord_x=linspace(Coord{nb_dim}(1),Coord{nb_dim}(end),npX);
|
---|
| 1285 | test_direct_x=test_direct(nb_dim);
|
---|
| 1286 | DAX=DCoord_min(nb_dim);
|
---|
| 1287 | DAY=DCoord_min(nb_dim-1);
|
---|
| 1288 | if nb_dim==3
|
---|
[8] | 1289 | DZ=abs(DCoord_min(1));
|
---|
[174] | 1290 | Coord_z=linspace(Coord{1}(1),Coord{1}(end),DimValue(1));
|
---|
[8] | 1291 | test_direct_z=test_direct(1);
|
---|
| 1292 | end
|
---|
| 1293 | minAX=min(Coord_x);
|
---|
| 1294 | maxAX=max(Coord_x);
|
---|
| 1295 | minAY=min(Coord_y);
|
---|
| 1296 | maxAY=max(Coord_y);
|
---|
| 1297 | xcorner=[minAX maxAX minAX maxAX]-ObjectData.Coord(1,1);
|
---|
| 1298 | ycorner=[maxAY maxAY minAY minAY]-ObjectData.Coord(1,2);
|
---|
| 1299 | xcor_new=xcorner*cos(Phi)+ycorner*sin(Phi);%coord new frame
|
---|
| 1300 | ycor_new=-xcorner*sin(Phi)+ycorner*cos(Phi);
|
---|
| 1301 | if ~testXMax
|
---|
| 1302 | XMax=max(xcor_new);
|
---|
| 1303 | end
|
---|
| 1304 | if ~testXMin
|
---|
| 1305 | XMin=min(xcor_new);
|
---|
| 1306 | end
|
---|
| 1307 | if ~testYMax
|
---|
| 1308 | YMax=max(ycor_new);
|
---|
| 1309 | end
|
---|
| 1310 | if ~testYMin
|
---|
| 1311 | YMin=min(ycor_new);
|
---|
| 1312 | end
|
---|
[109] | 1313 | DXinit=(maxAX-minAX)/(DimValue(2)-1);
|
---|
| 1314 | DYinit=(maxAY-minAY)/(DimValue(1)-1);
|
---|
[8] | 1315 | if DX==0
|
---|
| 1316 | DX=DXinit;
|
---|
| 1317 | end
|
---|
| 1318 | if DY==0
|
---|
| 1319 | DY=DYinit;
|
---|
| 1320 | end
|
---|
| 1321 | npX=floor((XMax-XMin)/DX+1);
|
---|
[109] | 1322 | npY=floor((YMax-YMin)/DY+1);
|
---|
[8] | 1323 | if test_direct_y
|
---|
| 1324 | coord_y_proj=linspace(YMin,YMax,npY);%abscissa of the new pixels along the line
|
---|
| 1325 | else
|
---|
| 1326 | coord_y_proj=linspace(YMax,YMin,npY);%abscissa of the new pixels along the line
|
---|
| 1327 | end
|
---|
| 1328 | if test_direct_x
|
---|
| 1329 | coord_x_proj=linspace(XMin,XMax,npX);%abscissa of the new pixels along the line
|
---|
| 1330 | else
|
---|
| 1331 | coord_x_proj=linspace(XMax,XMin,npX);%abscissa of the new pixels along the line
|
---|
| 1332 | end
|
---|
| 1333 |
|
---|
| 1334 | % case with no rotation and interpolation
|
---|
| 1335 | if isequal(ProjMode,'projection') && isequal(Phi,0) && isequal(Theta,0) && isequal(Psi,0)
|
---|
[174] | 1336 | if ~testXMin && ~testXMax && ~testYMin && ~testYMax && nb_dim==2
|
---|
[159] | 1337 | ProjData=FieldData;
|
---|
[8] | 1338 | else
|
---|
[159] | 1339 | if test_direct(1)
|
---|
| 1340 | min_ind1=ceil((YMin-Coord{1}(1))/DYinit)+1;
|
---|
| 1341 | max_ind1=floor((YMax-Coord{1}(1))/DYinit)+1;
|
---|
| 1342 | Ybound(1)=Coord{1}(1)+DYinit*(min_ind1-1);
|
---|
| 1343 | Ybound(2)=Coord{1}(1)+DYinit*(max_ind1-1);
|
---|
| 1344 | else
|
---|
| 1345 | min_ind1=ceil((Coord{1}(1)-YMax)/DYinit)+1;
|
---|
| 1346 | max_ind1=floor((Coord{1}(1)-YMin)/DYinit)+1;
|
---|
| 1347 | Ybound(2)=Coord{1}(1)-DYinit*(max_ind1-1);
|
---|
| 1348 | Ybound(1)=Coord{1}(1)-DYinit*(min_ind1-1);
|
---|
| 1349 | end
|
---|
| 1350 | if test_direct(2)==1
|
---|
| 1351 | min_ind2=ceil((XMin-Coord{2}(1))/DXinit)+1;
|
---|
| 1352 | max_ind2=floor((XMax-Coord{2}(1))/DXinit)+1;
|
---|
| 1353 | Xbound(1)=Coord{2}(1)+DXinit*(min_ind2-1);
|
---|
| 1354 | Xbound(2)=Coord{2}(1)+DXinit*(max_ind2-1);
|
---|
| 1355 | else
|
---|
| 1356 | min_ind2=ceil((Coord{2}(1)-XMax)/DXinit)+1;
|
---|
| 1357 | max_ind2=floor((Coord{2}(1)-XMin)/DXinit)+1;
|
---|
| 1358 | Xbound(2)=Coord{2}(1)+DXinit*(max_ind2-1);
|
---|
| 1359 | Xbound(1)=Coord{2}(1)+DXinit*(min_ind2-1);
|
---|
| 1360 | end
|
---|
[174] | 1361 | if nb_dim==3 %TODO: to update
|
---|
| 1362 | min_ind3=ceil((Coord{1}(1)-ZMax)/DZinit)+1;
|
---|
| 1363 | max_ind2=floor((Coord{1}(2)-XMin)/DZinit)+1;
|
---|
| 1364 | Zbound(2)=Coord{1}(1)+DXinit*(max_ind2-1);
|
---|
| 1365 | Zbound(1)=Coord{1}(1)+DXinit*(min_ind2-1);
|
---|
| 1366 | end
|
---|
[159] | 1367 | min_ind1=max(min_ind1,1);% deals with margin (bound lower than the first index)
|
---|
| 1368 | min_ind2=max(min_ind2,1);
|
---|
| 1369 | max_ind1=min(max_ind1,DimValue(1));
|
---|
| 1370 | max_ind2=min(max_ind2,DimValue(2));
|
---|
| 1371 | for ivar=VarIndex
|
---|
| 1372 | VarName=FieldData.ListVarName{ivar};
|
---|
| 1373 | ProjData.ListVarName=[ProjData.ListVarName VarName];
|
---|
| 1374 | ProjData.VarDimName=[ProjData.VarDimName {DimCell}];
|
---|
| 1375 | if isfield(FieldData,'VarAttribute') && length(FieldData.VarAttribute)>=ivar
|
---|
| 1376 | ProjData.VarAttribute{length(ProjData.ListVarName)}=FieldData.VarAttribute{ivar};
|
---|
| 1377 | end
|
---|
| 1378 | eval(['ProjData.' VarName '=FieldData.' VarName '(min_ind1:max_ind1,min_ind2:max_ind2,:) ;']);
|
---|
| 1379 | end
|
---|
| 1380 | eval(['ProjData.' AYName '=[Ybound(1) Ybound(2)];']) %record the new (projected ) y coordinates
|
---|
| 1381 | eval(['ProjData.' AXName '=[Xbound(1) Xbound(2)];']) %record the new (projected ) x coordinates
|
---|
| 1382 | end
|
---|
[109] | 1383 | else % case with rotation and/or interpolation
|
---|
[8] | 1384 | if isempty(Coord_z) %2D case
|
---|
| 1385 | [X,Y]=meshgrid(coord_x_proj,coord_y_proj);%grid in the new coordinates
|
---|
| 1386 | XIMA=ObjectData.Coord(1,1)+(X)*cos(Phi)-Y*sin(Phi);%corresponding coordinates in the original image
|
---|
| 1387 | YIMA=ObjectData.Coord(1,2)+(X)*sin(Phi)+Y*cos(Phi);
|
---|
| 1388 | XIMA=(XIMA-minAX)/DXinit+1;% image index along x
|
---|
| 1389 | YIMA=(-YIMA+maxAY)/DYinit+1;% image index along y
|
---|
| 1390 | XIMA=reshape(round(XIMA),1,npX*npY);%indices reorganized in 'line'
|
---|
| 1391 | YIMA=reshape(round(YIMA),1,npX*npY);
|
---|
[109] | 1392 | flagin=XIMA>=1 & XIMA<=DimValue(2) & YIMA >=1 & YIMA<=DimValue(1);%flagin=1 inside the original image
|
---|
[8] | 1393 | if isequal(ObjectData.ProjMode,'filter')
|
---|
| 1394 | npx_filter=ceil(abs(DX/DAX));
|
---|
| 1395 | npy_filter=ceil(abs(DY/DAY));
|
---|
| 1396 | Mfilter=ones(npy_filter,npx_filter)/(npx_filter*npy_filter);
|
---|
| 1397 | test_filter=1;
|
---|
| 1398 | else
|
---|
| 1399 | test_filter=0;
|
---|
| 1400 | end
|
---|
[109] | 1401 | eval(['ProjData.' AYName '=[coord_y_proj(1) coord_y_proj(end)];']) %record the new (projected ) y coordinates
|
---|
| 1402 | eval(['ProjData.' AXName '=[coord_x_proj(1) coord_x_proj(end)];']) %record the new (projected ) x coordinates
|
---|
[8] | 1403 | for ivar=VarIndex
|
---|
[109] | 1404 | VarName=FieldData.ListVarName{ivar};
|
---|
| 1405 | if test_interp(1) || test_interp(2)%interpolate on a regular grid
|
---|
| 1406 | eval(['ProjData.' VarName '=interp2(Coord{2},Coord{1},FieldData.' VarName ',Coord_x,Coord_y'');']) %TO TEST
|
---|
[8] | 1407 | end
|
---|
| 1408 | %filter the field (image) if option 'filter' is used
|
---|
| 1409 | if test_filter
|
---|
| 1410 | Aclass=class(FieldData.A);
|
---|
[109] | 1411 | eval(['ProjData.' VarName '=filter2(Mfilter,FieldData.' VarName ',''valid'');'])
|
---|
[8] | 1412 | if ~isequal(Aclass,'double')
|
---|
[109] | 1413 | eval(['ProjData.' VarName '=' Aclass '(FieldData.' VarName ');'])%revert to integer values
|
---|
[8] | 1414 | end
|
---|
| 1415 | end
|
---|
[109] | 1416 | eval(['vec_A=reshape(FieldData.' VarName ',[],nbcolor);'])%put the original image in line
|
---|
[8] | 1417 | ind_in=find(flagin);
|
---|
| 1418 | ind_out=find(~flagin);
|
---|
[109] | 1419 | ICOMB=(XIMA-1)*DimValue(1)+YIMA;
|
---|
[8] | 1420 | ICOMB=ICOMB(flagin);%index corresponding to XIMA and YIMA in the aligned original image vec_A
|
---|
| 1421 | vec_B(ind_in,[1:nbcolor])=vec_A(ICOMB,:);
|
---|
| 1422 | for icolor=1:nbcolor
|
---|
| 1423 | vec_B(ind_out,icolor)=zeros(size(ind_out));
|
---|
| 1424 | end
|
---|
[109] | 1425 | ProjData.ListVarName=[ProjData.ListVarName VarName];
|
---|
| 1426 | ProjData.VarDimName=[ProjData.VarDimName {DimCell}];
|
---|
| 1427 | if isfield(FieldData,'VarAttribute')&&length(FieldData.VarAttribute)>=ivar
|
---|
[8] | 1428 | ProjData.VarAttribute{length(ProjData.ListVarName)+nbcoord}=FieldData.VarAttribute{ivar};
|
---|
[77] | 1429 | end
|
---|
| 1430 | eval(['ProjData.' VarName '=reshape(vec_B,npY,npX,nbcolor);']);
|
---|
| 1431 | end
|
---|
| 1432 | ProjData.FF=reshape(~flagin,npY,npX);%false flag A FAIRE: tenir compte d'un flga antérieur
|
---|
| 1433 | ProjData.ListVarName=[ProjData.ListVarName 'FF'];
|
---|
[109] | 1434 | ProjData.VarDimName=[ProjData.VarDimName {DimCell}];
|
---|
[77] | 1435 | ProjData.VarAttribute{length(ProjData.ListVarName)}.Role='errorflag';
|
---|
| 1436 | else %3D case
|
---|
| 1437 | if isequal(Theta,0) & isequal(Phi,0)
|
---|
| 1438 | test_sup=(Coord{1}>=ObjectData.Coord(1,3));
|
---|
| 1439 | iz_sup=find(test_sup);
|
---|
| 1440 | iz=iz_sup(1);
|
---|
| 1441 | if iz>=1 & iz<=npz
|
---|
[109] | 1442 | %ProjData.ListDimName=[ProjData.ListDimName ListDimName(2:end)];
|
---|
| 1443 | %ProjData.DimValue=[ProjData.DimValue npY npX];
|
---|
[77] | 1444 | for ivar=VarIndex
|
---|
| 1445 | VarName=FieldData.ListVarName{ivar};
|
---|
| 1446 | ProjData.ListVarName=[ProjData.ListVarName VarName];
|
---|
| 1447 | ProjData.VarAttribute{length(ProjData.ListVarName)}=FieldData.VarAttribute{ivar}; %reproduce the variable attributes
|
---|
| 1448 | eval(['ProjData.' VarName '=squeeze(FieldData.' VarName '(iz,:,:));'])% select the z index iz
|
---|
| 1449 | %TODO : do a vertical average for a thick plane
|
---|
| 1450 | if test_interp(2) | test_interp(3)
|
---|
| 1451 | eval(['ProjData.' VarName '=interp2(Coord{3},Coord{2},ProjData.' VarName ',Coord_x,Coord_y'');'])
|
---|
| 1452 | end
|
---|
| 1453 | end
|
---|
[8] | 1454 | end
|
---|
[77] | 1455 | else
|
---|
| 1456 | errormsg='projection of structured coordinates on oblique plane not yet implemented';
|
---|
| 1457 | %TODO: use interp3
|
---|
| 1458 | return
|
---|
| 1459 | end
|
---|
| 1460 | end
|
---|
| 1461 | end
|
---|
| 1462 | end
|
---|
[158] | 1463 |
|
---|
| 1464 | %% projection of velocity components in the rotated coordinates
|
---|
[77] | 1465 | if ~isequal(Phi,0) && length(ivar_U)==1
|
---|
| 1466 | if isempty(ivar_V)
|
---|
| 1467 | msgbox_uvmat('ERROR','v velocity component missing in proj_field.m')
|
---|
| 1468 | return
|
---|
| 1469 | end
|
---|
| 1470 | UName=FieldData.ListVarName{ivar_U};
|
---|
| 1471 | VName=FieldData.ListVarName{ivar_V};
|
---|
| 1472 | eval(['ProjData.' UName '=cos(Phi)*ProjData.' UName '+ sin(Phi)*ProjData.' VName ';'])
|
---|
| 1473 | eval(['ProjData.' VName '=cos(Theta)*(-sin(Phi)*ProjData.' UName '+ cos(Phi)*ProjData.' VName ');'])
|
---|
| 1474 | if ~isempty(ivar_W)
|
---|
| 1475 | WName=FieldData.ListVarName{ivar_W};
|
---|
| 1476 | eval(['ProjData.' VName '=ProjData.' VName '+ ProjData.' WName '*sin(Theta);'])%
|
---|
| 1477 | eval(['ProjData.' WName '=NormVec_X*ProjData.' UName '+ NormVec_Y*ProjData.' VName '+ NormVec_Z* ProjData.' WName ';']);
|
---|
| 1478 | end
|
---|
| 1479 | if ~isequal(Psi,0)
|
---|
| 1480 | eval(['ProjData.' UName '=cos(Psi)* ProjData.' UName '- sin(Psi)*ProjData.' VName ';']);
|
---|
| 1481 | eval(['ProjData.' VName '=sin(Psi)* ProjData.' UName '+ cos(Psi)*ProjData.' VName ';']);
|
---|
| 1482 | end
|
---|
| 1483 | end
|
---|
| 1484 | end
|
---|
| 1485 |
|
---|
| 1486 | %-----------------------------------------------------------------
|
---|
| 1487 | %project in a volume
|
---|
| 1488 | % A FAIRE ....(copie de proj_plane)
|
---|
| 1489 | function [ProjData,errormsg] = proj_volume(FieldData, ObjectData)
|
---|
| 1490 | %-----------------------------------------------------------------
|
---|
| 1491 |
|
---|
| 1492 | %initialisation of the input parameters of the projection plane
|
---|
| 1493 | %-----------------------------------------------------------------
|
---|
| 1494 | ProjMode='projection';%direct projection by default
|
---|
| 1495 | if isfield(ObjectData,'ProjMode'),ProjMode=ObjectData.ProjMode; end;
|
---|
| 1496 |
|
---|
| 1497 | %axis origin
|
---|
| 1498 | if isempty(ObjectData.Coord)
|
---|
| 1499 | ObjectData.Coord(1,1)=0;%origin of the volume set to [0 0] by default
|
---|
| 1500 | ObjectData.Coord(1,2)=0;
|
---|
| 1501 | ObjectData.Coord(1,3)=0;
|
---|
| 1502 | end
|
---|
| 1503 |
|
---|
| 1504 | %rotation angles
|
---|
| 1505 | Phi=0;%default
|
---|
| 1506 | Theta=0;
|
---|
| 1507 | Psi=0;
|
---|
| 1508 | if isfield(ObjectData,'Phi')&& ~isempty(ObjectData.Phi)
|
---|
| 1509 | Phi=(pi/180)*ObjectData.Phi;%first Euler angle in radian
|
---|
| 1510 | end
|
---|
| 1511 | if isfield(ObjectData,'Theta')&& ~isempty(ObjectData.Theta)
|
---|
| 1512 | Theta=(pi/180)*ObjectData.Theta;%second Euler angle in radian
|
---|
| 1513 | end
|
---|
| 1514 | if isfield(ObjectData,'Psi')&& ~isempty(ObjectData.Psi)
|
---|
| 1515 | Psi=(pi/180)*ObjectData.Psi;%third Euler angle in radian
|
---|
| 1516 | end
|
---|
| 1517 |
|
---|
| 1518 | %components of the unity vector normal to the projection plane
|
---|
| 1519 | NormVec_X=-sin(Phi)*sin(Theta);
|
---|
| 1520 | NormVec_Y=cos(Phi)*sin(Theta);
|
---|
| 1521 | NormVec_Z=cos(Theta);
|
---|
| 1522 |
|
---|
| 1523 | % test for 3D fields
|
---|
| 1524 | test3D=0;
|
---|
| 1525 | if isfield(FieldData,'nb_dim')
|
---|
| 1526 | test3D=isequal(FieldData.nb_dim,3);
|
---|
| 1527 | end
|
---|
| 1528 | test3C=test3D; %default 3 vel components
|
---|
| 1529 |
|
---|
| 1530 | %mesh sizes DX and DY
|
---|
| 1531 | DX=0;
|
---|
| 1532 | DY=0; %default
|
---|
| 1533 | if isfield(ObjectData,'DX')&~isempty(ObjectData.DX)
|
---|
| 1534 | DX=abs(ObjectData.DX);%mesh of interpolation points
|
---|
| 1535 | end
|
---|
| 1536 | if isfield(ObjectData,'DY')&~isempty(ObjectData.DY)
|
---|
| 1537 | DY=abs(ObjectData.DY);%mesh of interpolation points
|
---|
| 1538 | end
|
---|
| 1539 | if ~isequal(ProjMode,'projection') & (DX==0|DY==0)
|
---|
| 1540 | errormsg='DX or DY missing';
|
---|
| 1541 | display(errormsg)
|
---|
| 1542 | return
|
---|
| 1543 | end
|
---|
| 1544 | if isfield(ObjectData,'DZ')&~isempty(ObjectData.DZ)
|
---|
| 1545 | DZ=abs(ObjectData.DZ);%mesh of interpolation points
|
---|
| 1546 | end
|
---|
| 1547 |
|
---|
| 1548 | %extrema along each axis
|
---|
| 1549 | testXMin=0;
|
---|
| 1550 | testXMax=0;
|
---|
| 1551 | testYMin=0;
|
---|
| 1552 | testYMax=0;
|
---|
| 1553 | if isfield(ObjectData,'RangeX')
|
---|
| 1554 | XMin=min(ObjectData.RangeX);
|
---|
| 1555 | XMax=max(ObjectData.RangeX);
|
---|
| 1556 | testXMin=XMax>XMin;
|
---|
| 1557 | testXMax=1;
|
---|
| 1558 | end
|
---|
| 1559 | if isfield(ObjectData,'RangeY')
|
---|
| 1560 | YMin=min(ObjectData.RangeY);
|
---|
| 1561 | YMax=max(ObjectData.RangeY);
|
---|
| 1562 | testYMin=YMax>YMin;
|
---|
| 1563 | testYMax=1;
|
---|
| 1564 | end
|
---|
| 1565 | width=0;%default width of the projection band
|
---|
| 1566 | if isfield(ObjectData,'RangeZ')
|
---|
| 1567 | ZMin=min(ObjectData.RangeZ);
|
---|
| 1568 | ZMax=max(ObjectData.RangeZ);
|
---|
| 1569 | testZMin=YMax>YMin;
|
---|
| 1570 | testZMax=1;
|
---|
| 1571 | % width=max(ObjectData.RangeZ);
|
---|
| 1572 | end
|
---|
| 1573 |
|
---|
| 1574 | % initiate Matlab structure for physical field
|
---|
[150] | 1575 | [ProjData,errormsg]=proj_heading(FieldData,ObjectData);
|
---|
[77] | 1576 | ProjData.NbDim=3;
|
---|
[109] | 1577 | %ProjData.ListDimName={};%name of dimension
|
---|
| 1578 | %ProjData.DimValue=[];%values of dimension (nbre of vectors)
|
---|
[77] | 1579 | ProjData.ListVarName={};
|
---|
| 1580 | ProjData.VarDimName={};
|
---|
| 1581 |
|
---|
| 1582 | error=0;%default
|
---|
| 1583 | flux=0;
|
---|
| 1584 | testfalse=0;
|
---|
| 1585 | ListIndex={};
|
---|
| 1586 |
|
---|
| 1587 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
---|
| 1588 | %group the variables (fields of 'FieldData') in cells of variables with the same dimensions
|
---|
| 1589 | %-----------------------------------------------------------------
|
---|
| 1590 | idimvar=0;
|
---|
| 1591 | [CellVarIndex,NbDim,VarTypeCell,errormsg]=find_field_indices(FieldData);
|
---|
| 1592 | if ~isempty(errormsg)
|
---|
| 1593 | errormsg=['error in proj_field/proj_plane:' errormsg];
|
---|
| 1594 | return
|
---|
| 1595 | end
|
---|
| 1596 | %LOOP ON GROUPS OF VARIABLES SHARING THE SAME DIMENSIONS
|
---|
| 1597 | % CellVarIndex=cells of variable index arrays
|
---|
| 1598 | ivar_new=0; % index of the current variable in the projected field
|
---|
| 1599 | icoord=0;
|
---|
| 1600 | nbcoord=0;%number of added coordinate variables brought by projection
|
---|
| 1601 | for icell=1:length(CellVarIndex)
|
---|
| 1602 | if NbDim(icell)<2
|
---|
| 1603 | continue
|
---|
| 1604 | end
|
---|
| 1605 | VarIndex=CellVarIndex{icell};% indices of the selected variables in the list FieldData.ListVarName
|
---|
| 1606 | VarType=VarTypeCell{icell};
|
---|
| 1607 | ivar_X=VarType.coord_x;
|
---|
| 1608 | ivar_Y=VarType.coord_y;
|
---|
| 1609 | ivar_Z=VarType.coord_z;
|
---|
| 1610 | ivar_U=VarType.vector_x;
|
---|
| 1611 | ivar_V=VarType.vector_y;
|
---|
| 1612 | ivar_W=VarType.vector_z;
|
---|
| 1613 | ivar_C=VarType.scalar ;
|
---|
| 1614 | ivar_Anc=VarType.ancillary;
|
---|
| 1615 | test_anc=zeros(size(VarIndex));
|
---|
| 1616 | test_anc(ivar_Anc)=ones(size(ivar_Anc));
|
---|
| 1617 | ivar_F=VarType.warnflag;
|
---|
| 1618 | ivar_FF=VarType.errorflag;
|
---|
| 1619 | testX=~isempty(ivar_X) && ~isempty(ivar_Y);
|
---|
| 1620 | DimCell=FieldData.VarDimName{VarIndex(1)};
|
---|
| 1621 | if ischar(DimCell)
|
---|
| 1622 | DimCell={DimCell};%name of dimensions
|
---|
| 1623 | end
|
---|
| 1624 |
|
---|
| 1625 | %case of input fields with unstructured coordinates
|
---|
| 1626 | if testX
|
---|
| 1627 | XName=FieldData.ListVarName{ivar_X};
|
---|
| 1628 | YName=FieldData.ListVarName{ivar_Y};
|
---|
| 1629 | eval(['coord_x=FieldData.' XName ';'])
|
---|
| 1630 | eval(['coord_y=FieldData.' YName ';'])
|
---|
| 1631 | if length(ivar_Z)==1
|
---|
| 1632 | ZName=FieldData.ListVarName{ivar_Z};
|
---|
| 1633 | eval(['coord_z=FieldData.' ZName ';'])
|
---|
| 1634 | end
|
---|
| 1635 |
|
---|
| 1636 | % translate initial coordinates
|
---|
| 1637 | coord_x=coord_x-ObjectData.Coord(1,1);
|
---|
| 1638 | coord_y=coord_y-ObjectData.Coord(1,2);
|
---|
| 1639 | if ~isempty(ivar_Z)
|
---|
| 1640 | coord_z=coord_z-ObjectData.Coord(1,3);
|
---|
| 1641 | end
|
---|
| 1642 |
|
---|
| 1643 | % selection of the vectors in the projection range (3D case)
|
---|
| 1644 | if length(ivar_Z)==1 && width > 0
|
---|
| 1645 | %components of the unitiy vector normal to the projection plane
|
---|
| 1646 | fieldZ=NormVec_X*coord_x + NormVec_Y*coord_y+ NormVec_Z*coord_z;% distance to the plane
|
---|
| 1647 | indcut=find(abs(fieldZ) <= width);
|
---|
| 1648 | for ivar=VarIndex
|
---|
| 1649 | VarName=FieldData.ListVarName{ivar};
|
---|
| 1650 | eval(['FieldData.' VarName '=FieldData.' VarName '(indcut);'])
|
---|
| 1651 | % end
|
---|
| 1652 | % A VOIR : CAS DE VAR STRUCTUREE MAIS PAS GRILLE REGULIERE : INTERPOLER SUR GRILLE REGULIERE
|
---|
| 1653 | end
|
---|
| 1654 | coord_x=coord_x(indcut);
|
---|
| 1655 | coord_y=coord_y(indcut);
|
---|
| 1656 | coord_z=coord_z(indcut);
|
---|
| 1657 | end
|
---|
| 1658 |
|
---|
| 1659 | %rotate coordinates if needed
|
---|
| 1660 | if isequal(Phi,0)
|
---|
| 1661 | coord_X=coord_x;
|
---|
| 1662 | coord_Y=coord_y;
|
---|
| 1663 | if ~isequal(Theta,0)
|
---|
| 1664 | coord_Y=coord_Y *cos(Theta);
|
---|
| 1665 | end
|
---|
| 1666 | else
|
---|
| 1667 | coord_X=(coord_x *cos(Phi) + coord_y* sin(Phi));
|
---|
| 1668 | coord_Y=(-coord_x *sin(Phi) + coord_y *cos(Phi))*cos(Theta);
|
---|
| 1669 | end
|
---|
| 1670 | if ~isempty(ivar_Z)
|
---|
| 1671 | coord_Y=coord_Y+coord_z *sin(Theta);
|
---|
| 1672 | end
|
---|
| 1673 | if ~isequal(Psi,0)
|
---|
| 1674 | coord_X=(coord_X *cos(Psi) - coord_Y* sin(Psi));%A VERIFIER
|
---|
| 1675 | coord_Y=(coord_X *sin(Psi) + coord_Y* cos(Psi));
|
---|
| 1676 | end
|
---|
| 1677 | coord_Z=coord_z; %TO UPDATE
|
---|
| 1678 | %restriction to the range of x and y if imposed
|
---|
| 1679 | testin=ones(size(coord_X)); %default
|
---|
| 1680 | testbound=0;
|
---|
| 1681 | if testXMin
|
---|
| 1682 | testin=testin & (coord_X >= XMin);
|
---|
| 1683 | testbound=1;
|
---|
| 1684 | end
|
---|
| 1685 | if testXMax
|
---|
| 1686 | testin=testin & (coord_X <= XMax);
|
---|
| 1687 | testbound=1;
|
---|
| 1688 | end
|
---|
| 1689 | if testYMin
|
---|
| 1690 | testin=testin & (coord_Y >= YMin);
|
---|
| 1691 | testbound=1;
|
---|
| 1692 | end
|
---|
| 1693 | if testYMin
|
---|
| 1694 | testin=testin & (coord_Y <= YMax);
|
---|
| 1695 | testbound=1;
|
---|
| 1696 | end
|
---|
| 1697 | if testbound
|
---|
| 1698 | indcut=find(testin);
|
---|
| 1699 | for ivar=VarIndex
|
---|
| 1700 | VarName=FieldData.ListVarName{ivar};
|
---|
| 1701 | eval(['FieldData.' VarName '=FieldData.' VarName '(indcut);'])
|
---|
| 1702 | end
|
---|
| 1703 | coord_X=coord_X(indcut);
|
---|
| 1704 | coord_Y=coord_Y(indcut);
|
---|
| 1705 | if length(ivar_Z)==1
|
---|
| 1706 | coord_Z=coord_Z(indcut);
|
---|
| 1707 | end
|
---|
| 1708 | end
|
---|
| 1709 | % different cases of projection
|
---|
| 1710 | if isequal(ObjectData.ProjMode,'projection')
|
---|
| 1711 | %the list of dimension
|
---|
[109] | 1712 | %ProjData.ListDimName=[ProjData.ListDimName FieldData.VarDimName(VarIndex(1))];%add the point index to the list of dimensions
|
---|
| 1713 | %ProjData.DimValue=[ProjData.DimValue length(coord_X)];
|
---|
[77] | 1714 | nbvar=0;
|
---|
| 1715 | for ivar=VarIndex %transfer variables to the projection plane
|
---|
| 1716 | VarName=FieldData.ListVarName{ivar};
|
---|
| 1717 | if ivar==ivar_X %x coordinate
|
---|
| 1718 | eval(['ProjData.' VarName '=coord_X;'])
|
---|
| 1719 | elseif ivar==ivar_Y % y coordinate
|
---|
| 1720 | eval(['ProjData.' VarName '=coord_Y;'])
|
---|
| 1721 | elseif isempty(ivar_Z) || ivar~=ivar_Z % other variables (except Z coordinate wyhich is not reproduced)
|
---|
| 1722 | eval(['ProjData.' VarName '=FieldData.' VarName ';'])
|
---|
| 1723 | end
|
---|
| 1724 | if isempty(ivar_Z) || ivar~=ivar_Z
|
---|
| 1725 | ProjData.ListVarName=[ProjData.ListVarName VarName];
|
---|
| 1726 | ProjData.VarDimName=[ProjData.VarDimName DimCell];
|
---|
| 1727 | nbvar=nbvar+1;
|
---|
| 1728 | if isfield(FieldData,'VarAttribute') & length(FieldData.VarAttribute) >=ivar
|
---|
| 1729 | ProjData.VarAttribute{nbvar}=FieldData.VarAttribute{ivar};
|
---|
| 1730 | end
|
---|
| 1731 | end
|
---|
| 1732 | end
|
---|
| 1733 | elseif isequal(ObjectData.ProjMode,'interp')||isequal(ObjectData.ProjMode,'filter')%interpolate data on a regular grid
|
---|
| 1734 | coord_x_proj=[XMin:DX:XMax];
|
---|
| 1735 | coord_y_proj=[YMin:DY:YMax];
|
---|
| 1736 | coord_z_proj=[ZMin:DZ:ZMax];
|
---|
| 1737 | [XI,YI,ZI]=meshgrid(coord_x_proj,coord_y_proj,coord_z_proj);
|
---|
| 1738 | DimCell={'coord_y','coord_x'};
|
---|
| 1739 | ProjData.ListVarName={'coord_z','coord_y','coord_x'};
|
---|
| 1740 | ProjData.VarDimName={'coord_z','coord_y','coord_x'};
|
---|
| 1741 | nbcoord=3;
|
---|
| 1742 | ProjData.coord_z=[ZMin ZMax];
|
---|
| 1743 | ProjData.coord_y=[YMin YMax];
|
---|
| 1744 | ProjData.coord_x=[XMin XMax];
|
---|
| 1745 | if isempty(ivar_X), ivar_X=0; end;
|
---|
| 1746 | if isempty(ivar_Y), ivar_Y=0; end;
|
---|
| 1747 | if isempty(ivar_Z), ivar_Z=0; end;
|
---|
| 1748 | if isempty(ivar_U), ivar_U=0; end;
|
---|
| 1749 | if isempty(ivar_V), ivar_V=0; end;
|
---|
| 1750 | if isempty(ivar_W), ivar_W=0; end;
|
---|
| 1751 | if isempty(ivar_F), ivar_F=0; end;
|
---|
| 1752 | if isempty(ivar_FF), ivar_FF=0; end;
|
---|
| 1753 | if ~isequal(ivar_FF,0)
|
---|
| 1754 | VarName_FF=FieldData.ListVarName{ivar_FF};
|
---|
| 1755 | eval(['indsel=find(FieldData.' VarName_FF '==0);'])
|
---|
| 1756 | coord_X=coord_X(indsel);
|
---|
| 1757 | coord_Y=coord_Y(indsel);
|
---|
| 1758 | end
|
---|
| 1759 | FF=zeros(1,length(coord_y_proj)*length(coord_x_proj));
|
---|
| 1760 | testFF=0;
|
---|
| 1761 | size(XI)
|
---|
| 1762 | size(YI)
|
---|
| 1763 | size(ZI)
|
---|
| 1764 | for ivar=VarIndex
|
---|
| 1765 | VarName=FieldData.ListVarName{ivar};
|
---|
| 1766 | if ~( ivar==ivar_X || ivar==ivar_Y || ivar==ivar_Z || ivar==ivar_F || ivar==ivar_FF || test_anc(ivar)==1)
|
---|
| 1767 | ivar_new=ivar_new+1;
|
---|
| 1768 | ProjData.ListVarName=[ProjData.ListVarName {VarName}];
|
---|
| 1769 | ProjData.VarDimName=[ProjData.VarDimName {DimCell}];
|
---|
| 1770 | if isfield(FieldData,'VarAttribute') && length(FieldData.VarAttribute) >=ivar
|
---|
| 1771 | ProjData.VarAttribute{ivar_new+nbcoord}=FieldData.VarAttribute{ivar};
|
---|
| 1772 | end
|
---|
| 1773 | if ~isequal(ivar_FF,0)
|
---|
| 1774 | eval(['FieldData.' VarName '=FieldData.' VarName '(indsel);'])
|
---|
| 1775 | end
|
---|
| 1776 | eval(['ProjData.' VarName '=griddata3(double(coord_X),double(coord_Y),double(coord_Z),double(FieldData.' VarName '),XI,YI,ZI);'])
|
---|
| 1777 | % eval(['varline=reshape(ProjData.' VarName ',1,length(coord_y_proj)*length(coord_x_proj));'])
|
---|
| 1778 | % FFlag= isnan(varline); %detect undefined values NaN
|
---|
| 1779 | % indnan=find(FFlag);
|
---|
| 1780 | % if~isempty(indnan)
|
---|
| 1781 | % varline(indnan)=zeros(size(indnan));
|
---|
| 1782 | % eval(['ProjData.' VarName '=reshape(varline,length(coord_y_proj),length(coord_x_proj));'])
|
---|
| 1783 | % FF(indnan)=ones(size(indnan));
|
---|
| 1784 | % testFF=1;
|
---|
[8] | 1785 | % end
|
---|
[77] | 1786 | % if ivar==ivar_U
|
---|
| 1787 | % ivar_U=ivar_new;
|
---|
| 1788 | % end
|
---|
| 1789 | % if ivar==ivar_V
|
---|
| 1790 | % ivar_V=ivar_new;
|
---|
| 1791 | % end
|
---|
| 1792 | % if ivar==ivar_W
|
---|
| 1793 | % ivar_W=ivar_new;
|
---|
| 1794 | % end
|
---|
| 1795 | end
|
---|
| 1796 | end
|
---|
| 1797 | if testFF
|
---|
| 1798 | ProjData.FF=reshape(FF,length(coord_y_proj),length(coord_x_proj));
|
---|
| 1799 | ProjData.ListVarName=[ProjData.ListVarName {'FF'}];
|
---|
| 1800 | ProjData.VarDimName=[ProjData.VarDimName {DimCell}];
|
---|
| 1801 | ProjData.VarAttribute{ivar_new+1+nbcoord}.Role='errorflag';
|
---|
| 1802 | end
|
---|
| 1803 | end
|
---|
| 1804 | %case of fields defined on a structured grid
|
---|
| 1805 | else
|
---|
| 1806 | AYName=FieldData.ListVarName{VarType.coord(1)};
|
---|
| 1807 | AXName=FieldData.ListVarName{VarType.coord(2)};
|
---|
| 1808 | eval(['AX=FieldData.' AXName ';'])
|
---|
| 1809 | eval(['AY=FieldData.' AYName ';'])
|
---|
| 1810 | VarName=FieldData.ListVarName{VarIndex(1)};
|
---|
| 1811 | eval(['DimValue=size(FieldData.' VarName ');'])
|
---|
| 1812 | ListDimName=FieldData.VarDimName{VarIndex(1)};
|
---|
| 1813 | ProjData.ListVarName=[{AYName} {AXName} ProjData.ListVarName]; %TODO: check if it already exists in Projdata (several cells)
|
---|
| 1814 | ProjData.VarDimName=[{AYName} {AXName} ProjData.VarDimName];
|
---|
| 1815 | nbcolor=1; %default
|
---|
| 1816 | for idim=1:length(ListDimName)
|
---|
| 1817 | DimName=ListDimName{idim};
|
---|
| 1818 | if isequal(DimName,'rgb')|isequal(DimName,'nb_coord')|isequal(DimName,'nb_coord_i')
|
---|
| 1819 | nbcolor=DimValue(idim);
|
---|
| 1820 | DimIndices(idim)=[];
|
---|
| 1821 | DimValue(idim)=[];
|
---|
| 1822 | end
|
---|
| 1823 | if isequal(DimName,'nb_coord_j')% NOTE: CASE OF TENSOR NOT TREATED
|
---|
| 1824 | DimIndices(idim)=[];
|
---|
| 1825 | DimValue(idim)=[];
|
---|
| 1826 | end
|
---|
| 1827 | end
|
---|
| 1828 | ind_1=find(DimValue==1);
|
---|
| 1829 | DimIndices(ind_1)=[]; %suppress singleton dimensions
|
---|
| 1830 | % indxy=find(DimVarIndex(DimIndices));%select dimension variables (DimIndices non zero)
|
---|
| 1831 | nb_dim=length(DimIndices);%number of space dimensions
|
---|
| 1832 | Coord_z=[];
|
---|
| 1833 | Coord_y=[];
|
---|
| 1834 | Coord_x=[];
|
---|
| 1835 |
|
---|
| 1836 | for idim=1:nb_dim %loop on space dimensions
|
---|
| 1837 | test_interp(idim)=0;%test for coordiate interpolation (non regular grid), =0 by default
|
---|
| 1838 | ivar=DimVarIndex(DimIndices(idim));% index of the variable corresponding to the current dimension
|
---|
| 1839 | if ~isequal(ivar,0)% a variable corresponds to the current dimension
|
---|
| 1840 | eval(['Coord{idim}=FieldData.' FieldData.ListVarName{ivar} ';']) ;% position for the first index
|
---|
| 1841 | DCoord=diff(Coord{idim});
|
---|
| 1842 | DCoord_min(idim)=min(DCoord);
|
---|
| 1843 | DCoord_max=max(DCoord);
|
---|
| 1844 | test_direct(idim)=DCoord_max>0;% =1 for increasing values, 0 otherwise
|
---|
| 1845 | test_direct_min=DCoord_min(idim)>0;% =1 for increasing values, 0 otherwise
|
---|
| 1846 | if ~isequal(test_direct(idim),test_direct_min)
|
---|
| 1847 | msgbox_uvmat('ERROR',['non monotonic dimension variable # ' num2str(idim) ' in proj_field.m'])
|
---|
| 1848 | return
|
---|
| 1849 | end
|
---|
| 1850 | test_interp(idim)=(DCoord_max-DCoord_min(idim))> 0.0001*abs(DCoord_max);% test grid regularity
|
---|
| 1851 | else % no variable associated with the first dimension, look for variable attributes Coord_1, _2 or _3
|
---|
| 1852 | Coord_i_str=['Coord_' num2str(idim)];
|
---|
| 1853 | DCoord_min(idim)=1;%default
|
---|
| 1854 | Coord{idim}=[0.5 DimValue(idim)-0.5];
|
---|
| 1855 | test_direct(idim)=1;
|
---|
| 1856 | end
|
---|
| 1857 | end
|
---|
| 1858 | if nb_dim==2
|
---|
| 1859 | if DY==0
|
---|
| 1860 | DY=abs(DCoord_min(1));
|
---|
| 1861 | end
|
---|
| 1862 | npY=1+round(abs(Coord{1}(end)-Coord{1}(1))/DY);%nbre of points after interpolation
|
---|
[109] | 1863 | DimValue(1)=1+round(abs(Coord{1}(end)-Coord{1}(1))/abs(DCoord_min(1)));%nbre of points after possible interpolation on a regular grid
|
---|
[77] | 1864 | if DX==0
|
---|
| 1865 | DX=abs(DCoord_min(2));
|
---|
| 1866 | end
|
---|
| 1867 | npX=1+round(abs(Coord{2}(end)-Coord{2}(1))/DX);%nbre of points after interpol
|
---|
[109] | 1868 | DimValue(2)=1+round(abs(Coord{2}(end)-Coord{2}(1))/abs(DCoord_min(2)));%nbre of points after possible interpolation on a regular grid
|
---|
[77] | 1869 | Coord_y=linspace(Coord{1}(1),Coord{1}(end),npY);
|
---|
| 1870 | test_direct_y=test_direct(1);
|
---|
| 1871 | Coord_x=linspace(Coord{2}(1),Coord{2}(end),npX);
|
---|
| 1872 | test_direct_x=test_direct(2);
|
---|
| 1873 | DAX=DCoord_min(2);
|
---|
| 1874 | DAY=DCoord_min(1);
|
---|
| 1875 | elseif nb_dim==3
|
---|
| 1876 | DZ=abs(DCoord_min(1));
|
---|
| 1877 | npz=1+round(abs(Coord{1}(end)-Coord{1}(1))/DZ);%nbre of points after interpolation
|
---|
| 1878 | if DY==0
|
---|
| 1879 | DY=abs(DCoord_min(2));
|
---|
| 1880 | end
|
---|
| 1881 | npY=1+round(abs(Coord{2}(end)-Coord{2}(1))/DY);%nbre of points after interpol
|
---|
[109] | 1882 | DimValue(1)=1+round(abs(Coord{2}(end)-Coord{2}(1))/abs(DCoord_min(2)));%nbre of points before interpol
|
---|
[77] | 1883 | if DX==0
|
---|
| 1884 | DX=abs(DCoord_min(3));
|
---|
| 1885 | end
|
---|
| 1886 | npX=1+round(abs(Coord{3}(end)-Coord{3}(1))/DX);%nbre of points after interpol
|
---|
[109] | 1887 | DimValue(2)=1+round(abs(Coord{3}(end)-Coord{3}(1))/abs(DCoord_min(3)));%nbre of points before interpol
|
---|
[77] | 1888 | Coord_z=linspace(Coord{1}(1),Coord{1}(end),npz);
|
---|
| 1889 | test_direct_z=test_direct(1);
|
---|
| 1890 | Coord_y=linspace(Coord{2}(1),Coord{2}(end),npY);
|
---|
| 1891 | test_direct_y=test_direct(2);
|
---|
| 1892 | Coord_x=linspace(Coord{3}(1),Coord{3}(end),npX);
|
---|
| 1893 | test_direct_x=test_direct(3);
|
---|
| 1894 | end
|
---|
| 1895 | minAX=min(Coord_x);
|
---|
| 1896 | maxAX=max(Coord_x);
|
---|
| 1897 | minAY=min(Coord_y);
|
---|
| 1898 | maxAY=max(Coord_y);
|
---|
| 1899 | xcorner=[minAX maxAX minAX maxAX]-ObjectData.Coord(1,1);
|
---|
| 1900 | ycorner=[maxAY maxAY minAY minAY]-ObjectData.Coord(1,2);
|
---|
| 1901 | xcor_new=xcorner*cos(Phi)+ycorner*sin(Phi);%coord new frame
|
---|
| 1902 | ycor_new=-xcorner*sin(Phi)+ycorner*cos(Phi);
|
---|
| 1903 | if ~testXMax
|
---|
| 1904 | XMax=max(xcor_new);
|
---|
| 1905 | end
|
---|
| 1906 | if ~testXMin
|
---|
| 1907 | XMin=min(xcor_new);
|
---|
| 1908 | end
|
---|
| 1909 | if ~testYMax
|
---|
| 1910 | YMax=max(ycor_new);
|
---|
| 1911 | end
|
---|
| 1912 | if ~testYMin
|
---|
| 1913 | YMin=min(ycor_new);
|
---|
| 1914 | end
|
---|
[109] | 1915 | DXinit=(maxAX-minAX)/(DimValue(2)-1);
|
---|
| 1916 | DYinit=(maxAY-minAY)/(DimValue(1)-1);
|
---|
[77] | 1917 | if DX==0
|
---|
| 1918 | DX=DXinit;
|
---|
| 1919 | end
|
---|
| 1920 | if DY==0
|
---|
| 1921 | DY=DYinit;
|
---|
| 1922 | end
|
---|
| 1923 | npX=floor((XMax-XMin)/DX+1);
|
---|
| 1924 | npY=floor((YMax-YMin)/DY+1);
|
---|
| 1925 | if test_direct_y
|
---|
| 1926 | coord_y_proj=linspace(YMin,YMax,npY);%abscissa of the new pixels along the line
|
---|
| 1927 | else
|
---|
| 1928 | coord_y_proj=linspace(YMax,YMin,npY);%abscissa of the new pixels along the line
|
---|
| 1929 | end
|
---|
| 1930 | if test_direct_x
|
---|
| 1931 | coord_x_proj=linspace(XMin,XMax,npX);%abscissa of the new pixels along the line
|
---|
| 1932 | else
|
---|
| 1933 | coord_x_proj=linspace(XMax,XMin,npX);%abscissa of the new pixels along the line
|
---|
| 1934 | end
|
---|
| 1935 |
|
---|
| 1936 | % case with no rotation and interpolation
|
---|
| 1937 | if isequal(ProjMode,'projection') && isequal(Phi,0) && isequal(Theta,0) && isequal(Psi,0)
|
---|
| 1938 | if test_direct(1)
|
---|
| 1939 | min_ind1=ceil((YMin-Coord{1}(1))/DYinit)+1;
|
---|
| 1940 | max_ind1=floor((YMax-Coord{1}(1))/DYinit)+1;
|
---|
| 1941 | Ybound(1)=Coord{1}(1)+DYinit*(min_ind1-1);
|
---|
| 1942 | Ybound(2)=Coord{1}(1)+DYinit*(max_ind1-1);
|
---|
| 1943 | else
|
---|
| 1944 | min_ind1=ceil((Coord{1}(1)-YMax)/DYinit)+1;
|
---|
| 1945 | max_ind1=floor((Coord{1}(1)-YMin)/DYinit)+1;
|
---|
| 1946 | Ybound(2)=Coord{1}(1)-DYinit*(max_ind1-1);
|
---|
| 1947 | Ybound(1)=Coord{1}(1)-DYinit*(min_ind1-1);
|
---|
| 1948 | end
|
---|
| 1949 | if test_direct(2)==1
|
---|
| 1950 | min_ind2=ceil((XMin-Coord{2}(1))/DXinit)+1;
|
---|
| 1951 | max_ind2=floor((XMax-Coord{2}(1))/DXinit)+1;
|
---|
| 1952 | Xbound(1)=Coord{2}(1)+DXinit*(min_ind2-1);
|
---|
| 1953 | Xbound(2)=Coord{2}(1)+DXinit*(max_ind2-1);
|
---|
| 1954 | else
|
---|
| 1955 | min_ind2=ceil((Coord{2}(1)-XMax)/DXinit)+1;
|
---|
| 1956 | max_ind2=floor((Coord{2}(1)-XMin)/DXinit)+1;
|
---|
| 1957 | Xbound(2)=Coord{2}(1)+DXinit*(max_ind2-1);
|
---|
| 1958 | Xbound(1)=Coord{2}(1)+DXinit*(min_ind2-1);
|
---|
| 1959 | end
|
---|
| 1960 | min_ind1=max(min_ind1,1);% deals with margin (bound lower than the first index)
|
---|
| 1961 | min_ind2=max(min_ind2,1);
|
---|
[109] | 1962 | max_ind1=min(max_ind1,DimValue(1));
|
---|
| 1963 | max_ind2=min(max_ind2,DimValue(2));
|
---|
[77] | 1964 | for ivar=VarIndex
|
---|
| 1965 | VarName=FieldData.ListVarName{ivar};
|
---|
| 1966 | ProjData.ListVarName=[ProjData.ListVarName VarName];
|
---|
[109] | 1967 | %ProjData.VarDimIndex=[ProjData.VarDimIndex [nb_dim-1 nb_dim]];
|
---|
[77] | 1968 | if length(FieldData.VarAttribute)>=ivar
|
---|
| 1969 | ProjData.VarAttribute{length(ProjData.ListVarName)}=FieldData.VarAttribute{ivar};
|
---|
| 1970 | end
|
---|
| 1971 | eval(['ProjData.' VarName '=FieldData.' VarName '(min_ind1:max_ind1,min_ind2:max_ind2) ;']);
|
---|
| 1972 | end
|
---|
| 1973 | else
|
---|
| 1974 | % case with rotation and/or interpolation
|
---|
| 1975 | if isempty(Coord_z) %2D case
|
---|
| 1976 | [X,Y]=meshgrid(coord_x_proj,coord_y_proj);%grid in the new coordinates
|
---|
| 1977 | XIMA=ObjectData.Coord(1,1)+(X)*cos(Phi)-Y*sin(Phi);%corresponding coordinates in the original image
|
---|
| 1978 | YIMA=ObjectData.Coord(1,2)+(X)*sin(Phi)+Y*cos(Phi);
|
---|
| 1979 | XIMA=(XIMA-minAX)/DXinit+1;% image index along x
|
---|
| 1980 | YIMA=(-YIMA+maxAY)/DYinit+1;% image index along y
|
---|
| 1981 | XIMA=reshape(round(XIMA),1,npX*npY);%indices reorganized in 'line'
|
---|
| 1982 | YIMA=reshape(round(YIMA),1,npX*npY);
|
---|
[109] | 1983 | flagin=XIMA>=1 & XIMA<=DimValue(2) & YIMA >=1 & YIMA<=DimValue(1);%flagin=1 inside the original image
|
---|
[77] | 1984 | if isequal(ObjectData.ProjMode,'filter')
|
---|
| 1985 | npx_filter=ceil(abs(DX/DAX));
|
---|
| 1986 | npy_filter=ceil(abs(DY/DAY));
|
---|
| 1987 | Mfilter=ones(npy_filter,npx_filter)/(npx_filter*npy_filter);
|
---|
| 1988 | test_filter=1;
|
---|
| 1989 | else
|
---|
| 1990 | test_filter=0;
|
---|
| 1991 | end
|
---|
| 1992 | for ivar=VarIndex
|
---|
| 1993 | VarName=FieldData.ListVarName{ivar} ;
|
---|
| 1994 | if test_interp(1) | test_interp(2)%interpolate on a regular grid
|
---|
| 1995 | eval(['FieldData.' VarName '=interp2(Coord{2},Coord{1},FieldData.' VarName ',Coord_x,Coord_y'');']) %TO TEST
|
---|
| 1996 | end
|
---|
| 1997 | %filter the field (image) if option 'filter' is used
|
---|
| 1998 | if test_filter
|
---|
| 1999 | Aclass=class(FieldData.A);
|
---|
| 2000 | eval(['FieldData.' VarName '=filter2(Mfilter,FieldData.' VarName ',''valid'');'])
|
---|
| 2001 | if ~isequal(Aclass,'double')
|
---|
| 2002 | eval(['FieldData.' VarName '=' Aclass '(FieldData.' VarName ');'])%revert to integer values
|
---|
| 2003 | end
|
---|
| 2004 | end
|
---|
[109] | 2005 | eval(['vec_A=reshape(FieldData.' VarName ',[],nbcolor);'])%put the original image in line
|
---|
[77] | 2006 | ind_in=find(flagin);
|
---|
| 2007 | ind_out=find(~flagin);
|
---|
[109] | 2008 | ICOMB=(XIMA-1)*DimValue(1)+YIMA;
|
---|
[77] | 2009 | ICOMB=ICOMB(flagin);%index corresponding to XIMA and YIMA in the aligned original image vec_A
|
---|
| 2010 | vec_B(ind_in,[1:nbcolor])=vec_A(ICOMB,:);
|
---|
| 2011 | for icolor=1:nbcolor
|
---|
| 2012 | vec_B(ind_out,icolor)=zeros(size(ind_out));
|
---|
| 2013 | end
|
---|
| 2014 | ProjData.ListVarName=[ProjData.ListVarName VarName];
|
---|
| 2015 | if length(FieldData.VarAttribute)>=ivar
|
---|
| 2016 | ProjData.VarAttribute{length(ProjData.ListVarName)+nbcoord}=FieldData.VarAttribute{ivar};
|
---|
| 2017 | end
|
---|
[8] | 2018 | eval(['ProjData.' VarName '=reshape(vec_B,npY,npX,nbcolor);']);
|
---|
| 2019 | end
|
---|
| 2020 | ProjData.FF=reshape(~flagin,npY,npX);%false flag A FAIRE: tenir compte d'un flga antérieur
|
---|
| 2021 | ProjData.ListVarName=[ProjData.ListVarName 'FF'];
|
---|
| 2022 | ProjData.VarAttribute{length(ProjData.ListVarName)}.Role='errorflag';
|
---|
| 2023 | else %3D case
|
---|
| 2024 | if isequal(Theta,0) & isequal(Phi,0)
|
---|
| 2025 | test_sup=(Coord{1}>=ObjectData.Coord(1,3));
|
---|
| 2026 | iz_sup=find(test_sup);
|
---|
| 2027 | iz=iz_sup(1);
|
---|
| 2028 | if iz>=1 & iz<=npz
|
---|
[109] | 2029 | %ProjData.ListDimName=[ProjData.ListDimName ListDimName(2:end)];
|
---|
| 2030 | %ProjData.DimValue=[ProjData.DimValue npY npX];
|
---|
[8] | 2031 | for ivar=VarIndex
|
---|
| 2032 | VarName=FieldData.ListVarName{ivar};
|
---|
| 2033 | ProjData.ListVarName=[ProjData.ListVarName VarName];
|
---|
[77] | 2034 | ProjData.VarAttribute{length(ProjData.ListVarName)}=FieldData.VarAttribute{ivar}; %reproduce the variable attributes
|
---|
[8] | 2035 | eval(['ProjData.' VarName '=squeeze(FieldData.' VarName '(iz,:,:));'])% select the z index iz
|
---|
| 2036 | %TODO : do a vertical average for a thick plane
|
---|
| 2037 | if test_interp(2) | test_interp(3)
|
---|
| 2038 | eval(['ProjData.' VarName '=interp2(Coord{3},Coord{2},ProjData.' VarName ',Coord_x,Coord_y'');'])
|
---|
| 2039 | end
|
---|
| 2040 | end
|
---|
| 2041 | end
|
---|
| 2042 | else
|
---|
| 2043 | errormsg='projection of structured coordinates on oblique plane not yet implemented';
|
---|
| 2044 | %TODO: use interp3
|
---|
| 2045 | return
|
---|
| 2046 | end
|
---|
| 2047 | end
|
---|
| 2048 | end
|
---|
| 2049 | end
|
---|
| 2050 | %projection of velocity components in the rotated coordinates
|
---|
[46] | 2051 | if ~isequal(Phi,0) && length(ivar_U)==1
|
---|
[8] | 2052 | if isempty(ivar_V)
|
---|
[38] | 2053 | msgbox_uvmat('ERROR','v velocity component missing in proj_field.m')
|
---|
[8] | 2054 | return
|
---|
| 2055 | end
|
---|
| 2056 | UName=FieldData.ListVarName{ivar_U};
|
---|
| 2057 | VName=FieldData.ListVarName{ivar_V};
|
---|
| 2058 | eval(['ProjData.' UName '=cos(Phi)*ProjData.' UName '+ sin(Phi)*ProjData.' VName ';'])
|
---|
| 2059 | eval(['ProjData.' VName '=cos(Theta)*(-sin(Phi)*ProjData.' UName '+ cos(Phi)*ProjData.' VName ');'])
|
---|
| 2060 | if ~isempty(ivar_W)
|
---|
| 2061 | WName=FieldData.ListVarName{ivar_W};
|
---|
| 2062 | eval(['ProjData.' VName '=ProjData.' VName '+ ProjData.' WName '*sin(Theta);'])%
|
---|
| 2063 | eval(['ProjData.' WName '=NormVec_X*ProjData.' UName '+ NormVec_Y*ProjData.' VName '+ NormVec_Z* ProjData.' WName ';']);
|
---|
| 2064 | end
|
---|
| 2065 | if ~isequal(Psi,0)
|
---|
| 2066 | eval(['ProjData.' UName '=cos(Psi)* ProjData.' UName '- sin(Psi)*ProjData.' VName ';']);
|
---|
| 2067 | eval(['ProjData.' VName '=sin(Psi)* ProjData.' UName '+ cos(Psi)*ProjData.' VName ';']);
|
---|
| 2068 | end
|
---|
| 2069 | end
|
---|
| 2070 | end
|
---|
| 2071 |
|
---|
| 2072 | %-----------------------------------------------------------------
|
---|
| 2073 | %transmit the global attributes
|
---|
| 2074 | function [ProjData,errormsg]=proj_heading(FieldData,ObjectData)
|
---|
| 2075 | %-----------------------------------------------------------------
|
---|
| 2076 | % ProjData=FieldData;
|
---|
| 2077 | ProjData=[];%default
|
---|
[150] | 2078 | errormsg=[];%default
|
---|
[8] | 2079 | if ~isfield(FieldData,'ListGlobalAttribute')
|
---|
| 2080 | ProjData.ListGlobalAttribute={};
|
---|
| 2081 | else
|
---|
| 2082 | ProjData.ListGlobalAttribute=FieldData.ListGlobalAttribute;
|
---|
| 2083 | end
|
---|
| 2084 | if isfield(FieldData,'Txt')
|
---|
| 2085 | errormsg=FieldData.Txt; %transmit erreur message
|
---|
| 2086 | return;
|
---|
| 2087 | end
|
---|
| 2088 | for iattr=1:length(ProjData.ListGlobalAttribute)
|
---|
| 2089 | AttrName=ProjData.ListGlobalAttribute{iattr};
|
---|
| 2090 | if isfield(FieldData,AttrName)
|
---|
| 2091 | eval(['ProjData.' AttrName '=FieldData.' AttrName ';']);
|
---|
| 2092 | end
|
---|
| 2093 | end
|
---|
[158] | 2094 | if isfield(FieldData,'CoordUnit')
|
---|
| 2095 | if isfield(ObjectData,'CoordUnit')&~isequal(FieldData.CoordUnit,ObjectData.CoordUnit)
|
---|
| 2096 | errormsg=[ObjectData.Style ' in ' ObjectData.CoordUnit ' coordinates, while field in ' FieldData.CoordUnit ];
|
---|
[8] | 2097 | return
|
---|
| 2098 | else
|
---|
[158] | 2099 | ProjData.CoordUnit=FieldData.CoordUnit;
|
---|
[8] | 2100 | end
|
---|
| 2101 | end
|
---|
| 2102 |
|
---|
| 2103 | ListObject={'Style','ProjMode','RangeX','RangeY','RangeZ','Phi','Theta','Psi','Coord'};
|
---|
| 2104 | for ilist=1:length(ListObject)
|
---|
| 2105 | if isfield(ObjectData,ListObject{ilist})
|
---|
| 2106 | eval(['val=ObjectData.' ListObject{ilist} ';'])
|
---|
| 2107 | if ~isempty(val)
|
---|
| 2108 | eval(['ProjData.Object' ListObject{ilist} '=val;']);
|
---|
| 2109 | ProjData.ListGlobalAttribute=[ProjData.ListGlobalAttribute {['Object' ListObject{ilist}]}];
|
---|
| 2110 | end
|
---|
| 2111 | end
|
---|
| 2112 | end
|
---|