1 | %'proj_field': projects the field on a projection object
|
---|
2 | %--------------------------------------------------------------------------
|
---|
3 | % function [ProjData,errormsg]=proj_field(FieldData,ObjectData)
|
---|
4 | %
|
---|
5 | % OUTPUT:
|
---|
6 | % ProjData structure containing the fields of the input field FieldData,
|
---|
7 | % transmitted or projected on the object, plus the additional fields
|
---|
8 | % .UMax, .UMin, .VMax, .VMin: min and max of velocity components in a domain
|
---|
9 | % .UMean,VMean: mean of the velocity components in a domain
|
---|
10 | % .AMin, AMax: min and max of a scalar
|
---|
11 | % .AMean: mean of a scalar in a domain
|
---|
12 | % .NbPix;
|
---|
13 | % .DimName= names of the matrix dimensions (matlab cell)
|
---|
14 | % .VarName= names of the variables [ProjData.VarName {'A','AMean','AMin','AMax'}];
|
---|
15 | % .VarDimNameIndex= dimensions of the variables, indicated by indices in the list .DimName;
|
---|
16 | %
|
---|
17 | %INPUT
|
---|
18 | % ObjectData: structure characterizing the projection object
|
---|
19 | % .Type : type of projection object
|
---|
20 | % .ProjMode=mode of projection ;
|
---|
21 | % .CoordUnit: 'px', 'cm' units for the coordinates defining the object
|
---|
22 | % .Angle ( angles of rotation (=[0 0 0] by default)
|
---|
23 | % .ProjAngle=angle of projection;
|
---|
24 | % .DX,.DY,.DZ=increments along each coordinate
|
---|
25 | % .Coord(nbpoints,3): set of coordinates defining the object position;
|
---|
26 |
|
---|
27 | %FieldData: data of the field to be projected on the projection object, with optional fields
|
---|
28 | % .Txt: error message, transmitted to the projection
|
---|
29 | % .FieldList: cell array of strings representing the fields to calculate
|
---|
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 |
|
---|
82 | function [ProjData,errormsg]=proj_field(FieldData,ObjectData)
|
---|
83 | errormsg='';%default
|
---|
84 | ProjData=[];
|
---|
85 |
|
---|
86 | %% case of no projection (object is used only as graph display)
|
---|
87 | if isfield(ObjectData,'ProjMode') && (isequal(ObjectData.ProjMode,'none')||isequal(ObjectData.ProjMode,'mask_inside')||isequal(ObjectData.ProjMode,'mask_outside'))
|
---|
88 | return
|
---|
89 | end
|
---|
90 |
|
---|
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 |
|
---|
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')
|
---|
99 | ProjData=FieldData;
|
---|
100 | return
|
---|
101 | end
|
---|
102 | if ~isfield(ObjectData,'Coord')
|
---|
103 | if strcmp(ObjectData.Type,'plane')
|
---|
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 |
|
---|
132 | %% apply projection depending on the object type
|
---|
133 | switch ObjectData.Type
|
---|
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'
|
---|
145 | [ProjData,errormsg] = proj_plane(FieldData,ObjectData);
|
---|
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;
|
---|
180 | [CellVarIndex,NbDimCell,VarTypeCell,errormsg]=find_field_indices(FieldData);
|
---|
181 | if ~isempty(errormsg)
|
---|
182 | errormsg=['error in proj_field/proj_points:' errormsg];
|
---|
183 | return
|
---|
184 | end
|
---|
185 | %LOOP ON GROUPS OF VARIABLES SHARING THE SAME DIMENSIONS
|
---|
186 | for icell=1:length(CellVarIndex)
|
---|
187 | if NbDimCell(icell)==1
|
---|
188 | continue
|
---|
189 | end
|
---|
190 | VarIndex=CellVarIndex{icell};% indices of the selected variables in the list FieldData.ListVarName
|
---|
191 | VarType=VarTypeCell{icell};% structure defining the types of variables in the cell
|
---|
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)
|
---|
201 | test_grid=1;%test for input data on regular grid (e.g. image)coordinates
|
---|
202 | else
|
---|
203 | if length(ivar_X)>1 || length(ivar_Y)>1 || length(ivar_Z)>1
|
---|
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};
|
---|
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)
|
---|
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
|
---|
231 | if length(ivar_F)>1 || length(ivar_FF)>1
|
---|
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};
|
---|
245 | FF=FieldData.(FFName)(indsel);
|
---|
246 | indsel=indsel(~FF);
|
---|
247 | end
|
---|
248 | ProjData.NbVal(ipoint,1)=length(indsel);
|
---|
249 | for ivar=VarIndex
|
---|
250 | VarName=FieldData.ListVarName{ivar};
|
---|
251 | if isempty(indsel)
|
---|
252 | ProjData.(VarName)(ipoint,1)=NaN;
|
---|
253 | else
|
---|
254 | Var=FieldData.(VarName)(indsel);
|
---|
255 | ProjData.(VarName)(ipoint,1)=mean(Var);
|
---|
256 | if isequal(ObjectData.ProjMode,'interp')
|
---|
257 | ProjData.(VarName)(ipoint,1)=griddata_uvmat(coord_x(indsel),coord_y(indsel),Var,Xpoint(1),Xpoint(2));
|
---|
258 | end
|
---|
259 | end
|
---|
260 | end
|
---|
261 | end
|
---|
262 | else %case of structured coordinates
|
---|
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
|
---|
268 | AName=FieldData.ListVarName{VarIndex(1)};% a single variable assumed in the current cell
|
---|
269 | eval(['A=FieldData.' AName ';']);% scalar
|
---|
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
|
---|
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);
|
---|
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
|
---|
292 | end
|
---|
293 | test_interp(idim)=(DCoord_max-DCoord_min(idim))> 0.0001*abs(DCoord_max);% test grid regularity
|
---|
294 | test_coord(idim)=1;
|
---|
295 | end
|
---|
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
|
---|
324 | Avalue=FieldData.(FieldData.ListVarName{ivar})(j_int,i_int,:);
|
---|
325 | ProjData.(FieldData.ListVarName{ivar})(ipoint,:)=mean(mean(Avalue));
|
---|
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)};
|
---|
426 | DimValue=size(FieldData.(VarName));
|
---|
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
|
---|
441 | % testcolor=find(numel(DimValue)==3);
|
---|
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)};
|
---|
456 | FieldData.(VarName)=reshape(FieldData.(VarName),npxy(1)*npxy(2),npxy(3)); % keep only non false vectors
|
---|
457 | end
|
---|
458 | end
|
---|
459 | %select the indices in the range of action
|
---|
460 | testin=[];%default
|
---|
461 | if isequal(ObjectData.Type,'rectangle')
|
---|
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
|
---|
475 | elseif isequal(ObjectData.Type,'polygon')
|
---|
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
|
---|
483 | elseif isequal(ObjectData.Type,'ellipse')
|
---|
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};
|
---|
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
|
---|
510 | if isequal(Mesh(ivar),0)
|
---|
511 | eval(['[ProjData.' VarName 'Histo,ProjData.' VarName ']=hist(double(FieldData.' VarName '(indsel,:,:)),100);']); % default histogram with 100 bins
|
---|
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
|
---|
518 | ProjData.VarDimName=[ProjData.VarDimName {VarName} {{VarName,'rgb'}} {'rgb'} {'rgb'} {'rgb'}];%{{'nb_point','rgb'}};
|
---|
519 | else
|
---|
520 | ProjData.VarDimName=[ProjData.VarDimName {VarName} {VarName} {'one'} {'one'} {'one'}];
|
---|
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;
|
---|
548 | % ProjAngle=90; %90 degrees projection by default
|
---|
549 | % if isfield(FieldData,'ProjAngle'),ProjAngle=ObjectData.ProjAngle; end;
|
---|
550 | width=0;%default width of the projection band
|
---|
551 | if isfield(ObjectData,'Range')&&size(ObjectData.Range,2)>=2
|
---|
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)
|
---|
703 | Xproj=linelength/(2*npoint):linelength/npoint:linelength-linelength/(2*npoint);
|
---|
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)
|
---|
713 | Xproj=linelength/(2*npoint):linelength/npoint:linelength-linelength/(2*npoint);
|
---|
714 | siz=size(X_sel);
|
---|
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);
|
---|
719 | Aij=exp(-lambda*((xij-xregij).*(xij-xregij)+(yij-yregij).*(yij-yregij)));
|
---|
720 | norm=Aij'*ones(siz(1),1);
|
---|
721 | for ivar=1:numel(ProjVar)
|
---|
722 | if ~isempty(ProjVar{ivar})
|
---|
723 | ProjVar{ivar}=Aij'*ProjVar{ivar}./norm;
|
---|
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;
|
---|
758 | if ~isequal(ObjectData.Type,'line')% exclude polyline
|
---|
759 | errormsg=['no projection available on ' ObjectData.Type 'for structured coordinates']; %
|
---|
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
|
---|
841 | VarName{ivar}=FieldData.ListVarName{ivar};
|
---|
842 | if test_interp2% interpolate on new grid
|
---|
843 | eval(['FieldData.' VarName{ivar} '=interp2(FieldData.' AXName ',FieldData.' AYName ',FieldData.' VarName{ivar} ',AXI,AYI'');']) %TO TEST
|
---|
844 | end
|
---|
845 | eval(['vec_A=reshape(squeeze(FieldData.' VarName{ivar} '),npx*npy,nbcolor);']) %put the original image in colum
|
---|
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);
|
---|
850 | eval(['ProjData.' VarName{ivar} '=((sum(A_out,1)/npY))'';']);
|
---|
851 | elseif nbcolor==3
|
---|
852 | vec_B(ind_in,1:3)=vec_A(ICOMB,:);
|
---|
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);
|
---|
857 | eval(['ProjData.' VarName{ivar} '=squeeze(sum(A_out,1)/npY);']);
|
---|
858 | end
|
---|
859 | ProjData.ListVarName=[ProjData.ListVarName VarName{ivar} ];
|
---|
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
|
---|
864 | eval(['vector_x =ProjData.' VarName{VarType.vector_x} ';'])
|
---|
865 | eval(['vector_y =ProjData.' VarName{VarType.vector_y} ';'])
|
---|
866 | eval(['ProjData.' VarName{VarType.vector_x} '=cos(theta)*vector_x+sin(theta)*vector_y;'])
|
---|
867 | eval(['ProjData.' VarName{VarType.vector_y} '=-sin(theta)*vector_x+cos(theta)*vector_y;'])
|
---|
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
|
---|
894 | function [ProjData,errormsg] = proj_plane(FieldData, ObjectData)
|
---|
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 |
|
---|
901 | %% axis origin
|
---|
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 |
|
---|
908 | %% rotation angles
|
---|
909 | PlaneAngle=[0 0 0];
|
---|
910 | norm_plane=[0 0 1];
|
---|
911 | cos_om=1;
|
---|
912 | sin_om=0;
|
---|
913 | test90x=0;%=1 for 90 degree rotation alround x axis
|
---|
914 | test90y=0;%=1 for 90 degree rotation alround y axis
|
---|
915 | if isfield(ObjectData,'Angle')&& isequal(size(ObjectData.Angle),[1 3])&& ~isequal(ObjectData.Angle,[0 0 0])
|
---|
916 | test90y=isequal(ObjectData.Angle,[0 90 0]);
|
---|
917 | PlaneAngle=(pi/180)*ObjectData.Angle;
|
---|
918 | om=norm(PlaneAngle);%norm of rotation angle in radians
|
---|
919 | OmAxis=PlaneAngle/om; %unit vector marking the rotation axis
|
---|
920 | cos_om=cos(om);
|
---|
921 | sin_om=sin(om);
|
---|
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;
|
---|
927 | end
|
---|
928 | testangle=~isequal(PlaneAngle,[0 0 0]);% && ~test90y && ~test90x;%=1 for slanted plane
|
---|
929 |
|
---|
930 | %% mesh sizes DX and DY
|
---|
931 | DX=0;
|
---|
932 | DY=0; %default
|
---|
933 | if isfield(ObjectData,'DX') && ~isempty(ObjectData.DX)
|
---|
934 | DX=abs(ObjectData.DX);%mesh of interpolation points
|
---|
935 | end
|
---|
936 | if isfield(ObjectData,'DY') && ~isempty(ObjectData.DY)
|
---|
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 |
|
---|
945 | %% extrema along each axis
|
---|
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 |
|
---|
967 | %% initiate Matlab structure for physical field
|
---|
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;
|
---|
986 |
|
---|
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
|
---|
996 | % icoord=0;
|
---|
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
|
---|
1002 | continue % only cells represnting 2D or 3D fields are involved
|
---|
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;
|
---|
1012 | % ivar_C=VarType.scalar ;
|
---|
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;
|
---|
1018 | check_unstructured_coord=(~isempty(ivar_X) && ~isempty(ivar_Y))||~isempty(VarType.coord_tps);
|
---|
1019 | DimCell=FieldData.VarDimName{VarIndex(1)};
|
---|
1020 | if ischar(DimCell)
|
---|
1021 | DimCell={DimCell};%name of dimensions
|
---|
1022 | end
|
---|
1023 |
|
---|
1024 | %% case of input fields with unstructured coordinates
|
---|
1025 | coord_z=0;%default
|
---|
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);
|
---|
1032 | if length(ivar_Z)==1
|
---|
1033 | ZName=FieldData.ListVarName{ivar_Z};
|
---|
1034 | coord_z=FieldData.(ZName);
|
---|
1035 | end
|
---|
1036 |
|
---|
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
|
---|
1054 | end
|
---|
1055 | coord_x=coord_x(indcut);
|
---|
1056 | coord_y=coord_y(indcut);
|
---|
1057 | coord_z=coord_z(indcut);
|
---|
1058 | end
|
---|
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));
|
---|
1071 | else
|
---|
1072 | coord_X=coord_x;
|
---|
1073 | coord_Y=coord_y;
|
---|
1074 | end
|
---|
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;
|
---|
1082 | end
|
---|
1083 | if testXMax
|
---|
1084 | testin=testin & (coord_X <= XMax);
|
---|
1085 | testbound=1;
|
---|
1086 | end
|
---|
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);
|
---|
1097 | if isempty(indcut)
|
---|
1098 | errormsg='data outside the bounds of the projection object';
|
---|
1099 | return
|
---|
1100 | end
|
---|
1101 | for ivar=VarIndex
|
---|
1102 | VarName=FieldData.ListVarName{ivar};
|
---|
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};
|
---|
1152 | indsel=find(FieldData.(VarName_FF)==0);
|
---|
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};
|
---|
1161 | if ~( ivar==ivar_X || ivar==ivar_Y || ivar==ivar_Z || ivar==ivar_F || ivar==ivar_FF || test_anc(ivar)==1)
|
---|
1162 | ivar_new=ivar_new+1;
|
---|
1163 | ProjData.ListVarName=[ProjData.ListVarName {VarName}];
|
---|
1164 | ProjData.VarDimName=[ProjData.VarDimName {DimCell}];
|
---|
1165 | if isfield(FieldData,'VarAttribute') && length(FieldData.VarAttribute) >=ivar
|
---|
1166 | ProjData.VarAttribute{ivar_new+nbcoord}=FieldData.VarAttribute{ivar};
|
---|
1167 | end
|
---|
1168 | if ~isequal(ivar_FF,0)
|
---|
1169 | FieldData.(VarName)=FieldData.(VarName)(indsel);
|
---|
1170 | end
|
---|
1171 | ProjData.(VarName)=griddata_uvmat(double(coord_X),double(coord_Y),double(FieldData.(VarName)),coord_x_proj,coord_y_proj');
|
---|
1172 | varline=reshape(ProjData.(VarName),1,length(coord_y_proj)*length(coord_x_proj));
|
---|
1173 | FFlag= isnan(varline); %detect undefined values NaN
|
---|
1174 | indnan=find(FFlag);
|
---|
1175 | if~isempty(indnan)
|
---|
1176 | varline(indnan)=zeros(size(indnan));
|
---|
1177 | ProjData.(VarName)=reshape(varline,length(coord_y_proj),length(coord_x_proj));
|
---|
1178 | FF(indnan)=ones(size(indnan));
|
---|
1179 | testFF=1;
|
---|
1180 | end
|
---|
1181 | if ivar==ivar_U
|
---|
1182 | ivar_U=ivar_new;
|
---|
1183 | end
|
---|
1184 | if ivar==ivar_V
|
---|
1185 | ivar_V=ivar_new;
|
---|
1186 | end
|
---|
1187 | if ivar==ivar_W
|
---|
1188 | ivar_W=ivar_new;
|
---|
1189 | end
|
---|
1190 | end
|
---|
1191 | end
|
---|
1192 | if testFF
|
---|
1193 | ProjData.FF=reshape(FF,length(coord_y_proj),length(coord_x_proj));
|
---|
1194 | ProjData.ListVarName=[ProjData.ListVarName {'FF'}];
|
---|
1195 | ProjData.VarDimName=[ProjData.VarDimName {DimCell}];
|
---|
1196 | ProjData.VarAttribute{ivar_new+1+nbcoord}.Role='errorflag';
|
---|
1197 | end
|
---|
1198 | case 'filter'
|
---|
1199 | if ~isempty(VarType.coord_tps)
|
---|
1200 | %Coord_tps=FieldData.ListVarName{VarType.coord_tps};
|
---|
1201 | %TODO: possibly translate and rotate coordiantes translate initial coordinates
|
---|
1202 | coord_x_proj=XMin:DX:XMax;
|
---|
1203 | coord_y_proj=YMin:DY:YMax;
|
---|
1204 | np_x=numel(coord_x_proj);
|
---|
1205 | np_y=numel(coord_y_proj);
|
---|
1206 | [XI,YI]=meshgrid(coord_x_proj,coord_y_proj');
|
---|
1207 | XI=reshape(XI,[],1)+ObjectData.Coord(1,1);
|
---|
1208 | YI=reshape(YI,[],1)+ObjectData.Coord(1,2);
|
---|
1209 | ProjData=calc_field(FieldData.FieldList,FieldData,[XI YI]);
|
---|
1210 | for ilist=3:length(ProjData.ListVarName)% reshape data, excluding coordinates (ilist=1-2), TODO: rationalise
|
---|
1211 | VarName=ProjData.ListVarName{ilist};
|
---|
1212 | ProjData.(VarName)=reshape(ProjData.(VarName),np_y,np_x);
|
---|
1213 | end
|
---|
1214 | ProjData.coord_x=[XMin XMax];
|
---|
1215 | ProjData.coord_y=[YMin YMax];
|
---|
1216 | end
|
---|
1217 | end
|
---|
1218 | %% case of input fields defined on a structured grid
|
---|
1219 | else
|
---|
1220 | VarName=FieldData.ListVarName{VarIndex(1)};%get the first variable of the cell to get the input matrix dimensions
|
---|
1221 | eval(['DimValue=size(FieldData.' VarName ');'])%input matrix dimensions
|
---|
1222 | DimValue(DimValue==1)=[];%remove singleton dimensions
|
---|
1223 | NbDim=numel(DimValue);%update number of space dimensions
|
---|
1224 | nbcolor=1; %default number of 'color' components: third matrix index without corresponding coordinate
|
---|
1225 | if NbDim>=3
|
---|
1226 | if NbDim>3
|
---|
1227 | errormsg='matrices with more than 3 dimensions not handled';
|
---|
1228 | return
|
---|
1229 | else
|
---|
1230 | if numel(find(VarType.coord))==2% the third matrix dimension does not correspond to a space coordinate
|
---|
1231 | nbcolor=DimValue(3);
|
---|
1232 | DimValue(3)=[]; %number of 'color' components updated
|
---|
1233 | NbDim=2;% space dimension set to 2
|
---|
1234 | end
|
---|
1235 | end
|
---|
1236 | end
|
---|
1237 | AYName=FieldData.ListVarName{VarType.coord(NbDim-1)};%name of input x coordinate (name preserved on projection)
|
---|
1238 | AXName=FieldData.ListVarName{VarType.coord(NbDim)};%name of input y coordinate (name preserved on projection)
|
---|
1239 | if testangle% TODO modify name also in case of origin shift in x or y
|
---|
1240 | AYProjName='Y';
|
---|
1241 | AXProjName='X';
|
---|
1242 | count=0;
|
---|
1243 | %modify coordinate names if they are already used
|
---|
1244 | while ~(isempty(find(strcmp('AXName',ProjData.ListVarName),1)) && isempty(find(strcmp('AYName',ProjData.ListVarName),1)))
|
---|
1245 | count=count+1;
|
---|
1246 | AYProjName=[AYProjName '_' num2str(count)];
|
---|
1247 | AXProjName=[AXProjName '_' num2str(count)];
|
---|
1248 | end
|
---|
1249 | else
|
---|
1250 | AYProjName=AYName;% (name preserved on projection)
|
---|
1251 | AXProjName=AXName;%name of input y coordinate (name preserved on projection)
|
---|
1252 | end
|
---|
1253 | ListDimName=FieldData.VarDimName{VarIndex(1)};
|
---|
1254 | ProjData.ListVarName=[ProjData.ListVarName {AYProjName} {AXProjName}]; %TODO: check if it already exists in Projdata (several cells)
|
---|
1255 | ProjData.VarDimName=[ProjData.VarDimName {AYProjName} {AXProjName}];
|
---|
1256 | Coord_z=[];
|
---|
1257 | Coord_y=[];
|
---|
1258 | Coord_x=[];
|
---|
1259 |
|
---|
1260 | for idim=1:NbDim %loop on space dimensions
|
---|
1261 | test_interp(idim)=0;%test for coordiate interpolation (non regular grid), =0 by default
|
---|
1262 | ivar=VarType.coord(idim);% index of the variable corresponding to the current dimension
|
---|
1263 | if ~isequal(ivar,0)% a variable corresponds to the dimension #idim
|
---|
1264 | eval(['Coord{idim}=FieldData.' FieldData.ListVarName{ivar} ';']) ;% coord values for the input field
|
---|
1265 | if numel(Coord{idim})==2 %input array defined on a regular grid
|
---|
1266 | DCoord_min(idim)=(Coord{idim}(2)-Coord{idim}(1))/DimValue(idim);
|
---|
1267 | else
|
---|
1268 | DCoord=diff(Coord{idim});%array of coordinate derivatives for the input field
|
---|
1269 | DCoord_min(idim)=min(DCoord);
|
---|
1270 | DCoord_max=max(DCoord);
|
---|
1271 | % test_direct(idim)=DCoord_max>0;% =1 for increasing values, 0 otherwise
|
---|
1272 | if abs(DCoord_max-DCoord_min(idim))>abs(DCoord_max/1000)
|
---|
1273 | msgbox_uvmat('ERROR',['non monotonic dimension variable # ' num2str(idim) ' in proj_field.m'])
|
---|
1274 | return
|
---|
1275 | end
|
---|
1276 | test_interp(idim)=(DCoord_max-DCoord_min(idim))> 0.0001*abs(DCoord_max);% test grid regularity
|
---|
1277 | end
|
---|
1278 | test_direct(idim)=(DCoord_min(idim)>0);
|
---|
1279 | else % no variable associated with the dimension #idim, the coordinate value is set equal to the matrix index by default
|
---|
1280 | Coord_i_str=['Coord_' num2str(idim)];
|
---|
1281 | DCoord_min(idim)=1;%default
|
---|
1282 | Coord{idim}=[0.5 DimValue(idim)-0.5];
|
---|
1283 | test_direct(idim)=1;
|
---|
1284 | end
|
---|
1285 | end
|
---|
1286 | if DY==0
|
---|
1287 | DY=abs(DCoord_min(NbDim-1));
|
---|
1288 | end
|
---|
1289 | npY=1+round(abs(Coord{NbDim-1}(end)-Coord{NbDim-1}(1))/DY);%nbre of points after interpol
|
---|
1290 | if DX==0
|
---|
1291 | DX=abs(DCoord_min(NbDim));
|
---|
1292 | end
|
---|
1293 | npX=1+round(abs(Coord{NbDim}(end)-Coord{NbDim}(1))/DX);%nbre of points after interpol
|
---|
1294 | for idim=1:NbDim
|
---|
1295 | if test_interp(idim)
|
---|
1296 | 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
|
---|
1297 | end
|
---|
1298 | end
|
---|
1299 | Coord_y=linspace(Coord{NbDim-1}(1),Coord{NbDim-1}(end),npY);
|
---|
1300 | test_direct_y=test_direct(NbDim-1);
|
---|
1301 | Coord_x=linspace(Coord{NbDim}(1),Coord{NbDim}(end),npX);
|
---|
1302 | test_direct_x=test_direct(NbDim);
|
---|
1303 | DAX=DCoord_min(NbDim);
|
---|
1304 | DAY=DCoord_min(NbDim-1);
|
---|
1305 | minAX=min(Coord_x);
|
---|
1306 | maxAX=max(Coord_x);
|
---|
1307 | minAY=min(Coord_y);
|
---|
1308 | maxAY=max(Coord_y);
|
---|
1309 | xcorner=[minAX maxAX minAX maxAX]-ObjectData.Coord(1,1);
|
---|
1310 | ycorner=[maxAY maxAY minAY minAY]-ObjectData.Coord(1,2);
|
---|
1311 | xcor_new=xcorner*cos_om+ycorner*sin_om;%coord new frame
|
---|
1312 | ycor_new=-xcorner*sin_om+ycorner*cos_om;
|
---|
1313 | if ~testXMax
|
---|
1314 | XMax=max(xcor_new);
|
---|
1315 | end
|
---|
1316 | if ~testXMin
|
---|
1317 | XMin=min(xcor_new);
|
---|
1318 | end
|
---|
1319 | if ~testYMax
|
---|
1320 | YMax=max(ycor_new);
|
---|
1321 | end
|
---|
1322 | if ~testYMin
|
---|
1323 | YMin=min(ycor_new);
|
---|
1324 | end
|
---|
1325 | DXinit=(maxAX-minAX)/(DimValue(NbDim)-1);
|
---|
1326 | DYinit=(maxAY-minAY)/(DimValue(NbDim-1)-1);
|
---|
1327 | if DX==0
|
---|
1328 | DX=DXinit;
|
---|
1329 | end
|
---|
1330 | if DY==0
|
---|
1331 | DY=DYinit;
|
---|
1332 | end
|
---|
1333 | if NbDim==3
|
---|
1334 | DZ=(Coord{1}(end)-Coord{1}(1))/(DimValue(1)-1);
|
---|
1335 | if ~test_direct(1)
|
---|
1336 | DZ=-DZ;
|
---|
1337 | end
|
---|
1338 | Coord_z=linspace(Coord{1}(1),Coord{1}(end),DimValue(1));
|
---|
1339 | test_direct_z=test_direct(1);
|
---|
1340 | end
|
---|
1341 | npX=floor((XMax-XMin)/DX+1);
|
---|
1342 | npY=floor((YMax-YMin)/DY+1);
|
---|
1343 | if test_direct_y
|
---|
1344 | coord_y_proj=linspace(YMin,YMax,npY);%abscissa of the new pixels along the line
|
---|
1345 | else
|
---|
1346 | coord_y_proj=linspace(YMax,YMin,npY);%abscissa of the new pixels along the line
|
---|
1347 | end
|
---|
1348 | if test_direct_x
|
---|
1349 | coord_x_proj=linspace(XMin,XMax,npX);%abscissa of the new pixels along the line
|
---|
1350 | else
|
---|
1351 | coord_x_proj=linspace(XMax,XMin,npX);%abscissa of the new pixels along the line
|
---|
1352 | end
|
---|
1353 | % case with no interpolation
|
---|
1354 | if isequal(ProjMode,'projection') && (~testangle || test90y || test90x)
|
---|
1355 | if NbDim==2 && ~testXMin && ~testXMax && ~testYMin && ~testYMax
|
---|
1356 | ProjData=FieldData;% no change by projection
|
---|
1357 | else
|
---|
1358 | indY=NbDim-1;
|
---|
1359 | if test_direct(indY)
|
---|
1360 | min_indy=ceil((YMin-Coord{indY}(1))/DYinit)+1;
|
---|
1361 | max_indy=floor((YMax-Coord{indY}(1))/DYinit)+1;
|
---|
1362 | Ybound(1)=Coord{indY}(1)+DYinit*(min_indy-1);
|
---|
1363 | Ybound(2)=Coord{indY}(1)+DYinit*(max_indy-1);
|
---|
1364 | else
|
---|
1365 | min_indy=ceil((Coord{indY}(1)-YMax)/DYinit)+1;
|
---|
1366 | max_indy=floor((Coord{indY}(1)-YMin)/DYinit)+1;
|
---|
1367 | Ybound(2)=Coord{indY}(1)-DYinit*(max_indy-1);
|
---|
1368 | Ybound(1)=Coord{indY}(1)-DYinit*(min_indy-1);
|
---|
1369 | end
|
---|
1370 | if test_direct(NbDim)==1
|
---|
1371 | min_indx=ceil((XMin-Coord{NbDim}(1))/DXinit)+1;
|
---|
1372 | max_indx=floor((XMax-Coord{NbDim}(1))/DXinit)+1;
|
---|
1373 | Xbound(1)=Coord{NbDim}(1)+DXinit*(min_indx-1);
|
---|
1374 | Xbound(2)=Coord{NbDim}(1)+DXinit*(max_indx-1);
|
---|
1375 | else
|
---|
1376 | min_indx=ceil((Coord{NbDim}(1)-XMax)/DXinit)+1;
|
---|
1377 | max_indx=floor((Coord{NbDim}(1)-XMin)/DXinit)+1;
|
---|
1378 | Xbound(2)=Coord{NbDim}(1)+DXinit*(max_indx-1);
|
---|
1379 | Xbound(1)=Coord{NbDim}(1)+DXinit*(min_indx-1);
|
---|
1380 | end
|
---|
1381 | min_indy=max(min_indy,1);% deals with margin (bound lower than the first index)
|
---|
1382 | min_indx=max(min_indx,1);
|
---|
1383 |
|
---|
1384 | if test90y
|
---|
1385 | ind_new=[3 2 1];
|
---|
1386 | DimCell={AYProjName,AXProjName};
|
---|
1387 | % DimValue=DimValue(ind_new);
|
---|
1388 | iz=ceil((ObjectData.Coord(1,1)-Coord{3}(1))/DX)+1;
|
---|
1389 | for ivar=VarIndex
|
---|
1390 | VarName=FieldData.ListVarName{ivar};
|
---|
1391 | ProjData.ListVarName=[ProjData.ListVarName VarName];
|
---|
1392 | ProjData.VarDimName=[ProjData.VarDimName {DimCell}];
|
---|
1393 | ProjData.VarAttribute{length(ProjData.ListVarName)}=FieldData.VarAttribute{ivar}; %reproduce the variable attributes
|
---|
1394 | eval(['ProjData.' VarName '=permute(FieldData.' VarName ',ind_new);'])% permute x and z indices for 90 degree rotation
|
---|
1395 | eval(['ProjData.' VarName '=squeeze(ProjData.' VarName '(iz,:,:));'])% select the z index iz
|
---|
1396 | end
|
---|
1397 | eval(['ProjData.' AYProjName '=[Ybound(1) Ybound(2)];']) %record the new (projected ) y coordinates
|
---|
1398 | eval(['ProjData.' AXProjName '=[Coord{1}(end),Coord{1}(1)];']) %record the new (projected ) x coordinates
|
---|
1399 | else
|
---|
1400 | if NbDim==3
|
---|
1401 | DimCell(1)=[]; %suppress z variable
|
---|
1402 | DimValue(1)=[];
|
---|
1403 | if test_direct(1)
|
---|
1404 | iz=ceil((ObjectData.Coord(1,3)-Coord{1}(1))/DZ)+1;
|
---|
1405 | else
|
---|
1406 | iz=ceil((Coord{1}(1)-ObjectData.Coord(1,3))/DZ)+1;
|
---|
1407 | end
|
---|
1408 | end
|
---|
1409 | max_indy=min(max_indy,DimValue(1));%introduce bounds in y and x indices
|
---|
1410 | max_indx=min(max_indx,DimValue(2));
|
---|
1411 | for ivar=VarIndex% loop on non coordinate variables
|
---|
1412 | VarName=FieldData.ListVarName{ivar};
|
---|
1413 | ProjData.ListVarName=[ProjData.ListVarName VarName];
|
---|
1414 | ProjData.VarDimName=[ProjData.VarDimName {DimCell}];
|
---|
1415 | if isfield(FieldData,'VarAttribute') && length(FieldData.VarAttribute)>=ivar
|
---|
1416 | ProjData.VarAttribute{length(ProjData.ListVarName)}=FieldData.VarAttribute{ivar};
|
---|
1417 | end
|
---|
1418 | if NbDim==3
|
---|
1419 | eval(['ProjData.' VarName '=squeeze(FieldData.' VarName '(iz,min_indy:max_indy,min_indx:max_indx));']);
|
---|
1420 | else
|
---|
1421 | eval(['ProjData.' VarName '=FieldData.' VarName '(min_indy:max_indy,min_indx:max_indx,:);']);
|
---|
1422 | end
|
---|
1423 | end
|
---|
1424 | eval(['ProjData.' AYProjName '=[Ybound(1) Ybound(2)];']) %record the new (projected ) y coordinates
|
---|
1425 | eval(['ProjData.' AXProjName '=[Xbound(1) Xbound(2)];']) %record the new (projected ) x coordinates
|
---|
1426 | end
|
---|
1427 | end
|
---|
1428 | else % case with rotation and/or interpolation
|
---|
1429 | if NbDim==2 %2D case
|
---|
1430 | [X,Y]=meshgrid(coord_x_proj,coord_y_proj);%grid in the new coordinates
|
---|
1431 | XIMA=ObjectData.Coord(1,1)+(X)*cos(PlaneAngle(3))-Y*sin(PlaneAngle(3));%corresponding coordinates in the original image
|
---|
1432 | YIMA=ObjectData.Coord(1,2)+(X)*sin(PlaneAngle(3))+Y*cos(PlaneAngle(3));
|
---|
1433 | XIMA=(XIMA-minAX)/DXinit+1;% image index along x
|
---|
1434 | YIMA=(-YIMA+maxAY)/DYinit+1;% image index along y
|
---|
1435 | XIMA=reshape(round(XIMA),1,npX*npY);%indices reorganized in 'line'
|
---|
1436 | YIMA=reshape(round(YIMA),1,npX*npY);
|
---|
1437 | flagin=XIMA>=1 & XIMA<=DimValue(2) & YIMA >=1 & YIMA<=DimValue(1);%flagin=1 inside the original image
|
---|
1438 | if isequal(ObjectData.ProjMode,'filter')
|
---|
1439 | npx_filter=ceil(abs(DX/DAX));
|
---|
1440 | npy_filter=ceil(abs(DY/DAY));
|
---|
1441 | Mfilter=ones(npy_filter,npx_filter)/(npx_filter*npy_filter);
|
---|
1442 | test_filter=1;
|
---|
1443 | else
|
---|
1444 | test_filter=0;
|
---|
1445 | end
|
---|
1446 | eval(['ProjData.' AYName '=[coord_y_proj(1) coord_y_proj(end)];']) %record the new (projected ) y coordinates
|
---|
1447 | eval(['ProjData.' AXName '=[coord_x_proj(1) coord_x_proj(end)];']) %record the new (projected ) x coordinates
|
---|
1448 | for ivar=VarIndex
|
---|
1449 | VarName=FieldData.ListVarName{ivar};
|
---|
1450 | if test_interp(1) || test_interp(2)%interpolate on a regular grid
|
---|
1451 | eval(['ProjData.' VarName '=interp2(Coord{2},Coord{1},FieldData.' VarName ',Coord_x,Coord_y'');']) %TO TEST
|
---|
1452 | end
|
---|
1453 | %filter the field (image) if option 'filter' is used
|
---|
1454 | if test_filter
|
---|
1455 | Aclass=class(FieldData.A);
|
---|
1456 | eval(['ProjData.' VarName '=filter2(Mfilter,FieldData.' VarName ',''valid'');'])
|
---|
1457 | if ~isequal(Aclass,'double')
|
---|
1458 | eval(['ProjData.' VarName '=' Aclass '(FieldData.' VarName ');'])%revert to integer values
|
---|
1459 | end
|
---|
1460 | end
|
---|
1461 | eval(['vec_A=reshape(FieldData.' VarName ',[],nbcolor);'])%put the original image in line
|
---|
1462 | %ind_in=find(flagin);
|
---|
1463 | ind_out=find(~flagin);
|
---|
1464 | ICOMB=(XIMA-1)*DimValue(1)+YIMA;
|
---|
1465 | ICOMB=ICOMB(flagin);%index corresponding to XIMA and YIMA in the aligned original image vec_A
|
---|
1466 | vec_B(flagin,1:nbcolor)=vec_A(ICOMB,:);
|
---|
1467 | for icolor=1:nbcolor
|
---|
1468 | vec_B(ind_out,icolor)=zeros(size(ind_out));
|
---|
1469 | end
|
---|
1470 | ProjData.ListVarName=[ProjData.ListVarName VarName];
|
---|
1471 | ProjData.VarDimName=[ProjData.VarDimName {DimCell}];
|
---|
1472 | if isfield(FieldData,'VarAttribute')&&length(FieldData.VarAttribute)>=ivar
|
---|
1473 | ProjData.VarAttribute{length(ProjData.ListVarName)+nbcoord}=FieldData.VarAttribute{ivar};
|
---|
1474 | end
|
---|
1475 | eval(['ProjData.' VarName '=reshape(vec_B,npY,npX,nbcolor);']);
|
---|
1476 | end
|
---|
1477 | ProjData.FF=reshape(~flagin,npY,npX);%false flag A FAIRE: tenir compte d'un flga antérieur
|
---|
1478 | ProjData.ListVarName=[ProjData.ListVarName 'FF'];
|
---|
1479 | ProjData.VarDimName=[ProjData.VarDimName {DimCell}];
|
---|
1480 | ProjData.VarAttribute{length(ProjData.ListVarName)}.Role='errorflag';
|
---|
1481 | elseif ~testangle
|
---|
1482 | % unstructured z coordinate
|
---|
1483 | test_sup=(Coord{1}>=ObjectData.Coord(1,3));
|
---|
1484 | iz_sup=find(test_sup);
|
---|
1485 | iz=iz_sup(1);
|
---|
1486 | if iz>=1 & iz<=npz
|
---|
1487 | %ProjData.ListDimName=[ProjData.ListDimName ListDimName(2:end)];
|
---|
1488 | %ProjData.DimValue=[ProjData.DimValue npY npX];
|
---|
1489 | for ivar=VarIndex
|
---|
1490 | VarName=FieldData.ListVarName{ivar};
|
---|
1491 | ProjData.ListVarName=[ProjData.ListVarName VarName];
|
---|
1492 | ProjData.VarAttribute{length(ProjData.ListVarName)}=FieldData.VarAttribute{ivar}; %reproduce the variable attributes
|
---|
1493 | eval(['ProjData.' VarName '=squeeze(FieldData.' VarName '(iz,:,:));'])% select the z index iz
|
---|
1494 | %TODO : do a vertical average for a thick plane
|
---|
1495 | if test_interp(2) || test_interp(3)
|
---|
1496 | eval(['ProjData.' VarName '=interp2(Coord{3},Coord{2},ProjData.' VarName ',Coord_x,Coord_y'');'])
|
---|
1497 | end
|
---|
1498 | end
|
---|
1499 | end
|
---|
1500 | else
|
---|
1501 | errormsg='projection of structured coordinates on oblique plane not yet implemented';
|
---|
1502 | %TODO: use interp3
|
---|
1503 | return
|
---|
1504 | end
|
---|
1505 | end
|
---|
1506 | end
|
---|
1507 |
|
---|
1508 | %% projection of velocity components in the rotated coordinates
|
---|
1509 | if testangle && length(ivar_U)==1
|
---|
1510 | if isempty(ivar_V)
|
---|
1511 | msgbox_uvmat('ERROR','v velocity component missing in proj_field.m')
|
---|
1512 | return
|
---|
1513 | end
|
---|
1514 | UName=FieldData.ListVarName{ivar_U};
|
---|
1515 | VName=FieldData.ListVarName{ivar_V};
|
---|
1516 | eval(['ProjData.' UName '=cos(PlaneAngle(3))*ProjData.' UName '+ sin(PlaneAngle(3))*ProjData.' VName ';'])
|
---|
1517 | eval(['ProjData.' VName '=cos(Theta)*(-sin(PlaneAngle(3))*ProjData.' UName '+ cos(PlaneAngle(3))*ProjData.' VName ');'])
|
---|
1518 | if ~isempty(ivar_W)
|
---|
1519 | WName=FieldData.ListVarName{ivar_W};
|
---|
1520 | eval(['ProjData.' VName '=ProjData.' VName '+ ProjData.' WName '*sin(Theta);'])%
|
---|
1521 | eval(['ProjData.' WName '=NormVec_X*ProjData.' UName '+ NormVec_Y*ProjData.' VName '+ NormVec_Z* ProjData.' WName ';']);
|
---|
1522 | end
|
---|
1523 | if ~isequal(Psi,0)
|
---|
1524 | eval(['ProjData.' UName '=cos(Psi)* ProjData.' UName '- sin(Psi)*ProjData.' VName ';']);
|
---|
1525 | eval(['ProjData.' VName '=sin(Psi)* ProjData.' UName '+ cos(Psi)*ProjData.' VName ';']);
|
---|
1526 | end
|
---|
1527 | end
|
---|
1528 | end
|
---|
1529 |
|
---|
1530 | %-----------------------------------------------------------------
|
---|
1531 | %projection in a volume
|
---|
1532 | function [ProjData,errormsg] = proj_volume(FieldData, ObjectData)
|
---|
1533 | %-----------------------------------------------------------------
|
---|
1534 | ProjData=FieldData;%default output
|
---|
1535 |
|
---|
1536 | %% initialisation of the input parameters of the projection plane
|
---|
1537 | ProjMode='projection';%direct projection by default
|
---|
1538 | if isfield(ObjectData,'ProjMode'),ProjMode=ObjectData.ProjMode; end;
|
---|
1539 |
|
---|
1540 | %% axis origin
|
---|
1541 | if isempty(ObjectData.Coord)
|
---|
1542 | ObjectData.Coord(1,1)=0;%origin of the plane set to [0 0] by default
|
---|
1543 | ObjectData.Coord(1,2)=0;
|
---|
1544 | ObjectData.Coord(1,3)=0;
|
---|
1545 | end
|
---|
1546 |
|
---|
1547 | %% rotation angles
|
---|
1548 | VolumeAngle=[0 0 0];
|
---|
1549 | norm_plane=[0 0 1];
|
---|
1550 | if isfield(ObjectData,'Angle')&& isequal(size(ObjectData.Angle),[1 3])&& ~isequal(ObjectData.Angle,[0 0 0])
|
---|
1551 | PlaneAngle=ObjectData.Angle;
|
---|
1552 | VolumeAngle=ObjectData.Angle;
|
---|
1553 | om=norm(VolumeAngle);%norm of rotation angle in radians
|
---|
1554 | OmAxis=VolumeAngle/om; %unit vector marking the rotation axis
|
---|
1555 | cos_om=cos(pi*om/180);
|
---|
1556 | sin_om=sin(pi*om/180);
|
---|
1557 | coeff=OmAxis(3)*(1-cos_om);
|
---|
1558 | %components of the unity vector norm_plane normal to the projection plane
|
---|
1559 | norm_plane(1)=OmAxis(1)*coeff+OmAxis(2)*sin_om;
|
---|
1560 | norm_plane(2)=OmAxis(2)*coeff-OmAxis(1)*sin_om;
|
---|
1561 | norm_plane(3)=OmAxis(3)*coeff+cos_om;
|
---|
1562 | end
|
---|
1563 | testangle=~isequal(VolumeAngle,[0 0 0]);
|
---|
1564 |
|
---|
1565 | %% mesh sizes DX, DY, DZ
|
---|
1566 | DX=0;
|
---|
1567 | DY=0; %default
|
---|
1568 | DZ=0;
|
---|
1569 | if isfield(ObjectData,'DX')&~isempty(ObjectData.DX)
|
---|
1570 | DX=abs(ObjectData.DX);%mesh of interpolation points
|
---|
1571 | end
|
---|
1572 | if isfield(ObjectData,'DY')&~isempty(ObjectData.DY)
|
---|
1573 | DY=abs(ObjectData.DY);%mesh of interpolation points
|
---|
1574 | end
|
---|
1575 | if isfield(ObjectData,'DZ')&~isempty(ObjectData.DZ)
|
---|
1576 | DZ=abs(ObjectData.DZ);%mesh of interpolation points
|
---|
1577 | end
|
---|
1578 | if ~strcmp(ProjMode,'projection') && (DX==0||DY==0||DZ==0)
|
---|
1579 | errormsg='grid mesh DX , DY or DZ is missing';
|
---|
1580 | return
|
---|
1581 | end
|
---|
1582 |
|
---|
1583 | %% extrema along each axis
|
---|
1584 | testXMin=0;
|
---|
1585 | testXMax=0;
|
---|
1586 | testYMin=0;
|
---|
1587 | testYMax=0;
|
---|
1588 | if isfield(ObjectData,'RangeX')
|
---|
1589 | XMin=min(ObjectData.RangeX);
|
---|
1590 | XMax=max(ObjectData.RangeX);
|
---|
1591 | testXMin=XMax>XMin;
|
---|
1592 | testXMax=1;
|
---|
1593 | end
|
---|
1594 | if isfield(ObjectData,'RangeY')
|
---|
1595 | YMin=min(ObjectData.RangeY);
|
---|
1596 | YMax=max(ObjectData.RangeY);
|
---|
1597 | testYMin=YMax>YMin;
|
---|
1598 | testYMax=1;
|
---|
1599 | end
|
---|
1600 | width=0;%default width of the projection band
|
---|
1601 | if isfield(ObjectData,'RangeZ')
|
---|
1602 | ZMin=min(ObjectData.RangeZ);
|
---|
1603 | ZMax=max(ObjectData.RangeZ);
|
---|
1604 | testZMin=ZMax>ZMin;
|
---|
1605 | testZMax=1;
|
---|
1606 | end
|
---|
1607 |
|
---|
1608 | %% initiate Matlab structure for physical field
|
---|
1609 | [ProjData,errormsg]=proj_heading(FieldData,ObjectData);
|
---|
1610 | ProjData.NbDim=3;
|
---|
1611 | ProjData.ListVarName={};
|
---|
1612 | ProjData.VarDimName={};
|
---|
1613 | if ~isequal(DX,0)&& ~isequal(DY,0)
|
---|
1614 | ProjData.Mesh=sqrt(DX*DY);%define typical data mesh, useful for mouse selection in plots
|
---|
1615 | elseif isfield(FieldData,'Mesh')
|
---|
1616 | ProjData.Mesh=FieldData.Mesh;
|
---|
1617 | end
|
---|
1618 |
|
---|
1619 | error=0;%default
|
---|
1620 | flux=0;
|
---|
1621 | testfalse=0;
|
---|
1622 | ListIndex={};
|
---|
1623 |
|
---|
1624 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
---|
1625 | %% group the variables (fields of 'FieldData') in cells of variables with the same dimensions
|
---|
1626 | %-----------------------------------------------------------------
|
---|
1627 | idimvar=0;
|
---|
1628 | [CellVarIndex,NbDimVec,VarTypeCell,errormsg]=find_field_indices(FieldData);
|
---|
1629 | if ~isempty(errormsg)
|
---|
1630 | errormsg=['error in proj_field/proj_plane:' errormsg];
|
---|
1631 | return
|
---|
1632 | end
|
---|
1633 |
|
---|
1634 | % LOOP ON GROUPS OF VARIABLES SHARING THE SAME DIMENSIONS
|
---|
1635 | % CellVarIndex=cells of variable index arrays
|
---|
1636 | ivar_new=0; % index of the current variable in the projected field
|
---|
1637 | icoord=0;
|
---|
1638 | nbcoord=0;%number of added coordinate variables brought by projection
|
---|
1639 | nbvar=0;
|
---|
1640 | for icell=1:length(CellVarIndex)
|
---|
1641 | NbDim=NbDimVec(icell);
|
---|
1642 | if NbDim<3
|
---|
1643 | continue
|
---|
1644 | end
|
---|
1645 | VarIndex=CellVarIndex{icell};% indices of the selected variables in the list FieldData.ListVarName
|
---|
1646 | VarType=VarTypeCell{icell};
|
---|
1647 | ivar_X=VarType.coord_x;
|
---|
1648 | ivar_Y=VarType.coord_y;
|
---|
1649 | ivar_Z=VarType.coord_z;
|
---|
1650 | ivar_U=VarType.vector_x;
|
---|
1651 | ivar_V=VarType.vector_y;
|
---|
1652 | ivar_W=VarType.vector_z;
|
---|
1653 | ivar_C=VarType.scalar ;
|
---|
1654 | ivar_Anc=VarType.ancillary;
|
---|
1655 | test_anc=zeros(size(VarIndex));
|
---|
1656 | test_anc(ivar_Anc)=ones(size(ivar_Anc));
|
---|
1657 | ivar_F=VarType.warnflag;
|
---|
1658 | ivar_FF=VarType.errorflag;
|
---|
1659 | check_unstructured_coord=~isempty(ivar_X) && ~isempty(ivar_Y);
|
---|
1660 | DimCell=FieldData.VarDimName{VarIndex(1)};
|
---|
1661 | if ischar(DimCell)
|
---|
1662 | DimCell={DimCell};%name of dimensions
|
---|
1663 | end
|
---|
1664 |
|
---|
1665 | %% case of input fields with unstructured coordinates
|
---|
1666 | if check_unstructured_coord
|
---|
1667 | XName=FieldData.ListVarName{ivar_X};
|
---|
1668 | YName=FieldData.ListVarName{ivar_Y};
|
---|
1669 | eval(['coord_x=FieldData.' XName ';'])
|
---|
1670 | eval(['coord_y=FieldData.' YName ';'])
|
---|
1671 | if length(ivar_Z)==1
|
---|
1672 | ZName=FieldData.ListVarName{ivar_Z};
|
---|
1673 | eval(['coord_z=FieldData.' ZName ';'])
|
---|
1674 | end
|
---|
1675 |
|
---|
1676 | % translate initial coordinates
|
---|
1677 | coord_x=coord_x-ObjectData.Coord(1,1);
|
---|
1678 | coord_y=coord_y-ObjectData.Coord(1,2);
|
---|
1679 | if ~isempty(ivar_Z)
|
---|
1680 | coord_z=coord_z-ObjectData.Coord(1,3);
|
---|
1681 | end
|
---|
1682 |
|
---|
1683 | % selection of the vectors in the projection range
|
---|
1684 | % if length(ivar_Z)==1 && width > 0
|
---|
1685 | % %components of the unitiy vector normal to the projection plane
|
---|
1686 | % fieldZ=NormVec_X*coord_x + NormVec_Y*coord_y+ NormVec_Z*coord_z;% distance to the plane
|
---|
1687 | % indcut=find(abs(fieldZ) <= width);
|
---|
1688 | % for ivar=VarIndex
|
---|
1689 | % VarName=FieldData.ListVarName{ivar};
|
---|
1690 | % eval(['FieldData.' VarName '=FieldData.' VarName '(indcut);'])
|
---|
1691 | % % A VOIR : CAS DE VAR STRUCTUREE MAIS PAS GRILLE REGULIERE : INTERPOLER SUR GRILLE REGULIERE
|
---|
1692 | % end
|
---|
1693 | % coord_x=coord_x(indcut);
|
---|
1694 | % coord_y=coord_y(indcut);
|
---|
1695 | % coord_z=coord_z(indcut);
|
---|
1696 | % end
|
---|
1697 |
|
---|
1698 | %rotate coordinates if needed: TODO modify
|
---|
1699 | if testangle
|
---|
1700 | coord_X=(coord_x *cos(Phi) + coord_y* sin(Phi));
|
---|
1701 | coord_Y=(-coord_x *sin(Phi) + coord_y *cos(Phi))*cos(Theta);
|
---|
1702 | if ~isempty(ivar_Z)
|
---|
1703 | coord_Y=coord_Y+coord_z *sin(Theta);
|
---|
1704 | end
|
---|
1705 |
|
---|
1706 | coord_X=(coord_X *cos(Psi) - coord_Y* sin(Psi));%A VERIFIER
|
---|
1707 | coord_Y=(coord_X *sin(Psi) + coord_Y* cos(Psi));
|
---|
1708 |
|
---|
1709 | else
|
---|
1710 | coord_X=coord_x;
|
---|
1711 | coord_Y=coord_y;
|
---|
1712 | coord_Z=coord_z;
|
---|
1713 | end
|
---|
1714 | %restriction to the range of x and y if imposed
|
---|
1715 | testin=ones(size(coord_X)); %default
|
---|
1716 | testbound=0;
|
---|
1717 | if testXMin
|
---|
1718 | testin=testin & (coord_X >= XMin);
|
---|
1719 | testbound=1;
|
---|
1720 | end
|
---|
1721 | if testXMax
|
---|
1722 | testin=testin & (coord_X <= XMax);
|
---|
1723 | testbound=1;
|
---|
1724 | end
|
---|
1725 | if testYMin
|
---|
1726 | testin=testin & (coord_Y >= YMin);
|
---|
1727 | testbound=1;
|
---|
1728 | end
|
---|
1729 | if testYMax
|
---|
1730 | testin=testin & (coord_Y <= YMax);
|
---|
1731 | testbound=1;
|
---|
1732 | end
|
---|
1733 | if testbound
|
---|
1734 | indcut=find(testin);
|
---|
1735 | for ivar=VarIndex
|
---|
1736 | VarName=FieldData.ListVarName{ivar};
|
---|
1737 | eval(['FieldData.' VarName '=FieldData.' VarName '(indcut);'])
|
---|
1738 | end
|
---|
1739 | coord_X=coord_X(indcut);
|
---|
1740 | coord_Y=coord_Y(indcut);
|
---|
1741 | if length(ivar_Z)==1
|
---|
1742 | coord_Z=coord_Z(indcut);
|
---|
1743 | end
|
---|
1744 | end
|
---|
1745 | % different cases of projection
|
---|
1746 | if isequal(ObjectData.ProjMode,'projection')%%%%%%% NOT USED %%%%%%%%%%
|
---|
1747 | for ivar=VarIndex %transfer variables to the projection plane
|
---|
1748 | VarName=FieldData.ListVarName{ivar};
|
---|
1749 | if ivar==ivar_X %x coordinate
|
---|
1750 | eval(['ProjData.' VarName '=coord_X;'])
|
---|
1751 | elseif ivar==ivar_Y % y coordinate
|
---|
1752 | eval(['ProjData.' VarName '=coord_Y;'])
|
---|
1753 | elseif isempty(ivar_Z) || ivar~=ivar_Z % other variables (except Z coordinate wyhich is not reproduced)
|
---|
1754 | eval(['ProjData.' VarName '=FieldData.' VarName ';'])
|
---|
1755 | end
|
---|
1756 | if isempty(ivar_Z) || ivar~=ivar_Z
|
---|
1757 | ProjData.ListVarName=[ProjData.ListVarName VarName];
|
---|
1758 | ProjData.VarDimName=[ProjData.VarDimName DimCell];
|
---|
1759 | nbvar=nbvar+1;
|
---|
1760 | if isfield(FieldData,'VarAttribute') && length(FieldData.VarAttribute) >=ivar
|
---|
1761 | ProjData.VarAttribute{nbvar}=FieldData.VarAttribute{ivar};
|
---|
1762 | end
|
---|
1763 | end
|
---|
1764 | end
|
---|
1765 | elseif isequal(ObjectData.ProjMode,'interp')||isequal(ObjectData.ProjMode,'filter')%interpolate data on a regular grid
|
---|
1766 | coord_x_proj=XMin:DX:XMax;
|
---|
1767 | coord_y_proj=YMin:DY:YMax;
|
---|
1768 | coord_z_proj=ZMin:DZ:ZMax;
|
---|
1769 | DimCell={'coord_z','coord_y','coord_x'};
|
---|
1770 | ProjData.ListVarName={'coord_z','coord_y','coord_x'};
|
---|
1771 | ProjData.VarDimName={'coord_z','coord_y','coord_x'};
|
---|
1772 | nbcoord=2;
|
---|
1773 | ProjData.coord_z=[ZMin ZMax];
|
---|
1774 | ProjData.coord_y=[YMin YMax];
|
---|
1775 | ProjData.coord_x=[XMin XMax];
|
---|
1776 | if isempty(ivar_X), ivar_X=0; end;
|
---|
1777 | if isempty(ivar_Y), ivar_Y=0; end;
|
---|
1778 | if isempty(ivar_Z), ivar_Z=0; end;
|
---|
1779 | if isempty(ivar_U), ivar_U=0; end;
|
---|
1780 | if isempty(ivar_V), ivar_V=0; end;
|
---|
1781 | if isempty(ivar_W), ivar_W=0; end;
|
---|
1782 | if isempty(ivar_F), ivar_F=0; end;
|
---|
1783 | if isempty(ivar_FF), ivar_FF=0; end;
|
---|
1784 | if ~isequal(ivar_FF,0)
|
---|
1785 | VarName_FF=FieldData.ListVarName{ivar_FF};
|
---|
1786 | eval(['indsel=find(FieldData.' VarName_FF '==0);'])
|
---|
1787 | coord_X=coord_X(indsel);
|
---|
1788 | coord_Y=coord_Y(indsel);
|
---|
1789 | end
|
---|
1790 | FF=zeros(1,length(coord_y_proj)*length(coord_x_proj));
|
---|
1791 | testFF=0;
|
---|
1792 | [X,Y,Z]=meshgrid(coord_y_proj,coord_z_proj,coord_x_proj);%grid in the new coordinates
|
---|
1793 | for ivar=VarIndex
|
---|
1794 | VarName=FieldData.ListVarName{ivar};
|
---|
1795 | if ~( ivar==ivar_X || ivar==ivar_Y || ivar==ivar_Z || ivar==ivar_F || ivar==ivar_FF || test_anc(ivar)==1)
|
---|
1796 | ivar_new=ivar_new+1;
|
---|
1797 | ProjData.ListVarName=[ProjData.ListVarName {VarName}];
|
---|
1798 | ProjData.VarDimName=[ProjData.VarDimName {DimCell}];
|
---|
1799 | if isfield(FieldData,'VarAttribute') && length(FieldData.VarAttribute) >=ivar
|
---|
1800 | ProjData.VarAttribute{ivar_new+nbcoord}=FieldData.VarAttribute{ivar};
|
---|
1801 | end
|
---|
1802 | if ~isequal(ivar_FF,0)
|
---|
1803 | eval(['FieldData.' VarName '=FieldData.' VarName '(indsel);'])
|
---|
1804 | end
|
---|
1805 | eval(['InterpFct=TriScatteredInterp(double(coord_X),double(coord_Y),double(coord_Z),double(FieldData.' VarName '))'])
|
---|
1806 | eval(['ProjData.' VarName '=InterpFct(X,Y,Z);'])
|
---|
1807 | % eval(['varline=reshape(ProjData.' VarName ',1,length(coord_y_proj)*length(coord_x_proj));'])
|
---|
1808 | % FFlag= isnan(varline); %detect undefined values NaN
|
---|
1809 | % indnan=find(FFlag);
|
---|
1810 | % if~isempty(indnan)
|
---|
1811 | % varline(indnan)=zeros(size(indnan));
|
---|
1812 | % eval(['ProjData.' VarName '=reshape(varline,length(coord_y_proj),length(coord_x_proj));'])
|
---|
1813 | % FF(indnan)=ones(size(indnan));
|
---|
1814 | % testFF=1;
|
---|
1815 | % end
|
---|
1816 | if ivar==ivar_U
|
---|
1817 | ivar_U=ivar_new;
|
---|
1818 | end
|
---|
1819 | if ivar==ivar_V
|
---|
1820 | ivar_V=ivar_new;
|
---|
1821 | end
|
---|
1822 | if ivar==ivar_W
|
---|
1823 | ivar_W=ivar_new;
|
---|
1824 | end
|
---|
1825 | end
|
---|
1826 | end
|
---|
1827 | if testFF
|
---|
1828 | ProjData.FF=reshape(FF,length(coord_y_proj),length(coord_x_proj));
|
---|
1829 | ProjData.ListVarName=[ProjData.ListVarName {'FF'}];
|
---|
1830 | ProjData.VarDimName=[ProjData.VarDimName {DimCell}];
|
---|
1831 | ProjData.VarAttribute{ivar_new+1+nbcoord}.Role='errorflag';
|
---|
1832 | end
|
---|
1833 | end
|
---|
1834 |
|
---|
1835 | %% case of input fields defined on a structured grid
|
---|
1836 | else
|
---|
1837 | VarName=FieldData.ListVarName{VarIndex(1)};%get the first variable of the cell to get the input matrix dimensions
|
---|
1838 | eval(['DimValue=size(FieldData.' VarName ');'])%input matrix dimensions
|
---|
1839 | DimValue(DimValue==1)=[];%remove singleton dimensions
|
---|
1840 | NbDim=numel(DimValue);%update number of space dimensions
|
---|
1841 | nbcolor=1; %default number of 'color' components: third matrix index without corresponding coordinate
|
---|
1842 | if NbDim>=3
|
---|
1843 | if NbDim>3
|
---|
1844 | errormsg='matrices with more than 3 dimensions not handled';
|
---|
1845 | return
|
---|
1846 | else
|
---|
1847 | if numel(find(VarType.coord))==2% the third matrix dimension does not correspond to a space coordinate
|
---|
1848 | nbcolor=DimValue(3);
|
---|
1849 | DimValue(3)=[]; %number of 'color' components updated
|
---|
1850 | NbDim=2;% space dimension set to 2
|
---|
1851 | end
|
---|
1852 | end
|
---|
1853 | end
|
---|
1854 | AYName=FieldData.ListVarName{VarType.coord(NbDim-1)};%name of input x coordinate (name preserved on projection)
|
---|
1855 | AXName=FieldData.ListVarName{VarType.coord(NbDim)};%name of input y coordinate (name preserved on projection)
|
---|
1856 | eval(['AX=FieldData.' AXName ';'])
|
---|
1857 | eval(['AY=FieldData.' AYName ';'])
|
---|
1858 | ListDimName=FieldData.VarDimName{VarIndex(1)};
|
---|
1859 | ProjData.ListVarName=[ProjData.ListVarName {AYName} {AXName}]; %TODO: check if it already exists in Projdata (several cells)
|
---|
1860 | ProjData.VarDimName=[ProjData.VarDimName {AYName} {AXName}];
|
---|
1861 |
|
---|
1862 | % for idim=1:length(ListDimName)
|
---|
1863 | % DimName=ListDimName{idim};
|
---|
1864 | % if strcmp(DimName,'rgb')||strcmp(DimName,'nb_coord')||strcmp(DimName,'nb_coord_i')
|
---|
1865 | % nbcolor=DimValue(idim);
|
---|
1866 | % DimValue(idim)=[];
|
---|
1867 | % end
|
---|
1868 | % if isequal(DimName,'nb_coord_j')% NOTE: CASE OF TENSOR NOT TREATED
|
---|
1869 | % DimValue(idim)=[];
|
---|
1870 | % end
|
---|
1871 | % end
|
---|
1872 | Coord_z=[];
|
---|
1873 | Coord_y=[];
|
---|
1874 | Coord_x=[];
|
---|
1875 |
|
---|
1876 | for idim=1:NbDim %loop on space dimensions
|
---|
1877 | test_interp(idim)=0;%test for coordiate interpolation (non regular grid), =0 by default
|
---|
1878 | ivar=VarType.coord(idim);% index of the variable corresponding to the current dimension
|
---|
1879 | if ~isequal(ivar,0)% a variable corresponds to the dimension #idim
|
---|
1880 | eval(['Coord{idim}=FieldData.' FieldData.ListVarName{ivar} ';']) ;% coord values for the input field
|
---|
1881 | if numel(Coord{idim})==2 %input array defined on a regular grid
|
---|
1882 | DCoord_min(idim)=(Coord{idim}(2)-Coord{idim}(1))/DimValue(idim);
|
---|
1883 | else
|
---|
1884 | DCoord=diff(Coord{idim});%array of coordinate derivatives for the input field
|
---|
1885 | DCoord_min(idim)=min(DCoord);
|
---|
1886 | DCoord_max=max(DCoord);
|
---|
1887 | % test_direct(idim)=DCoord_max>0;% =1 for increasing values, 0 otherwise
|
---|
1888 | if abs(DCoord_max-DCoord_min(idim))>abs(DCoord_max/1000)
|
---|
1889 | msgbox_uvmat('ERROR',['non monotonic dimension variable # ' num2str(idim) ' in proj_field.m'])
|
---|
1890 | return
|
---|
1891 | end
|
---|
1892 | test_interp(idim)=(DCoord_max-DCoord_min(idim))> 0.0001*abs(DCoord_max);% test grid regularity
|
---|
1893 | end
|
---|
1894 | test_direct(idim)=(DCoord_min(idim)>0);
|
---|
1895 | else % no variable associated with the dimension #idim, the coordinate value is set equal to the matrix index by default
|
---|
1896 | Coord_i_str=['Coord_' num2str(idim)];
|
---|
1897 | DCoord_min(idim)=1;%default
|
---|
1898 | Coord{idim}=[0.5 DimValue(idim)-0.5];
|
---|
1899 | test_direct(idim)=1;
|
---|
1900 | end
|
---|
1901 | end
|
---|
1902 | if DY==0
|
---|
1903 | DY=abs(DCoord_min(NbDim-1));
|
---|
1904 | end
|
---|
1905 | npY=1+round(abs(Coord{NbDim-1}(end)-Coord{NbDim-1}(1))/DY);%nbre of points after interpol
|
---|
1906 | if DX==0
|
---|
1907 | DX=abs(DCoord_min(NbDim));
|
---|
1908 | end
|
---|
1909 | npX=1+round(abs(Coord{NbDim}(end)-Coord{NbDim}(1))/DX);%nbre of points after interpol
|
---|
1910 | for idim=1:NbDim
|
---|
1911 | if test_interp(idim)
|
---|
1912 | 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
|
---|
1913 | end
|
---|
1914 | end
|
---|
1915 | Coord_y=linspace(Coord{NbDim-1}(1),Coord{NbDim-1}(end),npY);
|
---|
1916 | test_direct_y=test_direct(NbDim-1);
|
---|
1917 | Coord_x=linspace(Coord{NbDim}(1),Coord{NbDim}(end),npX);
|
---|
1918 | test_direct_x=test_direct(NbDim);
|
---|
1919 | DAX=DCoord_min(NbDim);
|
---|
1920 | DAY=DCoord_min(NbDim-1);
|
---|
1921 | minAX=min(Coord_x);
|
---|
1922 | maxAX=max(Coord_x);
|
---|
1923 | minAY=min(Coord_y);
|
---|
1924 | maxAY=max(Coord_y);
|
---|
1925 | xcorner=[minAX maxAX minAX maxAX]-ObjectData.Coord(1,1);
|
---|
1926 | ycorner=[maxAY maxAY minAY minAY]-ObjectData.Coord(1,2);
|
---|
1927 | xcor_new=xcorner*cos(Phi)+ycorner*sin(Phi);%coord new frame
|
---|
1928 | ycor_new=-xcorner*sin(Phi)+ycorner*cos(Phi);
|
---|
1929 | if ~testXMax
|
---|
1930 | XMax=max(xcor_new);
|
---|
1931 | end
|
---|
1932 | if ~testXMin
|
---|
1933 | XMin=min(xcor_new);
|
---|
1934 | end
|
---|
1935 | if ~testYMax
|
---|
1936 | YMax=max(ycor_new);
|
---|
1937 | end
|
---|
1938 | if ~testYMin
|
---|
1939 | YMin=min(ycor_new);
|
---|
1940 | end
|
---|
1941 | DXinit=(maxAX-minAX)/(DimValue(NbDim)-1);
|
---|
1942 | DYinit=(maxAY-minAY)/(DimValue(NbDim-1)-1);
|
---|
1943 | if DX==0
|
---|
1944 | DX=DXinit;
|
---|
1945 | end
|
---|
1946 | if DY==0
|
---|
1947 | DY=DYinit;
|
---|
1948 | end
|
---|
1949 | if NbDim==3
|
---|
1950 | DZ=(Coord{1}(end)-Coord{1}(1))/(DimValue(1)-1);
|
---|
1951 | if ~test_direct(1)
|
---|
1952 | DZ=-DZ;
|
---|
1953 | end
|
---|
1954 | Coord_z=linspace(Coord{1}(1),Coord{1}(end),DimValue(1));
|
---|
1955 | test_direct_z=test_direct(1);
|
---|
1956 | end
|
---|
1957 | npX=floor((XMax-XMin)/DX+1);
|
---|
1958 | npY=floor((YMax-YMin)/DY+1);
|
---|
1959 | if test_direct_y
|
---|
1960 | coord_y_proj=linspace(YMin,YMax,npY);%abscissa of the new pixels along the line
|
---|
1961 | else
|
---|
1962 | coord_y_proj=linspace(YMax,YMin,npY);%abscissa of the new pixels along the line
|
---|
1963 | end
|
---|
1964 | if test_direct_x
|
---|
1965 | coord_x_proj=linspace(XMin,XMax,npX);%abscissa of the new pixels along the line
|
---|
1966 | else
|
---|
1967 | coord_x_proj=linspace(XMax,XMin,npX);%abscissa of the new pixels along the line
|
---|
1968 | end
|
---|
1969 |
|
---|
1970 | % case with no rotation and interpolation
|
---|
1971 | if isequal(ProjMode,'projection') && isequal(Phi,0) && isequal(Theta,0) && isequal(Psi,0)
|
---|
1972 | if ~testXMin && ~testXMax && ~testYMin && ~testYMax && NbDim==2
|
---|
1973 | ProjData=FieldData;
|
---|
1974 | else
|
---|
1975 | indY=NbDim-1;
|
---|
1976 | if test_direct(indY)
|
---|
1977 | min_indy=ceil((YMin-Coord{indY}(1))/DYinit)+1;
|
---|
1978 | max_indy=floor((YMax-Coord{indY}(1))/DYinit)+1;
|
---|
1979 | Ybound(1)=Coord{indY}(1)+DYinit*(min_indy-1);
|
---|
1980 | Ybound(2)=Coord{indY}(1)+DYinit*(max_indy-1);
|
---|
1981 | else
|
---|
1982 | min_indy=ceil((Coord{indY}(1)-YMax)/DYinit)+1;
|
---|
1983 | max_indy=floor((Coord{indY}(1)-YMin)/DYinit)+1;
|
---|
1984 | Ybound(2)=Coord{indY}(1)-DYinit*(max_indy-1);
|
---|
1985 | Ybound(1)=Coord{indY}(1)-DYinit*(min_indy-1);
|
---|
1986 | end
|
---|
1987 | if test_direct(NbDim)==1
|
---|
1988 | min_indx=ceil((XMin-Coord{NbDim}(1))/DXinit)+1;
|
---|
1989 | max_indx=floor((XMax-Coord{NbDim}(1))/DXinit)+1;
|
---|
1990 | Xbound(1)=Coord{NbDim}(1)+DXinit*(min_indx-1);
|
---|
1991 | Xbound(2)=Coord{NbDim}(1)+DXinit*(max_indx-1);
|
---|
1992 | else
|
---|
1993 | min_indx=ceil((Coord{NbDim}(1)-XMax)/DXinit)+1;
|
---|
1994 | max_indx=floor((Coord{NbDim}(1)-XMin)/DXinit)+1;
|
---|
1995 | Xbound(2)=Coord{NbDim}(1)+DXinit*(max_indx-1);
|
---|
1996 | Xbound(1)=Coord{NbDim}(1)+DXinit*(min_indx-1);
|
---|
1997 | end
|
---|
1998 | if NbDim==3
|
---|
1999 | DimCell(1)=[]; %suppress z variable
|
---|
2000 | DimValue(1)=[];
|
---|
2001 | %structured coordinates
|
---|
2002 | if test_direct(1)
|
---|
2003 | iz=ceil((ObjectData.Coord(1,3)-Coord{1}(1))/DZ)+1;
|
---|
2004 | else
|
---|
2005 | iz=ceil((Coord{1}(1)-ObjectData.Coord(1,3))/DZ)+1;
|
---|
2006 | end
|
---|
2007 | end
|
---|
2008 | min_indy=max(min_indy,1);% deals with margin (bound lower than the first index)
|
---|
2009 | min_indx=max(min_indx,1);
|
---|
2010 | max_indy=min(max_indy,DimValue(1));
|
---|
2011 | max_indx=min(max_indx,DimValue(2));
|
---|
2012 | for ivar=VarIndex% loop on non coordinate variables
|
---|
2013 | VarName=FieldData.ListVarName{ivar};
|
---|
2014 | ProjData.ListVarName=[ProjData.ListVarName VarName];
|
---|
2015 | ProjData.VarDimName=[ProjData.VarDimName {DimCell}];
|
---|
2016 | if isfield(FieldData,'VarAttribute') && length(FieldData.VarAttribute)>=ivar
|
---|
2017 | ProjData.VarAttribute{length(ProjData.ListVarName)}=FieldData.VarAttribute{ivar};
|
---|
2018 | end
|
---|
2019 | if NbDim==3
|
---|
2020 | eval(['ProjData.' VarName '=squeeze(FieldData.' VarName '(iz,min_indy:max_indy,min_indx:max_indx));']);
|
---|
2021 | else
|
---|
2022 | eval(['ProjData.' VarName '=FieldData.' VarName '(min_indy:max_indy,min_indx:max_indx,:);']);
|
---|
2023 | end
|
---|
2024 | end
|
---|
2025 | eval(['ProjData.' AYName '=[Ybound(1) Ybound(2)];']) %record the new (projected ) y coordinates
|
---|
2026 | eval(['ProjData.' AXName '=[Xbound(1) Xbound(2)];']) %record the new (projected ) x coordinates
|
---|
2027 | end
|
---|
2028 | else % case with rotation and/or interpolation
|
---|
2029 | if NbDim==2 %2D case
|
---|
2030 | [X,Y]=meshgrid(coord_x_proj,coord_y_proj);%grid in the new coordinates
|
---|
2031 | XIMA=ObjectData.Coord(1,1)+(X)*cos(Phi)-Y*sin(Phi);%corresponding coordinates in the original image
|
---|
2032 | YIMA=ObjectData.Coord(1,2)+(X)*sin(Phi)+Y*cos(Phi);
|
---|
2033 | XIMA=(XIMA-minAX)/DXinit+1;% image index along x
|
---|
2034 | YIMA=(-YIMA+maxAY)/DYinit+1;% image index along y
|
---|
2035 | XIMA=reshape(round(XIMA),1,npX*npY);%indices reorganized in 'line'
|
---|
2036 | YIMA=reshape(round(YIMA),1,npX*npY);
|
---|
2037 | flagin=XIMA>=1 & XIMA<=DimValue(2) & YIMA >=1 & YIMA<=DimValue(1);%flagin=1 inside the original image
|
---|
2038 | if isequal(ObjectData.ProjMode,'filter')
|
---|
2039 | npx_filter=ceil(abs(DX/DAX));
|
---|
2040 | npy_filter=ceil(abs(DY/DAY));
|
---|
2041 | Mfilter=ones(npy_filter,npx_filter)/(npx_filter*npy_filter);
|
---|
2042 | test_filter=1;
|
---|
2043 | else
|
---|
2044 | test_filter=0;
|
---|
2045 | end
|
---|
2046 | eval(['ProjData.' AYName '=[coord_y_proj(1) coord_y_proj(end)];']) %record the new (projected ) y coordinates
|
---|
2047 | eval(['ProjData.' AXName '=[coord_x_proj(1) coord_x_proj(end)];']) %record the new (projected ) x coordinates
|
---|
2048 | for ivar=VarIndex
|
---|
2049 | VarName=FieldData.ListVarName{ivar};
|
---|
2050 | if test_interp(1) || test_interp(2)%interpolate on a regular grid
|
---|
2051 | eval(['ProjData.' VarName '=interp2(Coord{2},Coord{1},FieldData.' VarName ',Coord_x,Coord_y'');']) %TO TEST
|
---|
2052 | end
|
---|
2053 | %filter the field (image) if option 'filter' is used
|
---|
2054 | if test_filter
|
---|
2055 | Aclass=class(FieldData.A);
|
---|
2056 | eval(['ProjData.' VarName '=filter2(Mfilter,FieldData.' VarName ',''valid'');'])
|
---|
2057 | if ~isequal(Aclass,'double')
|
---|
2058 | eval(['ProjData.' VarName '=' Aclass '(FieldData.' VarName ');'])%revert to integer values
|
---|
2059 | end
|
---|
2060 | end
|
---|
2061 | eval(['vec_A=reshape(FieldData.' VarName ',[],nbcolor);'])%put the original image in line
|
---|
2062 | %ind_in=find(flagin);
|
---|
2063 | ind_out=find(~flagin);
|
---|
2064 | ICOMB=(XIMA-1)*DimValue(1)+YIMA;
|
---|
2065 | ICOMB=ICOMB(flagin);%index corresponding to XIMA and YIMA in the aligned original image vec_A
|
---|
2066 | vec_B(flagin,1:nbcolor)=vec_A(ICOMB,:);
|
---|
2067 | for icolor=1:nbcolor
|
---|
2068 | vec_B(ind_out,icolor)=zeros(size(ind_out));
|
---|
2069 | end
|
---|
2070 | ProjData.ListVarName=[ProjData.ListVarName VarName];
|
---|
2071 | ProjData.VarDimName=[ProjData.VarDimName {DimCell}];
|
---|
2072 | if isfield(FieldData,'VarAttribute')&&length(FieldData.VarAttribute)>=ivar
|
---|
2073 | ProjData.VarAttribute{length(ProjData.ListVarName)+nbcoord}=FieldData.VarAttribute{ivar};
|
---|
2074 | end
|
---|
2075 | eval(['ProjData.' VarName '=reshape(vec_B,npY,npX,nbcolor);']);
|
---|
2076 | end
|
---|
2077 | ProjData.FF=reshape(~flagin,npY,npX);%false flag A FAIRE: tenir compte d'un flga antérieur
|
---|
2078 | ProjData.ListVarName=[ProjData.ListVarName 'FF'];
|
---|
2079 | ProjData.VarDimName=[ProjData.VarDimName {DimCell}];
|
---|
2080 | ProjData.VarAttribute{length(ProjData.ListVarName)}.Role='errorflag';
|
---|
2081 | else %3D case
|
---|
2082 | if ~testangle
|
---|
2083 | % unstructured z coordinate
|
---|
2084 | test_sup=(Coord{1}>=ObjectData.Coord(1,3));
|
---|
2085 | iz_sup=find(test_sup);
|
---|
2086 | iz=iz_sup(1);
|
---|
2087 | if iz>=1 & iz<=npz
|
---|
2088 | %ProjData.ListDimName=[ProjData.ListDimName ListDimName(2:end)];
|
---|
2089 | %ProjData.DimValue=[ProjData.DimValue npY npX];
|
---|
2090 | for ivar=VarIndex
|
---|
2091 | VarName=FieldData.ListVarName{ivar};
|
---|
2092 | ProjData.ListVarName=[ProjData.ListVarName VarName];
|
---|
2093 | ProjData.VarAttribute{length(ProjData.ListVarName)}=FieldData.VarAttribute{ivar}; %reproduce the variable attributes
|
---|
2094 | eval(['ProjData.' VarName '=squeeze(FieldData.' VarName '(iz,:,:));'])% select the z index iz
|
---|
2095 | %TODO : do a vertical average for a thick plane
|
---|
2096 | if test_interp(2) || test_interp(3)
|
---|
2097 | eval(['ProjData.' VarName '=interp2(Coord{3},Coord{2},ProjData.' VarName ',Coord_x,Coord_y'');'])
|
---|
2098 | end
|
---|
2099 | end
|
---|
2100 | end
|
---|
2101 | else
|
---|
2102 | errormsg='projection of structured coordinates on oblique plane not yet implemented';
|
---|
2103 | %TODO: use interp3
|
---|
2104 | return
|
---|
2105 | end
|
---|
2106 | end
|
---|
2107 | end
|
---|
2108 | end
|
---|
2109 |
|
---|
2110 | %% projection of velocity components in the rotated coordinates
|
---|
2111 | if testangle
|
---|
2112 | if isempty(ivar_V)
|
---|
2113 | msgbox_uvmat('ERROR','v velocity component missing in proj_field.m')
|
---|
2114 | return
|
---|
2115 | end
|
---|
2116 | UName=FieldData.ListVarName{ivar_U};
|
---|
2117 | VName=FieldData.ListVarName{ivar_V};
|
---|
2118 | eval(['ProjData.' UName '=cos(Phi)*ProjData.' UName '+ sin(Phi)*ProjData.' VName ';'])
|
---|
2119 | eval(['ProjData.' VName '=cos(Theta)*(-sin(Phi)*ProjData.' UName '+ cos(Phi)*ProjData.' VName ');'])
|
---|
2120 | if ~isempty(ivar_W)
|
---|
2121 | WName=FieldData.ListVarName{ivar_W};
|
---|
2122 | eval(['ProjData.' VName '=ProjData.' VName '+ ProjData.' WName '*sin(Theta);'])%
|
---|
2123 | eval(['ProjData.' WName '=NormVec_X*ProjData.' UName '+ NormVec_Y*ProjData.' VName '+ NormVec_Z* ProjData.' WName ';']);
|
---|
2124 | end
|
---|
2125 | if ~isequal(Psi,0)
|
---|
2126 | eval(['ProjData.' UName '=cos(Psi)* ProjData.' UName '- sin(Psi)*ProjData.' VName ';']);
|
---|
2127 | eval(['ProjData.' VName '=sin(Psi)* ProjData.' UName '+ cos(Psi)*ProjData.' VName ';']);
|
---|
2128 | end
|
---|
2129 | end
|
---|
2130 | end
|
---|
2131 |
|
---|
2132 | %------------------------------------------------------------------------
|
---|
2133 | %--- transfer the global attributes
|
---|
2134 | function [ProjData,errormsg]=proj_heading(FieldData,ObjectData)
|
---|
2135 | %------------------------------------------------------------------------
|
---|
2136 | ProjData=[];%default
|
---|
2137 | errormsg='';%default
|
---|
2138 |
|
---|
2139 | %% transfer error
|
---|
2140 | if isfield(FieldData,'Txt')
|
---|
2141 | errormsg=FieldData.Txt; %transmit erreur message
|
---|
2142 | return;
|
---|
2143 | end
|
---|
2144 |
|
---|
2145 | %% transfer global attributes
|
---|
2146 | if ~isfield(FieldData,'ListGlobalAttribute')
|
---|
2147 | ProjData.ListGlobalAttribute={};
|
---|
2148 | else
|
---|
2149 | ProjData.ListGlobalAttribute=FieldData.ListGlobalAttribute;
|
---|
2150 | end
|
---|
2151 | for iattr=1:length(ProjData.ListGlobalAttribute)
|
---|
2152 | AttrName=ProjData.ListGlobalAttribute{iattr};
|
---|
2153 | if isfield(FieldData,AttrName)
|
---|
2154 | eval(['ProjData.' AttrName '=FieldData.' AttrName ';']);
|
---|
2155 | end
|
---|
2156 | end
|
---|
2157 |
|
---|
2158 | %% transfer coordinate unit
|
---|
2159 | if isfield(FieldData,'CoordUnit')
|
---|
2160 | if isfield(ObjectData,'CoordUnit') && ~strcmp(FieldData.CoordUnit,ObjectData.CoordUnit)
|
---|
2161 | errormsg=[ObjectData.Type ' in ' ObjectData.CoordUnit ' coordinates, while field in ' FieldData.CoordUnit ];
|
---|
2162 | return
|
---|
2163 | else
|
---|
2164 | ProjData.CoordUnit=FieldData.CoordUnit;
|
---|
2165 | end
|
---|
2166 | end
|
---|
2167 |
|
---|
2168 | %% store the properties of the projection object
|
---|
2169 | ListObject={'Type','ProjMode','RangeX','RangeY','RangeZ','Phi','Theta','Psi','Coord'};
|
---|
2170 | for ilist=1:length(ListObject)
|
---|
2171 | if isfield(ObjectData,ListObject{ilist})
|
---|
2172 | eval(['val=ObjectData.' ListObject{ilist} ';'])
|
---|
2173 | if ~isempty(val)
|
---|
2174 | eval(['ProjData.Object' ListObject{ilist} '=val;']);
|
---|
2175 | ProjData.ListGlobalAttribute=[ProjData.ListGlobalAttribute {['Object' ListObject{ilist}]}];
|
---|
2176 | end
|
---|
2177 | end
|
---|
2178 | end
|
---|