source: trunk/src/uvmat.m @ 452

Last change on this file since 452 was 452, checked in by sommeria, 12 years ago

bugs repaired

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