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