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