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