source: trunk/src/uvmat.m @ 498

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

various bug corrections, compatibilty with older PIV data

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