source: trunk/src/uvmat.m @ 525

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

various bug repairs and cleaning

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