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