source: trunk/src/uvmat.m @ 595

Last change on this file since 595 was 595, checked in by sommeria, 11 years ago

steps further to use series with cluster. Some bsolete functions removed

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