source: trunk/src/uvmat.m @ 648

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

get_field updated, several bugs corrected,open_uvmat suppressd

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