source: trunk/src/uvmat.m @ 567

Last change on this file since 567 was 567, checked in by sommeria, 8 years ago

LIF calibration improved

File size: 213.8 KB
Line 
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 fieldname (with fieldname
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 fieldname (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 fieldname 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 fieldname 
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 fieldname
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%------------------------------------------------------------------------
142function varargout = uvmat(varargin)
143
144% Begin initialization code - DO NOT EDIT
145gui_Singleton = 1;
146gui_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',      []);
152if nargin && ischar(varargin{1})&& ~isempty(regexp(varargin{1},'_Callback','once'))
153    gui_State.gui_Callback = str2func(varargin{1});
154end
155
156if nargout
157    varargout{1:nargout} = gui_mainfcn(gui_State, varargin{:});
158else
159    gui_mainfcn(gui_State, varargin{:});
160end
161% End initialization code - DO NOT EDIT
162
163%------------------------------------------------------------------------
164% --- Executes just before the GUI uvmat is made visible.
165function uvmat_OpeningFcn(hObject, eventdata, handles, input )
166%------------------------------------------------------------------------
167
168%% Choose default command menuline output for uvmat (standard GUI)
169handles.output = hObject;
170
171%% Update handles structure (standard GUI)
172guidata(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)
175path_uvmat=fileparts(which('uvmat'));
176
177%% set the position of colorbar and ancillary GUIs:
178set(hObject,'Units','Normalized')
179movegui(hObject,'center')
180%UvData.OpenParam.PosColorbar=[0.8450    0.0900    0.0190    0.3600];
181UvData.OpenParam.PosColorbar=[0.805 0.022 0.019 0.445];
182UvData.OpenParam.PosSetObject=[-0.05 -0.03 0.3 0.7]; %position for set_object
183UvData.OpenParam.PosGeometryCalib=[0.95 -0.03 0.28 1 ];%position for geometry_calib (TO IMPROVE)
184% UvData.OpenParam.CalSize=[0.28 1];
185% UvData.PlotAxes=[];%initiate the record of plotted field
186% UvData.axes2=[];
187% UvData.axes1=[];
188AxeData.LimEditBox=1; %initialise AxeData
189set(handles.PlotAxes,'UserData',AxeData)
190
191%% set functions for the mouse and keyboard
192set(hObject,'KeyPressFcn',{'keyboard_callback',handles})%set keyboard action function
193set(hObject,'WindowButtonMotionFcn',{'mouse_motion',handles})%set mouse action functio
194set(hObject,'WindowButtonDownFcn',{'mouse_down'})%set mouse click action function
195set(hObject,'WindowButtonUpFcn',{'mouse_up',handles})
196set(hObject,'DeleteFcn',{@closefcn})%
197
198%% initialisation
199% set(handles.ListObject,'Value',1)% default: empty projection objectproj_field
200% set(handles.ListObject,'String',{''})
201% set(handles.ListObject_1,'Value',1)% default: empty projection objectproj_field
202% set(handles.ListObject_1,'String',{''})
203set(handles.FieldName,'Value',1)
204set(handles.FieldName,'string',{''})
205UvData.Object={[]};
206
207%% TRANSFORM menu: builtin fcts
208transform_menu={'';'sub_field';'phys';'phys_polar'};
209UvData.OpenParam.NbBuiltin=numel(transform_menu); %number of functions
210transform_path=fullfile(path_uvmat,'transform_field');
211path_list=cell(UvData.OpenParam.NbBuiltin,1);
212path_list{1}='';
213for ilist=2:UvData.OpenParam.NbBuiltin
214path_list{ilist}=transform_path; % set transform_path to the path_list
215end
216
217%% load the list of previously browsed files in menus Open, Open_1 and transform_fct
218 dir_perso=prefdir; % path to the directory .matlab for personal data
219 profil_perso=fullfile(dir_perso,'uvmat_perso.mat');% personal data file uvmauvmat_perso.mat' in .matlab
220 if exist(profil_perso,'file')
221     h=load (profil_perso);
222     if isfield(h,'MenuFile')% load the menu of previously opened files
223         for ifile=1:min(length(h.MenuFile),5)
224             eval(['set(handles.MenuFile_' num2str(ifile) ',''Label'',h.MenuFile{ifile});'])
225             eval(['set(handles.MenuFile_' num2str(ifile) '_1,''Label'',h.MenuFile{ifile});'])
226         end
227     end
228     if isfield(h,'transform_fct') && iscell(h.transform_fct) % load the menu of transform fct set by user
229         for ilist=1:length(h.transform_fct);
230             if exist(h.transform_fct{ilist},'file')
231                 [path,file]=fileparts(h.transform_fct{ilist});
232                 transform_menu=[transform_menu; {file}];
233                 path_list=[path_list; {path}];
234             end
235         end
236     end
237 end
238transform_menu=[transform_menu;{'more...'}];%append the option more.. to the menu
239set(handles.transform_fct,'String',transform_menu)% display the menu of transform fcts
240set(handles.transform_fct,'UserData',path_list)% store the corresponding list of path in UserData of uicontrol transform_fct
241set(handles.path_transform,'String','')
242set(handles.path_transform,'UserData',[])
243
244%% case of an input argument for uvmat
245testinputfield=0;
246inputfile=[];
247Field=[];
248if exist('input','var')
249    if ishandle(handles.UVMAT_title)
250        delete(handles.UVMAT_title)
251    end   
252    if isstruct(input)
253        if isfield(input,'InputFile')
254            inputfile=input.InputFile;
255        end
256        if isfield(input,'TimeIndex')
257            set(handles.i1,num2str(input.TimeIndex))
258        end
259        if isfield(input,'FieldsString')
260            UvData.FieldsString=input.FieldsString;
261        end
262    elseif ischar(input)% file name introduced as input
263           inputfile=input;
264    elseif isnumeric(input)%simple matrix introduced as input
265        sizinput=size(input);
266        if sizinput(1)<=1 || sizinput(2)<=1
267            msgbox_uvmat('ERROR','bad input for uvmat: file name, structure or numerical matrix accepted')
268            return
269        end
270        UvData.Field.ListVarName={'A','coord_y','coord_x'};
271        UvData.Field.VarDimName={{'coord_y','coord_x'},'cord_y','coord_x'};
272        UvData.Field.A=input;
273        UvData.Field.coord_x=[0.5 size(input,2)-0.5];
274        UvData.Field.coord_y=[size(input,1)-0.5 0.5];
275        testinputfield=1;
276    end
277else
278    %% check the path and date of modification of all functions in uvmat
279    path_to_uvmat=which ('uvmat');% check the path detected for source file uvmat
280    [infomsg,date_str,svn_info]=check_files;%check the path of the functions called by uvmat.m   
281    date_str=['last modification: ' date_str];
282    if ishandle(handles.UVMAT_title)
283        set(handles.UVMAT_title,'String',...
284            [{'Copyright  LEGI UMR 5519 /CNRS-UJF-Grenoble INP, 2010'};...
285            {'GNU General Public License'};...
286            {path_to_uvmat};...
287            {date_str};...
288            infomsg]);
289    end
290end
291set(handles.uvmat,'UserData',UvData)
292if ~isempty(inputfile)
293    %%%%% display the input field %%%%%%%
294    display_file_name(handles,inputfile)
295    %%%%%%%
296end
297
298set_vec_col_bar(handles) %update the display of color code for vectors
299
300%------------------------------------------------------------------------
301% --- Outputs from this function are returned to the command menuline.
302function varargout = uvmat_OutputFcn(hObject, eventdata, handles)
303varargout{1} = handles.output;% the only output argument is the handle to the GUI figure
304
305%------------------------------------------------------------------------
306% --- executed when closing uvmat: delete or desactivate the associated figures if exist
307function closefcn(gcbo,eventdata)
308%------------------------------------------------------------------------
309hh=findobj(allchild(0),'tag','view_field');
310if ~isempty(hh)
311    delete(hh)
312end
313hh=findobj(allchild(0),'tag','geometry_calib');
314if ~isempty(hh)
315    delete(hh)
316end
317hh=findobj(allchild(0),'tag','set_object');
318if ~isempty(hh)
319    hhh=findobj(hh,'tag','PLOT');
320    set(hhh,'enable','off')
321end
322
323%------------------------------------------------------------------------
324%------------------------------------------------------------------------
325%  II - FUNCTIONS FOR INTRODUCING THE INPUT FILES
326% automatically sets the global properties when the rootfile name is introduced
327% then activate the view-field action if selected
328% it is activated either by clicking on the RootPath window or by the
329% browser
330%------------------------------------------------------------------------
331%------------------------------------------------------------------------
332% --- Executes on the menu Open/Browse...
333% search the files, recognize their type according to their name and fill the rootfile input windows
334function MenuBrowse_Callback(hObject, eventdata, handles)
335[RootPath,SubDir,RootFile,FileIndices,FileExt]=read_file_boxes(handles);
336%oldfile=[fullfile(RootPath,SubDir,RootFile) FileIndices FileExt];
337oldfile=fullfile(RootPath,SubDir);
338if isempty(oldfile)||isequal(oldfile,'') %loads the previously stored file name and set it as default in the file_input box
339         dir_perso=prefdir;
340         profil_perso=fullfile(dir_perso,'uvmat_perso.mat');
341         if exist(profil_perso,'file')
342              h=load (profil_perso);
343             if isfield(h,'MenuFile_1')
344                  oldfile=h.MenuFile_1;
345             end
346         end
347end
348[FileName, PathName] = uigetfile({'*.*','All Files(*.*)'},'Pick a file',oldfile);
349if ~ischar(FileName),return,end %abandon if the browser is cancelled
350fileinput=[PathName FileName];%complete file name
351
352%% display the selected field and related information
353display_file_name( handles,fileinput)
354
355% -----------------------------------------------------------------------
356% --- Open again the file whose name has been recorded in MenuFile_1
357function MenuFile_1_Callback(hObject, eventdata, handles)
358%------------------------------------------------------------------------
359fileinput=get(handles.MenuFile_1,'Label');
360display_file_name( handles,fileinput)
361
362% -----------------------------------------------------------------------
363% --- Open again the file whose name has been recorded in MenuFile_2
364function MenuFile_2_Callback(hObject, eventdata, handles)
365%------------------------------------------------------------------------
366fileinput=get(handles.MenuFile_2,'Label');
367display_file_name(handles,fileinput)
368
369% -----------------------------------------------------------------------
370% --- Open again the file whose name has been recorded in MenuFile_3
371function MenuFile_3_Callback(hObject, eventdata, handles)
372%------------------------------------------------------------------------
373fileinput=get(handles.MenuFile_3,'Label');
374display_file_name(handles,fileinput)
375
376% -----------------------------------------------------------------------
377% --- Open again the file whose name has been recorded in MenuFile_4
378function MenuFile_4_Callback(hObject, eventdata, handles)
379%------------------------------------------------------------------------
380fileinput=get(handles.MenuFile_4,'Label');
381display_file_name(handles,fileinput)
382
383% -----------------------------------------------------------------------
384% --- Open again the file whose name has been recorded in MenuFile_5
385function MenuFile_5_Callback(hObject, eventdata, handles)
386%------------------------------------------------------------------------
387fileinput=get(handles.MenuFile_5,'Label');
388display_file_name(handles,fileinput)
389
390%------------------------------------------------------------------------
391% --- Executes on the menu Open/Browse_1 for the second input field,
392%     search the files, recognize their type according to their name and fill the rootfile input windows
393function MenuBrowse_1_Callback(hObject, eventdata, handles)
394%------------------------------------------------------------------------
395RootPath=get(handles.RootPath,'String');
396[FileName, PathName] = uigetfile({'*.*','All Files(*.*)'},'Pick a file',RootPath);
397if ~ischar(FileName),return,end %abandon if the browser is cancelled
398fileinput_1=[PathName FileName];%complete file name
399
400% refresh the current displayed field
401set(handles.SubField,'Value',1)
402display_file_name(handles,fileinput_1,2)
403
404%update list of recent files in the menubar
405MenuFile_1=fileinput_1;
406MenuFile_2=get(handles.MenuFile_1,'Label');
407MenuFile_3=get(handles.MenuFile_2,'Label');
408MenuFile_4=get(handles.MenuFile_3,'Label');
409MenuFile_5=get(handles.MenuFile_4,'Label');
410set(handles.MenuFile_1,'Label',MenuFile_1)
411set(handles.MenuFile_2,'Label',MenuFile_2)
412set(handles.MenuFile_3,'Label',MenuFile_3)
413set(handles.MenuFile_4,'Label',MenuFile_4)
414set(handles.MenuFile_5,'Label',MenuFile_5)
415set(handles.MenuFile_1_1,'Label',MenuFile_1)
416set(handles.MenuFile_2_1,'Label',MenuFile_2)
417set(handles.MenuFile_3_1,'Label',MenuFile_3)
418set(handles.MenuFile_4_1,'Label',MenuFile_4)
419set(handles.MenuFile_5_1,'Label',MenuFile_5)
420dir_perso=prefdir;
421profil_perso=fullfile(dir_perso,'uvmat_perso.mat');
422if exist(profil_perso,'file')
423    save (profil_perso,'MenuFile_1','MenuFile_2','MenuFile_3','MenuFile_4', 'MenuFile_5','-append'); %store the file names for future opening of uvmat
424else
425    txt=ver('MATLAB');
426    Release=txt.Release;
427    relnumb=str2double(Release(3:4));
428    if relnumb >= 14
429        save (profil_perso,'MenuFile_1','MenuFile_2','MenuFile_3','MenuFile_4', 'MenuFile_5','-V6'); %store the file names for future opening of uvmat
430    else
431        save (profil_perso,'MenuFile_1','MenuFile_2','MenuFile_3','MenuFile_4', 'MenuFile_5'); %store the file names for future opening of uvmat
432    end
433end
434
435% -----------------------------------------------------------------------
436% --- Open again as second field the file whose name has been recorded in MenuFile_1
437function MenuFile_1_1_Callback(hObject, eventdata, handles)
438% -----------------------------------------------------------------------
439fileinput_1=get(handles.MenuFile_1_1,'Label');
440set(handles.SubField,'Value',1)
441display_file_name(handles,fileinput_1,2)
442
443% -----------------------------------------------------------------------
444% --- Open again as second field the file whose name has been recorded in MenuFile_2
445function MenuFile_2_1_Callback(hObject, eventdata, handles)
446% -----------------------------------------------------------------------
447fileinput_1=get(handles.MenuFile_2_1,'Label');
448set(handles.SubField,'Value',1)
449display_file_name(handles,fileinput_1,2)
450
451% -----------------------------------------------------------------------
452% --- Open again as second field the file whose name has been recorded in MenuFile_3
453function MenuFile_3_1_Callback(hObject, eventdata, handles)
454% -----------------------------------------------------------------------
455fileinput_1=get(handles.MenuFile_3_1,'Label');
456set(handles.SubField,'Value',1)
457display_file_name(handles,fileinput_1,2)
458
459% -----------------------------------------------------------------------
460% --- Open again as second field the file whose name has been recorded in MenuFile_4
461function MenuFile_4_1_Callback(hObject, eventdata, handles)
462% -----------------------------------------------------------------------
463fileinput_1=get(handles.MenuFile_4_1,'Label');
464set(handles.SubField,'Value',1)
465display_file_name(handles,fileinput_1,2)
466
467% -----------------------------------------------------------------------
468% --- Open again as second field the file whose name has been recorded in MenuFile_5
469function MenuFile_5_1_Callback(hObject, eventdata, handles)
470% -----------------------------------------------------------------------
471fileinput_1=get(handles.MenuFile_5_1,'Label');
472set(handles.SubField,'Value',1)
473display_file_name(handles,fileinput_1,2)
474
475%------------------------------------------------------------------------
476% --- Called by action in RootPath edit box
477function RootPath_Callback(hObject,eventdata,handles)
478%------------------------------------------------------------------------
479% read the current input file name:
480[RootPath,SubDir,RootFile,FileIndices,FileExt]=read_file_boxes(handles);
481if ~exist(fullfile(RootPath,SubDir),'dir')
482    msgbox_uvmat('ERROR',['directory ' fullfile(RootPath,SubDir) ' does not exist'])
483    return
484end
485% detect the file type, get the movie object if relevant, and look for the corresponding file series:
486[RootPath,SubDir,RootFile,i1_series,i2_series,j1_series,j2_series,tild,FileType,MovieObject]=find_file_series(fullfile(RootPath,SubDir),[RootFile FileIndices FileExt]);
487% initiate the input file series and refresh the current field view:
488update_rootinfo(handles,i1_series,i2_series,j1_series,j2_series,FileType,MovieObject,1);
489
490%-----------------------------------------------------------------------
491% --- Called by action in RootPath_1 edit box
492function RootPath_1_Callback(hObject,eventdata,handles)
493% -----------------------------------------------------------------------
494% update_rootinfo_1(hObject,eventdata,handles)
495[RootPath,SubDir,RootFile,FileIndices,FileExt]=read_file_boxes_1(handles);
496if ~exist(fullfile(RootPath,SubDir),'dir')
497    msgbox_uvmat('ERROR',['directory ' fullfile(RootPath,SubDir) ' does not exist'])
498    return
499end
500% detect the file type, get the movie object if relevant, and look for the corresponding file series:
501[RootPath,SubDir,RootFile,i1_series,i2_series,j1_series,j2_series,tild,FileType,MovieObject]=find_file_series(fullfile(RootPath,SubDir),[RootFile FileIndices FileExt]);
502% initiate the input file series and refresh the current field view:
503update_rootinfo(handles,i1_series,i2_series,j1_series,j2_series,FileType,MovieObject,2);
504
505%------------------------------------------------------------------------
506% --- Called by action in RootFile edit box
507function SubDir_Callback(hObject, eventdata, handles)
508%------------------------------------------------------------------------
509%refresh the menu of input fieldname
510Fields_Callback(hObject, eventdata, handles);
511% refresh the current field view
512run0_Callback(hObject, eventdata, handles);
513
514%------------------------------------------------------------------------
515% --- Called by action in RootFile edit box
516function RootFile_Callback(hObject, eventdata, handles)
517%------------------------------------------------------------------------
518RootPath_Callback(hObject,eventdata,handles)
519
520%-----------------------------------------------------------------------
521% --- Called by action in RootFile_1 edit box
522function RootFile_1_Callback(hObject, eventdata, handles)
523% -----------------------------------------------------------------------
524RootPath_1_Callback(hObject,eventdata,handles)
525
526%------------------------------------------------------------------------
527% --- Called by action in FileIndex edit box
528function FileIndex_Callback(hObject, eventdata, handles)
529%------------------------------------------------------------------------
530[tild,tild,tild,i1,i2,j1,j2]=fileparts_uvmat(get(handles.FileIndex,'String'));
531set(handles.i1,'String',num2str(i1));
532set(handles.i2,'String',num2str(i2));
533set(handles.j1,'String',num2str(j1));
534set(handles.j2,'String',num2str(j2));
535
536% refresh the current field view
537run0_Callback(hObject, eventdata, handles)
538
539%------------------------------------------------------------------------
540% --- Called by action in FileIndex_1 edit box
541function FileIndex_1_Callback(hObject, eventdata, handles)
542%------------------------------------------------------------------------
543run0_Callback(hObject, eventdata, handles)
544
545%------------------------------------------------------------------------
546% --- Called by action in NomType edit box
547function NomType_Callback(hObject, eventdata, handles)
548%------------------------------------------------------------------------
549i1=str2num(get(handles.i1,'String'));
550i2=str2num(get(handles.i2,'String'));
551j1=str2num(get(handles.j1,'String'));
552j2=str2num(get(handles.j2,'String'));
553FileIndex=fullfile_uvmat('','','','',get(handles.NomType,'String'),i1,i2,j1,j2);
554set(handles.FileIndex,'String',FileIndex)
555% refresh the current settings and refresh the field view
556RootPath_Callback(hObject,eventdata,handles)
557
558%------------------------------------------------------------------------
559% --- Called by action in NomType edit box
560function NomType_1_Callback(hObject, eventdata, handles)
561%------------------------------------------------------------------------
562i1=str2num(get(handles.i1,'String'));
563i2=str2num(get(handles.i2,'String'));
564j1=str2num(get(handles.j1,'String'));
565j2=str2num(get(handles.j2,'String'));
566FileIndex=fullfile_uvmat('','','','',get(handles.NomType_1,'String'),i1,i2,j1,j2);
567set(handles.FileIndex_1,'String',FileIndex)
568% refresh the current settings and refresh the field view
569RootPath_1_Callback(hObject,eventdata,handles)
570
571%------------------------------------------------------------------------
572% --- Fills the edit boxes RootPath, RootFile,NomType...from an input file name 'fileinput'
573function display_file_name(handles,fileinput,index)
574%------------------------------------------------------------------------
575%% look for the input file existence
576if ~exist(fileinput,'file')
577    msgbox_uvmat('ERROR',['input file ' fileinput  ' does not exist'])
578    return
579end
580
581%% set the mouse pointer to 'watch'
582set(handles.uvmat,'Pointer','watch')
583set(handles.RootPath,'BackgroundColor',[1 1 0])
584drawnow
585
586%% define the relevant handles for the first field series (index=1) or the second file series (index=2)
587if ~exist('index','var')
588    index=1;
589end
590if index==1
591    handles_RootPath=handles.RootPath;
592    handles_SubDir=handles.SubDir;
593    handles_RootFile=handles.RootFile;
594    handles_FileIndex=handles.FileIndex;
595    handles_NomType=handles.NomType;
596    handles_FileExt=handles.FileExt;
597elseif index==2
598    handles_RootPath=handles.RootPath_1;
599    handles_SubDir=handles.SubDir_1;
600    handles_RootFile=handles.RootFile_1;
601    handles_FileIndex=handles.FileIndex_1;
602    handles_NomType=handles.NomType_1;
603    handles_FileExt=handles.FileExt_1;
604    set(handles.RootPath_1,'Visible','on')
605    set(handles.RootFile_1,'Visible','on')
606    set(handles.SubDir_1,'Visible','on');
607    set(handles.FileIndex_1,'Visible','on');
608    set(handles.FileExt_1,'Visible','on');
609    set(handles.NomType_1,'Visible','on');
610end
611
612%% detect root name, nomenclature and indices in the input file name:
613[FilePath,FileName,FileExt]=fileparts(fileinput);
614% detect the file type, get the movie object if relevant, and look for the corresponding file series:
615% the root name and indices may be corrected by including the first index i1 if a corresponding xml file exists
616[RootPath,SubDir,RootFile,i1_series,i2_series,j1_series,j2_series,NomType,FileType,MovieObject,i1,i2,j1,j2]=find_file_series(FilePath,[FileName FileExt]);
617
618%% open the file or fill the GUI uvmat according to the detected file type
619switch FileType
620    case ''
621        msgbox_uvmat('ERROR','invalid input file type')
622    case 'txt'
623        edit(fileinput)
624    case 'figure'                           %display matlab figure
625        hfig=open(fileinput);
626        set(hfig,'WindowButtonMotionFcn','mouse_motion')%set mouse action functio
627        set(hfig,'WindowButtonUpFcn','mouse_up')%set mouse click action function
628        set(hfig,'WindowButtonUpFcn','mouse_down')%set mouse click action function
629    case 'xml'                % edit xml files
630        t=xmltree(fileinput);
631        % the xml file marks a project or project link, open datatree_browser
632        if strcmp(get(t,1,'name'),'Project')&& exist(regexprep(fileinput,'.xml$',''),'dir')
633            datatree_browser(fileinput)
634        else % other xml file, open the xml editor
635            editxml(fileinput);
636        end
637    case 'xls'% Excel file opended by editxml
638        editxml(fileinput);
639    otherwise
640        set(handles_RootPath,'String',RootPath);
641        rootname=fullfile(RootPath,SubDir,RootFile);
642        set(handles_SubDir,'String',['/' SubDir]);
643        set(handles_RootFile,'String',['/' RootFile]); %display the separator
644        indices=fileinput(length(rootname)+1:end);
645        indices(end-length(FileExt)+1:end)=[]; %remove extension
646        set(handles_FileIndex,'String',indices);
647        set(handles_NomType,'String',NomType);
648        set(handles_FileExt,'String',FileExt);
649        if index==1
650            % fill file index counters if the first file series is opened
651            set(handles.i1,'String',num2str(i1));
652            set(handles.i2,'String',num2str(i2));
653            set(handles.j1,'String',num2stra(j1,NomType));
654            set(handles.j2,'String',num2stra(j2,NomType));
655        else %read the current field index to synchronise with the first series
656            i1_s=str2num(get(handles.i1,'String'));
657            i2_0=str2num(get(handles.i2,'String'));
658            if ~isempty(i2_0)
659                i2_s=i2_0;
660            else
661               i2_s=i2;
662            end
663            j1_0=stra2num(get(handles.j1,'String'));
664            if ~isempty(j1_0)
665                j1_s=j1_0;
666            else
667                j1_s=j1;
668            end
669            j2_0=stra2num(get(handles.j2,'String'));
670            if ~isempty(j2_0)
671                j2_s=j2_0;
672            else
673                j2_s=j2;
674            end
675        end
676       
677        % synchronise indices of the second  input file if it exists
678        if get(handles.SubField,'Value')==1% if the subfield button is activated, update the field numbers
679            Input=read_GUI(handles.InputFile);
680            if ~isfield(Input,'RootPath_1')||strcmp(Input.RootPath_1,'"')
681                Input.RootPath_1=Input.RootPath;
682            end
683            if ~isfield(Input,'SubDir_1')||strcmp(Input.SubDir_1,'"')
684                Input.SubDir_1=Input.SubDir;
685            end
686            if ~isfield(Input,'RootFile_1')||strcmp(Input.RootFile_1,'"')
687                Input.RootFile_1=Input.RootFile;
688            end
689            if ~isfield(Input,'FileExt_1')||strcmp(Input.FileExt_1,'"')
690                Input.FileExt_1=Input.FileExt;
691            end
692            if ~isfield(Input,'NomType_1')||strcmp(Input.NomType_1,'"')
693                Input.NomType_1=Input.NomType;
694            end
695            %updtate the indices of the second field series to correspond to the newly opened one
696            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);
697            if exist(FileName_1,'file')
698                FileIndex_1=fullfile_uvmat('','','','',Input.NomType_1,i1_s,i2_s,j1_s,j2_s);
699            else
700                FileIndex_1=fullfile_uvmat('','','','',Input.NomType_1,i1,i2,j1,j2);
701                msgbox_uvmat('WARNING','unable to synchronise the indices of the two series')
702            end
703            set(handles.FileIndex_1,'String',FileIndex_1)
704        end
705       
706        %enable other menus
707        set(handles.MenuOpen_1,'Enable','on')
708        set(handles.MenuFile_1_1,'Enable','on')
709        set(handles.MenuFile_2_1,'Enable','on')
710        set(handles.MenuFile_3_1,'Enable','on')
711        set(handles.MenuFile_4_1,'Enable','on')
712        set(handles.MenuFile_5_1,'Enable','on')
713        set(handles.MenuExport,'Enable','on')
714        set(handles.MenuExportFigure,'Enable','on')
715        set(handles.MenuExportMovie,'Enable','on')
716        set(handles.MenuTools,'Enable','on')
717
718        % initiate input file series and refresh the current field view:     
719        update_rootinfo(handles,i1_series,i2_series,j1_series,j2_series,FileType,MovieObject,index);
720
721end
722
723%% update list of recent files in the menubar and save it for future opening
724MenuFile=[{get(handles.MenuFile_1,'Label')};{get(handles.MenuFile_2,'Label')};...
725    {get(handles.MenuFile_3,'Label')};{get(handles.MenuFile_4,'Label')};{get(handles.MenuFile_5,'Label')}];
726str_find=strcmp(fileinput,MenuFile);
727if isempty(find(str_find,1))
728    MenuFile=[{fileinput};MenuFile];%insert the current file if not already in the list
729end
730for ifile=1:min(length(MenuFile),5)
731    eval(['set(handles.MenuFile_' num2str(ifile) ',''Label'',MenuFile{ifile});'])
732    eval(['set(handles.MenuFile_' num2str(ifile) '_1,''Label'',MenuFile{ifile});'])
733end
734dir_perso=prefdir;
735profil_perso=fullfile(dir_perso,'uvmat_perso.mat');
736if exist(profil_perso,'file')
737    save (profil_perso,'MenuFile','-append'); %store the file names for future opening of uvmat
738else
739    save (profil_perso,'MenuFile','-V6'); %store the file names for future opening of uvmat
740end
741
742%% set back the mouse pointer to arrow
743set(handles.uvmat,'Pointer','arrow')
744
745
746%------------------------------------------------------------------------
747% --- Update information about a new field series (indices to scan, timing,
748%     calibration from an xml file, then refresh current plots
749
750function update_rootinfo(handles,i1_series,i2_series,j1_series,j2_series,FileType,VideoObject,index)
751%------------------------------------------------------------------------
752%% define the relevant handles depending on the index (1=first file series, 2= second file series)
753if ~exist('index','var')
754    index=1;
755end
756if index==1
757    handles_RootPath=handles.RootPath;
758    handles_Fields=handles.FieldName;
759elseif index==2
760    handles_RootPath=handles.RootPath_1;
761    handles_Fields=handles.FieldName_1;
762end
763
764set(handles_RootPath,'BackgroundColor',[1 1 0])
765drawnow
766set(handles.FieldName,'UserData',[])% reinialize data from uvmat opening
767UvData=get(handles.uvmat,'UserData');%huvmat=handles of the uvmat interface
768UvData.NewSeries=1; %flag for run0: begin a new series
769UvData.FileName_1='';% name of the current second field (used to detect a  constant field during file scanning)
770UvData.FileType{index}=FileType;
771UvData.i1_series{index}=i1_series;
772UvData.i2_series{index}=i2_series;
773UvData.j1_series{index}=j1_series;
774UvData.j2_series{index}=j2_series;
775set(handles.FixVelType,'Value',0); %desactivate fixed veltype
776if index==1
777    [RootPath,SubDir,RootFile,FileIndices,FileExt]=read_file_boxes(handles);
778else
779    [RootPath,SubDir,RootFile,FileIndices,FileExt]=read_file_boxes_1(handles);
780end
781FileName=[fullfile(RootPath,SubDir,RootFile) FileIndices FileExt];
782FileBase=fullfile(RootPath,RootFile);
783if ~exist(FileName,'file')
784   msgbox_uvmat('ERROR',['input file ' FileName ' not found']);
785    return
786end
787
788%% read timing and total frame number from the current file (movie files) !! may be overrid by xml file
789XmlData.Time=[];%default
790XmlData.GeometryCalib=[];%default
791TimeUnit='';%default
792Time=[];
793% testima=0; %test for image input
794imainfo=[];
795ColorType='falsecolor'; %default
796% hhh=[];
797UvData.MovieObject{index}=VideoObject;
798if ~isempty(VideoObject)
799    imainfo=get(VideoObject);
800%     testima=1;
801    TimeUnit='s';
802    if isempty(j1_series); %frame index along i
803        Time=(0:1/imainfo.FrameRate:(imainfo.NumberOfFrames)/imainfo.FrameRate)';
804    else
805        Time=ones(size(i1_series,1),1)*(0:1/imainfo.FrameRate:(imainfo.NumberOfFrames)/imainfo.FrameRate);
806    end
807    set(handles.Dt_txt,'String',['Dt=' num2str(1000/imainfo.FrameRate) 'ms']);%display the elementary time interval in millisec
808    ColorType='truecolor';
809elseif ~isempty(FileExt(2:end))&&(~isempty(imformats(FileExt(2:end))) || isequal(FileExt,'.vol'))%&& isequal(NomType,'*')% multi-frame image
810%     testima=1;
811    if ~isequal(SubDir,'')
812        imainfo=imfinfo([fullfile(RootPath,SubDir,RootFile) FileIndices FileExt]);
813    else
814        imainfo=imfinfo([FileBase FileIndices FileExt]);
815    end
816    ColorType=imainfo.ColorType;%='truecolor' for color images
817end
818if isfield(imainfo,'Width') && isfield(imainfo,'Height')
819    if length(imainfo)>1
820        set(handles.num_Npx,'String',num2str(imainfo(1).Width));%fills nbre of pixels x box
821        set(handles.num_Npy,'String',num2str(imainfo(1).Height));%fills nbre of pixels x box
822    else
823        set(handles.num_Npx,'String',num2str(imainfo.Width));%fills nbre of pixels x box
824        set(handles.num_Npy,'String',num2str(imainfo.Height));%fills nbre of pixels x box
825    end
826else
827    set(handles.num_Npx,'String','');%fills nbre of pixels x box
828    set(handles.num_Npy,'String','');%fills nbre of pixels x box
829end
830set(handles.CheckBW,'Value',strcmp(ColorType,'grayscale'))% select handles.CheckBW if grayscale image
831
832%% read parameters (time, geometric calibration..) from a documentation file (.xml advised)
833XmlFileName=find_imadoc(RootPath,SubDir,RootFile,FileExt);
834[tild,tild,DocExt]=fileparts(XmlFileName);
835warntext='';%default warning message
836NbSlice=1;%default
837set(handles.RootPath,'BackgroundColor',[1 1 1])
838if ~isempty(XmlFileName)
839    set(handles.view_xml,'Visible','on')
840    set(handles.view_xml,'BackgroundColor',[1 1 0])
841    set(handles.view_xml,'String','view .xml')
842    drawnow
843    [XmlDataRead,warntext]=imadoc2struct(XmlFileName);
844    if ~isempty(warntext)
845        msgbox_uvmat('WARNING',warntext)
846    end
847    if isempty(XmlDataRead)
848        set(handles.view_xml,'Visible','off')
849    else
850        set(handles.view_xml,'String',['view ' DocExt])   
851        XmlData=XmlDataRead;
852        if isfield(XmlData,'TimeUnit')
853            if isfield(XmlData,'TimeUnit')&& ~isempty(XmlData.TimeUnit)
854                TimeUnit=XmlData.TimeUnit;
855            end
856        end
857        set(handles.view_xml,'BackgroundColor',[1 1 1])
858        drawnow
859        if isfield(XmlData, 'GeometryCalib') && ~isempty(XmlData.GeometryCalib)
860            if isfield(XmlData.GeometryCalib,'VolumeScan') && isequal(XmlData.GeometryCalib.VolumeScan,'y')
861                set (handles.num_NbSlice,'String','volume')
862            end
863            hgeometry_calib=findobj('tag','geometry_calib');
864            if ~isempty(hgeometry_calib)
865                GUserData=get(hgeometry_calib,'UserData');
866                if ~(isfield(GUserData,'XmlInputFile') && strcmp(GUserData.XmlInputFile,XmlFileName))
867                    answer=msgbox_uvmat('INPUT_Y-N','replace the display of geometry_calib with the new input data?');
868                    if strcmp(answer,'Yes')
869                        geometry_calib(XmlFileName);%diplay the new calibration points and parameters in geometry_calib
870                    end
871                end
872            end
873        end
874    end
875end
876if ~(isfield(XmlData,'Time')&& ~isempty(XmlData.Time))
877    XmlData.Time=Time; %time set by video
878end
879
880%% store last index in handles.lat_i and .last_j
881nbfield=max(max(max(i2_series)));
882if isempty(nbfield)
883    nbfield=max(max(max(i1_series)));
884end
885nbfield_j=max(max(max(j2_series)));
886if isempty(nbfield_j)
887    nbfield_j=max(max(max(j1_series)));
888end
889if ~isempty(XmlData.Time)
890    %transform .Time to a column vector if it is a line vector the nomenclature uses a single index
891    if isequal(size(XmlData.Time,1),1)
892        %NomType=get(handles.NomType,'String');
893        XmlData.Time=(XmlData.Time)';
894    end
895end
896last_i_cell=get(handles.last_i,'String');
897if isempty(nbfield)
898    last_i_cell{index}='';
899else
900    last_i_cell{index}=num2str(nbfield);
901end
902set(handles.last_i,'String',last_i_cell)
903last_j_cell=get(handles.last_j,'String');
904if isempty(nbfield_j)
905     last_j_cell{index}='';
906else
907     last_j_cell{index}=num2str(nbfield_j);
908end
909set(handles.last_j,'String',last_j_cell);
910
911%% store geometric calibration in UvData
912if isfield(XmlData,'GeometryCalib')
913    GeometryCalib=XmlData.GeometryCalib;
914    if isempty(GeometryCalib)
915        set(handles.pxcm,'String','')
916        set(handles.pycm,'String','')
917        set(handles.transform_fct,'Value',1); %  no transform by default
918    else
919        if (isfield(GeometryCalib,'R')&& ~isequal(GeometryCalib.R(2,1),0) && ~isequal(GeometryCalib.R(1,2),0)) ||...
920            (isfield(GeometryCalib,'kappa1')&& ~isequal(GeometryCalib.kappa1,0))
921            set(handles.pxcm,'String','var')
922            set(handles.pycm,'String','var')
923        elseif isfield(GeometryCalib,'fx_fy')
924            pixcmx=GeometryCalib.fx_fy(1);%*GeometryCalib.R(1,1)*GeometryCalib.sx/(GeometryCalib.Tz*GeometryCalib.dpx);
925            pixcmy=GeometryCalib.fx_fy(2);%*GeometryCalib.R(2,2)/(GeometryCalib.Tz*GeometryCalib.dpy);
926            set(handles.pxcm,'String',num2str(pixcmx))
927            set(handles.pycm,'String',num2str(pixcmy))
928        end
929        if ~get(handles.CheckFixLimits,'Value')
930            set(handles.transform_fct,'Value',3); % phys transform by default if fixedLimits is off
931        end
932        if isfield(GeometryCalib,'SliceCoord')           
933           siz=size(GeometryCalib.SliceCoord);
934           if siz(1)>1
935               NbSlice=siz(1);
936               set(handles.slices,'Visible','on')
937               set(handles.slices,'Value',1)
938           end
939           if isfield(GeometryCalib,'VolumeScan') && isequal(GeometryCalib.VolumeScan,'y')
940               set(handles.num_NbSlice,'String','volume')
941           else
942               set(handles.num_NbSlice,'String',num2str(NbSlice))
943           end
944           slices_Callback([],[], handles)
945        end           
946    end
947end
948
949%% update the data attached to the uvmat interface
950if ~isempty(TimeUnit)
951    set(handles.time_txt,'String',['time (' TimeUnit ')'])
952end
953UvData.TimeUnit=TimeUnit;
954UvData.XmlData{index}=XmlData;
955UvData.NewSeries=1;
956% UvData.MovieObject=MovieObject;
957
958%display warning message
959if ~isequal(warntext,'')
960    msgbox_uvmat('WARNING',warntext);
961end
962
963%% set default options in menu 'FieldName'
964switch FileType
965    case {'civx','civdata'}
966        [FieldList,ColorList]=calc_field;
967        set(handles_Fields,'String',[{'image'};FieldList;{'get_field...'}]);%standard menu for civx data
968        set(handles_Fields,'Value',2) % set menu to 'velocity
969        set(handles.ColorScalar,'Value',1)
970        set(handles.ColorScalar,'String',ColorList)
971        set(handles.Vectors,'Visible','on')
972        set(handles.Coord_x,'Value',1);
973        set(handles.Coord_x,'String',{'X'});
974        set(handles.Coord_y,'Value',1);
975        set(handles.Coord_y,'String',{'Y'});
976    case 'netcdf'
977        set(handles_Fields,'Value',1)
978        set(handles_Fields,'String',{'get_field...'})
979        hget_field=get_field(FileName);
980        hhget_field=guidata(hget_field);
981        get_field('RUN_Callback',hhget_field.RUN,[],hhget_field);
982    otherwise
983        set(handles_Fields,'Value',1) % set menu to 'image'
984        set(handles_Fields,'String',{'image'})
985        set(handles.Coord_x,'Value',1);
986        set(handles.Coord_x,'String',{'AX'});
987        set(handles.Coord_y,'Value',1);
988        set(handles.Coord_y,'String',{'AY'});
989end
990set(handles.uvmat,'UserData',UvData)
991
992%% set index navigation options and refresh plots
993scan_option='i';%default
994state_j='off'; %default
995if index==2
996    if get(handles.scan_j,'Value')
997        scan_option='j'; %keep the scan option for the second file series
998    end
999    if strcmp(get(handles.j1,'Visible'),'on')
1000        state_j='on';
1001    end
1002end
1003[ref_j,ref_i]=find(squeeze(i1_series(1,:,:)));
1004if ~isempty(j1_series)
1005        state_j='on';
1006        if index==1
1007            if isequal(ref_i,ref_i(1)*ones(size(ref_j)))% if ref_i is always equal to its first value
1008                scan_option='j'; %scan j indext               
1009            end
1010        end
1011end
1012if isequal(scan_option,'i')
1013    diff_ref_i=diff(ref_i,1);
1014    if isempty(diff_ref_i)
1015        diff_ref_i=1;
1016    end
1017    if isequal (diff_ref_i,diff_ref_i(1)*ones(size(diff_ref_i)))
1018        set(handles.num_IndexIncrement,'String',num2str(diff_ref_i(1)))
1019    end
1020     set(handles.scan_i,'Value',1)
1021     scan_i_Callback([],[], handles);
1022else
1023    diff_ref_j=diff(ref_j);
1024    if isempty(diff_ref_j)
1025        diff_ref_j=1;
1026    end
1027    if isequal (diff_ref_j,diff_ref_j(1)*ones(size(diff_ref_j)))
1028        set(handles.num_IndexIncrement,'String',num2str(diff_ref_j(1)))
1029    end
1030     set(handles.scan_j,'Value',1)
1031     scan_j_Callback([],[], handles);
1032end
1033set(handles.scan_j,'Visible',state_j)
1034set(handles.j1,'Visible',state_j)
1035set(handles.j2,'Visible',state_j)
1036set(handles.last_j,'Visible',state_j);
1037set(handles.frame_j,'Visible',state_j);
1038set(handles.j_text,'Visible',state_j);
1039if ~isempty(i2_series)||~isempty(j2_series)
1040    set(handles.CheckFixPair,'Visible','on')
1041elseif index==1
1042    set(handles.CheckFixPair,'Visible','off')
1043end
1044
1045%% apply the effect of the transform fct and view the field 
1046transform=get(handles.path_transform,'UserData');
1047if index==2 && (~isa(transform,'function_handle')||nargin(transform)<3)
1048    set(handles.transform_fct,'value',2); % set transform to sub_field if the current fct doe not accept two input fields
1049end
1050transform_fct_Callback([],[],handles)
1051mask_test=get(handles.CheckMask,'value');
1052if mask_test
1053    MaskData=get(handles.CheckMask,'UserData');
1054    if isfield(MaskData,'maskhandle') && ishandle(MaskData.maskhandle)
1055          delete(MaskData.maskhandle)    %delete old mask
1056    end
1057    CheckMask_Callback([],[],handles)
1058end
1059
1060%------------------------------------------------------------------------
1061% --- switch file index scanning options scan_i and scan_j in an exclusive way
1062function scan_i_Callback(hObject, eventdata, handles)
1063%------------------------------------------------------------------------
1064if get(handles.scan_i,'Value')==1
1065    set(handles.scan_i,'BackgroundColor',[1 1 0])
1066    set(handles.scan_j,'Value',0)
1067else
1068    set(handles.scan_i,'BackgroundColor',[0.831 0.816 0.784])
1069    set(handles.scan_j,'Value',1)
1070end
1071scan_j_Callback(hObject, eventdata, handles)
1072
1073%------------------------------------------------------------------------
1074% --- switch file index scanning options scan_i and scan_j in an exclusive way
1075function scan_j_Callback(hObject, eventdata, handles)
1076%------------------------------------------------------------------------
1077if get(handles.scan_j,'Value')==1
1078    set(handles.scan_j,'BackgroundColor',[1 1 0])
1079    set(handles.scan_i,'Value',0)
1080    set(handles.scan_i,'BackgroundColor',[0.831 0.816 0.784])
1081%     NomType=get(handles.NomType,'String');
1082%     switch NomType
1083%     case {'_1_1-2','#_ab','%3dab'},% pair with j index
1084%         set(handles.CheckFixPair,'Visible','on')% option fixed pair on/off made visible (choice of avaible pair with buttons + and - if ='off')
1085%     otherwise
1086%         set(handles.CheckFixPair,'Visible','off')
1087%     end
1088else
1089    set(handles.scan_j,'BackgroundColor',[0.831 0.816 0.784])
1090    set(handles.scan_i,'Value',1)
1091    set(handles.scan_i,'BackgroundColor',[1 1 0])
1092    set(handles.CheckFixPair,'Visible','off')
1093end
1094
1095%------------------------------------------------------------------------
1096function i1_Callback(hObject, eventdata, handles)
1097%------------------------------------------------------------------------
1098update_ij(handles,1)
1099
1100%------------------------------------------------------------------------
1101function i2_Callback(hObject, eventdata, handles)
1102%------------------------------------------------------------------------
1103update_ij(handles,2)
1104
1105%------------------------------------------------------------------------
1106function j1_Callback(hObject, eventdata, handles)
1107%------------------------------------------------------------------------
1108update_ij(handles,3)
1109
1110%------------------------------------------------------------------------
1111function j2_Callback(hObject, eventdata, handles)
1112%------------------------------------------------------------------------
1113update_ij(handles,4)
1114
1115%------------------------------------------------------------------------
1116%--- update the index display after action on edit boxes i1, i2, j1 or j2
1117function update_ij(handles,index_rank)
1118NomType=get(handles.NomType,'String');
1119indices=get(handles.FileIndex,'String');
1120[tild,tild,tild,i1,i2,j1,j2]=fileparts_uvmat(indices);% the indices for the second series taken from FileIndex
1121switch index_rank
1122    case 1
1123        indices=fullfile_uvmat('','','','',NomType,stra2num(get(handles.i1,'String')),i2,j1,j2);
1124        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
1125    case 2
1126        indices=fullfile_uvmat('','','','',NomType,i1,stra2num(get(handles.i2,'String')),j1,j2);
1127        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
1128    case 3
1129        indices=fullfile_uvmat('','','','',NomType,i1,i2,stra2num(get(handles.j1,'String')),j2);
1130        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
1131    case 4
1132        indices=fullfile_uvmat('','','','',NomType,i1,i2,j1,stra2num(get(handles.j2,'String')));
1133        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
1134end
1135set(handles.FileIndex,'String',indices)
1136set(handles.FileIndex,'BackgroundColor',[0.7 0.7 0.7])% mark the edit box in grey, then RUN0 will mark it in white for confirmation
1137% update the second index if relevant
1138if strcmp(get(handles.FileIndex_1,'Visible'),'on')
1139    NomType_1=get(handles.NomType_1,'String');
1140    indices_1=get(handles.FileIndex_1,'String');
1141    [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
1142    switch index_rank
1143        case 1
1144            indices_1=fullfile_uvmat('','','','',NomType_1,stra2num(get(handles.i1,'String')),i2_1,j1_1,j2_1);
1145        case 2
1146            indices_1=fullfile_uvmat('','','','',NomType_1,i1_1,stra2num(get(handles.i2,'String')),j1_1,j2_1);
1147        case 3
1148            indices_1=fullfile_uvmat('','','','',NomType_1,i1_1,i2_1,stra2num(get(handles.j1,'String')),j2_1);
1149        case 4
1150            indices_1=fullfile_uvmat('','','','',NomType_1,i1_1,i2_1,j1_1,stra2num(get(handles.j2,'String')));
1151    end
1152    set(handles.FileIndex_1,'String',indices_1)
1153    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
1154end
1155   
1156%------------------------------------------------------------------------
1157
1158%------------------------------------------------------------------------
1159function slices_Callback(hObject, eventdata, handles)
1160%------------------------------------------------------------------------
1161if get(handles.slices,'Value')==1
1162    set(handles.slices,'BackgroundColor',[1 1 0])
1163    set(handles.num_NbSlice,'Visible','on')
1164    set(handles.z_text,'Visible','on')
1165    set(handles.z_index,'Visible','on')
1166    num_NbSlice_Callback(hObject, eventdata, handles)
1167else
1168    set(handles.num_NbSlice,'Visible','off')
1169    set(handles.slices,'BackgroundColor',[0.7 0.7 0.7])
1170    set(handles.z_text,'Visible','off')
1171    set(handles.z_index,'Visible','off')
1172    set(handles.masklevel,'Value',1)
1173    set(handles.masklevel,'String',{'1'})
1174end
1175
1176%------------------------------------------------------------------------
1177function num_NbSlice_Callback(hObject, eventdata, handles)
1178%------------------------------------------------------------------------
1179nb_slice_str=get(handles.num_NbSlice,'String');
1180if isequal(nb_slice_str,'volume')
1181    num=stra2num(get(handles.j1,'String'));
1182    last_j=get(handles.last_j,'String');
1183    nbslice=str2double(last_j{1});
1184else
1185    num=str2double(get(handles.i1,'String'));
1186    nbslice=str2double(get(handles.num_NbSlice,'String'));
1187end
1188z=mod(num-1,nbslice)+1;
1189set(handles.z_index,'String',num2str(z))
1190for ilist=1:nbslice
1191    list_index{ilist,1}=num2str(ilist);
1192end   
1193set(handles.masklevel,'String',list_index)
1194set(handles.masklevel,'Value',z)
1195
1196%------------------------------------------------------------------------
1197% --- Executes on button press in view_xml.
1198function view_xml_Callback(hObject, eventdata, handles)
1199%------------------------------------------------------------------------
1200%[FileName,RootPath,FileBase,FileIndices,FileExt]=read_file_boxes(handles);
1201 [RootPath,SubDir,RootFile,FileIndices,FileExt]=read_file_boxes(handles);
1202FileBase=fullfile(RootPath,RootFile);
1203option=get(handles.view_xml,'String');
1204if isequal(option,'view .xml')
1205    FileXml=fullfile(RootPath,[SubDir '.xml']);
1206    if ~exist(FileXml,'file')% case of civ files , removes the extension for subdir
1207        FileXml=fullfile(RootPath,[regexprep(SubDir,'\..+$','') '.xml']);
1208    end
1209    heditxml=editxml(FileXml);
1210end
1211
1212%------------------------------------------------------------------------
1213% --- Executes on button press in CheckMask.
1214function CheckMask_Callback(hObject, eventdata, handles)
1215%------------------------------------------------------------------------
1216%case of view mask selection
1217if isequal(get(handles.CheckMask,'Value'),1)
1218     [RootPath,SubDir,RootFile,FileIndices,FileExt]=read_file_boxes(handles);
1219     FileBase=fullfile(RootPath,RootFile);
1220    num_i1=stra2num(get(handles.i1,'String'));
1221    num_j1=stra2num(get(handles.j1,'String'));
1222    currentdir=pwd; 
1223    cd(RootPath);
1224    maskfiles=dir('*_*mask_*.png');%look for a mask file
1225    cd(currentdir);%come back to the working directory
1226    mdetect=0;
1227    if ~isempty(maskfiles)
1228        for ilist=1:length(maskfiles)
1229            maskname=maskfiles(ilist).name;% take the first mask file in the list
1230            [tild,tild,tild,tild,tild,tild,tild,MaskExt,Mask_NomType{ilist}]=fileparts_uvmat(maskname);
1231             [tild,Name]=fileparts(maskname);
1232            Namedouble=double(Name);
1233            val=(48>Namedouble)|(Namedouble>57);% select the non-numerical characters
1234            ind_mask=findstr('mask',Name);
1235            i=ind_mask-1;
1236            while val(i)==0 && i>0
1237                i=i-1;
1238            end
1239            nbmask_str=str2num(Name(i+1:ind_mask-1));
1240            if ~isempty(nbmask_str)
1241                nbslice(ilist)=nbmask_str; % number of different masks (slices)
1242            end
1243        end
1244        if isequal(min(nbslice),max(nbslice))
1245            nbslice=nbslice(1);
1246        else
1247            msgbox_uvmat('ERROR','several inconsistent mask sets coexist in the current image directory')
1248            return
1249        end
1250        if ~isempty(nbslice) && Name(i)=='_'
1251            Mask.Base=[FileBase Name(i:ind_mask+3)];
1252            Mask.NbSlice=nbslice;
1253            num_i1=mod(num_i1-1,nbslice)+1;
1254            Mask.NomType=regexprep(Mask_NomType{1},'0','');%remove '0' in nom type for masks
1255            [RootPath,RootFile]=fileparts(Mask.Base);
1256            maskname=fullfile_uvmat(RootPath,'',RootFile,'.png',Mask.NomType,num_i1,[],num_j1);
1257            %maskname=name_generator(Mask.Base,num_i1,num_j1,'.png',Mask.NomType);%
1258            mdetect=exist(maskname,'file');
1259            if mdetect
1260                set(handles.num_NbSlice,'String',Name(i+1:ind_mask-1));
1261                set(handles.num_NbSlice,'BackgroundColor',[1 1 0])
1262                set(handles.CheckMask,'UserData',Mask);
1263                set(handles.CheckMask,'BackgroundColor',[1 1 0])
1264                if nbslice > 1
1265                    set(handles.slices,'value',1)
1266                    slices_Callback(hObject, eventdata, handles)
1267                end
1268            end
1269        end
1270    end
1271    errormsg=[];%default
1272    if mdetect==0
1273        [FileName, PathName, filterindex] = uigetfile( ...
1274            {'*.png', ' (*.png)';
1275            '*.png',  '.png files '; ...
1276            '*.*', 'All Files (*.*)'}, ...
1277            'Pick a mask file *.png',FileBase);
1278        if ~ischar(FileName),return,end %abandon if the browser is cancelled
1279        maskname=fullfile(PathName,FileName);
1280        [RootDir,SubDir,RootFile,tild,tild,tild,tild,tild,Mask.NomType]=fileparts_uvmat(maskname);
1281        Mask.Base=fullfile(RootDir,SubDir,RootFile);
1282        Mask.NbSlice=1;
1283        set(handles.CheckMask,'UserData',Mask);
1284        set(handles.CheckMask,'BackgroundColor',[1 1 0])
1285    end
1286    if isempty(errormsg)
1287        errormsg=update_mask(handles,num_i1,num_j1);
1288    end
1289    if ~isempty(errormsg)
1290            set(handles.CheckMask,'Value',0)
1291            set(handles.CheckMask,'BackgroundColor',[0.7 0.7 0.7])
1292     end
1293else % desactivate mask display
1294    MaskData=get(handles.CheckMask,'UserData');
1295    if isfield(MaskData,'maskhandle') && ishandle(MaskData.maskhandle)
1296          delete(MaskData.maskhandle)   
1297    end
1298    set(handles.CheckMask,'UserData',[])   
1299    UvData=get(handles.uvmat,'UserData');
1300    if isfield(UvData,'MaskName')
1301        UvData=rmfield(UvData,'MaskName');
1302        set(handles.uvmat,'UserData',UvData)
1303    end
1304    set(handles.CheckMask,'BackgroundColor',[0.7 0.7 0.7])
1305end
1306
1307%------------------------------------------------------------------------
1308function errormsg=update_mask(handles,num_i1,num_j1)
1309%------------------------------------------------------------------------
1310errormsg=[];%default
1311MaskData=get(handles.CheckMask,'UserData');
1312if isfield(MaskData,'maskhandle')&& ishandle(MaskData.maskhandle)
1313    uistack(MaskData.maskhandle,'top');
1314end
1315num_i1_mask=mod(num_i1-1,MaskData.NbSlice)+1;
1316[RootPath,RootFile]=fileparts(MaskData.Base);
1317MaskName=fullfile_uvmat(RootPath,'',RootFile,'.png',MaskData.NomType,num_i1_mask,[],num_j1);
1318UvData=get(handles.uvmat,'UserData');
1319%update mask image if the mask is new
1320if ~ (isfield(UvData,'MaskName') && isequal(UvData.MaskName,MaskName))
1321    UvData.MaskName=MaskName; %update the recorded name on UvData
1322    set(handles.uvmat,'UserData',UvData);
1323    if ~exist(MaskName,'file')
1324        if isfield(MaskData,'maskhandle')&& ishandle(MaskData.maskhandle)
1325            delete(MaskData.maskhandle)   
1326        end
1327    else
1328        %read mask image
1329        [Mask,tild,errormsg] = read_field(MaskName,'image');
1330%         Mask.AName='image';
1331%         Mask.A=imread(MaskName);
1332        if ~isempty(errormsg)
1333            return
1334        end
1335        npxy=size(Mask.A);
1336        if length(npxy)>2
1337            errormsg=[MaskName ' is not a grey scale image'];
1338            return
1339        elseif ~isa(Mask.A,'uint8')
1340            errormsg=[MaskName ' is not a 8 bit grey level image'];
1341            return
1342        end
1343%         Mask.AX=[0.5 npxy(2)-0.5];
1344%         Mask.AY=[npxy(1)-0.5 0.5 ];
1345%         Mask.CoordUnit='pixel';
1346        if isequal(get(handles.slices,'Value'),1)
1347           NbSlice=str2num(get(handles.num_NbSlice,'String'));
1348           num_i1=str2num(get(handles.i1,'String'));
1349           Mask.ZIndex=mod(num_i1-1,NbSlice)+1;
1350        end
1351        %px to phys or other transform on field
1352         menu_transform=get(handles.transform_fct,'String');
1353        choice_value=get(handles.transform_fct,'Value');
1354        transform_name=menu_transform{choice_value};%name of the transform fct  given by the menu 'transform_fct'
1355%         transform_list=get(handles.transform_fct,'UserData');
1356%         transform=transform_list{choice_value};
1357        transform=get(handles.path_transform,'UserData');
1358        if  ~isequal(transform_name,'') && ~isequal(transform_name,'px')
1359            if isfield(UvData,'XmlData') && isfield(UvData.XmlData{1},'GeometryCalib')%use geometry calib recorded from the ImaDoc xml file as first priority
1360                Calib=UvData.XmlData{1}.GeometryCalib;
1361                Mask=transform(Mask,UvData.XmlData{1});
1362            end
1363        end
1364        flagmask=Mask.A < 200;
1365       
1366        %make brown color image
1367        imflag(:,:,1)=0.9*flagmask;
1368        imflag(:,:,2)=0.7*flagmask;
1369        imflag(:,:,3)=zeros(size(flagmask));
1370       
1371        %update mask image
1372        hmask=[]; %default
1373        if isfield(MaskData,'maskhandle')&& ishandle(MaskData.maskhandle)
1374            hmask=MaskData.maskhandle;
1375        end
1376        if ~isempty(hmask)
1377            set(hmask,'CData',imflag)   
1378            set(hmask,'AlphaData',flagmask*0.6)
1379            set(hmask,'XData',Mask.AX);
1380            set(hmask,'YData',Mask.AY);
1381%             uistack(hmask,'top')
1382        else
1383            axes(handles.PlotAxes)
1384            hold on   
1385            size(flagmask)
1386           % MaskData.maskhandle=image(Mask.AX,Mask.AY,imflag,'Tag','mask','HitTest','off','AlphaData',0.6*flagmask);
1387            MaskData.maskhandle=image(Mask.AX,Mask.AY,imflag,'Tag','mask','HitTest','off','AlphaData',0.6*ones(size(flagmask)));
1388%             set(MaskData.maskhandle,'AlphaData',0.6*flagmask)
1389            set(handles.CheckMask,'UserData',MaskData)
1390        end
1391    end
1392end
1393
1394%------------------------------------------------------------------------
1395%------------------------------------------------------------------------
1396% III - MAIN REFRESH FUNCTIONS : 'FRAME PLOT'
1397%------------------------------------------------------------------------
1398
1399%------------------------------------------------------------------------
1400% --- Executes on button press in runplus: make one step forward and call
1401% --- run0. The step forward is along the fieldname series 1 or 2 depending on
1402% --- the scan_i and scan_j check box (exclusive each other)
1403function runplus_Callback(hObject, eventdata, handles)
1404%------------------------------------------------------------------------
1405set(handles.runplus,'BackgroundColor',[1 1 0])%paint the command button in yellow
1406drawnow
1407%TODO: introduce the option: increment ='*' to move to the next available view
1408increment=str2num(get(handles.num_IndexIncrement,'String')); %get the field increment d
1409% if isnan(increment)
1410%     set(handles.num_IndexIncrement,'String','1')%default value
1411%     increment=1;
1412% end
1413errormsg=runpm(hObject,eventdata,handles,increment);
1414if ~isempty(errormsg)
1415    msgbox_uvmat('ERROR',errormsg);
1416end
1417set(handles.runplus,'BackgroundColor',[1 0 0])%paint the command button back to red
1418
1419%------------------------------------------------------------------------
1420% --- Executes on button press in runmin: make one step backward and call
1421% --- run0. The step backward is along the fieldname series 1 or 2 depending on
1422% --- the scan_i and scan_j check box (exclusive each other)
1423function runmin_Callback(hObject, eventdata, handles)
1424%------------------------------------------------------------------------
1425set(handles.runmin,'BackgroundColor',[1 1 0])%paint the command button in yellow
1426drawnow
1427increment=-str2num(get(handles.num_IndexIncrement,'String')); %get the field increment d
1428% if isnan(increment)
1429%     set(handles.num_IndexIncrement,'String','1')%default value
1430%     increment=1;
1431% end
1432errormsg=runpm(hObject,eventdata,handles,increment);
1433if ~isempty(errormsg)
1434    msgbox_uvmat('ERROR',errormsg);
1435end
1436set(handles.runmin,'BackgroundColor',[1 0 0])%paint the command button back to red
1437
1438%------------------------------------------------------------------------
1439% -- Executes on button press in Movie: make a series of +> steps
1440function Movie_Callback(hObject, eventdata, handles)
1441%------------------------------------------------------------------------
1442set(handles.Movie,'BackgroundColor',[1 1 0])%paint the command button in yellow
1443drawnow
1444increment=str2num(get(handles.num_IndexIncrement,'String')); %get the field increment d
1445% if isnan(increment)
1446%     set(handles.num_IndexIncrement,'String','1')%default value
1447%     increment=1;
1448% end
1449set(handles.STOP,'Visible','on')
1450set(handles.speed,'Visible','on')
1451set(handles.speed_txt,'Visible','on')
1452set(handles.Movie,'BusyAction','queue')
1453UvData=get(handles.uvmat,'UserData');
1454
1455while get(handles.Movie,'Value')==1 && get(handles.speed,'Value')~=0 && isequal(get(handles.Movie,'BusyAction'),'queue') % enable STOP command
1456        errormsg=runpm(hObject,eventdata,handles,increment);
1457        if ~isempty(errormsg)
1458            set(handles.Movie,'BackgroundColor',[1 0 0])%paint the command buttonback to red
1459            return
1460        end
1461        pause(1.02-get(handles.speed,'Value'))% wait for next image
1462end
1463if isfield(UvData,'aviobj') && ~isempty( UvData.aviobj),
1464    UvData.aviobj=close(UvData.aviobj);
1465   set(handles.uvmat,'UserData',UvData);
1466end
1467set(handles.Movie,'BackgroundColor',[1 0 0])%paint the command buttonback to red
1468
1469%------------------------------------------------------------------------
1470% -- Executes on button press in Movie: make a series of <- steps
1471function MovieBackward_Callback(hObject, eventdata, handles)
1472%------------------------------------------------------------------------
1473set(handles.MovieBackward,'BackgroundColor',[1 1 0])%paint the command button in yellow
1474drawnow
1475increment=-str2num(get(handles.num_IndexIncrement,'String')); %get the field increment d
1476set(handles.STOP,'Visible','on')
1477set(handles.speed,'Visible','on')
1478set(handles.speed_txt,'Visible','on')
1479set(handles.MovieBackward,'BusyAction','queue')
1480UvData=get(handles.uvmat,'UserData');
1481
1482while get(handles.MovieBackward,'Value')==1 && get(handles.speed,'Value')~=0 && isequal(get(handles.MovieBackward,'BusyAction'),'queue') % enable STOP command
1483        errormsg=runpm(hObject,eventdata,handles,increment);
1484        if ~isempty(errormsg)
1485            set(handles.MovieBackward,'BackgroundColor',[1 0 0])%paint the command buttonback to red
1486            return
1487        end
1488        pause(1.02-get(handles.speed,'Value'))% wait for next image
1489end
1490if isfield(UvData,'aviobj') && ~isempty( UvData.aviobj),
1491    UvData.aviobj=close(UvData.aviobj);
1492   set(handles.uvmat,'UserData',UvData);
1493end
1494set(handles.MovieBackward,'BackgroundColor',[1 0 0])%paint the command buttonback to red
1495
1496%------------------------------------------------------------------------
1497function STOP_Callback(hObject, eventdata, handles)
1498%------------------------------------------------------------------------
1499set(handles.movie_pair,'BusyAction','Cancel')
1500set(handles.movie_pair,'value',0)
1501set(handles.Movie,'BusyAction','Cancel')
1502set(handles.MovieBackward,'BusyAction','Cancel')
1503set(handles.MenuExportMovie,'BusyAction','Cancel')
1504set(handles.movie_pair,'BackgroundColor',[1 0 0])%paint the command buttonback to red
1505set(handles.Movie,'BackgroundColor',[1 0 0])%paint the command buttonback to red
1506set(handles.MovieBackward,'BackgroundColor',[1 0 0])%paint the command buttonback to red
1507
1508%------------------------------------------------------------------------
1509% --- function activated by runplus and run minus
1510function errormsg=runpm(hObject,eventdata,handles,increment)
1511%------------------------------------------------------------------------
1512errormsg='';%default
1513%% check for movie pair status
1514movie_status=get(handles.movie_pair,'Value');
1515if isequal(movie_status,1)
1516    STOP_Callback(hObject, eventdata, handles)%interrupt movie pair if active
1517end
1518
1519%% read the current input file name(s) and field indices
1520InputFile=read_GUI(handles.InputFile);
1521InputFile.RootFile=regexprep(InputFile.RootFile,'^[\\/]|[\\/]$','');%suppress possible / or \ separator at the beginning or the end of the string
1522InputFile.SubDir=regexprep(InputFile.SubDir,'^[\\/]|[\\/]$','');%suppress possible / or \ separator at the beginning or the end of the string
1523FileExt=InputFile.FileExt;
1524NomType=get(handles.NomType,'String');
1525i1=str2num(get(handles.i1,'String'));%read the field indices (for movie, it is not given by the file name)
1526i2=[];%default
1527if strcmp(get(handles.i2,'Visible'),'on')
1528    i2=str2num(get(handles.i2,'String'));
1529end
1530j1=[];
1531if strcmp(get(handles.j1,'Visible'),'on')
1532    j1=stra2num(get(handles.j1,'String'));
1533end
1534j2=j1;
1535if strcmp(get(handles.j2,'Visible'),'on')
1536    j2=stra2num(get(handles.j2,'String'));
1537end
1538sub_value= get(handles.SubField,'Value');
1539if sub_value % a second input file has been entered
1540     [InputFile.RootPath_1,InputFile.SubDir_1,InputFile.RootFile_1,InputFile.FileIndex_1,InputFile.FileExt_1,InputFile.NomType_1]=read_file_boxes_1(handles);   
1541    [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
1542else
1543    filename_1=[];
1544end   
1545
1546%% increment (or decrement) the field indices and update the input filename(s)
1547if isempty(increment)
1548    set(handles.CheckFixPair,'Value',0)
1549end
1550CheckFixPair=get(handles.CheckFixPair,'Value')||(isempty(i2)&&isempty(j2));
1551
1552% the pair i1-i2 or j1-j2 is imposed (check box CheckFixPair selected)
1553        i1_1=i1;
1554        i2_1=i2;
1555        j1_1=j1;
1556        j2_1=j2;
1557if CheckFixPair
1558    if get(handles.scan_i,'Value')==1% case of scanning along index i
1559        i1=i1+increment;
1560        i2=i2+increment;
1561        if sub_value
1562            i1_1=i1_1+increment;
1563            i2_1=i2_1+increment;
1564        end
1565       
1566    else % case of scanning along index j (burst numbers)
1567        j1=j1+increment;
1568        j2=j2+increment;
1569        if sub_value
1570            j1_1=j1_1+increment;
1571            j2_1=j2_1+increment;
1572        end
1573    end
1574   
1575% the pair i1-i2 or j1-j2 is free (check box CheckFixPair not selected): the list of existing indices recorded in UvData is used
1576else
1577    UvData=get(handles.uvmat,'UserData');
1578    ref_i=i1;
1579    if ~isempty(i2)
1580        ref_i=floor((i1+i2)/2);% current reference index i
1581    end
1582    ref_j=1;
1583    if ~isempty(j1)
1584        ref_j=j1;
1585        if ~isempty(j2)
1586            ref_j=floor((j1+j2)/2);% current reference index j
1587        end
1588    end
1589    if ~isempty(increment)
1590        if get(handles.scan_i,'Value')==1% case of scanning along index i
1591            ref_i=ref_i+increment;% increment the current reference index i
1592        else % case of scanning along index j (burst numbers)
1593            ref_j=ref_j+increment;% increment the current reference index j if scan_j option is used
1594        end
1595    else % free increment
1596        runaction=get(gcbo,'tag');
1597        if strcmp(runaction,'runplus')||strcmp(runaction,'Movie')% if runplus or movie is activated
1598            step=1;
1599        else
1600            step=-1;
1601        end
1602        if get(handles.scan_i,'Value')==1% case of scanning along index i
1603            ref_i=ref_i+step;
1604            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
1605                ref_i=ref_i+step;
1606            end
1607        else % case of scanning along index j (burst numbers)
1608            ref_j=ref_j+step;
1609            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
1610                ref_j=ref_j+step;
1611            end
1612        end
1613    end
1614    if ref_i<0
1615        errormsg='minimum i index reached';
1616    elseif ref_j<0
1617        errormsg='minimum j index reached';
1618    elseif ref_i+1>size(UvData.i1_series{1},3)
1619        errormsg='maximum i index reached (reload the input file to update the index bound)';
1620    elseif ref_j+1>size(UvData.i1_series{1},2)
1621        errormsg='maximum j index reached (reload the input file to update the index bound)';
1622    end
1623    if ~isempty(errormsg),return,end
1624    siz=size(UvData.i1_series{1});
1625    ref_indices=ref_i*siz(1)*siz(2)+ref_j*siz(1)+1:ref_i*siz(1)*siz(2)+(ref_j+1)*siz(1);
1626    i1_subseries=UvData.i1_series{1}(ref_indices);
1627    ref_indices=ref_indices(i1_subseries>0);
1628    if isempty(ref_indices)% case of pairs (free index i)
1629        ref_indices=ref_i*siz(1)*siz(2)+1:(ref_i+1)*siz(1)*siz(2);
1630        i1_subseries=UvData.i1_series{1}(ref_indices);
1631        ref_indices=ref_indices(i1_subseries>0);
1632    end
1633    if isempty(ref_indices),errormsg='no next frame: set num_IndexIncrement =''*'' to reach the next existing file';return
1634    end
1635    i1=UvData.i1_series{1}(ref_indices(end));
1636    if ~isempty(UvData.i2_series{1})
1637        i2=UvData.i2_series{1}(ref_indices(end));
1638    end
1639    if ~isempty(UvData.j1_series{1})
1640        j1=UvData.j1_series{1}(ref_indices(end));
1641    end
1642    if ~isempty(UvData.j2_series{1})
1643        j2=UvData.j2_series{1}(ref_indices(end));
1644    end
1645   
1646    % case of a second file series
1647    if sub_value
1648        ref_i_1=i1_1;
1649        if ~isempty(i2_1)
1650            ref_i_1=floor((i1_1+i2_1)/2);% current reference index i
1651        end
1652        ref_j_1=1;
1653        if ~isempty(j1_1)
1654            ref_j_1=j1_1;
1655            if ~isempty(j2_1)
1656                ref_j_1=floor((j1_1+j2_1)/2);% current reference index j
1657            end
1658        end
1659        if ~isempty(increment)
1660            if get(handles.scan_i,'Value')==1% case of scanning along index i
1661                ref_i_1=ref_i_1+increment;% increment the current reference index i
1662            else % case of scanning along index j (burst numbers)
1663                ref_j_1=ref_j_1+increment;% increment the current reference index j if scan_j option is used
1664            end
1665        else % free increment, synchronise the ref indices with the first series
1666            ref_i_1=ref_i;
1667            ref_j_1=ref_j;
1668        end
1669        if numel(UvData.i1_series)==1
1670            UvData.i1_series{2}=UvData.i1_series{1};
1671            UvData.j1_series{2}=UvData.j1_series{1};
1672            UvData.i2_series{2}=UvData.i2_series{1};
1673            UvData.j2_series{2}=UvData.j2_series{1};
1674        end
1675        if ref_i_1<0
1676            errormsg='minimum i index reached';
1677        elseif ref_j_1<0
1678            errormsg='minimum j index reached';
1679        elseif ref_i_1+1>size(UvData.i1_series{2},3)
1680            errormsg='maximum i index reached for the second series (reload the input file to update the index bound)';
1681        elseif ref_j_1+1>size(UvData.i1_series{2},2)
1682            errormsg='maximum j index reached for the second series(reload the input file to update the index bound)';
1683        end
1684        if ~isempty(errormsg),return,end
1685        siz=size(UvData.i1_series{2});
1686        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);
1687        i1_subseries=UvData.i1_series{2}(ref_indices);
1688        ref_indices=ref_indices(i1_subseries>0);
1689        if isempty(ref_indices)% case of pairs (free index i)
1690            ref_indices=ref_i_1*siz(1)*siz(2)+1:(ref_i_1+1)*siz(1)*siz(2);
1691            i1_subseries=UvData.i1_series{2}(ref_indices);
1692            ref_indices=ref_indices(i1_subseries>0);
1693        end
1694        i1_1=UvData.i1_series{2}(ref_indices(end));
1695        if ~isempty(UvData.i2_series{2})
1696            i2_1=UvData.i2_series{2}(ref_indices(end));
1697        end
1698        if ~isempty(UvData.j1_series{2})
1699            j1_1=UvData.j1_series{2}(ref_indices(end));
1700        end
1701        if ~isempty(UvData.j2_series{2})
1702            j2_1=UvData.j2_series{1}(ref_indices(end));
1703        end   
1704    else% the second series (if needed) is the same file as the first
1705        i1_1=i1;
1706        i2_1=i2;
1707        j1_1=j1;
1708        j2_1=j2;
1709    end
1710end
1711filename=fullfile_uvmat(InputFile.RootPath,InputFile.SubDir,InputFile.RootFile,FileExt,NomType,i1,i2,j1,j2);
1712if sub_value
1713    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);
1714end
1715
1716%% refresh plots
1717errormsg=refresh_field(handles,filename,filename_1,i1,i2,j1,j2,i1_1,i2_1,j1_1,j2_1);
1718
1719%% update the index counters if the index move is successfull
1720if isempty(errormsg)
1721    set(handles.i1,'String',num2stra(i1,NomType,1));
1722    if isequal(i2,i1)
1723        set(handles.i2,'String','');
1724    else
1725        set(handles.i2,'String',num2stra(i2,NomType,1));
1726    end
1727    set(handles.j1,'String',num2stra(j1,NomType,2));
1728    if isequal(j2,j1)
1729        set(handles.j2,'String','');
1730    else
1731        set(handles.j2,'String',num2stra(j2,NomType,2));
1732    end
1733    indices=fullfile_uvmat('','','','',NomType,i1,i2,j1,j2);
1734    set(handles.FileIndex,'String',indices);
1735    if ~isempty(filename_1)
1736        indices_1=fullfile_uvmat('','','','',InputFile.NomType_1,i1_1,i2_1,j1_1,j2_1);
1737        set(handles.FileIndex_1,'String',indices_1);
1738    end
1739    if isequal(movie_status,1)
1740        set(handles.movie_pair,'Value',1)
1741        movie_pair_Callback(hObject, eventdata, handles); %reactivate moviepair if it was activated
1742    end
1743end
1744
1745%------------------------------------------------------------------------
1746% --- Executes on button press in movie_pair: create an alternating movie with two view
1747function movie_pair_Callback(hObject, eventdata, handles)
1748%------------------------------------------------------------------------
1749%% stop movie action if the movie_pair button is off
1750if ~get(handles.movie_pair,'value')
1751    set(handles.movie_pair,'BusyAction','Cancel')%stop movie pair if button is 'off'
1752    set(handles.i2,'String','')
1753    set(handles.j2,'String','')
1754    return
1755else
1756    set(handles.movie_pair,'BusyAction','queue')
1757end
1758
1759%% initialisation
1760set(handles.movie_pair,'BackgroundColor',[1 1 0])%paint the command button in yellow
1761drawnow
1762list_fields=get(handles.FieldName,'String');% list menu fields
1763index_fields=get(handles.FieldName,'Value');% selected string index
1764FieldName=list_fields{index_fields}; % selected field
1765UvData=get(handles.uvmat,'UserData');
1766if isequal(FieldName,'image')
1767    index=1;
1768    [RootPath,SubDir,RootFile,FileIndices,Ext]=read_file_boxes(handles);
1769    NomType=get(handles.NomType,'String');
1770else
1771    list_fields=get(handles.FieldName_1,'String');% list menu fields
1772    index_fields=get(handles.FieldName_1,'Value');% selected string index
1773    FieldName=list_fields{index_fields}; % selected field
1774    if isequal(FieldName,'image')
1775        index=2;
1776        [RootPath,tild,RootFile,FileIndex_1,Ext,NomType]=read_file_boxes_1(handles);
1777    else
1778        msgbox_uvmat('ERROR','an image or movie must be first introduced as input')
1779        set(handles.movie_pair,'BackgroundColor',[1 0 0])%paint the command button in red
1780        set(handles.movie_pair,'Value',0)
1781        return
1782    end
1783end
1784num_i1=str2num(get(handles.i1,'String'));
1785num_j1=stra2num(get(handles.j1,'String'));
1786num_i2=str2num(get(handles.i2,'String'));
1787num_j2=stra2num(get(handles.j2,'String'));
1788if isempty(num_j2)
1789    if isempty(num_i2)   
1790        msgbox_uvmat('ERROR', 'a second image index i2 or j2 is needed to show the pair as a movie')
1791        set(handles.movie_pair,'BackgroundColor',[1 0 0])%paint the command button in red
1792         set(handles.movie_pair,'Value',0)
1793        return
1794    else
1795        num_j2=num_j1;%repeat the index i1 by default
1796    end
1797end
1798if isempty(num_i2)
1799    num_i2=num_i1;%repeat the index i1 by default
1800end
1801imaname_1=fullfile_uvmat(RootPath,SubDir,RootFile,Ext,NomType,num_i2,[],num_j2);
1802if strcmp(NomType,'*')
1803    num_frame=num_i2;
1804else
1805    num_frame=num_j2;
1806end
1807if ~exist(imaname_1,'file')
1808      msgbox_uvmat('ERROR',['second input open (-)  ' imaname_1 ' not found']);
1809      set(handles.movie_pair,'BackgroundColor',[1 0 0])%paint the command button in red
1810       set(handles.movie_pair,'Value',0)
1811      return
1812end
1813
1814%% get the first image
1815%Field.AName='image';
1816if index==1
1817    Field_a=UvData.Field;% movie on the second field
1818else
1819    Field_a=UvData.Field_1;% movie on the first field
1820end
1821
1822%% read the second image
1823MovieObject=[];
1824if numel(UvData.MovieObject)>=index
1825    MovieObject=UvData.MovieObject{index};
1826end
1827[Field_b,ParamOut,errormsg] = read_field(imaname_1,UvData.FileType{index},MovieObject,num_frame);
1828% Field_b.AX=Field_a.AX;
1829% Field_b.AY=Field_a.AY;
1830% % z index
1831% nbslice=str2double(get(handles.num_NbSlice,'String'));
1832% if ~isempty(nbslice)
1833%     Field_b.ZIndex=mod(num_i2-1,nbslice)+1;
1834% end
1835% Field_b.CoordUnit='pixel';
1836%
1837% %% determine the input file type
1838% if (test_1 && isfield(UvData,'MovieObject')&& numel(UvData.MovieObject>=2))||(~test_1 && ~isempty(UvData.MovieObject{1}))
1839%     FileType='movie';
1840% elseif isequal(lower(Ext),'.avi')
1841%     FileType='avi';
1842% elseif isequal(lower(Ext),'.vol')
1843%     FileType='vol';
1844% else
1845%    form=imformats(Ext(2:end));
1846%    if ~isempty(form)% if the extension corresponds to an image format recognized by Matlab
1847%        if isequal(NomType,'*');
1848%            FileType='multimage';
1849%        else
1850%            FileType='image';
1851%        end
1852%    end
1853% end
1854% switch FileType
1855%         case 'movie'
1856%             if test_1
1857%                 Field_b.A=read(UvData.MovieObject{2},num_i2);
1858%             else
1859%                 Field_b.A=read(UvData.MovieObject{1},num_i2);
1860%             end
1861%         case 'avi'
1862%             mov=aviread(imaname_1,num_i2);
1863%             Field_b.A=frame2im(mov(1));
1864%         case 'vol'
1865%             Field_b.A=imread(imaname_1);
1866%         case 'multimage'
1867%             Field_b.A=imread(imaname_1,num_i2);
1868%         case 'image'
1869%             Field_b.A=imread(imaname_1);
1870% end
1871% if get(handles.slices,'Value')
1872%     Field.ZIndex=str2double(get(handles.z_index,'String'));
1873% end
1874
1875%px to phys or other transform on field
1876% menu_transform=get(handles.transform_fct,'String');
1877% choice_value=get(handles.transform_fct,'Value');
1878% transform_name=menu_transform{choice_value};%name of the transform fct  given by the menu 'transform_fct'
1879% transform_list=get(handles.transform_fct,'UserData');
1880transform=get(handles.path_transform,'UserData');
1881if  ~isempty(transform)
1882    if isfield(UvData,'XmlData') && numel(UvData.XmlData)>=index %use geometry calib recorded from the ImaDoc xml file as first priority
1883        if index==2
1884        Field_a=transform(Field_a,UvData.XmlData{index});%the first field has been stored without transform
1885        end
1886        Field_b=transform(Field_b,UvData.XmlData{index});
1887    end
1888end
1889
1890 % make movie until movie speed is set to 0 or STOP is activated
1891hima=findobj(handles.PlotAxes,'Tag','ima');% %handles.PlotAxes =main plotting window (A GENERALISER)
1892set(handles.STOP,'Visible','on')
1893set(handles.speed,'Visible','on')
1894set(handles.speed_txt,'Visible','on')
1895while get(handles.speed,'Value')~=0 && isequal(get(handles.movie_pair,'BusyAction'),'queue')%isequal(get(handles.run0,'BusyAction'),'queue'); % enable STOP command
1896    % read and plot the series of images in non erase mode
1897    set(hima,'CData',Field_b.A);
1898    pause(1.02-get(handles.speed,'Value'));% wait for next image
1899    set(hima,'CData',Field_a.A);
1900    pause(1.02-get(handles.speed,'Value'));% wait for next image
1901end
1902set(handles.movie_pair,'BackgroundColor',[1 0 0])%paint the command button in red
1903 set(handles.movie_pair,'Value',0)
1904
1905%------------------------------------------------------------------------
1906% --- Executes on button press in run0.
1907function run0_Callback(hObject, eventdata, handles)
1908%------------------------------------------------------------------------
1909set(handles.run0,'BackgroundColor',[1 1 0])%paint the command button in yellow
1910drawnow
1911[RootPath,SubDir,RootFile,FileIndex,FileExt]=read_file_boxes(handles);
1912filename=[fullfile(RootPath,SubDir,RootFile) FileIndex FileExt];
1913filename_1='';%default
1914FileIndex_1='';
1915if get(handles.SubField,'Value')
1916    [RootPath_1,SubDir_1,RootFile_1,FileIndex_1,FileExt_1]=read_file_boxes_1(handles);
1917    filename_1=[fullfile(RootPath_1,SubDir_1,RootFile_1) FileIndex_1 FileExt_1];
1918end
1919num_i1=stra2num(get(handles.i1,'String'));
1920num_i2=stra2num(get(handles.i2,'String'));
1921num_j1=stra2num(get(handles.j1,'String'));
1922num_j2=stra2num(get(handles.j2,'String'));
1923[tild,tild,tild,i1_1,i2_1,j1_1,j2_1]=fileparts_uvmat(FileIndex_1);
1924
1925errormsg=refresh_field(handles,filename,filename_1,num_i1,num_i2,num_j1,num_j2,i1_1,i2_1,j1_1,j2_1);
1926
1927if ~isempty(errormsg)
1928      msgbox_uvmat('ERROR',errormsg);
1929else
1930    set(handles.i1,'BackgroundColor',[1 1 1])
1931    set(handles.i2,'BackgroundColor',[1 1 1])
1932    set(handles.j1,'BackgroundColor',[1 1 1])
1933    set(handles.j2,'BackgroundColor',[1 1 1])
1934    set(handles.FileIndex,'BackgroundColor',[1 1 1])
1935    set(handles.FileIndex_1,'BackgroundColor',[1 1 1])
1936end   
1937set(handles.run0,'BackgroundColor',[1 0 0])
1938
1939
1940%------------------------------------------------------------------------
1941% --- read the input files and refresh all the plots, including projection.
1942% OUTPUT:
1943%  errormsg: error message char string  =[] by default
1944% INPUT:
1945% filename: first input file (=[] in the absence of input file)
1946% filename_1: second input file (=[] in the asbsenc of secodn input file)
1947% num_i1,num_i2,num_j1,num_j2; frame indices
1948% Field: structure describing an optional input field (then replace the input file)
1949
1950function errormsg=refresh_field(handles,FileName,FileName_1,num_i1,num_i2,num_j1,num_j2,i1_1,i2_1,j1_1,j2_1)
1951%------------------------------------------------------------------------
1952
1953%% initialisation
1954abstime=[];
1955abstime_1=[];
1956dt=[];
1957if ~exist('Field','var')
1958    Field={};
1959end
1960UvData=get(handles.uvmat,'UserData');
1961if ishandle(handles.UVMAT_title) %remove title panel on uvmat
1962    delete(handles.UVMAT_title)
1963end
1964
1965%% determine the main input file information for action
1966if ~exist(FileName,'file')
1967    errormsg=['input file ' FileName ' does not exist'];
1968    return
1969end
1970NomType=get(handles.NomType,'String');
1971NomType_1='';
1972if strcmp(get(handles.NomType_1,'Visible'),'on')
1973    NomType_1=get(handles.NomType_1,'String');
1974end
1975%update the z position index
1976nbslice_str=get(handles.num_NbSlice,'String');
1977if isequal(nbslice_str,'volume')%NOT USED
1978    z_index=num_j1;
1979    set(handles.z_index,'String',num2str(z_index))
1980else
1981    nbslice=str2num(nbslice_str);
1982    z_index=mod(num_i1-1,nbslice)+1;
1983    set(handles.z_index,'String',num2str(z_index))
1984end
1985% refresh menu for save_mask if relevant
1986masknumber=get(handles.masklevel,'String');
1987if length(masknumber)>=z_index
1988    set(handles.masklevel,'Value',z_index)
1989end
1990
1991%% test for need of tps
1992check_proj_tps=0;
1993if  (strcmp(UvData.FileType{1},'civdata')||strcmp(UvData.FileType{1},'civx'))
1994    for iobj=1:numel(UvData.Object)
1995        if isfield(UvData.Object{iobj},'ProjMode')&& strcmp(UvData.Object{iobj}.ProjMode,'filter')
1996            check_proj_tps=1;
1997            break
1998        end
1999    end
2000end
2001
2002%% read the first input field
2003ParamIn.ColorVar='';%default variable name for vector color
2004frame_index=1;%default
2005FieldName='';%default
2006VelType='';%default
2007switch UvData.FileType{1}
2008    case {'civx','civdata','netcdf'};
2009        list_fields=get(handles.FieldName,'String');% list menu fields
2010        FieldName= list_fields{get(handles.FieldName,'Value')}; % selected field
2011        if ~strcmp(FieldName,'get_field...')
2012            if get(handles.FixVelType,'Value')
2013                VelTypeList=get(handles.VelType,'String');
2014                VelType=VelTypeList{get(handles.VelType,'Value')};
2015            end
2016        end
2017        if ~isempty(regexp(FieldName,'^vec('))
2018            list_code=get(handles.ColorCode,'String');% list menu fields
2019            index_code=get(handles.ColorCode,'Value');% selected string index
2020            if  ~strcmp(list_code{index_code},'black') &&  ~strcmp(list_code{index_code},'white')
2021                list_code=get(handles.ColorScalar,'String');% list menu fields
2022                index_code=get(handles.ColorScalar,'Value');% selected string index
2023                ParamIn.ColorVar= list_code{index_code}; % selected field
2024            end
2025        end
2026    case {'video','mmreader'}
2027        ParamIn=UvData.MovieObject{1};     
2028        if ~strcmp(NomType,'*')
2029            frame_index=num_j1;%frame index for movies or multimage
2030        else
2031            frame_index=num_i1;
2032        end
2033    case 'multimage'
2034        if ~strcmp(NomType,'*')
2035            frame_index=num_j1;%frame index for movies or multimage
2036        else
2037            frame_index=num_i1;
2038        end
2039    case 'vol' %TODO: update
2040        if isfield(UvData.XmlData,'Npy') && isfield(UvData.XmlData,'Npx')
2041            ParamIn.Npy=UvData.XmlData.Npy;
2042            ParamIn.Npx=UvData.XmlData.Npx;
2043        else           
2044            errormsg='Npx and Npy need to be defined in the xml file for volume images .vol';
2045            return
2046        end
2047end
2048if isstruct (ParamIn)
2049    ParamIn.FieldName=FieldName;
2050    ParamIn.VelType=VelType;
2051    XNameMenu=get(handles.Coord_x,'String');
2052    ParamIn.Coord_x=XNameMenu(get(handles.Coord_x,'Value'));
2053    YNameMenu=get(handles.Coord_y,'String');
2054    ParamIn.Coord_y=YNameMenu(get(handles.Coord_y,'Value'));
2055end
2056check_tps = 0;         
2057if strcmp(UvData.FileType{1},'civdata')&&~strcmp(ParamIn.FieldName,'velocity')&&~strcmp(ParamIn.FieldName,'get_field...')
2058       check_tps=1;%tps needed to get the requested field
2059end
2060[Field{1},ParamOut,errormsg] = read_field(FileName,UvData.FileType{1},ParamIn,frame_index);
2061if ~isempty(errormsg)
2062    errormsg=['uvmat / refresh_field / read_field( ' FileName ') / ' errormsg];
2063    return
2064end 
2065if isfield(ParamOut,'Npx')&& isfield(ParamOut,'Npy')
2066    set(handles.num_Npx,'String',num2str(ParamOut.Npx));% display image size on the interface
2067    set(handles.num_Npy,'String',num2str(ParamOut.Npy));
2068end
2069if isfield(ParamOut,'TimeIndex')% case of time obtained from get_field
2070    set(handles.i1,'String',num2str(ParamOut.TimeIndex))
2071end
2072if isfield(ParamOut,'TimeValue')
2073    Field{1}.Time=ParamOut.TimeValue;% case of time obtained from get_field
2074end
2075Field{1}.ZIndex=z_index; %used for multiplane 3D calibration
2076% end
2077
2078%% choose and read a second field FileName_1 if defined
2079VelType_1=[];%default
2080FieldName_1=[];
2081ParamIn_1=[];
2082ParamOut_1=[];
2083frame_index_1=1;
2084if ~isempty(FileName_1)
2085    if ~exist(FileName_1,'file')
2086        errormsg=['second file ' FileName_1 ' does not exist'];
2087        return
2088    end
2089    Name=FileName_1;
2090    switch UvData.FileType{2}
2091        case {'civx','civdata','netcdf'};
2092            list_fields=get(handles.FieldName_1,'String');% list menu fields
2093            if ischar(list_fields),list_fields={list_fields};end
2094            FieldName_1= list_fields{get(handles.FieldName_1,'Value')}; % selected field
2095            if ~strcmp(FieldName,'get_field...')
2096                if get(handles.FixVelType,'Value')
2097                    VelTypeList=get(handles.VelType_1,'String');
2098                    VelType_1=VelTypeList{get(handles.VelType_1,'Value')};% read the velocity type.
2099                end
2100            end
2101            if strcmp(FieldName_1,'velocity')&& strcmp(get(handles.ColorCode,'Visible'),'on')
2102                list_code=get(handles.ColorCode,'String');% list menu fields
2103                index_code=get(handles.ColorCode,'Value');% selected string index
2104                if  ~strcmp(list_code{index_code},'black') &&  ~strcmp(list_code{index_code},'white')
2105                    list_code=get(handles.ColorScalar,'String');% list menu fields
2106                    index_code=get(handles.ColorScalar,'Value');% selected string index
2107                    ParamIn_1.ColorVar= list_code{index_code}; % selected field for vector color display                 
2108                end
2109            end
2110        case {'video','mmreader'}
2111            ParamIn_1=UvData.MovieObject{2};
2112                        if ~strcmp(NomType_1,'*')
2113                frame_index_1=j1_1;%frame index for movies or multimage
2114            else
2115                frame_index_1=i1_1;
2116            end 
2117         case 'multimage'
2118            if ~strcmp(NomType_1,'*')
2119                frame_index_1=j1_1;%frame index for movies or multimage
2120            else
2121                frame_index_1=i1_1;
2122            end   
2123        case 'vol' %TODO: update
2124            if isfield(UvData.XmlData,'Npy') && isfield(UvData.XmlData,'Npx')
2125                ParamIn_1.Npy=UvData.XmlData.Npy;
2126                ParamIn_1.Npx=UvData.XmlData.Npx;
2127            else
2128                errormsg='Npx and Npy need to be defined in the xml file for volume images .vol';
2129                return
2130            end
2131    end
2132    if isequal(get(handles.NomType_1,'Visible'),'on')
2133    NomType_1=get(handles.NomType_1,'String');
2134    else
2135        NomType_1=get(handles.NomType,'String');
2136    end
2137    test_keepdata_1=0;% test for keeping the previous stored data if the input files are unchanged
2138    if ~isequal(NomType_1,'*')&& isfield(UvData,'FileName_1')
2139           test_keepdata_1= strcmp(FileName_1,UvData.FileName_1) ;%&& strcmp(FieldName_1,UvData.FieldName_1);
2140    end
2141    if test_keepdata_1
2142        Field{2}=UvData.Field_1;% keep the stored field
2143        ParamOut_1=UvData.ParamOut_1;
2144    else
2145        if isempty(ParamIn_1) || isstruct(ParamIn_1)
2146        ParamIn_1.FieldName=FieldName_1;
2147        ParamIn_1.VelType=VelType_1;
2148        ParamIn_1.GUIName='get_field_1';
2149        end 
2150        [Field{2},ParamOut_1,errormsg] = read_field(Name,UvData.FileType{2},ParamIn_1,frame_index_1);
2151        if ~isempty(errormsg)
2152            errormsg=['error in reading ' FieldName_1 ' in ' FileName_1 ': ' errormsg];
2153            return
2154        end
2155        if isstruct(ParamOut_1)&&~strcmp(ParamOut_1.FieldName,'get_field...')&& (strcmp(UvData.FileType{2},'civdata')||strcmp(UvData.FileType{2},'civx'))...
2156                &&~strcmp(ParamOut_1.FieldName,'velocity') && ~strcmp(ParamOut_1.FieldName,'get_field...')
2157            if ~check_proj_tps
2158             %   Field{2}=calc_field([{ParamOut_1.FieldName} {ParamOut_1.ColorVar}],Field{2});
2159            end
2160        end
2161    end
2162    Field{2}.ZIndex=z_index;%used for multi-plane 3D calibration
2163end
2164
2165%% update uvmat interface
2166if isfield(ParamOut,'Npx')
2167    set(handles.num_Npx,'String',num2str(ParamOut.Npx));% display image size on the interface
2168    set(handles.num_Npy,'String',num2str(ParamOut.Npy));
2169elseif isfield(ParamOut_1,'Npx')
2170    set(handles.num_Npx,'String',num2str(ParamOut_1.Npx));% display image size on the interface
2171    set(handles.num_Npy,'String',num2str(ParamOut_1.Npy));
2172end
2173
2174%% update the display menu for the first velocity type (first menuline)
2175test_veltype=0;
2176% if ~isequal(FileType,'netcdf')|| isequal(FieldName,'get_field...')
2177if (strcmp(UvData.FileType{1},'civx')||strcmp(UvData.FileType{1},'civdata'))&& ~strcmp(FieldName,'get_field...')
2178    test_veltype=1;
2179    set(handles.VelType,'Visible','on')
2180    set(handles.VelType_1,'Visible','on')
2181    set(handles.FixVelType,'Visible','on')
2182    menu=set_veltype_display(ParamOut.CivStage,UvData.FileType{1});
2183    index_menu=strcmp(ParamOut.VelType,menu);%look for VelType in  the menu
2184    index_val=find(index_menu,1);
2185    if isempty(index_val)
2186        index_val=1;
2187    end
2188    set(handles.VelType,'Value',index_val)
2189    if ~get(handles.SubField,'value')
2190        set(handles.VelType,'String',menu)
2191        set(handles.VelType_1,'Value',1)
2192        set(handles.VelType_1,'String',[{''};menu])
2193    end
2194else
2195    set(handles.VelType,'Visible','off')
2196end
2197% display the FieldName menu from the input file and pick the selected one:
2198% if isstruct(ParamOut)
2199%     field_index=strcmp(ParamOut.FieldName,ParamOut.FieldList);
2200%     set(handles.FieldName,'String',ParamOut.FieldList); %update the field menu
2201%     set(handles.FieldName,'Value',find(field_index,1))
2202% end
2203
2204%% update the display menu for the second velocity type (second menuline)
2205test_veltype_1=0;
2206if isempty(FileName_1)
2207%     set(handles.FieldName_1,'Value',1); %update the field menu
2208%     if isstruct(ParamOut)
2209%     set(handles.FieldName_1,'String',[{''};ParamOut.FieldList]); %update the field menu
2210%     end
2211elseif ~test_keepdata_1
2212    if (~strcmp(UvData.FileType{2},'netcdf')&&~strcmp(UvData.FileType{2},'civdata')&&~strcmp(UvData.FileType{2},'civx'))|| isequal(FieldName_1,'get_field...')
2213        set(handles.VelType_1,'Visible','off')
2214    else
2215        test_veltype_1=1;
2216        set(handles.VelType_1,'Visible','on')
2217        menu=set_veltype_display(ParamOut_1.CivStage,UvData.FileType{2});
2218        index_menu=strcmp(ParamOut_1.VelType,menu);
2219        set(handles.VelType_1,'Value',1+find(index_menu,1))
2220        set(handles.VelType_1,'String',[{''};menu])
2221    end
2222    % update the second field menu: the same quantity
2223    if isstruct(ParamOut_1)
2224    set(handles.FieldName_1,'String',[{''};ParamOut_1.FieldList]); %update the field menu
2225    % display the FieldName menu from the input file and pick the selected one:
2226    field_index=strcmp(ParamOut_1.FieldName,ParamOut_1.FieldList);
2227    set(handles.FieldName_1,'Value',find(field_index,1)+1) 
2228    end
2229   
2230end
2231if test_veltype||test_veltype_1
2232     set(handles.FixVelType,'Visible','on')
2233else
2234     set(handles.FixVelType,'Visible','off')
2235end
2236
2237% field_index=strcmp(ParamOut_1.FieldName,ParamOut_1.FieldList);
2238% set(handles.FieldName,'String',ParamOut.FieldList); %update the field menu
2239% set(handles.FieldName,'Value',find(field_index,1))
2240   
2241%% introduce w as background image by default for a new series (only for nbdim=2)
2242if ~isfield(UvData,'NewSeries')
2243    UvData.NewSeries=1;
2244end
2245%put W as background image by default if NbDim=2:
2246if  UvData.NewSeries && isequal(get(handles.SubField,'Value'),0) && isfield(Field{1},'W') && ~isempty(Field{1}.W) && ~isequal(Field{1}.NbDim,3);
2247        set(handles.SubField,'Value',1);
2248        set(handles.RootPath_1,'String','"')
2249        set(handles.RootFile_1,'String','"')
2250        set(handles.SubDir_1,'String','"');
2251         indices=fullfile_uvmat('','','','',NomType,num_i1,num_i2,num_j1,num_j2);
2252        set(handles.FileIndex_1,'String',indices)
2253        set(handles.FileExt_1,'String','"');
2254        set(handles.FieldName_1,'Visible','on');
2255        set(handles.FieldName_1,'Visible','on');
2256        set(handles.RootPath_1,'Visible','on')
2257        set(handles.RootFile_1,'Visible','on')
2258        set(handles.SubDir_1,'Visible','on');
2259        set(handles.FileIndex_1,'Visible','on');
2260        set(handles.FileExt_1,'Visible','on');
2261        set(handles.FieldName_1,'Visible','on');
2262        Field{1}.AName='w';
2263end           
2264
2265%% display time
2266testimedoc=0;
2267TimeUnit='';
2268if isfield(Field{1},'Time')
2269    abstime=Field{1}.Time;%time read from the netcdf input file
2270end
2271if numel(Field)==2 && isfield(Field{2},'Time')
2272    abstime_1=Field{2}.Time;%time read from the netcdf input file
2273end
2274if isfield(Field{1},'Dt')
2275    dt=Field{1}.Dt;%dt read from the netcdf input file
2276    if isfield(Field{1},'TimeUnit')
2277       TimeUnit=Field{1}.TimeUnit;
2278    end
2279elseif numel(Field)==2 && isfield(Field{2},'Dt')%dt obtained from the second field if not defined in the first
2280    dt=Field{2}.Dt;%dt read from the netcdf input file
2281    if isfield(Field{2},'TimeUnit')
2282       TimeUnit=Field{2}.TimeUnit;
2283    end
2284end
2285% time from xml file overset previous result
2286if isfield(UvData,'XmlData') && isfield(UvData.XmlData{1},'Time')
2287    if isempty(num_i2)||isnan(num_i2)
2288        num_i2=num_i1;
2289    end
2290    if isempty(num_j1)||isnan(num_j1)
2291        num_j1=1;
2292    end
2293    if isempty(num_j2)||isnan(num_j2)
2294        num_j2=num_j1;
2295    end
2296    siz=size(UvData.XmlData{1}.Time);
2297    if ~isempty(num_i1)&& ~isempty(num_i2) && num_i1>0 &&siz(1)>=max(num_i1,num_i2) && siz(2)>=max(num_j1,num_j2)
2298        abstime=(UvData.XmlData{1}.Time(num_i1,num_j1)+UvData.XmlData{1}.Time(num_i2,num_j2))/2;%overset the time read from files
2299        dt=(UvData.XmlData{1}.Time(num_i2,num_j2)-UvData.XmlData{1}.Time(num_i1,num_j1));
2300        Field{1}.Dt=dt;
2301        if isfield(UvData.XmlData{1},'TimeUnit')
2302            TimeUnit=UvData.XmlData{1}.TimeUnit;
2303        end
2304    end
2305    if numel(UvData.XmlData)==2
2306        if isempty(i2_1)
2307            i2_1=num_i1;
2308        end
2309        if isempty(j1_1)
2310            j1_1=1;
2311        end
2312        if isempty(j2_1)
2313            j2_1=j1_1;
2314        end
2315        siz=size(UvData.XmlData{2}.Time);
2316        if ~isempty(i1_1) && siz(1)>=max(i1_1,i2_1) && siz(2)>=max(j1_1,j2_1)
2317            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
2318            Field{2}.Dt=(UvData.XmlData{2}.Time(i2_1,j2_1)-UvData.XmlData{2}.Time(i1_1,j1_1));
2319        end
2320    end
2321end
2322if ~isequal(numel(abstime),1)
2323    abstime=[];
2324end
2325if ~isequal(numel(abstime_1),1)
2326      abstime_1=[];
2327end 
2328set(handles.abs_time,'String',num2str(abstime,5))
2329set(handles.abs_time_1,'String',num2str(abstime_1,5))
2330if isempty(dt)||isequal(dt,0)
2331    set(handles.Dt_txt,'String','')
2332else
2333    if  isempty(TimeUnit)
2334        set(handles.Dt_txt,'String',['Dt=' num2str(1000*dt,3) '  10^(-3)'] )
2335    else
2336        set(handles.Dt_txt,'String',['Dt=' num2str(1000*dt,3) '  m' TimeUnit] )
2337    end
2338end
2339
2340
2341%% store the current open names, fieldname and vel types in uvmat interface
2342UvData.FileName_1=FileName_1;
2343UvData.ParamOut_1=ParamOut_1;
2344if numel(Field)==2
2345UvData.Field_1=Field{2}; %store the second field for possible use at next RUN
2346end
2347
2348%% apply coordinate transform or other user fct
2349transform=get(handles.path_transform,'UserData');
2350if isempty(transform)
2351    UvData.Field=Field{1};
2352else
2353    XmlData=[];%default
2354    XmlData_1=[];%default
2355    if isfield(UvData,'XmlData')%use geometry calib recorded from the ImaDoc xml file as first priority
2356        XmlData=UvData.XmlData{1};
2357        if numel(UvData.XmlData)==2
2358            XmlData_1=UvData.XmlData{2};
2359        end
2360    end
2361    transform=get(handles.path_transform,'UserData');
2362    switch nargin(transform)
2363        case 4
2364            if length(Field)==2
2365                UvData.Field=transform(Field{1},XmlData,Field{2},XmlData_1);
2366            else
2367                UvData.Field=transform(Field{1},XmlData);
2368            end
2369        case 3
2370            if length(Field)==2
2371                UvData.Field=transform(Field{1},XmlData,Field{2});
2372            else
2373                UvData.Field=transform(Field{1},XmlData);
2374            end
2375        case 2
2376            UvData.Field=transform(Field{1},XmlData);
2377        case 1
2378            UvData.Field=transform(Field{1});
2379    end
2380end
2381
2382%% calculate tps coefficients if needed
2383UvData.Field=calc_tps(UvData.Field,check_proj_tps);
2384
2385%% analyse input field
2386%test_x=0;
2387%test_z=0;% test for unstructured z coordinate
2388%[errormsg,ListDimName,DimValue,VarDimIndex]=check_field_structure(UvData.Field);% check the input field structure
2389% if ~isempty(errormsg)
2390%     errormsg=['error in uvmat/refresh_field/check_field_structure: ' errormsg];% display error
2391%     return
2392% end
2393[CellInfo,NbDimArray,errormsg]=find_field_cells(UvData.Field);% analyse  the input field structure
2394if ~isempty(errormsg)
2395    errormsg=['uvmat /refresh_field / find_field_cells / ' errormsg];% display error
2396    return
2397end
2398
2399NbDim=max(NbDimArray);% spatial dimension of the input field
2400imax=find(NbDimArray==NbDim);% indices of field cells to consider
2401if isfield(UvData.Field,'NbDim')
2402    NbDim=double(UvData.Field.NbDim);% deal with plane fields containing z coordinates
2403end
2404
2405
2406%% get bounds and mesh (needed  to propose default options for projection objects)
2407if NbDim>1
2408    CoordMax=zeros(numel(imax),NbDim);
2409    CoordMin=zeros(numel(imax),NbDim);
2410    Mesh=zeros(1,numel(imax));
2411    for ind=1:numel(imax)
2412        if strcmp(CellInfo{imax(ind)}.CoordType,'tps')
2413            CoordName=UvData.Field.ListVarName{CellInfo{imax(ind)}.CoordIndex};% X,Y coordinates in a single variable
2414            CoordMax(ind,NbDim)=max(UvData.Field.(CoordName)(1:end-3,1,:));
2415            CoordMax(ind,NbDim-1)=max(UvData.Field.(CoordName)(1:end-3,2,:));
2416            CoordMin(ind,NbDim)=min(UvData.Field.(CoordName)(1:end-3,1,:));
2417            CoordMin(ind,NbDim-1)=min(UvData.Field.(CoordName)(1:end-3,2,:));
2418        else
2419            XName=UvData.Field.ListVarName{CellInfo{imax(ind)}.CoordIndex(end)};
2420            YName=UvData.Field.ListVarName{CellInfo{imax(ind)}.CoordIndex(end-1)};
2421            CoordMax(ind,NbDim)=max(max(UvData.Field.(XName)));
2422            CoordMin(ind,NbDim)=min(min(UvData.Field.(XName)));
2423            CoordMax(ind,NbDim-1)=max(max(UvData.Field.(YName)));
2424            CoordMin(ind,NbDim-1)=min(min(UvData.Field.(YName)));
2425            %         test_x=1;%test for unstructured coordinates
2426            if NbDim==3
2427                ZName=UvData.Field.ListVarName{CellInfo{imax(ind)}.CoordIndex(1)};
2428                CoordMax(imax(ind),1)=max(max(UvData.Field.(ZName)));
2429                CoordMin(ind,1)=min(min(UvData.Field.(ZName)));
2430            end
2431        end
2432        switch CellInfo{imax(ind)}.CoordType
2433           
2434            case {'scattered','tps'} %unstructured coordinates
2435                NbPoints=CellInfo{imax(ind)}.CoordSize;% total nbre of points
2436                Mesh(ind)=(prod(CoordMax(ind,:)-CoordMin(ind,:))/NbPoints)^(1/NbDim); %(volume or area per point)^(1/NbDim)
2437            case 'grid'%structured coordinate
2438                NbPoints=CellInfo{imax(ind)}.CoordSize;% nbre of points in each direction
2439                Mesh(ind)=min((CoordMax(ind,:)-CoordMin(ind,:))./(NbPoints-1));               
2440        end
2441    end
2442    UvData.Field.Mesh=min(Mesh);
2443    UvData.Field.XMax=max(CoordMax(ind,end));
2444    UvData.Field.XMin=min(CoordMin(ind,end));
2445    UvData.Field.YMax=max(CoordMax(ind,end-1));
2446    UvData.Field.YMin=max(CoordMin(ind,end-1));
2447    if NbDim==3
2448        UvData.Field.ZMax=max(CoordMax(ind,1));
2449        UvData.Field.ZMin=max(CoordMin(ind,1));
2450    end
2451    % adjust the mesh to a value 1, 2 , 5 *10^n
2452    ord=10^(floor(log10(UvData.Field.Mesh)));%order of magnitude
2453    if UvData.Field.Mesh/ord>=5
2454        UvData.Field.Mesh=5*ord;
2455    elseif UvData.Field.Mesh/ord>=2
2456        UvData.Field.Mesh=2*ord;
2457    else
2458        UvData.Field.Mesh=ord;
2459    end
2460    % default projection plane
2461    if isempty(UvData.Object{1})
2462        UvData.Object{1}.Type='plane';%main plotting plane
2463        UvData.Object{1}.ProjMode='projection';%main plotting plane
2464        UvData.Object{1}.DisplayHandle.uvmat=[]; %plane not visible in uvmat
2465        UvData.Object{1}.DisplayHandle.view_field=[]; %plane not visible in uvmat
2466    end
2467    %% 3D case (menuvolume)
2468    if NbDim==3% && UvData.NewSeries
2469        test_set_object=1;
2470        hset_object=findobj(allchild(0),'tag','set_object');% look for the set_object GUI
2471        ZBounds(1)=UvData.Field.ZMin; %minimum for the Z slider
2472        ZBounds(2)=UvData.Field.ZMax;%maximum for the Z slider
2473        if ~isempty(hset_object) %if set_object is detected
2474            delete(hset_object);% delete the GUI set_object if it does not fit
2475        end
2476        if test_set_object% reinitiate the GUI set_object
2477            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
2478            UvData.Object{1}.NbDim=NbDim;%test for 3D objects
2479            UvData.Object{1}.RangeZ=UvData.Field.Mesh;%main plotting plane
2480            UvData.Object{1}.Coord(1,3)=(UvData.Field.ZMin+UvData.Field.ZMax)/2;%section at a middle plane chosen
2481            UvData.Object{1}.Angle=[0 0 0];
2482            UvData.Object{1}.HandlesDisplay=plot(0,0,'Tag','proj_object');% A REVOIR
2483            UvData.Object{1}.Name='1-PLANE';
2484            UvData.Object{1}.enable_plot=1;
2485            set_object(UvData.Object{1},handles,ZBounds);
2486            set(handles.ListObject,'Value',1);
2487            set(handles.ListObject,'String',{'1-PLANE'});
2488            set(handles.edit_object,'Value',1)% put the plane in edit mode to enable the z cursor
2489            edit_object_Callback([],[], handles)
2490        end
2491        %multilevel case (single menuplane in a 3D space)
2492    elseif isfield(UvData,'Z')
2493        if isfield(UvData,'CoordType')&& isequal(UvData.CoordType,'phys') && isfield(UvData,'XmlData')
2494            XmlData=UvData.XmlData{1};
2495            if isfield(XmlData,'PlanePos')
2496                UvData.Object{1}.Coord=XmlData.PlanePos(UvData.ZIndex,:);
2497            end
2498            if isfield(XmlData,'PlaneAngle')
2499                siz=size(XmlData.PlaneAngle);
2500                indangle=min(siz(1),UvData.ZIndex);%take first angle if a single angle is defined (translating scanning)
2501                UvData.Object{1}.PlaneAngle=XmlData.PlaneAngle(indangle,:);
2502            end
2503        elseif isfield(UvData,'ZIndex')
2504            UvData.Object{1}.ZObject=UvData.ZIndex;
2505        end
2506    end
2507end
2508
2509testnewseries=UvData.NewSeries;
2510UvData.NewSeries=0;% put to 0 the test for a new field series (set by RootPath_callback)
2511set(handles.uvmat,'UserData',UvData)
2512
2513%% reset the min and max of scalar if only the mask is displayed(TODO: check the need)
2514% if isfield(UvData,'Mask')&& ~isfield(UvData,'A')
2515%     set(handles.num_MinA,'String','0')
2516%     set(handles.num_MaxA,'String','255')
2517% end
2518
2519%% usual 1D (x,y) plots
2520if NbDim<=1
2521    set(handles.Objects,'Visible','off')
2522    set(handles.ListObject_1_title,'Visible','off')
2523    set(handles.ListObject_1,'Visible','off')
2524    [PlotType,PlotParamOut]=plot_field(UvData.Field,handles.PlotAxes,read_GUI(handles.uvmat));
2525    write_plot_param(handles,PlotParamOut) %update the auto plot parameters
2526   
2527%% 2D or 3D fieldname are generally projected
2528else
2529    set(handles.Objects,'Visible','on')
2530    set(handles.ListObject_1_title,'Visible','on')
2531    set(handles.ListObject_1,'Visible','on')
2532   
2533    %% Plot the projections on the selected  projection objects
2534    % main projection object (uvmat display)
2535    list_object=get(handles.ListObject_1,'String');
2536    if isequal(list_object,{''})||isequal(list_object,' ')%refresh list of objects if the menu is empty
2537        set(handles.ListObject,'Value',1)
2538        set(handles.ListObject,'String',{'plane'})
2539        UvData.Object{1}.Type='plane';%main plotting plane
2540        UvData.Object{1}.ProjMode='projection';%main plotting plane
2541        UvData.Object{1}.DisplayHandle.uvmat=[]; %plane not visible in uvmat
2542        UvData.Object{1}.DisplayHandle.view_field=[]; %plane not visible in uvmat
2543        set(handles.ListObject_1,'Value',1)
2544        set(handles.ListObject_1,'String',{'plane'})
2545    end
2546    IndexObj(1)=get(handles.ListObject_1,'Value');%selected projection object for main view
2547    if IndexObj(1)> numel(UvData.Object)
2548        IndexObj(1)=1;%select the first object if the selected one does not exist
2549        set(handles.ListObject_1,'Value',1)
2550    end
2551    IndexObj(2)=get(handles.ListObject,'Value');%selected projection object for main view
2552    if isequal(IndexObj(2),IndexObj(1))
2553        IndexObj(2)=[];
2554    end
2555    plot_handles{1}=handles;
2556    if isfield(UvData,'plotaxes')%case of movies
2557        haxes(1)=UvData.plotaxes;
2558    else
2559        haxes(1)=handles.PlotAxes;
2560    end
2561    PlotParam{1}=read_GUI(handles.uvmat);
2562    %default settings if vectors not visible
2563    if ~isfield(PlotParam{1},'Vectors')
2564        PlotParam{1}.Vectors.MaxVec=1;
2565        PlotParam{1}.Vectors.MinVec=0;
2566        PlotParam{1}.Vectors.CheckFixVecColor=1;
2567        PlotParam{1}.Vectors.ColCode1=0.33;
2568        PlotParam{1}.Vectors.ColCode2=0.66;
2569        PlotParam{1}.Vectors.ColorScalar={''};
2570        PlotParam{1}.Vectors.ColorCode= {'rgb'};
2571    end
2572    PosColorbar{1}=UvData.OpenParam.PosColorbar;%prescribe the colorbar position on the uvmat interface
2573   
2574    %% second projection object (view_field display)
2575    if length( IndexObj)>=2
2576        view_field_handle=findobj(allchild(0),'tag','view_field');%handles of the view_field GUI
2577        if ~isempty(view_field_handle)
2578            plot_handles{2}=guidata(view_field_handle);
2579            haxes(2)=plot_handles{2}.PlotAxes;
2580            PlotParam{2}=read_GUI(handles.uvmat);%read plotting parameters on the uvmat interface
2581            PosColorbar{2}='*'; %TODO: deal with colorbar position on view_field
2582        end
2583    end
2584   
2585    %% loop on the projection objects: one or two
2586   
2587    for imap=1:numel(IndexObj)
2588        iobj=IndexObj(imap);
2589        [ObjectData,errormsg]=proj_field(UvData.Field,UvData.Object{iobj});% project field on the object
2590        if ~isempty(errormsg)
2591            return
2592        end
2593        if testnewseries
2594            PlotParam{imap}.Scalar.CheckBW=[]; %B/W option depends on the input field (image or scalar)
2595            if isfield(ObjectData,'CoordUnit')
2596                PlotParam{imap}.Coordinates.CheckFixAspectRatio=1;% set x and y scaling equal if CoordUnit is defined (common unit for x and y)
2597                PlotParam{imap}.Coordinates.AspectRatio=1; %set aspect ratio to 1
2598            end
2599        end
2600        %use of mask (TODO: check)
2601        if isfield(ObjectData,'NbDim') && isequal(ObjectData.NbDim,2) && isfield(ObjectData,'Mask') && isfield(ObjectData,'A')
2602            flag_mask=double(ObjectData.Mask>200);%=0 for masked regions
2603            AX=ObjectData.AX;%x coordiantes for the scalar field
2604            AY=ObjectData.AY;%y coordinates for the scalar field
2605            MaskX=ObjectData.MaskX;%x coordiantes for the mask
2606            MaskY=ObjectData.MaskY;%y coordiantes for the mask
2607            if ~isequal(MaskX,AX)||~isequal(MaskY,AY)
2608                nxy=size(flag_mask);
2609                sizpx=(ObjectData.MaskX(end)-ObjectData.MaskX(1))/(nxy(2)-1);%size of a mask pixel
2610                sizpy=(ObjectData.MaskY(1)-ObjectData.MaskY(end))/(nxy(1)-1);
2611                x_mask=ObjectData.MaskX(1):sizpx:ObjectData.MaskX(end); % pixel x coordinates for image display
2612                y_mask=ObjectData.MaskY(1):-sizpy:ObjectData.MaskY(end);% pixel x coordinates for image display
2613                %project on the positions of the scalar
2614                npxy=size(ObjectData.A);
2615                dxy(1)=(ObjectData.AY(end)-ObjectData.AY(1))/(npxy(1)-1);%grid mesh in y
2616                dxy(2)=(ObjectData.AX(end)-ObjectData.AX(1))/(npxy(2)-1);%grid mesh in x
2617                xi=ObjectData.AX(1):dxy(2):ObjectData.AX(end);
2618                yi=ObjectData.AY(1):dxy(1):ObjectData.AY(end);
2619                [XI,YI]=meshgrid(xi,yi);% creates the matrix of regular coordinates
2620                flag_mask = interp2(x_mask,y_mask,flag_mask,XI,YI);
2621            end
2622            AClass=class(ObjectData.A);
2623            ObjectData.A=flag_mask.*double(ObjectData.A);
2624            ObjectData.A=feval(AClass,ObjectData.A);
2625%             ind_off=[];
2626%             if isfield(ObjectData,'ListVarName')
2627%                 for ilist=1:length(ObjectData.ListVarName)
2628%                     if isequal(ObjectData.ListVarName{ilist},'Mask')||isequal(ObjectData.ListVarName{ilist},'MaskX')||isequal(ObjectData.ListVarName{ilist},'MaskY')
2629%                         ind_off=[ind_off ilist];
2630%                     end
2631%                 end
2632%                 ObjectData.ListVarName(ind_off)=[];
2633%                 VarDimIndex(ind_off)=[];
2634%                 ind_off=[];
2635%             
2636%             end
2637        end
2638        if ~isempty(ObjectData)
2639            PlotType='none'; %default
2640            if imap==2 && isempty(view_field_handle)
2641                view_field(ObjectData)
2642            else
2643                [PlotType,PlotParamOut]=plot_field(ObjectData,haxes(imap),PlotParam{imap},PosColorbar{imap});
2644                write_plot_param(plot_handles{imap},PlotParamOut) %update the auto plot parameters
2645                if isfield(Field,'Mesh')&&~isempty(Field.Mesh)
2646                    ObjectData.Mesh=Field.Mesh; % gives an estimated mesh size (useful for mouse action on the plot)
2647                end
2648            end
2649        end
2650    end
2651   
2652    %% update the mask
2653    if isequal(get(handles.CheckMask,'Value'),1)%if the mask option is on
2654        update_mask(handles,num_i1,num_i2);
2655    end
2656   
2657    %% prepare the menus of histograms and plot them (histogram of the whole volume in 3D case)
2658    menu_histo=(UvData.Field.ListVarName)';%list of field variables to be displayed for the menu of histogram display
2659    ind_skip=[];
2660    % nb_histo=1;
2661    Ustring='';
2662    Vstring='';
2663    % suppress coordinates from the histogram menu
2664    for ivar=1:numel(menu_histo)%l loop on field variables:
2665        if isfield(UvData.Field,'VarAttribute') && numel(UvData.Field.VarAttribute)>=ivar && isfield(UvData.Field.VarAttribute{ivar},'Role')
2666            Role=UvData.Field.VarAttribute{ivar}.Role;
2667            switch Role
2668                case {'coord_x','coord_y','coord_z','dimvar'}
2669                    ind_skip=[ind_skip ivar];
2670                case {'vector_x'}
2671                    Ustring=UvData.Field.ListVarName{ivar};
2672                    ind_skip=[ind_skip ivar];
2673                case {'vector_y'}
2674                    Vstring=UvData.Field.ListVarName{ivar};
2675                    ind_skip=[ind_skip ivar];
2676            end
2677        end
2678        DimCell=UvData.Field.VarDimName{ivar};
2679        DimName='';
2680        if ischar(DimCell)
2681            DimName=DimCell;
2682        elseif iscell(DimCell)&& numel(DimCell)==1
2683            DimName=DimCell{1};
2684        end
2685        if strcmp(DimName,menu_histo{ivar})
2686            ind_skip=[ind_skip ivar];
2687        end
2688    end
2689    menu_histo(ind_skip)=[];% remove skipped items
2690    if ~isempty(Ustring)
2691        menu_histo=[{[Ustring ',' Vstring]};menu_histo];% add U, V at the beginning if they exist
2692    end
2693   
2694    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2695    % display menus and plot histograms
2696    test_v=0;
2697    if ~isempty(menu_histo)
2698        set(handles.histo1_menu,'Value',1)
2699        set(handles.histo1_menu,'String',menu_histo)
2700        histo1_menu_Callback(handles.histo1_menu, [], handles)% plot first histogram
2701    end
2702end
2703
2704%------------------------------------------------------------------------
2705function histo1_menu_Callback(hObject, eventdata, handles)
2706%--------------------------------------------
2707histo_menu=get(handles.histo1_menu,'String');
2708histo_value=get(handles.histo1_menu,'Value');
2709FieldName=histo_menu{histo_value};
2710
2711UvData=get(handles.uvmat,'UserData');
2712Field=UvData.Field;
2713r=regexp(FieldName,'(?<var1>.*)(?<sep>,)(?<var2>.*)','names');
2714FieldName_2='';
2715if ~isempty(r)
2716    FieldName=r.var1;
2717    FieldName_2=r.var2;
2718end
2719if ~isfield(UvData.Field,FieldName)
2720    msgbox_uvmat('ERROR',['no field  ' FieldName ' for histogram'])
2721    return
2722end
2723FieldHisto=Field.(FieldName);
2724if isfield(Field,'FF') && ~isempty(Field.FF) && isequal(size(Field.FF),size(FieldHisto))
2725    indsel=find(Field.FF==0);%find values marked as false
2726    if ~isempty(indsel)
2727        FieldHisto=FieldHisto(indsel);
2728        if ~isempty(FieldName_2)
2729            FieldHisto(:,:,2)=Field.(FieldName_2)(indsel);
2730        end
2731    end
2732end
2733if isempty(Field)
2734    msgbox_uvmat('ERROR',['empty field ' FieldName])
2735else
2736    nxy=size(FieldHisto);
2737    Amin=double(min(min(min(FieldHisto))));%min of field value
2738    Amax=double(max(max(max(FieldHisto))));%max of field value
2739    if isequal(Amin,Amax)
2740        cla(handles.HistoAxes)
2741    else
2742        Histo.ListVarName={FieldName,'histo'};
2743        if isfield(Field,'NbDim') && isequal(Field.NbDim,3)
2744            Histo.VarDimName={FieldName,FieldName}; %dimensions for the histogram
2745        else
2746            if numel(nxy)==2
2747                Histo.VarDimName={FieldName,FieldName}; %dimensions for the histogram
2748            else
2749                Histo.VarDimName={FieldName,{FieldName,'component'}}; %dimensions for the histogram
2750            end
2751        end
2752        %unit
2753        units=[]; %default
2754        for ivar=1:numel(Field.ListVarName)
2755            if strcmp(Field.ListVarName{ivar},FieldName)
2756                if isfield(Field,'VarAttribute') && numel(Field.VarAttribute)>=ivar && isfield(Field.VarAttribute{ivar},'units')
2757                    units=Field.VarAttribute{ivar}.units;
2758                    break
2759                end
2760            end
2761        end
2762        if ~isempty(units)
2763            Histo.VarAttribute{1}.units=units;
2764        end
2765        eval(['Histo.' FieldName '=linspace(Amin,Amax,50);'])%absissa values for histo
2766        if isfield(Field,'NbDim') && isequal(Field.NbDim,3)
2767            C=reshape(double(FieldHisto),1,[]);% reshape in a vector
2768            Histo.histo(:,1)=hist(C, Histo.(FieldName));  %calculate histogram
2769        else
2770            for col=1:size(FieldHisto,3)
2771                B=FieldHisto(:,:,col);
2772                C=reshape(double(B),1,nxy(1)*nxy(2));% reshape in a vector
2773                Histo.histo(:,col)=hist(C, Histo.(FieldName));  %calculate histogram
2774            end
2775        end
2776        plot_field(Histo,handles.HistoAxes);
2777        hlegend=legend;
2778        if isempty(FieldName_2)
2779        set(hlegend,'String',FieldName)
2780        else
2781            set(hlegend,'String',{FieldName;FieldName_2})
2782        end
2783    end
2784end
2785
2786%-------------------------------------------------------------------
2787% --- translate coordinate to matrix index
2788%-------------------------------------------------------------------
2789function [indx,indy]=pos2ind(x0,rangx0,nxy)
2790indx=1+round((nxy(2)-1)*(x0-rangx0(1))/(rangx0(2)-rangx0(1)));% index x of pixel 
2791indy=1+round((nxy(1)-1)*(y12-rangy0(1))/(rangy0(2)-rangy0(1)));% index y of pixel
2792
2793
2794%-------------------------------------------------------------------
2795% --- Executes on button press in 'CheckZoom'.
2796%-------------------------------------------------------------------
2797function CheckZoom_Callback(hObject, eventdata, handles)
2798
2799if (get(handles.CheckZoom,'Value') == 1);
2800    set(handles.CheckZoom,'BackgroundColor',[1 1 0])
2801    set(handles.CheckFixLimits,'Value',1)% propose by default fixed limits for the plotting axes
2802    set(handles.CheckFixLimits,'BackgroundColor',[1 1 0])
2803else
2804    set(handles.CheckZoom,'BackgroundColor',[0.7 0.7 0.7])
2805end
2806
2807%-------------------------------------------------------------------
2808% --- Executes on button press in 'CheckFixLimits'.
2809%-------------------------------------------------------------------
2810function CheckFixLimits_Callback(hObject, eventdata, handles)
2811test=get(handles.CheckFixLimits,'Value');
2812if test
2813    set(handles.CheckFixLimits,'BackgroundColor',[1 1 0])
2814else
2815    set(handles.CheckFixLimits,'BackgroundColor',[0.7 0.7 0.7])
2816    update_plot(handles);
2817end
2818
2819%-------------------------------------------------------------------
2820% --- Executes on button press in CheckFixAspectRatio.
2821function CheckFixAspectRatio_Callback(hObject, eventdata, handles)
2822%-------------------------------------------------------------------
2823if get(handles.CheckFixAspectRatio,'Value')
2824    set(handles.CheckFixAspectRatio,'BackgroundColor',[1 1 0])
2825    update_plot(handles);
2826else
2827    set(handles.CheckFixAspectRatio,'BackgroundColor',[0.7 0.7 0.7])
2828    update_plot(handles);
2829end
2830
2831%-------------------------------------------------------------------
2832function num_AspectRatio_Callback(hObject, eventdata, handles)
2833%-------------------------------------------------------------------
2834set(handles.CheckFixAspectRatio,'Value',1)% select the fixed aspect ratio button
2835set(handles.CheckFixAspectRatio,'BackgroundColor',[1 1 0])% mark in yellow
2836update_plot(handles);
2837%-------------------------------------------------------------------
2838
2839%-------------------------------------------------------------------
2840
2841
2842
2843%-------------------------------------------------------------------
2844%----Executes on button press in 'record': records the current flags of manual correction.
2845%-------------------------------------------------------------------
2846function record_Callback(hObject, eventdata, handles)
2847% [filebase,num_i1,num_j1,num_i2,num_j2,Ext,NomType,SubDir]=read_input_file(handles);
2848[RootPath,SubDir,RootFile,FileIndices,FileExt]=read_file_boxes(handles);
2849FileName=[fullfile(RootPath,SubDir,RootFile) FileIndices FileExt];
2850%FileName=read_file_boxes(handles);
2851[erread,message]=fileattrib(FileName);
2852if ~isempty(message) && ~isequal(message.UserWrite,1)
2853     msgbox_uvmat('ERROR',['no writting access to ' FileName])
2854     return
2855end
2856test_civ2=isequal(get(handles.civ2,'BackgroundColor'),[1 1 0]);
2857test_civ1=isequal(get(handles.VelType,'BackgroundColor'),[1 1 0]);
2858if ~test_civ2 && ~test_civ1
2859    msgbox_uvmat('ERROR','manual correction only possible for CIV1 or CIV2 velocity fields')
2860end
2861if test_civ2
2862    nbname='nb_vectors2';
2863   flagname='vec2_FixFlag';
2864   attrname='fix2';
2865end
2866if test_civ1
2867    nbname='nb_vectors';
2868   flagname='vec_FixFlag';
2869   attrname='fix';
2870end
2871%write fix flags in the netcdf file
2872UvData=get(handles.uvmat,'UserData');
2873hhh=which('netcdf.open');% look for built-in matlab netcdf library
2874if ~isequal(hhh,'')% case of new builtin Matlab netcdf library
2875    nc=netcdf.open(FileName,'NC_WRITE');
2876    netcdf.reDef(nc);
2877    netcdf.putAtt(nc,netcdf.getConstant('NC_GLOBAL'),attrname,1);
2878    dimid = netcdf.inqDimID(nc,nbname);
2879    try
2880        varid = netcdf.inqVarID(nc,flagname);% look for already existing fixflag variable
2881    catch
2882        varid=netcdf.defVar(nc,flagname,'double',dimid);%create fixflag variable if it does not exist
2883    end
2884    netcdf.endDef(nc);
2885    netcdf.putVar(nc,varid,UvData.PlotAxes.FF);
2886    netcdf.close(nc); 
2887else %old netcdf library
2888    netcdf_toolbox(FileName,AxeData,attrname,nbname,flagname)
2889end
2890
2891%-------------------------------------------------------------------
2892%----Correct the netcdf file, using toolbox (old versions of Matlab).
2893%-------------------------------------------------------------------
2894function netcdf_toolbox(FileName,AxeData,attrname,nbname,flagname)
2895nc=netcdf(FileName,'write'); %open netcdf file
2896result=redef(nc);
2897eval(['nc.' attrname '=1;']);
2898theDim=nc(nbname) ;% get the number of velocity vectors
2899nb_vectors=size(theDim);
2900var_FixFlag=ncvar(flagname,nc);% var_FixFlag will be written as the netcdf variable vec_FixFlag
2901var_FixFlag(1:nb_vectors)=AxeData.FF;%
2902fin=close(nc);
2903
2904%-------------------------------------------------------------------
2905% --- Executes on button press in SubField
2906function SubField_Callback(hObject, eventdata, handles)
2907%-------------------------------------------------------------------
2908UvData=get(handles.uvmat,'UserData');
2909if get(handles.SubField,'Value')==0% if the subfield button is desactivated   
2910    set(handles.RootPath_1,'String','')
2911    set(handles.RootFile_1,'String','')
2912    set(handles.SubDir_1,'String','');
2913    set(handles.FileIndex_1,'String','');
2914    set(handles.FileExt_1,'String','');
2915    set(handles.RootPath_1,'Visible','off')
2916    set(handles.RootFile_1,'Visible','off')
2917    set(handles.SubDir_1,'Visible','off');
2918    set(handles.NomType_1,'Visible','off');
2919    set(handles.abs_time_1,'Visible','off')
2920    set(handles.FileIndex_1,'Visible','off');
2921    set(handles.FileExt_1,'Visible','off');
2922    set(handles.FieldName_1,'Value',1);%set to blank state
2923    set(handles.VelType_1,'Value',1);%set to blank state
2924    set(handles.num_Opacity,'String','')% desactivate opacity setting
2925    if ~strcmp(get(handles.VelType,'Visible'),'on')
2926        set(handles.VelType_1,'Visible','off')
2927    end
2928    if isfield(UvData,'XmlData_1')
2929        UvData=rmfield(UvData,'XmlData_1');
2930    end
2931    set(handles.uvmat,'UserData',UvData);
2932    transform_fct_list=get(handles.transform_fct,'String');
2933    transform_fct=transform_fct_list(get(handles.transform_fct,'Value'));
2934    if strcmp(transform_fct,'sub_field')
2935        set(handles.transform_fct,'Value',1)%suppress the sub_field transform
2936        transform_fct_Callback(hObject, eventdata, handles);
2937    else
2938        run0_Callback(hObject, eventdata, handles)
2939    end 
2940else
2941    MenuBrowse_1_Callback(hObject, eventdata, handles)
2942end
2943
2944%------------------------------------------------------------------------
2945% --- read the data displayed for the input rootfile windows (new): TODO use read_GUI
2946
2947function [RootPath,SubDir,RootFile,FileIndices,FileExt]=read_file_boxes(handles)
2948%------------------------------------------------------------------------
2949InputFile=read_GUI(handles.InputFile);
2950RootPath=InputFile.RootPath;
2951SubDir=regexprep(InputFile.SubDir,'/|\','');
2952RootFile=regexprep(InputFile.RootFile,'/|\','');
2953FileIndices=InputFile.FileIndex;
2954FileExt=InputFile.FileExt;
2955
2956
2957%------------------------------------------------------------------------
2958% ---- read the data displayed for the second input rootfile windows
2959function [RootPath_1,SubDir_1,RootFile_1,FileIndex_1,FileExt_1,NomType_1]=read_file_boxes_1(handles)
2960%------------------------------------------------------------------------
2961RootPath_1=get(handles.RootPath_1,'String'); % read the data from the file1_input window
2962if isequal(get(handles.RootPath_1,'Visible'),'off') || isequal(RootPath_1,'"')
2963    RootPath_1=get(handles.RootPath,'String');
2964end;
2965SubDir_1=get(handles.SubDir_1,'String');
2966if isequal(get(handles.SubDir_1,'Visible'),'off')|| isequal(SubDir_1,'"')
2967    SubDir_1=get(handles.SubDir,'String');
2968end
2969SubDir_1=regexprep(SubDir_1,'\<[\\/]|[\\/]\>','');%suppress possible / or \ separator at the beginning or the end of the string
2970RootFile_1=get(handles.RootFile_1,'String');
2971if isequal(get(handles.RootFile_1,'Visible'),'off') || isequal(RootFile_1,'"')
2972    RootFile_1=get(handles.RootFile,'String');
2973end
2974RootFile_1=regexprep(RootFile_1,'\<[\\/]|[\\/]\>','');%suppress possible / or \ separator at the beginning or the end of the string
2975FileIndex_1=get(handles.FileIndex_1,'String');
2976if isequal(get(handles.FileIndex_1,'Visible'),'off')|| isequal(FileIndex_1,'"')
2977    FileIndex_1=get(handles.FileIndex,'String');
2978end
2979FileExt_1=get(handles.FileExt_1,'String');
2980if isequal(get(handles.FileExt_1,'Visible'),'off') || isequal(FileExt_1,'"')
2981    FileExt_1=get(handles.FileExt,'String');%read FileExt by default
2982end
2983NomType_1=get(handles.NomType_1,'String');
2984if isequal(get(handles.NomType_1,'Visible'),'off') || isequal(NomType_1,'"')
2985    NomType_1=get(handles.NomType,'String');%read FileExt by default
2986end
2987%------------------------------------------------------------------------
2988% --- Executes on menu selection FieldName
2989function FieldName_Callback(hObject, eventdata, handles)
2990%------------------------------------------------------------------------
2991list_fields=get(handles.FieldName,'String');% list menu fields
2992index_fields=get(handles.FieldName,'Value');% selected string index
2993field= list_fields{index_fields(1)}; % selected string
2994if isequal(field,'get_field...')
2995    set(handles.FixVelType,'visible','off')
2996    set(handles.VelType,'visible','off')
2997    set(handles.VelType_1,'visible','off')
2998    [RootPath,SubDir,RootFile,FileIndices,FileExt]=read_file_boxes(handles);
2999    FileName=[fullfile(RootPath,SubDir,RootFile) FileIndices FileExt];
3000    hget_field=findobj(allchild(0),'name','get_field');
3001    if ~isempty(hget_field)
3002        delete(hget_field)
3003    end
3004    get_field(FileName);
3005    return %no further action
3006end
3007
3008UvData=get(handles.uvmat,'UserData');
3009
3010%read the rootfile input display
3011[RootPath,SubDir,RootFile,FileIndices,FileExt]=read_file_boxes(handles);
3012FileName=[fullfile(RootPath,SubDir,RootFile) FileIndices FileExt];
3013[tild,tild,tild,i1,i2,j1,j2,tild,NomType]=fileparts_uvmat(['xxx' get(handles.FileIndex,'String') FileExt]);
3014if isequal(field,'image')
3015    if  isfield(UvData.Field,'Civ2_ImageA')%get the corresponding input image in the netcdf file
3016        imagename=UvData.Field.Civ2_ImageA;
3017    elseif isfield(UvData.Field,'Civ1_ImageA')%
3018        imagename=UvData.Field.Civ1_ImageA;
3019    else
3020        SubDirBase=regexprep(SubDir,'\..*','');%take the root part of SubDir, before the first dot '.'
3021        imagename=fullfile_uvmat(RootPath,SubDirBase,RootFile,'.png',NomType,i1,[],j1,[]);
3022    end
3023    if ~exist(imagename,'file')
3024        [FileName,PathName] = uigetfile( ...
3025            {'*.png;*.jpg;*.tif;*.avi;*.AVI;*.vol', ' (*.png, .tif, *.avi,*.vol)';
3026            '*.jpg',' jpeg image files'; ...
3027            '*.png','.png image files'; ...
3028            '*.tif','.tif image files'; ...
3029            '*.avi;*.AVI','.avi movie files'; ...
3030            '*.vol','.volume images (png)'; ...
3031            '*.*',  'All Files (*.*)'}, ...
3032            'Pick an image',imagename);
3033        if ~ischar(FileName),return,end %abandon if the browser is cancelled
3034        imagename=[PathName FileName];
3035    end
3036     % display the selected field and related information
3037    display_file_name(handles,imagename)%display the image
3038    return
3039else
3040    ext=get(handles.FileExt,'String');
3041    if ~isequal(ext,'.nc') %find the new NomType if the previous display was not already a netcdf file
3042        [FileName,PathName] = uigetfile( ...
3043            {'*.nc', ' (*.nc)';
3044            '*.nc',' netcdf files'; ...
3045            '*.*',  'All Files (*.*)'}, ...
3046            'Pick a netcdf file',FileBase);
3047        if ~ischar(FileName),return,end %abandon if the browser is cancelled
3048        FullFileName=[PathName FileName];
3049        % display the selected field and related information
3050        display_file_name( handles,FullFileName)
3051        return
3052    end
3053end
3054indices=fullfile_uvmat('','','','',NomType,i1,i2,j1,j2);
3055set(handles.FileIndex,'String',indices)
3056% set(handles.NomType,'String',NomType)
3057
3058%common to Fields_1_Callback
3059list_fields_1=get(handles.FieldName_1,'String');% list menu fields
3060field_1='';
3061if ~isempty(list_fields_1)
3062field_1= list_fields_1{get(handles.FieldName_1,'Value')}; % selected string
3063end
3064if isequal(field,'image')||isequal(field_1,'image')
3065    set(handles.TitleNpxy,'Visible','on')% visible npx,pxcm... buttons
3066    set(handles.num_Npx,'Visible','on')
3067    set(handles.num_Npy,'Visible','on')
3068else
3069    set(handles.TitleNpxy,'Visible','off')% visible npx,pxcm... buttons
3070    set(handles.num_Npx,'Visible','off')
3071    set(handles.num_Npy,'Visible','off')
3072end
3073if ~(isfield(UvData,'NewSeries')&&isequal(UvData.NewSeries,1))
3074    run0_Callback(hObject, eventdata, handles)
3075end
3076
3077%---------------------------------------------------
3078% --- Executes on menu selection FieldName
3079function FieldName_1_Callback(hObject, eventdata, handles)
3080%-------------------------------------------------
3081%% read input data
3082check_new=~get(handles.SubField,'Value'); %check_new=1 if a second field was not previously entered
3083UvData=get(handles.uvmat,'UserData');
3084if check_new && isfield(UvData,'XmlData')
3085    UvData.XmlData{2}=UvData.XmlData{1};
3086end
3087if isfield(UvData,'Field_1')
3088    UvData=rmfield(UvData,'Field_1');% remove the stored second field (a new one needs to be read)
3089end
3090UvData.FileName_1='';% desactivate the use of a constant second file
3091list_fields=get(handles.FieldName,'String');% list menu fields
3092field= list_fields{get(handles.FieldName,'Value')}; % selected string
3093list_fields=get(handles.FieldName_1,'String');% list menu fields
3094field_1= list_fields{get(handles.FieldName_1,'Value')}; % selected string for the second field
3095if isempty(field_1)%||(numel(UvData.FileType)>=2 && strcmp(UvData.FileType{2},'image'))
3096    set(handles.SubField,'Value',0)
3097    SubField_Callback(hObject, eventdata, handles)
3098    return
3099else
3100    set(handles.SubField,'Value',1)%state that a second field is now entered
3101end
3102
3103%% read the rootfile input display
3104[RootPath_1,SubDir_1,RootFile_1,FileIndex_1,FileExt_1]=read_file_boxes_1(handles);
3105FileName_1=[fullfile(RootPath_1,SubDir_1,RootFile_1) FileIndex_1 FileExt_1];
3106[tild,tild,tild,i1,i2,j1,j2]=fileparts_uvmat(get(handles.FileIndex,'String'));
3107switch field_1
3108    case 'get_field...'
3109        set_veltype_display(0) % no veltype display
3110        hget_field=findobj(allchild(0),'name','get_field_1');
3111        if ~isempty(hget_field)
3112            delete(hget_field)
3113        end
3114        hget_field=get_field(FileName_1);
3115        set(hget_field,'name','get_field_1')
3116        hhget_field=guidata(hget_field);
3117        set(hhget_field.list_fig,'Value',1)
3118        set(hhget_field.list_fig,'String',{'uvmat'})
3119        if check_new
3120            UvData.FileType{2}=UvData.FileType{1};
3121            set(handles.FileIndex_1,'String',get(handles.FileIndex,'String'))
3122              set(handles.uvmat,'UserData',UvData)
3123        end
3124    case 'image'
3125        % get the image name corresponding to the current netcdf name (no unique correspondance)
3126        if  isfield(UvData.Field,'Civ2_ImageA')%get the corresponding input image in the netcdf file
3127            imagename=UvData.Field.Civ2_ImageA;
3128        elseif isfield(UvData.Field,'Civ1_ImageA')%
3129            imagename=UvData.Field.Civ1_ImageA;
3130        else
3131            SubDirBase=regexprep(SubDir_1,'\..*','');%take the root part of SubDir, before the first dot '.'
3132            imagename=fullfile_uvmat(RootPath_1,SubDirBase,RootFile_1,'.png',get(handles.NomType,'String'),i1,[],j1);
3133        end
3134        if ~exist(imagename,'file') % browse for images if it is not found
3135            [FileName,PathName] = uigetfile( ...
3136                {'*.png;*.jpg;*.tif;*.avi;*.AVI;*.vol', ' (*.png, .tif, *.avi,*.vol)';
3137                '*.jpg',' jpeg image files'; ...
3138                '*.png','.png image files'; ...
3139                '*.tif','.tif image files'; ...
3140                '*.avi;*.AVI','.avi movie files'; ...
3141                '*.vol','.volume images (png)'; ...
3142                '*.*',  'All Files (*.*)'}, ...
3143                'Pick an image',imagename);
3144            if ~ischar(FileName),return,end %abandon if the browser is cancelled
3145            imagename=[PathName FileName];
3146        end
3147        if ~ischar(imagename)% quit if the browser has  been closed
3148            set(handles.SubField,'Value',0)
3149        else %valid browser input:  display the selected image
3150            set(handles.TitleNpxy,'Visible','on')% visible npx,pxcm... buttons
3151            set(handles.num_Npx,'Visible','on')
3152            set(handles.num_Npy,'Visible','on')
3153            display_file_name(handles,imagename,2)%display the imag
3154        end
3155    otherwise
3156        if check_new
3157            UvData.FileType{2}=UvData.FileType{1};
3158            set(handles.FileIndex_1,'String',get(handles.FileIndex,'String'))
3159            set(handles.FileExt_1,'String',get(handles.FileExt,'String'))
3160        end
3161        if ~isequal(field,'image')
3162            set(handles.TitleNpxy,'Visible','off')% visible npx,pxcm... buttons
3163            set(handles.num_Npx,'Visible','off')
3164            set(handles.num_Npy,'Visible','off')
3165        end
3166        set(handles.uvmat,'UserData',UvData)
3167        if ~(isfield(UvData,'NewSeries')&&isequal(UvData.NewSeries,1))
3168            run0_Callback(hObject, eventdata, handles)
3169        end
3170end
3171
3172%------------------------------------------------------------------------
3173% --- set the visibility of relevant velocity type menus:
3174function menu=set_veltype_display(Civ,FileType)
3175%------------------------------------------------------------------------
3176if ~exist('FileType','var')
3177    FileType='civx';
3178end
3179switch FileType
3180    case 'civx'
3181        menu={'civ1';'interp1';'filter1';'civ2';'interp2';'filter2'};
3182        if isequal(Civ,0)
3183            imax=0;
3184        elseif isequal(Civ,1) || isequal(Civ,2)
3185            imax=1;
3186        elseif isequal(Civ,3)
3187            imax=3;
3188        elseif isequal(Civ,4) || isequal(Civ,5)
3189            imax=4;
3190        elseif isequal(Civ,6) %patch2
3191            imax=6;
3192        end
3193    case 'civdata'
3194        menu={'civ1';'filter1';'civ2';'filter2'};
3195        if isequal(Civ,0)
3196            imax=0;
3197        elseif isequal(Civ,1) || isequal(Civ,2)
3198            imax=1;
3199        elseif isequal(Civ,3)
3200            imax=2;
3201        elseif isequal(Civ,4) || isequal(Civ,5)
3202            imax=3;
3203        elseif isequal(Civ,6) %patch2
3204            imax=4;
3205        end
3206end
3207menu=menu(1:imax);
3208
3209%------------------------------------------------------------------------
3210% --- Executes on button press in FixVelType.
3211function FixVelType_Callback(hObject, eventdata, handles)
3212%------------------------------------------------------------------------
3213% refresh the current plot if the fixed  veltype is unselected
3214if ~get(handles.FixVelType,'Value')
3215    run0_Callback(hObject, eventdata, handles)
3216end
3217
3218%------------------------------------------------------------------------
3219% --- Executes on button press in VelType.
3220function VelType_Callback(hObject, eventdata, handles)
3221%------------------------------------------------------------------------
3222set(handles.FixVelType,'Value',1)
3223run0_Callback(hObject, eventdata, handles)
3224
3225%------------------------------------------------------------------------
3226% --- Executes on choice selection in VelType_1.
3227function VelType_1_Callback(hObject, eventdata, handles)
3228%------------------------------------------------------------------------
3229set(handles.FixVelType,'Value',1)% the velocity type is now imposed by the GUI (not automatic)
3230UvData=get(handles.uvmat,'UserData');
3231set(handles.run0,'BackgroundColor',[1 1 0])%paint run0 button in yellow to indicate its activation
3232drawnow   
3233InputFile=read_GUI(handles.InputFile);% read the input file parameters
3234[RootPath,SubDir,RootFile,FileIndex,FileExt]=read_file_boxes(handles);
3235[RootPath_1,SubDir_1,RootFile_1,FileIndex_1,FileExt_1]=read_file_boxes_1(handles);
3236FileName=[fullfile(RootPath,SubDir,RootFile) FileIndex FileExt];% name of the first input file
3237
3238check_refresh=0;
3239if isempty(InputFile.VelType_1)
3240        FileName_1='';% we plot the first input field without the second field
3241        set(handles.SubField,'Value',0)
3242        SubField_Callback(hObject, eventdata, handles)% activate SubField_Callback and refresh current display, removing the second field
3243elseif get(handles.SubField,'Value')% if subfield is already 'on'
3244     FileName_1=[fullfile(RootPath_1,SubDir_1,RootFile_1) FileIndex_1 FileExt_1];% name of the second input file
3245     check_refresh=1;%will refresh the current display
3246else% we introduce the same file (with a different field) for the second series
3247     FileName_1=FileName;% we compare two fields in the same file
3248     UvData.FileType{2}=UvData.FileType{1};
3249     UvData.XmlData{2}= UvData.XmlData{1};
3250     set(handles.SubField,'Value',1)
3251     transform=get(handles.path_transform,'UserData');
3252     if (~isa(transform,'function_handle')||nargin(transform)<3)
3253        set(handles.transform_fct,'value',2); % set transform to sub_field if the current fct doe not accept two input fields
3254        transform_fct_Callback(hObject, eventdata, handles)% activate transform_fct_Callback and refresh current display
3255     else
3256         check_refresh=1;
3257     end 
3258end
3259
3260% refresh the current display if it has not been done previously
3261if check_refresh
3262    UvData.FileName_1='';% desactivate the use of a constant second file
3263    set(handles.uvmat,'UserData',UvData)
3264    num_i1=stra2num(get(handles.i1,'String'));
3265    num_i2=stra2num(get(handles.i2,'String'));
3266    num_j1=stra2num(get(handles.j1,'String'));
3267    num_j2=stra2num(get(handles.j2,'String'));
3268    [tild,tild,tild,i1_1,i2_1,j1_1,j2_1]=fileparts_uvmat(['xx' FileIndex_1]);
3269    errormsg=refresh_field(handles,FileName,FileName_1,num_i1,num_i2,num_j1,num_j2,i1_1,i2_1,j1_1,j2_1);
3270    if ~isempty(errormsg)
3271        msgbox_uvmat('ERROR',errormsg);
3272    else
3273        set(handles.i1,'BackgroundColor',[1 1 1])
3274        set(handles.i2,'BackgroundColor',[1 1 1])
3275        set(handles.j1,'BackgroundColor',[1 1 1])
3276        set(handles.j2,'BackgroundColor',[1 1 1])
3277        set(handles.FileIndex,'BackgroundColor',[1 1 1])
3278        set(handles.FileIndex_1,'BackgroundColor',[1 1 1])
3279    end
3280    set(handles.run0,'BackgroundColor',[1 0 0])
3281end
3282
3283%-----------------------------------------------
3284% --- reset civ buttons
3285function reset_vel_type(handles_civ0,handle1)
3286for ibutton=1:length(handles_civ0)
3287    set(handles_civ0(ibutton),'BackgroundColor',[0.831 0.816 0.784])
3288    set(handles_civ0(ibutton),'Value',0)
3289end
3290if exist('handle1','var')%handles of selected button
3291        set(handle1,'BackgroundColor',[1 1 0]) 
3292end
3293
3294%-------------------------------------------------------
3295% --- Executes on button press in MENUVOLUME.
3296%-------------------------------------------------------
3297function VOLUME_Callback(hObject, eventdata, handles)
3298%errordlg('command VOL not implemented yet')
3299if ishandle(handles.UVMAT_title)
3300    delete(handles.UVMAT_title)
3301end
3302UvData=get(handles.uvmat,'UserData');%read UvData properties stored on the uvmat interface
3303if isequal(get(handles.VOLUME,'Value'),1)
3304    set(handles.CheckZoom,'Value',0)
3305    set(handles.CheckZoom,'BackgroundColor',[0.7 0.7 0.7])
3306    set(handles.edit_vect,'Value',0)
3307    edit_vect_Callback(hObject, eventdata, handles)
3308    set(handles.edit_object,'Value',0)
3309    set(handles.edit_object,'BackgroundColor',[0.7 0.7 0.7])
3310%     set(handles.cal,'Value',0)
3311%     set(handles.cal,'BackgroundColor',[0 1 0])
3312    set(handles.edit_vect,'Value',0)
3313    edit_vect_Callback(hObject, eventdata, handles)
3314    %initiate set_object GUI
3315    data.Name='VOLUME';
3316    if isfield(UvData,'CoordType')
3317        data.CoordType=UvData.CoordType;
3318    end
3319    if isfield(UvData.Field,'Mesh')&~isempty(UvData.Field.Mesh)
3320        data.RangeX=[UvData.Field.XMin UvData.Field.XMax];
3321        data.RangeY=[UvData.Field.YMin UvData.Field.YMax];
3322        data.DX=UvData.Field.Mesh;
3323        data.DY=UvData.Field.Mesh;
3324    elseif isfield(UvData.Field,'AX')&isfield(UvData.Field,'AY')& isfield(UvData.Field,'A')%only image
3325        np=size(UvData.Field.A);
3326        meshx=(UvData.Field.AX(end)-UvData.Field.AX(1))/np(2);
3327        meshy=abs(UvData.Field.AY(end)-UvData.Field.AY(1))/np(1);
3328        data.RangeY=max(meshx,meshy);
3329        data.RangeX=max(meshx,meshy);
3330        data.DX=max(meshx,meshy);
3331    end
3332    data.ParentButton=handles.VOLUME;
3333    PlotHandles=get_plot_handles(handles);%get the handles of the interface elements setting the plotting parameters
3334    [hset_object,UvData.sethandles]=set_object(data,PlotHandles);% call the set_object interface with action on haxes,
3335                                                      % associate the set_object interface handle to the plotting axes
3336    set(hset_object,'Position',get(handles.uvmat,'Position')+UvData.OpenParam.PosSetObject)
3337    UvData.MouseAction='create_object';
3338else
3339    set(handles.VOLUME,'BackgroundColor',[0 1 0])
3340end
3341set(handles.uvmat,'UserData',UvData)
3342
3343%-------------------------------------------------------
3344function edit_vect_Callback(hObject, eventdata, handles)
3345%-------------------------------------------------------
3346%
3347% UvData=get(handles.uvmat,'UserData');%read UvData properties stored on the uvmat interface
3348if isequal(get(handles.edit_vect,'Value'),1)
3349    test_civ2=isequal(get(handles.civ2,'BackgroundColor'),[1 1 0]);
3350    test_civ1=isequal(get(handles.VelType,'BackgroundColor'),[1 1 0]);
3351    if ~test_civ2 && ~test_civ1
3352        msgbox_uvmat('ERROR','manual correction only possible for CIV1 or CIV2 velocity fields')
3353    end
3354    set(handles.record,'Visible','on')
3355    set(handles.edit_vect,'BackgroundColor',[1 1 0])
3356    set(handles.edit_object,'Value',0)
3357    set(handles.CheckZoom,'Value',0)
3358    set(handles.CheckZoom,'BackgroundColor',[0.7 0.7 0.7])
3359%     set(handles.create,'Value',0)
3360%     set(handles.create,'BackgroundColor',[0 1 0])
3361    set(handles.edit_object,'BackgroundColor',[0.7 0.7 0.7])
3362    set(gcf,'Pointer','arrow')
3363%     UvData.MouseAction='edit_vect';
3364else
3365    set(handles.record,'Visible','off')
3366    set(handles.edit_vect,'BackgroundColor',[0.7 0.7 0.7])
3367end
3368
3369%----------------------------------------------
3370function save_mask_Callback(hObject, eventdata, handles)
3371%-----------------------------------------------------------------------
3372UvData=get(handles.uvmat,'UserData');
3373
3374flag=1;
3375npx=size(UvData.Field.A,2);
3376npy=size(UvData.Field.A,1);
3377xi=0.5:npx-0.5;
3378yi=0.5:npy-0.5;
3379[Xi,Yi]=meshgrid(xi,yi);
3380if isfield(UvData,'Object')
3381    for iobj=1:length(UvData.Object)
3382        ObjectData=UvData.Object{iobj};
3383        if isfield(ObjectData,'ProjMode') &&(isequal(ObjectData.ProjMode,'mask_inside')||isequal(ObjectData.ProjMode,'mask_outside'));
3384            flagobj=1;
3385            testphys=0; %coordinates in pixels by default
3386            if isfield(ObjectData,'CoordType') && isequal(ObjectData.CoordType,'phys')
3387                if isfield(UvData,'XmlData')&& isfield(UvData.XmlData{1},'GeometryCalib')
3388                    Calib=UvData.XmlData{1}.GeometryCalib;
3389                    testphys=1;
3390                end
3391            end
3392            if isfield(ObjectData,'Coord')& isfield(ObjectData,'Style')
3393                if isequal(ObjectData.Type,'polygon')
3394                    X=ObjectData.Coord(:,1);
3395                    Y=ObjectData.Coord(:,2);
3396                    if testphys
3397                        [X,Y]=px_XYZ(Calib,X,Y,0);% to generalise with 3D cases
3398                    end
3399                    flagobj=~inpolygon(Xi,Yi,X',Y');%=0 inside the polygon, 1 outside                 
3400                elseif isequal(ObjectData.Type,'ellipse')
3401                    if testphys
3402                        %[X,Y]=px_XYZ(Calib,X,Y,0);% TODO:create a polygon boundary and transform to phys
3403                    end
3404                    RangeX=max(ObjectData.RangeX);
3405                    RangeY=max(ObjectData.RangeY);
3406                    X2Max=RangeX*RangeX;
3407                    Y2Max=RangeY*RangeY;
3408                    distX=(Xi-ObjectData.Coord(1,1));
3409                    distY=(Yi-ObjectData.Coord(1,2));
3410                    flagobj=(distX.*distX/X2Max+distY.*distY/Y2Max)>1;
3411                elseif isequal(ObjectData.Type,'rectangle')
3412                    if testphys
3413                        %[X,Y]=px_XYZ(Calib,X,Y,0);% TODO:create a polygon boundary and transform to phys
3414                    end
3415                    distX=abs(Xi-ObjectData.Coord(1,1));
3416                    distY=abs(Yi-ObjectData.Coord(1,2));
3417                    flagobj=distX>max(ObjectData.RangeX) | distY>max(ObjectData.RangeY);
3418                end
3419                if isequal(ObjectData.ProjMode,'mask_outside')
3420                    flagobj=~flagobj;
3421                end
3422                flag=flag & flagobj;
3423            end
3424        end
3425    end
3426end
3427% flag=~flag;
3428%mask name
3429RootPath=get(handles.RootPath,'String');
3430RootFile=get(handles.RootFile,'String');
3431RootFile=regexprep(RootFile,'\<[\\/]|[\\/]\>','');%suppress possible / or \ separator at the beginning or the end of the string
3432filebase=fullfile(RootPath,RootFile);
3433list=get(handles.masklevel,'String');
3434masknumber=num2str(length(list));
3435maskindex=get(handles.masklevel,'Value');
3436mask_name=fullfile_uvmat(RootPath,SubDir,[RootFile '_' masknumber 'mask'],'.png','_1',maskindex);
3437%mask_name=name_generator([filebase '_' masknumber 'mask'],maskindex,1,'.png','_i');
3438imflag=uint8(255*(0.392+0.608*flag));% =100 for flag=0 (vectors not computed when 20<imflag<200)
3439imflag=flipdim(imflag,1);
3440% imflag=uint8(255*flag);% =0 for flag=0 (vectors=0 when 20<imflag<200)
3441msgbox_uvmat('CONFIRMATION',[mask_name ' saved'])
3442imwrite(imflag,mask_name,'BitDepth',8);
3443
3444%display the mask
3445figure;
3446vec=linspace(0,1,256);%define a linear greyscale colormap
3447map=[vec' vec' vec'];
3448colormap(map)
3449
3450image(imflag);
3451
3452%-------------------------------------------------------------------
3453%-------------------------------------------------------------------
3454%  - FUNCTIONS FOR SETTING PLOTTING PARAMETERS
3455
3456%------------------------------------------------------------------
3457%-------------------------------------------------------------
3458% --- Executes on selection change in transform_fct.
3459
3460function transform_fct_Callback(hObject, eventdata, handles)
3461%-------------------------------------------------------------
3462UvData=get(handles.uvmat,'UserData');
3463menu=get(handles.transform_fct,'String');refresh
3464ichoice=get(handles.transform_fct,'Value');%item number in the menu
3465transform_name=menu{ichoice};% choice of the transform fct
3466list_path=get(handles.transform_fct,'UserData');
3467
3468%% add a new item to the menu if the option 'more...' has been selected
3469prev_path=fullfile(get(handles.path_transform,'String'));
3470if ~exist(prev_path,'dir')
3471    prev_path=fullfile(fileparts(which('uvmat')),'transform_field');
3472end
3473if strcmp(transform_name,'more...');
3474    [FileName, PathName] = uigetfile( ...
3475        {'*.m', ' (*.m)';
3476        '*.m',  '.m files '; ...
3477        '*.*', 'All Files (*.*)'}, ...
3478        'Pick the transform function', prev_path);
3479    if ~ischar(FileName),return,end %abandon if the browser is cancelled
3480    path_transform_fct =fullfile(PathName,FileName);
3481    if isempty(regexp(FileName,'\.m$'))% detect file extension .m
3482        msgbox_uvmat('ERROR','a Matlab function .m must be introduced');
3483        return
3484    else
3485        transform_name=regexprep(FileName,'\.m','');
3486    end
3487    ichoice=find(strcmp(transform_name,menu),1);%look for the selected fct in the existing menu
3488    if isempty(ichoice)% if the item is not found, add it to the menu (before 'more...' and select it)
3489        menu=[menu(1:end-1);{transform_name};{'more...'}];
3490        ichoice=numel(menu)-1;   
3491    end
3492    list_path{ichoice}=PathName;%update the list fo fct paths
3493    set(handles.transform_fct,'String',menu)
3494    set(handles.transform_fct,'Value',ichoice)
3495   
3496    % save the new menu in the personal file 'uvmat_perso.mat'
3497    dir_perso=prefdir;%personal Matalb directory
3498    profil_perso=fullfile(dir_perso,'uvmat_perso.mat');
3499    if exist(profil_perso,'file')
3500        nb_builtin=UvData.OpenParam.NbBuiltin;% number of 'builtin' (basic) transform fcts in uvmat
3501        if nb_builtin<numel(list_path)
3502        for ilist=nb_builtin+1:numel(list_path)
3503            transform_fct{ilist-nb_builtin}=[fullfile(list_path{ilist},menu{ilist}) '.m'];
3504        end
3505        save (profil_perso,'transform_fct','-append'); %store the root name for future opening of uvmat
3506        end
3507    end
3508end
3509
3510%% create the function handle of the selected fct
3511
3512if isempty(list_path{ichoice})% case of no selected fct
3513    transform_handle=[];
3514else
3515    if ~exist(list_path{ichoice},'dir')
3516        msgbox_uvmat('ERROR','invalid fct path: select the transform fct again with the option more...')
3517        return
3518    end
3519    current_dir=pwd;%current working dir
3520    cd(list_path{ichoice})
3521    transform_handle=str2func(transform_name);
3522    cd(current_dir)
3523end
3524set(handles.path_transform,'String',list_path{ichoice})
3525set(handles.path_transform,'UserData',transform_handle)
3526set(handles.transform_fct,'UserData',list_path)
3527
3528%% update the ToolTip string of the menu transform_fct with the first line of the selected fct file
3529if isempty(list_path{ichoice})% case of no selected fct
3530    set(handles.transform_fct,'ToolTipString','transform_fct:choose a transform function')
3531else
3532    try
3533        [fid,errormsg] =fopen([fullfile(list_path{ichoice},transform_name) '.m']);
3534        InputText=textscan(fid,'%s',1,'delimiter','\n');
3535        fclose(fid)
3536        set(handles.transform_fct,'ToolTipString',['transform_fct: ' InputText{1}{1}])% put the first line of the selected function as tooltip help
3537    end
3538end
3539
3540%% adapt the GUI to the input/output conditions of the selected transform fct
3541DataOut=[];
3542CoordUnit='';
3543CoordUnitPrev='';
3544if isfield(UvData,'Field')&&isfield(UvData.Field,'CoordUnit')
3545    CoordUnitPrev=UvData.Field.CoordUnit;
3546end
3547if ~isempty(list_path{ichoice})
3548    if nargin(transform_handle)>1 && isfield(UvData,'XmlData')&&~isempty(UvData.XmlData)
3549        XmlData=UvData.XmlData{1};
3550        DataOut=feval(transform_handle,'*',XmlData);
3551        if isfield(DataOut,'CoordUnit')
3552            CoordUnit=DataOut.CoordUnit;
3553        end
3554        if isfield(DataOut,'InputFieldType')
3555            UvData.InputFieldType=DataOut.InputFieldType;
3556        end
3557    else
3558        DataOut=feval(transform_handle,'*');
3559    end
3560end
3561
3562
3563%% delete drawn objects if the output CooordUnit is different from the previous one
3564if ~strcmp(CoordUnit,CoordUnitPrev)
3565    set(handles.CheckFixLimits,'Value',0)
3566set(handles.CheckFixLimits,'BackgroundColor',[0.7 0.7 0.7])
3567    hother=findobj('Tag','proj_object');%find all the proj objects
3568    for iobj=1:length(hother)
3569        delete_object(hother(iobj))
3570    end
3571    hother=findobj('Tag','DeformPoint');%find all the proj objects
3572    for iobj=1:length(hother)
3573        delete_object(hother(iobj))
3574    end
3575    hh=findobj('Tag','calib_points');
3576    if ~isempty(hh)
3577        delete(hh)
3578    end
3579    hhh=findobj('Tag','calib_marker');
3580    if ~isempty(hhh)
3581        delete(hhh)
3582    end
3583%     if isfield(UvData,'Object')
3584%         UvData.Object=UvData.Object(1);
3585%     end
3586    set(handles.ListObject,'Value',1)
3587    set(handles.ListObject,'String',{''})
3588    set(handles.ListObject_1,'Value',1)
3589    set(handles.ListObject_1,'String',{''})
3590    set(handles.ViewObject,'value',0)
3591    ViewObject_Callback(hObject, eventdata, handles)
3592    set(handles.ViewField,'value',0)
3593    ViewField_Callback(hObject, eventdata, handles)
3594    set(handles.edit_object,'Value',0)
3595    edit_object_Callback(hObject, eventdata, handles)
3596    UvData.Object={[]};
3597end
3598set(handles.uvmat,'UserData',UvData)
3599
3600%% refresh the current plot
3601if isempty(list_path{ichoice}) || nargin(transform_handle)<3
3602    set(handles.SubField,'Value',0)
3603    SubField_Callback(hObject, eventdata, handles)
3604else
3605    run0_Callback(hObject, eventdata, handles)
3606end
3607
3608%------------------------------------------------
3609%CALLBACKS FOR PLOTTING PARAMETERS
3610%-------------------------------------------------
3611%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3612% Plot coordinates
3613%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3614%------------------------------------------------------------------------
3615function num_MinX_Callback(hObject, eventdata, handles)
3616%------------------------------------------------------------------------
3617set(handles.CheckFixLimits,'Value',1) %suppress auto mode
3618set(handles.CheckFixLimits,'BackgroundColor',[1 1 0])
3619update_plot(handles);
3620
3621%------------------------------------------------------------------------
3622function num_MaxX_Callback(hObject, eventdata, handles)
3623%------------------------------------------------------------------------
3624set(handles.CheckFixLimits,'Value',1) %suppress auto mode
3625set(handles.CheckFixLimits,'BackgroundColor',[1 1 0])
3626update_plot(handles);
3627
3628%------------------------------------------------------------------------
3629function num_MinY_Callback(hObject, eventdata, handles)
3630%------------------------------------------
3631set(handles.CheckFixLimits,'Value',1) %suppress auto mode
3632set(handles.CheckFixLimits,'BackgroundColor',[1 1 0])
3633update_plot(handles);
3634
3635%------------------------------------------------------------------------
3636function num_MaxY_Callback(hObject, eventdata, handles)
3637%------------------------------------------------------------------------
3638set(handles.CheckFixLimits,'Value',1) %suppress auto mode
3639set(handles.CheckFixLimits,'BackgroundColor',[1 1 0])
3640update_plot(handles);
3641
3642%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3643% Scalar or image representation
3644%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3645%------------------------------------------------------------------------
3646function num_MinA_Callback(hObject, eventdata, handles)
3647%------------------------------------------
3648set(handles.CheckFixScalar,'Value',1) %suppress auto mode
3649set(handles.CheckFixScalar,'BackgroundColor',[1 1 0])
3650MinA=str2double(get(handles.num_MinA,'String'));
3651MaxA=str2double(get(handles.num_MaxA,'String'));
3652if MinA>MaxA% switch minA and maxA in case of error
3653    MinA_old=MinA;
3654    MinA=MaxA;
3655    MaxA=MinA_old;
3656    set(handles.num_MinA,'String',num2str(MinA,5));
3657    set(handles.num_MaxA,'String',num2str(MaxA,5));
3658end
3659update_plot(handles);
3660
3661%------------------------------------------------------------------------
3662function num_MaxA_Callback(hObject, eventdata, handles)
3663%------------------------------------------------------------------------
3664set(handles.CheckFixScalar,'Value',1) %suppress auto mode
3665set(handles.CheckFixScalar,'BackgroundColor',[1 1 0])
3666MinA=str2double(get(handles.num_MinA,'String'));
3667MaxA=str2double(get(handles.num_MaxA,'String'));
3668if MinA>MaxA% switch minA and maxA in case of error
3669        MinA_old=MinA;
3670    MinA=MaxA;
3671    MaxA=MinA_old;
3672    set(handles.num_MinA,'String',num2str(MinA,5));
3673    set(handles.num_MaxA,'String',num2str(MaxA,5));
3674end
3675update_plot(handles);
3676
3677%------------------------------------------------------------------------
3678function CheckFixScalar_Callback(hObject, eventdata, handles)
3679%------------------------------------------------------------------------
3680test=get(handles.CheckFixScalar,'Value');
3681if test
3682    set(handles.CheckFixScalar,'BackgroundColor',[1 1 0])
3683else
3684    set(handles.CheckFixScalar,'BackgroundColor',[0.7 0.7 0.7])
3685    update_plot(handles);
3686end
3687
3688%-------------------------------------------------------------------
3689function CheckBW_Callback(hObject, eventdata, handles)
3690%-------------------------------------------------------------------
3691update_plot(handles);
3692
3693%-------------------------------------------------------------------
3694function num_Opacity_Callback(hObject, eventdata, handles)
3695update_plot(handles);
3696%-------------------------------------------------------------------
3697
3698%-------------------------------------------------------------------
3699function ListContour_Callback(hObject, eventdata, handles)
3700%-------------------------------------------------------------------
3701val=get(handles.ListContour,'Value');
3702if val==2
3703    set(handles.interval_txt,'Visible','on')
3704    set(handles.num_IncrA,'Visible','on')
3705else
3706    set(handles.interval_txt,'Visible','off')
3707    set(handles.num_IncrA,'Visible','off')
3708end
3709update_plot(handles);
3710
3711%-------------------------------------------------------------------
3712function num_IncrA_Callback(hObject, eventdata, handles)
3713%-------------------------------------------------------------------
3714update_plot(handles);
3715
3716
3717%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3718% Vector representation
3719%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3720%-------------------------------------------------------------------
3721function CheckHideWarning_Callback(hObject, eventdata, handles)
3722%-------------------------------------------------------------------
3723update_plot(handles);
3724
3725%-------------------------------------------------------------------
3726function CheckHideFalse_Callback(hObject, eventdata, handles)
3727%-------------------------------------------------------------------
3728update_plot(handles);
3729
3730%-------------------------------------------------------------------
3731function num_VecScale_Callback(hObject, eventdata, handles)
3732%-------------------------------------------------------------------
3733set(handles.CheckFixVectors,'Value',1);
3734set(handles.CheckFixVectors,'BackgroundColor',[1 1 0])
3735update_plot(handles);
3736
3737%-------------------------------------------------------------------
3738function CheckFixVectors_Callback(hObject, eventdata, handles)
3739%-------------------------------------------------------------------
3740test=get(handles.CheckFixVectors,'Value');
3741if test
3742    set(handles.CheckFixVectors,'BackgroundColor',[1 1 0])
3743else
3744    update_plot(handles);
3745    %set(handles.num_VecScale,'String',num2str(ScalOut.num_VecScale,3))
3746    set(handles.CheckFixVectors,'BackgroundColor',[0.7 0.7 0.7])
3747end
3748
3749%------------------------------------------------------------------------
3750% --- Executes on selection change in CheckDecimate4 (nb_vec/4).
3751function CheckDecimate4_Callback(hObject, eventdata, handles)
3752%------------------------------------------------------------------------
3753update_plot(handles);
3754
3755%------------------------------------------------------------------------
3756% --- Executes on selection change in ColorCode menu
3757function ColorCode_Callback(hObject, eventdata, handles)
3758%------------------------------------------------------------------------
3759% edit the choice for color code
3760update_color_code_boxes(handles);
3761update_plot(handles);
3762
3763%------------------------------------------------------------------------
3764function update_color_code_boxes(handles)
3765%------------------------------------------------------------------------
3766list_code=get(handles.ColorCode,'String');% list menu fields
3767colcode= list_code{get(handles.ColorCode,'Value')}; % selected field
3768enable_slider='off';%default
3769enable_bounds='off';%default
3770enable_scalar='off';%default
3771switch colcode
3772    case {'rgb','bgr'}
3773        enable_slider='on';
3774        enable_bounds='on';
3775        enable_scalar='on';
3776    case '64 colors'
3777        enable_bounds='on';
3778        enable_scalar='on';
3779end
3780set(handles.Slider1,'Visible',enable_slider)
3781set(handles.Slider2,'Visible', enable_slider)
3782set(handles.num_ColCode1,'Visible',enable_slider)
3783set(handles.num_ColCode2,'Visible',enable_slider)
3784set(handles.TitleColCode1,'Visible',enable_slider)
3785set(handles.TitleColCode2,'Visible',enable_slider)
3786set(handles.CheckFixVecColor,'Visible',enable_bounds)
3787set(handles.num_MinVec,'Visible',enable_bounds)
3788set(handles.num_MaxVec,'Visible',enable_bounds)
3789set(handles.ColorScalar,'Visible',enable_scalar)
3790set_vec_col_bar(handles)
3791
3792%------------------------------------------------------------------
3793% --- Executes on selection change in ColorScalar: choice of the color code.
3794function ColorScalar_Callback(hObject, eventdata, handles)
3795%------------------------------------------------------------------
3796% edit the choice for color code
3797list_scalar=get(handles.ColorScalar,'String');% list menu fields
3798col_scalar= list_scalar{get(handles.ColorScalar,'Value')}; % selected field
3799if isequal(col_scalar,'ima_cor')
3800    set(handles.CheckFixVecColor,'Value',1)%fixed scale by default
3801    ColorCode='rgb';
3802    set(handles.num_MinVec,'String','0')
3803    set(handles.num_MaxVec,'String','1')
3804    set(handles.num_ColCode1,'String','0.333')
3805    set(handles.num_ColCode2,'String','0.666')
3806else
3807    set(handles.CheckFixVecColor,'Value',0)%auto scale between min,max by default
3808    ColorCode='64 colors';
3809end
3810ColorCodeList=get(handles.ColorCode,'String');
3811ichoice=find(strcmp(ColorCode,ColorCodeList),1);
3812set(handles.ColorCode,'Value',ichoice)% set color code in the menu
3813
3814update_color_code_boxes(handles);
3815%replot the current graph
3816run0_Callback(hObject, eventdata, handles)
3817
3818%----------------------------------------------------------------
3819% -- Executes on slider movement to set the color code
3820%
3821function Slider1_Callback(hObject, eventdata, handles)
3822%------------------------------------------------------------------
3823slider1=get(handles.Slider1,'Value');
3824min_val=str2num(get(handles.num_MinVec,'String'));
3825max_val=str2num(get(handles.num_MaxVec,'String'));
3826col=min_val+(max_val-min_val)*slider1;
3827set(handles.num_ColCode1,'String',num2str(col))
3828if(get(handles.Slider2,'Value') < col)%move also the second slider at the same value if needed
3829    set(handles.Slider2,'Value',col)
3830    set(handles.num_ColCode2,'String',num2str(col))
3831end
3832set_vec_col_bar(handles)
3833update_plot(handles);
3834
3835%----------------------------------------------------------------
3836% Executes on slider movement to set the color code
3837%----------------------------------------------------------------
3838function Slider2_Callback(hObject, eventdata, handles)
3839slider2=get(handles.Slider2,'Value');
3840min_val=str2num(get(handles.num_MinVec,'String'));
3841max_val=str2num(get(handles.num_MaxVec,'String'));
3842col=min_val+(max_val-min_val)*slider2;
3843set(handles.num_ColCode2,'String',num2str(col))
3844if(get(handles.Slider1,'Value') > col)%move also the first slider at the same value if needed
3845    set(handles.Slider1,'Value',col)
3846    set(handles.num_ColCode1,'String',num2str(col))
3847end
3848set_vec_col_bar(handles)
3849update_plot(handles);
3850
3851%----------------------------------------------------------------
3852% --- Execute on return carriage on the edit box corresponding to slider 1
3853%----------------------------------------------------------------
3854function num_ColCode1_Callback(hObject, eventdata, handles)
3855set_vec_col_bar(handles)
3856update_plot(handles);
3857
3858%----------------------------------------------------------------
3859% --- Execute on return carriage on the edit box corresponding to slider 2
3860%----------------------------------------------------------------
3861function num_ColCode2_Callback(hObject, eventdata, handles)
3862set_vec_col_bar(handles)
3863update_plot(handles);
3864%------------------------------------------------------------------------
3865%-------------------------------------------------------
3866% --- Executes on button press in CheckFixVecColor.
3867%-------------------------------------------------------
3868function VecColBar_Callback(hObject, eventdata, handles)
3869set_vec_col_bar(handles)
3870
3871%------------------------------------------------------------------------
3872% --- Executes on button press in CheckFixVecColor.
3873function CheckFixVecColor_Callback(hObject, eventdata, handles)
3874%------------------------------------------------------------------------
3875if ~get(handles.CheckFixVecColor,'Value')
3876    update_plot(handles);
3877end
3878
3879%------------------------------------------------------------------------
3880% --- Executes on selection change in num_MaxVec.
3881function num_MinVec_Callback(hObject, eventdata, handles)
3882%------------------------------------------------------------------------
3883max_vec_Callback(hObject, eventdata, handles)
3884
3885%------------------------------------------------------------------------
3886% --- Executes on selection change in num_MaxVec.
3887function num_MaxVec_Callback(hObject, eventdata, handles)
3888%------------------------------------------------------------------------
3889set(handles.CheckFixVecColor,'Value',1)
3890CheckFixVecColor_Callback(hObject, eventdata, handles)
3891min_val=str2num(get(handles.num_MinVec,'String'));
3892max_val=str2num(get(handles.num_MaxVec,'String'));
3893slider1=get(handles.Slider1,'Value');
3894slider2=get(handles.Slider2,'Value');
3895colcode1=min_val+(max_val-min_val)*slider1;
3896colcode2=min_val+(max_val-min_val)*slider2;
3897set(handles.num_ColCode1,'String',num2str(colcode1))
3898set(handles.num_ColCode2,'String',num2str(colcode2))
3899update_plot(handles);
3900
3901%------------------------------------------------------------------------
3902% --- update the display of color code for vectors (on vecColBar)
3903function set_vec_col_bar(handles)
3904%------------------------------------------------------------------------
3905%get the image of the color display button 'VecColBar' in pixels
3906set(handles.VecColBar,'Unit','pixel');
3907pos_vert=get(handles.VecColBar,'Position');
3908set(handles.VecColBar,'Unit','Normalized');
3909width=ceil(pos_vert(3));
3910height=ceil(pos_vert(4));
3911
3912%get slider indications
3913list=get(handles.ColorCode,'String');
3914ichoice=get(handles.ColorCode,'Value');
3915colcode.ColorCode=list{ichoice};
3916colcode.MinVec=str2num(get(handles.num_MinVec,'String'));
3917colcode.MaxVec=str2num(get(handles.num_MaxVec,'String'));
3918test3color=strcmp(colcode.ColorCode,'rgb') || strcmp(colcode.ColorCode,'bgr');
3919if test3color
3920    colcode.ColCode1=str2num(get(handles.num_ColCode1,'String'));
3921    colcode.ColCode2=str2num(get(handles.num_ColCode2,'String'));
3922end
3923vec_C=colcode.MinVec+(colcode.MaxVec-colcode.MinVec)*(0.5:width-0.5)/width;%sample of vec_C values from min to max
3924[colorlist,col_vec]=set_col_vec(colcode,vec_C);
3925oneheight=ones(1,height);
3926A1=colorlist(col_vec,1)*oneheight;
3927A2=colorlist(col_vec,2)*oneheight;
3928A3=colorlist(col_vec,3)*oneheight;
3929A(:,:,1)=A1';
3930A(:,:,2)=A2';
3931A(:,:,3)=A3';
3932set(handles.VecColBar,'Cdata',A)
3933
3934%-------------------------------------------------------------------
3935function update_plot(handles)
3936%-------------------------------------------------------------------
3937UvData=get(handles.uvmat,'UserData');
3938AxeData=UvData.PlotAxes;% retrieve the current plotted data
3939PlotParam=read_GUI(handles.uvmat);
3940[tild,PlotParamOut]= plot_field(AxeData,handles.PlotAxes,PlotParam);
3941write_plot_param(handles,PlotParamOut); %update the auto plot parameters
3942
3943%------------------------------------------------------------------------
3944%------------------------------------------------------------------------
3945%   SELECTION AND EDITION OF PROJECTION OBJECTS
3946%------------------------------------------------------------------------
3947%------------------------------------------------------------------------
3948
3949% --- Executes on selection change in ListObject_1.
3950function ListObject_1_Callback(hObject, eventdata, handles)
3951list_str=get(handles.ListObject,'String');
3952UvData=get(handles.uvmat,'UserData');
3953ObjectData=UvData.Object{get(handles.ListObject_1,'Value')};
3954
3955%% update the projection plot on uvmat
3956ProjData= proj_field(UvData.Field,ObjectData);%project the current input field on object ObjectData
3957plot_field(ProjData,handles.PlotAxes,read_GUI(handles.uvmat));% plot the projected field;
3958%replot all the objects within the new projected field
3959for IndexObj=1:numel(list_str)
3960        hobject=UvData.Object{IndexObj}.DisplayHandle.uvmat;
3961        if isempty(hobject) || ~ishandle(hobject)
3962            hobject=handles.PlotAxes;
3963        end
3964        if isequal(IndexObj,get(handles.ListObject,'Value'))
3965            objectcolor='m'; %paint in magenta the currently selected object in ListObject
3966        else
3967            objectcolor='b';
3968        end
3969        UvData.Object{IndexObj}.DisplayHandle.uvmat=plot_object(UvData.Object{IndexObj},ObjectData,hobject,objectcolor);%draw the object in uvmat     
3970end
3971set(handles.uvmat,'UserData',UvData)
3972
3973%% display the object parameters if the GUI set_object is already opened
3974if ~get(handles.ViewObject,'Value')
3975    ZBounds=0; % default
3976    if isfield(UvData.Field,'ZMin') && isfield(UvData.Field,'ZMax')
3977        ZBounds(1)=UvData.Field.ZMin; %minimum for the Z slider
3978        ZBounds(2)=UvData.Field.ZMax;%maximum for the Z slider
3979    end
3980    ObjectData.Name=list_str{get(handles.ListObject_1,'Value')};
3981    set_object(ObjectData,[],ZBounds);
3982    set(handles.ViewObject,'Value',1)% show that the selected object in ListObject_1 is currently visualised
3983end
3984
3985%  desactivate the edit object mode
3986set(handles.edit_object,'Value',0)
3987set(handles.edit_object,'BackgroundColor',[0.7,0.7,0.7])
3988
3989%------------------------------------------------------------------------
3990% --- Executes on selection change in ListObject.
3991function ListObject_Callback(hObject, eventdata, handles)
3992%------------------------------------------------------------------------
3993list_str=get(handles.ListObject,'String');
3994IndexObj=get(handles.ListObject,'Value');%present object selection
3995
3996%% The object  is displayed in set_object if this GUI is already opened
3997UvData=get(handles.uvmat,'UserData');
3998ObjectData=UvData.Object{IndexObj};
3999hset_object=findobj(allchild(0),'tag','set_object');
4000if ~isempty(hset_object)
4001    ZBounds=0; % default
4002    if isfield(UvData.Field,'ZMin') && isfield(UvData.Field,'ZMax')
4003        ZBounds(1)=UvData.Field.ZMin; %minimum for the Z slider
4004        ZBounds(2)=UvData.Field.ZMax;%maximum for the Z slider
4005    end
4006    ObjectData.Name=list_str{IndexObj};
4007    set_object(ObjectData,[],ZBounds);
4008    set(handles.ViewField,'Value',1)% show that the selected object in ListObject is currently visualised
4009end
4010
4011%%  desactivate the edit object mode
4012set(handles.edit_object,'Value',0)
4013set(handles.edit_object,'BackgroundColor',[0.7,0.7,0.7])
4014
4015%% update the  plot on view_field if view_field is already openened
4016hview_field=findobj(allchild(0),'tag','view_field');
4017if isempty(hview_field)
4018    hhview_field.PlotAxes=[];
4019else
4020    Data=get(hview_field,'UserData');
4021    hhview_field=guidata(hview_field);
4022    ProjData= proj_field(UvData.Field,ObjectData);%project the current interface field on ObjectData
4023    [PlotType,PlotParam]=plot_field(ProjData,hhview_field.PlotAxes,read_GUI(hview_field));%read plotting parameters on the uvmat interfachhview_fiel
4024    write_plot_param(hhview_field,PlotParam); %update the display of plotting parameters for the current object
4025    haxes=findobj(hview_field,'tag','axes3');
4026    pos=get(hview_field,'Position'); 
4027    if strcmp(get(haxes,'Visible'),'off')%sempty(PlotParam.Coordinates)% case of no plot display (pure text table)
4028        h_TableDisplay=findobj(hview_field,'tag','TableDisplay');
4029        pos_table=get(h_TableDisplay,'Position');
4030        set(hview_field,'Position',[pos(1)+pos(3)-pos_table(3) pos(2)+pos(4)-pos_table(4) pos_table(3) pos_table(4)])
4031        drawnow% needed to change position before the next command
4032        set(hview_field,'UserData',Data);% restore the previously stored GUI position after GUI resizing
4033    else
4034        set(hview_field,'Position',Data.GUISize)% return to the previously stored GUI position and size
4035    end
4036end
4037
4038%% update the color of the graphic object representation: the selected object in magenta, others in blue
4039update_object_color(handles.PlotAxes,hhview_field.PlotAxes,UvData.Object{IndexObj}.DisplayHandle.uvmat)
4040
4041%------------------------------------------------------------------------
4042%--- update the color representation of objects (indicating the selected ones)
4043function update_object_color(axes_uvmat,axes_view_field,DisplayHandle)
4044%------------------------------------------------------------------------
4045if isempty(axes_view_field)% case with no view_field plot
4046hother=[findobj(axes_uvmat,'Tag','proj_object');findobj(axes_uvmat,'Tag','DeformPoint')];%find all the proj object and deform point representations
4047else
4048hother=[findobj(axes_uvmat,'Tag','proj_object') ;findobj(axes_view_field,'Tag','proj_object');... %find all the proj object representations
4049findobj(axes_uvmat,'Tag','DeformPoint'); findobj(axes_view_field,'Tag','DeformPoint')];%find all the deform point representations
4050end
4051for iobj=1:length(hother)
4052    if isequal(get(hother(iobj),'Type'),'rectangle')||isequal(get(hother(iobj),'Type'),'patch')
4053        set(hother(iobj),'EdgeColor','b')
4054        if isequal(get(hother(iobj),'FaceColor'),'m')
4055            set(hother(iobj),'FaceColor','b')
4056        end
4057    elseif isequal(get(hother(iobj),'Type'),'image')
4058        Acolor=get(hother(iobj),'CData');
4059        Acolor(:,:,1)=zeros(size(Acolor,1),size(Acolor,2));
4060        set(hother(iobj),'CData',Acolor);
4061    else
4062        set(hother(iobj),'Color','b')
4063    end
4064    set(hother(iobj),'Selected','off')
4065end
4066if ishandle(DisplayHandle)
4067    linetype=get(DisplayHandle,'Type');
4068    if isequal(linetype,'line')
4069        set(DisplayHandle,'Color','m'); %set the selected object to magenta color
4070    elseif isequal(linetype,'rectangle')
4071        set(DisplayHandle,'EdgeColor','m'); %set the selected object to magenta color
4072    elseif isequal(linetype,'patch')
4073        set(DisplayHandle,'FaceColor','m'); %set the selected object to magenta color
4074    end
4075    SubObjectData=get(DisplayHandle,'UserData');
4076    if isfield(SubObjectData,'SubObject') & ishandle(SubObjectData.SubObject)
4077        for iobj=1:length(SubObjectData.SubObject)
4078            hsub=SubObjectData.SubObject(iobj);
4079            if isequal(get(hsub,'Type'),'rectangle')
4080                set(hsub,'EdgeColor','m'); %set the selected object to magenta color
4081            elseif isequal(get(hsub,'Type'),'image')
4082                Acolor=get(hsub,'CData');
4083                Acolor(:,:,1)=Acolor(:,:,3);
4084                set(hsub,'CData',Acolor);
4085            else
4086                set(hsub,'Color','m')
4087            end
4088        end
4089    end
4090    if isfield(SubObjectData,'DeformPoint') & ishandle(SubObjectData.DeformPoint)
4091        set(SubObjectData.DeformPoint,'Color','m')
4092    end
4093end
4094
4095%-------------------------------------------------------------------
4096% --- Executes on selection change in edit_object.
4097function edit_object_Callback(hObject, eventdata, handles)
4098%-------------------------------------------------------------------
4099UvData=get(handles.uvmat,'UserData');%read UvData properties stored on the uvmat interface
4100hset_object=findobj(allchild(0),'Tag','set_object');
4101if get(handles.edit_object,'Value')
4102    set(handles.edit_object,'BackgroundColor',[1,1,0]) 
4103    %suppress the other options
4104    set(handles.CheckZoom,'Value',0)
4105    CheckZoom_Callback(hObject, eventdata, handles)
4106    hgeometry_calib=findobj(allchild(0),'tag','geometry_calib');
4107    if ishandle(hgeometry_calib)
4108        hhgeometry_calib=guidata(hgeometry_calib);
4109        set(hhgeometry_calib.edit_append,'Value',0)% desactivate mouse action in geometry_calib
4110        set(hhgeometry_calib.edit_append,'BackgroundColor',[0.7 0.7 0.7])
4111    end
4112    set(handles.ViewObject,'value',1)
4113    ViewObject_Callback(hObject, eventdata, handles)
4114else % desctivate object edit mode
4115    set(handles.edit_object,'BackgroundColor',[0.7,0.7,0.7]) 
4116    if ~isempty(hset_object)% open the
4117        hhset_object=guidata(hset_object);
4118        set(hhset_object.PLOT,'enable','off');
4119        set(get(hset_object,'children'),'enable','inactive')
4120    end
4121end
4122
4123
4124%------------------------------------------------------------------------
4125% --- Executes on button press in ViewObject.
4126function ViewObject_Callback(hObject, eventdata, handles)
4127%------------------------------------------------------------------------
4128check_view=get(handles.ViewObject,'Value');
4129
4130if check_view %activate set_object   
4131    IndexObj=get(handles.ListObject,'Value');
4132    list_object=get(handles.ListObject,'String');
4133    UvData=get(handles.uvmat,'UserData');%read UvData properties stored on the uvmat interface
4134    UvData.Object{IndexObj}.Name=list_object{IndexObj};
4135    if numel(UvData.Object)<IndexObj;% error in UvData
4136        msgbox_uvmat('ERROR','invalid object list')
4137        return
4138    end
4139    ZBounds=0; % default
4140    if isfield(UvData.Field,'ZMin') && isfield(UvData.Field,'ZMax')
4141        ZBounds(1)=UvData.Field.ZMin; %minimum for the Z slider
4142        ZBounds(2)=UvData.Field.ZMax;%maximum for the Z slider
4143    end
4144%     set(handles.ListObject_1,'Value',IndexObj);%restore ListObject selection after set_object deletion
4145    data=UvData.Object{IndexObj};
4146    if ~isfield(data,'Type')% default plane
4147        data.Type='plane';
4148    end
4149%     if isfield(UvData,'Field')
4150%         Field=UvData.Field;
4151%         if isfield(UvData.Field,'Mesh')&&~isempty(UvData.Field.Mesh)
4152%             data.RangeX=[UvData.Field.XMin UvData.Field.XMax];
4153%             if strcmp(data.Type,'line')||strcmp(data.Type,'polyline')
4154%                 data.RangeY=UvData.Field.Mesh;
4155%             else
4156%                 data.RangeY=[UvData.Field.YMin UvData.Field.YMax];
4157%             end
4158%             data.DX=UvData.Field.Mesh;
4159%             data.DY=UvData.Field.Mesh;
4160%         end
4161%         if isfield(Field,'NbDim')&& isequal(Field.NbDim,3)
4162%             data.Coord=[0 0 0]; %default
4163%         end
4164%         if isfield(Field,'CoordUnit')
4165%             data.CoordUnit=Field.CoordUnit;
4166%         end
4167%     end
4168    hset_object=set_object(data,[],ZBounds);
4169    hhset_object=guidata(hset_object);
4170    if get(handles.edit_object,'Value')% edit mode
4171        set(hhset_object.PLOT,'Enable','on')
4172        set(get(hset_object,'children'),'enable','on')
4173    else
4174        set(hhset_object.PLOT,'Enable','off')
4175        set(get(hset_object,'children'),'enable','inactive')% deactivate the GUI except SAVE
4176        set(hhset_object.SAVE,'Enable','on')
4177    end
4178else
4179    hset_object=findobj(allchild(0),'tag','set_object');
4180    if ~isempty(hset_object)
4181        delete(hset_object)% delete existing version of set_object
4182    end
4183end
4184 
4185
4186%------------------------------------------------------------------------
4187% --- Executes on button press in ViewField.
4188function ViewField_Callback(hObject, eventdata, handles)
4189%------------------------------------------------------------------------
4190check_view=get(handles.ViewField,'Value');
4191
4192if check_view
4193    IndexObj=get(handles.ListObject,'Value');
4194    UvData=get(handles.uvmat,'UserData');%read UvData properties stored on the uvmat interface
4195    if numel(UvData.Object)<IndexObj(end);% error in UvData
4196        msgbox_uvmat('ERROR','invalid object list')
4197        return
4198    end
4199    ZBounds=0; % default
4200    if isfield(UvData.Field,'ZMin') && isfield(UvData.Field,'ZMax')
4201        ZBounds(1)=UvData.Field.ZMin; %minimum for the Z slider
4202        ZBounds(2)=UvData.Field.ZMax;%maximum for the Z slider
4203    end
4204    set(handles.ListObject,'Value',IndexObj);%restore ListObject selection after set_object deletion
4205    if ~isfield(UvData.Object{IndexObj(1)},'Type')% default plane
4206        UvData.Object{IndexObj(1)}.Type='plane';
4207    end
4208    list_object=get(handles.ListObject,'String');
4209    UvData.Object{IndexObj(end)}.Name=list_object{IndexObj(end)};
4210   
4211    %% show the projection of the selected object on view_field
4212    ProjData= proj_field(UvData.Field,UvData.Object{IndexObj});%project the current field on ObjectData
4213    hview_field=findobj(allchild(0),'tag','view_field');
4214    if isempty(hview_field)
4215        hview_field=view_field;
4216    end
4217    hhview_field=guidata(hview_field);
4218    [PlotType,PlotParam]=plot_field(ProjData,hhview_field.PlotAxes,read_GUI(hview_field));%read plotting parameters on the GUI view_field);
4219    write_plot_param(hhview_field,PlotParam); %update the display of plotting parameters for the current object
4220    haxes=findobj(hview_field,'tag','axes3');
4221    pos=get(hview_field,'Position');
4222    if strcmp(get(haxes,'Visible'),'off')%sempty(PlotParam.Coordinates)% case of no plot display (pure text table)
4223        h_TableDisplay=findobj(hview_field,'tag','TableDisplay');
4224        pos_table=get(h_TableDisplay,'Position');
4225        set(hview_field,'Position',[pos(1)+pos(3)-pos_table(3) pos(2)+pos(4)-pos_table(4) pos_table(3) pos_table(4)])
4226    else
4227        Data=get(hview_field,'UserData');
4228        set(hview_field,'Position',Data.GUISize)% restore the size of view_field for plots
4229    end
4230else
4231    hview_field=findobj(allchild(0),'tag','view_field');
4232    if ~isempty(hview_field)
4233        delete(hview_field)% delete existing version of set_object
4234    end
4235end
4236
4237
4238%------------------------------------------------------------------------
4239% --- Executes on button press in delete_object.
4240function delete_object_Callback(hObject, eventdata, handles)
4241%------------------------------------------------------------------------
4242IndexObj=get(handles.ListObject,'Value');%projection object selected for view_field
4243IndexObj_1=get(handles.ListObject_1,'Value');%projection object selected for uvmat plot
4244if IndexObj>1 && ~isequal(IndexObj,IndexObj_1) % do not delete the object used for the uvmat plot
4245    delete_object(IndexObj)
4246end
4247
4248%------------------------------------------------------------------------
4249%------------------------------------------------------------------------
4250%  II - TOOLS FROM THE UPPER MENU BAR
4251%------------------------------------------------------------------------
4252%------------------------------------------------------------------------
4253
4254%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4255% Export  Menu Callbacks
4256%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4257%------------------------------------------------------------------------
4258% --- Executes on button press in Menu/Export/field in workspace.
4259function MenuExportField_Callback(hObject, eventdata, handles)
4260%------------------------------------------------------------------------
4261global Data_uvmat
4262Data_uvmat=get(handles.uvmat,'UserData');
4263evalin('base','global Data_uvmat')%make CurData global in the workspace
4264display('current field :')
4265evalin('base','Data_uvmat') %display CurData in the workspace
4266commandwindow; %brings the Matlab command window to the front
4267
4268%------------------------------------------------------------------------
4269% --- Executes on button press in Menu/Export/extract figure.
4270function MenuExportFigure_Callback(hObject, eventdata, handles)
4271%------------------------------------------------------------------------
4272% huvmat=get(handles.MenuExport,'parent');
4273hfig=figure;
4274copyobj(handles.PlotAxes,hfig);
4275map=colormap(handles.PlotAxes);
4276colormap(map);%transmit the current colormap to the zoom fig
4277colorbar
4278
4279% --------------------------------------------------------------------
4280function MenuExportAxis_Callback(hObject, eventdata, handles)
4281answer=msgbox_uvmat('CONFIRMATION','select a figure/axis on which the current uvmat plot will be exported')
4282if strcmp(answer,'Yes')
4283hchild=get(handles.PlotAxes,'children');
4284copyobj(hchild,gca);
4285end
4286
4287%------------------------------------------------------------------------
4288% --------------------------------------------------------------------
4289function MenuExportMovie_Callback(hObject, eventdata, handles)
4290% --------------------------------------------------------------------
4291set(handles.MenuExportMovie,'BusyAction','queue')% activate the button
4292huvmat=get(handles.run0,'parent');
4293UvData=get(huvmat,'UserData');
4294%[xx,xx,FileBase]=read_file_boxes(handles);
4295[RootPath,SubDir,RootFile,FileIndex,FileExt]=read_file_boxes(handles);
4296FileBase=fullfile(RootPath,RootFile);
4297 %read the current input file name
4298prompt = {'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)'};
4299dlg_title = 'select properties of the output avi movie';
4300num_lines= 1;
4301def     = {[FileBase '_out.avi'];'10';'1';'[0.03 0.05 0.95 0.92]';'10'};
4302answer = inputdlg(prompt,dlg_title,num_lines,def,'on');
4303aviname=answer{1};
4304fps=str2double(answer{2});
4305% check for existing file with output name aviname
4306if exist(aviname,'file')
4307    backup=aviname;
4308    testexist=2;
4309    while testexist==2
4310        backup=[backup '~'];
4311        testexist=exist(backup,'file');     
4312    end
4313    [success,message]=copyfile(aviname,backup);%make backup of the existing file
4314    if isequal(success,1)
4315        delete(aviname)%delete existing file
4316    else
4317        msgbox_uvmat('ERROR',message)
4318        return
4319    end
4320end
4321%create avi open
4322aviobj=avifile(aviname,'Compression','None','fps',fps);
4323
4324%display first view for tests
4325newfig=figure;
4326newaxes=copyobj(handles.PlotAxes,newfig);%new plotting axes in the new figure
4327set(newaxes,'Tag','movieaxes')
4328nbpix=[512 384]*str2double(answer{3});
4329set(gcf,'Position',[1 1 nbpix])% resolution XVGA
4330set(newaxes,'Position',eval(answer{4}));
4331map=colormap(handles.PlotAxes);
4332colormap(map);%transmit the current colormap to the zoom fig
4333msgbox_uvmat('INPUT_Y-N',{['adjust figure ' num2str(newfig) ' with its matlab edit menu '] ;...
4334        ['then press OK to get the avi movie as a copy of figure ' num2str(newfig) ' display']});
4335UvData.plotaxes=newaxes;% the axis in the new figure becomes the current main plotting axes
4336set(huvmat,'UserData',UvData);
4337increment=str2num(get(handles.num_IndexIncrement,'String')); %get the field increment d
4338set(handles.STOP,'Visible','on')
4339set(handles.speed,'Visible','on')
4340set(handles.speed_txt,'Visible','on')
4341set(handles.Movie,'BusyAction','queue')
4342
4343%imin=str2double(get(handles.i1,'String'));
4344imax=str2double(answer{5});
4345% if isfield(UvData,'Time')
4346htitle=get(newaxes,'Title');
4347xlim=get(newaxes,'XLim');
4348ylim=get(newaxes,'YLim');
4349set(htitle,'Position',[xlim(2)+0.07*(xlim(2)-xlim(1)) ylim(2)-0.05*(ylim(2)-ylim(1)) 0])
4350time_str=get(handles.abs_time,'String');
4351set(htitle,'String',['t=' time_str])
4352set(handles.speed,'Value',1)
4353for i=1:imax
4354    if get(handles.speed,'Value')~=0 && isequal(get(handles.MenuExportMovie,'BusyAction'),'queue') % enable STOP command
4355            runpm(hObject,eventdata,handles,increment)% run plus
4356            drawnow
4357            time_str=get(handles.abs_time,'String');
4358            if ishandle(htitle)
4359             set(htitle,'String',['t=' time_str])
4360            end
4361            mov=getframe(newfig);
4362            aviobj=addframe(aviobj,mov);
4363    end
4364end
4365aviobj=close(aviobj);
4366UvData=rmfield(UvData,'plotaxes');
4367%UvData.Object{1}.plotaxes=handles.PlotAxes;
4368set(huvmat,'UserData',UvData);
4369msgbox_uvmat('CONFIRMATION',{['movie ' aviname ' created '];['with ' num2str(imax) ' frames']})
4370
4371
4372%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4373% Projection Objects Menu Callbacks
4374%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4375
4376% -----------------------------------------------------------------------
4377function Menupoints_Callback(hObject, eventdata, handles)
4378%------------------------------------------------------------------------
4379data.Type='points';
4380data.ProjMode='projection';%default
4381data.ProjModeMenu={};% do not restrict ProjMode menus
4382create_object(data,handles)
4383
4384% -----------------------------------------------------------------------
4385function Menuline_Callback(hObject, eventdata, handles)
4386%------------------------------------------------------------------------
4387data.Type='line';
4388data.ProjMode='projection';%default
4389data.ProjModeMenu={};% do not restrict ProjMode menus
4390create_object(data,handles)
4391
4392%------------------------------------------------------------------------
4393function Menupolyline_Callback(hObject, eventdata, handles)
4394%------------------------------------------------------------------------
4395data.Type='polyline';
4396data.ProjMode='projection';%default
4397data.ProjModeMenu={};% do not restrict ProjMode menus
4398create_object(data,handles)
4399
4400%------------------------------------------------------------------------
4401function Menupolygon_Callback(hObject, eventdata, handles)
4402%------------------------------------------------------------------------
4403data.Type='polygon';
4404data.ProjMode='inside';%default
4405data.ProjModeMenu={};% do not restrict ProjMode menus
4406create_object(data,handles)
4407
4408%------------------------------------------------------------------------
4409function Menurectangle_Callback(hObject, eventdata, handles)
4410%------------------------------------------------------------------------
4411data.Type='rectangle';
4412data.ProjMode='inside';%default
4413data.ProjModeMenu={};% do not restrict ProjMode menus
4414create_object(data,handles)
4415
4416%------------------------------------------------------------------------
4417function Menuellipse_Callback(hObject, eventdata, handles)
4418%------------------------------------------------------------------------
4419data.Type='ellipse';
4420data.ProjMode='inside';%default
4421data.ProjModeMenu={};% do not restrict ProjMode menus
4422create_object(data,handles)
4423
4424%------------------------------------------------------------------------
4425function MenuMaskObject_Callback(hObject, eventdata, handles)
4426%------------------------------------------------------------------------
4427data.Type='polygon';
4428data.TypeMenu={'polygon'};
4429data.ProjMode='mask_inside';%default
4430data.ProjModeMenu={'mask_inside';'mask_outside'};
4431create_object(data,handles)
4432
4433%------------------------------------------------------------------------
4434function Menuplane_Callback(hObject, eventdata, handles)
4435%------------------------------------------------------------------------
4436data.Type='plane';
4437data.ProjMode='projection';%default
4438data.ProjModeMenu={};% do not restrict ProjMode menus
4439create_object(data,handles)
4440
4441%------------------------------------------------------------------------
4442function Menuvolume_Callback(hObject, eventdata, handles)
4443%------------------------------------------------------------------------
4444data.Type='volume';
4445data.ProjMode='interp';%default
4446data.ProjModeMenu={};
4447% set(handles.create,'Visible','on')
4448% set(handles.create,'Value',1)
4449% VOLUME_Callback(hObject,eventdata,handles)data.ProjModeMenu={};
4450create_object(data,handles)
4451
4452%------------------------------------------------------------------------
4453% --- generic function used for the creation of a projection object
4454function create_object(data,handles)
4455%------------------------------------------------------------------------
4456% desactivate geometric calibration if opened
4457hgeometry_calib=findobj(allchild(0),'tag','geometry_calib');
4458if ishandle(hgeometry_calib)
4459    hhgeometry_calib=guidata(hgeometry_calib);
4460    set(hhgeometry_calib.edit_append,'Value',0)% desactivate mouse action in geometry_calib
4461    set(hhgeometry_calib.edit_append,'BackgroundColor',[0.7 0.7 0.7])
4462end
4463set(handles.edit_object,'Value',0); %suppress the object edit mode
4464set(handles.edit_object,'BackgroundColor',[0.7,0.7,0.7]) 
4465ListObject=get(handles.ListObject,'String');
4466if isempty(ListObject)
4467    ListObject={''};
4468end
4469if ~strcmp(ListObject{end},'')
4470    ListObject=[ListObject;{''}]; %append a blank to the list (if nort already done) to indicate the creation of a new object
4471    set(handles.ListObject,'String',ListObject)
4472end
4473IndexObj=length(ListObject);
4474set(handles.ListObject,'Value',IndexObj)
4475UvData=get(handles.uvmat,'UserData');
4476UvData.Object{IndexObj}=[]; %create a new empty object
4477UvData.Object{IndexObj}.DisplayHandle.uvmat=handles.PlotAxes; % axes for plot_object
4478UvData.Object{IndexObj}.DisplayHandle.view_field=[]; %no plot handle before plot_field operation
4479data.Name=data.Type;% default name=type
4480data.Coord=[0 0]; %default
4481if isfield(UvData,'Field')
4482    Field=UvData.Field;
4483    if isfield(UvData.Field,'Mesh')&&~isempty(UvData.Field.Mesh)
4484        data.RangeX=[UvData.Field.XMin UvData.Field.XMax];
4485        if strcmp(data.Type,'line')||strcmp(data.Type,'polyline')||strcmp(data.Type,'points')
4486            data.RangeY=UvData.Field.Mesh;
4487        else
4488            data.RangeY=[UvData.Field.YMin UvData.Field.YMax];
4489        end
4490        data.DX=UvData.Field.Mesh;
4491        data.DY=UvData.Field.Mesh;
4492    end
4493    if isfield(Field,'NbDim')&& isequal(Field.NbDim,3)
4494         data.Coord=[0 0 0]; %default
4495    end
4496    if isfield(Field,'CoordUnit')
4497        data.CoordUnit=Field.CoordUnit;
4498    end
4499end
4500if ishandle(handles.UVMAT_title)
4501    delete(handles.UVMAT_title)%delete the initial display of uvmat if no field has been entered
4502end
4503hset_object=set_object(data,handles);% call the set_object interface
4504hhset_object=guidata(hset_object);
4505hchild=get(hset_object,'children');
4506set(hchild,'enable','on')
4507set(handles.uvmat,'UserData',UvData)
4508set(handles.CheckZoom,'Value',0) %desactivate the zoom for object creation by the mouse
4509CheckZoom_Callback(handles.uvmat, [], handles)
4510set(handles.delete_object,'Visible','on')
4511
4512%------------------------------------------------------------------------
4513function MenuBrowseObject_Callback(hObject, eventdata, handles)
4514%------------------------------------------------------------------------
4515%get the object file
4516[FileName, PathName, filterindex] = uigetfile( ...
4517       {'*.xml;*.mat', ' (*.xml,*.mat)';
4518       '*.xml',  '.xml files '; ...
4519        '*.mat',  '.mat matlab files '}, ...
4520        'Pick an xml Object file',get(handles.RootPath,'String'));
4521fileinput=[PathName FileName];%complete file name
4522sizf=size(fileinput);
4523if (~ischar(fileinput)||~isequal(sizf(1),1)),return;end
4524
4525%read the file
4526[data,heading]=xml2struct(fileinput);
4527if ~strcmp(heading,'ProjObject')
4528    msgbox_uvmat('WARNING','The xml file does not have the heading ProjObject for projection objects')
4529end
4530[tild,data.Name]=fileparts(FileName);% object name set as file name
4531ListObject=get(handles.ListObject,'String');
4532if ~strcmp(ListObject{end},'')
4533    ListObject=[ListObject;{''}]; %append a blank to the list (if not already done) to indicate the creation of a new object
4534    set(handles.ListObject,'String',ListObject)
4535end
4536IndexObj=length(ListObject);
4537
4538UvData=get(handles.uvmat,'UserData');
4539UvData.Object{IndexObj}=[]; %create a new empty object
4540UvData.Object{IndexObj}.DisplayHandle.uvmat=[]; %no plot handle before plot_field operation
4541UvData.Object{IndexObj}.DisplayHandle.view_field=[]; %no plot handle before plot_field operation
4542set(handles.uvmat,'UserData',UvData)
4543set(handles.ListObject,'Value',IndexObj)
4544hset_object=set_object(data);% call the set_object interface
4545set(get(hset_object,'children'),'enable','on')% enable edit action on elements on GUI set_object
4546set(handles.edit_object,'Value',0); %suppress the object edit mode
4547set(handles.edit_object,'BackgroundColor',[0.7,0.7,0.7]) 
4548set(handles.delete_object,'Visible','on')
4549
4550
4551%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4552% MenuEdit Callbacks
4553%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4554%------------------------------------------------------------------------
4555function MenuEditObject_Callback(hObject, eventdata, handles)
4556%------------------------------------------------------------------------
4557set(handles.edit_object,'Value',1)
4558edit_Callback(hObject, eventdata, handles)
4559
4560%------------------------------------------------------------------------
4561function MenuEditVectors_Callback(hObject, eventdata, handles)
4562%------------------------------------------------------------------------
4563set(handles.edit_vect,'Visible','on')
4564set(handles.edit_vect,'Value',1)
4565edit_vect_Callback(hObject, eventdata, handles)
4566
4567%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4568% MenuTools Callbacks
4569%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4570%------------------------------------------------------------------------
4571function MenuCalib_Callback(hObject, eventdata, handles)
4572%------------------------------------------------------------------------
4573
4574UvData=get(handles.uvmat,'UserData');%read UvData properties stored on the uvmat interface
4575
4576%suppress competing options
4577set(handles.CheckZoom,'Value',0)
4578set(handles.CheckZoom,'BackgroundColor',[0.7 0.7 0.7])
4579set(handles.ListObject,'Value',1)     
4580% initiate display of GUI geometry_calib
4581data=[]; %default
4582if isfield(UvData,'CoordType')
4583    data.CoordType=UvData.CoordType;
4584end
4585[RootPath,SubDir,RootFile,FileIndex,FileExt]=read_file_boxes(handles);
4586FileName=[fullfile(RootPath,SubDir,RootFile) FileIndex FileExt];
4587set(handles.view_xml,'Backgroundcolor',[1 1 0])%indicate the reading of the current xml file by geometry_calib
4588pos_uvmat=get(handles.uvmat,'Position');
4589pos_cal(1)=pos_uvmat(1)+UvData.OpenParam.PosGeometryCalib(1)*pos_uvmat(3);
4590pos_cal(2)=pos_uvmat(2)+UvData.OpenParam.PosGeometryCalib(2)*pos_uvmat(4);
4591pos_cal(3:4)=UvData.OpenParam.PosGeometryCalib(3:4).* pos_uvmat(3:4);
4592geometry_calib(FileName,pos_cal);% call the geometry_calib interface   
4593set(handles.view_xml,'Backgroundcolor',[1 1 1])%indicate the end of reading of the current xml file by geometry_calib
4594set(handles.MenuCalib,'checked','on')% indicate that MenuCalib is activated, test used by mouse action
4595
4596
4597%-----------------------------------------------------------------------
4598function MenuLIFCalib_Callback(hObject, eventdata, handles)
4599%------------------------------------------------------------------------
4600%% read UvData properties stored on the uvmat interface
4601UvData=get(handles.uvmat,'UserData');
4602if isfield(UvData,'XmlData')&& isfield(UvData.XmlData{1},'GeometryCalib')
4603    XmlData=UvData.XmlData{1};
4604else
4605    msgbox_uvmat('ERROR','geometric calibration needed: use Tools/geometric calibration in the menu bar');
4606    return
4607end
4608
4609%% read lines currently drawn
4610ListObj=UvData.Object;
4611select=zeros(1,numel(ListObj));
4612for iobj=1:numel(ListObj);
4613    if isfield(ListObj{iobj},'Type') && strcmp(ListObj{iobj}.Type,'line')
4614        select(iobj)=1;
4615    end
4616end
4617val=find(select);
4618if numel(val)<2
4619    msgbox_uvmat('ERROR','light rays must be defined by at least two lines created by Projection object/line in the menu bar');
4620    return
4621else
4622    set(handles.ListObject,'Value',val);% show the selected lines on the list
4623    ObjectData=UvData.Object(val);
4624    for iobj=1:length(ObjectData)
4625%         if isfield(ObjectData{iobj},'Coord')
4626            xA(iobj)=ObjectData{iobj}.Coord(1,1);
4627            yA(iobj)=ObjectData{iobj}.Coord(1,2);
4628            xB(iobj)=ObjectData{iobj}.Coord(2,1);
4629            yB(iobj)=ObjectData{iobj}.Coord(2,2);
4630%         end
4631    end
4632end
4633
4634%% find the origin as intersection of the two first lines (see http://www.ahristov.com/tutorial/geometry-games/intersection-lines.html )
4635x1=xA(1);x2=xB(1);
4636x3=xA(2);x4=xB(2);
4637y1=yA(1);y2=yB(1);
4638y3=yA(2);y4=yB(2);
4639D = (x1-x2)*(y3-y4) -(y1-y2)*(x3-x4);
4640if D==0
4641    msgbox_uvmat('ERROR','the two lines are parallel');
4642    return
4643end
4644x0=((x3-x4)*(x1*y2-y1*x2)-(x1-x2)*(x3*y4-y3*x4))/D;
4645y0=((y3-y4)*(x1*y2-y1*x2)-(y1-y2)*(x3*y4-y3*x4))/D;
4646XmlData.Illumination.Origin=[x0 y0];
4647XmlData.PolarCentre=[x0 y0];
4648
4649%% display the current image in polar coordinates with origin at the  illumination source
4650currentdir=pwd; 
4651uvmatpath=fileparts(which('uvmat'));
4652cd(fullfile(uvmatpath,'transform_field'));
4653phys_polar=str2func('phys_polar');
4654cd(currentdir)
4655DataOut=phys_polar(UvData.Field,XmlData);
4656view_field(DataOut);
4657
4658%% use the third line for reference luminosity
4659if numel(val)==3
4660    x_ref=linspace(ObjectData{3}.Coord(1,1),ObjectData{3}.Coord(2,1),10);
4661    y_ref=linspace(ObjectData{3}.Coord(1,2),ObjectData{3}.Coord(2,2),10);
4662    x_ref=x_ref-x0;
4663    y_ref=y_ref-y0;
4664    [theta_ref,r_ref] = cart2pol(x_ref,y_ref);%theta_ref  and r_ref are the polar coordinates of the points on the line
4665    theta_ref=theta_ref*180/pi;
4666    figure
4667    plot(theta_ref,r_ref)
4668    azimuth_ima=linspace(DataOut.AY(1),DataOut.AY(2),size(DataOut.A,1));%profile of x index on the transformed image
4669    dist_source = interp1(theta_ref,r_ref,azimuth_ima);
4670    dist_source_pixel=round(size(DataOut.A,2)*(dist_source-DataOut.AX(1))/(DataOut.AX(2)-DataOut.AX(1)));
4671    line_nan= isnan(dist_source_pixel);
4672    dist_source_pixel(line_nan)=1;
4673    width=20; %number of pixels used for reference
4674    DataOut.A=double(DataOut.A);
4675    Anorm=zeros(size(DataOut.A));
4676    Aval=mean(mean(DataOut.A));
4677    for iline=1:size(DataOut.A,1)
4678        lum(iline)=mean(DataOut.A(iline,dist_source_pixel(iline):dist_source_pixel(iline)+width));
4679        Anorm(iline,:)=uint16(Aval*DataOut.A(iline,:)/lum(iline));
4680    end
4681    lum(line_nan)=NaN;
4682    figure
4683    plot(1:size(DataOut.A,1),lum)
4684end
4685ImaName=regexprep([get(handles.RootFile,'String') get(handles.FileIndex,'String')],'//','');
4686NewImageName=fullfile(get(handles.RootPath,'String'),'polar',[ImaName get(handles.FileExt,'String')]);
4687imwrite(Anorm,NewImageName,'BitDepth',16)
4688
4689%% record the origin in the xml file
4690XmlFileName=find_imadoc(get(handles.RootPath,'String'),get(handles.SubDir,'String'),get(handles.RootFile,'String'),get(handles.FileExt,'String'));
4691answer=msgbox_uvmat('INPUT_Y-N','save the illumination origin in the current xml file?');
4692if strcmp(answer,'Yes')
4693    t=xmltree(XmlFileName); %read the file
4694    title=get(t,1,'name');
4695    if ~strcmp(title,'ImaDoc')
4696        msgbox_uvmat('ERROR','wrong xml file');
4697        return
4698    end
4699    % backup the output file if it already exist, and read it
4700    backupfile=XmlFileName;
4701    testexist=2;
4702    while testexist==2
4703        backupfile=[backupfile '~'];
4704        testexist=exist(backupfile,'file');
4705    end
4706    [success,message]=copyfile(XmlFileName,backupfile);%make backup
4707    if success~=1
4708        errormsg=['errror in xml file backup: ' message];
4709        return
4710    end
4711    uid_illumination=find(t,'ImaDoc/Illumination');
4712    if isempty(uid_illumination)  %if GeometryCalib does not already exists, create it
4713        [t,uid_illumination]=add(t,1,'element','Illumination');
4714    end
4715    uid_origin=find(t,'ImaDoc/Illumination/Origin');
4716    if ~isempty(uid_origin)  %if GeometryCalib does not already exists, create it
4717         t=delete(t,uid_origin);
4718    end
4719    % save the illumination origin
4720    t=struct2xml(XmlData.Illumination,t,uid_illumination);
4721    save(t,XmlFileName);
4722end
4723   
4724
4725
4726%------------------------------------------------------------------------
4727function MenuMask_Callback(hObject, eventdata, handles)
4728%------------------------------------------------------------------------
4729UvData=get(handles.uvmat,'UserData');%read UvData properties stored on the uvmat interface
4730ListObj=UvData.Object;
4731select=zeros(1,numel(ListObj));
4732for iobj=1:numel(ListObj);
4733    if strcmp(ListObj{iobj}.ProjMode,'mask_inside')||strcmp(ListObj{iobj}.ProjMode,'mask_outside')
4734        select(iobj)=1;
4735    end
4736end
4737val=find(select);
4738if isempty(val)
4739    msgbox_uvmat('ERROR','polygons must be first created by Projection object/mask polygon in the menu bar');
4740    return
4741else
4742    set(handles.ListObject,'Value',val);
4743    flag=1;
4744    npx=size(UvData.Field.A,2);
4745    npy=size(UvData.Field.A,1);
4746    xi=0.5:npx-0.5;
4747    yi=0.5:npy-0.5;
4748    [Xi,Yi]=meshgrid(xi,yi);
4749%     if isfield(UvData,'Object')
4750        for iobj=1:length(UvData.Object)
4751            ObjectData=UvData.Object{iobj};
4752            if isfield(ObjectData,'ProjMode') &&(isequal(ObjectData.ProjMode,'mask_inside')||isequal(ObjectData.ProjMode,'mask_outside'));
4753                flagobj=1;
4754                testphys=0; %coordinates in pixels by default
4755                if isfield(ObjectData,'CoordUnit') && ~isequal(ObjectData.CoordUnit,'pixel')
4756                    if isfield(UvData,'XmlData')&& isfield(UvData.XmlData{1},'GeometryCalib')
4757                        Calib=UvData.XmlData{1}.GeometryCalib;
4758                        testphys=1;
4759                    end
4760                end
4761                if isfield(ObjectData,'Coord')&& isfield(ObjectData,'Type')
4762                    if isequal(ObjectData.Type,'polygon')
4763                        X=ObjectData.Coord(:,1);
4764                        Y=ObjectData.Coord(:,2);
4765                        if testphys
4766                            pos=[X Y zeros(size(X))];
4767                            if isfield(Calib,'SliceCoord') && length(Calib.SliceCoord)>=3
4768                                if isfield(Calib,'SliceAngle')&&~isequal(Calib.SliceAngle,[0 0 0])
4769                                    om=norm(Calib.SliceAngle);%norm of rotation angle in radians
4770                                    OmAxis=Calib.SliceAngle/om; %unit vector marking the rotation axis
4771                                    cos_om=cos(pi*om/180);
4772                                    sin_om=sin(pi*om/180);
4773                                    pos=cos_om*pos+sin_om*cross(OmAxis,pos)+(1-cos_om)*(OmAxis*pos')*OmAxis;
4774                                end
4775                                pos(:,1)=pos(:,1)+Calib.SliceCoord(1);
4776                                pos(:,2)=pos(:,2)+Calib.SliceCoord(2);
4777                                pos(:,3)=pos(:,3)+Calib.SliceCoord(3);
4778                            end                           
4779                            [X,Y]=px_XYZ(Calib,pos(:,1),pos(:,2),pos(:,3));
4780                        end
4781                        flagobj=~inpolygon(Xi,Yi,X',Y');%=0 inside the polygon, 1 outside
4782                    elseif isequal(ObjectData.Type,'ellipse')
4783                        if testphys
4784                            %[X,Y]=px_XYZ(Calib,X,Y,0);% TODO:create a polygon boundary and transform to phys
4785                        end
4786                        RangeX=max(ObjectData.RangeX);
4787                        RangeY=max(ObjectData.RangeY);
4788                        X2Max=RangeX*RangeX;
4789                        Y2Max=RangeY*RangeY;
4790                        distX=(Xi-ObjectData.Coord(1,1));
4791                        distY=(Yi-ObjectData.Coord(1,2));
4792                        flagobj=(distX.*distX/X2Max+distY.*distY/Y2Max)>1;
4793                    elseif isequal(ObjectData.Type,'rectangle')
4794                        if testphys
4795                            %[X,Y]=px_XYZ(Calib,X,Y,0);% TODO:create a polygon boundary and transform to phys
4796                        end
4797                        distX=abs(Xi-ObjectData.Coord(1,1));
4798                        distY=abs(Yi-ObjectData.Coord(1,2));
4799                        flagobj=distX>max(ObjectData.RangeX) | distY>max(ObjectData.RangeY);
4800                    end
4801                    if isequal(ObjectData.ProjMode,'mask_outside')
4802                        flagobj=~flagobj;
4803                    end
4804                    flag=flag & flagobj;
4805                end
4806            end
4807        end
4808%     end
4809    %mask name
4810    RootPath=get(handles.RootPath,'String');
4811    SubDir=get(handles.SubDir,'String');
4812    RootFile=get(handles.RootFile,'String');
4813    if ~isempty(RootFile)&&(isequal(RootFile(1),'/')|| isequal(RootFile(1),'\'))
4814        RootFile(1)=[];
4815    end
4816    list=get(handles.masklevel,'String');
4817    masknumber=num2str(length(list));
4818    maskindex=get(handles.masklevel,'Value');
4819   % mask_name=fullfile_uvmat(RootPath,'',[RootFile '_' masknumber 'mask'],'.png','_1',maskindex);
4820    mask_name=fullfile_uvmat(RootPath,[SubDir '.mask'],'mask','.png','_1',maskindex);
4821    imflag=uint8(255*(0.392+0.608*flag));% =100 for flag=0 (vectors not computed when 20<imflag<200)
4822    imflag=flipdim(imflag,1);
4823
4824    %display the mask
4825    hfigmask=figure;
4826    set(hfigmask,'Name','mask image')
4827    vec=linspace(0,1,256);%define a linear greyscale colormap
4828    map=[vec' vec' vec'];
4829    colormap(map)
4830    image(imflag);
4831    answer=msgbox_uvmat('INPUT_TXT','mask file name:', mask_name);
4832    if ~strcmp(answer,'Cancel')
4833        mask_dir=fileparts(answer);
4834        if ~exist(mask_dir,'dir')
4835            [xx,msg1]=mkdir(mask_dir);
4836            if ~strcmp(msg1,'')
4837                errormsg=['cannot create ' mask_dir ': ' msg1];%error message for directory creation
4838                return
4839            end
4840        end
4841        imwrite(imflag,answer,'BitDepth',8);
4842    end
4843    set(handles.ListObject,'Value',1)
4844end
4845
4846%------------------------------------------------------------------------
4847%-- open the GUI set_grid.fig to create grid
4848function MenuGrid_Callback(hObject, eventdata, handles)
4849%------------------------------------------------------------------------
4850%suppress the other options if grid is chosen
4851set(handles.edit_vect,'Value',0)
4852edit_vect_Callback(hObject, eventdata, handles)
4853set(handles.edit_object,'BackgroundColor',[0.7 0.7 0.7])
4854set(handles.ListObject,'Value',1)     
4855
4856%prepare display of the set_grid GUI
4857[RootPath,SubDir,RootFile,FileIndex,FileExt]=read_file_boxes(handles);
4858FileName=[fullfile(RootPath,SubDir,RootFile) FileIndex FileExt];
4859CoordList=get(handles.transform_fct,'String');
4860val=get(handles.transform_fct,'Value');
4861set_grid(FileName,CoordList{val});% call the set_object interface
4862
4863
4864%------------------------------------------------------------------------
4865function MenuRuler_Callback(hObject, eventdata, handles)
4866%------------------------------------------------------------------------
4867set(handles.CheckZoom,'Value',0)
4868CheckZoom_Callback(handles.uvmat, [], handles)
4869set(handles.MenuRuler,'checked','on')
4870UvData=get(handles.uvmat,'UserData');
4871UvData.MouseAction='ruler';
4872set(handles.uvmat,'UserData',UvData);
4873
4874%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4875% MenuRun Callbacks
4876%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4877
4878%------------------------------------------------------------------------
4879% open the GUI 'series'
4880function MenuSeries_Callback(hObject, eventdata, handles)
4881%------------------------------------------------------------------------
4882series; %first display of the GUI to fill waiting time
4883[RootPath,SubDir,RootFile,FileIndex,FileExt]=read_file_boxes(handles);
4884Param.FileName=[fullfile(RootPath,SubDir,RootFile) FileIndex FileExt];%first input file name
4885if isequal(get(handles.SubField,'Value'),1)
4886    [RootPath_1,SubDir_1,RootFile_1,FileIndex_1,FileExt_1]=read_file_boxes_1(handles);
4887    FileName_1=[fullfile(RootPath_1,SubDir_1,RootFile_1) FileIndex_1 FileExt_1];
4888    if ~isequal(FileName_1,Param.FileName)
4889        Param.FileName_1=FileName_1;%second input file name if relevant
4890    end
4891end
4892Param.NomType=get(handles.NomType,'String');
4893Param.NomType_1=get(handles.NomType_1,'String');
4894Param.CheckFixPair=get(handles.CheckFixPair,'Value');
4895UvData=get(handles.uvmat,'UserData');
4896if isfield(UvData,'XmlData')&& isfield(UvData.XmlData{1},'Time')
4897    Param.Time=UvData.XmlData{1}.Time;
4898end
4899if isequal(get(handles.scan_i,'Value'),1)
4900    Param.incr_i=str2num(get(handles.num_IndexIncrement,'String'));
4901elseif isequal(get(handles.scan_j,'Value'),1)
4902    Param.incr_j=str2num(get(handles.num_IndexIncrement,'String'));
4903end
4904
4905%% transfer fields and coordinate names
4906Param.list_fields=get(handles.FieldName,'String');% list menu fields
4907FieldName=Param.list_fields{get(handles.FieldName,'Value')};
4908ind_image=find(strcmp('image',Param.list_fields));
4909if ~isempty(ind_image) && numel(Param.list_fields)>1
4910    Param.list_fields(ind_image)=[]; %suppress  'image' option
4911end
4912Param.index_fields=find(strcmp(FieldName,Param.list_fields));% selected string index
4913Param.list_fields_1=get(handles.FieldName_1,'String');% list menu fields
4914if ischar(Param.list_fields_1),Param.list_fields_1={Param.list_fields_1};end
4915FieldName_1=Param.list_fields_1{get(handles.FieldName_1,'Value')};
4916ind_image=find(strcmp('image',Param.list_fields_1));
4917if ~isempty(ind_image) && numel(Param.list_fields_1)>1
4918    Param.list_fields_1(ind_image)=[]; %suppress  'image' option
4919end
4920Param.index_fields_1=find(strcmp(FieldName_1,Param.list_fields_1));% selected string index
4921Param.transform_str=get(handles.transform_fct,'String');
4922Param.transform_val=get(handles.transform_fct,'Value');
4923Param.Coord_x_str=get(handles.Coord_x,'String');
4924Param.Coord_x_val=get(handles.Coord_x,'Value');
4925Param.Coord_y_str=get(handles.Coord_y,'String');
4926Param.Coord_y_val=get(handles.Coord_y,'Value');
4927series(Param); %run the series interface
4928
4929%------------------------------------------------------------------------
4930% -- open the GUI civ.fig for PIV
4931function MenuPIV_Callback(hObject, eventdata, handles)
4932%------------------------------------------------------------------------
4933 [RootPath,SubDir,RootFile,FileIndex,FileExt]=read_file_boxes(handles);
4934 FileName=[fullfile(RootPath,SubDir,RootFile) FileIndex FileExt];
4935civ(FileName);% interface de civ(not in the uvmat file)
4936
4937% --------------------------------------------------------------------
4938function MenuHelp_Callback(hObject, eventdata, handles)
4939% --------------------------------------------------------------------
4940path_to_uvmat=which ('uvmat');% check the path of uvmat
4941pathelp=fileparts(path_to_uvmat);
4942helpfile=fullfile(pathelp,'uvmat_doc','uvmat_doc.html');
4943if isempty(dir(helpfile)), msgbox_uvmat('ERROR','Please put the help file uvmat_doc.html in the sub-directory /uvmat_doc of the UVMAT package')
4944else
4945    addpath (fullfile(pathelp,'uvmat_doc'))
4946    web(helpfile);
4947end
4948
4949
4950% --------------------------------------------------------------------
4951function MenuSetProject_Callback(hObject, eventdata, handles)
4952RootPath=get(handles.RootPath,'String');
4953ProjectDir = uigetdir(fileparts(fileparts(RootPath)), 'select the project source directory');
4954datatree_browser(ProjectDir)
4955
4956
4957% --------------------------------------------------------------------
4958function MenuBrowseProject_Callback(hObject, eventdata, handles)
4959RootPath=get(handles.RootPath,'String');
4960ProjectDir = uigetdir(fileparts(fileparts(RootPath)), 'select the project directory');
4961datatree_browser(ProjectDir)
4962
4963
4964% --- Executes on selection change in Coord_y.
4965function Coord_y_Callback(hObject, eventdata, handles)
4966
4967% --- Executes on selection change in Coord_x.
4968function Coord_x_Callback(hObject, eventdata, handles)
4969
4970
4971% --- Executes on button press in CheckColorBar.
4972function CheckColorBar_Callback(hObject, eventdata, handles)
4973% hObject    handle to CheckColorBar (see GCBO)
4974% eventdata  reserved - to be defined in a future version of MATLAB
4975% handles    structure with handles and user data (see GUIDATA)
4976
4977% Hint: get(hObject,'Value') returns toggle state of CheckColorBar
4978
Note: See TracBrowser for help on using the repository browser.