source: trunk/src/uvmat.m @ 415

Last change on this file since 415 was 415, checked in by sommeria, 9 years ago

bugs corrected: problems with Dt in read_civxdata and uvmat.

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