1 | %'uvmat': function associated with the GUI 'uvmat.fig' for images and data field visualization |
---|
2 | %------------------------------------------------------------------------ |
---|
3 | % function huvmat=uvmat(input) |
---|
4 | % |
---|
5 | %OUTPUT |
---|
6 | % huvmat=current handles of the GUI uvmat.fig |
---|
7 | %% |
---|
8 | % |
---|
9 | %INPUT: |
---|
10 | % input: input file name (if character chain), or input image matrix to |
---|
11 | % visualize, or Matlab structure representing netcdf fields (with fields |
---|
12 | % ListVarName....) |
---|
13 | % |
---|
14 | %AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA |
---|
15 | % Copyright Joel Sommeria, 2008, LEGI / CNRS-UJF-INPG, joel.sommeria@legi.grenoble-inp.fr. |
---|
16 | %AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA |
---|
17 | % This open is part of the toolbox UVMAT. |
---|
18 | % |
---|
19 | % UVMAT is free software; you can redistribute it and/or modify |
---|
20 | % it under the terms of the GNU General Public License as published by |
---|
21 | % the Free Software Foundation; either version 2 of the License, or |
---|
22 | % (at your option) any later version. |
---|
23 | % |
---|
24 | % UVMAT is distributed in the hope that it will be useful, |
---|
25 | % but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
26 | % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
27 | % GNU General Public License (open UVMAT/COPYING.txt) for more details. |
---|
28 | %AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA |
---|
29 | % |
---|
30 | % Information stored on the interface:(use 'Export/field in workspace' in |
---|
31 | % the menu bar of uvmat to retrieve it) |
---|
32 | % .OpenParam: structure containing parameters defined when uvmat is opened |
---|
33 | % .PosColorbar: position (1x4 vector)of the colorbar (relative to the fig uvmat) |
---|
34 | % .PosSetObject: position of set_object |
---|
35 | % .PosGeometryCalib: size of set_object |
---|
36 | % .NbBuiltin: nbre of functions always displayed in transform_fct menu |
---|
37 | % .Object: cell array of structures representing the current projection objects, as produced by 'set_object.m'={[]} by default |
---|
38 | % .NewSeries: =0/1 flag telling whether a new field series has been opened |
---|
39 | % .FileName_1: name of the current second field (used to detect a constant field during file scanning) |
---|
40 | % .FileType: current file type, as defined by the fct get_file_type.m) |
---|
41 | % .i1_series,.i2_series,.j1_series,.j1_series: series of i1,i2,j1,j2 indices detected in the input dir,set by the fct find_file_series |
---|
42 | % .MovieObject: current movie object |
---|
43 | % .TimeUnit: unit for time |
---|
44 | % .XmlData: cell array of 1 or 2 structures representing the xml files associated with the input fields (containing timing and geometry calibration) |
---|
45 | % .Field: cell array of 1 or 2 structures representing the current input field(s) |
---|
46 | % .PlotAxes: field structure representing the current field plotted on the main axes (used for mouse operations) |
---|
47 | % .HistoAxes: idem for histogram axes |
---|
48 | |
---|
49 | % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%% DATA FLOW (for run0_Callback) %%%%%%%%%%%%%%%%%%%%: |
---|
50 | % |
---|
51 | % |
---|
52 | % 1) Input filenames are determined by MenuBrowse (first field), MenuBrowse_1 |
---|
53 | % (second field), or by the stored file name .FileName_1, or as an input of uvmat. |
---|
54 | % 2) These functions call 'uvmat/display_file_name.m' which detects the file series, and fills the file index boxes |
---|
55 | % 3) Then 'uvmat/update_rootinfo.m' Updates information about a new field series (indices to scan, timing, calibration from an xml file) |
---|
56 | % 4) Then fields are opened and visualised by the main sub-function 'uvmat/refresh_field.m' |
---|
57 | % The function first reads the name of the input file(s) (one or two) from the edit boxes of the GUI |
---|
58 | % It then reads the input file(s) with the function read_field.m and perform the following list of operations: |
---|
59 | % |
---|
60 | % %%%%%%%% structure of uvmat/refresh_field.m %%%%%%%% |
---|
61 | % |
---|
62 | % Main input open second input open_1 |
---|
63 | % | | |
---|
64 | % read_field.m read_field.m |
---|
65 | % | | |
---|
66 | % Field{1} Field{2} |
---|
67 | % | | |
---|
68 | % --->transform fct<--- transform (e.g. phys.m) and combine input fields |
---|
69 | % | |
---|
70 | % (calc_tps.m) calculate tps coefficients (for filter projection or spatial derivatives). |
---|
71 | % | |
---|
72 | % UvData.Field-------------->histogram |
---|
73 | % _____________|____________ |
---|
74 | % | | |
---|
75 | % proj_field.m proj_field.m project the field on the projection objects (use calc_field.m) |
---|
76 | % | | |
---|
77 | % UvData.PlotAxes ViewData.PlotAxes (on view_field) |
---|
78 | % | | |
---|
79 | % plot_field.m (uvmat) plot_field.m (view_field) plot the projected fields |
---|
80 | % |
---|
81 | % |
---|
82 | %%%%%%%%%%%%%% SCALARS: %%%%%%%%%%%%??%%% |
---|
83 | % scalars are displayed either as an image or countour plot, either as a color of |
---|
84 | % velocity vectors. The scalar values in the first case is represented by |
---|
85 | % UvData.Field.A, and by UvData.Field.C in the second case. The corresponding set of X |
---|
86 | % and Y coordinates are represented by UvData.Field.AX and UvData.Field.AY, and .X and |
---|
87 | % .Y for C (the same as velocity vectors). If A is a nxxny matrix (scalar |
---|
88 | % on a regtular grid), then .AX andf.AY contains only two elements, represneting the |
---|
89 | % coordinates of the four image corners. The scalar name is represented by |
---|
90 | % the strings .AName and/or .CName. |
---|
91 | % If the scalar exists in an input open (image or scalar stored under its |
---|
92 | % name in a netcdf open), it is directly read at the level of Field{1}or Field{2}. |
---|
93 | % Else only its name AName is recorded in Field{i}, and its field is then calculated |
---|
94 | %by the fuction calc_scal after the coordinate transform or after projection on an edit_object |
---|
95 | |
---|
96 | % Properties attached to plotting figures (standard Matlab properties): |
---|
97 | % 'CurrentAxes'= gca or get(gcf,'CurrentAxes'); |
---|
98 | % 'CurrentPoint'=get(gcf,'CurrentPoint'): figure coordinates of the point over which the mouse is positioned |
---|
99 | % 'CurrentCharacter'=get(gcf,'CurrentCharacter'): last character typed over the figure where the mouse is positioned |
---|
100 | % 'WindowButtonMotionFcn': function permanently called by mouse motion over the figure |
---|
101 | % 'KeyPressFcn': function called by pressing a key on the key board |
---|
102 | % 'WindowButtonDownFcn': function called by pressing the mouse over the figure |
---|
103 | % 'WindowButtonUpFcn': function called by releasing the mouse pressure over the figure |
---|
104 | |
---|
105 | % Properties attached to plotting axes: |
---|
106 | % 'CurrentPoint'=get(gca,'CurrentPoint'); (standard Matlab) same as for the figure, but position in plot coordinates. |
---|
107 | % AxeData:=get(gca,'UserData'); |
---|
108 | % AxeData.Drawing = create: create a new object |
---|
109 | % = deform: modify an existing object by moving its defining create |
---|
110 | % = off: no current drawing action |
---|
111 | % = translate: translate an existing object |
---|
112 | % = calibration: move a calibration point |
---|
113 | % = CheckZoom: isolate a subregion for CheckZoom in=1 if an object is being currently drawn, 0 else (set to 0 by releasing mouse button) |
---|
114 | % .CurrentOrigin: Origin of a curently drawn edit_object |
---|
115 | % .CurrentLine: currently drawn menuline (A REVOIR) |
---|
116 | % .CurrentObject: handle of the currently drawn edit_object |
---|
117 | % .CurrentRectZoom: current rectangle used for CheckZoom |
---|
118 | |
---|
119 | % Properties attached to projection objects (create, menuline, menuplane...): |
---|
120 | % 'Tag'='proj_object': for all projection objects |
---|
121 | % ObjectData.Type=...: style of projection object: |
---|
122 | % .ProjMode |
---|
123 | % .Coord: defines the position of the object |
---|
124 | % .XMin,YMin.... |
---|
125 | % .XMax,YMax.... |
---|
126 | % .DX,DY,DZ |
---|
127 | % .Phi, .Theta, .Psi : Euler angles |
---|
128 | % .X,.Y,.U,.V.... : field data projected on the object |
---|
129 | % .IndexObj: index in the list of UvData.Object |
---|
130 | %during plotting |
---|
131 | % .plotaxes: handles of the current axes used to plot the result of field projection on the object |
---|
132 | % .plothandle: vector of handle(s) of the object graphic represnetation in all the opened plotting axes |
---|
133 | % To each projection object #iobj, corresponds an axis |
---|
134 | % Object{iobj}.plotaxes and nbobj representation graphs Object{iobj}.plothandles(:) (where nbobj is the |
---|
135 | % nbre of current objects opened in uvmat. Note that Object{iobj}.plothandles(iobj)=[] : an object is not represented in its own projection field; |
---|
136 | |
---|
137 | %------------------------------------------------------------------------ |
---|
138 | %------------------------------------------------------------------------ |
---|
139 | % I - MAIN FUNCTION uvmat |
---|
140 | %------------------------------------------------------------------------ |
---|
141 | %------------------------------------------------------------------------ |
---|
142 | function varargout = uvmat(varargin) |
---|
143 | |
---|
144 | % Begin initialization code - DO NOT EDIT |
---|
145 | gui_Singleton = 1; |
---|
146 | gui_State = struct('gui_Name', mfilename, ... |
---|
147 | 'gui_Singleton', gui_Singleton, ... |
---|
148 | 'gui_OpeningFcn', @uvmat_OpeningFcn, ... |
---|
149 | 'gui_OutputFcn', @uvmat_OutputFcn, ... |
---|
150 | 'gui_LayoutFcn', [], ... |
---|
151 | 'gui_Callback', []); |
---|
152 | if nargin && ischar(varargin{1})&& ~isempty(regexp(varargin{1},'_Callback','once')) |
---|
153 | gui_State.gui_Callback = str2func(varargin{1}); |
---|
154 | end |
---|
155 | |
---|
156 | if nargout |
---|
157 | varargout{1:nargout} = gui_mainfcn(gui_State, varargin{:}); |
---|
158 | else |
---|
159 | gui_mainfcn(gui_State, varargin{:}); |
---|
160 | end |
---|
161 | % End initialization code - DO NOT EDIT |
---|
162 | |
---|
163 | %------------------------------------------------------------------------ |
---|
164 | % --- Executes just before the GUI uvmat is made visible. |
---|
165 | function uvmat_OpeningFcn(hObject, eventdata, handles, input ) |
---|
166 | %------------------------------------------------------------------------ |
---|
167 | |
---|
168 | %% Choose default command menuline output for uvmat (standard GUI) |
---|
169 | handles.output = hObject; |
---|
170 | |
---|
171 | %% Update handles structure (standard GUI) |
---|
172 | guidata(hObject, handles); |
---|
173 | |
---|
174 | %% add the path to uvmat (useful if uvmat has been opened in the working directory and a working directory change occured) |
---|
175 | path_uvmat=fileparts(which('uvmat')); |
---|
176 | |
---|
177 | %% set the position of colorbar and ancillary GUIs: |
---|
178 | set(hObject,'Units','Normalized') |
---|
179 | movegui(hObject,'center') |
---|
180 | UvData.OpenParam.PosColorbar=[0.805 0.022 0.019 0.445]; |
---|
181 | UvData.OpenParam.PosSetObject=[-0.05 -0.03 0.3 0.7]; %position for set_object |
---|
182 | UvData.OpenParam.PosGeometryCalib=[0.95 -0.03 0.28 1 ];%position for geometry_calib (TO IMPROVE) |
---|
183 | % UvData.OpenParam.CalSize=[0.28 1]; |
---|
184 | % UvData.PlotAxes=[];%initiate the record of plotted field |
---|
185 | % UvData.axes2=[]; |
---|
186 | % UvData.axes1=[]; |
---|
187 | AxeData.LimEditBox=1; %initialise AxeData |
---|
188 | set(handles.PlotAxes,'UserData',AxeData) |
---|
189 | |
---|
190 | %% set functions for the mouse and keyboard |
---|
191 | set(hObject,'KeyPressFcn',{'keyboard_callback',handles})%set keyboard action function |
---|
192 | set(hObject,'WindowButtonMotionFcn',{'mouse_motion',handles})%set mouse action functio |
---|
193 | set(hObject,'WindowButtonDownFcn',{'mouse_down'})%set mouse click action function |
---|
194 | set(hObject,'WindowButtonUpFcn',{'mouse_up',handles}) |
---|
195 | set(hObject,'DeleteFcn',{@closefcn})% |
---|
196 | |
---|
197 | %% initialisation |
---|
198 | % set(handles.ListObject,'Value',1)% default: empty projection objectproj_field |
---|
199 | % set(handles.ListObject,'String',{''}) |
---|
200 | % set(handles.ListObject_1,'Value',1)% default: empty projection objectproj_field |
---|
201 | % set(handles.ListObject_1,'String',{''}) |
---|
202 | set(handles.Fields,'Value',1) |
---|
203 | set(handles.Fields,'string',{''}) |
---|
204 | UvData.Object={[]}; |
---|
205 | |
---|
206 | %% TRANSFORM menu: builtin fcts |
---|
207 | transform_menu={'';'sub_field';'phys';'phys_polar'}; |
---|
208 | UvData.OpenParam.NbBuiltin=numel(transform_menu); %number of functions |
---|
209 | transform_path=fullfile(path_uvmat,'transform_field'); |
---|
210 | path_list{1}=''; |
---|
211 | for ilist=2:UvData.OpenParam.NbBuiltin |
---|
212 | path_list{ilist}=transform_path; % set transform_path to the path_list |
---|
213 | end |
---|
214 | |
---|
215 | %% load the list of previously browsed files in menus Open, Open_1 and transform_fct |
---|
216 | dir_perso=prefdir; % path to the directory .matlab for personal data |
---|
217 | profil_perso=fullfile(dir_perso,'uvmat_perso.mat');% personal data file uvmauvmat_perso.mat' in .matlab |
---|
218 | if exist(profil_perso,'file') |
---|
219 | h=load (profil_perso); |
---|
220 | if isfield(h,'MenuFile')% load the menu of previously opened files |
---|
221 | for ifile=1:min(length(h.MenuFile),5) |
---|
222 | eval(['set(handles.MenuFile_' num2str(ifile) ',''Label'',h.MenuFile{ifile});']) |
---|
223 | eval(['set(handles.MenuFile_' num2str(ifile) '_1,''Label'',h.MenuFile{ifile});']) |
---|
224 | end |
---|
225 | end |
---|
226 | if isfield(h,'transform_fct') && iscell(h.transform_fct) % load the menu of transform fct set by user |
---|
227 | for ilist=1:length(h.transform_fct); |
---|
228 | if exist(h.transform_fct{ilist},'file') |
---|
229 | [path,file]=fileparts(h.transform_fct{ilist}); |
---|
230 | transform_menu=[transform_menu; {file}]; |
---|
231 | path_list=[path_list; {path}]; |
---|
232 | end |
---|
233 | end |
---|
234 | end |
---|
235 | end |
---|
236 | transform_menu=[transform_menu;{'more...'}];%append the option more.. to the menu |
---|
237 | set(handles.transform_fct,'String',transform_menu)% display the menu of transform fcts |
---|
238 | set(handles.transform_fct,'UserData',path_list)% store the corresponding list of path in UserData of uicontrol transform_fct |
---|
239 | set(handles.path_transform,'String','') |
---|
240 | set(handles.path_transform,'UserData',[]) |
---|
241 | |
---|
242 | %% case of an input argument for uvmat |
---|
243 | testinputfield=0; |
---|
244 | inputfile=[]; |
---|
245 | Field=[]; |
---|
246 | if exist('input','var') |
---|
247 | if ishandle(handles.UVMAT_title) |
---|
248 | delete(handles.UVMAT_title) |
---|
249 | end |
---|
250 | if isstruct(input) |
---|
251 | if isfield(input,'InputFile') |
---|
252 | inputfile=input.InputFile; |
---|
253 | end |
---|
254 | if isfield(input,'TimeIndex') |
---|
255 | set(handles.i1,num2str(input.TimeIndex)) |
---|
256 | end |
---|
257 | if isfield(input,'FieldsString') |
---|
258 | UvData.FieldsString=input.FieldsString; |
---|
259 | end |
---|
260 | elseif ischar(input)% file name introduced as input |
---|
261 | inputfile=input; |
---|
262 | elseif isnumeric(input)%simple matrix introduced as input |
---|
263 | sizinput=size(input); |
---|
264 | if sizinput(1)<=1 || sizinput(2)<=1 |
---|
265 | msgbox_uvmat('ERROR','bad input for uvmat: file name, structure or numerical matrix accepted') |
---|
266 | return |
---|
267 | end |
---|
268 | UvData.Field.ListVarName={'A','coord_y','coord_x'}; |
---|
269 | UvData.Field.VarDimName={{'coord_y','coord_x'},'cord_y','coord_x'}; |
---|
270 | UvData.Field.A=input; |
---|
271 | UvData.Field.coord_x=[0.5 size(input,2)-0.5]; |
---|
272 | UvData.Field.coord_y=[size(input,1)-0.5 0.5]; |
---|
273 | testinputfield=1; |
---|
274 | end |
---|
275 | else |
---|
276 | %% check the path and date of modification of all functions in uvmat |
---|
277 | path_to_uvmat=which ('uvmat');% check the path detected for source file uvmat |
---|
278 | [infomsg,date_str,svn_info]=check_files;%check the path of the functions called by uvmat.m |
---|
279 | date_str=['last modification: ' date_str]; |
---|
280 | if ishandle(handles.UVMAT_title) |
---|
281 | set(handles.UVMAT_title,'String',... |
---|
282 | [{'Copyright LEGI UMR 5519 /CNRS-UJF-Grenoble INP, 2010'};... |
---|
283 | {'GNU General Public License'};... |
---|
284 | {path_to_uvmat};... |
---|
285 | {date_str};... |
---|
286 | infomsg]); |
---|
287 | end |
---|
288 | end |
---|
289 | set(handles.uvmat,'UserData',UvData) |
---|
290 | if ~isempty(inputfile) |
---|
291 | %%%%% display the input field %%%%%%% |
---|
292 | display_file_name(handles,inputfile) |
---|
293 | %%%%%%% |
---|
294 | testinputfield=1; |
---|
295 | end |
---|
296 | |
---|
297 | %% plot input field if exists |
---|
298 | % if testinputfield |
---|
299 | % %delete drawn objects |
---|
300 | % hother=findobj(handles.PlotAxes,'Tag','proj_object');%find all the proj objects |
---|
301 | % for iobj=1:length(hother) |
---|
302 | % delete_object(hother(iobj)) |
---|
303 | % end |
---|
304 | % if isempty(inputfile) |
---|
305 | % errormsg=refresh_field(handles,[],[],[],[],[],[],{Field}); |
---|
306 | % set(handles.MenuTools,'Enable','on') |
---|
307 | % set(handles.OBJECT_txt,'Visible','on') |
---|
308 | % set(handles.edit_object,'Visible','on') |
---|
309 | % % set(handles.ListObject_1,'Visible','on') |
---|
310 | % set(handles.frame_object,'Visible','on') |
---|
311 | % if ~isempty(errormsg) |
---|
312 | % msgbox_uvmat('ERROR',errormsg) |
---|
313 | % end |
---|
314 | % end |
---|
315 | % end |
---|
316 | |
---|
317 | set_vec_col_bar(handles) %update the display of color code for vectors |
---|
318 | |
---|
319 | %------------------------------------------------------------------------ |
---|
320 | % --- Outputs from this function are returned to the command menuline. |
---|
321 | function varargout = uvmat_OutputFcn(hObject, eventdata, handles) |
---|
322 | varargout{1} = handles.output;% the only output argument is the handle to the GUI figure |
---|
323 | |
---|
324 | %------------------------------------------------------------------------ |
---|
325 | % --- executed when closing uvmat: delete or desactivate the associated figures if exist |
---|
326 | function closefcn(gcbo,eventdata) |
---|
327 | %------------------------------------------------------------------------ |
---|
328 | hh=findobj(allchild(0),'tag','view_field'); |
---|
329 | if ~isempty(hh) |
---|
330 | delete(hh) |
---|
331 | end |
---|
332 | hh=findobj(allchild(0),'tag','geometry_calib'); |
---|
333 | if ~isempty(hh) |
---|
334 | delete(hh) |
---|
335 | end |
---|
336 | hh=findobj(allchild(0),'tag','set_object'); |
---|
337 | if ~isempty(hh) |
---|
338 | hhh=findobj(hh,'tag','PLOT'); |
---|
339 | set(hhh,'enable','off') |
---|
340 | end |
---|
341 | |
---|
342 | %------------------------------------------------------------------------ |
---|
343 | %------------------------------------------------------------------------ |
---|
344 | % II - FUNCTIONS FOR INTRODUCING THE INPUT FILES |
---|
345 | % automatically sets the global properties when the rootfile name is introduced |
---|
346 | % then activate the view-field action if selected |
---|
347 | % it is activated either by clicking on the RootPath window or by the |
---|
348 | % browser |
---|
349 | %------------------------------------------------------------------------ |
---|
350 | %------------------------------------------------------------------------ |
---|
351 | % --- Executes on the menu Open/Browse... |
---|
352 | % search the files, recognize their type according to their name and fill the rootfile input windows |
---|
353 | function MenuBrowse_Callback(hObject, eventdata, handles) |
---|
354 | [RootPath,SubDir,RootFile,FileIndices,FileExt]=read_file_boxes(handles); |
---|
355 | %oldfile=[fullfile(RootPath,SubDir,RootFile) FileIndices FileExt]; |
---|
356 | oldfile=fullfile(RootPath,SubDir); |
---|
357 | if isempty(oldfile)||isequal(oldfile,'') %loads the previously stored file name and set it as default in the file_input box |
---|
358 | dir_perso=prefdir; |
---|
359 | profil_perso=fullfile(dir_perso,'uvmat_perso.mat'); |
---|
360 | if exist(profil_perso,'file') |
---|
361 | h=load (profil_perso); |
---|
362 | if isfield(h,'MenuFile_1') |
---|
363 | oldfile=h.MenuFile_1; |
---|
364 | end |
---|
365 | end |
---|
366 | end |
---|
367 | [FileName, PathName] = uigetfile({'*.*','All Files(*.*)'},'Pick a file',oldfile); |
---|
368 | fileinput=[PathName FileName];%complete file name |
---|
369 | if ~exist(fileinput,'file') |
---|
370 | return %abandon if the browser is cancelled |
---|
371 | end |
---|
372 | |
---|
373 | %% display the selected field and related information |
---|
374 | display_file_name( handles,fileinput) |
---|
375 | |
---|
376 | % ----------------------------------------------------------------------- |
---|
377 | % --- Open again the file whose name has been recorded in MenuFile_1 |
---|
378 | function MenuFile_1_Callback(hObject, eventdata, handles) |
---|
379 | %------------------------------------------------------------------------ |
---|
380 | fileinput=get(handles.MenuFile_1,'Label'); |
---|
381 | display_file_name( handles,fileinput) |
---|
382 | |
---|
383 | % ----------------------------------------------------------------------- |
---|
384 | % --- Open again the file whose name has been recorded in MenuFile_2 |
---|
385 | function MenuFile_2_Callback(hObject, eventdata, handles) |
---|
386 | %------------------------------------------------------------------------ |
---|
387 | fileinput=get(handles.MenuFile_2,'Label'); |
---|
388 | display_file_name(handles,fileinput) |
---|
389 | |
---|
390 | % ----------------------------------------------------------------------- |
---|
391 | % --- Open again the file whose name has been recorded in MenuFile_3 |
---|
392 | function MenuFile_3_Callback(hObject, eventdata, handles) |
---|
393 | %------------------------------------------------------------------------ |
---|
394 | fileinput=get(handles.MenuFile_3,'Label'); |
---|
395 | display_file_name(handles,fileinput) |
---|
396 | |
---|
397 | % ----------------------------------------------------------------------- |
---|
398 | % --- Open again the file whose name has been recorded in MenuFile_4 |
---|
399 | function MenuFile_4_Callback(hObject, eventdata, handles) |
---|
400 | %------------------------------------------------------------------------ |
---|
401 | fileinput=get(handles.MenuFile_4,'Label'); |
---|
402 | display_file_name(handles,fileinput) |
---|
403 | |
---|
404 | % ----------------------------------------------------------------------- |
---|
405 | % --- Open again the file whose name has been recorded in MenuFile_5 |
---|
406 | function MenuFile_5_Callback(hObject, eventdata, handles) |
---|
407 | %------------------------------------------------------------------------ |
---|
408 | fileinput=get(handles.MenuFile_5,'Label'); |
---|
409 | display_file_name(handles,fileinput) |
---|
410 | |
---|
411 | %------------------------------------------------------------------------ |
---|
412 | % --- Executes on the menu Open/Browse_1 for the second input field, |
---|
413 | % search the files, recognize their type according to their name and fill the rootfile input windows |
---|
414 | function MenuBrowse_1_Callback(hObject, eventdata, handles) |
---|
415 | %------------------------------------------------------------------------ |
---|
416 | RootPath=get(handles.RootPath,'String'); |
---|
417 | [FileName, PathName] = uigetfile({'*.*','All Files(*.*)'},'Pick a file',RootPath); |
---|
418 | fileinput_1=[PathName FileName];%complete file name |
---|
419 | if ~exist(fileinput_1,'file') |
---|
420 | return %abandon of the browser is cancelled |
---|
421 | end |
---|
422 | |
---|
423 | % refresh the current displayed field |
---|
424 | set(handles.SubField,'Value',1) |
---|
425 | display_file_name(handles,fileinput_1,2) |
---|
426 | |
---|
427 | %update list of recent files in the menubar |
---|
428 | MenuFile_1=fileinput_1; |
---|
429 | MenuFile_2=get(handles.MenuFile_1,'Label'); |
---|
430 | MenuFile_3=get(handles.MenuFile_2,'Label'); |
---|
431 | MenuFile_4=get(handles.MenuFile_3,'Label'); |
---|
432 | MenuFile_5=get(handles.MenuFile_4,'Label'); |
---|
433 | set(handles.MenuFile_1,'Label',MenuFile_1) |
---|
434 | set(handles.MenuFile_2,'Label',MenuFile_2) |
---|
435 | set(handles.MenuFile_3,'Label',MenuFile_3) |
---|
436 | set(handles.MenuFile_4,'Label',MenuFile_4) |
---|
437 | set(handles.MenuFile_5,'Label',MenuFile_5) |
---|
438 | set(handles.MenuFile_1_1,'Label',MenuFile_1) |
---|
439 | set(handles.MenuFile_2_1,'Label',MenuFile_2) |
---|
440 | set(handles.MenuFile_3_1,'Label',MenuFile_3) |
---|
441 | set(handles.MenuFile_4_1,'Label',MenuFile_4) |
---|
442 | set(handles.MenuFile_5_1,'Label',MenuFile_5) |
---|
443 | dir_perso=prefdir; |
---|
444 | profil_perso=fullfile(dir_perso,'uvmat_perso.mat'); |
---|
445 | if exist(profil_perso,'file') |
---|
446 | save (profil_perso,'MenuFile_1','MenuFile_2','MenuFile_3','MenuFile_4', 'MenuFile_5','-append'); %store the file names for future opening of uvmat |
---|
447 | else |
---|
448 | txt=ver('MATLAB'); |
---|
449 | Release=txt.Release; |
---|
450 | relnumb=str2double(Release(3:4)); |
---|
451 | if relnumb >= 14 |
---|
452 | save (profil_perso,'MenuFile_1','MenuFile_2','MenuFile_3','MenuFile_4', 'MenuFile_5','-V6'); %store the file names for future opening of uvmat |
---|
453 | else |
---|
454 | save (profil_perso,'MenuFile_1','MenuFile_2','MenuFile_3','MenuFile_4', 'MenuFile_5'); %store the file names for future opening of uvmat |
---|
455 | end |
---|
456 | end |
---|
457 | |
---|
458 | % ----------------------------------------------------------------------- |
---|
459 | % --- Open again as second field the file whose name has been recorded in MenuFile_1 |
---|
460 | function MenuFile_1_1_Callback(hObject, eventdata, handles) |
---|
461 | % ----------------------------------------------------------------------- |
---|
462 | fileinput_1=get(handles.MenuFile_1_1,'Label'); |
---|
463 | set(handles.SubField,'Value',1) |
---|
464 | display_file_name(handles,fileinput_1,2) |
---|
465 | |
---|
466 | % ----------------------------------------------------------------------- |
---|
467 | % --- Open again as second field the file whose name has been recorded in MenuFile_2 |
---|
468 | function MenuFile_2_1_Callback(hObject, eventdata, handles) |
---|
469 | % ----------------------------------------------------------------------- |
---|
470 | fileinput_1=get(handles.MenuFile_2_1,'Label'); |
---|
471 | set(handles.SubField,'Value',1) |
---|
472 | display_file_name(handles,fileinput_1,2) |
---|
473 | |
---|
474 | % ----------------------------------------------------------------------- |
---|
475 | % --- Open again as second field the file whose name has been recorded in MenuFile_3 |
---|
476 | function MenuFile_3_1_Callback(hObject, eventdata, handles) |
---|
477 | % ----------------------------------------------------------------------- |
---|
478 | fileinput_1=get(handles.MenuFile_3_1,'Label'); |
---|
479 | set(handles.SubField,'Value',1) |
---|
480 | display_file_name(handles,fileinput_1,2) |
---|
481 | |
---|
482 | % ----------------------------------------------------------------------- |
---|
483 | % --- Open again as second field the file whose name has been recorded in MenuFile_4 |
---|
484 | function MenuFile_4_1_Callback(hObject, eventdata, handles) |
---|
485 | % ----------------------------------------------------------------------- |
---|
486 | fileinput_1=get(handles.MenuFile_4_1,'Label'); |
---|
487 | set(handles.SubField,'Value',1) |
---|
488 | display_file_name(handles,fileinput_1,2) |
---|
489 | |
---|
490 | % ----------------------------------------------------------------------- |
---|
491 | % --- Open again as second field the file whose name has been recorded in MenuFile_5 |
---|
492 | function MenuFile_5_1_Callback(hObject, eventdata, handles) |
---|
493 | % ----------------------------------------------------------------------- |
---|
494 | fileinput_1=get(handles.MenuFile_5_1,'Label'); |
---|
495 | set(handles.SubField,'Value',1) |
---|
496 | display_file_name(handles,fileinput_1,2) |
---|
497 | |
---|
498 | %------------------------------------------------------------------------ |
---|
499 | % --- Called by action in RootPath edit box |
---|
500 | function RootPath_Callback(hObject,eventdata,handles) |
---|
501 | %------------------------------------------------------------------------ |
---|
502 | % read the current input file name: |
---|
503 | [RootPath,SubDir,RootFile,FileIndices,FileExt]=read_file_boxes(handles); |
---|
504 | if ~exist(fullfile(RootPath,SubDir),'dir') |
---|
505 | msgbox_uvmat('ERROR',['directory ' fullfile(RootPath,SubDir) ' does not exist']) |
---|
506 | return |
---|
507 | end |
---|
508 | % detect the file type, get the movie object if relevant, and look for the corresponding file series: |
---|
509 | [RootPath,SubDir,RootFile,i1_series,i2_series,j1_series,j2_series,tild,FileType,MovieObject]=find_file_series(fullfile(RootPath,SubDir),[RootFile FileIndices FileExt]); |
---|
510 | % initiate the input file series and refresh the current field view: |
---|
511 | update_rootinfo(handles,i1_series,i2_series,j1_series,j2_series,FileType,MovieObject,1); |
---|
512 | |
---|
513 | %----------------------------------------------------------------------- |
---|
514 | % --- Called by action in RootPath_1 edit box |
---|
515 | function RootPath_1_Callback(hObject,eventdata,handles) |
---|
516 | % ----------------------------------------------------------------------- |
---|
517 | % update_rootinfo_1(hObject,eventdata,handles) |
---|
518 | [RootPath,SubDir,RootFile,FileIndices,FileExt]=read_file_boxes_1(handles); |
---|
519 | if ~exist(fullfile(RootPath,SubDir),'dir') |
---|
520 | msgbox_uvmat('ERROR',['directory ' fullfile(RootPath,SubDir) ' does not exist']) |
---|
521 | return |
---|
522 | end |
---|
523 | % detect the file type, get the movie object if relevant, and look for the corresponding file series: |
---|
524 | [RootPath,SubDir,RootFile,i1_series,i2_series,j1_series,j2_series,tild,FileType,MovieObject]=find_file_series(fullfile(RootPath,SubDir),[RootFile FileIndices FileExt]); |
---|
525 | % initiate the input file series and refresh the current field view: |
---|
526 | update_rootinfo(handles,i1_series,i2_series,j1_series,j2_series,FileType,MovieObject,2); |
---|
527 | |
---|
528 | %------------------------------------------------------------------------ |
---|
529 | % --- Called by action in RootFile edit box |
---|
530 | function SubDir_Callback(hObject, eventdata, handles) |
---|
531 | %------------------------------------------------------------------------ |
---|
532 | %refresh the menu of input fields |
---|
533 | Fields_Callback(hObject, eventdata, handles); |
---|
534 | % refresh the current field view |
---|
535 | run0_Callback(hObject, eventdata, handles); |
---|
536 | |
---|
537 | %------------------------------------------------------------------------ |
---|
538 | % --- Called by action in RootFile edit box |
---|
539 | function RootFile_Callback(hObject, eventdata, handles) |
---|
540 | %------------------------------------------------------------------------ |
---|
541 | RootPath_Callback(hObject,eventdata,handles) |
---|
542 | |
---|
543 | %----------------------------------------------------------------------- |
---|
544 | % --- Called by action in RootFile_1 edit box |
---|
545 | function RootFile_1_Callback(hObject, eventdata, handles) |
---|
546 | % ----------------------------------------------------------------------- |
---|
547 | RootPath_1_Callback(hObject,eventdata,handles) |
---|
548 | |
---|
549 | %------------------------------------------------------------------------ |
---|
550 | % --- Called by action in FileIndex edit box |
---|
551 | function FileIndex_Callback(hObject, eventdata, handles) |
---|
552 | %------------------------------------------------------------------------ |
---|
553 | [tild,tild,tild,i1,i2,j1,j2]=fileparts_uvmat(get(handles.FileIndex,'String')); |
---|
554 | set(handles.i1,'String',num2str(i1)); |
---|
555 | set(handles.i2,'String',num2str(i2)); |
---|
556 | set(handles.j1,'String',num2str(j1)); |
---|
557 | set(handles.j2,'String',num2str(j2)); |
---|
558 | |
---|
559 | % refresh the current field view |
---|
560 | run0_Callback(hObject, eventdata, handles) |
---|
561 | |
---|
562 | %------------------------------------------------------------------------ |
---|
563 | % --- Called by action in FileIndex_1 edit box |
---|
564 | function FileIndex_1_Callback(hObject, eventdata, handles) |
---|
565 | %------------------------------------------------------------------------ |
---|
566 | run0_Callback(hObject, eventdata, handles) |
---|
567 | |
---|
568 | %------------------------------------------------------------------------ |
---|
569 | % --- Called by action in NomType edit box |
---|
570 | function NomType_Callback(hObject, eventdata, handles) |
---|
571 | %------------------------------------------------------------------------ |
---|
572 | i1=str2num(get(handles.i1,'String')); |
---|
573 | i2=str2num(get(handles.i2,'String')); |
---|
574 | j1=str2num(get(handles.j1,'String')); |
---|
575 | j2=str2num(get(handles.j2,'String')); |
---|
576 | FileIndex=fullfile_uvmat('','','','',get(handles.NomType,'String'),i1,i2,j1,j2); |
---|
577 | set(handles.FileIndex,'String',FileIndex) |
---|
578 | % refresh the current settings and refresh the field view |
---|
579 | RootPath_Callback(hObject,eventdata,handles) |
---|
580 | |
---|
581 | %------------------------------------------------------------------------ |
---|
582 | % --- Called by action in NomType edit box |
---|
583 | function NomType_1_Callback(hObject, eventdata, handles) |
---|
584 | %------------------------------------------------------------------------ |
---|
585 | i1=str2num(get(handles.i1,'String')); |
---|
586 | i2=str2num(get(handles.i2,'String')); |
---|
587 | j1=str2num(get(handles.j1,'String')); |
---|
588 | j2=str2num(get(handles.j2,'String')); |
---|
589 | FileIndex=fullfile_uvmat('','','','',get(handles.NomType_1,'String'),i1,i2,j1,j2); |
---|
590 | set(handles.FileIndex_1,'String',FileIndex) |
---|
591 | % refresh the current settings and refresh the field view |
---|
592 | RootPath_1_Callback(hObject,eventdata,handles) |
---|
593 | |
---|
594 | %------------------------------------------------------------------------ |
---|
595 | % --- Fills the edit boxes RootPath, RootFile,NomType...from an input file name 'fileinput' |
---|
596 | function display_file_name(handles,fileinput,index) |
---|
597 | %------------------------------------------------------------------------ |
---|
598 | %% look for the input file existence |
---|
599 | if ~exist(fileinput,'file') |
---|
600 | msgbox_uvmat('ERROR',['input file ' fileinput ' does not exist']) |
---|
601 | return |
---|
602 | end |
---|
603 | |
---|
604 | %% set the mouse pointer to 'watch' |
---|
605 | set(handles.uvmat,'Pointer','watch') |
---|
606 | set(handles.RootPath,'BackgroundColor',[1 1 0]) |
---|
607 | drawnow |
---|
608 | |
---|
609 | %% define the relevant handles for the first field series (index=1) or the second file series (index=2) |
---|
610 | if ~exist('index','var') |
---|
611 | index=1; |
---|
612 | end |
---|
613 | if index==1 |
---|
614 | handles_RootPath=handles.RootPath; |
---|
615 | handles_SubDir=handles.SubDir; |
---|
616 | handles_RootFile=handles.RootFile; |
---|
617 | handles_FileIndex=handles.FileIndex; |
---|
618 | handles_NomType=handles.NomType; |
---|
619 | handles_FileExt=handles.FileExt; |
---|
620 | elseif index==2 |
---|
621 | handles_RootPath=handles.RootPath_1; |
---|
622 | handles_SubDir=handles.SubDir_1; |
---|
623 | handles_RootFile=handles.RootFile_1; |
---|
624 | handles_FileIndex=handles.FileIndex_1; |
---|
625 | handles_NomType=handles.NomType_1; |
---|
626 | handles_FileExt=handles.FileExt_1; |
---|
627 | set(handles.RootPath_1,'Visible','on') |
---|
628 | set(handles.RootFile_1,'Visible','on') |
---|
629 | set(handles.SubDir_1,'Visible','on'); |
---|
630 | set(handles.FileIndex_1,'Visible','on'); |
---|
631 | set(handles.FileExt_1,'Visible','on'); |
---|
632 | set(handles.NomType_1,'Visible','on'); |
---|
633 | end |
---|
634 | |
---|
635 | %% detect root name, nomenclature and indices in the input file name: |
---|
636 | [FilePath,FileName,FileExt]=fileparts(fileinput); |
---|
637 | % detect the file type, get the movie object if relevant, and look for the corresponding file series: |
---|
638 | % the root name and indices may be corrected by including the first index i1 if a corresponding xml file exists |
---|
639 | [RootPath,SubDir,RootFile,i1_series,i2_series,j1_series,j2_series,NomType,FileType,MovieObject,i1,i2,j1,j2]=find_file_series(FilePath,[FileName FileExt]); |
---|
640 | |
---|
641 | %% open the file or fill the GUI uvmat according to the detected file type |
---|
642 | switch FileType |
---|
643 | case '' |
---|
644 | msgbox_uvmat('ERROR','invalid input file type') |
---|
645 | case 'txt' |
---|
646 | edit(fileinput) |
---|
647 | case 'figure' %display matlab figure |
---|
648 | hfig=open(fileinput); |
---|
649 | set(hfig,'WindowButtonMotionFcn','mouse_motion')%set mouse action functio |
---|
650 | set(hfig,'WindowButtonUpFcn','mouse_up')%set mouse click action function |
---|
651 | set(hfig,'WindowButtonUpFcn','mouse_down')%set mouse click action function |
---|
652 | case 'xml' % edit xml files |
---|
653 | t=xmltree(fileinput); |
---|
654 | % the xml file marks a project or project link, open datatree_browser |
---|
655 | if strcmp(get(t,1,'name'),'Project')&& exist(regexprep(fileinput,'.xml$',''),'dir') |
---|
656 | datatree_browser(fileinput) |
---|
657 | else % other xml file, open the xml editor |
---|
658 | editxml(fileinput); |
---|
659 | end |
---|
660 | case 'xls'% Excel file opended by editxml |
---|
661 | editxml(fileinput); |
---|
662 | otherwise |
---|
663 | set(handles_RootPath,'String',RootPath); |
---|
664 | rootname=fullfile(RootPath,SubDir,RootFile); |
---|
665 | set(handles_SubDir,'String',['/' SubDir]); |
---|
666 | set(handles_RootFile,'String',['/' RootFile]); %display the separator |
---|
667 | indices=fileinput(length(rootname)+1:end); |
---|
668 | indices(end-length(FileExt)+1:end)=[]; %remove extension |
---|
669 | set(handles_FileIndex,'String',indices); |
---|
670 | set(handles_NomType,'String',NomType); |
---|
671 | set(handles_FileExt,'String',FileExt); |
---|
672 | if index==1 |
---|
673 | % fill file index counters if the first file series is opened |
---|
674 | set(handles.i1,'String',num2str(i1)); |
---|
675 | set(handles.i2,'String',num2str(i2)); |
---|
676 | set(handles.j1,'String',num2stra(j1,NomType)); |
---|
677 | set(handles.j2,'String',num2stra(j2,NomType)); |
---|
678 | else %read the current field index to synchronise with the first series |
---|
679 | i1_s=str2num(get(handles.i1,'String')); |
---|
680 | i2_0=str2num(get(handles.i2,'String')); |
---|
681 | if ~isempty(i2_0) |
---|
682 | i2_s=i2_0; |
---|
683 | else |
---|
684 | i2_s=i2; |
---|
685 | end |
---|
686 | j1_0=stra2num(get(handles.j1,'String')); |
---|
687 | if ~isempty(j1_0) |
---|
688 | j1_s=j1_0; |
---|
689 | else |
---|
690 | j1_s=j1; |
---|
691 | end |
---|
692 | j2_0=stra2num(get(handles.j2,'String')); |
---|
693 | if ~isempty(j2_0) |
---|
694 | j2_s=j2_0; |
---|
695 | else |
---|
696 | j2_s=j2; |
---|
697 | end |
---|
698 | end |
---|
699 | |
---|
700 | % synchronise indices of the second input file if it exists |
---|
701 | if get(handles.SubField,'Value')==1% if the subfield button is activated, update the field numbers |
---|
702 | Input=read_GUI(handles.InputFile); |
---|
703 | if ~isfield(Input,'RootPath_1')||strcmp(Input.RootPath_1,'"') |
---|
704 | Input.RootPath_1=Input.RootPath; |
---|
705 | end |
---|
706 | if ~isfield(Input,'SubDir_1')||strcmp(Input.SubDir_1,'"') |
---|
707 | Input.SubDir_1=Input.SubDir; |
---|
708 | end |
---|
709 | if ~isfield(Input,'RootFile_1')||strcmp(Input.RootFile_1,'"') |
---|
710 | Input.RootFile_1=Input.RootFile; |
---|
711 | end |
---|
712 | if ~isfield(Input,'FileExt_1')||strcmp(Input.FileExt_1,'"') |
---|
713 | Input.FileExt_1=Input.FileExt; |
---|
714 | end |
---|
715 | if ~isfield(Input,'NomType_1')||strcmp(Input.NomType_1,'"') |
---|
716 | Input.NomType_1=Input.NomType; |
---|
717 | end |
---|
718 | %updtate the indices of the second field series to correspond to the newly opened one |
---|
719 | FileName_1=fullfile_uvmat(Input.RootPath_1,Input.SubDir_1,Input.RootFile_1,Input.FileExt_1,Input.NomType_1,i1_s,i2_s,j1_s,j2_s); |
---|
720 | if exist(FileName_1,'file') |
---|
721 | FileIndex_1=fullfile_uvmat('','','','',Input.NomType_1,i1_s,i2_s,j1_s,j2_s); |
---|
722 | else |
---|
723 | FileIndex_1=fullfile_uvmat('','','','',Input.NomType_1,i1,i2,j1,j2); |
---|
724 | msgbox_uvmat('WARNING','unable to synchronise the indices of the two series') |
---|
725 | end |
---|
726 | set(handles.FileIndex_1,'String',FileIndex_1) |
---|
727 | end |
---|
728 | |
---|
729 | %enable other menus |
---|
730 | set(handles.MenuOpen_1,'Enable','on') |
---|
731 | set(handles.MenuFile_1_1,'Enable','on') |
---|
732 | set(handles.MenuFile_2_1,'Enable','on') |
---|
733 | set(handles.MenuFile_3_1,'Enable','on') |
---|
734 | set(handles.MenuFile_4_1,'Enable','on') |
---|
735 | set(handles.MenuFile_5_1,'Enable','on') |
---|
736 | set(handles.MenuExport,'Enable','on') |
---|
737 | set(handles.MenuExportFigure,'Enable','on') |
---|
738 | set(handles.MenuExportMovie,'Enable','on') |
---|
739 | set(handles.MenuTools,'Enable','on') |
---|
740 | |
---|
741 | % initiate input file series and refresh the current field view: |
---|
742 | update_rootinfo(handles,i1_series,i2_series,j1_series,j2_series,FileType,MovieObject,index); |
---|
743 | |
---|
744 | end |
---|
745 | |
---|
746 | %% update list of recent files in the menubar and save it for future opening |
---|
747 | MenuFile=[{get(handles.MenuFile_1,'Label')};{get(handles.MenuFile_2,'Label')};... |
---|
748 | {get(handles.MenuFile_3,'Label')};{get(handles.MenuFile_4,'Label')};{get(handles.MenuFile_5,'Label')}]; |
---|
749 | str_find=strcmp(fileinput,MenuFile); |
---|
750 | if isempty(find(str_find,1)) |
---|
751 | MenuFile=[{fileinput};MenuFile];%insert the current file if not already in the list |
---|
752 | end |
---|
753 | for ifile=1:min(length(MenuFile),5) |
---|
754 | eval(['set(handles.MenuFile_' num2str(ifile) ',''Label'',MenuFile{ifile});']) |
---|
755 | eval(['set(handles.MenuFile_' num2str(ifile) '_1,''Label'',MenuFile{ifile});']) |
---|
756 | end |
---|
757 | dir_perso=prefdir; |
---|
758 | profil_perso=fullfile(dir_perso,'uvmat_perso.mat'); |
---|
759 | if exist(profil_perso,'file') |
---|
760 | save (profil_perso,'MenuFile','-append'); %store the file names for future opening of uvmat |
---|
761 | else |
---|
762 | save (profil_perso,'MenuFile','-V6'); %store the file names for future opening of uvmat |
---|
763 | end |
---|
764 | |
---|
765 | %% set back the mouse pointer to arrow |
---|
766 | set(handles.uvmat,'Pointer','arrow') |
---|
767 | |
---|
768 | |
---|
769 | %------------------------------------------------------------------------ |
---|
770 | % --- Update information about a new field series (indices to scan, timing, |
---|
771 | % calibration from an xml file, then refresh current plots |
---|
772 | |
---|
773 | function update_rootinfo(handles,i1_series,i2_series,j1_series,j2_series,FileType,VideoObject,index) |
---|
774 | %------------------------------------------------------------------------ |
---|
775 | %% define the relevant handles depending on the index (1=first file series, 2= second file series) |
---|
776 | if ~exist('index','var') |
---|
777 | index=1; |
---|
778 | end |
---|
779 | if index==1 |
---|
780 | handles_RootPath=handles.RootPath; |
---|
781 | handles_Fields=handles.Fields; |
---|
782 | elseif index==2 |
---|
783 | handles_RootPath=handles.RootPath_1; |
---|
784 | handles_Fields=handles.Fields_1; |
---|
785 | end |
---|
786 | |
---|
787 | set(handles_RootPath,'BackgroundColor',[1 1 0]) |
---|
788 | drawnow |
---|
789 | set(handles.Fields,'UserData',[])% reinialize data from uvmat opening |
---|
790 | UvData=get(handles.uvmat,'UserData');%huvmat=handles of the uvmat interface |
---|
791 | UvData.NewSeries=1; %flag for run0: begin a new series |
---|
792 | UvData.FileName_1='';% name of the current second field (used to detect a constant field during file scanning) |
---|
793 | UvData.FileType{index}=FileType; |
---|
794 | UvData.i1_series{index}=i1_series; |
---|
795 | UvData.i2_series{index}=i2_series; |
---|
796 | UvData.j1_series{index}=j1_series; |
---|
797 | UvData.j2_series{index}=j2_series; |
---|
798 | set(handles.FixVelType,'Value',0); %desactivate fixed veltype |
---|
799 | if index==1 |
---|
800 | [RootPath,SubDir,RootFile,FileIndices,FileExt]=read_file_boxes(handles); |
---|
801 | else |
---|
802 | [RootPath,SubDir,RootFile,FileIndices,FileExt]=read_file_boxes_1(handles); |
---|
803 | end |
---|
804 | FileName=[fullfile(RootPath,SubDir,RootFile) FileIndices FileExt]; |
---|
805 | FileBase=fullfile(RootPath,RootFile); |
---|
806 | if ~exist(FileName,'file') |
---|
807 | msgbox_uvmat('ERROR',['input file ' FileName ' not found']); |
---|
808 | return |
---|
809 | end |
---|
810 | |
---|
811 | %% read timing and total frame number from the current file (movie files) !! may be overrid by xml file |
---|
812 | XmlData.Time=[];%default |
---|
813 | XmlData.GeometryCalib=[];%default |
---|
814 | TimeUnit='';%default |
---|
815 | Time=[]; |
---|
816 | testima=0; %test for image input |
---|
817 | imainfo=[]; |
---|
818 | ColorType='falsecolor'; %default |
---|
819 | hhh=[]; |
---|
820 | UvData.MovieObject{index}=VideoObject; |
---|
821 | if ~isempty(VideoObject) |
---|
822 | imainfo=get(VideoObject); |
---|
823 | testima=1; |
---|
824 | TimeUnit='s'; |
---|
825 | if isempty(j1_series); %frame index along i |
---|
826 | Time=(0:1/imainfo.FrameRate:(imainfo.NumberOfFrames)/imainfo.FrameRate)'; |
---|
827 | else |
---|
828 | Time=ones(size(i1_series,1),1)*(0:1/imainfo.FrameRate:(imainfo.NumberOfFrames)/imainfo.FrameRate); |
---|
829 | end |
---|
830 | %nbfield=imainfo.NumberOfFrames; |
---|
831 | set(handles.Dt_txt,'String',['Dt=' num2str(1000/imainfo.FrameRate) 'ms']);%display the elementary time interval in millisec |
---|
832 | ColorType='truecolor'; |
---|
833 | elseif ~isempty(FileExt(2:end))&&(~isempty(imformats(FileExt(2:end))) || isequal(FileExt,'.vol'))%&& isequal(NomType,'*')% multi-frame image |
---|
834 | testima=1; |
---|
835 | if ~isequal(SubDir,'') |
---|
836 | RootFile=get(handles.RootFile,'String'); |
---|
837 | imainfo=imfinfo([fullfile(RootPath,SubDir,RootFile) FileIndices FileExt]); |
---|
838 | else |
---|
839 | imainfo=imfinfo([FileBase FileIndices FileExt]); |
---|
840 | end |
---|
841 | ColorType=imainfo.ColorType;%='truecolor' for color images |
---|
842 | if length(imainfo) >1 %case of image with multiple frames |
---|
843 | % nbfield=length(imainfo); |
---|
844 | % nbfield_j=1; |
---|
845 | end |
---|
846 | end |
---|
847 | if isfield(imainfo,'Width') && isfield(imainfo,'Height') |
---|
848 | if length(imainfo)>1 |
---|
849 | set(handles.num_Npx,'String',num2str(imainfo(1).Width));%fills nbre of pixels x box |
---|
850 | set(handles.num_Npy,'String',num2str(imainfo(1).Height));%fills nbre of pixels x box |
---|
851 | else |
---|
852 | set(handles.num_Npx,'String',num2str(imainfo.Width));%fills nbre of pixels x box |
---|
853 | set(handles.num_Npy,'String',num2str(imainfo.Height));%fills nbre of pixels x box |
---|
854 | end |
---|
855 | else |
---|
856 | set(handles.num_Npx,'String','');%fills nbre of pixels x box |
---|
857 | set(handles.num_Npy,'String','');%fills nbre of pixels x box |
---|
858 | end |
---|
859 | set(handles.CheckBW,'Value',strcmp(ColorType,'grayscale'))% select handles.CheckBW if grayscale image |
---|
860 | |
---|
861 | %% read parameters (time, geometric calibration..) from a documentation file (.xml advised) |
---|
862 | XmlFileName=find_imadoc(RootPath,SubDir,RootFile,FileExt); |
---|
863 | [tild,tild,DocExt]=fileparts(XmlFileName); |
---|
864 | warntext='';%default warning message |
---|
865 | NbSlice=1;%default |
---|
866 | set(handles.RootPath,'BackgroundColor',[1 1 1]) |
---|
867 | if ~isempty(XmlFileName) |
---|
868 | set(handles.view_xml,'Visible','on') |
---|
869 | set(handles.view_xml,'BackgroundColor',[1 1 0]) |
---|
870 | set(handles.view_xml,'String','view .xml') |
---|
871 | drawnow |
---|
872 | [XmlDataRead,warntext]=imadoc2struct(XmlFileName); |
---|
873 | if ~isempty(warntext) |
---|
874 | msgbox_uvmat('WARNING',warntext) |
---|
875 | end |
---|
876 | if isempty(XmlDataRead) |
---|
877 | set(handles.view_xml,'Visible','off') |
---|
878 | else |
---|
879 | set(handles.view_xml,'String',['view ' DocExt]) |
---|
880 | XmlData=XmlDataRead; |
---|
881 | if isfield(XmlData,'TimeUnit') |
---|
882 | if isfield(XmlData,'TimeUnit')&& ~isempty(XmlData.TimeUnit) |
---|
883 | TimeUnit=XmlData.TimeUnit; |
---|
884 | end |
---|
885 | end |
---|
886 | set(handles.view_xml,'BackgroundColor',[1 1 1]) |
---|
887 | drawnow |
---|
888 | if isfield(XmlData, 'GeometryCalib') && ~isempty(XmlData.GeometryCalib) |
---|
889 | if isfield(XmlData.GeometryCalib,'VolumeScan') && isequal(XmlData.GeometryCalib.VolumeScan,'y') |
---|
890 | set (handles.num_NbSlice,'String','volume') |
---|
891 | end |
---|
892 | hgeometry_calib=findobj('tag','geometry_calib'); |
---|
893 | if ~isempty(hgeometry_calib) |
---|
894 | GUserData=get(hgeometry_calib,'UserData'); |
---|
895 | if ~(isfield(GUserData,'XmlInputFile') && strcmp(GUserData.XmlInputFile,XmlFileName)) |
---|
896 | answer=msgbox_uvmat('INPUT_Y-N','replace the display of geometry_calib with the new input data?'); |
---|
897 | if strcmp(answer,'Yes') |
---|
898 | geometry_calib(XmlFileName);%diplay the new calibration points and parameters in geometry_calib |
---|
899 | end |
---|
900 | end |
---|
901 | end |
---|
902 | end |
---|
903 | end |
---|
904 | end |
---|
905 | if ~(isfield(XmlData,'Time')&& ~isempty(XmlData.Time)) |
---|
906 | XmlData.Time=Time; %time set by video |
---|
907 | end |
---|
908 | |
---|
909 | %% store last index in handles.lat_i and .last_j |
---|
910 | nbfield=max(max(max(i2_series))); |
---|
911 | if isempty(nbfield) |
---|
912 | nbfield=max(max(max(i1_series))); |
---|
913 | end |
---|
914 | nbfield_j=max(max(max(j2_series))); |
---|
915 | if isempty(nbfield_j) |
---|
916 | nbfield_j=max(max(max(j2_series))); |
---|
917 | end |
---|
918 | if ~isempty(XmlData.Time) |
---|
919 | %transform .Time to a column vector if it is a line vector the nomenclature uses a single index |
---|
920 | if isequal(size(XmlData.Time,1),1) |
---|
921 | NomType=get(handles.NomType,'String'); |
---|
922 | XmlData.Time=(XmlData.Time)'; |
---|
923 | end |
---|
924 | end |
---|
925 | last_i_cell=get(handles.last_i,'String'); |
---|
926 | if isempty(nbfield) |
---|
927 | last_i_cell{1}=''; |
---|
928 | else |
---|
929 | last_i_cell{1}=num2str(nbfield); |
---|
930 | end |
---|
931 | set(handles.last_i,'String',last_i_cell) |
---|
932 | last_j_cell=get(handles.last_j,'String'); |
---|
933 | if isempty(nbfield_j) |
---|
934 | last_j_cell{1}=''; |
---|
935 | else |
---|
936 | last_j_cell{1}=num2str(nbfield_j); |
---|
937 | end |
---|
938 | set(handles.last_j,'String',last_j_cell); |
---|
939 | |
---|
940 | %% store geometric calibration in UvData |
---|
941 | if isfield(XmlData,'GeometryCalib') |
---|
942 | GeometryCalib=XmlData.GeometryCalib; |
---|
943 | if isempty(GeometryCalib) |
---|
944 | set(handles.pxcm,'String','') |
---|
945 | set(handles.pycm,'String','') |
---|
946 | set(handles.transform_fct,'Value',1); % no transform by default |
---|
947 | else |
---|
948 | if (isfield(GeometryCalib,'R')&& ~isequal(GeometryCalib.R(2,1),0) && ~isequal(GeometryCalib.R(1,2),0)) ||... |
---|
949 | (isfield(GeometryCalib,'kappa1')&& ~isequal(GeometryCalib.kappa1,0)) |
---|
950 | set(handles.pxcm,'String','var') |
---|
951 | set(handles.pycm,'String','var') |
---|
952 | elseif isfield(GeometryCalib,'fx_fy') |
---|
953 | pixcmx=GeometryCalib.fx_fy(1);%*GeometryCalib.R(1,1)*GeometryCalib.sx/(GeometryCalib.Tz*GeometryCalib.dpx); |
---|
954 | pixcmy=GeometryCalib.fx_fy(2);%*GeometryCalib.R(2,2)/(GeometryCalib.Tz*GeometryCalib.dpy); |
---|
955 | set(handles.pxcm,'String',num2str(pixcmx)) |
---|
956 | set(handles.pycm,'String',num2str(pixcmy)) |
---|
957 | end |
---|
958 | if ~get(handles.CheckFixLimits,'Value') |
---|
959 | set(handles.transform_fct,'Value',3); % phys transform by default if fixedLimits is off |
---|
960 | end |
---|
961 | if isfield(GeometryCalib,'SliceCoord') |
---|
962 | siz=size(GeometryCalib.SliceCoord); |
---|
963 | if siz(1)>1 |
---|
964 | NbSlice=siz(1); |
---|
965 | set(handles.slices,'Visible','on') |
---|
966 | set(handles.slices,'Value',1) |
---|
967 | end |
---|
968 | if isfield(GeometryCalib,'VolumeScan') && isequal(GeometryCalib.VolumeScan,'y') |
---|
969 | set(handles.num_NbSlice,'String','volume') |
---|
970 | else |
---|
971 | set(handles.num_NbSlice,'String',num2str(NbSlice)) |
---|
972 | end |
---|
973 | slices_Callback([],[], handles) |
---|
974 | end |
---|
975 | end |
---|
976 | end |
---|
977 | |
---|
978 | %% update the data attached to the uvmat interface |
---|
979 | if ~isempty(TimeUnit) |
---|
980 | set(handles.time_txt,'String',['time (' TimeUnit ')']) |
---|
981 | end |
---|
982 | UvData.TimeUnit=TimeUnit; |
---|
983 | UvData.XmlData{index}=XmlData; |
---|
984 | UvData.NewSeries=1; |
---|
985 | % UvData.MovieObject=MovieObject; |
---|
986 | |
---|
987 | %display warning message |
---|
988 | if ~isequal(warntext,'') |
---|
989 | msgbox_uvmat('WARNING',warntext); |
---|
990 | end |
---|
991 | |
---|
992 | %% set default options in menu 'Fields' |
---|
993 | switch FileType |
---|
994 | case {'civx','civdata'} |
---|
995 | [FieldList,ColorList]=calc_field; |
---|
996 | set(handles_Fields,'String',[{'image'};FieldList;{'get_field...'}]);%standard menu for civx data |
---|
997 | set(handles_Fields,'Value',2) % set menu to 'velocity |
---|
998 | % col_vec=FieldList; |
---|
999 | % col_vec(1)=[];%remove 'velocity' option for vector color (must be a scalar) |
---|
1000 | set(handles.ColorScalar,'Value',1) |
---|
1001 | set(handles.ColorScalar,'String',ColorList) |
---|
1002 | set(handles.Vectors,'Visible','on') |
---|
1003 | set(handles.Coord_x,'Value',1); |
---|
1004 | set(handles.Coord_x,'String',{'X'}); |
---|
1005 | set(handles.Coord_y,'Value',1); |
---|
1006 | set(handles.Coord_y,'String',{'Y'}); |
---|
1007 | case 'netcdf' |
---|
1008 | set(handles_Fields,'Value',1) |
---|
1009 | set(handles_Fields,'String',{'get_field...'}) |
---|
1010 | hget_field=get_field(FileName); |
---|
1011 | hhget_field=guidata(hget_field); |
---|
1012 | get_field('RUN_Callback',hhget_field.RUN,[],hhget_field); |
---|
1013 | % set(handles_Fields,'Value',1) % set menu to 'get_field... |
---|
1014 | % set(handles_Fields,'String',{'get_field...'}) |
---|
1015 | % col_vec={'get_field...'}; |
---|
1016 | % |
---|
1017 | % set(handles.ColorScalar,'String',col_vec) |
---|
1018 | otherwise |
---|
1019 | set(handles_Fields,'Value',1) % set menu to 'image' |
---|
1020 | set(handles_Fields,'String',{'image'}) |
---|
1021 | set(handles.Coord_x,'Value',1); |
---|
1022 | set(handles.Coord_x,'String',{'AX'}); |
---|
1023 | set(handles.Coord_y,'Value',1); |
---|
1024 | set(handles.Coord_y,'String',{'AY'}); |
---|
1025 | end |
---|
1026 | set(handles.uvmat,'UserData',UvData) |
---|
1027 | |
---|
1028 | %% set index navigation options and refresh plots |
---|
1029 | scan_option='i';%default |
---|
1030 | state_j='off'; %default |
---|
1031 | if index==2 |
---|
1032 | if get(handles.scan_j,'Value') |
---|
1033 | scan_option='j'; %keep the scan option for the second file series |
---|
1034 | end |
---|
1035 | if strcmp(get(handles.j1,'Visible'),'on') |
---|
1036 | state_j='on'; |
---|
1037 | end |
---|
1038 | end |
---|
1039 | [ref_j,ref_i]=find(squeeze(i1_series(1,:,:))); |
---|
1040 | if ~isempty(j1_series) |
---|
1041 | state_j='on'; |
---|
1042 | if index==1 |
---|
1043 | if isequal(ref_i,ref_i(1)*ones(size(ref_j)))% if ref_i is always equal to its first value |
---|
1044 | scan_option='j'; %scan j indext |
---|
1045 | end |
---|
1046 | end |
---|
1047 | end |
---|
1048 | if isequal(scan_option,'i') |
---|
1049 | diff_ref_i=diff(ref_i,1); |
---|
1050 | if isempty(diff_ref_i) |
---|
1051 | diff_ref_i=1; |
---|
1052 | end |
---|
1053 | if isequal (diff_ref_i,diff_ref_i(1)*ones(size(diff_ref_i))) |
---|
1054 | set(handles.num_IndexIncrement,'String',num2str(diff_ref_i(1))) |
---|
1055 | end |
---|
1056 | set(handles.scan_i,'Value',1) |
---|
1057 | scan_i_Callback([],[], handles); |
---|
1058 | else |
---|
1059 | diff_ref_j=diff(ref_j); |
---|
1060 | if isempty(diff_ref_j) |
---|
1061 | diff_ref_j=1; |
---|
1062 | end |
---|
1063 | if isequal (diff_ref_j,diff_ref_j(1)*ones(size(diff_ref_j))) |
---|
1064 | set(handles.num_IndexIncrement,'String',num2str(diff_ref_j(1))) |
---|
1065 | end |
---|
1066 | set(handles.scan_j,'Value',1) |
---|
1067 | scan_j_Callback([],[], handles); |
---|
1068 | end |
---|
1069 | set(handles.scan_j,'Visible',state_j) |
---|
1070 | set(handles.j1,'Visible',state_j) |
---|
1071 | set(handles.j2,'Visible',state_j) |
---|
1072 | set(handles.last_j,'Visible',state_j); |
---|
1073 | set(handles.frame_j,'Visible',state_j); |
---|
1074 | set(handles.j_text,'Visible',state_j); |
---|
1075 | if ~isempty(i2_series)||~isempty(j2_series) |
---|
1076 | set(handles.CheckFixPair,'Visible','on') |
---|
1077 | elseif index==1 |
---|
1078 | set(handles.CheckFixPair,'Visible','off') |
---|
1079 | end |
---|
1080 | |
---|
1081 | %% apply the effect of the transform fct and view the field |
---|
1082 | transform=get(handles.path_transform,'UserData'); |
---|
1083 | if index==2 && (~isa(transform,'function_handle')||nargin(transform)<3) |
---|
1084 | set(handles.transform_fct,'value',2); % set transform to sub_field if the current fct doe not accept two input fields |
---|
1085 | end |
---|
1086 | transform_fct_Callback([],[],handles) |
---|
1087 | mask_test=get(handles.CheckMask,'value'); |
---|
1088 | if mask_test |
---|
1089 | MaskData=get(handles.CheckMask,'UserData'); |
---|
1090 | if isfield(MaskData,'maskhandle') && ishandle(MaskData.maskhandle) |
---|
1091 | delete(MaskData.maskhandle) %delete old mask |
---|
1092 | end |
---|
1093 | CheckMask_Callback([],[],handles) |
---|
1094 | end |
---|
1095 | |
---|
1096 | %------------------------------------------------------------------------ |
---|
1097 | % --- switch file index scanning options scan_i and scan_j in an exclusive way |
---|
1098 | function scan_i_Callback(hObject, eventdata, handles) |
---|
1099 | %------------------------------------------------------------------------ |
---|
1100 | if get(handles.scan_i,'Value')==1 |
---|
1101 | set(handles.scan_i,'BackgroundColor',[1 1 0]) |
---|
1102 | set(handles.scan_j,'Value',0) |
---|
1103 | else |
---|
1104 | set(handles.scan_i,'BackgroundColor',[0.831 0.816 0.784]) |
---|
1105 | set(handles.scan_j,'Value',1) |
---|
1106 | end |
---|
1107 | scan_j_Callback(hObject, eventdata, handles) |
---|
1108 | |
---|
1109 | %------------------------------------------------------------------------ |
---|
1110 | % --- switch file index scanning options scan_i and scan_j in an exclusive way |
---|
1111 | function scan_j_Callback(hObject, eventdata, handles) |
---|
1112 | %------------------------------------------------------------------------ |
---|
1113 | if get(handles.scan_j,'Value')==1 |
---|
1114 | set(handles.scan_j,'BackgroundColor',[1 1 0]) |
---|
1115 | set(handles.scan_i,'Value',0) |
---|
1116 | set(handles.scan_i,'BackgroundColor',[0.831 0.816 0.784]) |
---|
1117 | % NomType=get(handles.NomType,'String'); |
---|
1118 | % switch NomType |
---|
1119 | % case {'_1_1-2','#_ab','%3dab'},% pair with j index |
---|
1120 | % set(handles.CheckFixPair,'Visible','on')% option fixed pair on/off made visible (choice of avaible pair with buttons + and - if ='off') |
---|
1121 | % otherwise |
---|
1122 | % set(handles.CheckFixPair,'Visible','off') |
---|
1123 | % end |
---|
1124 | else |
---|
1125 | set(handles.scan_j,'BackgroundColor',[0.831 0.816 0.784]) |
---|
1126 | set(handles.scan_i,'Value',1) |
---|
1127 | set(handles.scan_i,'BackgroundColor',[1 1 0]) |
---|
1128 | set(handles.CheckFixPair,'Visible','off') |
---|
1129 | end |
---|
1130 | |
---|
1131 | %------------------------------------------------------------------------ |
---|
1132 | function i1_Callback(hObject, eventdata, handles) |
---|
1133 | %------------------------------------------------------------------------ |
---|
1134 | update_ij(handles,1) |
---|
1135 | |
---|
1136 | %------------------------------------------------------------------------ |
---|
1137 | function i2_Callback(hObject, eventdata, handles) |
---|
1138 | %------------------------------------------------------------------------ |
---|
1139 | update_ij(handles,2) |
---|
1140 | |
---|
1141 | %------------------------------------------------------------------------ |
---|
1142 | function j1_Callback(hObject, eventdata, handles) |
---|
1143 | %------------------------------------------------------------------------ |
---|
1144 | update_ij(handles,3) |
---|
1145 | |
---|
1146 | %------------------------------------------------------------------------ |
---|
1147 | function j2_Callback(hObject, eventdata, handles) |
---|
1148 | %------------------------------------------------------------------------ |
---|
1149 | update_ij(handles,4) |
---|
1150 | |
---|
1151 | %------------------------------------------------------------------------ |
---|
1152 | %--- update the index display after action on edit boxes i1, i2, j1 or j2 |
---|
1153 | function update_ij(handles,index_rank) |
---|
1154 | NomType=get(handles.NomType,'String'); |
---|
1155 | indices=get(handles.FileIndex,'String'); |
---|
1156 | [tild,tild,tild,i1,i2,j1,j2]=fileparts_uvmat(indices);% the indices for the second series taken from FileIndex |
---|
1157 | switch index_rank |
---|
1158 | case 1 |
---|
1159 | indices=fullfile_uvmat('','','','',NomType,stra2num(get(handles.i1,'String')),i2,j1,j2); |
---|
1160 | set(handles.i1,'BackgroundColor',[0.7 0.7 0.7])% mark the edit box in grey, then RUN0 will mark it in white for confirmation |
---|
1161 | case 2 |
---|
1162 | indices=fullfile_uvmat('','','','',NomType,i1,stra2num(get(handles.i2,'String')),j1,j2); |
---|
1163 | set(handles.i2,'BackgroundColor',[0.7 0.7 0.7])% mark the edit box in grey, then RUN0 will mark it in white for confirmation |
---|
1164 | case 3 |
---|
1165 | indices=fullfile_uvmat('','','','',NomType,i1,i2,stra2num(get(handles.j1,'String')),j2); |
---|
1166 | set(handles.j1,'BackgroundColor',[0.7 0.7 0.7])% mark the edit box in grey, then RUN0 will mark it in white for confirmation |
---|
1167 | case 4 |
---|
1168 | indices=fullfile_uvmat('','','','',NomType,i1,i2,j1,stra2num(get(handles.j2,'String'))); |
---|
1169 | set(handles.j2,'BackgroundColor',[0.7 0.7 0.7])% mark the edit box in grey, then RUN0 will mark it in white for confirmation |
---|
1170 | end |
---|
1171 | set(handles.FileIndex,'String',indices) |
---|
1172 | set(handles.FileIndex,'BackgroundColor',[0.7 0.7 0.7])% mark the edit box in grey, then RUN0 will mark it in white for confirmation |
---|
1173 | % update the second index if relevant |
---|
1174 | if strcmp(get(handles.FileIndex_1,'Visible'),'on') |
---|
1175 | NomType_1=get(handles.NomType_1,'String'); |
---|
1176 | indices_1=get(handles.FileIndex_1,'String'); |
---|
1177 | [tild,tild,tild,i1_1,i2_1,j1_1,j2_1]=fileparts_uvmat(indices_1);% the indices for the second series taken from FileIndex_1 |
---|
1178 | switch index_rank |
---|
1179 | case 1 |
---|
1180 | indices_1=fullfile_uvmat('','','','',NomType_1,stra2num(get(handles.i1,'String')),i2_1,j1_1,j2_1); |
---|
1181 | case 2 |
---|
1182 | indices_1=fullfile_uvmat('','','','',NomType_1,i1_1,stra2num(get(handles.i2,'String')),j1_1,j2_1); |
---|
1183 | case 3 |
---|
1184 | indices_1=fullfile_uvmat('','','','',NomType_1,i1_1,i2_1,stra2num(get(handles.j1,'String')),j2_1); |
---|
1185 | case 4 |
---|
1186 | indices_1=fullfile_uvmat('','','','',NomType_1,i1_1,i2_1,j1_1,stra2num(get(handles.j2,'String'))); |
---|
1187 | end |
---|
1188 | set(handles.FileIndex_1,'String',indices_1) |
---|
1189 | set(handles.FileIndex_1,'BackgroundColor',[0.7 0.7 0.7])% mark the edit box in grey, then RUN0 will mark it in white for confirmation |
---|
1190 | end |
---|
1191 | |
---|
1192 | %------------------------------------------------------------------------ |
---|
1193 | |
---|
1194 | %------------------------------------------------------------------------ |
---|
1195 | function slices_Callback(hObject, eventdata, handles) |
---|
1196 | %------------------------------------------------------------------------ |
---|
1197 | if get(handles.slices,'Value')==1 |
---|
1198 | set(handles.slices,'BackgroundColor',[1 1 0]) |
---|
1199 | set(handles.num_NbSlice,'Visible','on') |
---|
1200 | set(handles.z_text,'Visible','on') |
---|
1201 | set(handles.z_index,'Visible','on') |
---|
1202 | num_NbSlice_Callback(hObject, eventdata, handles) |
---|
1203 | else |
---|
1204 | set(handles.num_NbSlice,'Visible','off') |
---|
1205 | set(handles.slices,'BackgroundColor',[0.7 0.7 0.7]) |
---|
1206 | set(handles.z_text,'Visible','off') |
---|
1207 | set(handles.z_index,'Visible','off') |
---|
1208 | set(handles.masklevel,'Value',1) |
---|
1209 | set(handles.masklevel,'String',{'1'}) |
---|
1210 | end |
---|
1211 | |
---|
1212 | %------------------------------------------------------------------------ |
---|
1213 | function num_NbSlice_Callback(hObject, eventdata, handles) |
---|
1214 | %------------------------------------------------------------------------ |
---|
1215 | nb_slice_str=get(handles.num_NbSlice,'String'); |
---|
1216 | if isequal(nb_slice_str,'volume') |
---|
1217 | num=stra2num(get(handles.j1,'String')); |
---|
1218 | last_j=get(handles.last_j,'String'); |
---|
1219 | nbslice=str2double(last_j{1}); |
---|
1220 | else |
---|
1221 | num=str2double(get(handles.i1,'String')); |
---|
1222 | nbslice=str2double(get(handles.num_NbSlice,'String')); |
---|
1223 | end |
---|
1224 | z=mod(num-1,nbslice)+1; |
---|
1225 | set(handles.z_index,'String',num2str(z)) |
---|
1226 | for ilist=1:nbslice |
---|
1227 | list_index{ilist,1}=num2str(ilist); |
---|
1228 | end |
---|
1229 | set(handles.masklevel,'String',list_index) |
---|
1230 | set(handles.masklevel,'Value',z) |
---|
1231 | |
---|
1232 | %------------------------------------------------------------------------ |
---|
1233 | % --- Executes on button press in view_xml. |
---|
1234 | function view_xml_Callback(hObject, eventdata, handles) |
---|
1235 | %------------------------------------------------------------------------ |
---|
1236 | %[FileName,RootPath,FileBase,FileIndices,FileExt]=read_file_boxes(handles); |
---|
1237 | [RootPath,SubDir,RootFile,FileIndices,FileExt]=read_file_boxes(handles); |
---|
1238 | FileBase=fullfile(RootPath,RootFile); |
---|
1239 | option=get(handles.view_xml,'String'); |
---|
1240 | if isequal(option,'view .xml') |
---|
1241 | FileXml=fullfile(RootPath,[SubDir '.xml']); |
---|
1242 | if ~exist(FileXml,'file')% case of civ files , removes the extension for subdir |
---|
1243 | FileXml=fullfile(RootPath,[regexprep(SubDir,'\..+$','') '.xml']); |
---|
1244 | end |
---|
1245 | heditxml=editxml(FileXml); |
---|
1246 | end |
---|
1247 | |
---|
1248 | %------------------------------------------------------------------------ |
---|
1249 | % --- Executes on button press in CheckMask. |
---|
1250 | function CheckMask_Callback(hObject, eventdata, handles) |
---|
1251 | %------------------------------------------------------------------------ |
---|
1252 | %case of view mask selection |
---|
1253 | if isequal(get(handles.CheckMask,'Value'),1) |
---|
1254 | [RootPath,SubDir,RootFile,FileIndices,FileExt]=read_file_boxes(handles); |
---|
1255 | FileBase=fullfile(RootPath,RootFile); |
---|
1256 | num_i1=stra2num(get(handles.i1,'String')); |
---|
1257 | num_j1=stra2num(get(handles.j1,'String')); |
---|
1258 | currentdir=pwd; |
---|
1259 | cd(RootPath); |
---|
1260 | maskfiles=dir('*_*mask_*.png');%look for a mask file |
---|
1261 | cd(currentdir);%come back to the working directory |
---|
1262 | mdetect=0; |
---|
1263 | if ~isempty(maskfiles) |
---|
1264 | for ilist=1:length(maskfiles) |
---|
1265 | maskname=maskfiles(ilist).name;% take the first mask file in the list |
---|
1266 | [tild,tild,tild,tild,tild,tild,tild,MaskExt,Mask_NomType{ilist}]=fileparts_uvmat(maskname); |
---|
1267 | [tild,Name]=fileparts(maskname); |
---|
1268 | Namedouble=double(Name); |
---|
1269 | val=(48>Namedouble)|(Namedouble>57);% select the non-numerical characters |
---|
1270 | ind_mask=findstr('mask',Name); |
---|
1271 | i=ind_mask-1; |
---|
1272 | while val(i)==0 && i>0 |
---|
1273 | i=i-1; |
---|
1274 | end |
---|
1275 | nbmask_str=str2num(Name(i+1:ind_mask-1)); |
---|
1276 | if ~isempty(nbmask_str) |
---|
1277 | nbslice(ilist)=nbmask_str; % number of different masks (slices) |
---|
1278 | end |
---|
1279 | end |
---|
1280 | if isequal(min(nbslice),max(nbslice)) |
---|
1281 | nbslice=nbslice(1); |
---|
1282 | else |
---|
1283 | msgbox_uvmat('ERROR','several inconsistent mask sets coexist in the current image directory') |
---|
1284 | return |
---|
1285 | end |
---|
1286 | if ~isempty(nbslice) && Name(i)=='_' |
---|
1287 | Mask.Base=[FileBase Name(i:ind_mask+3)]; |
---|
1288 | Mask.NbSlice=nbslice; |
---|
1289 | num_i1=mod(num_i1-1,nbslice)+1; |
---|
1290 | Mask.NomType=regexprep(Mask_NomType{1},'0','');%remove '0' in nom type for masks |
---|
1291 | [RootPath,RootFile]=fileparts(Mask.Base); |
---|
1292 | maskname=fullfile_uvmat(RootPath,'',RootFile,'.png',Mask.NomType,num_i1,[],num_j1); |
---|
1293 | %maskname=name_generator(Mask.Base,num_i1,num_j1,'.png',Mask.NomType);% |
---|
1294 | mdetect=exist(maskname,'file'); |
---|
1295 | if mdetect |
---|
1296 | set(handles.num_NbSlice,'String',Name(i+1:ind_mask-1)); |
---|
1297 | set(handles.num_NbSlice,'BackgroundColor',[1 1 0]) |
---|
1298 | set(handles.CheckMask,'UserData',Mask); |
---|
1299 | set(handles.CheckMask,'BackgroundColor',[1 1 0]) |
---|
1300 | if nbslice > 1 |
---|
1301 | set(handles.slices,'value',1) |
---|
1302 | slices_Callback(hObject, eventdata, handles) |
---|
1303 | end |
---|
1304 | end |
---|
1305 | end |
---|
1306 | end |
---|
1307 | errormsg=[];%default |
---|
1308 | if mdetect==0 |
---|
1309 | [FileName, PathName, filterindex] = uigetfile( ... |
---|
1310 | {'*.png', ' (*.png)'; |
---|
1311 | '*.png', '.png files '; ... |
---|
1312 | '*.*', 'All Files (*.*)'}, ... |
---|
1313 | 'Pick a mask file *.png',FileBase); |
---|
1314 | maskname=fullfile(PathName,FileName); |
---|
1315 | if ~exist(maskname,'file') |
---|
1316 | errormsg='no file browsed'; |
---|
1317 | end |
---|
1318 | [RootDir,SubDir,RootFile,tild,tild,tild,tild,tild,Mask.NomType]=fileparts_uvmat(maskname); |
---|
1319 | Mask.Base=fullfile(RootDir,SubDir,RootFile); |
---|
1320 | Mask.NbSlice=1; |
---|
1321 | set(handles.CheckMask,'UserData',Mask); |
---|
1322 | set(handles.CheckMask,'BackgroundColor',[1 1 0]) |
---|
1323 | end |
---|
1324 | if isempty(errormsg) |
---|
1325 | errormsg=update_mask(handles,num_i1,num_j1); |
---|
1326 | end |
---|
1327 | if ~isempty(errormsg) |
---|
1328 | set(handles.CheckMask,'Value',0) |
---|
1329 | set(handles.CheckMask,'BackgroundColor',[0.7 0.7 0.7]) |
---|
1330 | end |
---|
1331 | else % desactivate mask display |
---|
1332 | MaskData=get(handles.CheckMask,'UserData'); |
---|
1333 | if isfield(MaskData,'maskhandle') && ishandle(MaskData.maskhandle) |
---|
1334 | delete(MaskData.maskhandle) |
---|
1335 | end |
---|
1336 | set(handles.CheckMask,'UserData',[]) |
---|
1337 | UvData=get(handles.uvmat,'UserData'); |
---|
1338 | if isfield(UvData,'MaskName') |
---|
1339 | UvData=rmfield(UvData,'MaskName'); |
---|
1340 | set(handles.uvmat,'UserData',UvData) |
---|
1341 | end |
---|
1342 | set(handles.CheckMask,'BackgroundColor',[0.7 0.7 0.7]) |
---|
1343 | end |
---|
1344 | |
---|
1345 | %------------------------------------------------------------------------ |
---|
1346 | function errormsg=update_mask(handles,num_i1,num_j1) |
---|
1347 | %------------------------------------------------------------------------ |
---|
1348 | errormsg=[];%default |
---|
1349 | MaskData=get(handles.CheckMask,'UserData'); |
---|
1350 | if isfield(MaskData,'maskhandle')&& ishandle(MaskData.maskhandle) |
---|
1351 | uistack(MaskData.maskhandle,'top'); |
---|
1352 | end |
---|
1353 | num_i1_mask=mod(num_i1-1,MaskData.NbSlice)+1; |
---|
1354 | [RootPath,RootFile]=fileparts(MaskData.Base); |
---|
1355 | MaskName=fullfile_uvmat(RootPath,'',RootFile,'.png',MaskData.NomType,num_i1_mask,[],num_j1); |
---|
1356 | UvData=get(handles.uvmat,'UserData'); |
---|
1357 | %update mask image if the mask is new |
---|
1358 | if ~ (isfield(UvData,'MaskName') && isequal(UvData.MaskName,MaskName)) |
---|
1359 | UvData.MaskName=MaskName; %update the recorded name on UvData |
---|
1360 | set(handles.uvmat,'UserData',UvData); |
---|
1361 | if ~exist(MaskName,'file') |
---|
1362 | if isfield(MaskData,'maskhandle')&& ishandle(MaskData.maskhandle) |
---|
1363 | delete(MaskData.maskhandle) |
---|
1364 | end |
---|
1365 | else |
---|
1366 | %read mask image |
---|
1367 | Mask.AName='image'; |
---|
1368 | Mask.A=imread(MaskName); |
---|
1369 | npxy=size(Mask.A); |
---|
1370 | test_error=0; |
---|
1371 | if length(npxy)>2 |
---|
1372 | errormsg=[MaskName ' is not a grey scale image']; |
---|
1373 | return |
---|
1374 | elseif ~isa(Mask.A,'uint8') |
---|
1375 | errormsg=[MaskName ' is not a 8 bit grey level image']; |
---|
1376 | return |
---|
1377 | end |
---|
1378 | Mask.AX=[0.5 npxy(2)-0.5]; |
---|
1379 | Mask.AY=[npxy(1)-0.5 0.5 ]; |
---|
1380 | Mask.CoordUnit='pixel'; |
---|
1381 | if isequal(get(handles.slices,'Value'),1) |
---|
1382 | NbSlice=str2num(get(handles.num_NbSlice,'String')); |
---|
1383 | num_i1=str2num(get(handles.i1,'String')); |
---|
1384 | Mask.ZIndex=mod(num_i1-1,NbSlice)+1; |
---|
1385 | end |
---|
1386 | %px to phys or other transform on field |
---|
1387 | menu_transform=get(handles.transform_fct,'String'); |
---|
1388 | choice_value=get(handles.transform_fct,'Value'); |
---|
1389 | transform_name=menu_transform{choice_value};%name of the transform fct given by the menu 'transform_fct' |
---|
1390 | transform_list=get(handles.transform_fct,'UserData'); |
---|
1391 | transform=transform_list{choice_value}; |
---|
1392 | if ~isequal(transform_name,'') && ~isequal(transform_name,'px') |
---|
1393 | if isfield(UvData,'XmlData') && isfield(UvData.XmlData{1},'GeometryCalib')%use geometry calib recorded from the ImaDoc xml file as first priority |
---|
1394 | Calib=UvData.XmlData{1}.GeometryCalib; |
---|
1395 | Mask=transform(Mask,UvData.XmlData{1}); |
---|
1396 | end |
---|
1397 | end |
---|
1398 | flagmask=Mask.A < 200; |
---|
1399 | |
---|
1400 | %make brown color image |
---|
1401 | imflag(:,:,1)=0.9*flagmask; |
---|
1402 | imflag(:,:,2)=0.7*flagmask; |
---|
1403 | imflag(:,:,3)=zeros(size(flagmask)); |
---|
1404 | |
---|
1405 | %update mask image |
---|
1406 | hmask=[]; %default |
---|
1407 | if isfield(MaskData,'maskhandle')&& ishandle(MaskData.maskhandle) |
---|
1408 | hmask=MaskData.maskhandle; |
---|
1409 | end |
---|
1410 | if ~isempty(hmask) |
---|
1411 | set(hmask,'CData',imflag) |
---|
1412 | set(hmask,'AlphaData',flagmask*0.6) |
---|
1413 | set(hmask,'XData',Mask.AX); |
---|
1414 | set(hmask,'YData',Mask.AY); |
---|
1415 | % uistack(hmask,'top') |
---|
1416 | else |
---|
1417 | axes(handles.PlotAxes) |
---|
1418 | hold on |
---|
1419 | size(flagmask) |
---|
1420 | % MaskData.maskhandle=image(Mask.AX,Mask.AY,imflag,'Tag','mask','HitTest','off','AlphaData',0.6*flagmask); |
---|
1421 | MaskData.maskhandle=image(Mask.AX,Mask.AY,imflag,'Tag','mask','HitTest','off','AlphaData',0.6*ones(size(flagmask))); |
---|
1422 | % set(MaskData.maskhandle,'AlphaData',0.6*flagmask) |
---|
1423 | set(handles.CheckMask,'UserData',MaskData) |
---|
1424 | end |
---|
1425 | end |
---|
1426 | end |
---|
1427 | |
---|
1428 | %------------------------------------------------------------------------ |
---|
1429 | %------------------------------------------------------------------------ |
---|
1430 | % III - MAIN REFRESH FUNCTIONS : 'FRAME PLOT' |
---|
1431 | %------------------------------------------------------------------------ |
---|
1432 | |
---|
1433 | %------------------------------------------------------------------------ |
---|
1434 | % --- Executes on button press in runplus: make one step forward and call |
---|
1435 | % --- run0. The step forward is along the fields series 1 or 2 depending on |
---|
1436 | % --- the scan_i and scan_j check box (exclusive each other) |
---|
1437 | function runplus_Callback(hObject, eventdata, handles) |
---|
1438 | %------------------------------------------------------------------------ |
---|
1439 | set(handles.runplus,'BackgroundColor',[1 1 0])%paint the command button in yellow |
---|
1440 | drawnow |
---|
1441 | %TODO: introduce the option: increment ='*' to move to the next available view |
---|
1442 | increment=str2num(get(handles.num_IndexIncrement,'String')); %get the field increment d |
---|
1443 | % if isnan(increment) |
---|
1444 | % set(handles.num_IndexIncrement,'String','1')%default value |
---|
1445 | % increment=1; |
---|
1446 | % end |
---|
1447 | errormsg=runpm(hObject,eventdata,handles,increment); |
---|
1448 | if ~isempty(errormsg) |
---|
1449 | msgbox_uvmat('ERROR',errormsg); |
---|
1450 | end |
---|
1451 | set(handles.runplus,'BackgroundColor',[1 0 0])%paint the command button back to red |
---|
1452 | |
---|
1453 | %------------------------------------------------------------------------ |
---|
1454 | % --- Executes on button press in runmin: make one step backward and call |
---|
1455 | % --- run0. The step backward is along the fields series 1 or 2 depending on |
---|
1456 | % --- the scan_i and scan_j check box (exclusive each other) |
---|
1457 | function runmin_Callback(hObject, eventdata, handles) |
---|
1458 | %------------------------------------------------------------------------ |
---|
1459 | set(handles.runmin,'BackgroundColor',[1 1 0])%paint the command button in yellow |
---|
1460 | drawnow |
---|
1461 | increment=-str2num(get(handles.num_IndexIncrement,'String')); %get the field increment d |
---|
1462 | % if isnan(increment) |
---|
1463 | % set(handles.num_IndexIncrement,'String','1')%default value |
---|
1464 | % increment=1; |
---|
1465 | % end |
---|
1466 | errormsg=runpm(hObject,eventdata,handles,increment); |
---|
1467 | if ~isempty(errormsg) |
---|
1468 | msgbox_uvmat('ERROR',errormsg); |
---|
1469 | end |
---|
1470 | set(handles.runmin,'BackgroundColor',[1 0 0])%paint the command button back to red |
---|
1471 | |
---|
1472 | %------------------------------------------------------------------------ |
---|
1473 | % -- Executes on button press in Movie: make a series of +> steps |
---|
1474 | function Movie_Callback(hObject, eventdata, handles) |
---|
1475 | %------------------------------------------------------------------------ |
---|
1476 | set(handles.Movie,'BackgroundColor',[1 1 0])%paint the command button in yellow |
---|
1477 | drawnow |
---|
1478 | increment=str2num(get(handles.num_IndexIncrement,'String')); %get the field increment d |
---|
1479 | % if isnan(increment) |
---|
1480 | % set(handles.num_IndexIncrement,'String','1')%default value |
---|
1481 | % increment=1; |
---|
1482 | % end |
---|
1483 | set(handles.STOP,'Visible','on') |
---|
1484 | set(handles.speed,'Visible','on') |
---|
1485 | set(handles.speed_txt,'Visible','on') |
---|
1486 | set(handles.Movie,'BusyAction','queue') |
---|
1487 | UvData=get(handles.uvmat,'UserData'); |
---|
1488 | |
---|
1489 | while get(handles.Movie,'Value')==1 && get(handles.speed,'Value')~=0 && isequal(get(handles.Movie,'BusyAction'),'queue') % enable STOP command |
---|
1490 | errormsg=runpm(hObject,eventdata,handles,increment); |
---|
1491 | if ~isempty(errormsg) |
---|
1492 | set(handles.Movie,'BackgroundColor',[1 0 0])%paint the command buttonback to red |
---|
1493 | return |
---|
1494 | end |
---|
1495 | pause(1.02-get(handles.speed,'Value'))% wait for next image |
---|
1496 | end |
---|
1497 | if isfield(UvData,'aviobj') && ~isempty( UvData.aviobj), |
---|
1498 | UvData.aviobj=close(UvData.aviobj); |
---|
1499 | set(handles.uvmat,'UserData',UvData); |
---|
1500 | end |
---|
1501 | set(handles.Movie,'BackgroundColor',[1 0 0])%paint the command buttonback to red |
---|
1502 | |
---|
1503 | %------------------------------------------------------------------------ |
---|
1504 | % -- Executes on button press in Movie: make a series of <- steps |
---|
1505 | function MovieBackward_Callback(hObject, eventdata, handles) |
---|
1506 | %------------------------------------------------------------------------ |
---|
1507 | set(handles.MovieBackward,'BackgroundColor',[1 1 0])%paint the command button in yellow |
---|
1508 | drawnow |
---|
1509 | increment=-str2num(get(handles.num_IndexIncrement,'String')); %get the field increment d |
---|
1510 | set(handles.STOP,'Visible','on') |
---|
1511 | set(handles.speed,'Visible','on') |
---|
1512 | set(handles.speed_txt,'Visible','on') |
---|
1513 | set(handles.MovieBackward,'BusyAction','queue') |
---|
1514 | UvData=get(handles.uvmat,'UserData'); |
---|
1515 | |
---|
1516 | while get(handles.MovieBackward,'Value')==1 && get(handles.speed,'Value')~=0 && isequal(get(handles.MovieBackward,'BusyAction'),'queue') % enable STOP command |
---|
1517 | errormsg=runpm(hObject,eventdata,handles,increment); |
---|
1518 | if ~isempty(errormsg) |
---|
1519 | set(handles.MovieBackward,'BackgroundColor',[1 0 0])%paint the command buttonback to red |
---|
1520 | return |
---|
1521 | end |
---|
1522 | pause(1.02-get(handles.speed,'Value'))% wait for next image |
---|
1523 | end |
---|
1524 | if isfield(UvData,'aviobj') && ~isempty( UvData.aviobj), |
---|
1525 | UvData.aviobj=close(UvData.aviobj); |
---|
1526 | set(handles.uvmat,'UserData',UvData); |
---|
1527 | end |
---|
1528 | set(handles.MovieBackward,'BackgroundColor',[1 0 0])%paint the command buttonback to red |
---|
1529 | |
---|
1530 | %------------------------------------------------------------------------ |
---|
1531 | function STOP_Callback(hObject, eventdata, handles) |
---|
1532 | %------------------------------------------------------------------------ |
---|
1533 | set(handles.movie_pair,'BusyAction','Cancel') |
---|
1534 | set(handles.movie_pair,'value',0) |
---|
1535 | set(handles.Movie,'BusyAction','Cancel') |
---|
1536 | set(handles.MovieBackward,'BusyAction','Cancel') |
---|
1537 | set(handles.MenuExportMovie,'BusyAction','Cancel') |
---|
1538 | set(handles.movie_pair,'BackgroundColor',[1 0 0])%paint the command buttonback to red |
---|
1539 | set(handles.Movie,'BackgroundColor',[1 0 0])%paint the command buttonback to red |
---|
1540 | set(handles.MovieBackward,'BackgroundColor',[1 0 0])%paint the command buttonback to red |
---|
1541 | |
---|
1542 | %------------------------------------------------------------------------ |
---|
1543 | % --- function activated by runplus and run minus |
---|
1544 | function errormsg=runpm(hObject,eventdata,handles,increment) |
---|
1545 | %------------------------------------------------------------------------ |
---|
1546 | errormsg='';%default |
---|
1547 | %% check for movie pair status |
---|
1548 | movie_status=get(handles.movie_pair,'Value'); |
---|
1549 | if isequal(movie_status,1) |
---|
1550 | STOP_Callback(hObject, eventdata, handles)%interrupt movie pair if active |
---|
1551 | end |
---|
1552 | |
---|
1553 | %% read the current input file name(s) and field indices |
---|
1554 | InputFile=read_GUI(handles.InputFile); |
---|
1555 | InputFile.RootFile=regexprep(InputFile.RootFile,'^[\\/]|[\\/]$','');%suppress possible / or \ separator at the beginning or the end of the string |
---|
1556 | InputFile.SubDir=regexprep(InputFile.SubDir,'^[\\/]|[\\/]$','');%suppress possible / or \ separator at the beginning or the end of the string |
---|
1557 | FileExt=InputFile.FileExt; |
---|
1558 | NomType=get(handles.NomType,'String'); |
---|
1559 | i1=str2num(get(handles.i1,'String'));%read the field indices (for movie, it is not given by the file name) |
---|
1560 | i2=[];%default |
---|
1561 | if strcmp(get(handles.i2,'Visible'),'on') |
---|
1562 | i2=str2num(get(handles.i2,'String')); |
---|
1563 | end |
---|
1564 | j1=[]; |
---|
1565 | if strcmp(get(handles.j1,'Visible'),'on') |
---|
1566 | j1=stra2num(get(handles.j1,'String')); |
---|
1567 | end |
---|
1568 | j2=j1; |
---|
1569 | if strcmp(get(handles.j2,'Visible'),'on') |
---|
1570 | j2=stra2num(get(handles.j2,'String')); |
---|
1571 | end |
---|
1572 | sub_value= get(handles.SubField,'Value'); |
---|
1573 | if sub_value % a second input file has been entered |
---|
1574 | [InputFile.RootPath_1,InputFile.SubDir_1,InputFile.RootFile_1,InputFile.FileIndex_1,InputFile.FileExt_1,InputFile.NomType_1]=read_file_boxes_1(handles); |
---|
1575 | [tild,tild,tild,i1_1,i2_1,j1_1,j2_1]=fileparts_uvmat(InputFile.FileIndex_1);% the indices for the second series taken from FileIndex_1 |
---|
1576 | else |
---|
1577 | filename_1=[]; |
---|
1578 | end |
---|
1579 | |
---|
1580 | %% increment (or decrement) the field indices and update the input filename(s) |
---|
1581 | if isempty(increment) |
---|
1582 | set(handles.CheckFixPair,'Value',0) |
---|
1583 | end |
---|
1584 | CheckFixPair=get(handles.CheckFixPair,'Value')||(isempty(i2)&&isempty(j2)); |
---|
1585 | |
---|
1586 | % the pair i1-i2 or j1-j2 is imposed (check box CheckFixPair selected) |
---|
1587 | if CheckFixPair |
---|
1588 | if get(handles.scan_i,'Value')==1% case of scanning along index i |
---|
1589 | i1=i1+increment; |
---|
1590 | i2=i2+increment; |
---|
1591 | if sub_value |
---|
1592 | i1_1=i1_1+increment; |
---|
1593 | i2_1=i2_1+increment; |
---|
1594 | end |
---|
1595 | |
---|
1596 | else % case of scanning along index j (burst numbers) |
---|
1597 | j1=j1+increment; |
---|
1598 | j2=j2+increment; |
---|
1599 | if sub_value |
---|
1600 | j1_1=j1_1+increment; |
---|
1601 | j2_1=j2_1+increment; |
---|
1602 | end |
---|
1603 | end |
---|
1604 | |
---|
1605 | % the pair i1-i2 or j1-j2 is free (check box CheckFixPair not selected): the list of existing indices recorded in UvData is used |
---|
1606 | else |
---|
1607 | UvData=get(handles.uvmat,'UserData'); |
---|
1608 | ref_i=i1; |
---|
1609 | if ~isempty(i2) |
---|
1610 | ref_i=floor((i1+i2)/2);% current reference index i |
---|
1611 | end |
---|
1612 | ref_j=1; |
---|
1613 | if ~isempty(j1) |
---|
1614 | ref_j=j1; |
---|
1615 | if ~isempty(j2) |
---|
1616 | ref_j=floor((j1+j2)/2);% current reference index j |
---|
1617 | end |
---|
1618 | end |
---|
1619 | if ~isempty(increment) |
---|
1620 | if get(handles.scan_i,'Value')==1% case of scanning along index i |
---|
1621 | ref_i=ref_i+increment;% increment the current reference index i |
---|
1622 | else % case of scanning along index j (burst numbers) |
---|
1623 | ref_j=ref_j+increment;% increment the current reference index j if scan_j option is used |
---|
1624 | end |
---|
1625 | else % free increment |
---|
1626 | runaction=get(gcbo,'tag'); |
---|
1627 | if strcmp(runaction,'runplus')||strcmp(runaction,'Movie')% if runplus or movie is activated |
---|
1628 | step=1; |
---|
1629 | else |
---|
1630 | step=-1; |
---|
1631 | end |
---|
1632 | if get(handles.scan_i,'Value')==1% case of scanning along index i |
---|
1633 | ref_i=ref_i+step; |
---|
1634 | while ref_i>=0 && size(UvData.i1_series{1},3)>=ref_i+1 && UvData.i1_series{1}(1,ref_j+1,ref_i+1)==0 |
---|
1635 | ref_i=ref_i+step; |
---|
1636 | end |
---|
1637 | else % case of scanning along index j (burst numbers) |
---|
1638 | ref_j=ref_j+step; |
---|
1639 | while ref_j>=0 && size(UvData.i1_series{1},2)>=ref_j+1 && UvData.i1_series{1}(1,ref_j+1,ref_i+1)==0 |
---|
1640 | ref_j=ref_j+step; |
---|
1641 | end |
---|
1642 | end |
---|
1643 | end |
---|
1644 | if ref_i<0 |
---|
1645 | errormsg='minimum i index reached'; |
---|
1646 | elseif ref_j<0 |
---|
1647 | errormsg='minimum j index reached'; |
---|
1648 | elseif ref_i+1>size(UvData.i1_series{1},3) |
---|
1649 | errormsg='maximum i index reached (reload the input file to update the index bound)'; |
---|
1650 | elseif ref_j+1>size(UvData.i1_series{1},2) |
---|
1651 | errormsg='maximum j index reached (reload the input file to update the index bound)'; |
---|
1652 | end |
---|
1653 | if ~isempty(errormsg),return,end |
---|
1654 | siz=size(UvData.i1_series{1}); |
---|
1655 | ref_indices=ref_i*siz(1)*siz(2)+ref_j*siz(1)+1:ref_i*siz(1)*siz(2)+(ref_j+1)*siz(1); |
---|
1656 | i1_subseries=UvData.i1_series{1}(ref_indices); |
---|
1657 | ref_indices=ref_indices(i1_subseries>0); |
---|
1658 | if isempty(ref_indices)% case of pairs (free index i) |
---|
1659 | ref_indices=ref_i*siz(1)*siz(2)+1:(ref_i+1)*siz(1)*siz(2); |
---|
1660 | i1_subseries=UvData.i1_series{1}(ref_indices); |
---|
1661 | ref_indices=ref_indices(i1_subseries>0); |
---|
1662 | end |
---|
1663 | if isempty(ref_indices),errormsg='no next frame: set num_IndexIncrement =''*'' to reach the next existing file';return |
---|
1664 | end |
---|
1665 | i1=UvData.i1_series{1}(ref_indices(end)); |
---|
1666 | if ~isempty(UvData.i2_series{1}) |
---|
1667 | i2=UvData.i2_series{1}(ref_indices(end)); |
---|
1668 | end |
---|
1669 | if ~isempty(UvData.j1_series{1}) |
---|
1670 | j1=UvData.j1_series{1}(ref_indices(end)); |
---|
1671 | end |
---|
1672 | if ~isempty(UvData.j2_series{1}) |
---|
1673 | j2=UvData.j2_series{1}(ref_indices(end)); |
---|
1674 | end |
---|
1675 | |
---|
1676 | % case of a second file series |
---|
1677 | if sub_value |
---|
1678 | ref_i_1=i1_1; |
---|
1679 | if ~isempty(i2_1) |
---|
1680 | ref_i_1=floor((i1_1+i2_1)/2);% current reference index i |
---|
1681 | end |
---|
1682 | ref_j_1=1; |
---|
1683 | if ~isempty(j1_1) |
---|
1684 | ref_j_1=j1_1; |
---|
1685 | if ~isempty(j2_1) |
---|
1686 | ref_j_1=floor((j1_1+j2_1)/2);% current reference index j |
---|
1687 | end |
---|
1688 | end |
---|
1689 | if ~isempty(increment) |
---|
1690 | if get(handles.scan_i,'Value')==1% case of scanning along index i |
---|
1691 | ref_i_1=ref_i_1+increment;% increment the current reference index i |
---|
1692 | else % case of scanning along index j (burst numbers) |
---|
1693 | ref_j_1=ref_j_1+increment;% increment the current reference index j if scan_j option is used |
---|
1694 | end |
---|
1695 | else % free increment, synchronise the ref indices with the first series |
---|
1696 | ref_i_1=ref_i; |
---|
1697 | ref_j_1=ref_j; |
---|
1698 | end |
---|
1699 | if numel(UvData.i1_series)==1 |
---|
1700 | UvData.i1_series{2}=UvData.i1_series{1}; |
---|
1701 | UvData.j1_series{2}=UvData.j1_series{1}; |
---|
1702 | UvData.i2_series{2}=UvData.i2_series{1}; |
---|
1703 | UvData.j2_series{2}=UvData.j2_series{1}; |
---|
1704 | end |
---|
1705 | if ref_i_1<0 |
---|
1706 | errormsg='minimum i index reached'; |
---|
1707 | elseif ref_j_1<0 |
---|
1708 | errormsg='minimum j index reached'; |
---|
1709 | elseif ref_i_1+1>size(UvData.i1_series{2},3) |
---|
1710 | errormsg='maximum i index reached for the second series (reload the input file to update the index bound)'; |
---|
1711 | elseif ref_j_1+1>size(UvData.i1_series{2},2) |
---|
1712 | errormsg='maximum j index reached for the second series(reload the input file to update the index bound)'; |
---|
1713 | end |
---|
1714 | if ~isempty(errormsg),return,end |
---|
1715 | siz=size(UvData.i1_series{2}); |
---|
1716 | ref_indices=ref_i_1*siz(1)*siz(2)+ref_j_1*siz(1)+1:ref_i_1*siz(1)*siz(2)+(ref_j_1+1)*siz(1); |
---|
1717 | i1_subseries=UvData.i1_series{2}(ref_indices); |
---|
1718 | ref_indices=ref_indices(i1_subseries>0); |
---|
1719 | if isempty(ref_indices)% case of pairs (free index i) |
---|
1720 | ref_indices=ref_i_1*siz(1)*siz(2)+1:(ref_i_1+1)*siz(1)*siz(2); |
---|
1721 | i1_subseries=UvData.i1_series{2}(ref_indices); |
---|
1722 | ref_indices=ref_indices(i1_subseries>0); |
---|
1723 | end |
---|
1724 | i1_1=UvData.i1_series{2}(ref_indices(end)); |
---|
1725 | if ~isempty(UvData.i2_series{2}) |
---|
1726 | i2_1=UvData.i2_series{2}(ref_indices(end)); |
---|
1727 | end |
---|
1728 | if ~isempty(UvData.j1_series{2}) |
---|
1729 | j1_1=UvData.j1_series{2}(ref_indices(end)); |
---|
1730 | end |
---|
1731 | if ~isempty(UvData.j2_series{2}) |
---|
1732 | j2_1=UvData.j2_series{1}(ref_indices(end)); |
---|
1733 | end |
---|
1734 | else% the second series (if needed) is the same file as the first |
---|
1735 | i1_1=i1; |
---|
1736 | i2_1=i2; |
---|
1737 | j1_1=j1; |
---|
1738 | j2_1=j2; |
---|
1739 | end |
---|
1740 | end |
---|
1741 | filename=fullfile_uvmat(InputFile.RootPath,InputFile.SubDir,InputFile.RootFile,FileExt,NomType,i1,i2,j1,j2); |
---|
1742 | if sub_value |
---|
1743 | filename_1=fullfile_uvmat(InputFile.RootPath_1,InputFile.SubDir_1,InputFile.RootFile_1,InputFile.FileExt_1,InputFile.NomType_1,i1_1,i2_1,j1_1,j2_1); |
---|
1744 | end |
---|
1745 | |
---|
1746 | %% refresh plots |
---|
1747 | errormsg=refresh_field(handles,filename,filename_1,i1,i2,j1,j2,i1_1,i2_1,j1_1,j2_1); |
---|
1748 | |
---|
1749 | %% update the index counters if the index move is successfull |
---|
1750 | if isempty(errormsg) |
---|
1751 | set(handles.i1,'String',num2stra(i1,NomType,1)); |
---|
1752 | if isequal(i2,i1) |
---|
1753 | set(handles.i2,'String',''); |
---|
1754 | else |
---|
1755 | set(handles.i2,'String',num2stra(i2,NomType,1)); |
---|
1756 | end |
---|
1757 | set(handles.j1,'String',num2stra(j1,NomType,2)); |
---|
1758 | if isequal(j2,j1) |
---|
1759 | set(handles.j2,'String',''); |
---|
1760 | else |
---|
1761 | set(handles.j2,'String',num2stra(j2,NomType,2)); |
---|
1762 | end |
---|
1763 | indices=fullfile_uvmat('','','','',NomType,i1,i2,j1,j2); |
---|
1764 | set(handles.FileIndex,'String',indices); |
---|
1765 | if ~isempty(filename_1) |
---|
1766 | indices_1=fullfile_uvmat('','','','',InputFile.NomType_1,i1_1,i2_1,j1_1,j2_1); |
---|
1767 | set(handles.FileIndex_1,'String',indices_1); |
---|
1768 | end |
---|
1769 | if isequal(movie_status,1) |
---|
1770 | set(handles.movie_pair,'Value',1) |
---|
1771 | movie_pair_Callback(hObject, eventdata, handles); %reactivate moviepair if it was activated |
---|
1772 | end |
---|
1773 | end |
---|
1774 | |
---|
1775 | %------------------------------------------------------------------------ |
---|
1776 | % --- Executes on button press in movie_pair: create an alternating movie with two view |
---|
1777 | function movie_pair_Callback(hObject, eventdata, handles) |
---|
1778 | %------------------------------------------------------------------------ |
---|
1779 | %% stop movie action if the movie_pair button is off |
---|
1780 | if ~get(handles.movie_pair,'value') |
---|
1781 | set(handles.movie_pair,'BusyAction','Cancel')%stop movie pair if button is 'off' |
---|
1782 | set(handles.i2,'String','') |
---|
1783 | set(handles.j2,'String','') |
---|
1784 | return |
---|
1785 | else |
---|
1786 | set(handles.movie_pair,'BusyAction','queue') |
---|
1787 | end |
---|
1788 | |
---|
1789 | %% initialisation |
---|
1790 | set(handles.movie_pair,'BackgroundColor',[1 1 0])%paint the command button in yellow |
---|
1791 | drawnow |
---|
1792 | list_fields=get(handles.Fields,'String');% list menu fields |
---|
1793 | index_fields=get(handles.Fields,'Value');% selected string index |
---|
1794 | FieldName=list_fields{index_fields}; % selected field |
---|
1795 | UvData=get(handles.uvmat,'UserData'); |
---|
1796 | if isequal(FieldName,'image') |
---|
1797 | index=1; |
---|
1798 | [RootPath,SubDir,RootFile,FileIndices,Ext]=read_file_boxes(handles); |
---|
1799 | NomType=get(handles.NomType,'String'); |
---|
1800 | else |
---|
1801 | list_fields=get(handles.Fields_1,'String');% list menu fields |
---|
1802 | index_fields=get(handles.Fields_1,'Value');% selected string index |
---|
1803 | FieldName=list_fields{index_fields}; % selected field |
---|
1804 | if isequal(FieldName,'image') |
---|
1805 | index=2; |
---|
1806 | [RootPath,tild,RootFile,FileIndex_1,Ext,NomType]=read_file_boxes_1(handles); |
---|
1807 | else |
---|
1808 | msgbox_uvmat('ERROR','an image or movie must be first introduced as input') |
---|
1809 | set(handles.movie_pair,'BackgroundColor',[1 0 0])%paint the command button in red |
---|
1810 | set(handles.movie_pair,'Value',0) |
---|
1811 | return |
---|
1812 | end |
---|
1813 | end |
---|
1814 | num_i1=str2num(get(handles.i1,'String')); |
---|
1815 | num_j1=stra2num(get(handles.j1,'String')); |
---|
1816 | num_i2=str2num(get(handles.i2,'String')); |
---|
1817 | num_j2=stra2num(get(handles.j2,'String')); |
---|
1818 | if isempty(num_j2) |
---|
1819 | if isempty(num_i2) |
---|
1820 | msgbox_uvmat('ERROR', 'a second image index i2 or j2 is needed to show the pair as a movie') |
---|
1821 | set(handles.movie_pair,'BackgroundColor',[1 0 0])%paint the command button in red |
---|
1822 | set(handles.movie_pair,'Value',0) |
---|
1823 | return |
---|
1824 | else |
---|
1825 | num_j2=num_j1;%repeat the index i1 by default |
---|
1826 | end |
---|
1827 | end |
---|
1828 | if isempty(num_i2) |
---|
1829 | num_i2=num_i1;%repeat the index i1 by default |
---|
1830 | end |
---|
1831 | imaname_1=fullfile_uvmat(RootPath,SubDir,RootFile,Ext,NomType,num_i2,[],num_j2); |
---|
1832 | if strcmp(NomType,'*') |
---|
1833 | num_frame=num_i2; |
---|
1834 | else |
---|
1835 | num_frame=num_j2; |
---|
1836 | end |
---|
1837 | if ~exist(imaname_1,'file') |
---|
1838 | msgbox_uvmat('ERROR',['second input open (-) ' imaname_1 ' not found']); |
---|
1839 | set(handles.movie_pair,'BackgroundColor',[1 0 0])%paint the command button in red |
---|
1840 | set(handles.movie_pair,'Value',0) |
---|
1841 | return |
---|
1842 | end |
---|
1843 | |
---|
1844 | %% get the first image |
---|
1845 | %Field.AName='image'; |
---|
1846 | if index==1 |
---|
1847 | Field_a=UvData.Field;% movie on the second field |
---|
1848 | else |
---|
1849 | Field_a=UvData.Field_1;% movie on the first field |
---|
1850 | end |
---|
1851 | |
---|
1852 | %% read the second image |
---|
1853 | MovieObject=[]; |
---|
1854 | if numel(UvData.MovieObject)>=index |
---|
1855 | MovieObject=UvData.MovieObject{index}; |
---|
1856 | end |
---|
1857 | [Field_b,ParamOut,errormsg] = read_field(imaname_1,UvData.FileType{index},MovieObject,num_frame) |
---|
1858 | % Field_b.AX=Field_a.AX; |
---|
1859 | % Field_b.AY=Field_a.AY; |
---|
1860 | % % z index |
---|
1861 | % nbslice=str2double(get(handles.num_NbSlice,'String')); |
---|
1862 | % if ~isempty(nbslice) |
---|
1863 | % Field_b.ZIndex=mod(num_i2-1,nbslice)+1; |
---|
1864 | % end |
---|
1865 | % Field_b.CoordUnit='pixel'; |
---|
1866 | % |
---|
1867 | % %% determine the input file type |
---|
1868 | % if (test_1 && isfield(UvData,'MovieObject')&& numel(UvData.MovieObject>=2))||(~test_1 && ~isempty(UvData.MovieObject{1})) |
---|
1869 | % FileType='movie'; |
---|
1870 | % elseif isequal(lower(Ext),'.avi') |
---|
1871 | % FileType='avi'; |
---|
1872 | % elseif isequal(lower(Ext),'.vol') |
---|
1873 | % FileType='vol'; |
---|
1874 | % else |
---|
1875 | % form=imformats(Ext(2:end)); |
---|
1876 | % if ~isempty(form)% if the extension corresponds to an image format recognized by Matlab |
---|
1877 | % if isequal(NomType,'*'); |
---|
1878 | % FileType='multimage'; |
---|
1879 | % else |
---|
1880 | % FileType='image'; |
---|
1881 | % end |
---|
1882 | % end |
---|
1883 | % end |
---|
1884 | % switch FileType |
---|
1885 | % case 'movie' |
---|
1886 | % if test_1 |
---|
1887 | % Field_b.A=read(UvData.MovieObject{2},num_i2); |
---|
1888 | % else |
---|
1889 | % Field_b.A=read(UvData.MovieObject{1},num_i2); |
---|
1890 | % end |
---|
1891 | % case 'avi' |
---|
1892 | % mov=aviread(imaname_1,num_i2); |
---|
1893 | % Field_b.A=frame2im(mov(1)); |
---|
1894 | % case 'vol' |
---|
1895 | % Field_b.A=imread(imaname_1); |
---|
1896 | % case 'multimage' |
---|
1897 | % Field_b.A=imread(imaname_1,num_i2); |
---|
1898 | % case 'image' |
---|
1899 | % Field_b.A=imread(imaname_1); |
---|
1900 | % end |
---|
1901 | % if get(handles.slices,'Value') |
---|
1902 | % Field.ZIndex=str2double(get(handles.z_index,'String')); |
---|
1903 | % end |
---|
1904 | |
---|
1905 | %px to phys or other transform on field |
---|
1906 | % menu_transform=get(handles.transform_fct,'String'); |
---|
1907 | % choice_value=get(handles.transform_fct,'Value'); |
---|
1908 | % transform_name=menu_transform{choice_value};%name of the transform fct given by the menu 'transform_fct' |
---|
1909 | % transform_list=get(handles.transform_fct,'UserData'); |
---|
1910 | transform=get(handles.path_transform,'UserData'); |
---|
1911 | if ~isempty(transform) |
---|
1912 | if isfield(UvData,'XmlData') && numel(UvData.XmlData)>=index %use geometry calib recorded from the ImaDoc xml file as first priority |
---|
1913 | if index==2 |
---|
1914 | Field_a=transform(Field_a,UvData.XmlData{index});%the first field has been stored without transform |
---|
1915 | end |
---|
1916 | Field_b=transform(Field_b,UvData.XmlData{index}); |
---|
1917 | end |
---|
1918 | end |
---|
1919 | |
---|
1920 | % make movie until movie speed is set to 0 or STOP is activated |
---|
1921 | hima=findobj(handles.PlotAxes,'Tag','ima');% %handles.PlotAxes =main plotting window (A GENERALISER) |
---|
1922 | set(handles.STOP,'Visible','on') |
---|
1923 | set(handles.speed,'Visible','on') |
---|
1924 | set(handles.speed_txt,'Visible','on') |
---|
1925 | while get(handles.speed,'Value')~=0 && isequal(get(handles.movie_pair,'BusyAction'),'queue')%isequal(get(handles.run0,'BusyAction'),'queue'); % enable STOP command |
---|
1926 | % read and plot the series of images in non erase mode |
---|
1927 | set(hima,'CData',Field_b.A); |
---|
1928 | pause(1.02-get(handles.speed,'Value'));% wait for next image |
---|
1929 | set(hima,'CData',Field_a.A); |
---|
1930 | pause(1.02-get(handles.speed,'Value'));% wait for next image |
---|
1931 | end |
---|
1932 | set(handles.movie_pair,'BackgroundColor',[1 0 0])%paint the command button in red |
---|
1933 | set(handles.movie_pair,'Value',0) |
---|
1934 | |
---|
1935 | %------------------------------------------------------------------------ |
---|
1936 | % --- Executes on button press in run0. |
---|
1937 | function run0_Callback(hObject, eventdata, handles) |
---|
1938 | %------------------------------------------------------------------------ |
---|
1939 | set(handles.run0,'BackgroundColor',[1 1 0])%paint the command button in yellow |
---|
1940 | drawnow |
---|
1941 | [RootPath,SubDir,RootFile,FileIndex,FileExt]=read_file_boxes(handles); |
---|
1942 | filename=[fullfile(RootPath,SubDir,RootFile) FileIndex FileExt]; |
---|
1943 | filename_1='';%default |
---|
1944 | FileIndex_1=''; |
---|
1945 | if get(handles.SubField,'Value') |
---|
1946 | [RootPath_1,SubDir_1,RootFile_1,FileIndex_1,FileExt_1]=read_file_boxes_1(handles); |
---|
1947 | filename_1=[fullfile(RootPath_1,SubDir_1,RootFile_1) FileIndex_1 FileExt_1]; |
---|
1948 | end |
---|
1949 | num_i1=stra2num(get(handles.i1,'String')); |
---|
1950 | num_i2=stra2num(get(handles.i2,'String')); |
---|
1951 | num_j1=stra2num(get(handles.j1,'String')); |
---|
1952 | num_j2=stra2num(get(handles.j2,'String')); |
---|
1953 | [tild,tild,tild,i1_1,i2_1,j1_1,j2_1]=fileparts_uvmat(FileIndex_1); |
---|
1954 | |
---|
1955 | errormsg=refresh_field(handles,filename,filename_1,num_i1,num_i2,num_j1,num_j2,i1_1,i2_1,j1_1,j2_1); |
---|
1956 | |
---|
1957 | if ~isempty(errormsg) |
---|
1958 | msgbox_uvmat('ERROR',errormsg); |
---|
1959 | else |
---|
1960 | set(handles.i1,'BackgroundColor',[1 1 1]) |
---|
1961 | set(handles.i2,'BackgroundColor',[1 1 1]) |
---|
1962 | set(handles.j1,'BackgroundColor',[1 1 1]) |
---|
1963 | set(handles.j2,'BackgroundColor',[1 1 1]) |
---|
1964 | set(handles.FileIndex,'BackgroundColor',[1 1 1]) |
---|
1965 | set(handles.FileIndex_1,'BackgroundColor',[1 1 1]) |
---|
1966 | end |
---|
1967 | set(handles.run0,'BackgroundColor',[1 0 0]) |
---|
1968 | |
---|
1969 | |
---|
1970 | %------------------------------------------------------------------------ |
---|
1971 | % --- read the input files and refresh all the plots, including projection. |
---|
1972 | % OUTPUT: |
---|
1973 | % errormsg: error message char string =[] by default |
---|
1974 | % INPUT: |
---|
1975 | % filename: first input file (=[] in the absence of input file) |
---|
1976 | % filename_1: second input file (=[] in the asbsenc of secodn input file) |
---|
1977 | % num_i1,num_i2,num_j1,num_j2; frame indices |
---|
1978 | % Field: structure describing an optional input field (then replace the input file) |
---|
1979 | |
---|
1980 | function errormsg=refresh_field(handles,FileName,FileName_1,num_i1,num_i2,num_j1,num_j2,i1_1,i2_1,j1_1,j2_1) |
---|
1981 | %------------------------------------------------------------------------ |
---|
1982 | |
---|
1983 | %% initialisation |
---|
1984 | abstime=[]; |
---|
1985 | abstime_1=[]; |
---|
1986 | dt=[]; |
---|
1987 | if ~exist('Field','var') |
---|
1988 | Field={}; |
---|
1989 | end |
---|
1990 | UvData=get(handles.uvmat,'UserData'); |
---|
1991 | if ishandle(handles.UVMAT_title) %remove title panel on uvmat |
---|
1992 | delete(handles.UVMAT_title) |
---|
1993 | end |
---|
1994 | |
---|
1995 | %% determine the main input file information for action |
---|
1996 | if ~exist(FileName,'file') |
---|
1997 | errormsg=['input file ' FileName ' does not exist']; |
---|
1998 | return |
---|
1999 | end |
---|
2000 | NomType=get(handles.NomType,'String'); |
---|
2001 | NomType_1=''; |
---|
2002 | if strcmp(get(handles.NomType_1,'Visible'),'on') |
---|
2003 | NomType_1=get(handles.NomType_1,'String'); |
---|
2004 | end |
---|
2005 | %update the z position index |
---|
2006 | nbslice_str=get(handles.num_NbSlice,'String'); |
---|
2007 | if isequal(nbslice_str,'volume')%NOT USED |
---|
2008 | z_index=num_j1; |
---|
2009 | set(handles.z_index,'String',num2str(z_index)) |
---|
2010 | else |
---|
2011 | nbslice=str2num(nbslice_str); |
---|
2012 | z_index=mod(num_i1-1,nbslice)+1; |
---|
2013 | set(handles.z_index,'String',num2str(z_index)) |
---|
2014 | end |
---|
2015 | % refresh menu for save_mask if relevant |
---|
2016 | masknumber=get(handles.masklevel,'String'); |
---|
2017 | if length(masknumber)>=z_index |
---|
2018 | set(handles.masklevel,'Value',z_index) |
---|
2019 | end |
---|
2020 | |
---|
2021 | %% test for need of tps |
---|
2022 | check_proj_tps=0; |
---|
2023 | if (strcmp(UvData.FileType{1},'civdata')||strcmp(UvData.FileType{1},'civx')) |
---|
2024 | for iobj=1:numel(UvData.Object) |
---|
2025 | if isfield(UvData.Object{iobj},'ProjMode')&& strcmp(UvData.Object{iobj}.ProjMode,'filter') |
---|
2026 | check_proj_tps=1; |
---|
2027 | break |
---|
2028 | end |
---|
2029 | end |
---|
2030 | end |
---|
2031 | |
---|
2032 | %% read the first input field |
---|
2033 | ParamIn.ColorVar='';%default variable name for vector color |
---|
2034 | frame_index=1;%default |
---|
2035 | % if ~isempty(FileName) |
---|
2036 | FieldName='';%default |
---|
2037 | VelType='';%default |
---|
2038 | % FileType=UvData.FileType{1}; |
---|
2039 | switch UvData.FileType{1} |
---|
2040 | case {'civx','civdata','netcdf'}; |
---|
2041 | list_fields=get(handles.Fields,'String');% list menu fields |
---|
2042 | FieldName= list_fields{get(handles.Fields,'Value')}; % selected field |
---|
2043 | if ~strcmp(FieldName,'get_field...') |
---|
2044 | if get(handles.FixVelType,'Value') |
---|
2045 | VelTypeList=get(handles.VelType,'String'); |
---|
2046 | VelType=VelTypeList{get(handles.VelType,'Value')}; |
---|
2047 | end |
---|
2048 | end |
---|
2049 | if ~isempty(regexp(FieldName,'^vec(')) |
---|
2050 | list_code=get(handles.ColorCode,'String');% list menu fields |
---|
2051 | index_code=get(handles.ColorCode,'Value');% selected string index |
---|
2052 | if ~strcmp(list_code{index_code},'black') && ~strcmp(list_code{index_code},'white') |
---|
2053 | list_code=get(handles.ColorScalar,'String');% list menu fields |
---|
2054 | index_code=get(handles.ColorScalar,'Value');% selected string index |
---|
2055 | ParamIn.ColorVar= list_code{index_code}; % selected field |
---|
2056 | end |
---|
2057 | end |
---|
2058 | case {'video','mmreader'} |
---|
2059 | ParamIn=UvData.MovieObject{1}; |
---|
2060 | if ~strcmp(NomType,'*') |
---|
2061 | frame_index=num_j1;%frame index for movies or multimage |
---|
2062 | else |
---|
2063 | frame_index=num_i1; |
---|
2064 | end |
---|
2065 | case 'multimage' |
---|
2066 | if ~strcmp(NomType,'*') |
---|
2067 | frame_index=num_j1;%frame index for movies or multimage |
---|
2068 | else |
---|
2069 | frame_index=num_i1; |
---|
2070 | end |
---|
2071 | case 'vol' %TODO: update |
---|
2072 | if isfield(UvData.XmlData,'Npy') && isfield(UvData.XmlData,'Npx') |
---|
2073 | ParamIn.Npy=UvData.XmlData.Npy; |
---|
2074 | ParamIn.Npx=UvData.XmlData.Npx; |
---|
2075 | else |
---|
2076 | errormsg='Npx and Npy need to be defined in the xml file for volume images .vol'; |
---|
2077 | return |
---|
2078 | end |
---|
2079 | end |
---|
2080 | if isstruct (ParamIn) |
---|
2081 | ParamIn.FieldName=FieldName; |
---|
2082 | ParamIn.VelType=VelType; |
---|
2083 | XNameMenu=get(handles.Coord_x,'String'); |
---|
2084 | ParamIn.CoordName=XNameMenu{get(handles.Coord_x,'Value')}; |
---|
2085 | YNameMenu=get(handles.Coord_y,'String'); |
---|
2086 | ParamIn.CoordName={ParamIn.CoordName, YNameMenu{get(handles.Coord_y,'Value')}}; |
---|
2087 | end |
---|
2088 | check_tps = 0; |
---|
2089 | if strcmp(UvData.FileType{1},'civdata')&&~strcmp(ParamIn.FieldName,'velocity')&&~strcmp(ParamIn.FieldName,'get_field...') |
---|
2090 | check_tps=1;%tps needed to get the requested field |
---|
2091 | end |
---|
2092 | [Field{1},ParamOut,errormsg] = read_field(FileName,UvData.FileType{1},ParamIn,frame_index); |
---|
2093 | if ~isempty(errormsg) |
---|
2094 | errormsg=['uvmat/refresh_field/read_field: ' FileName ': ' errormsg]; |
---|
2095 | return |
---|
2096 | end |
---|
2097 | if isfield(ParamOut,'Npx')&& isfield(ParamOut,'Npy') |
---|
2098 | set(handles.num_Npx,'String',num2str(ParamOut.Npx));% display image size on the interface |
---|
2099 | set(handles.num_Npy,'String',num2str(ParamOut.Npy)); |
---|
2100 | end |
---|
2101 | if isfield(ParamOut,'TimeIndex')% case of time obtained from get_field |
---|
2102 | set(handles.i1,'String',num2str(ParamOut.TimeIndex)) |
---|
2103 | end |
---|
2104 | if isfield(ParamOut,'TimeValue') |
---|
2105 | Field{1}.Time=ParamOut.TimeValue;% case of time obtained from get_field |
---|
2106 | end |
---|
2107 | Field{1}.ZIndex=z_index; %used for multiplane 3D calibration |
---|
2108 | % end |
---|
2109 | |
---|
2110 | %% choose and read a second field FileName_1 if defined |
---|
2111 | VelType_1=[];%default |
---|
2112 | FieldName_1=[]; |
---|
2113 | ParamIn_1=[]; |
---|
2114 | ParamOut_1=[]; |
---|
2115 | frame_index_1=1; |
---|
2116 | if ~isempty(FileName_1) |
---|
2117 | if ~exist(FileName_1,'file') |
---|
2118 | errormsg=['second file ' FileName_1 ' does not exist']; |
---|
2119 | return |
---|
2120 | end |
---|
2121 | Name=FileName_1; |
---|
2122 | switch UvData.FileType{2} |
---|
2123 | case {'civx','civdata','netcdf'}; |
---|
2124 | list_fields=get(handles.Fields_1,'String');% list menu fields |
---|
2125 | if ischar(list_fields),list_fields={list_fields};end |
---|
2126 | FieldName_1= list_fields{get(handles.Fields_1,'Value')}; % selected field |
---|
2127 | if ~strcmp(FieldName,'get_field...') |
---|
2128 | if get(handles.FixVelType,'Value') |
---|
2129 | VelTypeList=get(handles.VelType_1,'String'); |
---|
2130 | VelType_1=VelTypeList{get(handles.VelType_1,'Value')};% read the velocity type. |
---|
2131 | end |
---|
2132 | end |
---|
2133 | if strcmp(FieldName_1,'velocity')&& strcmp(get(handles.ColorCode,'Visible'),'on') |
---|
2134 | list_code=get(handles.ColorCode,'String');% list menu fields |
---|
2135 | index_code=get(handles.ColorCode,'Value');% selected string index |
---|
2136 | if ~strcmp(list_code{index_code},'black') && ~strcmp(list_code{index_code},'white') |
---|
2137 | list_code=get(handles.ColorScalar,'String');% list menu fields |
---|
2138 | index_code=get(handles.ColorScalar,'Value');% selected string index |
---|
2139 | ParamIn_1.ColorVar= list_code{index_code}; % selected field for vector color display |
---|
2140 | end |
---|
2141 | end |
---|
2142 | case {'video','mmreader'} |
---|
2143 | ParamIn_1=UvData.MovieObject{2}; |
---|
2144 | if ~strcmp(NomType_1,'*') |
---|
2145 | frame_index_1=j1_1;%frame index for movies or multimage |
---|
2146 | else |
---|
2147 | frame_index_1=i1_1; |
---|
2148 | end |
---|
2149 | case 'multimage' |
---|
2150 | if ~strcmp(NomType_1,'*') |
---|
2151 | frame_index_1=j1_1;%frame index for movies or multimage |
---|
2152 | else |
---|
2153 | frame_index_1=i1_1; |
---|
2154 | end |
---|
2155 | case 'vol' %TODO: update |
---|
2156 | if isfield(UvData.XmlData,'Npy') && isfield(UvData.XmlData,'Npx') |
---|
2157 | ParamIn_1.Npy=UvData.XmlData.Npy; |
---|
2158 | ParamIn_1.Npx=UvData.XmlData.Npx; |
---|
2159 | else |
---|
2160 | errormsg='Npx and Npy need to be defined in the xml file for volume images .vol'; |
---|
2161 | return |
---|
2162 | end |
---|
2163 | end |
---|
2164 | if isequal(get(handles.NomType_1,'Visible'),'on') |
---|
2165 | NomType_1=get(handles.NomType_1,'String'); |
---|
2166 | else |
---|
2167 | NomType_1=get(handles.NomType,'String'); |
---|
2168 | end |
---|
2169 | test_keepdata_1=0;% test for keeping the previous stored data if the input files are unchanged |
---|
2170 | if ~isequal(NomType_1,'*')&& isfield(UvData,'FileName_1') |
---|
2171 | test_keepdata_1= strcmp(FileName_1,UvData.FileName_1) ;%&& strcmp(FieldName_1,UvData.FieldName_1); |
---|
2172 | end |
---|
2173 | if test_keepdata_1 |
---|
2174 | Field{2}=UvData.Field_1;% keep the stored field |
---|
2175 | ParamOut_1=UvData.ParamOut_1; |
---|
2176 | else |
---|
2177 | if isempty(ParamIn_1) || isstruct(ParamIn_1) |
---|
2178 | ParamIn_1.FieldName=FieldName_1; |
---|
2179 | ParamIn_1.VelType=VelType_1; |
---|
2180 | ParamIn_1.GUIName='get_field_1'; |
---|
2181 | end |
---|
2182 | [Field{2},ParamOut_1,errormsg] = read_field(Name,UvData.FileType{2},ParamIn_1,frame_index_1); |
---|
2183 | if ~isempty(errormsg) |
---|
2184 | errormsg=['error in reading ' FieldName_1 ' in ' FileName_1 ': ' errormsg]; |
---|
2185 | return |
---|
2186 | end |
---|
2187 | if isstruct(ParamOut_1)&&~strcmp(ParamOut_1.FieldName,'get_field...')&& (strcmp(UvData.FileType{2},'civdata')||strcmp(UvData.FileType{2},'civx'))... |
---|
2188 | &&~strcmp(ParamOut_1.FieldName,'velocity') && ~strcmp(ParamOut_1.FieldName,'get_field...') |
---|
2189 | if ~check_proj_tps |
---|
2190 | % Field{2}=calc_field([{ParamOut_1.FieldName} {ParamOut_1.ColorVar}],Field{2}); |
---|
2191 | end |
---|
2192 | end |
---|
2193 | end |
---|
2194 | Field{2}.ZIndex=z_index;%used for multi-plane 3D calibration |
---|
2195 | end |
---|
2196 | |
---|
2197 | %% update uvmat interface |
---|
2198 | if isfield(ParamOut,'Npx') |
---|
2199 | set(handles.num_Npx,'String',num2str(ParamOut.Npx));% display image size on the interface |
---|
2200 | set(handles.num_Npy,'String',num2str(ParamOut.Npy)); |
---|
2201 | elseif isfield(ParamOut_1,'Npx') |
---|
2202 | set(handles.num_Npx,'String',num2str(ParamOut_1.Npx));% display image size on the interface |
---|
2203 | set(handles.num_Npy,'String',num2str(ParamOut_1.Npy)); |
---|
2204 | end |
---|
2205 | |
---|
2206 | %% update the display menu for the first velocity type (first menuline) |
---|
2207 | test_veltype=0; |
---|
2208 | % if ~isequal(FileType,'netcdf')|| isequal(FieldName,'get_field...') |
---|
2209 | if (strcmp(UvData.FileType{1},'civx')||strcmp(UvData.FileType{1},'civdata'))&& ~strcmp(FieldName,'get_field...') |
---|
2210 | test_veltype=1; |
---|
2211 | set(handles.VelType,'Visible','on') |
---|
2212 | set(handles.VelType_1,'Visible','on') |
---|
2213 | set(handles.FixVelType,'Visible','on') |
---|
2214 | menu=set_veltype_display(ParamOut.CivStage,UvData.FileType{1}); |
---|
2215 | index_menu=strcmp(ParamOut.VelType,menu);%look for VelType in the menu |
---|
2216 | index_val=find(index_menu,1); |
---|
2217 | if isempty(index_val) |
---|
2218 | index_val=1; |
---|
2219 | end |
---|
2220 | set(handles.VelType,'Value',index_val) |
---|
2221 | if ~get(handles.SubField,'value') |
---|
2222 | set(handles.VelType,'String',menu) |
---|
2223 | set(handles.VelType_1,'Value',1) |
---|
2224 | set(handles.VelType_1,'String',[{''};menu]) |
---|
2225 | end |
---|
2226 | else |
---|
2227 | set(handles.VelType,'Visible','off') |
---|
2228 | end |
---|
2229 | % display the Fields menu from the input file and pick the selected one: |
---|
2230 | % if isstruct(ParamOut) |
---|
2231 | % field_index=strcmp(ParamOut.FieldName,ParamOut.FieldList); |
---|
2232 | % set(handles.Fields,'String',ParamOut.FieldList); %update the field menu |
---|
2233 | % set(handles.Fields,'Value',find(field_index,1)) |
---|
2234 | % end |
---|
2235 | |
---|
2236 | %% update the display menu for the second velocity type (second menuline) |
---|
2237 | test_veltype_1=0; |
---|
2238 | if isempty(FileName_1) |
---|
2239 | % set(handles.Fields_1,'Value',1); %update the field menu |
---|
2240 | % if isstruct(ParamOut) |
---|
2241 | % set(handles.Fields_1,'String',[{''};ParamOut.FieldList]); %update the field menu |
---|
2242 | % end |
---|
2243 | elseif ~test_keepdata_1 |
---|
2244 | if (~strcmp(UvData.FileType{2},'netcdf')&&~strcmp(UvData.FileType{2},'civdata')&&~strcmp(UvData.FileType{2},'civx'))|| isequal(FieldName_1,'get_field...') |
---|
2245 | set(handles.VelType_1,'Visible','off') |
---|
2246 | else |
---|
2247 | test_veltype_1=1; |
---|
2248 | set(handles.VelType_1,'Visible','on') |
---|
2249 | menu=set_veltype_display(ParamOut_1.CivStage,UvData.FileType{2}); |
---|
2250 | index_menu=strcmp(ParamOut_1.VelType,menu); |
---|
2251 | set(handles.VelType_1,'Value',1+find(index_menu,1)) |
---|
2252 | set(handles.VelType_1,'String',[{''};menu]) |
---|
2253 | end |
---|
2254 | % update the second field menu: the same quantity |
---|
2255 | if isstruct(ParamOut_1) |
---|
2256 | set(handles.Fields_1,'String',[{''};ParamOut_1.FieldList]); %update the field menu |
---|
2257 | % display the Fields menu from the input file and pick the selected one: |
---|
2258 | field_index=strcmp(ParamOut_1.FieldName,ParamOut_1.FieldList); |
---|
2259 | set(handles.Fields_1,'Value',find(field_index,1)+1) |
---|
2260 | end |
---|
2261 | |
---|
2262 | end |
---|
2263 | if test_veltype||test_veltype_1 |
---|
2264 | set(handles.FixVelType,'Visible','on') |
---|
2265 | else |
---|
2266 | set(handles.FixVelType,'Visible','off') |
---|
2267 | end |
---|
2268 | |
---|
2269 | % field_index=strcmp(ParamOut_1.FieldName,ParamOut_1.FieldList); |
---|
2270 | % set(handles.Fields,'String',ParamOut.FieldList); %update the field menu |
---|
2271 | % set(handles.Fields,'Value',find(field_index,1)) |
---|
2272 | |
---|
2273 | %% introduce w as background image by default for a new series (only for nbdim=2) |
---|
2274 | if ~isfield(UvData,'NewSeries') |
---|
2275 | UvData.NewSeries=1; |
---|
2276 | end |
---|
2277 | %put W as background image by default if NbDim=2: |
---|
2278 | if UvData.NewSeries && isequal(get(handles.SubField,'Value'),0) && isfield(Field{1},'W') && ~isempty(Field{1}.W) && ~isequal(Field{1}.NbDim,3); |
---|
2279 | set(handles.SubField,'Value',1); |
---|
2280 | set(handles.RootPath_1,'String','"') |
---|
2281 | set(handles.RootFile_1,'String','"') |
---|
2282 | set(handles.SubDir_1,'String','"'); |
---|
2283 | indices=fullfile_uvmat('','','','',NomType,num_i1,num_i2,num_j1,num_j2); |
---|
2284 | set(handles.FileIndex_1,'String',indices) |
---|
2285 | set(handles.FileExt_1,'String','"'); |
---|
2286 | set(handles.Fields_1,'Visible','on'); |
---|
2287 | set(handles.Fields_1,'Visible','on'); |
---|
2288 | set(handles.RootPath_1,'Visible','on') |
---|
2289 | set(handles.RootFile_1,'Visible','on') |
---|
2290 | set(handles.SubDir_1,'Visible','on'); |
---|
2291 | set(handles.FileIndex_1,'Visible','on'); |
---|
2292 | set(handles.FileExt_1,'Visible','on'); |
---|
2293 | set(handles.Fields_1,'Visible','on'); |
---|
2294 | Field{1}.AName='w'; |
---|
2295 | end |
---|
2296 | |
---|
2297 | %% display time |
---|
2298 | testimedoc=0; |
---|
2299 | TimeUnit=''; |
---|
2300 | if isfield(Field{1},'Time') |
---|
2301 | abstime=Field{1}.Time;%time read from the netcdf input file |
---|
2302 | end |
---|
2303 | if numel(Field)==2 && isfield(Field{2},'Time') |
---|
2304 | abstime_1=Field{2}.Time;%time read from the netcdf input file |
---|
2305 | end |
---|
2306 | if isfield(Field{1},'Dt') |
---|
2307 | dt=Field{1}.Dt;%dt read from the netcdf input file |
---|
2308 | if isfield(Field{1},'TimeUnit') |
---|
2309 | TimeUnit=Field{1}.TimeUnit; |
---|
2310 | end |
---|
2311 | elseif numel(Field)==2 && isfield(Field{2},'Dt')%dt obtained from the second field if not defined in the first |
---|
2312 | dt=Field{2}.Dt;%dt read from the netcdf input file |
---|
2313 | if isfield(Field{2},'TimeUnit') |
---|
2314 | TimeUnit=Field{2}.TimeUnit; |
---|
2315 | end |
---|
2316 | end |
---|
2317 | % time from xml file overset previous result |
---|
2318 | if isfield(UvData,'XmlData') && isfield(UvData.XmlData{1},'Time') |
---|
2319 | if isempty(num_i2)||isnan(num_i2) |
---|
2320 | num_i2=num_i1; |
---|
2321 | end |
---|
2322 | if isempty(num_j1)||isnan(num_j1) |
---|
2323 | num_j1=1; |
---|
2324 | end |
---|
2325 | if isempty(num_j2)||isnan(num_j2) |
---|
2326 | num_j2=num_j1; |
---|
2327 | end |
---|
2328 | siz=size(UvData.XmlData{1}.Time); |
---|
2329 | if ~isempty(num_i1)&& ~isempty(num_i2)&&siz(1)>=max(num_i1,num_i2) && siz(2)>=max(num_j1,num_j2) |
---|
2330 | abstime=(UvData.XmlData{1}.Time(num_i1,num_j1)+UvData.XmlData{1}.Time(num_i2,num_j2))/2;%overset the time read from files |
---|
2331 | dt=(UvData.XmlData{1}.Time(num_i2,num_j2)-UvData.XmlData{1}.Time(num_i1,num_j1)); |
---|
2332 | Field{1}.Dt=dt; |
---|
2333 | if isfield(UvData.XmlData{1},'TimeUnit') |
---|
2334 | TimeUnit=UvData.XmlData{1}.TimeUnit; |
---|
2335 | end |
---|
2336 | end |
---|
2337 | if numel(UvData.XmlData)==2 |
---|
2338 | if isempty(i2_1) |
---|
2339 | i2_1=num_i1; |
---|
2340 | end |
---|
2341 | if isempty(j1_1) |
---|
2342 | j1_1=1; |
---|
2343 | end |
---|
2344 | if isempty(j2_1) |
---|
2345 | j2_1=j1_1; |
---|
2346 | end |
---|
2347 | siz=size(UvData.XmlData{2}.Time); |
---|
2348 | if ~isempty(i1_1) && siz(1)>=max(i1_1,i2_1) && siz(2)>=max(j1_1,j2_1) |
---|
2349 | abstime_1=(UvData.XmlData{2}.Time(i1_1,j1_1)+UvData.XmlData{2}.Time(i2_1,j2_1))/2;%overset the time read from files |
---|
2350 | Field{2}.Dt=(UvData.XmlData{2}.Time(i2_1,j2_1)-UvData.XmlData{2}.Time(i1_1,j1_1)); |
---|
2351 | end |
---|
2352 | end |
---|
2353 | end |
---|
2354 | if ~isequal(numel(abstime),1) |
---|
2355 | abstime=[]; |
---|
2356 | end |
---|
2357 | if ~isequal(numel(abstime_1),1) |
---|
2358 | abstime_1=[]; |
---|
2359 | end |
---|
2360 | set(handles.abs_time,'String',num2str(abstime,5)) |
---|
2361 | set(handles.abs_time_1,'String',num2str(abstime_1,5)) |
---|
2362 | if isempty(dt)||isequal(dt,0) |
---|
2363 | set(handles.Dt_txt,'String','') |
---|
2364 | else |
---|
2365 | if isempty(TimeUnit) |
---|
2366 | set(handles.Dt_txt,'String',['Dt=' num2str(1000*dt,3) ' 10^(-3)'] ) |
---|
2367 | else |
---|
2368 | set(handles.Dt_txt,'String',['Dt=' num2str(1000*dt,3) ' m' TimeUnit] ) |
---|
2369 | end |
---|
2370 | end |
---|
2371 | |
---|
2372 | |
---|
2373 | %% store the current open names, fields and vel types in uvmat interface |
---|
2374 | UvData.FileName_1=FileName_1; |
---|
2375 | UvData.ParamOut_1=ParamOut_1; |
---|
2376 | if numel(Field)==2 |
---|
2377 | UvData.Field_1=Field{2}; %store the second field for possible use at next RUN |
---|
2378 | end |
---|
2379 | |
---|
2380 | %% apply coordinate transform or other user fct |
---|
2381 | transform=get(handles.path_transform,'UserData'); |
---|
2382 | if isempty(transform) |
---|
2383 | UvData.Field=Field{1}; |
---|
2384 | else |
---|
2385 | XmlData=[];%default |
---|
2386 | XmlData_1=[];%default |
---|
2387 | if isfield(UvData,'XmlData')%use geometry calib recorded from the ImaDoc xml file as first priority |
---|
2388 | XmlData=UvData.XmlData{1}; |
---|
2389 | if numel(UvData.XmlData)==2 |
---|
2390 | XmlData_1=UvData.XmlData{2}; |
---|
2391 | end |
---|
2392 | end |
---|
2393 | transform=get(handles.path_transform,'UserData'); |
---|
2394 | switch nargin(transform) |
---|
2395 | case 4 |
---|
2396 | if length(Field)==2 |
---|
2397 | UvData.Field=transform(Field{1},XmlData,Field{2},XmlData_1); |
---|
2398 | else |
---|
2399 | UvData.Field=transform(Field{1},XmlData); |
---|
2400 | end |
---|
2401 | case 3 |
---|
2402 | if length(Field)==2 |
---|
2403 | UvData.Field=transform(Field{1},XmlData,Field{2}); |
---|
2404 | else |
---|
2405 | UvData.Field=transform(Field{1},XmlData); |
---|
2406 | end |
---|
2407 | case 2 |
---|
2408 | UvData.Field=transform(Field{1},XmlData); |
---|
2409 | case 1 |
---|
2410 | UvData.Field=transform(Field{1}); |
---|
2411 | end |
---|
2412 | end |
---|
2413 | |
---|
2414 | %% calculate tps coefficients if needed |
---|
2415 | UvData.Field=calc_tps(UvData.Field,check_proj_tps); |
---|
2416 | |
---|
2417 | %% analyse input field |
---|
2418 | test_x=0; |
---|
2419 | test_z=0;% test for unstructured z coordinate |
---|
2420 | [errormsg,ListDimName,DimValue,VarDimIndex]=check_field_structure(UvData.Field);% check the input field structure |
---|
2421 | if ~isempty(errormsg) |
---|
2422 | errormsg=['error in uvmat/refresh_field/check_field_structure: ' errormsg];% display error |
---|
2423 | return |
---|
2424 | end |
---|
2425 | [CellVarIndex,NbDim,VarType,errormsg]=find_field_cells(UvData.Field);% analyse the input field structure |
---|
2426 | if ~isempty(errormsg) |
---|
2427 | errormsg=['error in uvmat/refresh_field/find_field_cells: ' errormsg];% display error |
---|
2428 | return |
---|
2429 | end |
---|
2430 | [NbDim,imax]=max(NbDim);% spatial dimension of the input field |
---|
2431 | if isfield(UvData.Field,'NbDim') |
---|
2432 | NbDim=UvData.Field.NbDim;% deal with plane fields containing z coordinates |
---|
2433 | end |
---|
2434 | |
---|
2435 | %% get bounds and mesh (needed for mouse action and to open set_object) |
---|
2436 | if NbDim>1 |
---|
2437 | XName=''; %default |
---|
2438 | YName=''; |
---|
2439 | %unstructured coordinates |
---|
2440 | if ~isempty(VarType{imax}.coord_x)&&~isempty(VarType{imax}.coord_y) |
---|
2441 | XName=UvData.Field.ListVarName{VarType{imax}.coord_x}; |
---|
2442 | YName=UvData.Field.ListVarName{VarType{imax}.coord_y}; |
---|
2443 | %nbvec=length(UvData.Field.(XName));%nbre of measurement points (e.g. vectors) |
---|
2444 | test_x=1;%test for unstructured coordinates |
---|
2445 | if ~isempty(VarType{imax}.coord_z) |
---|
2446 | ZName=UvData.Field.ListVarName{VarType{imax}.coord_z}; |
---|
2447 | else |
---|
2448 | NbDim=2; |
---|
2449 | end |
---|
2450 | %structured coordinate |
---|
2451 | elseif numel(VarType)>=imax && numel(VarType{imax}.coord)>=NbDim && VarType{imax}.coord(NbDim)>0 |
---|
2452 | XName=UvData.Field.ListVarName{VarType{imax}.coord(NbDim)}; |
---|
2453 | if NbDim> 1 && VarType{imax}.coord(NbDim-1)>0 |
---|
2454 | YName=UvData.Field.ListVarName{VarType{imax}.coord(NbDim-1)}; %structured coordinates |
---|
2455 | end |
---|
2456 | % VarIndex=CellVarIndex{imax}; % list of variable indices |
---|
2457 | DimIndex=VarDimIndex{CellVarIndex{imax}(1)}; %list of dim indices for the variable |
---|
2458 | nbpoints_x=DimValue(DimIndex(NbDim)); |
---|
2459 | XMax=nbpoints_x;%default |
---|
2460 | XMin=1;%default |
---|
2461 | end |
---|
2462 | |
---|
2463 | if NbDim==3 |
---|
2464 | if ~test_x |
---|
2465 | ZName=UvData.Field.ListVarName{VarType{imax}.coord(1)};%structured coordinates in 3D |
---|
2466 | end |
---|
2467 | ZMax=max(UvData.Field.(ZName)); |
---|
2468 | ZMin=min(UvData.Field.(ZName)); |
---|
2469 | UvData.Field.ZMax=ZMax; |
---|
2470 | UvData.Field.ZMin=ZMin; |
---|
2471 | test_z=1; |
---|
2472 | if isequal(ZMin,ZMax)%no z dependency |
---|
2473 | NbDim=2; |
---|
2474 | test_z=0; |
---|
2475 | end |
---|
2476 | end |
---|
2477 | if ~isempty (XName) |
---|
2478 | XMax=max(max(UvData.Field.(XName))); |
---|
2479 | XMin=min(min(UvData.Field.(XName))); |
---|
2480 | UvData.Field.NbDim=NbDim; |
---|
2481 | UvData.Field.XMax=XMax; |
---|
2482 | UvData.Field.XMin=XMin; |
---|
2483 | if NbDim >1&& ~isempty(YName) |
---|
2484 | YMax=max(max(UvData.Field.(YName))); |
---|
2485 | YMin=min(min(UvData.Field.(YName))); |
---|
2486 | UvData.Field.YMax=YMax; |
---|
2487 | UvData.Field.YMin=YMin; |
---|
2488 | end |
---|
2489 | nbvec=length(UvData.Field.(XName)); |
---|
2490 | if test_x %unstructured coordinates |
---|
2491 | if test_z |
---|
2492 | UvData.Field.Mesh=((XMax-XMin)*(YMax-YMin)*(ZMax-ZMin))/nbvec;% volume per vector |
---|
2493 | UvData.Field.Mesh=(UvData.Field.Mesh)^(1/3); |
---|
2494 | else |
---|
2495 | UvData.Field.Mesh=sqrt((XMax-XMin)*(YMax-YMin)/nbvec);%2D |
---|
2496 | end |
---|
2497 | end |
---|
2498 | end |
---|
2499 | % case of structured coordinates |
---|
2500 | if ~test_x |
---|
2501 | DX=(XMax-XMin)/(nbpoints_x-1); |
---|
2502 | if NbDim >1 |
---|
2503 | nbpoints_y=DimValue(DimIndex(NbDim-1)); |
---|
2504 | if isempty(YName)% if the y coordinate is not expressed, it is taken as the matrix index |
---|
2505 | DY=1; |
---|
2506 | UvData.Field.YMax=nbpoints_y; |
---|
2507 | UvData.Field.YMin=1; |
---|
2508 | else |
---|
2509 | DY=(YMax-YMin)/(nbpoints_y-1); |
---|
2510 | end |
---|
2511 | end |
---|
2512 | if NbDim==3 |
---|
2513 | nbpoints_z=DimValue(DimIndex(1)); |
---|
2514 | DZ=(ZMax-ZMin)/(nbpoints_z-1); |
---|
2515 | UvData.Field.Mesh=(DX*DY*DZ)^(1/3); |
---|
2516 | UvData.Field.ZMax=ZMax; |
---|
2517 | UvData.Field.ZMin=ZMin; |
---|
2518 | else |
---|
2519 | UvData.Field.Mesh=DX;%sqrt(DX*DY); |
---|
2520 | end |
---|
2521 | end |
---|
2522 | % adjust the mesh to a value 1, 2 , 5 *10^n |
---|
2523 | ord=10^(floor(log10(UvData.Field.Mesh)));%order of magnitude |
---|
2524 | if UvData.Field.Mesh/ord>=5 |
---|
2525 | UvData.Field.Mesh=5*ord; |
---|
2526 | elseif UvData.Field.Mesh/ord>=2 |
---|
2527 | UvData.Field.Mesh=2*ord; |
---|
2528 | else |
---|
2529 | UvData.Field.Mesh=ord; |
---|
2530 | end |
---|
2531 | % default projection plane |
---|
2532 | if isempty(UvData.Object{1}) |
---|
2533 | UvData.Object{1}.Type='plane';%main plotting plane |
---|
2534 | UvData.Object{1}.ProjMode='projection';%main plotting plane |
---|
2535 | UvData.Object{1}.DisplayHandle.uvmat=[]; %plane not visible in uvmat |
---|
2536 | UvData.Object{1}.DisplayHandle.view_field=[]; %plane not visible in uvmat |
---|
2537 | end |
---|
2538 | %% 3D case (menuvolume) |
---|
2539 | if NbDim==3% && UvData.NewSeries |
---|
2540 | test_set_object=1; |
---|
2541 | hset_object=findobj(allchild(0),'tag','set_object');% look for the set_object GUI |
---|
2542 | ZBounds(1)=UvData.Field.ZMin; %minimum for the Z slider |
---|
2543 | ZBounds(2)=UvData.Field.ZMax;%maximum for the Z slider |
---|
2544 | if ~isempty(hset_object) %if set_object is detected |
---|
2545 | delete(hset_object);% delete the GUI set_object if it does not fit |
---|
2546 | end |
---|
2547 | if test_set_object% reinitiate the GUI set_object |
---|
2548 | delete_object(1);% delete the current projection object in the list UvData.Object, delete its graphic representations and update the list displayed in handles.ListObject and 2 |
---|
2549 | UvData.Object{1}.NbDim=NbDim;%test for 3D objects |
---|
2550 | UvData.Object{1}.RangeZ=UvData.Field.Mesh;%main plotting plane |
---|
2551 | UvData.Object{1}.Coord(1,3)=(UvData.Field.ZMin+UvData.Field.ZMax)/2;%section at a middle plane chosen |
---|
2552 | UvData.Object{1}.Angle=[0 0 0]; |
---|
2553 | UvData.Object{1}.HandlesDisplay=plot(0,0,'Tag','proj_object');% A REVOIR |
---|
2554 | UvData.Object{1}.Name='1-PLANE'; |
---|
2555 | UvData.Object{1}.enable_plot=1; |
---|
2556 | set_object(UvData.Object{1},handles,ZBounds); |
---|
2557 | set(handles.ListObject,'Value',1); |
---|
2558 | set(handles.ListObject,'String',{'1-PLANE'}); |
---|
2559 | set(handles.edit_object,'Value',1)% put the plane in edit mode to enable the z cursor |
---|
2560 | edit_object_Callback([],[], handles) |
---|
2561 | end |
---|
2562 | %multilevel case (single menuplane in a 3D space) |
---|
2563 | elseif isfield(UvData,'Z') |
---|
2564 | if isfield(UvData,'CoordType')&& isequal(UvData.CoordType,'phys') && isfield(UvData,'XmlData') |
---|
2565 | XmlData=UvData.XmlData{1}; |
---|
2566 | if isfield(XmlData,'PlanePos') |
---|
2567 | UvData.Object{1}.Coord=XmlData.PlanePos(UvData.ZIndex,:); |
---|
2568 | end |
---|
2569 | if isfield(XmlData,'PlaneAngle') |
---|
2570 | siz=size(XmlData.PlaneAngle); |
---|
2571 | indangle=min(siz(1),UvData.ZIndex);%take first angle if a single angle is defined (translating scanning) |
---|
2572 | UvData.Object{1}.PlaneAngle=XmlData.PlaneAngle(indangle,:); |
---|
2573 | end |
---|
2574 | elseif isfield(UvData,'ZIndex') |
---|
2575 | UvData.Object{1}.ZObject=UvData.ZIndex; |
---|
2576 | end |
---|
2577 | end |
---|
2578 | end |
---|
2579 | |
---|
2580 | testnewseries=UvData.NewSeries; |
---|
2581 | UvData.NewSeries=0;% put to 0 the test for a new field series (set by RootPath_callback) |
---|
2582 | set(handles.uvmat,'UserData',UvData) |
---|
2583 | |
---|
2584 | %% reset the min and max of scalar if only the mask is displayed(TODO: check the need) |
---|
2585 | % if isfield(UvData,'Mask')&& ~isfield(UvData,'A') |
---|
2586 | % set(handles.num_MinA,'String','0') |
---|
2587 | % set(handles.num_MaxA,'String','255') |
---|
2588 | % end |
---|
2589 | |
---|
2590 | %% usual 1D (x,y) plots |
---|
2591 | if NbDim<=1 |
---|
2592 | set(handles.Objects,'Visible','off') |
---|
2593 | set(handles.ListObject_1_title,'Visible','off') |
---|
2594 | set(handles.ListObject_1,'Visible','off') |
---|
2595 | [PlotType,PlotParamOut]=plot_field(UvData.Field,handles.PlotAxes,read_GUI(handles.uvmat)); |
---|
2596 | write_plot_param(handles,PlotParamOut) %update the auto plot parameters |
---|
2597 | |
---|
2598 | %% 2D or 3D fields are generally projected |
---|
2599 | else |
---|
2600 | set(handles.Objects,'Visible','on') |
---|
2601 | set(handles.ListObject_1_title,'Visible','on') |
---|
2602 | set(handles.ListObject_1,'Visible','on') |
---|
2603 | |
---|
2604 | %% Plot the projections on the selected projection objects |
---|
2605 | % main projection object (uvmat display) |
---|
2606 | list_object=get(handles.ListObject_1,'String'); |
---|
2607 | if isequal(list_object,{''})%refresh list of objects if the menu is empty |
---|
2608 | set(handles.ListObject,'Value',1) |
---|
2609 | set(handles.ListObject,'String',{'plane'}) |
---|
2610 | UvData.Object{1}.Type='plane';%main plotting plane |
---|
2611 | UvData.Object{1}.ProjMode='projection';%main plotting plane |
---|
2612 | UvData.Object{1}.DisplayHandle.uvmat=[]; %plane not visible in uvmat |
---|
2613 | UvData.Object{1}.DisplayHandle.view_field=[]; %plane not visible in uvmat |
---|
2614 | set(handles.ListObject_1,'Value',1) |
---|
2615 | set(handles.ListObject_1,'String',{'plane'}) |
---|
2616 | end |
---|
2617 | IndexObj(1)=get(handles.ListObject_1,'Value');%selected projection object for main view |
---|
2618 | if IndexObj(1)> numel(UvData.Object) |
---|
2619 | IndexObj(1)=1;%select the first object if the selected one does not exist |
---|
2620 | set(handles.ListObject_1,'Value',1) |
---|
2621 | end |
---|
2622 | IndexObj(2)=get(handles.ListObject,'Value');%selected projection object for main view |
---|
2623 | if isequal(IndexObj(2),IndexObj(1)) |
---|
2624 | IndexObj(2)=[]; |
---|
2625 | end |
---|
2626 | plot_handles{1}=handles; |
---|
2627 | if isfield(UvData,'plotaxes')%case of movies |
---|
2628 | haxes(1)=UvData.plotaxes; |
---|
2629 | else |
---|
2630 | haxes(1)=handles.PlotAxes; |
---|
2631 | end |
---|
2632 | PlotParam{1}=read_GUI(handles.uvmat); |
---|
2633 | %default settings if vectors not visible |
---|
2634 | if ~isfield(PlotParam{1},'Vectors') |
---|
2635 | PlotParam{1}.Vectors.MaxVec=1; |
---|
2636 | PlotParam{1}.Vectors.MinVec=0; |
---|
2637 | PlotParam{1}.Vectors.CheckFixVecColor=1; |
---|
2638 | PlotParam{1}.Vectors.ColCode1=0.33; |
---|
2639 | PlotParam{1}.Vectors.ColCode2=0.66; |
---|
2640 | PlotParam{1}.Vectors.ColorScalar={''}; |
---|
2641 | PlotParam{1}.Vectors.ColorCode= {'rgb'}; |
---|
2642 | end |
---|
2643 | PosColorbar{1}=UvData.OpenParam.PosColorbar;%prescribe the colorbar position on the uvmat interface |
---|
2644 | |
---|
2645 | %% second projection object (view_field display) |
---|
2646 | if length( IndexObj)>=2 |
---|
2647 | view_field_handle=findobj(allchild(0),'tag','view_field');%handles of the view_field GUI |
---|
2648 | if ~isempty(view_field_handle) |
---|
2649 | plot_handles{2}=guidata(view_field_handle); |
---|
2650 | haxes(2)=plot_handles{2}.PlotAxes; |
---|
2651 | PlotParam{2}=read_GUI(handles.uvmat);%read plotting parameters on the uvmat interface |
---|
2652 | PosColorbar{2}='*'; %TODO: deal with colorbar position on view_field |
---|
2653 | end |
---|
2654 | end |
---|
2655 | |
---|
2656 | %% loop on the projection objects: one or two |
---|
2657 | |
---|
2658 | for imap=1:numel(IndexObj) |
---|
2659 | iobj=IndexObj(imap); |
---|
2660 | [ObjectData,errormsg]=proj_field(UvData.Field,UvData.Object{iobj});% project field on the object |
---|
2661 | if ~isempty(errormsg) |
---|
2662 | return |
---|
2663 | end |
---|
2664 | if testnewseries |
---|
2665 | PlotParam{imap}.Scalar.CheckBW=[]; %B/W option depends on the input field (image or scalar) |
---|
2666 | if isfield(ObjectData,'CoordUnit') |
---|
2667 | PlotParam{imap}.Coordinates.CheckFixAspectRatio=1;% set x and y scaling equal if CoordUnit is defined (common unit for x and y) |
---|
2668 | PlotParam{imap}.Coordinates.AspectRatio=1; %set aspect ratio to 1 |
---|
2669 | end |
---|
2670 | end |
---|
2671 | %use of mask (TODO: check) |
---|
2672 | if isfield(ObjectData,'NbDim') && isequal(ObjectData.NbDim,2) && isfield(ObjectData,'Mask') && isfield(ObjectData,'A') |
---|
2673 | flag_mask=double(ObjectData.Mask>200);%=0 for masked regions |
---|
2674 | AX=ObjectData.AX;%x coordiantes for the scalar field |
---|
2675 | AY=ObjectData.AY;%y coordinates for the scalar field |
---|
2676 | MaskX=ObjectData.MaskX;%x coordiantes for the mask |
---|
2677 | MaskY=ObjectData.MaskY;%y coordiantes for the mask |
---|
2678 | if ~isequal(MaskX,AX)||~isequal(MaskY,AY) |
---|
2679 | nxy=size(flag_mask); |
---|
2680 | sizpx=(ObjectData.MaskX(end)-ObjectData.MaskX(1))/(nxy(2)-1);%size of a mask pixel |
---|
2681 | sizpy=(ObjectData.MaskY(1)-ObjectData.MaskY(end))/(nxy(1)-1); |
---|
2682 | x_mask=ObjectData.MaskX(1):sizpx:ObjectData.MaskX(end); % pixel x coordinates for image display |
---|
2683 | y_mask=ObjectData.MaskY(1):-sizpy:ObjectData.MaskY(end);% pixel x coordinates for image display |
---|
2684 | %project on the positions of the scalar |
---|
2685 | npxy=size(ObjectData.A); |
---|
2686 | dxy(1)=(ObjectData.AY(end)-ObjectData.AY(1))/(npxy(1)-1);%grid mesh in y |
---|
2687 | dxy(2)=(ObjectData.AX(end)-ObjectData.AX(1))/(npxy(2)-1);%grid mesh in x |
---|
2688 | xi=ObjectData.AX(1):dxy(2):ObjectData.AX(end); |
---|
2689 | yi=ObjectData.AY(1):dxy(1):ObjectData.AY(end); |
---|
2690 | [XI,YI]=meshgrid(xi,yi);% creates the matrix of regular coordinates |
---|
2691 | flag_mask = interp2(x_mask,y_mask,flag_mask,XI,YI); |
---|
2692 | end |
---|
2693 | AClass=class(ObjectData.A); |
---|
2694 | ObjectData.A=flag_mask.*double(ObjectData.A); |
---|
2695 | ObjectData.A=feval(AClass,ObjectData.A); |
---|
2696 | ind_off=[]; |
---|
2697 | if isfield(ObjectData,'ListVarName') |
---|
2698 | for ilist=1:length(ObjectData.ListVarName) |
---|
2699 | if isequal(ObjectData.ListVarName{ilist},'Mask')||isequal(ObjectData.ListVarName{ilist},'MaskX')||isequal(ObjectData.ListVarName{ilist},'MaskY') |
---|
2700 | ind_off=[ind_off ilist]; |
---|
2701 | end |
---|
2702 | end |
---|
2703 | ObjectData.ListVarName(ind_off)=[]; |
---|
2704 | VarDimIndex(ind_off)=[]; |
---|
2705 | ind_off=[]; |
---|
2706 | for ilist=1:length(ListDimName) |
---|
2707 | if isequal(ListDimName{ilist},'MaskX') || isequal(ListDimName{ilist},'MaskY') |
---|
2708 | ind_off=[ind_off ilist]; |
---|
2709 | end |
---|
2710 | end |
---|
2711 | ListDimName(ind_off)=[]; |
---|
2712 | DimValue(ind_off)=[]; |
---|
2713 | end |
---|
2714 | end |
---|
2715 | if ~isempty(ObjectData) |
---|
2716 | PlotType='none'; %default |
---|
2717 | if imap==2 && isempty(view_field_handle) |
---|
2718 | view_field(ObjectData) |
---|
2719 | else |
---|
2720 | [PlotType,PlotParamOut]=plot_field(ObjectData,haxes(imap),PlotParam{imap},PosColorbar{imap}); |
---|
2721 | write_plot_param(plot_handles{imap},PlotParamOut) %update the auto plot parameters |
---|
2722 | if isfield(Field,'Mesh')&&~isempty(Field.Mesh) |
---|
2723 | ObjectData.Mesh=Field.Mesh; % gives an estimated mesh size (useful for mouse action on the plot) |
---|
2724 | end |
---|
2725 | end |
---|
2726 | end |
---|
2727 | end |
---|
2728 | |
---|
2729 | %% update the mask |
---|
2730 | if isequal(get(handles.CheckMask,'Value'),1)%if the mask option is on |
---|
2731 | update_mask(handles,num_i1,num_i2); |
---|
2732 | end |
---|
2733 | |
---|
2734 | %% prepare the menus of histograms and plot them (histogram of the whole volume in 3D case) |
---|
2735 | menu_histo=(UvData.Field.ListVarName)';%list of field variables to be displayed for the menu of histogram display |
---|
2736 | ind_skip=[]; |
---|
2737 | % nb_histo=1; |
---|
2738 | Ustring=''; |
---|
2739 | Vstring=''; |
---|
2740 | % suppress coordinates from the histogram menu |
---|
2741 | for ivar=1:numel(menu_histo)%l loop on field variables: |
---|
2742 | if isfield(UvData.Field,'VarAttribute') && numel(UvData.Field.VarAttribute)>=ivar && isfield(UvData.Field.VarAttribute{ivar},'Role') |
---|
2743 | Role=UvData.Field.VarAttribute{ivar}.Role; |
---|
2744 | switch Role |
---|
2745 | case {'coord_x','coord_y','coord_z','dimvar'} |
---|
2746 | ind_skip=[ind_skip ivar]; |
---|
2747 | case {'vector_x'} |
---|
2748 | Ustring=UvData.Field.ListVarName{ivar}; |
---|
2749 | ind_skip=[ind_skip ivar]; |
---|
2750 | case {'vector_y'} |
---|
2751 | Vstring=UvData.Field.ListVarName{ivar}; |
---|
2752 | ind_skip=[ind_skip ivar]; |
---|
2753 | end |
---|
2754 | end |
---|
2755 | DimCell=UvData.Field.VarDimName{ivar}; |
---|
2756 | DimName=''; |
---|
2757 | if ischar(DimCell) |
---|
2758 | DimName=DimCell; |
---|
2759 | elseif iscell(DimCell)&& numel(DimCell)==1 |
---|
2760 | DimName=DimCell{1}; |
---|
2761 | end |
---|
2762 | if strcmp(DimName,menu_histo{ivar}) |
---|
2763 | ind_skip=[ind_skip ivar]; |
---|
2764 | end |
---|
2765 | end |
---|
2766 | menu_histo(ind_skip)=[];% remove skipped items |
---|
2767 | if ~isempty(Ustring) |
---|
2768 | menu_histo=[{[Ustring ',' Vstring]};menu_histo];% add U, V at the beginning if they exist |
---|
2769 | end |
---|
2770 | |
---|
2771 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
---|
2772 | % display menus and plot histograms |
---|
2773 | test_v=0; |
---|
2774 | if ~isempty(menu_histo) |
---|
2775 | set(handles.histo1_menu,'Value',1) |
---|
2776 | set(handles.histo1_menu,'String',menu_histo) |
---|
2777 | histo1_menu_Callback(handles.histo1_menu, [], handles)% plot first histogram |
---|
2778 | end |
---|
2779 | end |
---|
2780 | |
---|
2781 | %------------------------------------------------------------------------ |
---|
2782 | function histo1_menu_Callback(hObject, eventdata, handles) |
---|
2783 | %-------------------------------------------- |
---|
2784 | %plot first histo |
---|
2785 | %huvmat=get(handles.histo1_menu,'parent'); |
---|
2786 | histo_menu=get(handles.histo1_menu,'String'); |
---|
2787 | histo_value=get(handles.histo1_menu,'Value'); |
---|
2788 | FieldName=histo_menu{histo_value}; |
---|
2789 | % update_histo(handles.HistoAxes,handles.uvmat,FieldName) |
---|
2790 | % |
---|
2791 | % %------------------------------------------------------------------------ |
---|
2792 | % function histo2_menu_Callback(hObject, eventdata, handles) |
---|
2793 | % %------------------------------------------------------------------------ |
---|
2794 | % %plot second histo |
---|
2795 | % %huvmat=get(handles.histo2_menu,'parent'); |
---|
2796 | % histo_menu=get(handles.histo2_menu,'String'); |
---|
2797 | % histo_value=get(handles.histo2_menu,'Value'); |
---|
2798 | % FieldName=histo_menu{histo_value}; |
---|
2799 | % update_histo(handles.histo_v,handles.uvmat,FieldName) |
---|
2800 | % |
---|
2801 | % %------------------------------------------------------------------------ |
---|
2802 | % %read the field .Fieldname stored in UvData and plot its histogram |
---|
2803 | % function update_histo(haxes,huvmat,FieldName) |
---|
2804 | %------------------------------------------------------------------------ |
---|
2805 | UvData=get(handles.uvmat,'UserData'); |
---|
2806 | Field=UvData.Field; |
---|
2807 | r=regexp(FieldName,'(?<var1>.*)(?<sep>,)(?<var2>.*)','names'); |
---|
2808 | FieldName_2=''; |
---|
2809 | if ~isempty(r) |
---|
2810 | FieldName=r.var1; |
---|
2811 | FieldName_2=r.var2; |
---|
2812 | end |
---|
2813 | if ~isfield(UvData.Field,FieldName) |
---|
2814 | msgbox_uvmat('ERROR',['no field ' FieldName ' for histogram']) |
---|
2815 | return |
---|
2816 | end |
---|
2817 | FieldHisto=Field.(FieldName); |
---|
2818 | if isfield(Field,'FF') && ~isempty(Field.FF) && isequal(size(Field.FF),size(FieldHisto)) |
---|
2819 | indsel=find(Field.FF==0);%find values marked as false |
---|
2820 | if ~isempty(indsel) |
---|
2821 | FieldHisto=FieldHisto(indsel); |
---|
2822 | if ~isempty(FieldName_2) |
---|
2823 | FieldHisto(:,:,2)=Field.(FieldName_2)(indsel); |
---|
2824 | end |
---|
2825 | end |
---|
2826 | end |
---|
2827 | if isempty(Field) |
---|
2828 | msgbox_uvmat('ERROR',['empty field ' FieldName]) |
---|
2829 | else |
---|
2830 | nxy=size(FieldHisto); |
---|
2831 | Amin=double(min(min(min(FieldHisto))));%min of field value |
---|
2832 | Amax=double(max(max(max(FieldHisto))));%max of field value |
---|
2833 | if isequal(Amin,Amax) |
---|
2834 | cla(handles.HistoAxes) |
---|
2835 | else |
---|
2836 | Histo.ListVarName={FieldName,'histo'}; |
---|
2837 | if isfield(Field,'NbDim') && isequal(Field.NbDim,3) |
---|
2838 | Histo.VarDimName={FieldName,FieldName}; %dimensions for the histogram |
---|
2839 | else |
---|
2840 | if numel(nxy)==2 |
---|
2841 | Histo.VarDimName={FieldName,FieldName}; %dimensions for the histogram |
---|
2842 | else |
---|
2843 | Histo.VarDimName={FieldName,{FieldName,'component'}}; %dimensions for the histogram |
---|
2844 | end |
---|
2845 | end |
---|
2846 | %unit |
---|
2847 | units=[]; %default |
---|
2848 | for ivar=1:numel(Field.ListVarName) |
---|
2849 | if strcmp(Field.ListVarName{ivar},FieldName) |
---|
2850 | if isfield(Field,'VarAttribute') && numel(Field.VarAttribute)>=ivar && isfield(Field.VarAttribute{ivar},'units') |
---|
2851 | units=Field.VarAttribute{ivar}.units; |
---|
2852 | break |
---|
2853 | end |
---|
2854 | end |
---|
2855 | end |
---|
2856 | if ~isempty(units) |
---|
2857 | Histo.VarAttribute{1}.units=units; |
---|
2858 | end |
---|
2859 | eval(['Histo.' FieldName '=linspace(Amin,Amax,50);'])%absissa values for histo |
---|
2860 | if isfield(Field,'NbDim') && isequal(Field.NbDim,3) |
---|
2861 | C=reshape(double(FieldHisto),1,[]);% reshape in a vector |
---|
2862 | Histo.histo(:,1)=hist(C, Histo.(FieldName)); %calculate histogram |
---|
2863 | else |
---|
2864 | for col=1:size(FieldHisto,3) |
---|
2865 | B=FieldHisto(:,:,col); |
---|
2866 | C=reshape(double(B),1,nxy(1)*nxy(2));% reshape in a vector |
---|
2867 | Histo.histo(:,col)=hist(C, Histo.(FieldName)); %calculate histogram |
---|
2868 | end |
---|
2869 | end |
---|
2870 | plot_field(Histo,handles.HistoAxes); |
---|
2871 | hlegend=legend; |
---|
2872 | if isempty(FieldName_2) |
---|
2873 | set(hlegend,'String',FieldName) |
---|
2874 | else |
---|
2875 | set(hlegend,'String',{FieldName;FieldName_2}) |
---|
2876 | end |
---|
2877 | % hh=get(handles.HistoAxes,'children'); |
---|
2878 | % get(hh(1)) |
---|
2879 | % get(hh(2)) |
---|
2880 | end |
---|
2881 | end |
---|
2882 | |
---|
2883 | %------------------------------------------------------------------- |
---|
2884 | % --- translate coordinate to matrix index |
---|
2885 | %------------------------------------------------------------------- |
---|
2886 | function [indx,indy]=pos2ind(x0,rangx0,nxy) |
---|
2887 | indx=1+round((nxy(2)-1)*(x0-rangx0(1))/(rangx0(2)-rangx0(1)));% index x of pixel |
---|
2888 | indy=1+round((nxy(1)-1)*(y12-rangy0(1))/(rangy0(2)-rangy0(1)));% index y of pixel |
---|
2889 | |
---|
2890 | |
---|
2891 | %------------------------------------------------------------------- |
---|
2892 | % --- Executes on button press in 'CheckZoom'. |
---|
2893 | %------------------------------------------------------------------- |
---|
2894 | function CheckZoom_Callback(hObject, eventdata, handles) |
---|
2895 | |
---|
2896 | if (get(handles.CheckZoom,'Value') == 1); |
---|
2897 | set(handles.CheckZoom,'BackgroundColor',[1 1 0]) |
---|
2898 | set(handles.CheckFixLimits,'Value',1)% propose by default fixed limits for the plotting axes |
---|
2899 | set(handles.CheckFixLimits,'BackgroundColor',[1 1 0]) |
---|
2900 | else |
---|
2901 | set(handles.CheckZoom,'BackgroundColor',[0.7 0.7 0.7]) |
---|
2902 | end |
---|
2903 | |
---|
2904 | %------------------------------------------------------------------- |
---|
2905 | % --- Executes on button press in 'CheckFixLimits'. |
---|
2906 | %------------------------------------------------------------------- |
---|
2907 | function CheckFixLimits_Callback(hObject, eventdata, handles) |
---|
2908 | test=get(handles.CheckFixLimits,'Value'); |
---|
2909 | if test |
---|
2910 | set(handles.CheckFixLimits,'BackgroundColor',[1 1 0]) |
---|
2911 | else |
---|
2912 | set(handles.CheckFixLimits,'BackgroundColor',[0.7 0.7 0.7]) |
---|
2913 | update_plot(handles); |
---|
2914 | end |
---|
2915 | |
---|
2916 | %------------------------------------------------------------------- |
---|
2917 | % --- Executes on button press in CheckFixAspectRatio. |
---|
2918 | function CheckFixAspectRatio_Callback(hObject, eventdata, handles) |
---|
2919 | %------------------------------------------------------------------- |
---|
2920 | if get(handles.CheckFixAspectRatio,'Value') |
---|
2921 | set(handles.CheckFixAspectRatio,'BackgroundColor',[1 1 0]) |
---|
2922 | update_plot(handles); |
---|
2923 | else |
---|
2924 | set(handles.CheckFixAspectRatio,'BackgroundColor',[0.7 0.7 0.7]) |
---|
2925 | update_plot(handles); |
---|
2926 | end |
---|
2927 | |
---|
2928 | %------------------------------------------------------------------- |
---|
2929 | function num_AspectRatio_Callback(hObject, eventdata, handles) |
---|
2930 | %------------------------------------------------------------------- |
---|
2931 | set(handles.CheckFixAspectRatio,'Value',1)% select the fixed aspect ratio button |
---|
2932 | set(handles.CheckFixAspectRatio,'BackgroundColor',[1 1 0])% mark in yellow |
---|
2933 | update_plot(handles); |
---|
2934 | %------------------------------------------------------------------- |
---|
2935 | |
---|
2936 | %------------------------------------------------------------------- |
---|
2937 | |
---|
2938 | |
---|
2939 | |
---|
2940 | %------------------------------------------------------------------- |
---|
2941 | %----Executes on button press in 'record': records the current flags of manual correction. |
---|
2942 | %------------------------------------------------------------------- |
---|
2943 | function record_Callback(hObject, eventdata, handles) |
---|
2944 | % [filebase,num_i1,num_j1,num_i2,num_j2,Ext,NomType,SubDir]=read_input_file(handles); |
---|
2945 | [RootPath,SubDir,RootFile,FileIndices,FileExt]=read_file_boxes(handles); |
---|
2946 | FileName=[fullfile(RootPath,SubDir,RootFile) FileIndices FileExt]; |
---|
2947 | %FileName=read_file_boxes(handles); |
---|
2948 | [erread,message]=fileattrib(FileName); |
---|
2949 | if ~isempty(message) && ~isequal(message.UserWrite,1) |
---|
2950 | msgbox_uvmat('ERROR',['no writting access to ' FileName]) |
---|
2951 | return |
---|
2952 | end |
---|
2953 | test_civ2=isequal(get(handles.civ2,'BackgroundColor'),[1 1 0]); |
---|
2954 | test_civ1=isequal(get(handles.VelType,'BackgroundColor'),[1 1 0]); |
---|
2955 | if ~test_civ2 && ~test_civ1 |
---|
2956 | msgbox_uvmat('ERROR','manual correction only possible for CIV1 or CIV2 velocity fields') |
---|
2957 | end |
---|
2958 | if test_civ2 |
---|
2959 | nbname='nb_vectors2'; |
---|
2960 | flagname='vec2_FixFlag'; |
---|
2961 | attrname='fix2'; |
---|
2962 | end |
---|
2963 | if test_civ1 |
---|
2964 | nbname='nb_vectors'; |
---|
2965 | flagname='vec_FixFlag'; |
---|
2966 | attrname='fix'; |
---|
2967 | end |
---|
2968 | %write fix flags in the netcdf file |
---|
2969 | UvData=get(handles.uvmat,'UserData'); |
---|
2970 | hhh=which('netcdf.open');% look for built-in matlab netcdf library |
---|
2971 | if ~isequal(hhh,'')% case of new builtin Matlab netcdf library |
---|
2972 | nc=netcdf.open(FileName,'NC_WRITE'); |
---|
2973 | netcdf.reDef(nc); |
---|
2974 | netcdf.putAtt(nc,netcdf.getConstant('NC_GLOBAL'),attrname,1); |
---|
2975 | dimid = netcdf.inqDimID(nc,nbname); |
---|
2976 | try |
---|
2977 | varid = netcdf.inqVarID(nc,flagname);% look for already existing fixflag variable |
---|
2978 | catch |
---|
2979 | varid=netcdf.defVar(nc,flagname,'double',dimid);%create fixflag variable if it does not exist |
---|
2980 | end |
---|
2981 | netcdf.endDef(nc); |
---|
2982 | netcdf.putVar(nc,varid,UvData.PlotAxes.FF); |
---|
2983 | netcdf.close(nc); |
---|
2984 | else %old netcdf library |
---|
2985 | netcdf_toolbox(FileName,AxeData,attrname,nbname,flagname) |
---|
2986 | end |
---|
2987 | |
---|
2988 | %------------------------------------------------------------------- |
---|
2989 | %----Correct the netcdf file, using toolbox (old versions of Matlab). |
---|
2990 | %------------------------------------------------------------------- |
---|
2991 | function netcdf_toolbox(FileName,AxeData,attrname,nbname,flagname) |
---|
2992 | nc=netcdf(FileName,'write'); %open netcdf file |
---|
2993 | result=redef(nc); |
---|
2994 | eval(['nc.' attrname '=1;']); |
---|
2995 | theDim=nc(nbname) ;% get the number of velocity vectors |
---|
2996 | nb_vectors=size(theDim); |
---|
2997 | var_FixFlag=ncvar(flagname,nc);% var_FixFlag will be written as the netcdf variable vec_FixFlag |
---|
2998 | var_FixFlag(1:nb_vectors)=AxeData.FF;% |
---|
2999 | fin=close(nc); |
---|
3000 | |
---|
3001 | %------------------------------------------------------------------- |
---|
3002 | % --- Executes on button press in SubField |
---|
3003 | function SubField_Callback(hObject, eventdata, handles) |
---|
3004 | %------------------------------------------------------------------- |
---|
3005 | UvData=get(handles.uvmat,'UserData'); |
---|
3006 | if get(handles.SubField,'Value')==0% if the subfield button is desactivated |
---|
3007 | set(handles.RootPath_1,'String','') |
---|
3008 | set(handles.RootFile_1,'String','') |
---|
3009 | set(handles.SubDir_1,'String',''); |
---|
3010 | set(handles.FileIndex_1,'String',''); |
---|
3011 | set(handles.FileExt_1,'String',''); |
---|
3012 | set(handles.RootPath_1,'Visible','off') |
---|
3013 | set(handles.RootFile_1,'Visible','off') |
---|
3014 | set(handles.SubDir_1,'Visible','off'); |
---|
3015 | set(handles.NomType_1,'Visible','off'); |
---|
3016 | set(handles.abs_time_1,'Visible','off') |
---|
3017 | set(handles.FileIndex_1,'Visible','off'); |
---|
3018 | set(handles.FileExt_1,'Visible','off'); |
---|
3019 | set(handles.Fields_1,'Value',1);%set to blank state |
---|
3020 | set(handles.VelType_1,'Value',1);%set to blank state |
---|
3021 | set(handles.num_Opacity,'String','')% desactivate opacity setting |
---|
3022 | if ~strcmp(get(handles.VelType,'Visible'),'on') |
---|
3023 | set(handles.VelType_1,'Visible','off') |
---|
3024 | end |
---|
3025 | if isfield(UvData,'XmlData_1') |
---|
3026 | UvData=rmfield(UvData,'XmlData_1'); |
---|
3027 | end |
---|
3028 | set(handles.uvmat,'UserData',UvData); |
---|
3029 | transform_fct_list=get(handles.transform_fct,'String'); |
---|
3030 | transform_fct=transform_fct_list(get(handles.transform_fct,'Value')); |
---|
3031 | if strcmp(transform_fct,'sub_field') |
---|
3032 | set(handles.transform_fct,'Value',1)%suppress the sub_field transform |
---|
3033 | transform_fct_Callback(hObject, eventdata, handles); |
---|
3034 | else |
---|
3035 | run0_Callback(hObject, eventdata, handles) |
---|
3036 | end |
---|
3037 | else |
---|
3038 | MenuBrowse_1_Callback(hObject, eventdata, handles) |
---|
3039 | end |
---|
3040 | |
---|
3041 | %------------------------------------------------------------------------ |
---|
3042 | % --- read the data displayed for the input rootfile windows (new): TODO use read_GUI |
---|
3043 | |
---|
3044 | function [RootPath,SubDir,RootFile,FileIndices,FileExt]=read_file_boxes(handles) |
---|
3045 | %------------------------------------------------------------------------ |
---|
3046 | InputFile=read_GUI(handles.InputFile); |
---|
3047 | RootPath=InputFile.RootPath; |
---|
3048 | SubDir=regexprep(InputFile.SubDir,'/|\',''); |
---|
3049 | RootFile=regexprep(InputFile.RootFile,'/|\',''); |
---|
3050 | FileIndices=InputFile.FileIndex; |
---|
3051 | FileExt=InputFile.FileExt; |
---|
3052 | |
---|
3053 | |
---|
3054 | %------------------------------------------------------------------------ |
---|
3055 | % ---- read the data displayed for the second input rootfile windows |
---|
3056 | function [RootPath_1,SubDir_1,RootFile_1,FileIndex_1,FileExt_1,NomType_1]=read_file_boxes_1(handles) |
---|
3057 | %------------------------------------------------------------------------ |
---|
3058 | RootPath_1=get(handles.RootPath_1,'String'); % read the data from the file1_input window |
---|
3059 | if isequal(get(handles.RootPath_1,'Visible'),'off') || isequal(RootPath_1,'"') |
---|
3060 | RootPath_1=get(handles.RootPath,'String'); |
---|
3061 | end; |
---|
3062 | SubDir_1=get(handles.SubDir_1,'String'); |
---|
3063 | if isequal(get(handles.SubDir_1,'Visible'),'off')|| isequal(SubDir_1,'"') |
---|
3064 | SubDir_1=get(handles.SubDir,'String'); |
---|
3065 | end |
---|
3066 | SubDir_1=regexprep(SubDir_1,'\<[\\/]|[\\/]\>','');%suppress possible / or \ separator at the beginning or the end of the string |
---|
3067 | RootFile_1=get(handles.RootFile_1,'String'); |
---|
3068 | if isequal(get(handles.RootFile_1,'Visible'),'off') || isequal(RootFile_1,'"') |
---|
3069 | RootFile_1=get(handles.RootFile,'String'); |
---|
3070 | end |
---|
3071 | RootFile_1=regexprep(RootFile_1,'\<[\\/]|[\\/]\>','');%suppress possible / or \ separator at the beginning or the end of the string |
---|
3072 | FileIndex_1=get(handles.FileIndex_1,'String'); |
---|
3073 | if isequal(get(handles.FileIndex_1,'Visible'),'off')|| isequal(FileIndex_1,'"') |
---|
3074 | FileIndex_1=get(handles.FileIndex,'String'); |
---|
3075 | end |
---|
3076 | FileExt_1=get(handles.FileExt_1,'String'); |
---|
3077 | if isequal(get(handles.FileExt_1,'Visible'),'off') || isequal(FileExt_1,'"') |
---|
3078 | FileExt_1=get(handles.FileExt,'String');%read FileExt by default |
---|
3079 | end |
---|
3080 | NomType_1=get(handles.NomType_1,'String'); |
---|
3081 | if isequal(get(handles.NomType_1,'Visible'),'off') || isequal(NomType_1,'"') |
---|
3082 | NomType_1=get(handles.NomType,'String');%read FileExt by default |
---|
3083 | end |
---|
3084 | %------------------------------------------------------------------------ |
---|
3085 | % --- Executes on menu selection Fields |
---|
3086 | function Fields_Callback(hObject, eventdata, handles) |
---|
3087 | %------------------------------------------------------------------------ |
---|
3088 | list_fields=get(handles.Fields,'String');% list menu fields |
---|
3089 | index_fields=get(handles.Fields,'Value');% selected string index |
---|
3090 | field= list_fields{index_fields(1)}; % selected string |
---|
3091 | if isequal(field,'get_field...') |
---|
3092 | set(handles.FixVelType,'visible','off') |
---|
3093 | set(handles.VelType,'visible','off') |
---|
3094 | set(handles.VelType_1,'visible','off') |
---|
3095 | [RootPath,SubDir,RootFile,FileIndices,FileExt]=read_file_boxes(handles); |
---|
3096 | FileName=[fullfile(RootPath,SubDir,RootFile) FileIndices FileExt]; |
---|
3097 | hget_field=findobj(allchild(0),'name','get_field'); |
---|
3098 | if ~isempty(hget_field) |
---|
3099 | delete(hget_field) |
---|
3100 | end |
---|
3101 | hget_field=get_field(FileName); |
---|
3102 | % set(hget_field,'Name','get_field') |
---|
3103 | % hhget_field=guidata(hget_field); |
---|
3104 | % set(hhget_field.list_fig,'Value',1) |
---|
3105 | % set(hhget_field.list_fig,'String',{'uvmat'}) |
---|
3106 | % set(handles.transform_fct,'Value',1)% no transform by default |
---|
3107 | % set(handles.path_transform,'String','') |
---|
3108 | return %no further action |
---|
3109 | end |
---|
3110 | |
---|
3111 | UvData=get(handles.uvmat,'UserData'); |
---|
3112 | |
---|
3113 | %read the rootfile input display |
---|
3114 | [RootPath,SubDir,RootFile,FileIndices,FileExt]=read_file_boxes(handles); |
---|
3115 | FileName=[fullfile(RootPath,SubDir,RootFile) FileIndices FileExt]; |
---|
3116 | [tild,tild,tild,i1,i2,j1,j2,tild,NomType]=fileparts_uvmat(['xxx' get(handles.FileIndex,'String') FileExt]); |
---|
3117 | if isequal(field,'image') |
---|
3118 | if isfield(UvData.Field,'Civ2_ImageA')%get the corresponding input image in the netcdf file |
---|
3119 | imagename=UvData.Field.Civ2_ImageA; |
---|
3120 | elseif isfield(UvData.Field,'Civ1_ImageA')% |
---|
3121 | imagename=UvData.Field.Civ1_ImageA; |
---|
3122 | else |
---|
3123 | SubDirBase=regexprep(SubDir,'\..*','');%take the root part of SubDir, before the first dot '.' |
---|
3124 | imagename=fullfile_uvmat(RootPath,SubDirBase,RootFile,'.png',NomType,i1,[],j1,[]); |
---|
3125 | end |
---|
3126 | if ~exist(imagename,'file') |
---|
3127 | [FileName,PathName] = uigetfile( ... |
---|
3128 | {'*.png;*.jpg;*.tif;*.avi;*.AVI;*.vol', ' (*.png, .tif, *.avi,*.vol)'; |
---|
3129 | '*.jpg',' jpeg image files'; ... |
---|
3130 | '*.png','.png image files'; ... |
---|
3131 | '*.tif','.tif image files'; ... |
---|
3132 | '*.avi;*.AVI','.avi movie files'; ... |
---|
3133 | '*.vol','.volume images (png)'; ... |
---|
3134 | '*.*', 'All Files (*.*)'}, ... |
---|
3135 | 'Pick an image',imagename); |
---|
3136 | imagename=[PathName FileName]; |
---|
3137 | end |
---|
3138 | % display the selected field and related information |
---|
3139 | display_file_name(handles,imagename)%display the image |
---|
3140 | return |
---|
3141 | else |
---|
3142 | ext=get(handles.FileExt,'String'); |
---|
3143 | if ~isequal(ext,'.nc') %find the new NomType if the previous display was not already a netcdf file |
---|
3144 | [FileName,PathName] = uigetfile( ... |
---|
3145 | {'*.nc', ' (*.nc)'; |
---|
3146 | '*.nc',' netcdf files'; ... |
---|
3147 | '*.*', 'All Files (*.*)'}, ... |
---|
3148 | 'Pick a netcdf file',FileBase); |
---|
3149 | FullFileName=[PathName FileName]; |
---|
3150 | % display the selected field and related information |
---|
3151 | display_file_name( handles,FullFileName) |
---|
3152 | return |
---|
3153 | end |
---|
3154 | end |
---|
3155 | indices=fullfile_uvmat('','','','',NomType,i1,i2,j1,j2); |
---|
3156 | set(handles.FileIndex,'String',indices) |
---|
3157 | % set(handles.NomType,'String',NomType) |
---|
3158 | |
---|
3159 | %common to Fields_1_Callback |
---|
3160 | list_fields_1=get(handles.Fields_1,'String');% list menu fields |
---|
3161 | field_1=''; |
---|
3162 | if ~isempty(list_fields_1) |
---|
3163 | field_1= list_fields_1{get(handles.Fields_1,'Value')}; % selected string |
---|
3164 | end |
---|
3165 | if isequal(field,'image')||isequal(field_1,'image') |
---|
3166 | set(handles.TitleNpx,'Visible','on')% visible npx,pxcm... buttons |
---|
3167 | set(handles.TitleNpy,'Visible','on') |
---|
3168 | set(handles.num_Npx,'Visible','on') |
---|
3169 | set(handles.num_Npy,'Visible','on') |
---|
3170 | else |
---|
3171 | set(handles.TitleNpx,'Visible','off')% visible npx,pxcm... buttons |
---|
3172 | set(handles.TitleNpy,'Visible','off') |
---|
3173 | set(handles.num_Npx,'Visible','off') |
---|
3174 | set(handles.num_Npy,'Visible','off') |
---|
3175 | end |
---|
3176 | if ~(isfield(UvData,'NewSeries')&&isequal(UvData.NewSeries,1)) |
---|
3177 | run0_Callback(hObject, eventdata, handles) |
---|
3178 | end |
---|
3179 | |
---|
3180 | %--------------------------------------------------- |
---|
3181 | % --- Executes on menu selection Fields |
---|
3182 | function Fields_1_Callback(hObject, eventdata, handles) |
---|
3183 | %------------------------------------------------- |
---|
3184 | %% read input data |
---|
3185 | check_new=~get(handles.SubField,'Value'); %check_new=1 if a second field was not previously entered |
---|
3186 | UvData=get(handles.uvmat,'UserData'); |
---|
3187 | if check_new && isfield(UvData,'XmlData') |
---|
3188 | UvData.XmlData{2}=UvData.XmlData{1}; |
---|
3189 | end |
---|
3190 | if isfield(UvData,'Field_1') |
---|
3191 | UvData=rmfield(UvData,'Field_1');% remove the stored second field (a new one needs to be read) |
---|
3192 | end |
---|
3193 | UvData.FileName_1='';% desactivate the use of a constant second file |
---|
3194 | list_fields=get(handles.Fields,'String');% list menu fields |
---|
3195 | field= list_fields{get(handles.Fields,'Value')}; % selected string |
---|
3196 | list_fields=get(handles.Fields_1,'String');% list menu fields |
---|
3197 | field_1= list_fields{get(handles.Fields_1,'Value')}; % selected string for the second field |
---|
3198 | if isempty(field_1)%||(numel(UvData.FileType)>=2 && strcmp(UvData.FileType{2},'image')) |
---|
3199 | set(handles.SubField,'Value',0) |
---|
3200 | SubField_Callback(hObject, eventdata, handles) |
---|
3201 | return |
---|
3202 | else |
---|
3203 | set(handles.SubField,'Value',1)%state that a second field is now entered |
---|
3204 | end |
---|
3205 | |
---|
3206 | %% read the rootfile input display |
---|
3207 | [RootPath_1,SubDir_1,RootFile_1,FileIndex_1,FileExt_1]=read_file_boxes_1(handles); |
---|
3208 | FileName_1=[fullfile(RootPath_1,SubDir_1,RootFile_1) FileIndex_1 FileExt_1]; |
---|
3209 | [tild,tild,tild,i1,i2,j1,j2]=fileparts_uvmat(get(handles.FileIndex,'String')); |
---|
3210 | switch field_1 |
---|
3211 | case 'get_field...' |
---|
3212 | set_veltype_display(0) % no veltype display |
---|
3213 | hget_field=findobj(allchild(0),'name','get_field_1'); |
---|
3214 | if ~isempty(hget_field) |
---|
3215 | delete(hget_field) |
---|
3216 | end |
---|
3217 | hget_field=get_field(FileName_1); |
---|
3218 | set(hget_field,'name','get_field_1') |
---|
3219 | hhget_field=guidata(hget_field); |
---|
3220 | set(hhget_field.list_fig,'Value',1) |
---|
3221 | set(hhget_field.list_fig,'String',{'uvmat'}) |
---|
3222 | if check_new |
---|
3223 | UvData.FileType{2}=UvData.FileType{1}; |
---|
3224 | set(handles.FileIndex_1,'String',get(handles.FileIndex,'String')) |
---|
3225 | set(handles.uvmat,'UserData',UvData) |
---|
3226 | end |
---|
3227 | case 'image' |
---|
3228 | % get the image name corresponding to the current netcdf name (no unique correspondance) |
---|
3229 | if isfield(UvData.Field,'Civ2_ImageA')%get the corresponding input image in the netcdf file |
---|
3230 | imagename=UvData.Field.Civ2_ImageA; |
---|
3231 | elseif isfield(UvData.Field,'Civ1_ImageA')% |
---|
3232 | imagename=UvData.Field.Civ1_ImageA; |
---|
3233 | else |
---|
3234 | SubDirBase=regexprep(SubDir_1,'\..*','');%take the root part of SubDir, before the first dot '.' |
---|
3235 | imagename=fullfile_uvmat(RootPath_1,SubDirBase,RootFile_1,'.png',get(handles.NomType,'String'),i1,[],j1); |
---|
3236 | end |
---|
3237 | if ~exist(imagename,'file') % browse for images if it is not found |
---|
3238 | [FileName,PathName] = uigetfile( ... |
---|
3239 | {'*.png;*.jpg;*.tif;*.avi;*.AVI;*.vol', ' (*.png, .tif, *.avi,*.vol)'; |
---|
3240 | '*.jpg',' jpeg image files'; ... |
---|
3241 | '*.png','.png image files'; ... |
---|
3242 | '*.tif','.tif image files'; ... |
---|
3243 | '*.avi;*.AVI','.avi movie files'; ... |
---|
3244 | '*.vol','.volume images (png)'; ... |
---|
3245 | '*.*', 'All Files (*.*)'}, ... |
---|
3246 | 'Pick an image',imagename); |
---|
3247 | imagename=[PathName FileName]; |
---|
3248 | end |
---|
3249 | if ~ischar(imagename)% quit if the browser has been closed |
---|
3250 | set(handles.SubField,'Value',0) |
---|
3251 | else %valid browser input: display the selected image |
---|
3252 | set(handles.TitleNpx,'Visible','on')% visible npx,pxcm... buttons |
---|
3253 | set(handles.TitleNpy,'Visible','on') |
---|
3254 | set(handles.num_Npx,'Visible','on') |
---|
3255 | set(handles.num_Npy,'Visible','on') |
---|
3256 | display_file_name(handles,imagename,2)%display the imag |
---|
3257 | end |
---|
3258 | otherwise |
---|
3259 | if check_new |
---|
3260 | UvData.FileType{2}=UvData.FileType{1}; |
---|
3261 | set(handles.FileIndex_1,'String',get(handles.FileIndex,'String')) |
---|
3262 | set(handles.FileExt_1,'String',get(handles.FileExt,'String')) |
---|
3263 | end |
---|
3264 | if ~isequal(field,'image') |
---|
3265 | set(handles.TitleNpx,'Visible','off')% visible npx,pxcm... buttons |
---|
3266 | set(handles.TitleNpy,'Visible','off') |
---|
3267 | set(handles.num_Npx,'Visible','off') |
---|
3268 | set(handles.num_Npy,'Visible','off') |
---|
3269 | end |
---|
3270 | set(handles.uvmat,'UserData',UvData) |
---|
3271 | if ~(isfield(UvData,'NewSeries')&&isequal(UvData.NewSeries,1)) |
---|
3272 | run0_Callback(hObject, eventdata, handles) |
---|
3273 | end |
---|
3274 | end |
---|
3275 | |
---|
3276 | %------------------------------------------------------------------------ |
---|
3277 | % --- set the visibility of relevant velocity type menus: |
---|
3278 | function menu=set_veltype_display(Civ,FileType) |
---|
3279 | %------------------------------------------------------------------------ |
---|
3280 | if ~exist('FileType','var') |
---|
3281 | FileType='civx'; |
---|
3282 | end |
---|
3283 | switch FileType |
---|
3284 | case 'civx' |
---|
3285 | menu={'civ1';'interp1';'filter1';'civ2';'interp2';'filter2'}; |
---|
3286 | if isequal(Civ,0) |
---|
3287 | imax=0; |
---|
3288 | elseif isequal(Civ,1) || isequal(Civ,2) |
---|
3289 | imax=1; |
---|
3290 | elseif isequal(Civ,3) |
---|
3291 | imax=3; |
---|
3292 | elseif isequal(Civ,4) || isequal(Civ,5) |
---|
3293 | imax=4; |
---|
3294 | elseif isequal(Civ,6) %patch2 |
---|
3295 | imax=6; |
---|
3296 | end |
---|
3297 | case 'civdata' |
---|
3298 | menu={'civ1';'filter1';'civ2';'filter2'}; |
---|
3299 | if isequal(Civ,0) |
---|
3300 | imax=0; |
---|
3301 | elseif isequal(Civ,1) || isequal(Civ,2) |
---|
3302 | imax=1; |
---|
3303 | elseif isequal(Civ,3) |
---|
3304 | imax=2; |
---|
3305 | elseif isequal(Civ,4) || isequal(Civ,5) |
---|
3306 | imax=3; |
---|
3307 | elseif isequal(Civ,6) %patch2 |
---|
3308 | imax=4; |
---|
3309 | end |
---|
3310 | end |
---|
3311 | menu=menu(1:imax); |
---|
3312 | |
---|
3313 | %------------------------------------------------------------------------ |
---|
3314 | % --- Executes on button press in FixVelType. |
---|
3315 | function FixVelType_Callback(hObject, eventdata, handles) |
---|
3316 | %------------------------------------------------------------------------ |
---|
3317 | % refresh the current plot if the fixed veltype is unselected |
---|
3318 | if ~get(handles.FixVelType,'Value') |
---|
3319 | run0_Callback(hObject, eventdata, handles) |
---|
3320 | end |
---|
3321 | |
---|
3322 | %------------------------------------------------------------------------ |
---|
3323 | % --- Executes on button press in VelType. |
---|
3324 | function VelType_Callback(hObject, eventdata, handles) |
---|
3325 | %------------------------------------------------------------------------ |
---|
3326 | set(handles.FixVelType,'Value',1) |
---|
3327 | run0_Callback(hObject, eventdata, handles) |
---|
3328 | |
---|
3329 | %------------------------------------------------------------------------ |
---|
3330 | % --- Executes on choice selection in VelType_1. |
---|
3331 | function VelType_1_Callback(hObject, eventdata, handles) |
---|
3332 | %------------------------------------------------------------------------ |
---|
3333 | set(handles.FixVelType,'Value',1)% the velocity type is now imposed by the GUI (not automatic) |
---|
3334 | UvData=get(handles.uvmat,'UserData'); |
---|
3335 | set(handles.run0,'BackgroundColor',[1 1 0])%paint run0 button in yellow to indicate its activation |
---|
3336 | drawnow |
---|
3337 | InputFile=read_GUI(handles.InputFile);% read the input file parameters |
---|
3338 | [RootPath,SubDir,RootFile,FileIndex,FileExt]=read_file_boxes(handles); |
---|
3339 | [RootPath_1,SubDir_1,RootFile_1,FileIndex_1,FileExt_1]=read_file_boxes_1(handles); |
---|
3340 | FileName=[fullfile(RootPath,SubDir,RootFile) FileIndex FileExt];% name of the first input file |
---|
3341 | |
---|
3342 | check_refresh=0; |
---|
3343 | if isempty(InputFile.VelType_1) |
---|
3344 | FileName_1='';% we plot the first input field without the second field |
---|
3345 | set(handles.SubField,'Value',0) |
---|
3346 | SubField_Callback(hObject, eventdata, handles)% activate SubField_Callback and refresh current display, removing the second field |
---|
3347 | elseif get(handles.SubField,'Value')% if subfield is already 'on' |
---|
3348 | FileName_1=[fullfile(RootPath_1,SubDir_1,RootFile_1) FileIndex_1 FileExt_1];% name of the second input file |
---|
3349 | check_refresh=1;%will refresh the current display |
---|
3350 | else% we introduce the same file (with a different field) for the second series |
---|
3351 | FileName_1=FileName;% we compare two fields in the same file |
---|
3352 | UvData.FileType{2}=UvData.FileType{1}; |
---|
3353 | UvData.XmlData{2}= UvData.XmlData{1}; |
---|
3354 | set(handles.SubField,'Value',1) |
---|
3355 | transform=get(handles.path_transform,'UserData'); |
---|
3356 | if (~isa(transform,'function_handle')||nargin(transform)<3) |
---|
3357 | set(handles.transform_fct,'value',2); % set transform to sub_field if the current fct doe not accept two input fields |
---|
3358 | transform_fct_Callback(hObject, eventdata, handles)% activate transform_fct_Callback and refresh current display |
---|
3359 | else |
---|
3360 | check_refresh=1; |
---|
3361 | end |
---|
3362 | end |
---|
3363 | |
---|
3364 | % refresh the current display if it has not been done previously |
---|
3365 | if check_refresh |
---|
3366 | UvData.FileName_1='';% desactivate the use of a constant second file |
---|
3367 | set(handles.uvmat,'UserData',UvData) |
---|
3368 | num_i1=stra2num(get(handles.i1,'String')); |
---|
3369 | num_i2=stra2num(get(handles.i2,'String')); |
---|
3370 | num_j1=stra2num(get(handles.j1,'String')); |
---|
3371 | num_j2=stra2num(get(handles.j2,'String')); |
---|
3372 | [tild,tild,tild,i1_1,i2_1,j1_1,j2_1]=fileparts_uvmat(['xx' FileIndex_1]); |
---|
3373 | errormsg=refresh_field(handles,FileName,FileName_1,num_i1,num_i2,num_j1,num_j2,i1_1,i2_1,j1_1,j2_1); |
---|
3374 | if ~isempty(errormsg) |
---|
3375 | msgbox_uvmat('ERROR',errormsg); |
---|
3376 | else |
---|
3377 | set(handles.i1,'BackgroundColor',[1 1 1]) |
---|
3378 | set(handles.i2,'BackgroundColor',[1 1 1]) |
---|
3379 | set(handles.j1,'BackgroundColor',[1 1 1]) |
---|
3380 | set(handles.j2,'BackgroundColor',[1 1 1]) |
---|
3381 | set(handles.FileIndex,'BackgroundColor',[1 1 1]) |
---|
3382 | set(handles.FileIndex_1,'BackgroundColor',[1 1 1]) |
---|
3383 | end |
---|
3384 | set(handles.run0,'BackgroundColor',[1 0 0]) |
---|
3385 | end |
---|
3386 | |
---|
3387 | %----------------------------------------------- |
---|
3388 | % --- reset civ buttons |
---|
3389 | function reset_vel_type(handles_civ0,handle1) |
---|
3390 | for ibutton=1:length(handles_civ0) |
---|
3391 | set(handles_civ0(ibutton),'BackgroundColor',[0.831 0.816 0.784]) |
---|
3392 | set(handles_civ0(ibutton),'Value',0) |
---|
3393 | end |
---|
3394 | if exist('handle1','var')%handles of selected button |
---|
3395 | set(handle1,'BackgroundColor',[1 1 0]) |
---|
3396 | end |
---|
3397 | |
---|
3398 | %------------------------------------------------------- |
---|
3399 | % --- Executes on button press in MENUVOLUME. |
---|
3400 | %------------------------------------------------------- |
---|
3401 | function VOLUME_Callback(hObject, eventdata, handles) |
---|
3402 | %errordlg('command VOL not implemented yet') |
---|
3403 | if ishandle(handles.UVMAT_title) |
---|
3404 | delete(handles.UVMAT_title) |
---|
3405 | end |
---|
3406 | UvData=get(handles.uvmat,'UserData');%read UvData properties stored on the uvmat interface |
---|
3407 | if isequal(get(handles.VOLUME,'Value'),1) |
---|
3408 | set(handles.CheckZoom,'Value',0) |
---|
3409 | set(handles.CheckZoom,'BackgroundColor',[0.7 0.7 0.7]) |
---|
3410 | set(handles.edit_vect,'Value',0) |
---|
3411 | edit_vect_Callback(hObject, eventdata, handles) |
---|
3412 | set(handles.edit_object,'Value',0) |
---|
3413 | set(handles.edit_object,'BackgroundColor',[0.7 0.7 0.7]) |
---|
3414 | % set(handles.cal,'Value',0) |
---|
3415 | % set(handles.cal,'BackgroundColor',[0 1 0]) |
---|
3416 | set(handles.edit_vect,'Value',0) |
---|
3417 | edit_vect_Callback(hObject, eventdata, handles) |
---|
3418 | %initiate set_object GUI |
---|
3419 | data.Name='VOLUME'; |
---|
3420 | if isfield(UvData,'CoordType') |
---|
3421 | data.CoordType=UvData.CoordType; |
---|
3422 | end |
---|
3423 | if isfield(UvData.Field,'Mesh')&~isempty(UvData.Field.Mesh) |
---|
3424 | data.RangeX=[UvData.Field.XMin UvData.Field.XMax]; |
---|
3425 | data.RangeY=[UvData.Field.YMin UvData.Field.YMax]; |
---|
3426 | data.DX=UvData.Field.Mesh; |
---|
3427 | data.DY=UvData.Field.Mesh; |
---|
3428 | elseif isfield(UvData.Field,'AX')&isfield(UvData.Field,'AY')& isfield(UvData.Field,'A')%only image |
---|
3429 | np=size(UvData.Field.A); |
---|
3430 | meshx=(UvData.Field.AX(end)-UvData.Field.AX(1))/np(2); |
---|
3431 | meshy=abs(UvData.Field.AY(end)-UvData.Field.AY(1))/np(1); |
---|
3432 | data.RangeY=max(meshx,meshy); |
---|
3433 | data.RangeX=max(meshx,meshy); |
---|
3434 | data.DX=max(meshx,meshy); |
---|
3435 | end |
---|
3436 | data.ParentButton=handles.VOLUME; |
---|
3437 | PlotHandles=get_plot_handles(handles);%get the handles of the interface elements setting the plotting parameters |
---|
3438 | [hset_object,UvData.sethandles]=set_object(data,PlotHandles);% call the set_object interface with action on haxes, |
---|
3439 | % associate the set_object interface handle to the plotting axes |
---|
3440 | set(hset_object,'Position',get(handles.uvmat,'Position')+UvData.OpenParam.PosSetObject) |
---|
3441 | UvData.MouseAction='create_object'; |
---|
3442 | else |
---|
3443 | set(handles.VOLUME,'BackgroundColor',[0 1 0]) |
---|
3444 | end |
---|
3445 | set(handles.uvmat,'UserData',UvData) |
---|
3446 | |
---|
3447 | %------------------------------------------------------- |
---|
3448 | function edit_vect_Callback(hObject, eventdata, handles) |
---|
3449 | %------------------------------------------------------- |
---|
3450 | % |
---|
3451 | % UvData=get(handles.uvmat,'UserData');%read UvData properties stored on the uvmat interface |
---|
3452 | if isequal(get(handles.edit_vect,'Value'),1) |
---|
3453 | test_civ2=isequal(get(handles.civ2,'BackgroundColor'),[1 1 0]); |
---|
3454 | test_civ1=isequal(get(handles.VelType,'BackgroundColor'),[1 1 0]); |
---|
3455 | if ~test_civ2 && ~test_civ1 |
---|
3456 | msgbox_uvmat('ERROR','manual correction only possible for CIV1 or CIV2 velocity fields') |
---|
3457 | end |
---|
3458 | set(handles.record,'Visible','on') |
---|
3459 | set(handles.edit_vect,'BackgroundColor',[1 1 0]) |
---|
3460 | set(handles.edit_object,'Value',0) |
---|
3461 | set(handles.CheckZoom,'Value',0) |
---|
3462 | set(handles.CheckZoom,'BackgroundColor',[0.7 0.7 0.7]) |
---|
3463 | % set(handles.create,'Value',0) |
---|
3464 | % set(handles.create,'BackgroundColor',[0 1 0]) |
---|
3465 | set(handles.edit_object,'BackgroundColor',[0.7 0.7 0.7]) |
---|
3466 | set(gcf,'Pointer','arrow') |
---|
3467 | % UvData.MouseAction='edit_vect'; |
---|
3468 | else |
---|
3469 | set(handles.record,'Visible','off') |
---|
3470 | set(handles.edit_vect,'BackgroundColor',[0.7 0.7 0.7]) |
---|
3471 | end |
---|
3472 | |
---|
3473 | %---------------------------------------------- |
---|
3474 | function save_mask_Callback(hObject, eventdata, handles) |
---|
3475 | %----------------------------------------------------------------------- |
---|
3476 | UvData=get(handles.uvmat,'UserData'); |
---|
3477 | |
---|
3478 | flag=1; |
---|
3479 | npx=size(UvData.Field.A,2); |
---|
3480 | npy=size(UvData.Field.A,1); |
---|
3481 | xi=0.5:npx-0.5; |
---|
3482 | yi=0.5:npy-0.5; |
---|
3483 | [Xi,Yi]=meshgrid(xi,yi); |
---|
3484 | if isfield(UvData,'Object') |
---|
3485 | for iobj=1:length(UvData.Object) |
---|
3486 | ObjectData=UvData.Object{iobj}; |
---|
3487 | if isfield(ObjectData,'ProjMode') &&(isequal(ObjectData.ProjMode,'mask_inside')||isequal(ObjectData.ProjMode,'mask_outside')); |
---|
3488 | flagobj=1; |
---|
3489 | testphys=0; %coordinates in pixels by default |
---|
3490 | if isfield(ObjectData,'CoordType') && isequal(ObjectData.CoordType,'phys') |
---|
3491 | if isfield(UvData,'XmlData')&& isfield(UvData.XmlData{1},'GeometryCalib') |
---|
3492 | Calib=UvData.XmlData{1}.GeometryCalib; |
---|
3493 | testphys=1; |
---|
3494 | end |
---|
3495 | end |
---|
3496 | if isfield(ObjectData,'Coord')& isfield(ObjectData,'Style') |
---|
3497 | if isequal(ObjectData.Type,'polygon') |
---|
3498 | X=ObjectData.Coord(:,1); |
---|
3499 | Y=ObjectData.Coord(:,2); |
---|
3500 | if testphys |
---|
3501 | [X,Y]=px_XYZ(Calib,X,Y,0);% to generalise with 3D cases |
---|
3502 | end |
---|
3503 | flagobj=~inpolygon(Xi,Yi,X',Y');%=0 inside the polygon, 1 outside |
---|
3504 | elseif isequal(ObjectData.Type,'ellipse') |
---|
3505 | if testphys |
---|
3506 | %[X,Y]=px_XYZ(Calib,X,Y,0);% TODO:create a polygon boundary and transform to phys |
---|
3507 | end |
---|
3508 | RangeX=max(ObjectData.RangeX); |
---|
3509 | RangeY=max(ObjectData.RangeY); |
---|
3510 | X2Max=RangeX*RangeX; |
---|
3511 | Y2Max=RangeY*RangeY; |
---|
3512 | distX=(Xi-ObjectData.Coord(1,1)); |
---|
3513 | distY=(Yi-ObjectData.Coord(1,2)); |
---|
3514 | flagobj=(distX.*distX/X2Max+distY.*distY/Y2Max)>1; |
---|
3515 | elseif isequal(ObjectData.Type,'rectangle') |
---|
3516 | if testphys |
---|
3517 | %[X,Y]=px_XYZ(Calib,X,Y,0);% TODO:create a polygon boundary and transform to phys |
---|
3518 | end |
---|
3519 | distX=abs(Xi-ObjectData.Coord(1,1)); |
---|
3520 | distY=abs(Yi-ObjectData.Coord(1,2)); |
---|
3521 | flagobj=distX>max(ObjectData.RangeX) | distY>max(ObjectData.RangeY); |
---|
3522 | end |
---|
3523 | if isequal(ObjectData.ProjMode,'mask_outside') |
---|
3524 | flagobj=~flagobj; |
---|
3525 | end |
---|
3526 | flag=flag & flagobj; |
---|
3527 | end |
---|
3528 | end |
---|
3529 | end |
---|
3530 | end |
---|
3531 | % flag=~flag; |
---|
3532 | %mask name |
---|
3533 | RootPath=get(handles.RootPath,'String'); |
---|
3534 | RootFile=get(handles.RootFile,'String'); |
---|
3535 | RootFile=regexprep(RootFile,'\<[\\/]|[\\/]\>','');%suppress possible / or \ separator at the beginning or the end of the string |
---|
3536 | filebase=fullfile(RootPath,RootFile); |
---|
3537 | list=get(handles.masklevel,'String'); |
---|
3538 | masknumber=num2str(length(list)); |
---|
3539 | maskindex=get(handles.masklevel,'Value'); |
---|
3540 | mask_name=fullfile_uvmat(RootPath,SubDir,[RootFile '_' masknumber 'mask'],'.png','_1',maskindex); |
---|
3541 | %mask_name=name_generator([filebase '_' masknumber 'mask'],maskindex,1,'.png','_i'); |
---|
3542 | imflag=uint8(255*(0.392+0.608*flag));% =100 for flag=0 (vectors not computed when 20<imflag<200) |
---|
3543 | imflag=flipdim(imflag,1); |
---|
3544 | % imflag=uint8(255*flag);% =0 for flag=0 (vectors=0 when 20<imflag<200) |
---|
3545 | msgbox_uvmat('CONFIRMATION',[mask_name ' saved']) |
---|
3546 | imwrite(imflag,mask_name,'BitDepth',8); |
---|
3547 | |
---|
3548 | %display the mask |
---|
3549 | figure; |
---|
3550 | vec=linspace(0,1,256);%define a linear greyscale colormap |
---|
3551 | map=[vec' vec' vec']; |
---|
3552 | colormap(map) |
---|
3553 | |
---|
3554 | image(imflag); |
---|
3555 | |
---|
3556 | %------------------------------------------------------------------- |
---|
3557 | %------------------------------------------------------------------- |
---|
3558 | % - FUNCTIONS FOR SETTING PLOTTING PARAMETERS |
---|
3559 | |
---|
3560 | %------------------------------------------------------------------ |
---|
3561 | %------------------------------------------------------------- |
---|
3562 | % --- Executes on selection change in transform_fct. |
---|
3563 | |
---|
3564 | function transform_fct_Callback(hObject, eventdata, handles) |
---|
3565 | %------------------------------------------------------------- |
---|
3566 | UvData=get(handles.uvmat,'UserData'); |
---|
3567 | menu=get(handles.transform_fct,'String');refresh |
---|
3568 | ichoice=get(handles.transform_fct,'Value');%item number in the menu |
---|
3569 | transform_name=menu{ichoice};% choice of the transform fct |
---|
3570 | list_path=get(handles.transform_fct,'UserData'); |
---|
3571 | |
---|
3572 | %% add a new item to the menu if the option 'more...' has been selected |
---|
3573 | prev_path=fullfile(get(handles.path_transform,'String')); |
---|
3574 | if ~exist(prev_path,'dir') |
---|
3575 | prev_path=fullfile(fileparts(which('uvmat')),'transform_field'); |
---|
3576 | end |
---|
3577 | if strcmp(transform_name,'more...'); |
---|
3578 | [FileName, PathName] = uigetfile( ... |
---|
3579 | {'*.m', ' (*.m)'; |
---|
3580 | '*.m', '.m files '; ... |
---|
3581 | '*.*', 'All Files (*.*)'}, ... |
---|
3582 | 'Pick the transform function', prev_path); |
---|
3583 | path_transform_fct =fullfile(PathName,FileName); |
---|
3584 | if ~exist(path_transform_fct,'file')% cancel has been activated |
---|
3585 | return |
---|
3586 | end |
---|
3587 | if isempty(regexp(FileName,'.m$'))% detect file extension .m |
---|
3588 | msgbox_uvmat('ERROR','a Matlab function .m must be introduced'); |
---|
3589 | return |
---|
3590 | else |
---|
3591 | transform_name=regexprep(FileName,'.m',''); |
---|
3592 | end |
---|
3593 | ichoice=find(strcmp(transform_name,menu),1);%look for the selected fct in the existing menu |
---|
3594 | if isempty(ichoice)% if the item is not found, add it to the menu (before 'more...' and select it) |
---|
3595 | menu=[menu(1:end-1);{transform_name};{'more...'}]; |
---|
3596 | ichoice=numel(menu)-1; |
---|
3597 | end |
---|
3598 | list_path{ichoice}=PathName;%update the list fo fct paths |
---|
3599 | set(handles.transform_fct,'String',menu) |
---|
3600 | set(handles.transform_fct,'Value',ichoice) |
---|
3601 | |
---|
3602 | % save the new menu in the personal file 'uvmat_perso.mat' |
---|
3603 | dir_perso=prefdir;%personal Matalb directory |
---|
3604 | profil_perso=fullfile(dir_perso,'uvmat_perso.mat'); |
---|
3605 | if exist(profil_perso,'file') |
---|
3606 | nb_builtin=UvData.OpenParam.NbBuiltin;% number of 'builtin' (basic) transform fcts in uvmat |
---|
3607 | if nb_builtin<numel(list_path) |
---|
3608 | for ilist=nb_builtin+1:numel(list_path) |
---|
3609 | transform_fct{ilist-nb_builtin}=[fullfile(list_path{ilist},menu{ilist}) '.m']; |
---|
3610 | end |
---|
3611 | save (profil_perso,'transform_fct','-append'); %store the root name for future opening of uvmat |
---|
3612 | end |
---|
3613 | end |
---|
3614 | end |
---|
3615 | |
---|
3616 | %% create the function handle of the selected fct |
---|
3617 | |
---|
3618 | if isempty(list_path{ichoice})% case of no selected fct |
---|
3619 | transform_handle=[]; |
---|
3620 | else |
---|
3621 | if ~exist(list_path{ichoice},'dir') |
---|
3622 | msgbox_uvmat('ERROR','invalid fct path: select the transform fct again with the option more...') |
---|
3623 | return |
---|
3624 | end |
---|
3625 | current_dir=pwd;%current working dir |
---|
3626 | cd(list_path{ichoice}) |
---|
3627 | transform_handle=str2func(transform_name); |
---|
3628 | cd(current_dir) |
---|
3629 | end |
---|
3630 | set(handles.path_transform,'String',list_path{ichoice}) |
---|
3631 | set(handles.path_transform,'UserData',transform_handle) |
---|
3632 | set(handles.transform_fct,'UserData',list_path) |
---|
3633 | |
---|
3634 | %% update the ToolTip string of the menu transform_fct with the first line of the selected fct file |
---|
3635 | if isempty(list_path{ichoice})% case of no selected fct |
---|
3636 | set(handles.transform_fct,'ToolTipString','transform_fct:choose a transform function') |
---|
3637 | else |
---|
3638 | try |
---|
3639 | [fid,errormsg] =fopen([fullfile(list_path{ichoice},transform_name) '.m']); |
---|
3640 | InputText=textscan(fid,'%s',1,'delimiter','\n'); |
---|
3641 | fclose(fid) |
---|
3642 | set(handles.transform_fct,'ToolTipString',['transform_fct: ' InputText{1}{1}])% put the first line of the selected function as tooltip help |
---|
3643 | end |
---|
3644 | end |
---|
3645 | |
---|
3646 | %% adapt the GUI to the input/output conditions of the selected transform fct |
---|
3647 | DataOut=[]; |
---|
3648 | CoordUnit=''; |
---|
3649 | CoordUnitPrev=''; |
---|
3650 | if isfield(UvData,'Field')&&isfield(UvData.Field,'CoordUnit') |
---|
3651 | CoordUnitPrev=UvData.Field.CoordUnit; |
---|
3652 | end |
---|
3653 | if ~isempty(list_path{ichoice}) |
---|
3654 | if nargin(transform_handle)>1 && isfield(UvData,'XmlData')&&~isempty(UvData.XmlData) |
---|
3655 | XmlData=UvData.XmlData{1}; |
---|
3656 | DataOut=feval(transform_handle,'*',XmlData); |
---|
3657 | if isfield(DataOut,'CoordUnit') |
---|
3658 | CoordUnit=DataOut.CoordUnit; |
---|
3659 | end |
---|
3660 | if isfield(DataOut,'InputFieldType') |
---|
3661 | UvData.InputFieldType=DataOut.InputFieldType; |
---|
3662 | end |
---|
3663 | else |
---|
3664 | DataOut=feval(transform_handle,'*'); |
---|
3665 | end |
---|
3666 | end |
---|
3667 | |
---|
3668 | set(handles.CheckFixLimits,'Value',0) |
---|
3669 | set(handles.CheckFixLimits,'BackgroundColor',[0.7 0.7 0.7]) |
---|
3670 | |
---|
3671 | %% delete drawn objects if the output CooordUnit is different from the previous one |
---|
3672 | if ~strcmp(CoordUnit,CoordUnitPrev) |
---|
3673 | hother=findobj('Tag','proj_object');%find all the proj objects |
---|
3674 | for iobj=1:length(hother) |
---|
3675 | delete_object(hother(iobj)) |
---|
3676 | end |
---|
3677 | hother=findobj('Tag','DeformPoint');%find all the proj objects |
---|
3678 | for iobj=1:length(hother) |
---|
3679 | delete_object(hother(iobj)) |
---|
3680 | end |
---|
3681 | hh=findobj('Tag','calib_points'); |
---|
3682 | if ~isempty(hh) |
---|
3683 | delete(hh) |
---|
3684 | end |
---|
3685 | hhh=findobj('Tag','calib_marker'); |
---|
3686 | if ~isempty(hhh) |
---|
3687 | delete(hhh) |
---|
3688 | end |
---|
3689 | % if isfield(UvData,'Object') |
---|
3690 | % UvData.Object=UvData.Object(1); |
---|
3691 | % end |
---|
3692 | set(handles.ListObject,'Value',1) |
---|
3693 | set(handles.ListObject,'String',{''}) |
---|
3694 | set(handles.ListObject_1,'Value',1) |
---|
3695 | set(handles.ListObject_1,'String',{''}) |
---|
3696 | set(handles.ViewObject,'value',0) |
---|
3697 | ViewObject_Callback(hObject, eventdata, handles) |
---|
3698 | set(handles.ViewField,'value',0) |
---|
3699 | ViewField_Callback(hObject, eventdata, handles) |
---|
3700 | set(handles.edit_object,'Value',0) |
---|
3701 | edit_object_Callback(hObject, eventdata, handles) |
---|
3702 | UvData.Object={[]}; |
---|
3703 | end |
---|
3704 | set(handles.uvmat,'UserData',UvData) |
---|
3705 | |
---|
3706 | %% refresh the current plot |
---|
3707 | if isempty(list_path{ichoice}) || nargin(transform_handle)<3 |
---|
3708 | set(handles.SubField,'Value',0) |
---|
3709 | SubField_Callback(hObject, eventdata, handles) |
---|
3710 | else |
---|
3711 | run0_Callback(hObject, eventdata, handles) |
---|
3712 | end |
---|
3713 | |
---|
3714 | %------------------------------------------------ |
---|
3715 | %CALLBACKS FOR PLOTTING PARAMETERS |
---|
3716 | %------------------------------------------------- |
---|
3717 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
---|
3718 | % Plot coordinates |
---|
3719 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
---|
3720 | %------------------------------------------------------------------------ |
---|
3721 | function num_MinX_Callback(hObject, eventdata, handles) |
---|
3722 | %------------------------------------------------------------------------ |
---|
3723 | set(handles.CheckFixLimits,'Value',1) %suppress auto mode |
---|
3724 | set(handles.CheckFixLimits,'BackgroundColor',[1 1 0]) |
---|
3725 | update_plot(handles); |
---|
3726 | |
---|
3727 | %------------------------------------------------------------------------ |
---|
3728 | function num_MaxX_Callback(hObject, eventdata, handles) |
---|
3729 | %------------------------------------------------------------------------ |
---|
3730 | set(handles.CheckFixLimits,'Value',1) %suppress auto mode |
---|
3731 | set(handles.CheckFixLimits,'BackgroundColor',[1 1 0]) |
---|
3732 | update_plot(handles); |
---|
3733 | |
---|
3734 | %------------------------------------------------------------------------ |
---|
3735 | function num_MinY_Callback(hObject, eventdata, handles) |
---|
3736 | %------------------------------------------ |
---|
3737 | set(handles.CheckFixLimits,'Value',1) %suppress auto mode |
---|
3738 | set(handles.CheckFixLimits,'BackgroundColor',[1 1 0]) |
---|
3739 | update_plot(handles); |
---|
3740 | |
---|
3741 | %------------------------------------------------------------------------ |
---|
3742 | function num_MaxY_Callback(hObject, eventdata, handles) |
---|
3743 | %------------------------------------------------------------------------ |
---|
3744 | set(handles.CheckFixLimits,'Value',1) %suppress auto mode |
---|
3745 | set(handles.CheckFixLimits,'BackgroundColor',[1 1 0]) |
---|
3746 | update_plot(handles); |
---|
3747 | |
---|
3748 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
---|
3749 | % Scalar or image representation |
---|
3750 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
---|
3751 | %------------------------------------------------------------------------ |
---|
3752 | function num_MinA_Callback(hObject, eventdata, handles) |
---|
3753 | %------------------------------------------ |
---|
3754 | set(handles.CheckFixScalar,'Value',1) %suppress auto mode |
---|
3755 | set(handles.CheckFixScalar,'BackgroundColor',[1 1 0]) |
---|
3756 | MinA=str2double(get(handles.num_MinA,'String')); |
---|
3757 | MaxA=str2double(get(handles.num_MaxA,'String')); |
---|
3758 | if MinA>MaxA% switch minA and maxA in case of error |
---|
3759 | MinA_old=MinA; |
---|
3760 | MinA=MaxA; |
---|
3761 | MaxA=MinA_old; |
---|
3762 | set(handles.num_MinA,'String',num2str(MinA,5)); |
---|
3763 | set(handles.num_MaxA,'String',num2str(MaxA,5)); |
---|
3764 | end |
---|
3765 | update_plot(handles); |
---|
3766 | |
---|
3767 | %------------------------------------------------------------------------ |
---|
3768 | function num_MaxA_Callback(hObject, eventdata, handles) |
---|
3769 | %------------------------------------------------------------------------ |
---|
3770 | set(handles.CheckFixScalar,'Value',1) %suppress auto mode |
---|
3771 | set(handles.CheckFixScalar,'BackgroundColor',[1 1 0]) |
---|
3772 | MinA=str2double(get(handles.num_MinA,'String')); |
---|
3773 | MaxA=str2double(get(handles.num_MaxA,'String')); |
---|
3774 | if MinA>MaxA% switch minA and maxA in case of error |
---|
3775 | MinA_old=MinA; |
---|
3776 | MinA=MaxA; |
---|
3777 | MaxA=MinA_old; |
---|
3778 | set(handles.num_MinA,'String',num2str(MinA,5)); |
---|
3779 | set(handles.num_MaxA,'String',num2str(MaxA,5)); |
---|
3780 | end |
---|
3781 | update_plot(handles); |
---|
3782 | |
---|
3783 | %------------------------------------------------------------------------ |
---|
3784 | function CheckFixScalar_Callback(hObject, eventdata, handles) |
---|
3785 | %------------------------------------------------------------------------ |
---|
3786 | test=get(handles.CheckFixScalar,'Value'); |
---|
3787 | if test |
---|
3788 | set(handles.CheckFixScalar,'BackgroundColor',[1 1 0]) |
---|
3789 | else |
---|
3790 | set(handles.CheckFixScalar,'BackgroundColor',[0.7 0.7 0.7]) |
---|
3791 | update_plot(handles); |
---|
3792 | end |
---|
3793 | |
---|
3794 | %------------------------------------------------------------------- |
---|
3795 | function CheckBW_Callback(hObject, eventdata, handles) |
---|
3796 | %------------------------------------------------------------------- |
---|
3797 | update_plot(handles); |
---|
3798 | |
---|
3799 | %------------------------------------------------------------------- |
---|
3800 | function num_Opacity_Callback(hObject, eventdata, handles) |
---|
3801 | update_plot(handles); |
---|
3802 | %------------------------------------------------------------------- |
---|
3803 | |
---|
3804 | %------------------------------------------------------------------- |
---|
3805 | function ListContour_Callback(hObject, eventdata, handles) |
---|
3806 | %------------------------------------------------------------------- |
---|
3807 | val=get(handles.ListContour,'Value'); |
---|
3808 | if val==2 |
---|
3809 | set(handles.interval_txt,'Visible','on') |
---|
3810 | set(handles.num_IncrA,'Visible','on') |
---|
3811 | else |
---|
3812 | set(handles.interval_txt,'Visible','off') |
---|
3813 | set(handles.num_IncrA,'Visible','off') |
---|
3814 | end |
---|
3815 | update_plot(handles); |
---|
3816 | |
---|
3817 | %------------------------------------------------------------------- |
---|
3818 | function num_IncrA_Callback(hObject, eventdata, handles) |
---|
3819 | %------------------------------------------------------------------- |
---|
3820 | update_plot(handles); |
---|
3821 | |
---|
3822 | |
---|
3823 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
---|
3824 | % Vector representation |
---|
3825 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
---|
3826 | %------------------------------------------------------------------- |
---|
3827 | function CheckHideWarning_Callback(hObject, eventdata, handles) |
---|
3828 | %------------------------------------------------------------------- |
---|
3829 | update_plot(handles); |
---|
3830 | |
---|
3831 | %------------------------------------------------------------------- |
---|
3832 | function CheckHideFalse_Callback(hObject, eventdata, handles) |
---|
3833 | %------------------------------------------------------------------- |
---|
3834 | update_plot(handles); |
---|
3835 | |
---|
3836 | %------------------------------------------------------------------- |
---|
3837 | function num_VecScale_Callback(hObject, eventdata, handles) |
---|
3838 | %------------------------------------------------------------------- |
---|
3839 | set(handles.CheckFixVectors,'Value',1); |
---|
3840 | set(handles.CheckFixVectors,'BackgroundColor',[1 1 0]) |
---|
3841 | update_plot(handles); |
---|
3842 | |
---|
3843 | %------------------------------------------------------------------- |
---|
3844 | function CheckFixVectors_Callback(hObject, eventdata, handles) |
---|
3845 | %------------------------------------------------------------------- |
---|
3846 | test=get(handles.CheckFixVectors,'Value'); |
---|
3847 | if test |
---|
3848 | set(handles.CheckFixVectors,'BackgroundColor',[1 1 0]) |
---|
3849 | else |
---|
3850 | update_plot(handles); |
---|
3851 | %set(handles.num_VecScale,'String',num2str(ScalOut.num_VecScale,3)) |
---|
3852 | set(handles.CheckFixVectors,'BackgroundColor',[0.7 0.7 0.7]) |
---|
3853 | end |
---|
3854 | |
---|
3855 | %------------------------------------------------------------------------ |
---|
3856 | % --- Executes on selection change in CheckDecimate4 (nb_vec/4). |
---|
3857 | function CheckDecimate4_Callback(hObject, eventdata, handles) |
---|
3858 | %------------------------------------------------------------------------ |
---|
3859 | update_plot(handles); |
---|
3860 | |
---|
3861 | %------------------------------------------------------------------------ |
---|
3862 | % --- Executes on selection change in ColorCode menu |
---|
3863 | function ColorCode_Callback(hObject, eventdata, handles) |
---|
3864 | %------------------------------------------------------------------------ |
---|
3865 | % edit the choice for color code |
---|
3866 | update_color_code_boxes(handles); |
---|
3867 | update_plot(handles); |
---|
3868 | |
---|
3869 | %------------------------------------------------------------------------ |
---|
3870 | function update_color_code_boxes(handles) |
---|
3871 | %------------------------------------------------------------------------ |
---|
3872 | list_code=get(handles.ColorCode,'String');% list menu fields |
---|
3873 | colcode= list_code{get(handles.ColorCode,'Value')}; % selected field |
---|
3874 | enable_slider='off';%default |
---|
3875 | enable_bounds='off';%default |
---|
3876 | enable_scalar='off';%default |
---|
3877 | switch colcode |
---|
3878 | case {'rgb','bgr'} |
---|
3879 | enable_slider='on'; |
---|
3880 | enable_bounds='on'; |
---|
3881 | enable_scalar='on'; |
---|
3882 | case '64 colors' |
---|
3883 | enable_bounds='on'; |
---|
3884 | enable_scalar='on'; |
---|
3885 | end |
---|
3886 | set(handles.Slider1,'Visible',enable_slider) |
---|
3887 | set(handles.Slider2,'Visible', enable_slider) |
---|
3888 | set(handles.num_ColCode1,'Visible',enable_slider) |
---|
3889 | set(handles.num_ColCode2,'Visible',enable_slider) |
---|
3890 | set(handles.TitleColCode1,'Visible',enable_slider) |
---|
3891 | set(handles.TitleColCode2,'Visible',enable_slider) |
---|
3892 | set(handles.CheckFixVecColor,'Visible',enable_bounds) |
---|
3893 | set(handles.num_MinVec,'Visible',enable_bounds) |
---|
3894 | set(handles.num_MaxVec,'Visible',enable_bounds) |
---|
3895 | set(handles.ColorScalar,'Visible',enable_scalar) |
---|
3896 | set_vec_col_bar(handles) |
---|
3897 | |
---|
3898 | %------------------------------------------------------------------ |
---|
3899 | % --- Executes on selection change in ColorScalar: choice of the color code. |
---|
3900 | function ColorScalar_Callback(hObject, eventdata, handles) |
---|
3901 | %------------------------------------------------------------------ |
---|
3902 | % edit the choice for color code |
---|
3903 | list_scalar=get(handles.ColorScalar,'String');% list menu fields |
---|
3904 | col_scalar= list_scalar{get(handles.ColorScalar,'Value')}; % selected field |
---|
3905 | if isequal(col_scalar,'ima_cor') |
---|
3906 | set(handles.CheckFixVecColor,'Value',1)%fixed scale by default |
---|
3907 | ColorCode='rgb'; |
---|
3908 | set(handles.num_MinVec,'String','0') |
---|
3909 | set(handles.num_MaxVec,'String','1') |
---|
3910 | set(handles.num_ColCode1,'String','0.333') |
---|
3911 | set(handles.num_ColCode2,'String','0.666') |
---|
3912 | else |
---|
3913 | set(handles.CheckFixVecColor,'Value',0)%auto scale between min,max by default |
---|
3914 | ColorCode='64 colors'; |
---|
3915 | end |
---|
3916 | ColorCodeList=get(handles.ColorCode,'String'); |
---|
3917 | ichoice=find(strcmp(ColorCode,ColorCodeList),1); |
---|
3918 | set(handles.ColorCode,'Value',ichoice)% set color code in the menu |
---|
3919 | |
---|
3920 | update_color_code_boxes(handles); |
---|
3921 | %replot the current graph |
---|
3922 | run0_Callback(hObject, eventdata, handles) |
---|
3923 | |
---|
3924 | %---------------------------------------------------------------- |
---|
3925 | % -- Executes on slider movement to set the color code |
---|
3926 | % |
---|
3927 | function Slider1_Callback(hObject, eventdata, handles) |
---|
3928 | %------------------------------------------------------------------ |
---|
3929 | slider1=get(handles.Slider1,'Value'); |
---|
3930 | min_val=str2num(get(handles.num_MinVec,'String')); |
---|
3931 | max_val=str2num(get(handles.num_MaxVec,'String')); |
---|
3932 | col=min_val+(max_val-min_val)*slider1; |
---|
3933 | set(handles.num_ColCode1,'String',num2str(col)) |
---|
3934 | if(get(handles.Slider2,'Value') < col)%move also the second slider at the same value if needed |
---|
3935 | set(handles.Slider2,'Value',col) |
---|
3936 | set(handles.num_ColCode2,'String',num2str(col)) |
---|
3937 | end |
---|
3938 | set_vec_col_bar(handles) |
---|
3939 | update_plot(handles); |
---|
3940 | |
---|
3941 | %---------------------------------------------------------------- |
---|
3942 | % Executes on slider movement to set the color code |
---|
3943 | %---------------------------------------------------------------- |
---|
3944 | function Slider2_Callback(hObject, eventdata, handles) |
---|
3945 | slider2=get(handles.Slider2,'Value'); |
---|
3946 | min_val=str2num(get(handles.num_MinVec,'String')); |
---|
3947 | max_val=str2num(get(handles.num_MaxVec,'String')); |
---|
3948 | col=min_val+(max_val-min_val)*slider2; |
---|
3949 | set(handles.num_ColCode2,'String',num2str(col)) |
---|
3950 | if(get(handles.Slider1,'Value') > col)%move also the first slider at the same value if needed |
---|
3951 | set(handles.Slider1,'Value',col) |
---|
3952 | set(handles.num_ColCode1,'String',num2str(col)) |
---|
3953 | end |
---|
3954 | set_vec_col_bar(handles) |
---|
3955 | update_plot(handles); |
---|
3956 | |
---|
3957 | %---------------------------------------------------------------- |
---|
3958 | % --- Execute on return carriage on the edit box corresponding to slider 1 |
---|
3959 | %---------------------------------------------------------------- |
---|
3960 | function num_ColCode1_Callback(hObject, eventdata, handles) |
---|
3961 | set_vec_col_bar(handles) |
---|
3962 | update_plot(handles); |
---|
3963 | |
---|
3964 | %---------------------------------------------------------------- |
---|
3965 | % --- Execute on return carriage on the edit box corresponding to slider 2 |
---|
3966 | %---------------------------------------------------------------- |
---|
3967 | function num_ColCode2_Callback(hObject, eventdata, handles) |
---|
3968 | set_vec_col_bar(handles) |
---|
3969 | update_plot(handles); |
---|
3970 | %------------------------------------------------------------------------ |
---|
3971 | %------------------------------------------------------- |
---|
3972 | % --- Executes on button press in CheckFixVecColor. |
---|
3973 | %------------------------------------------------------- |
---|
3974 | function VecColBar_Callback(hObject, eventdata, handles) |
---|
3975 | set_vec_col_bar(handles) |
---|
3976 | |
---|
3977 | %------------------------------------------------------------------------ |
---|
3978 | % --- Executes on button press in CheckFixVecColor. |
---|
3979 | function CheckFixVecColor_Callback(hObject, eventdata, handles) |
---|
3980 | %------------------------------------------------------------------------ |
---|
3981 | if ~get(handles.CheckFixVecColor,'Value') |
---|
3982 | update_plot(handles); |
---|
3983 | end |
---|
3984 | |
---|
3985 | %------------------------------------------------------------------------ |
---|
3986 | % --- Executes on selection change in num_MaxVec. |
---|
3987 | function num_MinVec_Callback(hObject, eventdata, handles) |
---|
3988 | %------------------------------------------------------------------------ |
---|
3989 | max_vec_Callback(hObject, eventdata, handles) |
---|
3990 | |
---|
3991 | %------------------------------------------------------------------------ |
---|
3992 | % --- Executes on selection change in num_MaxVec. |
---|
3993 | function num_MaxVec_Callback(hObject, eventdata, handles) |
---|
3994 | %------------------------------------------------------------------------ |
---|
3995 | set(handles.CheckFixVecColor,'Value',1) |
---|
3996 | CheckFixVecColor_Callback(hObject, eventdata, handles) |
---|
3997 | min_val=str2num(get(handles.num_MinVec,'String')); |
---|
3998 | max_val=str2num(get(handles.num_MaxVec,'String')); |
---|
3999 | slider1=get(handles.Slider1,'Value'); |
---|
4000 | slider2=get(handles.Slider2,'Value'); |
---|
4001 | colcode1=min_val+(max_val-min_val)*slider1; |
---|
4002 | colcode2=min_val+(max_val-min_val)*slider2; |
---|
4003 | set(handles.num_ColCode1,'String',num2str(colcode1)) |
---|
4004 | set(handles.num_ColCode2,'String',num2str(colcode2)) |
---|
4005 | update_plot(handles); |
---|
4006 | |
---|
4007 | %------------------------------------------------------------------------ |
---|
4008 | % --- update the display of color code for vectors (on vecColBar) |
---|
4009 | function set_vec_col_bar(handles) |
---|
4010 | %------------------------------------------------------------------------ |
---|
4011 | %get the image of the color display button 'VecColBar' in pixels |
---|
4012 | set(handles.VecColBar,'Unit','pixel'); |
---|
4013 | pos_vert=get(handles.VecColBar,'Position'); |
---|
4014 | set(handles.VecColBar,'Unit','Normalized'); |
---|
4015 | width=ceil(pos_vert(3)); |
---|
4016 | height=ceil(pos_vert(4)); |
---|
4017 | |
---|
4018 | %get slider indications |
---|
4019 | list=get(handles.ColorCode,'String'); |
---|
4020 | ichoice=get(handles.ColorCode,'Value'); |
---|
4021 | colcode.ColorCode=list{ichoice}; |
---|
4022 | colcode.MinVec=str2num(get(handles.num_MinVec,'String')); |
---|
4023 | colcode.MaxVec=str2num(get(handles.num_MaxVec,'String')); |
---|
4024 | test3color=strcmp(colcode.ColorCode,'rgb') || strcmp(colcode.ColorCode,'bgr'); |
---|
4025 | if test3color |
---|
4026 | colcode.ColCode1=str2num(get(handles.num_ColCode1,'String')); |
---|
4027 | colcode.ColCode2=str2num(get(handles.num_ColCode2,'String')); |
---|
4028 | end |
---|
4029 | vec_C=colcode.MinVec+(colcode.MaxVec-colcode.MinVec)*(0.5:width-0.5)/width;%sample of vec_C values from min to max |
---|
4030 | [colorlist,col_vec]=set_col_vec(colcode,vec_C); |
---|
4031 | oneheight=ones(1,height); |
---|
4032 | A1=colorlist(col_vec,1)*oneheight; |
---|
4033 | A2=colorlist(col_vec,2)*oneheight; |
---|
4034 | A3=colorlist(col_vec,3)*oneheight; |
---|
4035 | A(:,:,1)=A1'; |
---|
4036 | A(:,:,2)=A2'; |
---|
4037 | A(:,:,3)=A3'; |
---|
4038 | set(handles.VecColBar,'Cdata',A) |
---|
4039 | |
---|
4040 | %------------------------------------------------------------------- |
---|
4041 | function update_plot(handles) |
---|
4042 | %------------------------------------------------------------------- |
---|
4043 | UvData=get(handles.uvmat,'UserData'); |
---|
4044 | AxeData=UvData.PlotAxes;% retrieve the current plotted data |
---|
4045 | PlotParam=read_GUI(handles.uvmat); |
---|
4046 | [tild,PlotParamOut]= plot_field(AxeData,handles.PlotAxes,PlotParam); |
---|
4047 | write_plot_param(handles,PlotParamOut); %update the auto plot parameters |
---|
4048 | |
---|
4049 | %------------------------------------------------------------------------ |
---|
4050 | %------------------------------------------------------------------------ |
---|
4051 | % SELECTION AND EDITION OF PROJECTION OBJECTS |
---|
4052 | %------------------------------------------------------------------------ |
---|
4053 | %------------------------------------------------------------------------ |
---|
4054 | |
---|
4055 | % --- Executes on selection change in ListObject_1. |
---|
4056 | function ListObject_1_Callback(hObject, eventdata, handles) |
---|
4057 | list_str=get(handles.ListObject,'String'); |
---|
4058 | UvData=get(handles.uvmat,'UserData'); |
---|
4059 | ObjectData=UvData.Object{get(handles.ListObject_1,'Value')}; |
---|
4060 | |
---|
4061 | %% update the projection plot on uvmat |
---|
4062 | ProjData= proj_field(UvData.Field,ObjectData);%project the current input field on object ObjectData |
---|
4063 | plot_field(ProjData,handles.PlotAxes,read_GUI(handles.uvmat));% plot the projected field; |
---|
4064 | %replot all the objects within the new projected field |
---|
4065 | for IndexObj=1:numel(list_str) |
---|
4066 | hobject=UvData.Object{IndexObj}.DisplayHandle.uvmat; |
---|
4067 | if isempty(hobject) || ~ishandle(hobject) |
---|
4068 | hobject=handles.PlotAxes; |
---|
4069 | end |
---|
4070 | if isequal(IndexObj,get(handles.ListObject,'Value')) |
---|
4071 | objectcolor='m'; %paint in magenta the currently selected object in ListObject |
---|
4072 | else |
---|
4073 | objectcolor='b'; |
---|
4074 | end |
---|
4075 | UvData.Object{IndexObj}.DisplayHandle.uvmat=plot_object(UvData.Object{IndexObj},ObjectData,hobject,objectcolor);%draw the object in uvmat |
---|
4076 | end |
---|
4077 | set(handles.uvmat,'UserData',UvData) |
---|
4078 | |
---|
4079 | %% display the object parameters if the GUI set_object is already opened |
---|
4080 | if ~get(handles.ViewObject,'Value') |
---|
4081 | ZBounds=0; % default |
---|
4082 | if isfield(UvData.Field,'ZMin') && isfield(UvData.Field,'ZMax') |
---|
4083 | ZBounds(1)=UvData.Field.ZMin; %minimum for the Z slider |
---|
4084 | ZBounds(2)=UvData.Field.ZMax;%maximum for the Z slider |
---|
4085 | end |
---|
4086 | ObjectData.Name=list_str{get(handles.ListObject_1,'Value')}; |
---|
4087 | set_object(ObjectData,[],ZBounds); |
---|
4088 | set(handles.ViewObject,'Value',1)% show that the selected object in ListObject_1 is currently visualised |
---|
4089 | end |
---|
4090 | |
---|
4091 | % desactivate the edit object mode |
---|
4092 | set(handles.edit_object,'Value',0) |
---|
4093 | set(handles.edit_object,'BackgroundColor',[0.7,0.7,0.7]) |
---|
4094 | |
---|
4095 | %------------------------------------------------------------------------ |
---|
4096 | % --- Executes on selection change in ListObject. |
---|
4097 | function ListObject_Callback(hObject, eventdata, handles) |
---|
4098 | %------------------------------------------------------------------------ |
---|
4099 | list_str=get(handles.ListObject,'String'); |
---|
4100 | IndexObj=get(handles.ListObject,'Value');%present object selection |
---|
4101 | |
---|
4102 | %% The object is displayed in set_object if this GUI is already opened |
---|
4103 | UvData=get(handles.uvmat,'UserData'); |
---|
4104 | ObjectData=UvData.Object{IndexObj}; |
---|
4105 | hset_object=findobj(allchild(0),'tag','set_object'); |
---|
4106 | if ~isempty(hset_object) |
---|
4107 | ZBounds=0; % default |
---|
4108 | if isfield(UvData.Field,'ZMin') && isfield(UvData.Field,'ZMax') |
---|
4109 | ZBounds(1)=UvData.Field.ZMin; %minimum for the Z slider |
---|
4110 | ZBounds(2)=UvData.Field.ZMax;%maximum for the Z slider |
---|
4111 | end |
---|
4112 | ObjectData.Name=list_str{IndexObj}; |
---|
4113 | set_object(ObjectData,[],ZBounds); |
---|
4114 | set(handles.ViewField,'Value',1)% show that the selected object in ListObject is currently visualised |
---|
4115 | end |
---|
4116 | |
---|
4117 | %% desactivate the edit object mode |
---|
4118 | set(handles.edit_object,'Value',0) |
---|
4119 | set(handles.edit_object,'BackgroundColor',[0.7,0.7,0.7]) |
---|
4120 | |
---|
4121 | %% update the plot on view_field if view_field is already openened |
---|
4122 | hview_field=findobj(allchild(0),'tag','view_field'); |
---|
4123 | if isempty(hview_field) |
---|
4124 | hhview_field.PlotAxes=[]; |
---|
4125 | else |
---|
4126 | Data=get(hview_field,'UserData'); |
---|
4127 | hhview_field=guidata(hview_field); |
---|
4128 | ProjData= proj_field(UvData.Field,ObjectData);%project the current interface field on ObjectData |
---|
4129 | [PlotType,PlotParam]=plot_field(ProjData,hhview_field.PlotAxes,read_GUI(hview_field));%read plotting parameters on the uvmat interfachhview_fiel |
---|
4130 | write_plot_param(hhview_field,PlotParam); %update the display of plotting parameters for the current object |
---|
4131 | haxes=findobj(hview_field,'tag','axes3'); |
---|
4132 | pos=get(hview_field,'Position'); |
---|
4133 | if strcmp(get(haxes,'Visible'),'off')%sempty(PlotParam.Coordinates)% case of no plot display (pure text table) |
---|
4134 | h_TableDisplay=findobj(hview_field,'tag','TableDisplay'); |
---|
4135 | pos_table=get(h_TableDisplay,'Position'); |
---|
4136 | set(hview_field,'Position',[pos(1)+pos(3)-pos_table(3) pos(2)+pos(4)-pos_table(4) pos_table(3) pos_table(4)]) |
---|
4137 | drawnow% needed to change position before the next command |
---|
4138 | set(hview_field,'UserData',Data);% restore the previously stored GUI position after GUI resizing |
---|
4139 | else |
---|
4140 | set(hview_field,'Position',Data.GUISize)% return to the previously stored GUI position and size |
---|
4141 | end |
---|
4142 | end |
---|
4143 | |
---|
4144 | %% update the color of the graphic object representation: the selected object in magenta, others in blue |
---|
4145 | update_object_color(handles.PlotAxes,hhview_field.PlotAxes,UvData.Object{IndexObj}.DisplayHandle.uvmat) |
---|
4146 | |
---|
4147 | %------------------------------------------------------------------------ |
---|
4148 | %--- update the color representation of objects (indicating the selected ones) |
---|
4149 | function update_object_color(axes_uvmat,axes_view_field,DisplayHandle) |
---|
4150 | %------------------------------------------------------------------------ |
---|
4151 | if isempty(axes_view_field)% case with no view_field plot |
---|
4152 | hother=[findobj(axes_uvmat,'Tag','proj_object');findobj(axes_uvmat,'Tag','DeformPoint')];%find all the proj object and deform point representations |
---|
4153 | else |
---|
4154 | hother=[findobj(axes_uvmat,'Tag','proj_object') ;findobj(axes_view_field,'Tag','proj_object');... %find all the proj object representations |
---|
4155 | findobj(axes_uvmat,'Tag','DeformPoint'); findobj(axes_view_field,'Tag','DeformPoint')];%find all the deform point representations |
---|
4156 | end |
---|
4157 | for iobj=1:length(hother) |
---|
4158 | if isequal(get(hother(iobj),'Type'),'rectangle')||isequal(get(hother(iobj),'Type'),'patch') |
---|
4159 | set(hother(iobj),'EdgeColor','b') |
---|
4160 | if isequal(get(hother(iobj),'FaceColor'),'m') |
---|
4161 | set(hother(iobj),'FaceColor','b') |
---|
4162 | end |
---|
4163 | elseif isequal(get(hother(iobj),'Type'),'image') |
---|
4164 | Acolor=get(hother(iobj),'CData'); |
---|
4165 | Acolor(:,:,1)=zeros(size(Acolor,1),size(Acolor,2)); |
---|
4166 | set(hother(iobj),'CData',Acolor); |
---|
4167 | else |
---|
4168 | set(hother(iobj),'Color','b') |
---|
4169 | end |
---|
4170 | set(hother(iobj),'Selected','off') |
---|
4171 | end |
---|
4172 | if ishandle(DisplayHandle) |
---|
4173 | linetype=get(DisplayHandle,'Type'); |
---|
4174 | if isequal(linetype,'line') |
---|
4175 | set(DisplayHandle,'Color','m'); %set the selected object to magenta color |
---|
4176 | elseif isequal(linetype,'rectangle') |
---|
4177 | set(DisplayHandle,'EdgeColor','m'); %set the selected object to magenta color |
---|
4178 | elseif isequal(linetype,'patch') |
---|
4179 | set(DisplayHandle,'FaceColor','m'); %set the selected object to magenta color |
---|
4180 | end |
---|
4181 | SubObjectData=get(DisplayHandle,'UserData'); |
---|
4182 | if isfield(SubObjectData,'SubObject') & ishandle(SubObjectData.SubObject) |
---|
4183 | for iobj=1:length(SubObjectData.SubObject) |
---|
4184 | hsub=SubObjectData.SubObject(iobj); |
---|
4185 | if isequal(get(hsub,'Type'),'rectangle') |
---|
4186 | set(hsub,'EdgeColor','m'); %set the selected object to magenta color |
---|
4187 | elseif isequal(get(hsub,'Type'),'image') |
---|
4188 | Acolor=get(hsub,'CData'); |
---|
4189 | Acolor(:,:,1)=Acolor(:,:,3); |
---|
4190 | set(hsub,'CData',Acolor); |
---|
4191 | else |
---|
4192 | set(hsub,'Color','m') |
---|
4193 | end |
---|
4194 | end |
---|
4195 | end |
---|
4196 | if isfield(SubObjectData,'DeformPoint') & ishandle(SubObjectData.DeformPoint) |
---|
4197 | set(SubObjectData.DeformPoint,'Color','m') |
---|
4198 | end |
---|
4199 | end |
---|
4200 | |
---|
4201 | %------------------------------------------------------------------- |
---|
4202 | % --- Executes on selection change in edit_object. |
---|
4203 | function edit_object_Callback(hObject, eventdata, handles) |
---|
4204 | %------------------------------------------------------------------- |
---|
4205 | UvData=get(handles.uvmat,'UserData');%read UvData properties stored on the uvmat interface |
---|
4206 | hset_object=findobj(allchild(0),'Tag','set_object'); |
---|
4207 | if get(handles.edit_object,'Value') |
---|
4208 | set(handles.edit_object,'BackgroundColor',[1,1,0]) |
---|
4209 | %suppress the other options |
---|
4210 | set(handles.CheckZoom,'Value',0) |
---|
4211 | CheckZoom_Callback(hObject, eventdata, handles) |
---|
4212 | hgeometry_calib=findobj(allchild(0),'tag','geometry_calib'); |
---|
4213 | if ishandle(hgeometry_calib) |
---|
4214 | hhgeometry_calib=guidata(hgeometry_calib); |
---|
4215 | set(hhgeometry_calib.edit_append,'Value',0)% desactivate mouse action in geometry_calib |
---|
4216 | set(hhgeometry_calib.edit_append,'BackgroundColor',[0.7 0.7 0.7]) |
---|
4217 | end |
---|
4218 | set(handles.ViewObject,'value',1) |
---|
4219 | ViewObject_Callback(hObject, eventdata, handles) |
---|
4220 | else % desctivate object edit mode |
---|
4221 | set(handles.edit_object,'BackgroundColor',[0.7,0.7,0.7]) |
---|
4222 | if ~isempty(hset_object)% open the |
---|
4223 | hhset_object=guidata(hset_object); |
---|
4224 | set(hhset_object.PLOT,'enable','off'); |
---|
4225 | set(get(hset_object,'children'),'enable','inactive') |
---|
4226 | end |
---|
4227 | end |
---|
4228 | |
---|
4229 | |
---|
4230 | %------------------------------------------------------------------------ |
---|
4231 | % --- Executes on button press in ViewObject. |
---|
4232 | function ViewObject_Callback(hObject, eventdata, handles) |
---|
4233 | %------------------------------------------------------------------------ |
---|
4234 | check_view=get(handles.ViewObject,'Value'); |
---|
4235 | |
---|
4236 | if check_view %activate set_object |
---|
4237 | IndexObj=get(handles.ListObject,'Value'); |
---|
4238 | list_object=get(handles.ListObject,'String'); |
---|
4239 | UvData=get(handles.uvmat,'UserData');%read UvData properties stored on the uvmat interface |
---|
4240 | UvData.Object{IndexObj}.Name=list_object{IndexObj}; |
---|
4241 | if numel(UvData.Object)<IndexObj;% error in UvData |
---|
4242 | msgbox_uvmat('ERROR','invalid object list') |
---|
4243 | return |
---|
4244 | end |
---|
4245 | ZBounds=0; % default |
---|
4246 | if isfield(UvData.Field,'ZMin') && isfield(UvData.Field,'ZMax') |
---|
4247 | ZBounds(1)=UvData.Field.ZMin; %minimum for the Z slider |
---|
4248 | ZBounds(2)=UvData.Field.ZMax;%maximum for the Z slider |
---|
4249 | end |
---|
4250 | % set(handles.ListObject_1,'Value',IndexObj);%restore ListObject selection after set_object deletion |
---|
4251 | data=UvData.Object{IndexObj}; |
---|
4252 | if ~isfield(data,'Type')% default plane |
---|
4253 | data.Type='plane'; |
---|
4254 | end |
---|
4255 | % if isfield(UvData,'Field') |
---|
4256 | % Field=UvData.Field; |
---|
4257 | % if isfield(UvData.Field,'Mesh')&&~isempty(UvData.Field.Mesh) |
---|
4258 | % data.RangeX=[UvData.Field.XMin UvData.Field.XMax]; |
---|
4259 | % if strcmp(data.Type,'line')||strcmp(data.Type,'polyline') |
---|
4260 | % data.RangeY=UvData.Field.Mesh; |
---|
4261 | % else |
---|
4262 | % data.RangeY=[UvData.Field.YMin UvData.Field.YMax]; |
---|
4263 | % end |
---|
4264 | % data.DX=UvData.Field.Mesh; |
---|
4265 | % data.DY=UvData.Field.Mesh; |
---|
4266 | % end |
---|
4267 | % if isfield(Field,'NbDim')&& isequal(Field.NbDim,3) |
---|
4268 | % data.Coord=[0 0 0]; %default |
---|
4269 | % end |
---|
4270 | % if isfield(Field,'CoordUnit') |
---|
4271 | % data.CoordUnit=Field.CoordUnit; |
---|
4272 | % end |
---|
4273 | % end |
---|
4274 | hset_object=set_object(data,[],ZBounds); |
---|
4275 | hhset_object=guidata(hset_object); |
---|
4276 | if get(handles.edit_object,'Value')% edit mode |
---|
4277 | set(hhset_object.PLOT,'Enable','on') |
---|
4278 | set(get(hset_object,'children'),'enable','on') |
---|
4279 | else |
---|
4280 | set(hhset_object.PLOT,'Enable','off') |
---|
4281 | set(get(hset_object,'children'),'enable','inactive')% deactivate the GUI except SAVE |
---|
4282 | set(hhset_object.SAVE,'Enable','on') |
---|
4283 | end |
---|
4284 | else |
---|
4285 | hset_object=findobj(allchild(0),'tag','set_object'); |
---|
4286 | if ~isempty(hset_object) |
---|
4287 | delete(hset_object)% delete existing version of set_object |
---|
4288 | end |
---|
4289 | end |
---|
4290 | |
---|
4291 | |
---|
4292 | %------------------------------------------------------------------------ |
---|
4293 | % --- Executes on button press in ViewField. |
---|
4294 | function ViewField_Callback(hObject, eventdata, handles) |
---|
4295 | %------------------------------------------------------------------------ |
---|
4296 | check_view=get(handles.ViewField,'Value'); |
---|
4297 | |
---|
4298 | if check_view |
---|
4299 | IndexObj=get(handles.ListObject,'Value'); |
---|
4300 | UvData=get(handles.uvmat,'UserData');%read UvData properties stored on the uvmat interface |
---|
4301 | if numel(UvData.Object)<IndexObj(end);% error in UvData |
---|
4302 | msgbox_uvmat('ERROR','invalid object list') |
---|
4303 | return |
---|
4304 | end |
---|
4305 | ZBounds=0; % default |
---|
4306 | if isfield(UvData.Field,'ZMin') && isfield(UvData.Field,'ZMax') |
---|
4307 | ZBounds(1)=UvData.Field.ZMin; %minimum for the Z slider |
---|
4308 | ZBounds(2)=UvData.Field.ZMax;%maximum for the Z slider |
---|
4309 | end |
---|
4310 | set(handles.ListObject,'Value',IndexObj);%restore ListObject selection after set_object deletion |
---|
4311 | if ~isfield(UvData.Object{IndexObj(1)},'Type')% default plane |
---|
4312 | UvData.Object{IndexObj(1)}.Type='plane'; |
---|
4313 | end |
---|
4314 | list_object=get(handles.ListObject,'String'); |
---|
4315 | UvData.Object{IndexObj(end)}.Name=list_object{IndexObj(end)}; |
---|
4316 | |
---|
4317 | %% show the projection of the selected object on view_field |
---|
4318 | ProjData= proj_field(UvData.Field,UvData.Object{IndexObj});%project the current field on ObjectData |
---|
4319 | hview_field=findobj(allchild(0),'tag','view_field'); |
---|
4320 | if isempty(hview_field) |
---|
4321 | hview_field=view_field; |
---|
4322 | end |
---|
4323 | hhview_field=guidata(hview_field); |
---|
4324 | [PlotType,PlotParam]=plot_field(ProjData,hhview_field.PlotAxes,read_GUI(hview_field));%read plotting parameters on the GUI view_field); |
---|
4325 | write_plot_param(hhview_field,PlotParam); %update the display of plotting parameters for the current object |
---|
4326 | haxes=findobj(hview_field,'tag','axes3'); |
---|
4327 | pos=get(hview_field,'Position'); |
---|
4328 | if strcmp(get(haxes,'Visible'),'off')%sempty(PlotParam.Coordinates)% case of no plot display (pure text table) |
---|
4329 | h_TableDisplay=findobj(hview_field,'tag','TableDisplay'); |
---|
4330 | pos_table=get(h_TableDisplay,'Position'); |
---|
4331 | set(hview_field,'Position',[pos(1)+pos(3)-pos_table(3) pos(2)+pos(4)-pos_table(4) pos_table(3) pos_table(4)]) |
---|
4332 | else |
---|
4333 | Data=get(hview_field,'UserData'); |
---|
4334 | set(hview_field,'Position',Data.GUISize)% restore the size of view_field for plots |
---|
4335 | end |
---|
4336 | else |
---|
4337 | hview_field=findobj(allchild(0),'tag','view_field'); |
---|
4338 | if ~isempty(hview_field) |
---|
4339 | delete(hview_field)% delete existing version of set_object |
---|
4340 | end |
---|
4341 | end |
---|
4342 | |
---|
4343 | |
---|
4344 | %------------------------------------------------------------------------ |
---|
4345 | % --- Executes on button press in delete_object. |
---|
4346 | function delete_object_Callback(hObject, eventdata, handles) |
---|
4347 | %------------------------------------------------------------------------ |
---|
4348 | IndexObj=get(handles.ListObject,'Value');%projection object selected for view_field |
---|
4349 | IndexObj_1=get(handles.ListObject_1,'Value');%projection object selected for uvmat plot |
---|
4350 | if IndexObj>1 && ~isequal(IndexObj,IndexObj_1) % do not delete the object used for the uvmat plot |
---|
4351 | delete_object(IndexObj) |
---|
4352 | end |
---|
4353 | |
---|
4354 | %------------------------------------------------------------------------ |
---|
4355 | %------------------------------------------------------------------------ |
---|
4356 | % II - TOOLS FROM THE UPPER MENU BAR |
---|
4357 | %------------------------------------------------------------------------ |
---|
4358 | %------------------------------------------------------------------------ |
---|
4359 | |
---|
4360 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
---|
4361 | % Export Menu Callbacks |
---|
4362 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
---|
4363 | %------------------------------------------------------------------------ |
---|
4364 | % --- Executes on button press in Menu/Export/field in workspace. |
---|
4365 | function MenuExportField_Callback(hObject, eventdata, handles) |
---|
4366 | %------------------------------------------------------------------------ |
---|
4367 | global Data_uvmat |
---|
4368 | Data_uvmat=get(handles.uvmat,'UserData'); |
---|
4369 | evalin('base','global Data_uvmat')%make CurData global in the workspace |
---|
4370 | display('current field :') |
---|
4371 | evalin('base','Data_uvmat') %display CurData in the workspace |
---|
4372 | commandwindow; %brings the Matlab command window to the front |
---|
4373 | |
---|
4374 | %------------------------------------------------------------------------ |
---|
4375 | % --- Executes on button press in Menu/Export/extract figure. |
---|
4376 | function MenuExportFigure_Callback(hObject, eventdata, handles) |
---|
4377 | %------------------------------------------------------------------------ |
---|
4378 | % huvmat=get(handles.MenuExport,'parent'); |
---|
4379 | hfig=figure; |
---|
4380 | copyobj(handles.PlotAxes,hfig); |
---|
4381 | map=colormap(handles.PlotAxes); |
---|
4382 | colormap(map);%transmit the current colormap to the zoom fig |
---|
4383 | colorbar |
---|
4384 | |
---|
4385 | % -------------------------------------------------------------------- |
---|
4386 | function MenuExportAxis_Callback(hObject, eventdata, handles) |
---|
4387 | answer=msgbox_uvmat('CONFIRMATION','select a figure/axis on which the current uvmat plot will be exported') |
---|
4388 | if strcmp(answer,'Yes') |
---|
4389 | hchild=get(handles.PlotAxes,'children'); |
---|
4390 | copyobj(hchild,gca); |
---|
4391 | end |
---|
4392 | |
---|
4393 | %------------------------------------------------------------------------ |
---|
4394 | % -------------------------------------------------------------------- |
---|
4395 | function MenuExportMovie_Callback(hObject, eventdata, handles) |
---|
4396 | % -------------------------------------------------------------------- |
---|
4397 | set(handles.MenuExportMovie,'BusyAction','queue')% activate the button |
---|
4398 | huvmat=get(handles.run0,'parent'); |
---|
4399 | UvData=get(huvmat,'UserData'); |
---|
4400 | %[xx,xx,FileBase]=read_file_boxes(handles); |
---|
4401 | [RootPath,SubDir,RootFile,FileIndex,FileExt]=read_file_boxes(handles); |
---|
4402 | FileBase=fullfile(RootPath,RootFile); |
---|
4403 | %read the current input file name |
---|
4404 | prompt = {'movie file name';'frames per second';'frame resolution (*[512x384] pixels)';'axis position relative to the frame';'total frame number (starting from the current uvmat display)'}; |
---|
4405 | dlg_title = 'select properties of the output avi movie'; |
---|
4406 | num_lines= 1; |
---|
4407 | def = {[FileBase '_out.avi'];'10';'1';'[0.03 0.05 0.95 0.92]';'10'}; |
---|
4408 | answer = inputdlg(prompt,dlg_title,num_lines,def,'on'); |
---|
4409 | aviname=answer{1}; |
---|
4410 | fps=str2double(answer{2}); |
---|
4411 | % check for existing file with output name aviname |
---|
4412 | if exist(aviname,'file') |
---|
4413 | backup=aviname; |
---|
4414 | testexist=2; |
---|
4415 | while testexist==2 |
---|
4416 | backup=[backup '~']; |
---|
4417 | testexist=exist(backup,'file'); |
---|
4418 | end |
---|
4419 | [success,message]=copyfile(aviname,backup);%make backup of the existing file |
---|
4420 | if isequal(success,1) |
---|
4421 | delete(aviname)%delete existing file |
---|
4422 | else |
---|
4423 | msgbox_uvmat('ERROR',message) |
---|
4424 | return |
---|
4425 | end |
---|
4426 | end |
---|
4427 | %create avi open |
---|
4428 | aviobj=avifile(aviname,'Compression','None','fps',fps); |
---|
4429 | |
---|
4430 | %display first view for tests |
---|
4431 | newfig=figure; |
---|
4432 | newaxes=copyobj(handles.PlotAxes,newfig);%new plotting axes in the new figure |
---|
4433 | set(newaxes,'Tag','movieaxes') |
---|
4434 | nbpix=[512 384]*str2double(answer{3}); |
---|
4435 | set(gcf,'Position',[1 1 nbpix])% resolution XVGA |
---|
4436 | set(newaxes,'Position',eval(answer{4})); |
---|
4437 | map=colormap(handles.PlotAxes); |
---|
4438 | colormap(map);%transmit the current colormap to the zoom fig |
---|
4439 | msgbox_uvmat('INPUT_Y-N',{['adjust figure ' num2str(newfig) ' with its matlab edit menu '] ;... |
---|
4440 | ['then press OK to get the avi movie as a copy of figure ' num2str(newfig) ' display']}); |
---|
4441 | UvData.plotaxes=newaxes;% the axis in the new figure becomes the current main plotting axes |
---|
4442 | set(huvmat,'UserData',UvData); |
---|
4443 | increment=str2num(get(handles.num_IndexIncrement,'String')); %get the field increment d |
---|
4444 | set(handles.STOP,'Visible','on') |
---|
4445 | set(handles.speed,'Visible','on') |
---|
4446 | set(handles.speed_txt,'Visible','on') |
---|
4447 | set(handles.Movie,'BusyAction','queue') |
---|
4448 | |
---|
4449 | %imin=str2double(get(handles.i1,'String')); |
---|
4450 | imax=str2double(answer{5}); |
---|
4451 | % if isfield(UvData,'Time') |
---|
4452 | htitle=get(newaxes,'Title'); |
---|
4453 | xlim=get(newaxes,'XLim'); |
---|
4454 | ylim=get(newaxes,'YLim'); |
---|
4455 | set(htitle,'Position',[xlim(2)+0.07*(xlim(2)-xlim(1)) ylim(2)-0.05*(ylim(2)-ylim(1)) 0]) |
---|
4456 | time_str=get(handles.abs_time,'String'); |
---|
4457 | set(htitle,'String',['t=' time_str]) |
---|
4458 | set(handles.speed,'Value',1) |
---|
4459 | for i=1:imax |
---|
4460 | if get(handles.speed,'Value')~=0 && isequal(get(handles.MenuExportMovie,'BusyAction'),'queue') % enable STOP command |
---|
4461 | runpm(hObject,eventdata,handles,increment)% run plus |
---|
4462 | drawnow |
---|
4463 | time_str=get(handles.abs_time,'String'); |
---|
4464 | if ishandle(htitle) |
---|
4465 | set(htitle,'String',['t=' time_str]) |
---|
4466 | end |
---|
4467 | mov=getframe(newfig); |
---|
4468 | aviobj=addframe(aviobj,mov); |
---|
4469 | end |
---|
4470 | end |
---|
4471 | aviobj=close(aviobj); |
---|
4472 | UvData=rmfield(UvData,'plotaxes'); |
---|
4473 | %UvData.Object{1}.plotaxes=handles.PlotAxes; |
---|
4474 | set(huvmat,'UserData',UvData); |
---|
4475 | msgbox_uvmat('CONFIRMATION',{['movie ' aviname ' created '];['with ' num2str(imax) ' frames']}) |
---|
4476 | |
---|
4477 | |
---|
4478 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
---|
4479 | % Projection Objects Menu Callbacks |
---|
4480 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
---|
4481 | |
---|
4482 | % ----------------------------------------------------------------------- |
---|
4483 | function Menupoints_Callback(hObject, eventdata, handles) |
---|
4484 | %------------------------------------------------------------------------ |
---|
4485 | data.Type='points'; |
---|
4486 | data.ProjMode='projection';%default |
---|
4487 | data.ProjModeMenu={};% do not restrict ProjMode menus |
---|
4488 | create_object(data,handles) |
---|
4489 | |
---|
4490 | % ----------------------------------------------------------------------- |
---|
4491 | function Menuline_Callback(hObject, eventdata, handles) |
---|
4492 | %------------------------------------------------------------------------ |
---|
4493 | data.Type='line'; |
---|
4494 | data.ProjMode='projection';%default |
---|
4495 | data.ProjModeMenu={};% do not restrict ProjMode menus |
---|
4496 | create_object(data,handles) |
---|
4497 | |
---|
4498 | %------------------------------------------------------------------------ |
---|
4499 | function Menupolyline_Callback(hObject, eventdata, handles) |
---|
4500 | %------------------------------------------------------------------------ |
---|
4501 | data.Type='polyline'; |
---|
4502 | data.ProjMode='projection';%default |
---|
4503 | data.ProjModeMenu={};% do not restrict ProjMode menus |
---|
4504 | create_object(data,handles) |
---|
4505 | |
---|
4506 | %------------------------------------------------------------------------ |
---|
4507 | function Menupolygon_Callback(hObject, eventdata, handles) |
---|
4508 | %------------------------------------------------------------------------ |
---|
4509 | data.Type='polygon'; |
---|
4510 | data.ProjMode='inside';%default |
---|
4511 | data.ProjModeMenu={};% do not restrict ProjMode menus |
---|
4512 | create_object(data,handles) |
---|
4513 | |
---|
4514 | %------------------------------------------------------------------------ |
---|
4515 | function Menurectangle_Callback(hObject, eventdata, handles) |
---|
4516 | %------------------------------------------------------------------------ |
---|
4517 | data.Type='rectangle'; |
---|
4518 | data.ProjMode='inside';%default |
---|
4519 | data.ProjModeMenu={};% do not restrict ProjMode menus |
---|
4520 | create_object(data,handles) |
---|
4521 | |
---|
4522 | %------------------------------------------------------------------------ |
---|
4523 | function Menuellipse_Callback(hObject, eventdata, handles) |
---|
4524 | %------------------------------------------------------------------------ |
---|
4525 | data.Type='ellipse'; |
---|
4526 | data.ProjMode='inside';%default |
---|
4527 | data.ProjModeMenu={};% do not restrict ProjMode menus |
---|
4528 | create_object(data,handles) |
---|
4529 | |
---|
4530 | %------------------------------------------------------------------------ |
---|
4531 | function MenuMaskObject_Callback(hObject, eventdata, handles) |
---|
4532 | %------------------------------------------------------------------------ |
---|
4533 | data.Type='polygon'; |
---|
4534 | data.TypeMenu={'polygon'}; |
---|
4535 | data.ProjMode='mask_inside';%default |
---|
4536 | data.ProjModeMenu={'mask_inside';'mask_outside'}; |
---|
4537 | create_object(data,handles) |
---|
4538 | |
---|
4539 | %------------------------------------------------------------------------ |
---|
4540 | function Menuplane_Callback(hObject, eventdata, handles) |
---|
4541 | %------------------------------------------------------------------------ |
---|
4542 | data.Type='plane'; |
---|
4543 | data.ProjMode='projection';%default |
---|
4544 | data.ProjModeMenu={};% do not restrict ProjMode menus |
---|
4545 | create_object(data,handles) |
---|
4546 | |
---|
4547 | %------------------------------------------------------------------------ |
---|
4548 | function Menuvolume_Callback(hObject, eventdata, handles) |
---|
4549 | %------------------------------------------------------------------------ |
---|
4550 | data.Type='volume'; |
---|
4551 | data.ProjMode='interp';%default |
---|
4552 | data.ProjModeMenu={}; |
---|
4553 | % set(handles.create,'Visible','on') |
---|
4554 | % set(handles.create,'Value',1) |
---|
4555 | % VOLUME_Callback(hObject,eventdata,handles)data.ProjModeMenu={}; |
---|
4556 | create_object(data,handles) |
---|
4557 | |
---|
4558 | %------------------------------------------------------------------------ |
---|
4559 | % --- generic function used for the creation of a projection object |
---|
4560 | function create_object(data,handles) |
---|
4561 | %------------------------------------------------------------------------ |
---|
4562 | % desactivate geometric calibration if opened |
---|
4563 | hgeometry_calib=findobj(allchild(0),'tag','geometry_calib'); |
---|
4564 | if ishandle(hgeometry_calib) |
---|
4565 | hhgeometry_calib=guidata(hgeometry_calib); |
---|
4566 | set(hhgeometry_calib.edit_append,'Value',0)% desactivate mouse action in geometry_calib |
---|
4567 | set(hhgeometry_calib.edit_append,'BackgroundColor',[0.7 0.7 0.7]) |
---|
4568 | end |
---|
4569 | set(handles.edit_object,'Value',0); %suppress the object edit mode |
---|
4570 | set(handles.edit_object,'BackgroundColor',[0.7,0.7,0.7]) |
---|
4571 | ListObject=get(handles.ListObject,'String'); |
---|
4572 | if ~strcmp(ListObject{end},'') |
---|
4573 | ListObject=[ListObject;{''}]; %append a blank to the list (if nort already done) to indicate the creation of a new object |
---|
4574 | set(handles.ListObject,'String',ListObject) |
---|
4575 | end |
---|
4576 | IndexObj=length(ListObject); |
---|
4577 | set(handles.ListObject,'Value',IndexObj) |
---|
4578 | UvData=get(handles.uvmat,'UserData'); |
---|
4579 | UvData.Object{IndexObj}=[]; %create a new empty object |
---|
4580 | UvData.Object{IndexObj}.DisplayHandle.uvmat=handles.PlotAxes; % axes for plot_object |
---|
4581 | UvData.Object{IndexObj}.DisplayHandle.view_field=[]; %no plot handle before plot_field operation |
---|
4582 | data.Name=data.Type;% default name=type |
---|
4583 | data.Coord=[0 0]; %default |
---|
4584 | if isfield(UvData,'Field') |
---|
4585 | Field=UvData.Field; |
---|
4586 | if isfield(UvData.Field,'Mesh')&&~isempty(UvData.Field.Mesh) |
---|
4587 | data.RangeX=[UvData.Field.XMin UvData.Field.XMax]; |
---|
4588 | if strcmp(data.Type,'line')||strcmp(data.Type,'polyline')||strcmp(data.Type,'points') |
---|
4589 | data.RangeY=UvData.Field.Mesh; |
---|
4590 | else |
---|
4591 | data.RangeY=[UvData.Field.YMin UvData.Field.YMax]; |
---|
4592 | end |
---|
4593 | data.DX=UvData.Field.Mesh; |
---|
4594 | data.DY=UvData.Field.Mesh; |
---|
4595 | end |
---|
4596 | if isfield(Field,'NbDim')&& isequal(Field.NbDim,3) |
---|
4597 | data.Coord=[0 0 0]; %default |
---|
4598 | end |
---|
4599 | if isfield(Field,'CoordUnit') |
---|
4600 | data.CoordUnit=Field.CoordUnit; |
---|
4601 | end |
---|
4602 | end |
---|
4603 | if ishandle(handles.UVMAT_title) |
---|
4604 | delete(handles.UVMAT_title)%delete the initial display of uvmat if no field has been entered |
---|
4605 | end |
---|
4606 | hset_object=set_object(data,handles);% call the set_object interface |
---|
4607 | hhset_object=guidata(hset_object); |
---|
4608 | hchild=get(hset_object,'children'); |
---|
4609 | set(hchild,'enable','on') |
---|
4610 | set(handles.uvmat,'UserData',UvData) |
---|
4611 | set(handles.CheckZoom,'Value',0) %desactivate the zoom for object creation by the mouse |
---|
4612 | CheckZoom_Callback(handles.uvmat, [], handles) |
---|
4613 | set(handles.delete_object,'Visible','on') |
---|
4614 | |
---|
4615 | %------------------------------------------------------------------------ |
---|
4616 | function MenuBrowseObject_Callback(hObject, eventdata, handles) |
---|
4617 | %------------------------------------------------------------------------ |
---|
4618 | %get the object file |
---|
4619 | [FileName, PathName, filterindex] = uigetfile( ... |
---|
4620 | {'*.xml;*.mat', ' (*.xml,*.mat)'; |
---|
4621 | '*.xml', '.xml files '; ... |
---|
4622 | '*.mat', '.mat matlab files '}, ... |
---|
4623 | 'Pick an xml Object file',get(handles.RootPath,'String')); |
---|
4624 | fileinput=[PathName FileName];%complete file name |
---|
4625 | sizf=size(fileinput); |
---|
4626 | if (~ischar(fileinput)||~isequal(sizf(1),1)),return;end |
---|
4627 | |
---|
4628 | %read the file |
---|
4629 | [data,heading]=xml2struct(fileinput); |
---|
4630 | if ~strcmp(heading,'ProjObject') |
---|
4631 | msgbox_uvmat('WARNING','The xml file does not have the heading ProjObject for projection objects') |
---|
4632 | end |
---|
4633 | [tild,data.Name]=fileparts(FileName);% object name set as file name |
---|
4634 | ListObject=get(handles.ListObject,'String'); |
---|
4635 | if ~strcmp(ListObject{end},'') |
---|
4636 | ListObject=[ListObject;{''}]; %append a blank to the list (if not already done) to indicate the creation of a new object |
---|
4637 | set(handles.ListObject,'String',ListObject) |
---|
4638 | end |
---|
4639 | IndexObj=length(ListObject); |
---|
4640 | |
---|
4641 | UvData=get(handles.uvmat,'UserData'); |
---|
4642 | UvData.Object{IndexObj}=[]; %create a new empty object |
---|
4643 | UvData.Object{IndexObj}.DisplayHandle.uvmat=[]; %no plot handle before plot_field operation |
---|
4644 | UvData.Object{IndexObj}.DisplayHandle.view_field=[]; %no plot handle before plot_field operation |
---|
4645 | set(handles.uvmat,'UserData',UvData) |
---|
4646 | set(handles.ListObject,'Value',IndexObj) |
---|
4647 | hset_object=set_object(data);% call the set_object interface |
---|
4648 | set(get(hset_object,'children'),'enable','on')% enable edit action on elements on GUI set_object |
---|
4649 | set(handles.edit_object,'Value',0); %suppress the object edit mode |
---|
4650 | set(handles.edit_object,'BackgroundColor',[0.7,0.7,0.7]) |
---|
4651 | set(handles.delete_object,'Visible','on') |
---|
4652 | |
---|
4653 | |
---|
4654 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
---|
4655 | % MenuEdit Callbacks |
---|
4656 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
---|
4657 | %------------------------------------------------------------------------ |
---|
4658 | function MenuEditObject_Callback(hObject, eventdata, handles) |
---|
4659 | %------------------------------------------------------------------------ |
---|
4660 | set(handles.edit_object,'Value',1) |
---|
4661 | edit_Callback(hObject, eventdata, handles) |
---|
4662 | |
---|
4663 | %------------------------------------------------------------------------ |
---|
4664 | function MenuEditVectors_Callback(hObject, eventdata, handles) |
---|
4665 | %------------------------------------------------------------------------ |
---|
4666 | set(handles.edit_vect,'Visible','on') |
---|
4667 | set(handles.edit_vect,'Value',1) |
---|
4668 | edit_vect_Callback(hObject, eventdata, handles) |
---|
4669 | |
---|
4670 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
---|
4671 | % MenuTools Callbacks |
---|
4672 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
---|
4673 | %------------------------------------------------------------------------ |
---|
4674 | function MenuCalib_Callback(hObject, eventdata, handles) |
---|
4675 | %------------------------------------------------------------------------ |
---|
4676 | |
---|
4677 | UvData=get(handles.uvmat,'UserData');%read UvData properties stored on the uvmat interface |
---|
4678 | |
---|
4679 | %suppress competing options |
---|
4680 | set(handles.CheckZoom,'Value',0) |
---|
4681 | set(handles.CheckZoom,'BackgroundColor',[0.7 0.7 0.7]) |
---|
4682 | set(handles.ListObject,'Value',1) |
---|
4683 | % initiate display of GUI geometry_calib |
---|
4684 | data=[]; %default |
---|
4685 | if isfield(UvData,'CoordType') |
---|
4686 | data.CoordType=UvData.CoordType; |
---|
4687 | end |
---|
4688 | [RootPath,SubDir,RootFile,FileIndex,FileExt]=read_file_boxes(handles); |
---|
4689 | FileName=[fullfile(RootPath,SubDir,RootFile) FileIndex FileExt]; |
---|
4690 | set(handles.view_xml,'Backgroundcolor',[1 1 0])%indicate the reading of the current xml file by geometry_calib |
---|
4691 | pos_uvmat=get(handles.uvmat,'Position'); |
---|
4692 | pos_cal(1)=pos_uvmat(1)+UvData.OpenParam.PosGeometryCalib(1)*pos_uvmat(3); |
---|
4693 | pos_cal(2)=pos_uvmat(2)+UvData.OpenParam.PosGeometryCalib(2)*pos_uvmat(4); |
---|
4694 | pos_cal(3:4)=UvData.OpenParam.PosGeometryCalib(3:4).* pos_uvmat(3:4); |
---|
4695 | geometry_calib(FileName,pos_cal);% call the geometry_calib interface |
---|
4696 | set(handles.view_xml,'Backgroundcolor',[1 1 1])%indicate the end of reading of the current xml file by geometry_calib |
---|
4697 | set(handles.MenuCalib,'checked','on')% indicate that MenuCalib is activated, test used by mouse action |
---|
4698 | |
---|
4699 | %------------------------------------------------------------------------ |
---|
4700 | function MenuMask_Callback(hObject, eventdata, handles) |
---|
4701 | %------------------------------------------------------------------------ |
---|
4702 | UvData=get(handles.uvmat,'UserData');%read UvData properties stored on the uvmat interface |
---|
4703 | ListObj=UvData.Object; |
---|
4704 | select=zeros(1,numel(ListObj)); |
---|
4705 | for iobj=1:numel(ListObj); |
---|
4706 | if strcmp(ListObj{iobj}.ProjMode,'mask_inside')||strcmp(ListObj{iobj}.ProjMode,'mask_outside') |
---|
4707 | select(iobj)=1; |
---|
4708 | end |
---|
4709 | end |
---|
4710 | val=find(select); |
---|
4711 | if isempty(val) |
---|
4712 | msgbox_uvmat('ERROR','polygons must be first created by Projection object/mask polygon in the menu bar'); |
---|
4713 | return |
---|
4714 | else |
---|
4715 | % set(handles.ListObject,'Max',2);%allow multiple selection |
---|
4716 | set(handles.ListObject,'Value',val); |
---|
4717 | flag=1; |
---|
4718 | npx=size(UvData.Field.A,2); |
---|
4719 | npy=size(UvData.Field.A,1); |
---|
4720 | xi=0.5:npx-0.5; |
---|
4721 | yi=0.5:npy-0.5; |
---|
4722 | [Xi,Yi]=meshgrid(xi,yi); |
---|
4723 | if isfield(UvData,'Object') |
---|
4724 | for iobj=1:length(UvData.Object) |
---|
4725 | ObjectData=UvData.Object{iobj}; |
---|
4726 | if isfield(ObjectData,'ProjMode') &&(isequal(ObjectData.ProjMode,'mask_inside')||isequal(ObjectData.ProjMode,'mask_outside')); |
---|
4727 | flagobj=1; |
---|
4728 | testphys=0; %coordinates in pixels by default |
---|
4729 | if isfield(ObjectData,'CoordUnit') && ~isequal(ObjectData.CoordUnit,'pixel') |
---|
4730 | if isfield(UvData,'XmlData')&& isfield(UvData.XmlData{1},'GeometryCalib') |
---|
4731 | Calib=UvData.XmlData{1}.GeometryCalib; |
---|
4732 | testphys=1; |
---|
4733 | end |
---|
4734 | end |
---|
4735 | if isfield(ObjectData,'Coord')&& isfield(ObjectData,'Type') |
---|
4736 | if isequal(ObjectData.Type,'polygon') |
---|
4737 | X=ObjectData.Coord(:,1); |
---|
4738 | Y=ObjectData.Coord(:,2); |
---|
4739 | if testphys |
---|
4740 | [X,Y]=px_XYZ(Calib,X,Y,0);% to generalise with 3D cases |
---|
4741 | end |
---|
4742 | flagobj=~inpolygon(Xi,Yi,X',Y');%=0 inside the polygon, 1 outside |
---|
4743 | elseif isequal(ObjectData.Type,'ellipse') |
---|
4744 | if testphys |
---|
4745 | %[X,Y]=px_XYZ(Calib,X,Y,0);% TODO:create a polygon boundary and transform to phys |
---|
4746 | end |
---|
4747 | RangeX=max(ObjectData.RangeX); |
---|
4748 | RangeY=max(ObjectData.RangeY); |
---|
4749 | X2Max=RangeX*RangeX; |
---|
4750 | Y2Max=RangeY*RangeY; |
---|
4751 | distX=(Xi-ObjectData.Coord(1,1)); |
---|
4752 | distY=(Yi-ObjectData.Coord(1,2)); |
---|
4753 | flagobj=(distX.*distX/X2Max+distY.*distY/Y2Max)>1; |
---|
4754 | elseif isequal(ObjectData.Type,'rectangle') |
---|
4755 | if testphys |
---|
4756 | %[X,Y]=px_XYZ(Calib,X,Y,0);% TODO:create a polygon boundary and transform to phys |
---|
4757 | end |
---|
4758 | distX=abs(Xi-ObjectData.Coord(1,1)); |
---|
4759 | distY=abs(Yi-ObjectData.Coord(1,2)); |
---|
4760 | flagobj=distX>max(ObjectData.RangeX) | distY>max(ObjectData.RangeY); |
---|
4761 | end |
---|
4762 | if isequal(ObjectData.ProjMode,'mask_outside') |
---|
4763 | flagobj=~flagobj; |
---|
4764 | end |
---|
4765 | flag=flag & flagobj; |
---|
4766 | end |
---|
4767 | end |
---|
4768 | end |
---|
4769 | end |
---|
4770 | %mask name |
---|
4771 | RootPath=get(handles.RootPath,'String'); |
---|
4772 | SubDir=get(handles.SubDir,'String'); |
---|
4773 | RootFile=get(handles.RootFile,'String'); |
---|
4774 | if ~isempty(RootFile)&&(isequal(RootFile(1),'/')|| isequal(RootFile(1),'\')) |
---|
4775 | RootFile(1)=[]; |
---|
4776 | end |
---|
4777 | % filebase=fullfile(RootPath,RootFile); |
---|
4778 | list=get(handles.masklevel,'String'); |
---|
4779 | masknumber=num2str(length(list)); |
---|
4780 | maskindex=get(handles.masklevel,'Value'); |
---|
4781 | % mask_name=fullfile_uvmat(RootPath,'',[RootFile '_' masknumber 'mask'],'.png','_1',maskindex); |
---|
4782 | mask_name=fullfile_uvmat(RootPath,[SubDir '.mask'],'mask','.png','_1',maskindex); |
---|
4783 | imflag=uint8(255*(0.392+0.608*flag));% =100 for flag=0 (vectors not computed when 20<imflag<200) |
---|
4784 | imflag=flipdim(imflag,1); |
---|
4785 | |
---|
4786 | %display the mask |
---|
4787 | hfigmask=figure; |
---|
4788 | set(hfigmask,'Name','mask image') |
---|
4789 | vec=linspace(0,1,256);%define a linear greyscale colormap |
---|
4790 | map=[vec' vec' vec']; |
---|
4791 | colormap(map) |
---|
4792 | image(imflag); |
---|
4793 | answer=msgbox_uvmat('INPUT_TXT','mask file name:', mask_name); |
---|
4794 | if ~strcmp(answer,'Cancel') |
---|
4795 | mask_dir=fileparts(answer); |
---|
4796 | if ~exist(mask_dir,'dir') |
---|
4797 | [xx,msg1]=mkdir(mask_dir); |
---|
4798 | if ~strcmp(msg1,'') |
---|
4799 | errormsg=['cannot create ' mask_dir ': ' msg1];%error message for directory creation |
---|
4800 | return |
---|
4801 | end |
---|
4802 | end |
---|
4803 | imwrite(imflag,answer,'BitDepth',8); |
---|
4804 | end |
---|
4805 | set(handles.ListObject,'Value',1) |
---|
4806 | end |
---|
4807 | |
---|
4808 | %------------------------------------------------------------------------ |
---|
4809 | %-- open the GUI set_grid.fig to create grid |
---|
4810 | function MenuGrid_Callback(hObject, eventdata, handles) |
---|
4811 | %------------------------------------------------------------------------ |
---|
4812 | %suppress the other options if grid is chosen |
---|
4813 | set(handles.edit_vect,'Value',0) |
---|
4814 | edit_vect_Callback(hObject, eventdata, handles) |
---|
4815 | set(handles.edit_object,'BackgroundColor',[0.7 0.7 0.7]) |
---|
4816 | set(handles.ListObject,'Value',1) |
---|
4817 | |
---|
4818 | %prepare display of the set_grid GUI |
---|
4819 | [RootPath,SubDir,RootFile,FileIndex,FileExt]=read_file_boxes(handles); |
---|
4820 | FileName=[fullfile(RootPath,SubDir,RootFile) FileIndex FileExt]; |
---|
4821 | CoordList=get(handles.transform_fct,'String'); |
---|
4822 | val=get(handles.transform_fct,'Value'); |
---|
4823 | set_grid(FileName,CoordList{val});% call the set_object interface |
---|
4824 | |
---|
4825 | |
---|
4826 | %------------------------------------------------------------------------ |
---|
4827 | function MenuRuler_Callback(hObject, eventdata, handles) |
---|
4828 | %------------------------------------------------------------------------ |
---|
4829 | set(handles.CheckZoom,'Value',0) |
---|
4830 | CheckZoom_Callback(handles.uvmat, [], handles) |
---|
4831 | set(handles.MenuRuler,'checked','on') |
---|
4832 | UvData=get(handles.uvmat,'UserData'); |
---|
4833 | UvData.MouseAction='ruler'; |
---|
4834 | set(handles.uvmat,'UserData',UvData); |
---|
4835 | |
---|
4836 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
---|
4837 | % MenuRun Callbacks |
---|
4838 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
---|
4839 | |
---|
4840 | %------------------------------------------------------------------------ |
---|
4841 | % open the GUI 'series' |
---|
4842 | function MenuSeries_Callback(hObject, eventdata, handles) |
---|
4843 | %------------------------------------------------------------------------ |
---|
4844 | series; %first display of the GUI to fill waiting time |
---|
4845 | [RootPath,SubDir,RootFile,FileIndex,FileExt]=read_file_boxes(handles); |
---|
4846 | param.FileName=[fullfile(RootPath,SubDir,RootFile) FileIndex FileExt]; |
---|
4847 | if isequal(get(handles.SubField,'Value'),1) |
---|
4848 | [RootPath_1,SubDir_1,RootFile_1,FileIndex_1,FileExt_1]=read_file_boxes_1(handles); |
---|
4849 | FileName_1=[fullfile(RootPath_1,SubDir_1,RootFile_1) FileIndex_1 FileExt_1]; |
---|
4850 | if ~isequal(FileName_1,param.FileName) |
---|
4851 | param.FileName_1=FileName_1; |
---|
4852 | end |
---|
4853 | end |
---|
4854 | param.NomType=get(handles.NomType,'String'); |
---|
4855 | param.NomType_1=get(handles.NomType_1,'String'); |
---|
4856 | param.CheckFixPair=get(handles.CheckFixPair,'Value'); |
---|
4857 | huvmat=get(handles.MenuSeries,'parent'); |
---|
4858 | UvData=get(huvmat,'UserData'); |
---|
4859 | if isfield(UvData,'XmlData')&& isfield(UvData.XmlData{1},'Time') |
---|
4860 | param.Time=UvData.XmlData{1}.Time; |
---|
4861 | end |
---|
4862 | if isequal(get(handles.scan_i,'Value'),1) |
---|
4863 | param.incr_i=str2num(get(handles.num_IndexIncrement,'String')); |
---|
4864 | elseif isequal(get(handles.scan_j,'Value'),1) |
---|
4865 | param.incr_j=str2num(get(handles.num_IndexIncrement,'String')); |
---|
4866 | end |
---|
4867 | param.list_fields=get(handles.Fields,'String');% list menu fields |
---|
4868 | FieldName=param.list_fields{get(handles.Fields,'Value')}; |
---|
4869 | ind_image=find(strcmp('image',param.list_fields)); |
---|
4870 | if ~isempty(ind_image) && numel(param.list_fields)>1 |
---|
4871 | param.list_fields(ind_image)=[]; %suppress 'image' option |
---|
4872 | end |
---|
4873 | param.index_fields=find(strcmp(FieldName,param.list_fields));% selected string index |
---|
4874 | % if param.index_fields>1 |
---|
4875 | % param.index_fields=param.index_fields-1; |
---|
4876 | % end |
---|
4877 | param.list_fields_1=get(handles.Fields_1,'String');% list menu fields |
---|
4878 | if ischar(param.list_fields_1),param.list_fields_1={param.list_fields_1};end |
---|
4879 | FieldName_1=param.list_fields_1{get(handles.Fields_1,'Value')}; |
---|
4880 | ind_image=find(strcmp('image',param.list_fields_1)); |
---|
4881 | if ~isempty(ind_image) && numel(param.list_fields_1)>1 |
---|
4882 | param.list_fields_1(ind_image)=[]; %suppress 'image' option |
---|
4883 | end |
---|
4884 | param.index_fields_1=find(strcmp(FieldName_1,param.list_fields_1));% selected string index |
---|
4885 | %param.index_fields=find(strcmp(FieldName,param.list_fields));% selected string index |
---|
4886 | % param.index_fields_1=get(handles.Fields_1,'Value')-1;% selected string index |
---|
4887 | % if param.index_fields_1>1 |
---|
4888 | % param.index_fields_1=param.index_fields_1-1; |
---|
4889 | % end |
---|
4890 | param.menu_coord_str=get(handles.transform_fct,'String'); |
---|
4891 | param.menu_coord_val=get(handles.transform_fct,'Value'); |
---|
4892 | series(param); %run the series interface |
---|
4893 | |
---|
4894 | %------------------------------------------------------------------------ |
---|
4895 | % -- open the GUI civ.fig for PIV |
---|
4896 | function MenuPIV_Callback(hObject, eventdata, handles) |
---|
4897 | %------------------------------------------------------------------------ |
---|
4898 | [RootPath,SubDir,RootFile,FileIndex,FileExt]=read_file_boxes(handles); |
---|
4899 | FileName=[fullfile(RootPath,SubDir,RootFile) FileIndex FileExt]; |
---|
4900 | civ(FileName);% interface de civ(not in the uvmat file) |
---|
4901 | |
---|
4902 | % -------------------------------------------------------------------- |
---|
4903 | function MenuHelp_Callback(hObject, eventdata, handles) |
---|
4904 | % -------------------------------------------------------------------- |
---|
4905 | path_to_uvmat=which ('uvmat');% check the path of uvmat |
---|
4906 | pathelp=fileparts(path_to_uvmat); |
---|
4907 | helpfile=fullfile(pathelp,'uvmat_doc','uvmat_doc.html'); |
---|
4908 | if isempty(dir(helpfile)), msgbox_uvmat('ERROR','Please put the help file uvmat_doc.html in the sub-directory /uvmat_doc of the UVMAT package') |
---|
4909 | else |
---|
4910 | addpath (fullfile(pathelp,'uvmat_doc')) |
---|
4911 | web(helpfile); |
---|
4912 | end |
---|
4913 | |
---|
4914 | |
---|
4915 | % -------------------------------------------------------------------- |
---|
4916 | function MenuSetProject_Callback(hObject, eventdata, handles) |
---|
4917 | RootPath=get(handles.RootPath,'String'); |
---|
4918 | ProjectDir = uigetdir(fileparts(fileparts(RootPath)), 'select the project source directory'); |
---|
4919 | datatree_browser(ProjectDir) |
---|
4920 | |
---|
4921 | |
---|
4922 | % -------------------------------------------------------------------- |
---|
4923 | function MenuBrowseProject_Callback(hObject, eventdata, handles) |
---|
4924 | RootPath=get(handles.RootPath,'String'); |
---|
4925 | ProjectDir = uigetdir(fileparts(fileparts(RootPath)), 'select the project directory'); |
---|
4926 | datatree_browser(ProjectDir) |
---|
4927 | |
---|
4928 | |
---|
4929 | % --- Executes on selection change in Coord_y. |
---|
4930 | function Coord_y_Callback(hObject, eventdata, handles) |
---|
4931 | |
---|
4932 | % --- Executes on selection change in Coord_x. |
---|
4933 | function Coord_x_Callback(hObject, eventdata, handles) |
---|