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 |
|
---|
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=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=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=proj_heading(FieldData,ObjectData);%transfer global attributes
|
---|
563 | ProjData.NbDim=1;
|
---|
564 |
|
---|
565 | %initialisation of the input parameters and defaultoutput
|
---|
566 | ProjMode='projection';%direct projection on the line by default
|
---|
567 | if isfield(ObjectData,'ProjMode'),ProjMode=ObjectData.ProjMode; end;
|
---|
568 | ProjAngle=90; %90 degrees projection by default
|
---|
569 | if isfield(FieldData,'ProjAngle'),ProjAngle=ObjectData.ProjAngle; end;
|
---|
570 | width=0;%default width of the projection band
|
---|
571 | if isfield(ObjectData,'Range')&size(ObjectData.Range,2)>=2
|
---|
572 | width=abs(ObjectData.Range(1,2));
|
---|
573 | end
|
---|
574 | if isfield(ObjectData,'RangeY')
|
---|
575 | width=max(ObjectData.RangeY);
|
---|
576 | end
|
---|
577 |
|
---|
578 | % default output
|
---|
579 | errormsg=[];%default
|
---|
580 | Xline=[];
|
---|
581 | flux=0;
|
---|
582 | circul=0;
|
---|
583 | liny=ObjectData.Coord(:,2);
|
---|
584 | siz_line=size(ObjectData.Coord);
|
---|
585 | if siz_line(1)<2
|
---|
586 | return% line needs at least 2 points to be defined
|
---|
587 | end
|
---|
588 | testfalse=0;
|
---|
589 | ListIndex={};
|
---|
590 |
|
---|
591 | %angles of the polyline and boundaries of action
|
---|
592 | dlinx=diff(ObjectData.Coord(:,1));
|
---|
593 | dliny=diff(ObjectData.Coord(:,2));
|
---|
594 | theta=angle(dlinx+i*dliny);%angle of each segment
|
---|
595 | theta(siz_line(1))=theta(siz_line(1)-1);
|
---|
596 | % determine a rectangles at +-width from the line (only used for the ProjMode='projection or 'filter')
|
---|
597 | if isequal(ProjMode,'projection') || isequal(ProjMode,'filter')
|
---|
598 | xsup(1)=ObjectData.Coord(1,1)-width*sin(theta(1));
|
---|
599 | xinf(1)=ObjectData.Coord(1,1)+width*sin(theta(1));
|
---|
600 | ysup(1)=ObjectData.Coord(1,2)+width*cos(theta(1));
|
---|
601 | yinf(1)=ObjectData.Coord(1,2)-width*cos(theta(1));
|
---|
602 | for ip=2:siz_line(1)
|
---|
603 | xsup(ip)=ObjectData.Coord(ip,1)-width*sin((theta(ip)+theta(ip-1))/2)/cos((theta(ip-1)-theta(ip))/2);
|
---|
604 | xinf(ip)=ObjectData.Coord(ip,1)+width*sin((theta(ip)+theta(ip-1))/2)/cos((theta(ip-1)-theta(ip))/2);
|
---|
605 | ysup(ip)=ObjectData.Coord(ip,2)+width*cos((theta(ip)+theta(ip-1))/2)/cos((theta(ip-1)-theta(ip))/2);
|
---|
606 | yinf(ip)=ObjectData.Coord(ip,2)-width*cos((theta(ip)+theta(ip-1))/2)/cos((theta(ip-1)-theta(ip))/2);
|
---|
607 | end
|
---|
608 | end
|
---|
609 |
|
---|
610 | %group the variables (fields of 'FieldData') in cells of variables with the same dimensions
|
---|
611 | [CellVarIndex,NbDim,VarTypeCell,errormsg]=find_field_indices(FieldData);
|
---|
612 | if ~isempty(errormsg)
|
---|
613 | errormsg=['error in proj_field/proj_line:' errormsg];
|
---|
614 | return
|
---|
615 | end
|
---|
616 |
|
---|
617 | % loop on variable cells with the same space dimension
|
---|
618 | ProjData.ListVarName={};
|
---|
619 | ProjData.VarDimName={};
|
---|
620 | for icell=1:length(CellVarIndex)
|
---|
621 | VarIndex=CellVarIndex{icell};% indices of the selected variables in the list FieldData.ListVarName
|
---|
622 | VarType=VarTypeCell{icell}; %types of variables
|
---|
623 | if NbDim(icell)~=2% proj_line acts only on fields of space dimension 2, TODO: check 3D case
|
---|
624 | continue
|
---|
625 | end
|
---|
626 | testX=~isempty(VarType.coord_x) && ~isempty(VarType.coord_y);% test for unstructured coordinates
|
---|
627 | testU=~isempty(VarType.vector_x) && ~isempty(VarType.vector_y);% test for vectors
|
---|
628 | testfalse=~isempty(VarType.errorflag);% test for error flag
|
---|
629 | testproj(VarIndex)=zeros(size(VarIndex));% test =1 for simply projected variables, default =0
|
---|
630 | %=0 for vector components, treated separately
|
---|
631 | testproj(VarType.scalar)=1;
|
---|
632 | testproj(VarType.image)=1;
|
---|
633 | testproj(VarType.color)=1;
|
---|
634 | VarIndex=VarIndex(find(testproj(VarIndex)));%select only the projected variables
|
---|
635 | if testU
|
---|
636 | VarIndex=[VarIndex VarType.vector_x VarType.vector_y];%append u and v at the end of the list of variables
|
---|
637 | end
|
---|
638 | %identify vector components
|
---|
639 | if testU
|
---|
640 | UName=FieldData.ListVarName{VarType.vector_x};
|
---|
641 | VName=FieldData.ListVarName{VarType.vector_y};
|
---|
642 | eval(['vector_x=FieldData.' UName ';'])
|
---|
643 | eval(['vector_y=FieldData.' VName ';'])
|
---|
644 | end
|
---|
645 | %identify error flag
|
---|
646 | if testfalse
|
---|
647 | FFName=FieldData.ListVarName{VarType.errorflag};
|
---|
648 | eval(['errorflag=FieldData.' FFName ';'])
|
---|
649 | end
|
---|
650 | % check needed object properties for unstructured positions (position given by the variables with role coord_x, coord_y
|
---|
651 | if testX
|
---|
652 | if ~isequal(ProjMode,'interp')
|
---|
653 | if width==0
|
---|
654 | errormsg='range of the projection object is missing';
|
---|
655 | return
|
---|
656 | else
|
---|
657 | lambda=2/(width*width); %smoothing factor used for filter: weight exp(-2) at distance width from the line
|
---|
658 | end
|
---|
659 | end
|
---|
660 | if ~isequal(ProjMode,'projection')
|
---|
661 | if isfield(ObjectData,'DX')&~isempty(ObjectData.DX)
|
---|
662 | DX=abs(ObjectData.DX);%mesh of interpolation points along the line
|
---|
663 | else
|
---|
664 | errormsg='DX missing';
|
---|
665 | return
|
---|
666 | end
|
---|
667 | end
|
---|
668 | XName= FieldData.ListVarName{VarType.coord_x};
|
---|
669 | YName= FieldData.ListVarName{VarType.coord_y};
|
---|
670 | eval(['coord_x=FieldData.' XName ';'])
|
---|
671 | eval(['coord_y=FieldData.' YName ';'])
|
---|
672 | end
|
---|
673 | %initiate projection
|
---|
674 | for ivar=1:length(VarIndex)
|
---|
675 | ProjLine{ivar}=[];
|
---|
676 | end
|
---|
677 | XLine=[];
|
---|
678 | linelengthtot=0;
|
---|
679 |
|
---|
680 | % circul=0;
|
---|
681 | % flux=0;
|
---|
682 | %%%%%%% % A FAIRE CALCULER MEAN DES QUANTITES %%%%%%
|
---|
683 | %case of unstructured coordinates
|
---|
684 | if testX
|
---|
685 | for ip=1:siz_line(1)-1 %Loop on the segments of the polyline
|
---|
686 | linelength=sqrt(dlinx(ip)*dlinx(ip)+dliny(ip)*dliny(ip));
|
---|
687 | %select the vector indices in the range of action
|
---|
688 | if testfalse
|
---|
689 | flagsel=(errorflag==0); % keep only non false vectors
|
---|
690 | else
|
---|
691 | flagsel=ones(size(coord_x));
|
---|
692 | end
|
---|
693 | if isequal(ProjMode,'projection') | isequal(ProjMode,'filter')
|
---|
694 | flagsel=flagsel & ((coord_y -yinf(ip))*(xinf(ip+1)-xinf(ip))>(coord_x-xinf(ip))*(yinf(ip+1)-yinf(ip))) ...
|
---|
695 | & ((coord_y -ysup(ip))*(xsup(ip+1)-xsup(ip))<(coord_x-xsup(ip))*(ysup(ip+1)-ysup(ip))) ...
|
---|
696 | & ((coord_y -yinf(ip+1))*(xsup(ip+1)-xinf(ip+1))>(coord_x-xinf(ip+1))*(ysup(ip+1)-yinf(ip+1))) ...
|
---|
697 | & ((coord_y -yinf(ip))*(xsup(ip)-xinf(ip))<(coord_x-xinf(ip))*(ysup(ip)-yinf(ip)));
|
---|
698 | end
|
---|
699 | indsel=find(flagsel);%indsel =indices of good vectors
|
---|
700 | X_sel=coord_x(indsel);
|
---|
701 | Y_sel=coord_y(indsel);
|
---|
702 | nbvar=0;
|
---|
703 | for iselect=1:numel(VarIndex)-2*testU
|
---|
704 | VarName=FieldData.ListVarName{VarIndex(iselect)};
|
---|
705 | eval(['ProjVar{iselect}=FieldData.' VarName '(indsel);']);%scalar value
|
---|
706 | end
|
---|
707 | if testU
|
---|
708 | ProjVar{numel(VarIndex)-1}=cos(theta(ip))*vector_x(indsel)+sin(theta(ip))*vector_y(indsel);% longitudinal component
|
---|
709 | ProjVar{numel(VarIndex)}=-sin(theta(ip))*vector_x(indsel)+cos(theta(ip))*vector_y(indsel);%transverse component
|
---|
710 | end
|
---|
711 | if isequal(ProjMode,'projection')
|
---|
712 | sintheta=sin(theta(ip));
|
---|
713 | costheta=cos(theta(ip));
|
---|
714 | Xproj=(X_sel-ObjectData.Coord(ip,1))*costheta + (Y_sel-ObjectData.Coord(ip,2))*sintheta; %projection on the line
|
---|
715 | [Xproj,indsort]=sort(Xproj);
|
---|
716 | for ivar=1:numel(ProjVar)
|
---|
717 | if ~isempty(ProjVar{ivar})
|
---|
718 | ProjVar{ivar}=ProjVar{ivar}(indsort);
|
---|
719 | end
|
---|
720 | end
|
---|
721 | elseif isequal(ProjMode,'interp') %linear interpolation:
|
---|
722 | npoint=floor(linelength/DX)+1;% nbre of points in the profile (interval DX)
|
---|
723 | Xproj=[linelength/(2*npoint):linelength/npoint:linelength-linelength/(2*npoint)];
|
---|
724 | xreg=cos(theta(ip))*Xproj+ObjectData.Coord(ip,1);
|
---|
725 | yreg=sin(theta(ip))*Xproj+ObjectData.Coord(ip,2);
|
---|
726 | for ivar=1:numel(ProjVar)
|
---|
727 | if ~isempty(ProjVar{ivar})
|
---|
728 | ProjVar{ivar}=griddata_uvmat(X_sel,Y_sel,ProjVar{ivar},xreg,yreg);
|
---|
729 | end
|
---|
730 | end
|
---|
731 | elseif isequal(ProjMode,'filter') %filtering
|
---|
732 | npoint=floor(linelength/DX)+1;% nbre of points in the profile (interval DX)
|
---|
733 | Xproj=[linelength/(2*npoint):linelength/npoint:linelength-linelength/(2*npoint)];
|
---|
734 | siz=size(X_sel);
|
---|
735 | xregij=cos(theta(ip))*Xproj'*ones(1,siz(2))+ObjectData.Coord(ip,1);
|
---|
736 | yregij=sin(theta(ip))*Xproj'*ones(1,siz(2))+ObjectData.Coord(ip,2);
|
---|
737 | xij=ones(npoint,1)*X_sel;
|
---|
738 | yij=ones(npoint,1)*Y_sel;
|
---|
739 | Aij=exp(-lambda*((xij-xregij).*(xij-xregij)+(yij-yregij).*(yij-yregij)));
|
---|
740 | norm=ones(1,siz(2))*Aij';
|
---|
741 | for ivar=1:numel(ProjVar)
|
---|
742 | if ~isempty(ProjVar{ivar})
|
---|
743 | ProjVar{ivar}=ProjVar{ivar}*Aij'./norm;
|
---|
744 | end
|
---|
745 | end
|
---|
746 | end
|
---|
747 | %prolongate the total record
|
---|
748 | for ivar=1:numel(ProjVar)
|
---|
749 | if ~isempty(ProjVar{ivar})
|
---|
750 | ProjLine{ivar}=[ProjLine{ivar}; ProjVar{ivar}];
|
---|
751 | end
|
---|
752 | end
|
---|
753 | XLine=[XLine ;(Xproj+linelengthtot)];%along line abscissa
|
---|
754 | linelengthtot=linelengthtot+linelength;
|
---|
755 | % circul=circul+(sum(U_sel))*linelength/npoint;
|
---|
756 | % flux=flux+(sum(V_sel))*linelength/npoint;
|
---|
757 | end
|
---|
758 | ProjData.X=XLine';
|
---|
759 | cur_index=1;
|
---|
760 | ProjData.ListVarName=[ProjData.ListVarName {XName}];
|
---|
761 | ProjData.VarDimName=[ProjData.VarDimName {XName}];
|
---|
762 | ProjData.VarAttribute{1}.long_name='abscissa along line';
|
---|
763 | for iselect=1:numel(VarIndex)
|
---|
764 | VarName=FieldData.ListVarName{VarIndex(iselect)};
|
---|
765 | eval(['ProjData.' VarName '=ProjLine{iselect};'])
|
---|
766 | ProjData.ListVarName=[ProjData.ListVarName {VarName}];
|
---|
767 | ProjData.VarDimName=[ProjData.VarDimName {XName}];
|
---|
768 | ProjData.VarAttribute{iselect}=FieldData.VarAttribute{VarIndex(iselect)};
|
---|
769 | if strcmp(ProjMode,'projection')
|
---|
770 | ProjData.VarAttribute{iselect}.Role='discrete';
|
---|
771 | else
|
---|
772 | ProjData.VarAttribute{iselect}.Role='continuous';
|
---|
773 | end
|
---|
774 | end
|
---|
775 |
|
---|
776 | %case of structured coordinates
|
---|
777 | elseif numel(VarType.coord)>=2 & VarType.coord(1:2) > 0;
|
---|
778 | if ~isequal(ObjectData.Style,'line')% exclude polyline
|
---|
779 | errormsg=['no projection available on ' ObjectData.Style 'for structured coordinates']; %
|
---|
780 | else
|
---|
781 | test_Amat=1;%image or 2D matrix
|
---|
782 | test_interp2=0;%default
|
---|
783 | % if ~isempty(VarType.coord_y)
|
---|
784 | AYName=FieldData.ListVarName{VarType.coord(1)};
|
---|
785 | AXName=FieldData.ListVarName{VarType.coord(2)};
|
---|
786 | eval(['AX=FieldData.' AXName ';']);% set of x positions
|
---|
787 | eval(['AY=FieldData.' AYName ';']);% set of y positions
|
---|
788 | AName=FieldData.ListVarName{VarIndex(1)};
|
---|
789 | eval(['A=FieldData.' AName ';']);% scalar
|
---|
790 | npxy=size(A);
|
---|
791 | npx=npxy(2);
|
---|
792 | npy=npxy(1);
|
---|
793 | if numel(AX)==2
|
---|
794 | DX=(AX(2)-AX(1))/(npx-1);
|
---|
795 | else
|
---|
796 | DX_vec=diff(AX);
|
---|
797 | DX=max(DX_vec);
|
---|
798 | DX_min=min(DX_vec);
|
---|
799 | if (DX-DX_min)>0.0001*abs(DX)
|
---|
800 | test_interp2=1;
|
---|
801 | DX=DX_min;
|
---|
802 | end
|
---|
803 | end
|
---|
804 | if numel(AY)==2
|
---|
805 | DY=(AY(2)-AY(1))/(npy-1);
|
---|
806 | else
|
---|
807 | DY_vec=diff(AY);
|
---|
808 | DY=max(DY_vec);
|
---|
809 | DY_min=min(DY_vec);
|
---|
810 | if (DY-DY_min)>0.0001*abs(DY)
|
---|
811 | test_interp2=1;
|
---|
812 | DY=DY_min;
|
---|
813 | end
|
---|
814 | end
|
---|
815 | AXI=linspace(AX(1),AX(end), npx);%set of x positions for the interpolated input data
|
---|
816 | AYI=linspace(AY(1),AY(end), npy);%set of x positions for the interpolated input data
|
---|
817 | if isfield(ObjectData,'DX')
|
---|
818 | DXY_line=ObjectData.DX;%mesh on the projection line
|
---|
819 | else
|
---|
820 | DXY_line=sqrt(abs(DX*DY));% mesh on the projection line
|
---|
821 | end
|
---|
822 | dlinx=ObjectData.Coord(2,1)-ObjectData.Coord(1,1);
|
---|
823 | dliny=ObjectData.Coord(2,2)-ObjectData.Coord(1,2);
|
---|
824 | linelength=sqrt(dlinx*dlinx+dliny*dliny);
|
---|
825 | theta=angle(dlinx+i*dliny);%angle of the line
|
---|
826 | if isfield(FieldData,'RangeX')
|
---|
827 | XMin=min(FieldData.RangeX);%shift of the origin on the line
|
---|
828 | else
|
---|
829 | XMin=0;
|
---|
830 | end
|
---|
831 | eval(['ProjData.' AXName '=linspace(XMin,XMin+linelength,linelength/DXY_line+1);'])%abscissa of the new pixels along the line
|
---|
832 | y=linspace(-width,width,2*width/DXY_line+1);%ordintes of the new pixels (coordinate across the line)
|
---|
833 | eval(['npX=length(ProjData.' AXName ');'])
|
---|
834 | npY=length(y); %TODO: utiliser proj_grid
|
---|
835 | eval(['[X,Y]=meshgrid(ProjData.' AXName ',y);'])%grid in the line coordinates
|
---|
836 | XIMA=ObjectData.Coord(1,1)+(X-XMin)*cos(theta)-Y*sin(theta);
|
---|
837 | YIMA=ObjectData.Coord(1,2)+(X-XMin)*sin(theta)+Y*cos(theta);
|
---|
838 | XIMA=(XIMA-AX(1))/DX+1;% index of the original image along x
|
---|
839 | YIMA=(YIMA-AY(1))/DY+1;% index of the original image along y
|
---|
840 | XIMA=reshape(round(XIMA),1,npX*npY);%indices reorganized in 'line'
|
---|
841 | YIMA=reshape(round(YIMA),1,npX*npY);
|
---|
842 | flagin=XIMA>=1 & XIMA<=npx & YIMA >=1 & YIMA<=npy;%flagin=1 inside the original image
|
---|
843 | ind_in=find(flagin);
|
---|
844 | ind_out=find(~flagin);
|
---|
845 | ICOMB=(XIMA-1)*npy+YIMA;
|
---|
846 | ICOMB=ICOMB(flagin);%index corresponding to XIMA and YIMA in the aligned original image vec_A
|
---|
847 | nbcolor=1; %color images
|
---|
848 | if numel(npxy)==2
|
---|
849 | nbcolor=1;
|
---|
850 | elseif length(npxy)==3
|
---|
851 | nbcolor=npxy(3);
|
---|
852 | else
|
---|
853 | errormsg='multicomponent field not projected';
|
---|
854 | display(errormsg)
|
---|
855 | return
|
---|
856 | end
|
---|
857 | nbvar=length(ProjData.ListVarName);% number of var from previous cells
|
---|
858 | ProjData.ListVarName=[ProjData.ListVarName {AXName}];
|
---|
859 | ProjData.VarDimName=[ProjData.VarDimName {AXName}];
|
---|
860 | for ivar=VarIndex
|
---|
861 | VarName{ivar}=FieldData.ListVarName{ivar};
|
---|
862 | if test_interp2% interpolate on new grid
|
---|
863 | eval(['FieldData.' VarName{ivar} '=interp2(FieldData.' AXName ',FieldData.' AYName ',FieldData.' VarName{ivar} ',AXI,AYI'');']) %TO TEST
|
---|
864 | end
|
---|
865 | eval(['vec_A=reshape(squeeze(FieldData.' VarName{ivar} '),npx*npy,nbcolor);']) %put the original image in colum
|
---|
866 | if nbcolor==1
|
---|
867 | vec_B(ind_in)=vec_A(ICOMB);
|
---|
868 | vec_B(ind_out)=zeros(size(ind_out));
|
---|
869 | A_out=reshape(vec_B,npY,npX);
|
---|
870 | eval(['ProjData.' VarName{ivar} '=((sum(A_out,1)/npY))'';']);
|
---|
871 | elseif nbcolor==3
|
---|
872 | vec_B(ind_in,[1:3])=vec_A(ICOMB,:);
|
---|
873 | vec_B(ind_out,1)=zeros(size(ind_out));
|
---|
874 | vec_B(ind_out,2)=zeros(size(ind_out));
|
---|
875 | vec_B(ind_out,3)=zeros(size(ind_out));
|
---|
876 | A_out=reshape(vec_B,npY,npX,nbcolor);
|
---|
877 | eval(['ProjData.' VarName{ivar} '=squeeze(sum(A_out,1)/npY);']);
|
---|
878 | end
|
---|
879 | ProjData.ListVarName=[ProjData.ListVarName VarName{ivar} ];
|
---|
880 | ProjData.VarDimName=[ProjData.VarDimName {AXName}];%to generalize with the initial name of the x coordinate
|
---|
881 | ProjData.VarAttribute{ivar}.Role='continuous';% for plot with continuous line
|
---|
882 | end
|
---|
883 | if testU
|
---|
884 | eval(['vector_x =ProjData.' VarName{VarType.vector_x} ';'])
|
---|
885 | eval(['vector_y =ProjData.' VarName{VarType.vector_y} ';'])
|
---|
886 | eval(['ProjData.' VarName{VarType.vector_x} '=cos(theta)*vector_x+sin(theta)*vector_y;'])
|
---|
887 | eval(['ProjData.' VarName{VarType.vector_y} '=-sin(theta)*vector_x+cos(theta)*vector_y;'])
|
---|
888 | end
|
---|
889 | ProjData.VarAttribute{nbvar+1}.long_name='abscissa along line';
|
---|
890 | if nbcolor==3
|
---|
891 | ProjData.VarDimName{end}={AXName,'rgb'};
|
---|
892 | end
|
---|
893 | end
|
---|
894 | end
|
---|
895 | end
|
---|
896 |
|
---|
897 | % %shotarter case for horizontal or vertical line (A FAIRE
|
---|
898 | % % Rangx=[0.5 npx-0.5];%image coordiantes of corners
|
---|
899 | % % Rangy=[npy-0.5 0.5];
|
---|
900 | % % if isfield(Calib,'Pxcmx')&isfield(Calib,'Pxcmy')%old calib
|
---|
901 | % % Rangx=Rangx/Calib.Pxcmx;
|
---|
902 | % % Rangy=Rangy/Calib.Pxcmy;
|
---|
903 | % % else
|
---|
904 | % % [Rangx]=phys_XYZ(Calib,Rangx,[0.5 0.5],[0 0]);%case of translations without rotation and quadratic deformation
|
---|
905 | % % [xx,Rangy]=phys_XYZ(Calib,[0.5 0.5],Rangy,[0 0]);
|
---|
906 | % % end
|
---|
907 | %
|
---|
908 | % % test_scal=0;%default% 3- 'UserData':(get(handles.Tag,'UserData')
|
---|
909 |
|
---|
910 |
|
---|
911 | %-----------------------------------------------------------------
|
---|
912 | %project on a plane
|
---|
913 | % AJOUTER flux,circul,error
|
---|
914 | function [ProjData,errormsg] = proj_plane(FieldData, ObjectData)
|
---|
915 | %-----------------------------------------------------------------
|
---|
916 |
|
---|
917 | %initialisation of the input parameters of the projection plane
|
---|
918 | %-----------------------------------------------------------------
|
---|
919 | ProjMode='projection';%direct projection by default
|
---|
920 | if isfield(ObjectData,'ProjMode'),ProjMode=ObjectData.ProjMode; end;
|
---|
921 |
|
---|
922 | %axis origin
|
---|
923 | if isempty(ObjectData.Coord)
|
---|
924 | ObjectData.Coord(1,1)=0;%origin of the plane set to [0 0] by default
|
---|
925 | ObjectData.Coord(1,2)=0;
|
---|
926 | ObjectData.Coord(1,3)=0;
|
---|
927 | end
|
---|
928 |
|
---|
929 | %rotation angles
|
---|
930 | Phi=0;%default
|
---|
931 | Theta=0;
|
---|
932 | Psi=0;
|
---|
933 | if isfield(ObjectData,'Phi')&& ~isempty(ObjectData.Phi)
|
---|
934 | Phi=(pi/180)*ObjectData.Phi;%first Euler angle in radian
|
---|
935 | end
|
---|
936 | if isfield(ObjectData,'Theta')&& ~isempty(ObjectData.Theta)
|
---|
937 | Theta=(pi/180)*ObjectData.Theta;%second Euler angle in radian
|
---|
938 | end
|
---|
939 | if isfield(ObjectData,'Psi')&& ~isempty(ObjectData.Psi)
|
---|
940 | Psi=(pi/180)*ObjectData.Psi;%third Euler angle in radian
|
---|
941 | end
|
---|
942 |
|
---|
943 | %components of the unity vector normal to the projection plane
|
---|
944 | NormVec_X=-sin(Phi)*sin(Theta);
|
---|
945 | NormVec_Y=cos(Phi)*sin(Theta);
|
---|
946 | NormVec_Z=cos(Theta);
|
---|
947 |
|
---|
948 | % test for 3D fields
|
---|
949 | test3D=0;
|
---|
950 | if isfield(FieldData,'nb_dim')
|
---|
951 | test3D=isequal(FieldData.nb_dim,3);
|
---|
952 | end
|
---|
953 | test3C=test3D; %default 3 vel components
|
---|
954 |
|
---|
955 | %mesh sizes DX and DY
|
---|
956 | DX=0;
|
---|
957 | DY=0; %default
|
---|
958 | if isfield(ObjectData,'DX')&~isempty(ObjectData.DX)
|
---|
959 | DX=abs(ObjectData.DX);%mesh of interpolation points
|
---|
960 | end
|
---|
961 | if isfield(ObjectData,'DY')&~isempty(ObjectData.DY)
|
---|
962 | DY=abs(ObjectData.DY);%mesh of interpolation points
|
---|
963 | end
|
---|
964 | if ~strcmp(ProjMode,'projection') && (DX==0||DY==0)
|
---|
965 | errormsg='DX or DY missing';
|
---|
966 | display(errormsg)
|
---|
967 | return
|
---|
968 | end
|
---|
969 |
|
---|
970 | %extrema along each axis
|
---|
971 | testXMin=0;
|
---|
972 | testXMax=0;
|
---|
973 | testYMin=0;
|
---|
974 | testYMax=0;
|
---|
975 | if isfield(ObjectData,'RangeX')
|
---|
976 | XMin=min(ObjectData.RangeX);
|
---|
977 | XMax=max(ObjectData.RangeX);
|
---|
978 | testXMin=XMax>XMin;
|
---|
979 | testXMax=1;
|
---|
980 | end
|
---|
981 | if isfield(ObjectData,'RangeY')
|
---|
982 | YMin=min(ObjectData.RangeY);
|
---|
983 | YMax=max(ObjectData.RangeY);
|
---|
984 | testYMin=YMax>YMin;
|
---|
985 | testYMax=1;
|
---|
986 | end
|
---|
987 | width=0;%default width of the projection band
|
---|
988 | if isfield(ObjectData,'RangeZ')
|
---|
989 | width=max(ObjectData.RangeZ);
|
---|
990 | end
|
---|
991 |
|
---|
992 | % initiate Matlab structure for physical field
|
---|
993 | ProjData=proj_heading(FieldData,ObjectData);
|
---|
994 | ProjData.NbDim=2;
|
---|
995 | ProjData.ListVarName={};
|
---|
996 | ProjData.VarDimName={};
|
---|
997 |
|
---|
998 | error=0;%default
|
---|
999 | flux=0;
|
---|
1000 | testfalse=0;
|
---|
1001 | ListIndex={};
|
---|
1002 |
|
---|
1003 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
---|
1004 | %group the variables (fields of 'FieldData') in cells of variables with the same dimensions
|
---|
1005 | %-----------------------------------------------------------------
|
---|
1006 | idimvar=0;
|
---|
1007 | [CellVarIndex,NbDim,VarTypeCell,errormsg]=find_field_indices(FieldData);
|
---|
1008 | if ~isempty(errormsg)
|
---|
1009 | errormsg=['error in proj_field/proj_plane:' errormsg];
|
---|
1010 | return
|
---|
1011 | end
|
---|
1012 | %LOOP ON GROUPS OF VARIABLES SHARING THE SAME DIMENSIONS
|
---|
1013 | % CellVarIndex=cells of variable index arrays
|
---|
1014 | ivar_new=0; % index of the current variable in the projected field
|
---|
1015 | icoord=0;
|
---|
1016 | nbcoord=0;%number of added coordinate variables brought by projection
|
---|
1017 | for icell=1:length(CellVarIndex)
|
---|
1018 | if NbDim(icell)<2
|
---|
1019 | continue
|
---|
1020 | end
|
---|
1021 | VarIndex=CellVarIndex{icell};% indices of the selected variables in the list FieldData.ListVarName
|
---|
1022 | VarType=VarTypeCell{icell};
|
---|
1023 | ivar_X=VarType.coord_x;
|
---|
1024 | ivar_Y=VarType.coord_y;
|
---|
1025 | ivar_Z=VarType.coord_z;
|
---|
1026 | ivar_U=VarType.vector_x;
|
---|
1027 | ivar_V=VarType.vector_y;
|
---|
1028 | ivar_W=VarType.vector_z;
|
---|
1029 | ivar_C=VarType.scalar ;
|
---|
1030 | ivar_Anc=VarType.ancillary;
|
---|
1031 | test_anc=zeros(size(VarIndex));
|
---|
1032 | test_anc(ivar_Anc)=ones(size(ivar_Anc));
|
---|
1033 | ivar_F=VarType.warnflag;
|
---|
1034 | ivar_FF=VarType.errorflag;
|
---|
1035 | testX=~isempty(ivar_X) && ~isempty(ivar_Y);
|
---|
1036 | %DimIndices=FieldData.VarDimIndex{VarIndex(1)};%indices of the dimensions of the first variable (common to all variables in the cell)
|
---|
1037 | DimCell=FieldData.VarDimName{VarIndex(1)};
|
---|
1038 | if ischar(DimCell)
|
---|
1039 | DimCell={DimCell};%name of dimensions
|
---|
1040 | end
|
---|
1041 |
|
---|
1042 | %case of input fields with unstructured coordinates
|
---|
1043 | if testX
|
---|
1044 | XName=FieldData.ListVarName{ivar_X};
|
---|
1045 | YName=FieldData.ListVarName{ivar_Y};
|
---|
1046 | eval(['coord_x=FieldData.' XName ';'])
|
---|
1047 | eval(['coord_y=FieldData.' YName ';'])
|
---|
1048 | if length(ivar_Z)==1
|
---|
1049 | ZName=FieldData.ListVarName{ivar_Z};
|
---|
1050 | eval(['coord_z=FieldData.' ZName ';'])
|
---|
1051 | end
|
---|
1052 |
|
---|
1053 | % translate initial coordinates
|
---|
1054 | coord_x=coord_x-ObjectData.Coord(1,1);
|
---|
1055 | coord_y=coord_y-ObjectData.Coord(1,2);
|
---|
1056 | if ~isempty(ivar_Z)
|
---|
1057 | coord_z=coord_z-ObjectData.Coord(1,3);
|
---|
1058 | end
|
---|
1059 |
|
---|
1060 | % selection of the vectors in the projection range (3D case)
|
---|
1061 | if length(ivar_Z)==1 && width > 0
|
---|
1062 | %components of the unitiy vector normal to the projection plane
|
---|
1063 | fieldZ=NormVec_X*coord_x + NormVec_Y*coord_y+ NormVec_Z*coord_z;% distance to the plane
|
---|
1064 | indcut=find(abs(fieldZ) <= width);
|
---|
1065 | for ivar=VarIndex
|
---|
1066 | VarName=FieldData.ListVarName{ivar};
|
---|
1067 | % eval(['size(FieldData.' VarName ')'])
|
---|
1068 | eval(['FieldData.' VarName '=FieldData.' VarName '(indcut);'])
|
---|
1069 | % end
|
---|
1070 | % A VOIR : CAS DE VAR STRUCTUREE MAIS PAS GRILLE REGULIERE : INTERPOLER SUR GRILLE REGULIERE
|
---|
1071 | end
|
---|
1072 | coord_x=coord_x(indcut);
|
---|
1073 | coord_y=coord_y(indcut);
|
---|
1074 | coord_z=coord_z(indcut);
|
---|
1075 | end
|
---|
1076 |
|
---|
1077 | %rotate coordinates if needed
|
---|
1078 | if isequal(Phi,0)
|
---|
1079 | coord_X=coord_x;
|
---|
1080 | coord_Y=coord_y;
|
---|
1081 | if ~isequal(Theta,0)
|
---|
1082 | coord_Y=coord_Y *cos(Theta);
|
---|
1083 | end
|
---|
1084 | else
|
---|
1085 | coord_X=(coord_x *cos(Phi) + coord_y* sin(Phi));
|
---|
1086 | coord_Y=(-coord_x *sin(Phi) + coord_y *cos(Phi))*cos(Theta);
|
---|
1087 | end
|
---|
1088 | if ~isempty(ivar_Z)
|
---|
1089 | coord_Y=coord_Y+coord_z *sin(Theta);
|
---|
1090 | end
|
---|
1091 | if ~isequal(Psi,0)
|
---|
1092 | coord_X=(coord_X *cos(Psi) - coord_Y* sin(Psi));%A VERIFIER
|
---|
1093 | coord_Y=(coord_X *sin(Psi) + coord_Y* cos(Psi));
|
---|
1094 | end
|
---|
1095 |
|
---|
1096 | %restriction to the range of x and y if imposed
|
---|
1097 | testin=ones(size(coord_X)); %default
|
---|
1098 | testbound=0;
|
---|
1099 | if testXMin
|
---|
1100 | testin=testin & (coord_X >= XMin);
|
---|
1101 | testbound=1;
|
---|
1102 | end
|
---|
1103 | if testXMax
|
---|
1104 | testin=testin & (coord_X <= XMax);
|
---|
1105 | testbound=1;
|
---|
1106 | end
|
---|
1107 | if testYMin
|
---|
1108 | testin=testin & (coord_Y >= YMin);
|
---|
1109 | testbound=1;
|
---|
1110 | end
|
---|
1111 | if testYMin
|
---|
1112 | testin=testin & (coord_Y <= YMax);
|
---|
1113 | testbound=1;
|
---|
1114 | end
|
---|
1115 | if testbound
|
---|
1116 | indcut=find(testin);
|
---|
1117 | for ivar=VarIndex
|
---|
1118 | VarName=FieldData.ListVarName{ivar};
|
---|
1119 | eval(['FieldData.' VarName '=FieldData.' VarName '(indcut);'])
|
---|
1120 | end
|
---|
1121 | coord_X=coord_X(indcut);
|
---|
1122 | coord_Y=coord_Y(indcut);
|
---|
1123 | if length(ivar_Z)==1
|
---|
1124 | coord_Z=coord_Z(indcut);
|
---|
1125 | end
|
---|
1126 | end
|
---|
1127 | % different cases of projection
|
---|
1128 | if isequal(ObjectData.ProjMode,'projection')
|
---|
1129 | %the list of dimension
|
---|
1130 | %ProjData.ListDimName=[ProjData.ListDimName FieldData.VarDimName(VarIndex(1))];%add the point index to the list of dimensions
|
---|
1131 | %ProjData.DimValue=[ProjData.
|
---|
1132 | %length(coord_X)];
|
---|
1133 | nbvar=0;
|
---|
1134 | for ivar=VarIndex %transfer variables to the projection plane
|
---|
1135 | VarName=FieldData.ListVarName{ivar};
|
---|
1136 | if ivar==ivar_X %x coordinate
|
---|
1137 | eval(['ProjData.' VarName '=coord_X;'])
|
---|
1138 | elseif ivar==ivar_Y % y coordinate
|
---|
1139 | eval(['ProjData.' VarName '=coord_Y;'])
|
---|
1140 | elseif isempty(ivar_Z) || ivar~=ivar_Z % other variables (except Z coordinate wyhich is not reproduced)
|
---|
1141 | eval(['ProjData.' VarName '=FieldData.' VarName ';'])
|
---|
1142 | end
|
---|
1143 | if isempty(ivar_Z) || ivar~=ivar_Z
|
---|
1144 | ProjData.ListVarName=[ProjData.ListVarName VarName];
|
---|
1145 | ProjData.VarDimName=[ProjData.VarDimName DimCell];
|
---|
1146 | nbvar=nbvar+1;
|
---|
1147 | if isfield(FieldData,'VarAttribute') & length(FieldData.VarAttribute) >=ivar
|
---|
1148 | ProjData.VarAttribute{nbvar}=FieldData.VarAttribute{ivar};
|
---|
1149 | end
|
---|
1150 | end
|
---|
1151 | end
|
---|
1152 | elseif isequal(ObjectData.ProjMode,'interp')||isequal(ObjectData.ProjMode,'filter')%interpolate data on a regular grid
|
---|
1153 | coord_x_proj=[XMin:DX:XMax];
|
---|
1154 | coord_y_proj=[YMin:DY:YMax];
|
---|
1155 | DimCell={'coord_y','coord_x'};
|
---|
1156 | ProjData.ListVarName={'coord_y','coord_x'};
|
---|
1157 | ProjData.VarDimName={'coord_y','coord_x'};
|
---|
1158 | nbcoord=2;
|
---|
1159 | ProjData.coord_y=[YMin YMax];
|
---|
1160 | ProjData.coord_x=[XMin XMax];
|
---|
1161 | if isempty(ivar_X), ivar_X=0; end;
|
---|
1162 | if isempty(ivar_Y), ivar_Y=0; end;
|
---|
1163 | if isempty(ivar_Z), ivar_Z=0; end;
|
---|
1164 | if isempty(ivar_U), ivar_U=0; end;
|
---|
1165 | if isempty(ivar_V), ivar_V=0; end;
|
---|
1166 | if isempty(ivar_W), ivar_W=0; end;
|
---|
1167 | if isempty(ivar_F), ivar_F=0; end;
|
---|
1168 | if isempty(ivar_FF), ivar_FF=0; end;
|
---|
1169 | if ~isequal(ivar_FF,0)
|
---|
1170 | VarName_FF=FieldData.ListVarName{ivar_FF};
|
---|
1171 | eval(['indsel=find(FieldData.' VarName_FF '==0);'])
|
---|
1172 | coord_X=coord_X(indsel);
|
---|
1173 | coord_Y=coord_Y(indsel);
|
---|
1174 | end
|
---|
1175 | FF=zeros(1,length(coord_y_proj)*length(coord_x_proj));
|
---|
1176 | testFF=0;
|
---|
1177 | for ivar=VarIndex
|
---|
1178 | VarName=FieldData.ListVarName{ivar};
|
---|
1179 | if ~( ivar==ivar_X || ivar==ivar_Y || ivar==ivar_Z || ivar==ivar_F || ivar==ivar_FF || test_anc(ivar)==1)
|
---|
1180 | ivar_new=ivar_new+1;
|
---|
1181 | ProjData.ListVarName=[ProjData.ListVarName {VarName}];
|
---|
1182 | ProjData.VarDimName=[ProjData.VarDimName {DimCell}];
|
---|
1183 | if isfield(FieldData,'VarAttribute') && length(FieldData.VarAttribute) >=ivar
|
---|
1184 | ProjData.VarAttribute{ivar_new+nbcoord}=FieldData.VarAttribute{ivar};
|
---|
1185 | end
|
---|
1186 | if ~isequal(ivar_FF,0)
|
---|
1187 | eval(['FieldData.' VarName '=FieldData.' VarName '(indsel);'])
|
---|
1188 | end
|
---|
1189 | eval(['ProjData.' VarName '=griddata_uvmat(double(coord_X),double(coord_Y),double(FieldData.' VarName '),coord_x_proj,coord_y_proj'');'])
|
---|
1190 | eval(['varline=reshape(ProjData.' VarName ',1,length(coord_y_proj)*length(coord_x_proj));'])
|
---|
1191 | FFlag= isnan(varline); %detect undefined values NaN
|
---|
1192 | indnan=find(FFlag);
|
---|
1193 | if~isempty(indnan)
|
---|
1194 | varline(indnan)=zeros(size(indnan));
|
---|
1195 | eval(['ProjData.' VarName '=reshape(varline,length(coord_y_proj),length(coord_x_proj));'])
|
---|
1196 | FF(indnan)=ones(size(indnan));
|
---|
1197 | testFF=1;
|
---|
1198 | end
|
---|
1199 | if ivar==ivar_U
|
---|
1200 | ivar_U=ivar_new;
|
---|
1201 | end
|
---|
1202 | if ivar==ivar_V
|
---|
1203 | ivar_V=ivar_new;
|
---|
1204 | end
|
---|
1205 | if ivar==ivar_W
|
---|
1206 | ivar_W=ivar_new;
|
---|
1207 | end
|
---|
1208 | end
|
---|
1209 | end
|
---|
1210 | if testFF
|
---|
1211 | ProjData.FF=reshape(FF,length(coord_y_proj),length(coord_x_proj));
|
---|
1212 | ProjData.ListVarName=[ProjData.ListVarName {'FF'}];
|
---|
1213 | ProjData.VarDimName=[ProjData.VarDimName {DimCell}];
|
---|
1214 | ProjData.VarAttribute{ivar_new+1+nbcoord}.Role='errorflag';
|
---|
1215 | end
|
---|
1216 | end
|
---|
1217 | %case of input fields defined on a structured grid
|
---|
1218 | else
|
---|
1219 | AYName=FieldData.ListVarName{VarType.coord(1)};%name of input x coordinate (name preserved on projection)
|
---|
1220 | AXName=FieldData.ListVarName{VarType.coord(2)};%name of input y coordinate (name preserved on projection)
|
---|
1221 | eval(['AX=FieldData.' AXName ';'])
|
---|
1222 | eval(['AY=FieldData.' AYName ';'])
|
---|
1223 | VarName=FieldData.ListVarName{VarIndex(1)};%get the first variable of the cell to get the input matrix dimensions
|
---|
1224 | eval(['DimValue=size(FieldData.' VarName ');'])%input matrix dimensions
|
---|
1225 | ListDimName=FieldData.VarDimName{VarIndex(1)};
|
---|
1226 | ProjData.ListVarName=[{AYName} {AXName} ProjData.ListVarName]; %TODO: check if it already exists in Projdata (several cells)
|
---|
1227 | ProjData.VarDimName=[{AYName} {AXName} ProjData.VarDimName];
|
---|
1228 | nbcolor=1; %default
|
---|
1229 | for idim=1:length(ListDimName)
|
---|
1230 | DimName=ListDimName{idim};
|
---|
1231 | if strcmp(DimName,'rgb')||strcmp(DimName,'nb_coord')||strcmp(DimName,'nb_coord_i')
|
---|
1232 | nbcolor=DimValue(idim);
|
---|
1233 | DimValue(idim)=[];
|
---|
1234 | end
|
---|
1235 | if isequal(DimName,'nb_coord_j')% NOTE: CASE OF TENSOR NOT TREATED
|
---|
1236 | DimValue(idim)=[];
|
---|
1237 | end
|
---|
1238 | end
|
---|
1239 | ind_1=find(DimValue==1);
|
---|
1240 | Coord_z=[];
|
---|
1241 | Coord_y=[];
|
---|
1242 | Coord_x=[];
|
---|
1243 | nb_dim=numel(size(DimValue));
|
---|
1244 | for idim=1:nb_dim %loop on space dimensions
|
---|
1245 | test_interp(idim)=0;%test for coordiate interpolation (non regular grid), =0 by default
|
---|
1246 | ivar=VarType.coord(idim);% index of the variable corresponding to the current dimension
|
---|
1247 | if ~isequal(ivar,0)% a variable corresponds to the dimension #idim
|
---|
1248 | eval(['Coord{idim}=FieldData.' FieldData.ListVarName{ivar} ';']) ;% coord values for the input field
|
---|
1249 | if numel(Coord{idim})==2 %input array defined on a regular grid
|
---|
1250 | DCoord_min(idim)=(Coord{idim}(2)-Coord{idim}(1))/DimValue(idim);
|
---|
1251 | else
|
---|
1252 | DCoord=diff(Coord{idim});%array of coordinate derivatives for the input field
|
---|
1253 | DCoord_min(idim)=min(DCoord);
|
---|
1254 | DCoord_max=max(DCoord);
|
---|
1255 | % test_direct(idim)=DCoord_max>0;% =1 for increasing values, 0 otherwise
|
---|
1256 | if ~isequal(DCoord_max,DCoord_min(idim)>0)
|
---|
1257 | msgbox_uvmat('ERROR',['non monotonic dimension variable # ' num2str(idim) ' in proj_field.m'])
|
---|
1258 | return
|
---|
1259 | end
|
---|
1260 | test_interp(idim)=(DCoord_max-DCoord_min(idim))> 0.0001*abs(DCoord_max);% test grid regularity
|
---|
1261 | end
|
---|
1262 | test_direct(idim)=(DCoord_min(idim)>0);
|
---|
1263 | else % no variable associated with the dimension #idim, the coordinate value is set equal to the matrix index by default
|
---|
1264 | Coord_i_str=['Coord_' num2str(idim)];
|
---|
1265 | DCoord_min(idim)=1;%default
|
---|
1266 | Coord{idim}=[0.5 DimValue(idim)-0.5];
|
---|
1267 | test_direct(idim)=1;
|
---|
1268 | end
|
---|
1269 | end
|
---|
1270 | if DY==0
|
---|
1271 | DY=abs(DCoord_min(nb_dim-1));
|
---|
1272 | end
|
---|
1273 | npY=1+round(abs(Coord{nb_dim-1}(end)-Coord{nb_dim-1}(1))/DY);%nbre of points after interpol
|
---|
1274 | if DX==0
|
---|
1275 | DX=abs(DCoord_min(nb_dim));
|
---|
1276 | end
|
---|
1277 | npX=1+round(abs(Coord{nb_dim}(end)-Coord{nb_dim}(1))/DX);%nbre of points after interpol
|
---|
1278 | for idim=[1:nb_dim]
|
---|
1279 | if test_interp(idim)
|
---|
1280 | 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
|
---|
1281 | end
|
---|
1282 | end
|
---|
1283 | Coord_y=linspace(Coord{nb_dim-1}(1),Coord{nb_dim-1}(end),npY);
|
---|
1284 | test_direct_y=test_direct(nb_dim-1);
|
---|
1285 | Coord_x=linspace(Coord{nb_dim}(1),Coord{nb_dim}(end),npX);
|
---|
1286 | test_direct_x=test_direct(nb_dim);
|
---|
1287 | DAX=DCoord_min(nb_dim);
|
---|
1288 | DAY=DCoord_min(nb_dim-1);
|
---|
1289 | if nb_dim==3
|
---|
1290 | DZ=abs(DCoord_min(1));
|
---|
1291 | Coord_z=linspace(Coord{1}(1),Coord{1}(end),npz);
|
---|
1292 | test_direct_z=test_direct(1);
|
---|
1293 | end
|
---|
1294 | minAX=min(Coord_x);
|
---|
1295 | maxAX=max(Coord_x);
|
---|
1296 | minAY=min(Coord_y);
|
---|
1297 | maxAY=max(Coord_y);
|
---|
1298 | xcorner=[minAX maxAX minAX maxAX]-ObjectData.Coord(1,1);
|
---|
1299 | ycorner=[maxAY maxAY minAY minAY]-ObjectData.Coord(1,2);
|
---|
1300 | xcor_new=xcorner*cos(Phi)+ycorner*sin(Phi);%coord new frame
|
---|
1301 | ycor_new=-xcorner*sin(Phi)+ycorner*cos(Phi);
|
---|
1302 | if ~testXMax
|
---|
1303 | XMax=max(xcor_new);
|
---|
1304 | end
|
---|
1305 | if ~testXMin
|
---|
1306 | XMin=min(xcor_new);
|
---|
1307 | end
|
---|
1308 | if ~testYMax
|
---|
1309 | YMax=max(ycor_new);
|
---|
1310 | end
|
---|
1311 | if ~testYMin
|
---|
1312 | YMin=min(ycor_new);
|
---|
1313 | end
|
---|
1314 | DXinit=(maxAX-minAX)/(DimValue(2)-1);
|
---|
1315 | DYinit=(maxAY-minAY)/(DimValue(1)-1);
|
---|
1316 | if DX==0
|
---|
1317 | DX=DXinit;
|
---|
1318 | end
|
---|
1319 | if DY==0
|
---|
1320 | DY=DYinit;
|
---|
1321 | end
|
---|
1322 | npX=floor((XMax-XMin)/DX+1);
|
---|
1323 | npY=floor((YMax-YMin)/DY+1);
|
---|
1324 | if test_direct_y
|
---|
1325 | coord_y_proj=linspace(YMin,YMax,npY);%abscissa of the new pixels along the line
|
---|
1326 | else
|
---|
1327 | coord_y_proj=linspace(YMax,YMin,npY);%abscissa of the new pixels along the line
|
---|
1328 | end
|
---|
1329 | if test_direct_x
|
---|
1330 | coord_x_proj=linspace(XMin,XMax,npX);%abscissa of the new pixels along the line
|
---|
1331 | else
|
---|
1332 | coord_x_proj=linspace(XMax,XMin,npX);%abscissa of the new pixels along the line
|
---|
1333 | end
|
---|
1334 |
|
---|
1335 | % case with no rotation and interpolation
|
---|
1336 | if isequal(ProjMode,'projection') && isequal(Phi,0) && isequal(Theta,0) && isequal(Psi,0)
|
---|
1337 | if test_direct(1)
|
---|
1338 | min_ind1=ceil((YMin-Coord{1}(1))/DYinit)+1;
|
---|
1339 | max_ind1=floor((YMax-Coord{1}(1))/DYinit)+1;
|
---|
1340 | Ybound(1)=Coord{1}(1)+DYinit*(min_ind1-1);
|
---|
1341 | Ybound(2)=Coord{1}(1)+DYinit*(max_ind1-1);
|
---|
1342 | else
|
---|
1343 | min_ind1=ceil((Coord{1}(1)-YMax)/DYinit)+1;
|
---|
1344 | max_ind1=floor((Coord{1}(1)-YMin)/DYinit)+1;
|
---|
1345 | Ybound(2)=Coord{1}(1)-DYinit*(max_ind1-1);
|
---|
1346 | Ybound(1)=Coord{1}(1)-DYinit*(min_ind1-1);
|
---|
1347 | end
|
---|
1348 | if test_direct(2)==1
|
---|
1349 | min_ind2=ceil((XMin-Coord{2}(1))/DXinit)+1;
|
---|
1350 | max_ind2=floor((XMax-Coord{2}(1))/DXinit)+1;
|
---|
1351 | Xbound(1)=Coord{2}(1)+DXinit*(min_ind2-1);
|
---|
1352 | Xbound(2)=Coord{2}(1)+DXinit*(max_ind2-1);
|
---|
1353 | else
|
---|
1354 | min_ind2=ceil((Coord{2}(1)-XMax)/DXinit)+1;
|
---|
1355 | max_ind2=floor((Coord{2}(1)-XMin)/DXinit)+1;
|
---|
1356 | Xbound(2)=Coord{2}(1)+DXinit*(max_ind2-1);
|
---|
1357 | Xbound(1)=Coord{2}(1)+DXinit*(min_ind2-1);
|
---|
1358 | end
|
---|
1359 | min_ind1=max(min_ind1,1);% deals with margin (bound lower than the first index)
|
---|
1360 | min_ind2=max(min_ind2,1);
|
---|
1361 | max_ind1=min(max_ind1,DimValue(1));
|
---|
1362 | max_ind2=min(max_ind2,DimValue(2));
|
---|
1363 | for ivar=VarIndex
|
---|
1364 | VarName=FieldData.ListVarName{ivar};
|
---|
1365 | ProjData.ListVarName=[ProjData.ListVarName VarName];
|
---|
1366 | ProjData.VarDimName=[ProjData.VarDimName {DimCell}];
|
---|
1367 | if length(FieldData.VarAttribute)>=ivar
|
---|
1368 | ProjData.VarAttribute{length(ProjData.ListVarName)}=FieldData.VarAttribute{ivar};
|
---|
1369 | end
|
---|
1370 | eval(['ProjData.' VarName '=FieldData.' VarName '(min_ind1:max_ind1,min_ind2:max_ind2) ;']);
|
---|
1371 | end
|
---|
1372 | else % case with rotation and/or interpolation
|
---|
1373 | if isempty(Coord_z) %2D case
|
---|
1374 | [X,Y]=meshgrid(coord_x_proj,coord_y_proj);%grid in the new coordinates
|
---|
1375 | XIMA=ObjectData.Coord(1,1)+(X)*cos(Phi)-Y*sin(Phi);%corresponding coordinates in the original image
|
---|
1376 | YIMA=ObjectData.Coord(1,2)+(X)*sin(Phi)+Y*cos(Phi);
|
---|
1377 | XIMA=(XIMA-minAX)/DXinit+1;% image index along x
|
---|
1378 | YIMA=(-YIMA+maxAY)/DYinit+1;% image index along y
|
---|
1379 | XIMA=reshape(round(XIMA),1,npX*npY);%indices reorganized in 'line'
|
---|
1380 | YIMA=reshape(round(YIMA),1,npX*npY);
|
---|
1381 | flagin=XIMA>=1 & XIMA<=DimValue(2) & YIMA >=1 & YIMA<=DimValue(1);%flagin=1 inside the original image
|
---|
1382 | if isequal(ObjectData.ProjMode,'filter')
|
---|
1383 | npx_filter=ceil(abs(DX/DAX));
|
---|
1384 | npy_filter=ceil(abs(DY/DAY));
|
---|
1385 | Mfilter=ones(npy_filter,npx_filter)/(npx_filter*npy_filter);
|
---|
1386 | test_filter=1;
|
---|
1387 | else
|
---|
1388 | test_filter=0;
|
---|
1389 | end
|
---|
1390 | eval(['ProjData.' AYName '=[coord_y_proj(1) coord_y_proj(end)];']) %record the new (projected ) y coordinates
|
---|
1391 | eval(['ProjData.' AXName '=[coord_x_proj(1) coord_x_proj(end)];']) %record the new (projected ) x coordinates
|
---|
1392 | for ivar=VarIndex
|
---|
1393 | VarName=FieldData.ListVarName{ivar};
|
---|
1394 | if test_interp(1) || test_interp(2)%interpolate on a regular grid
|
---|
1395 | eval(['ProjData.' VarName '=interp2(Coord{2},Coord{1},FieldData.' VarName ',Coord_x,Coord_y'');']) %TO TEST
|
---|
1396 | end
|
---|
1397 | %filter the field (image) if option 'filter' is used
|
---|
1398 | if test_filter
|
---|
1399 | Aclass=class(FieldData.A);
|
---|
1400 | eval(['ProjData.' VarName '=filter2(Mfilter,FieldData.' VarName ',''valid'');'])
|
---|
1401 | if ~isequal(Aclass,'double')
|
---|
1402 | eval(['ProjData.' VarName '=' Aclass '(FieldData.' VarName ');'])%revert to integer values
|
---|
1403 | end
|
---|
1404 | end
|
---|
1405 | eval(['vec_A=reshape(FieldData.' VarName ',[],nbcolor);'])%put the original image in line
|
---|
1406 | ind_in=find(flagin);
|
---|
1407 | ind_out=find(~flagin);
|
---|
1408 | ICOMB=(XIMA-1)*DimValue(1)+YIMA;
|
---|
1409 | ICOMB=ICOMB(flagin);%index corresponding to XIMA and YIMA in the aligned original image vec_A
|
---|
1410 | vec_B(ind_in,[1:nbcolor])=vec_A(ICOMB,:);
|
---|
1411 | for icolor=1:nbcolor
|
---|
1412 | vec_B(ind_out,icolor)=zeros(size(ind_out));
|
---|
1413 | end
|
---|
1414 | ProjData.ListVarName=[ProjData.ListVarName VarName];
|
---|
1415 | ProjData.VarDimName=[ProjData.VarDimName {DimCell}];
|
---|
1416 | if isfield(FieldData,'VarAttribute')&&length(FieldData.VarAttribute)>=ivar
|
---|
1417 | ProjData.VarAttribute{length(ProjData.ListVarName)+nbcoord}=FieldData.VarAttribute{ivar};
|
---|
1418 | end
|
---|
1419 | eval(['ProjData.' VarName '=reshape(vec_B,npY,npX,nbcolor);']);
|
---|
1420 | end
|
---|
1421 | ProjData.FF=reshape(~flagin,npY,npX);%false flag A FAIRE: tenir compte d'un flga antérieur
|
---|
1422 | ProjData.ListVarName=[ProjData.ListVarName 'FF'];
|
---|
1423 | ProjData.VarDimName=[ProjData.VarDimName {DimCell}];
|
---|
1424 | ProjData.VarAttribute{length(ProjData.ListVarName)}.Role='errorflag';
|
---|
1425 | else %3D case
|
---|
1426 | if isequal(Theta,0) & isequal(Phi,0)
|
---|
1427 | test_sup=(Coord{1}>=ObjectData.Coord(1,3));
|
---|
1428 | iz_sup=find(test_sup);
|
---|
1429 | iz=iz_sup(1);
|
---|
1430 | if iz>=1 & iz<=npz
|
---|
1431 | %ProjData.ListDimName=[ProjData.ListDimName ListDimName(2:end)];
|
---|
1432 | %ProjData.DimValue=[ProjData.DimValue npY npX];
|
---|
1433 | for ivar=VarIndex
|
---|
1434 | VarName=FieldData.ListVarName{ivar};
|
---|
1435 | ProjData.ListVarName=[ProjData.ListVarName VarName];
|
---|
1436 | ProjData.VarAttribute{length(ProjData.ListVarName)}=FieldData.VarAttribute{ivar}; %reproduce the variable attributes
|
---|
1437 | eval(['ProjData.' VarName '=squeeze(FieldData.' VarName '(iz,:,:));'])% select the z index iz
|
---|
1438 | %TODO : do a vertical average for a thick plane
|
---|
1439 | if test_interp(2) | test_interp(3)
|
---|
1440 | eval(['ProjData.' VarName '=interp2(Coord{3},Coord{2},ProjData.' VarName ',Coord_x,Coord_y'');'])
|
---|
1441 | end
|
---|
1442 | end
|
---|
1443 | end
|
---|
1444 | else
|
---|
1445 | errormsg='projection of structured coordinates on oblique plane not yet implemented';
|
---|
1446 | %TODO: use interp3
|
---|
1447 | return
|
---|
1448 | end
|
---|
1449 | end
|
---|
1450 | end
|
---|
1451 | end
|
---|
1452 | %projection of velocity components in the rotated coordinates
|
---|
1453 | if ~isequal(Phi,0) && length(ivar_U)==1
|
---|
1454 | if isempty(ivar_V)
|
---|
1455 | msgbox_uvmat('ERROR','v velocity component missing in proj_field.m')
|
---|
1456 | return
|
---|
1457 | end
|
---|
1458 | UName=FieldData.ListVarName{ivar_U};
|
---|
1459 | VName=FieldData.ListVarName{ivar_V};
|
---|
1460 | eval(['ProjData.' UName '=cos(Phi)*ProjData.' UName '+ sin(Phi)*ProjData.' VName ';'])
|
---|
1461 | eval(['ProjData.' VName '=cos(Theta)*(-sin(Phi)*ProjData.' UName '+ cos(Phi)*ProjData.' VName ');'])
|
---|
1462 | if ~isempty(ivar_W)
|
---|
1463 | WName=FieldData.ListVarName{ivar_W};
|
---|
1464 | eval(['ProjData.' VName '=ProjData.' VName '+ ProjData.' WName '*sin(Theta);'])%
|
---|
1465 | eval(['ProjData.' WName '=NormVec_X*ProjData.' UName '+ NormVec_Y*ProjData.' VName '+ NormVec_Z* ProjData.' WName ';']);
|
---|
1466 | end
|
---|
1467 | if ~isequal(Psi,0)
|
---|
1468 | eval(['ProjData.' UName '=cos(Psi)* ProjData.' UName '- sin(Psi)*ProjData.' VName ';']);
|
---|
1469 | eval(['ProjData.' VName '=sin(Psi)* ProjData.' UName '+ cos(Psi)*ProjData.' VName ';']);
|
---|
1470 | end
|
---|
1471 | end
|
---|
1472 | end
|
---|
1473 |
|
---|
1474 | %-----------------------------------------------------------------
|
---|
1475 | %project in a volume
|
---|
1476 | % A FAIRE ....(copie de proj_plane)
|
---|
1477 | function [ProjData,errormsg] = proj_volume(FieldData, ObjectData)
|
---|
1478 | %-----------------------------------------------------------------
|
---|
1479 |
|
---|
1480 | %initialisation of the input parameters of the projection plane
|
---|
1481 | %-----------------------------------------------------------------
|
---|
1482 | ProjMode='projection';%direct projection by default
|
---|
1483 | if isfield(ObjectData,'ProjMode'),ProjMode=ObjectData.ProjMode; end;
|
---|
1484 |
|
---|
1485 | %axis origin
|
---|
1486 | if isempty(ObjectData.Coord)
|
---|
1487 | ObjectData.Coord(1,1)=0;%origin of the volume set to [0 0] by default
|
---|
1488 | ObjectData.Coord(1,2)=0;
|
---|
1489 | ObjectData.Coord(1,3)=0;
|
---|
1490 | end
|
---|
1491 |
|
---|
1492 | %rotation angles
|
---|
1493 | Phi=0;%default
|
---|
1494 | Theta=0;
|
---|
1495 | Psi=0;
|
---|
1496 | if isfield(ObjectData,'Phi')&& ~isempty(ObjectData.Phi)
|
---|
1497 | Phi=(pi/180)*ObjectData.Phi;%first Euler angle in radian
|
---|
1498 | end
|
---|
1499 | if isfield(ObjectData,'Theta')&& ~isempty(ObjectData.Theta)
|
---|
1500 | Theta=(pi/180)*ObjectData.Theta;%second Euler angle in radian
|
---|
1501 | end
|
---|
1502 | if isfield(ObjectData,'Psi')&& ~isempty(ObjectData.Psi)
|
---|
1503 | Psi=(pi/180)*ObjectData.Psi;%third Euler angle in radian
|
---|
1504 | end
|
---|
1505 |
|
---|
1506 | %components of the unity vector normal to the projection plane
|
---|
1507 | NormVec_X=-sin(Phi)*sin(Theta);
|
---|
1508 | NormVec_Y=cos(Phi)*sin(Theta);
|
---|
1509 | NormVec_Z=cos(Theta);
|
---|
1510 |
|
---|
1511 | % test for 3D fields
|
---|
1512 | test3D=0;
|
---|
1513 | if isfield(FieldData,'nb_dim')
|
---|
1514 | test3D=isequal(FieldData.nb_dim,3);
|
---|
1515 | end
|
---|
1516 | test3C=test3D; %default 3 vel components
|
---|
1517 |
|
---|
1518 | %mesh sizes DX and DY
|
---|
1519 | DX=0;
|
---|
1520 | DY=0; %default
|
---|
1521 | if isfield(ObjectData,'DX')&~isempty(ObjectData.DX)
|
---|
1522 | DX=abs(ObjectData.DX);%mesh of interpolation points
|
---|
1523 | end
|
---|
1524 | if isfield(ObjectData,'DY')&~isempty(ObjectData.DY)
|
---|
1525 | DY=abs(ObjectData.DY);%mesh of interpolation points
|
---|
1526 | end
|
---|
1527 | if ~isequal(ProjMode,'projection') & (DX==0|DY==0)
|
---|
1528 | errormsg='DX or DY missing';
|
---|
1529 | display(errormsg)
|
---|
1530 | return
|
---|
1531 | end
|
---|
1532 | if isfield(ObjectData,'DZ')&~isempty(ObjectData.DZ)
|
---|
1533 | DZ=abs(ObjectData.DZ);%mesh of interpolation points
|
---|
1534 | end
|
---|
1535 |
|
---|
1536 | %extrema along each axis
|
---|
1537 | testXMin=0;
|
---|
1538 | testXMax=0;
|
---|
1539 | testYMin=0;
|
---|
1540 | testYMax=0;
|
---|
1541 | if isfield(ObjectData,'RangeX')
|
---|
1542 | XMin=min(ObjectData.RangeX);
|
---|
1543 | XMax=max(ObjectData.RangeX);
|
---|
1544 | testXMin=XMax>XMin;
|
---|
1545 | testXMax=1;
|
---|
1546 | end
|
---|
1547 | if isfield(ObjectData,'RangeY')
|
---|
1548 | YMin=min(ObjectData.RangeY);
|
---|
1549 | YMax=max(ObjectData.RangeY);
|
---|
1550 | testYMin=YMax>YMin;
|
---|
1551 | testYMax=1;
|
---|
1552 | end
|
---|
1553 | width=0;%default width of the projection band
|
---|
1554 | if isfield(ObjectData,'RangeZ')
|
---|
1555 | ZMin=min(ObjectData.RangeZ);
|
---|
1556 | ZMax=max(ObjectData.RangeZ);
|
---|
1557 | testZMin=YMax>YMin;
|
---|
1558 | testZMax=1;
|
---|
1559 | % width=max(ObjectData.RangeZ);
|
---|
1560 | end
|
---|
1561 |
|
---|
1562 | % initiate Matlab structure for physical field
|
---|
1563 | ProjData=proj_heading(FieldData,ObjectData);
|
---|
1564 | ProjData.NbDim=3;
|
---|
1565 | %ProjData.ListDimName={};%name of dimension
|
---|
1566 | %ProjData.DimValue=[];%values of dimension (nbre of vectors)
|
---|
1567 | ProjData.ListVarName={};
|
---|
1568 | ProjData.VarDimName={};
|
---|
1569 |
|
---|
1570 | error=0;%default
|
---|
1571 | flux=0;
|
---|
1572 | testfalse=0;
|
---|
1573 | ListIndex={};
|
---|
1574 |
|
---|
1575 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
---|
1576 | %group the variables (fields of 'FieldData') in cells of variables with the same dimensions
|
---|
1577 | %-----------------------------------------------------------------
|
---|
1578 | idimvar=0;
|
---|
1579 | [CellVarIndex,NbDim,VarTypeCell,errormsg]=find_field_indices(FieldData);
|
---|
1580 | if ~isempty(errormsg)
|
---|
1581 | errormsg=['error in proj_field/proj_plane:' errormsg];
|
---|
1582 | return
|
---|
1583 | end
|
---|
1584 | %LOOP ON GROUPS OF VARIABLES SHARING THE SAME DIMENSIONS
|
---|
1585 | % CellVarIndex=cells of variable index arrays
|
---|
1586 | ivar_new=0; % index of the current variable in the projected field
|
---|
1587 | icoord=0;
|
---|
1588 | nbcoord=0;%number of added coordinate variables brought by projection
|
---|
1589 | for icell=1:length(CellVarIndex)
|
---|
1590 | if NbDim(icell)<2
|
---|
1591 | continue
|
---|
1592 | end
|
---|
1593 | VarIndex=CellVarIndex{icell};% indices of the selected variables in the list FieldData.ListVarName
|
---|
1594 | VarType=VarTypeCell{icell};
|
---|
1595 | ivar_X=VarType.coord_x;
|
---|
1596 | ivar_Y=VarType.coord_y;
|
---|
1597 | ivar_Z=VarType.coord_z;
|
---|
1598 | ivar_U=VarType.vector_x;
|
---|
1599 | ivar_V=VarType.vector_y;
|
---|
1600 | ivar_W=VarType.vector_z;
|
---|
1601 | ivar_C=VarType.scalar ;
|
---|
1602 | ivar_Anc=VarType.ancillary;
|
---|
1603 | test_anc=zeros(size(VarIndex));
|
---|
1604 | test_anc(ivar_Anc)=ones(size(ivar_Anc));
|
---|
1605 | ivar_F=VarType.warnflag;
|
---|
1606 | ivar_FF=VarType.errorflag;
|
---|
1607 | testX=~isempty(ivar_X) && ~isempty(ivar_Y);
|
---|
1608 | DimCell=FieldData.VarDimName{VarIndex(1)};
|
---|
1609 | if ischar(DimCell)
|
---|
1610 | DimCell={DimCell};%name of dimensions
|
---|
1611 | end
|
---|
1612 |
|
---|
1613 | %case of input fields with unstructured coordinates
|
---|
1614 | if testX
|
---|
1615 | XName=FieldData.ListVarName{ivar_X};
|
---|
1616 | YName=FieldData.ListVarName{ivar_Y};
|
---|
1617 | eval(['coord_x=FieldData.' XName ';'])
|
---|
1618 | eval(['coord_y=FieldData.' YName ';'])
|
---|
1619 | if length(ivar_Z)==1
|
---|
1620 | ZName=FieldData.ListVarName{ivar_Z};
|
---|
1621 | eval(['coord_z=FieldData.' ZName ';'])
|
---|
1622 | end
|
---|
1623 |
|
---|
1624 | % translate initial coordinates
|
---|
1625 | coord_x=coord_x-ObjectData.Coord(1,1);
|
---|
1626 | coord_y=coord_y-ObjectData.Coord(1,2);
|
---|
1627 | if ~isempty(ivar_Z)
|
---|
1628 | coord_z=coord_z-ObjectData.Coord(1,3);
|
---|
1629 | end
|
---|
1630 |
|
---|
1631 | % selection of the vectors in the projection range (3D case)
|
---|
1632 | if length(ivar_Z)==1 && width > 0
|
---|
1633 | %components of the unitiy vector normal to the projection plane
|
---|
1634 | fieldZ=NormVec_X*coord_x + NormVec_Y*coord_y+ NormVec_Z*coord_z;% distance to the plane
|
---|
1635 | indcut=find(abs(fieldZ) <= width);
|
---|
1636 | for ivar=VarIndex
|
---|
1637 | VarName=FieldData.ListVarName{ivar};
|
---|
1638 | eval(['FieldData.' VarName '=FieldData.' VarName '(indcut);'])
|
---|
1639 | % end
|
---|
1640 | % A VOIR : CAS DE VAR STRUCTUREE MAIS PAS GRILLE REGULIERE : INTERPOLER SUR GRILLE REGULIERE
|
---|
1641 | end
|
---|
1642 | coord_x=coord_x(indcut);
|
---|
1643 | coord_y=coord_y(indcut);
|
---|
1644 | coord_z=coord_z(indcut);
|
---|
1645 | end
|
---|
1646 |
|
---|
1647 | %rotate coordinates if needed
|
---|
1648 | if isequal(Phi,0)
|
---|
1649 | coord_X=coord_x;
|
---|
1650 | coord_Y=coord_y;
|
---|
1651 | if ~isequal(Theta,0)
|
---|
1652 | coord_Y=coord_Y *cos(Theta);
|
---|
1653 | end
|
---|
1654 | else
|
---|
1655 | coord_X=(coord_x *cos(Phi) + coord_y* sin(Phi));
|
---|
1656 | coord_Y=(-coord_x *sin(Phi) + coord_y *cos(Phi))*cos(Theta);
|
---|
1657 | end
|
---|
1658 | if ~isempty(ivar_Z)
|
---|
1659 | coord_Y=coord_Y+coord_z *sin(Theta);
|
---|
1660 | end
|
---|
1661 | if ~isequal(Psi,0)
|
---|
1662 | coord_X=(coord_X *cos(Psi) - coord_Y* sin(Psi));%A VERIFIER
|
---|
1663 | coord_Y=(coord_X *sin(Psi) + coord_Y* cos(Psi));
|
---|
1664 | end
|
---|
1665 | coord_Z=coord_z; %TO UPDATE
|
---|
1666 | %restriction to the range of x and y if imposed
|
---|
1667 | testin=ones(size(coord_X)); %default
|
---|
1668 | testbound=0;
|
---|
1669 | if testXMin
|
---|
1670 | testin=testin & (coord_X >= XMin);
|
---|
1671 | testbound=1;
|
---|
1672 | end
|
---|
1673 | if testXMax
|
---|
1674 | testin=testin & (coord_X <= XMax);
|
---|
1675 | testbound=1;
|
---|
1676 | end
|
---|
1677 | if testYMin
|
---|
1678 | testin=testin & (coord_Y >= YMin);
|
---|
1679 | testbound=1;
|
---|
1680 | end
|
---|
1681 | if testYMin
|
---|
1682 | testin=testin & (coord_Y <= YMax);
|
---|
1683 | testbound=1;
|
---|
1684 | end
|
---|
1685 | if testbound
|
---|
1686 | indcut=find(testin);
|
---|
1687 | for ivar=VarIndex
|
---|
1688 | VarName=FieldData.ListVarName{ivar};
|
---|
1689 | eval(['FieldData.' VarName '=FieldData.' VarName '(indcut);'])
|
---|
1690 | end
|
---|
1691 | coord_X=coord_X(indcut);
|
---|
1692 | coord_Y=coord_Y(indcut);
|
---|
1693 | if length(ivar_Z)==1
|
---|
1694 | coord_Z=coord_Z(indcut);
|
---|
1695 | end
|
---|
1696 | end
|
---|
1697 | % different cases of projection
|
---|
1698 | if isequal(ObjectData.ProjMode,'projection')
|
---|
1699 | %the list of dimension
|
---|
1700 | %ProjData.ListDimName=[ProjData.ListDimName FieldData.VarDimName(VarIndex(1))];%add the point index to the list of dimensions
|
---|
1701 | %ProjData.DimValue=[ProjData.DimValue length(coord_X)];
|
---|
1702 | nbvar=0;
|
---|
1703 | for ivar=VarIndex %transfer variables to the projection plane
|
---|
1704 | VarName=FieldData.ListVarName{ivar};
|
---|
1705 | if ivar==ivar_X %x coordinate
|
---|
1706 | eval(['ProjData.' VarName '=coord_X;'])
|
---|
1707 | elseif ivar==ivar_Y % y coordinate
|
---|
1708 | eval(['ProjData.' VarName '=coord_Y;'])
|
---|
1709 | elseif isempty(ivar_Z) || ivar~=ivar_Z % other variables (except Z coordinate wyhich is not reproduced)
|
---|
1710 | eval(['ProjData.' VarName '=FieldData.' VarName ';'])
|
---|
1711 | end
|
---|
1712 | if isempty(ivar_Z) || ivar~=ivar_Z
|
---|
1713 | ProjData.ListVarName=[ProjData.ListVarName VarName];
|
---|
1714 | ProjData.VarDimName=[ProjData.VarDimName DimCell];
|
---|
1715 | nbvar=nbvar+1;
|
---|
1716 | if isfield(FieldData,'VarAttribute') & length(FieldData.VarAttribute) >=ivar
|
---|
1717 | ProjData.VarAttribute{nbvar}=FieldData.VarAttribute{ivar};
|
---|
1718 | end
|
---|
1719 | end
|
---|
1720 | end
|
---|
1721 | elseif isequal(ObjectData.ProjMode,'interp')||isequal(ObjectData.ProjMode,'filter')%interpolate data on a regular grid
|
---|
1722 | coord_x_proj=[XMin:DX:XMax];
|
---|
1723 | coord_y_proj=[YMin:DY:YMax];
|
---|
1724 | coord_z_proj=[ZMin:DZ:ZMax];
|
---|
1725 | [XI,YI,ZI]=meshgrid(coord_x_proj,coord_y_proj,coord_z_proj);
|
---|
1726 | DimCell={'coord_y','coord_x'};
|
---|
1727 | ProjData.ListVarName={'coord_z','coord_y','coord_x'};
|
---|
1728 | ProjData.VarDimName={'coord_z','coord_y','coord_x'};
|
---|
1729 | nbcoord=3;
|
---|
1730 | ProjData.coord_z=[ZMin ZMax];
|
---|
1731 | ProjData.coord_y=[YMin YMax];
|
---|
1732 | ProjData.coord_x=[XMin XMax];
|
---|
1733 | if isempty(ivar_X), ivar_X=0; end;
|
---|
1734 | if isempty(ivar_Y), ivar_Y=0; end;
|
---|
1735 | if isempty(ivar_Z), ivar_Z=0; end;
|
---|
1736 | if isempty(ivar_U), ivar_U=0; end;
|
---|
1737 | if isempty(ivar_V), ivar_V=0; end;
|
---|
1738 | if isempty(ivar_W), ivar_W=0; end;
|
---|
1739 | if isempty(ivar_F), ivar_F=0; end;
|
---|
1740 | if isempty(ivar_FF), ivar_FF=0; end;
|
---|
1741 | if ~isequal(ivar_FF,0)
|
---|
1742 | VarName_FF=FieldData.ListVarName{ivar_FF};
|
---|
1743 | eval(['indsel=find(FieldData.' VarName_FF '==0);'])
|
---|
1744 | coord_X=coord_X(indsel);
|
---|
1745 | coord_Y=coord_Y(indsel);
|
---|
1746 | end
|
---|
1747 | FF=zeros(1,length(coord_y_proj)*length(coord_x_proj));
|
---|
1748 | testFF=0;
|
---|
1749 | size(XI)
|
---|
1750 | size(YI)
|
---|
1751 | size(ZI)
|
---|
1752 | for ivar=VarIndex
|
---|
1753 | VarName=FieldData.ListVarName{ivar};
|
---|
1754 | if ~( ivar==ivar_X || ivar==ivar_Y || ivar==ivar_Z || ivar==ivar_F || ivar==ivar_FF || test_anc(ivar)==1)
|
---|
1755 | ivar_new=ivar_new+1;
|
---|
1756 | ProjData.ListVarName=[ProjData.ListVarName {VarName}];
|
---|
1757 | ProjData.VarDimName=[ProjData.VarDimName {DimCell}];
|
---|
1758 | if isfield(FieldData,'VarAttribute') && length(FieldData.VarAttribute) >=ivar
|
---|
1759 | ProjData.VarAttribute{ivar_new+nbcoord}=FieldData.VarAttribute{ivar};
|
---|
1760 | end
|
---|
1761 | if ~isequal(ivar_FF,0)
|
---|
1762 | eval(['FieldData.' VarName '=FieldData.' VarName '(indsel);'])
|
---|
1763 | end
|
---|
1764 | eval(['ProjData.' VarName '=griddata3(double(coord_X),double(coord_Y),double(coord_Z),double(FieldData.' VarName '),XI,YI,ZI);'])
|
---|
1765 | % eval(['varline=reshape(ProjData.' VarName ',1,length(coord_y_proj)*length(coord_x_proj));'])
|
---|
1766 | % FFlag= isnan(varline); %detect undefined values NaN
|
---|
1767 | % indnan=find(FFlag);
|
---|
1768 | % if~isempty(indnan)
|
---|
1769 | % varline(indnan)=zeros(size(indnan));
|
---|
1770 | % eval(['ProjData.' VarName '=reshape(varline,length(coord_y_proj),length(coord_x_proj));'])
|
---|
1771 | % FF(indnan)=ones(size(indnan));
|
---|
1772 | % testFF=1;
|
---|
1773 | % end
|
---|
1774 | % if ivar==ivar_U
|
---|
1775 | % ivar_U=ivar_new;
|
---|
1776 | % end
|
---|
1777 | % if ivar==ivar_V
|
---|
1778 | % ivar_V=ivar_new;
|
---|
1779 | % end
|
---|
1780 | % if ivar==ivar_W
|
---|
1781 | % ivar_W=ivar_new;
|
---|
1782 | % end
|
---|
1783 | end
|
---|
1784 | end
|
---|
1785 | if testFF
|
---|
1786 | ProjData.FF=reshape(FF,length(coord_y_proj),length(coord_x_proj));
|
---|
1787 | ProjData.ListVarName=[ProjData.ListVarName {'FF'}];
|
---|
1788 | ProjData.VarDimName=[ProjData.VarDimName {DimCell}];
|
---|
1789 | ProjData.VarAttribute{ivar_new+1+nbcoord}.Role='errorflag';
|
---|
1790 | end
|
---|
1791 | end
|
---|
1792 | %case of fields defined on a structured grid
|
---|
1793 | else
|
---|
1794 | AYName=FieldData.ListVarName{VarType.coord(1)};
|
---|
1795 | AXName=FieldData.ListVarName{VarType.coord(2)};
|
---|
1796 | eval(['AX=FieldData.' AXName ';'])
|
---|
1797 | eval(['AY=FieldData.' AYName ';'])
|
---|
1798 | VarName=FieldData.ListVarName{VarIndex(1)};
|
---|
1799 | eval(['DimValue=size(FieldData.' VarName ');'])
|
---|
1800 | ListDimName=FieldData.VarDimName{VarIndex(1)};
|
---|
1801 | ProjData.ListVarName=[{AYName} {AXName} ProjData.ListVarName]; %TODO: check if it already exists in Projdata (several cells)
|
---|
1802 | ProjData.VarDimName=[{AYName} {AXName} ProjData.VarDimName];
|
---|
1803 | nbcolor=1; %default
|
---|
1804 | for idim=1:length(ListDimName)
|
---|
1805 | DimName=ListDimName{idim};
|
---|
1806 | if isequal(DimName,'rgb')|isequal(DimName,'nb_coord')|isequal(DimName,'nb_coord_i')
|
---|
1807 | nbcolor=DimValue(idim);
|
---|
1808 | DimIndices(idim)=[];
|
---|
1809 | DimValue(idim)=[];
|
---|
1810 | end
|
---|
1811 | if isequal(DimName,'nb_coord_j')% NOTE: CASE OF TENSOR NOT TREATED
|
---|
1812 | DimIndices(idim)=[];
|
---|
1813 | DimValue(idim)=[];
|
---|
1814 | end
|
---|
1815 | end
|
---|
1816 | ind_1=find(DimValue==1);
|
---|
1817 | DimIndices(ind_1)=[]; %suppress singleton dimensions
|
---|
1818 | % indxy=find(DimVarIndex(DimIndices));%select dimension variables (DimIndices non zero)
|
---|
1819 | nb_dim=length(DimIndices);%number of space dimensions
|
---|
1820 | Coord_z=[];
|
---|
1821 | Coord_y=[];
|
---|
1822 | Coord_x=[];
|
---|
1823 |
|
---|
1824 | for idim=1:nb_dim %loop on space dimensions
|
---|
1825 | test_interp(idim)=0;%test for coordiate interpolation (non regular grid), =0 by default
|
---|
1826 | ivar=DimVarIndex(DimIndices(idim));% index of the variable corresponding to the current dimension
|
---|
1827 | if ~isequal(ivar,0)% a variable corresponds to the current dimension
|
---|
1828 | eval(['Coord{idim}=FieldData.' FieldData.ListVarName{ivar} ';']) ;% position for the first index
|
---|
1829 | DCoord=diff(Coord{idim});
|
---|
1830 | DCoord_min(idim)=min(DCoord);
|
---|
1831 | DCoord_max=max(DCoord);
|
---|
1832 | test_direct(idim)=DCoord_max>0;% =1 for increasing values, 0 otherwise
|
---|
1833 | test_direct_min=DCoord_min(idim)>0;% =1 for increasing values, 0 otherwise
|
---|
1834 | if ~isequal(test_direct(idim),test_direct_min)
|
---|
1835 | msgbox_uvmat('ERROR',['non monotonic dimension variable # ' num2str(idim) ' in proj_field.m'])
|
---|
1836 | return
|
---|
1837 | end
|
---|
1838 | test_interp(idim)=(DCoord_max-DCoord_min(idim))> 0.0001*abs(DCoord_max);% test grid regularity
|
---|
1839 | else % no variable associated with the first dimension, look for variable attributes Coord_1, _2 or _3
|
---|
1840 | Coord_i_str=['Coord_' num2str(idim)];
|
---|
1841 | DCoord_min(idim)=1;%default
|
---|
1842 | Coord{idim}=[0.5 DimValue(idim)-0.5];
|
---|
1843 | test_direct(idim)=1;
|
---|
1844 | end
|
---|
1845 | end
|
---|
1846 | if nb_dim==2
|
---|
1847 | if DY==0
|
---|
1848 | DY=abs(DCoord_min(1));
|
---|
1849 | end
|
---|
1850 | npY=1+round(abs(Coord{1}(end)-Coord{1}(1))/DY);%nbre of points after interpolation
|
---|
1851 | 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
|
---|
1852 | if DX==0
|
---|
1853 | DX=abs(DCoord_min(2));
|
---|
1854 | end
|
---|
1855 | npX=1+round(abs(Coord{2}(end)-Coord{2}(1))/DX);%nbre of points after interpol
|
---|
1856 | 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
|
---|
1857 | Coord_y=linspace(Coord{1}(1),Coord{1}(end),npY);
|
---|
1858 | test_direct_y=test_direct(1);
|
---|
1859 | Coord_x=linspace(Coord{2}(1),Coord{2}(end),npX);
|
---|
1860 | test_direct_x=test_direct(2);
|
---|
1861 | DAX=DCoord_min(2);
|
---|
1862 | DAY=DCoord_min(1);
|
---|
1863 | elseif nb_dim==3
|
---|
1864 | DZ=abs(DCoord_min(1));
|
---|
1865 | npz=1+round(abs(Coord{1}(end)-Coord{1}(1))/DZ);%nbre of points after interpolation
|
---|
1866 | if DY==0
|
---|
1867 | DY=abs(DCoord_min(2));
|
---|
1868 | end
|
---|
1869 | npY=1+round(abs(Coord{2}(end)-Coord{2}(1))/DY);%nbre of points after interpol
|
---|
1870 | DimValue(1)=1+round(abs(Coord{2}(end)-Coord{2}(1))/abs(DCoord_min(2)));%nbre of points before interpol
|
---|
1871 | if DX==0
|
---|
1872 | DX=abs(DCoord_min(3));
|
---|
1873 | end
|
---|
1874 | npX=1+round(abs(Coord{3}(end)-Coord{3}(1))/DX);%nbre of points after interpol
|
---|
1875 | DimValue(2)=1+round(abs(Coord{3}(end)-Coord{3}(1))/abs(DCoord_min(3)));%nbre of points before interpol
|
---|
1876 | Coord_z=linspace(Coord{1}(1),Coord{1}(end),npz);
|
---|
1877 | test_direct_z=test_direct(1);
|
---|
1878 | Coord_y=linspace(Coord{2}(1),Coord{2}(end),npY);
|
---|
1879 | test_direct_y=test_direct(2);
|
---|
1880 | Coord_x=linspace(Coord{3}(1),Coord{3}(end),npX);
|
---|
1881 | test_direct_x=test_direct(3);
|
---|
1882 | end
|
---|
1883 | minAX=min(Coord_x);
|
---|
1884 | maxAX=max(Coord_x);
|
---|
1885 | minAY=min(Coord_y);
|
---|
1886 | maxAY=max(Coord_y);
|
---|
1887 | xcorner=[minAX maxAX minAX maxAX]-ObjectData.Coord(1,1);
|
---|
1888 | ycorner=[maxAY maxAY minAY minAY]-ObjectData.Coord(1,2);
|
---|
1889 | xcor_new=xcorner*cos(Phi)+ycorner*sin(Phi);%coord new frame
|
---|
1890 | ycor_new=-xcorner*sin(Phi)+ycorner*cos(Phi);
|
---|
1891 | if ~testXMax
|
---|
1892 | XMax=max(xcor_new);
|
---|
1893 | end
|
---|
1894 | if ~testXMin
|
---|
1895 | XMin=min(xcor_new);
|
---|
1896 | end
|
---|
1897 | if ~testYMax
|
---|
1898 | YMax=max(ycor_new);
|
---|
1899 | end
|
---|
1900 | if ~testYMin
|
---|
1901 | YMin=min(ycor_new);
|
---|
1902 | end
|
---|
1903 | DXinit=(maxAX-minAX)/(DimValue(2)-1);
|
---|
1904 | DYinit=(maxAY-minAY)/(DimValue(1)-1);
|
---|
1905 | if DX==0
|
---|
1906 | DX=DXinit;
|
---|
1907 | end
|
---|
1908 | if DY==0
|
---|
1909 | DY=DYinit;
|
---|
1910 | end
|
---|
1911 | npX=floor((XMax-XMin)/DX+1);
|
---|
1912 | npY=floor((YMax-YMin)/DY+1);
|
---|
1913 | if test_direct_y
|
---|
1914 | coord_y_proj=linspace(YMin,YMax,npY);%abscissa of the new pixels along the line
|
---|
1915 | else
|
---|
1916 | coord_y_proj=linspace(YMax,YMin,npY);%abscissa of the new pixels along the line
|
---|
1917 | end
|
---|
1918 | if test_direct_x
|
---|
1919 | coord_x_proj=linspace(XMin,XMax,npX);%abscissa of the new pixels along the line
|
---|
1920 | else
|
---|
1921 | coord_x_proj=linspace(XMax,XMin,npX);%abscissa of the new pixels along the line
|
---|
1922 | end
|
---|
1923 |
|
---|
1924 | % case with no rotation and interpolation
|
---|
1925 | if isequal(ProjMode,'projection') && isequal(Phi,0) && isequal(Theta,0) && isequal(Psi,0)
|
---|
1926 | if test_direct(1)
|
---|
1927 | min_ind1=ceil((YMin-Coord{1}(1))/DYinit)+1;
|
---|
1928 | max_ind1=floor((YMax-Coord{1}(1))/DYinit)+1;
|
---|
1929 | Ybound(1)=Coord{1}(1)+DYinit*(min_ind1-1);
|
---|
1930 | Ybound(2)=Coord{1}(1)+DYinit*(max_ind1-1);
|
---|
1931 | else
|
---|
1932 | min_ind1=ceil((Coord{1}(1)-YMax)/DYinit)+1;
|
---|
1933 | max_ind1=floor((Coord{1}(1)-YMin)/DYinit)+1;
|
---|
1934 | Ybound(2)=Coord{1}(1)-DYinit*(max_ind1-1);
|
---|
1935 | Ybound(1)=Coord{1}(1)-DYinit*(min_ind1-1);
|
---|
1936 | end
|
---|
1937 | if test_direct(2)==1
|
---|
1938 | min_ind2=ceil((XMin-Coord{2}(1))/DXinit)+1;
|
---|
1939 | max_ind2=floor((XMax-Coord{2}(1))/DXinit)+1;
|
---|
1940 | Xbound(1)=Coord{2}(1)+DXinit*(min_ind2-1);
|
---|
1941 | Xbound(2)=Coord{2}(1)+DXinit*(max_ind2-1);
|
---|
1942 | else
|
---|
1943 | min_ind2=ceil((Coord{2}(1)-XMax)/DXinit)+1;
|
---|
1944 | max_ind2=floor((Coord{2}(1)-XMin)/DXinit)+1;
|
---|
1945 | Xbound(2)=Coord{2}(1)+DXinit*(max_ind2-1);
|
---|
1946 | Xbound(1)=Coord{2}(1)+DXinit*(min_ind2-1);
|
---|
1947 | end
|
---|
1948 | min_ind1=max(min_ind1,1);% deals with margin (bound lower than the first index)
|
---|
1949 | min_ind2=max(min_ind2,1);
|
---|
1950 | max_ind1=min(max_ind1,DimValue(1));
|
---|
1951 | max_ind2=min(max_ind2,DimValue(2));
|
---|
1952 | for ivar=VarIndex
|
---|
1953 | VarName=FieldData.ListVarName{ivar};
|
---|
1954 | ProjData.ListVarName=[ProjData.ListVarName VarName];
|
---|
1955 | %ProjData.VarDimIndex=[ProjData.VarDimIndex [nb_dim-1 nb_dim]];
|
---|
1956 | if length(FieldData.VarAttribute)>=ivar
|
---|
1957 | ProjData.VarAttribute{length(ProjData.ListVarName)}=FieldData.VarAttribute{ivar};
|
---|
1958 | end
|
---|
1959 | eval(['ProjData.' VarName '=FieldData.' VarName '(min_ind1:max_ind1,min_ind2:max_ind2) ;']);
|
---|
1960 | end
|
---|
1961 | else
|
---|
1962 | % case with rotation and/or interpolation
|
---|
1963 | if isempty(Coord_z) %2D case
|
---|
1964 | [X,Y]=meshgrid(coord_x_proj,coord_y_proj);%grid in the new coordinates
|
---|
1965 | XIMA=ObjectData.Coord(1,1)+(X)*cos(Phi)-Y*sin(Phi);%corresponding coordinates in the original image
|
---|
1966 | YIMA=ObjectData.Coord(1,2)+(X)*sin(Phi)+Y*cos(Phi);
|
---|
1967 | XIMA=(XIMA-minAX)/DXinit+1;% image index along x
|
---|
1968 | YIMA=(-YIMA+maxAY)/DYinit+1;% image index along y
|
---|
1969 | XIMA=reshape(round(XIMA),1,npX*npY);%indices reorganized in 'line'
|
---|
1970 | YIMA=reshape(round(YIMA),1,npX*npY);
|
---|
1971 | flagin=XIMA>=1 & XIMA<=DimValue(2) & YIMA >=1 & YIMA<=DimValue(1);%flagin=1 inside the original image
|
---|
1972 | if isequal(ObjectData.ProjMode,'filter')
|
---|
1973 | npx_filter=ceil(abs(DX/DAX));
|
---|
1974 | npy_filter=ceil(abs(DY/DAY));
|
---|
1975 | Mfilter=ones(npy_filter,npx_filter)/(npx_filter*npy_filter);
|
---|
1976 | test_filter=1;
|
---|
1977 | else
|
---|
1978 | test_filter=0;
|
---|
1979 | end
|
---|
1980 | for ivar=VarIndex
|
---|
1981 | VarName=FieldData.ListVarName{ivar} ;
|
---|
1982 | if test_interp(1) | test_interp(2)%interpolate on a regular grid
|
---|
1983 | eval(['FieldData.' VarName '=interp2(Coord{2},Coord{1},FieldData.' VarName ',Coord_x,Coord_y'');']) %TO TEST
|
---|
1984 | end
|
---|
1985 | %filter the field (image) if option 'filter' is used
|
---|
1986 | if test_filter
|
---|
1987 | Aclass=class(FieldData.A);
|
---|
1988 | eval(['FieldData.' VarName '=filter2(Mfilter,FieldData.' VarName ',''valid'');'])
|
---|
1989 | if ~isequal(Aclass,'double')
|
---|
1990 | eval(['FieldData.' VarName '=' Aclass '(FieldData.' VarName ');'])%revert to integer values
|
---|
1991 | end
|
---|
1992 | end
|
---|
1993 | eval(['vec_A=reshape(FieldData.' VarName ',[],nbcolor);'])%put the original image in line
|
---|
1994 | ind_in=find(flagin);
|
---|
1995 | ind_out=find(~flagin);
|
---|
1996 | ICOMB=(XIMA-1)*DimValue(1)+YIMA;
|
---|
1997 | ICOMB=ICOMB(flagin);%index corresponding to XIMA and YIMA in the aligned original image vec_A
|
---|
1998 | vec_B(ind_in,[1:nbcolor])=vec_A(ICOMB,:);
|
---|
1999 | for icolor=1:nbcolor
|
---|
2000 | vec_B(ind_out,icolor)=zeros(size(ind_out));
|
---|
2001 | end
|
---|
2002 | ProjData.ListVarName=[ProjData.ListVarName VarName];
|
---|
2003 | if length(FieldData.VarAttribute)>=ivar
|
---|
2004 | ProjData.VarAttribute{length(ProjData.ListVarName)+nbcoord}=FieldData.VarAttribute{ivar};
|
---|
2005 | end
|
---|
2006 | eval(['ProjData.' VarName '=reshape(vec_B,npY,npX,nbcolor);']);
|
---|
2007 | end
|
---|
2008 | ProjData.FF=reshape(~flagin,npY,npX);%false flag A FAIRE: tenir compte d'un flga antérieur
|
---|
2009 | ProjData.ListVarName=[ProjData.ListVarName 'FF'];
|
---|
2010 | ProjData.VarAttribute{length(ProjData.ListVarName)}.Role='errorflag';
|
---|
2011 | else %3D case
|
---|
2012 | if isequal(Theta,0) & isequal(Phi,0)
|
---|
2013 | test_sup=(Coord{1}>=ObjectData.Coord(1,3));
|
---|
2014 | iz_sup=find(test_sup);
|
---|
2015 | iz=iz_sup(1);
|
---|
2016 | if iz>=1 & iz<=npz
|
---|
2017 | %ProjData.ListDimName=[ProjData.ListDimName ListDimName(2:end)];
|
---|
2018 | %ProjData.DimValue=[ProjData.DimValue npY npX];
|
---|
2019 | for ivar=VarIndex
|
---|
2020 | VarName=FieldData.ListVarName{ivar};
|
---|
2021 | ProjData.ListVarName=[ProjData.ListVarName VarName];
|
---|
2022 | ProjData.VarAttribute{length(ProjData.ListVarName)}=FieldData.VarAttribute{ivar}; %reproduce the variable attributes
|
---|
2023 | eval(['ProjData.' VarName '=squeeze(FieldData.' VarName '(iz,:,:));'])% select the z index iz
|
---|
2024 | %TODO : do a vertical average for a thick plane
|
---|
2025 | if test_interp(2) | test_interp(3)
|
---|
2026 | eval(['ProjData.' VarName '=interp2(Coord{3},Coord{2},ProjData.' VarName ',Coord_x,Coord_y'');'])
|
---|
2027 | end
|
---|
2028 | end
|
---|
2029 | end
|
---|
2030 | else
|
---|
2031 | errormsg='projection of structured coordinates on oblique plane not yet implemented';
|
---|
2032 | %TODO: use interp3
|
---|
2033 | return
|
---|
2034 | end
|
---|
2035 | end
|
---|
2036 | end
|
---|
2037 | end
|
---|
2038 | %projection of velocity components in the rotated coordinates
|
---|
2039 | if ~isequal(Phi,0) && length(ivar_U)==1
|
---|
2040 | if isempty(ivar_V)
|
---|
2041 | msgbox_uvmat('ERROR','v velocity component missing in proj_field.m')
|
---|
2042 | return
|
---|
2043 | end
|
---|
2044 | UName=FieldData.ListVarName{ivar_U};
|
---|
2045 | VName=FieldData.ListVarName{ivar_V};
|
---|
2046 | eval(['ProjData.' UName '=cos(Phi)*ProjData.' UName '+ sin(Phi)*ProjData.' VName ';'])
|
---|
2047 | eval(['ProjData.' VName '=cos(Theta)*(-sin(Phi)*ProjData.' UName '+ cos(Phi)*ProjData.' VName ');'])
|
---|
2048 | if ~isempty(ivar_W)
|
---|
2049 | WName=FieldData.ListVarName{ivar_W};
|
---|
2050 | eval(['ProjData.' VName '=ProjData.' VName '+ ProjData.' WName '*sin(Theta);'])%
|
---|
2051 | eval(['ProjData.' WName '=NormVec_X*ProjData.' UName '+ NormVec_Y*ProjData.' VName '+ NormVec_Z* ProjData.' WName ';']);
|
---|
2052 | end
|
---|
2053 | if ~isequal(Psi,0)
|
---|
2054 | eval(['ProjData.' UName '=cos(Psi)* ProjData.' UName '- sin(Psi)*ProjData.' VName ';']);
|
---|
2055 | eval(['ProjData.' VName '=sin(Psi)* ProjData.' UName '+ cos(Psi)*ProjData.' VName ';']);
|
---|
2056 | end
|
---|
2057 | end
|
---|
2058 | end
|
---|
2059 |
|
---|
2060 | %-----------------------------------------------------------------
|
---|
2061 | %transmit the global attributes
|
---|
2062 | function [ProjData,errormsg]=proj_heading(FieldData,ObjectData)
|
---|
2063 | %-----------------------------------------------------------------
|
---|
2064 | % ProjData=FieldData;
|
---|
2065 | ProjData=[];%default
|
---|
2066 | if ~isfield(FieldData,'ListGlobalAttribute')
|
---|
2067 | ProjData.ListGlobalAttribute={};
|
---|
2068 | else
|
---|
2069 | ProjData.ListGlobalAttribute=FieldData.ListGlobalAttribute;
|
---|
2070 | end
|
---|
2071 | if isfield(FieldData,'Txt')
|
---|
2072 | errormsg=FieldData.Txt; %transmit erreur message
|
---|
2073 | return;
|
---|
2074 | end
|
---|
2075 | for iattr=1:length(ProjData.ListGlobalAttribute)
|
---|
2076 | AttrName=ProjData.ListGlobalAttribute{iattr};
|
---|
2077 | if isfield(FieldData,AttrName)
|
---|
2078 | eval(['ProjData.' AttrName '=FieldData.' AttrName ';']);
|
---|
2079 | end
|
---|
2080 | end
|
---|
2081 | if isfield(FieldData,'CoordType')
|
---|
2082 | if isfield(ObjectData,'CoordType')&~isequal(FieldData.CoordType,ObjectData.CoordType)
|
---|
2083 | errormsg=[ObjectData.Style ' in ' ObjectData.CoordType ' coordinates, while field in ' FieldData.CoordType ' coordinates'];
|
---|
2084 | return
|
---|
2085 | else
|
---|
2086 | ProjData.CoordType=FieldData.CoordType;
|
---|
2087 | end
|
---|
2088 | end
|
---|
2089 |
|
---|
2090 | ListObject={'Style','ProjMode','RangeX','RangeY','RangeZ','Phi','Theta','Psi','Coord'};
|
---|
2091 | for ilist=1:length(ListObject)
|
---|
2092 | if isfield(ObjectData,ListObject{ilist})
|
---|
2093 | eval(['val=ObjectData.' ListObject{ilist} ';'])
|
---|
2094 | if ~isempty(val)
|
---|
2095 | eval(['ProjData.Object' ListObject{ilist} '=val;']);
|
---|
2096 | ProjData.ListGlobalAttribute=[ProjData.ListGlobalAttribute {['Object' ListObject{ilist}]}];
|
---|
2097 | end
|
---|
2098 | end
|
---|
2099 | end
|
---|