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