source: trunk/src/uvmat.m @ 579

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

bugs corrected for reading vort div

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