source: trunk/src/series/civ_input.m @ 881

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

various bug fix

File size: 97.1 KB
Line 
1%'civ_input': function associated with the GUI 'civ_input.fig' to set the input parameters for civ_series
2%------------------------------------------------------------------------
3% function ParamOut = civ_input(Param)
4%
5% OUPUT:
6% ParamOut: Matlab structure containing the parameters set by the GUI civ_input
7%
8% INPUT:
9% Param: Matlab structure containing the input parameters set by the GUI
10
11%=======================================================================
12% Copyright 2008-2014, LEGI UMR 5519 / CNRS UJF G-INP, Grenoble, France
13%   http://www.legi.grenoble-inp.fr
14%   Joel.Sommeria - Joel.Sommeria (A) legi.cnrs.fr
15%
16%     This file is part of the toolbox UVMAT.
17%
18%     UVMAT is free software; you can redistribute it and/or modify
19%     it under the terms of the GNU General Public License as published
20%     by the Free Software Foundation; either version 2 of the license,
21%     or (at your option) any later version.
22%
23%     UVMAT is distributed in the hope that it will be useful,
24%     but WITHOUT ANY WARRANTY; without even the implied warranty of
25%     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
26%     GNU General Public License (see LICENSE.txt) for more details.
27%=======================================================================
28
29function varargout = civ_input(varargin)
30
31gui_Singleton = 1;
32gui_State = struct('gui_Name',       mfilename, ...
33    'gui_Singleton',  gui_Singleton, ...
34    'gui_OpeningFcn', @civ_input_OpeningFcn, ...
35    'gui_OutputFcn',  @civ_input_OutputFcn, ...
36    'gui_LayoutFcn',  [] , ...
37    'gui_Callback',   []);
38
39if nargin && ischar(varargin{1}) && ~isempty(regexp(varargin{1},'_Callback$','once'))
40        gui_State.gui_Callback = str2func(varargin{1});
41end
42
43if nargout
44    [varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
45else
46    gui_mainfcn(gui_State, varargin{:});
47end
48
49% End initialization code - DO NOT EDIT
50
51%------------------------------------------------------------------------
52% --- Executes just before civ_input is made visible.
53function civ_input_OpeningFcn(hObject, eventdata, handles, Param)
54%------------------------------------------------------------------------
55% This function has no output args, see OutputFcn.
56
57%% General settings
58handles.output = Param;
59guidata(hObject, handles); % Update handles structure
60set(hObject,'WindowButtonDownFcn',{'mouse_down'}) % allows mouse action with right button (zoom for uicontrol display)
61set(hObject,'WindowKeyPressFcn',{@keyboard_callback,handles})%set keyboard action function
62%set(hObject,'KeyPressFcn',{@KeyPressFcn,handles})%set keyboard action function
63set(handles.ref_i,'KeyPressFcn',{@ref_i_KeyPressFcn,handles})%set keyboard action function
64set(handles.ref_j,'KeyPressFcn',{@ref_i_KeyPressFcn,handles})%set keyboard action function
65%set(hObject,'WindowKeyPressFcn',{'keyboard_callback',handles})%set keyboard action function
66hseries=findobj(allchild(0),'Tag','series');% find the parent GUI 'series'
67hhseries=guidata(hseries); %handles of the elements in 'series'
68SeriesData=get(hseries,'UserData');% info stored in the GUI series
69
70%% set visibility options depending on the calling function (Param.Action.ActionName):
71if strcmp(Param.Action.ActionName,'civ_series')||strcmp(Param.Action.ActionName,'stereo_civ')
72     set(handles.num_MaxDiff,'Visible','on')
73    set(handles.num_MaxVel,'Visible','on')
74    set(handles.title_MaxVel,'Visible','on')
75    set(handles.title_MaxDiff,'Visible','on')
76    set(handles.num_Nx,'Visible','off')
77    set(handles.num_Ny,'Visible','off')
78    set(handles.title_Nx,'Visible','off')
79    set(handles.title_Ny,'Visible','off')
80    set(handles.num_CorrSmooth,'Style','popupmenu')
81    set(handles.num_CorrSmooth,'Value',1)
82    set(handles.num_CorrSmooth,'String',{'1';'2'})
83    set(handles.CheckThreshold,'Visible','on')
84    set(handles.CheckDeformation,'Value',0)% desactivate (work in progress)
85end
86switch Param.Action.ActionName
87    case 'stereo_civ'
88        set(handles.ListCompareMode,'Visible','off')
89        set(handles.PairIndices,'Visible','off')
90    case 'civ_series'
91        set(handles.ListCompareMode,'Visible','on')
92        set(handles.PairIndices,'Visible','on')
93end
94
95%% input file info
96NomTypeInput=Param.InputTable{1,4};
97FileType='image';%fdefault
98FileInfo=[];
99if isfield(SeriesData,'FileType')&&isfield(SeriesData,'FileInfo')
100    FileType=SeriesData.FileType{1};%type of the first input file series
101    FileInfo=SeriesData.FileInfo{1};% info on the first input file series
102else
103    set(hhseries.REFRESH,'BackgroundColor',[1 0 1])% indicate that the file input in series needs to be refreshed
104end
105
106%% case of netcdf file as input, read the processing stage and look for corresponding images
107ind_opening=0;%default
108NomTypeNc='';
109NomTypeImaA=NomTypeInput;
110iview_image=1;%line # for the input images
111switch FileType
112    case {'image','multimage','video','mmreader','netcdf'}
113%         NomTypeImaA=NomTypeInput;
114%         iview_image=1;%line # for the input images
115    case 'civdata'
116        if ~strcmp(Param.Action.ActionName,'civ_series')
117            msgbox_uvmat('ERROR','bad input data file: open an image or a nc file from civ_series')
118            return
119        end
120        NomTypeNc=NomTypeInput;
121        ind_opening=FileInfo.CivStage;
122        if isempty(regexp(NomTypeInput,'[ab|AB|-]', 'once'))
123            set(handles.ListCompareMode,'Value',2) %mode displacement advised if the nomencalture does not involve index pairs
124        else
125            set(handles.ListCompareMode,'Value',1)
126        end
127        [Data,tild,tild,errormsg]=nc2struct(FileInfo.FileName,[]);
128        if ~isempty(errormsg)
129            msgbox_uvmat('ERROR',['error in netcdf input file: ' errormsg])
130            return
131        end
132        [PathCiv1_ImageA,Civ1_ImageA,FileExtA]=fileparts(Data.Civ1_ImageA);%look for the source image A
133        [PathCiv1_ImageB,Civ1_ImageB,FileExtA]=fileparts(Data.Civ1_ImageB);%look for the source image B
134        if isfield(Data,'Civ2_ImageA')
135            [PathCiv2_ImageA,Civ2_ImageA,FileExtA]=fileparts(Data.Civ2_ImageA);
136            [PathCiv2_ImageB,Civ2_ImageB,FileExtA]=fileparts(Data.Civ2_ImageB);
137        end
138        if size(Param.InputTable,1)==1
139            series('display_file_name',hhseries,Data.Civ1_ImageA,'append');%append the image series to the input list
140        end
141        [RootPath,SubDir,RootFile,i1,i2,j1,j2,FileExt,NomTypeImaA]=fileparts_uvmat(Data.Civ1_ImageA);
142        [RootPath,SubDir,RootFile,i1,i2,j1,j2,FileExt,NomTypeImaB]=fileparts_uvmat(Data.Civ1_ImageB);
143        iview_image=2;%line # for the input images
144    case 'civxdata'% case of  civx data,
145        msgbox_uvmat('ERROR','old civX convention, use the GUI civ')
146        return
147    otherwise
148        msgbox_uvmat('ERROR','civ_series needs images, scalar fields in netcdf format, or civ data as input')
149        return
150end
151
152%% reinitialise menus
153set(handles.ListPairMode,'Value',1)
154set(handles.ListPairMode,'String',{''})
155set(handles.ListPairCiv1,'Value',1)
156set(handles.ListPairCiv1,'String',{''})
157set(handles.ListPairCiv2,'Value',1)
158set(handles.ListPairCiv2,'String',{''})
159       
160%% prepare the GUI with input parameters
161%
162set(handles.ref_i,'String',num2str(Param.IndexRange.first_i))
163if isfield(Param.IndexRange,'first_j')
164    set(handles.ref_j,'String',num2str(Param.IndexRange.first_j))
165end
166set(handles.ConfigSource,'String','\default')
167
168%%  set the menus of image pairs and default selection for civ_input   %%%%%%%%%%%%%%%%%%%
169
170%% display the min and max indices for the whole file series
171if isempty(Param.IndexRange.MaxIndex_i)|| isempty(Param.IndexRange.MinIndex_i)
172    msgbox_uvmat('ERROR','REFRESH the input files in the GUI series')
173     return
174end
175MaxIndex_i=Param.IndexRange.MaxIndex_i(iview_image);
176MinIndex_i=Param.IndexRange.MinIndex_i(iview_image);
177MaxIndex_j=1;%default
178MinIndex_j=1;
179if isfield(Param.IndexRange,'MaxIndex_j')&&isfield(Param.IndexRange,'MinIndex_j')...
180        && numel(Param.IndexRange.MaxIndex_j')>=iview_image &&numel(Param.IndexRange.MinIndex_j')>=iview_image
181    MaxIndex_j=Param.IndexRange.MaxIndex_j(iview_image);
182    MinIndex_j=Param.IndexRange.MinIndex_j(iview_image);
183end
184%update the bounds if possible
185if isfield(SeriesData,'i1_series')&&numel(SeriesData.i1_series)>=iview_image
186    if size(SeriesData.i1_series{iview_image},2)==2 && min(min(SeriesData.i1_series{iview_image}(:,1,:)))==0
187        MinIndex_j=1;% index j set to 1 by default
188        MaxIndex_j=1;
189        MinIndex_i=find(SeriesData.i1_series{iview_image}(1,2,:), 1 )-1;% min ref index i detected in the series (corresponding to the first non-zero value of i1_series, except for zero index)
190        MaxIndex_i=find(SeriesData.i1_series{iview_image}(1,2,:),1,'last' )-1;%max ref index i detected in the series (corresponding to the last non-zero value of i1_series)
191    else
192        ref_i=squeeze(max(SeriesData.i1_series{iview_image}(1,:,:),[],2));% select ref_j index for each ref_i
193        ref_j=squeeze(max(SeriesData.j1_series{iview_image}(1,:,:),[],3));% select ref_i index for each ref_j
194        MinIndex_i=min(find(ref_i))-1;
195        MaxIndex_i=max(find(ref_i))-1;
196        MaxIndex_j=max(find(ref_j))-1;
197        MinIndex_j=min(find(ref_j))-1;
198    end
199end
200if ~isfield(Param.IndexRange,'first_j')||isequal(MaxIndex_j,MinIndex_j)% no possibility of j pairs
201    set(handles.ListPairMode,'Value',1)
202    set(handles.ListPairMode,'String',{'series(Di)'})
203elseif  MaxIndex_i==1 && MaxIndex_j>1% simple series in j
204    set(handles.ListPairMode,'String',{'pair j1-j2';'series(Dj)'})
205    if  MaxIndex_j <= 10
206        set(handles.ListPairMode,'Value',1)% advice 'pair j1-j2' except in MaxIndex_j is large
207    end
208else
209    set(handles.ListPairMode,'String',{'pair j1-j2';'series(Dj)';'series(Di)'})%multiple choice
210    if strcmp(NomTypeNc,'_1-2_1')
211        set(handles.ListPairMode,'Value',3)% advise 'series(Di)'
212    elseif  MaxIndex_j <= 10
213        set(handles.ListPairMode,'Value',1)% advice 'pair j1-j2' except in MaxIndex_j is large
214    end
215end
216
217%%  transfer the time from the GUI series, or use file index by default
218time=[];
219TimeUnit='frame'; %default
220CoordUnit='';%default
221pxcm_search=1;
222if isfield(SeriesData,'Time') && ~isempty(SeriesData.Time{1})
223    time=SeriesData.Time{1};
224end
225if isfield(Param.IndexRange,'TimeUnit')&&~isempty(Param.IndexRange.TimeUnit)
226    TimeUnit=Param.IndexRange.TimeUnit;
227end
228% if isfield(SeriesData,'TimeSource')
229%     set(handles.TimeSource,'String',SeriesData.TimeSource)
230% end 
231if isfield(SeriesData,'GeometryCalib')
232    tsai=SeriesData.GeometryCalib;
233    if isfield(tsai,'fx_fy')
234        pxcm_search=max(tsai.fx_fy(1),tsai.fx_fy(2));%pixels:cm estimated for the search range
235    end
236    if isfield(tsai,'CoordUnit')
237        CoordUnit=tsai.CoordUnit;
238    end
239end
240
241%% timing display
242%show the reference image edit box if relevant (not needed for movies or in the absence of time information
243if numel(time)>=2 % if there are at least two time values to define dt
244    if size(time,1)<MaxIndex_i;
245        msgbox_uvmat('WARNING','maximum i index restricted by the timing of the xml file');
246    elseif size(time,2)<MaxIndex_j
247        msgbox_uvmat('WARNING','maximum j index restricted by the timing of the xml file');
248    end
249    MaxIndex_i=min(size(time,1),MaxIndex_i);%possibly adjust the max index according to time data
250    MaxIndex_j=min(size(time,2),MaxIndex_j);
251    set(handles.TimeSource,'String',Param.IndexRange.TimeSource);
252else
253    set(handles.TimeSource,'String',''); %xml file not used for timing
254    TimeUnit='frame';
255    time=ones(MaxIndex_j-MinIndex_j+1,1)*(MinIndex_i:MaxIndex_i);
256    time=time+0.001*(MinIndex_j:MaxIndex_j)'*ones(1,MaxIndex_i-MinIndex_i+1);
257end
258CivInputData.Time=time;
259CivInputData.NomTypeIma=NomTypeImaA;
260set(handles.civ_input,'UserData',CivInputData)
261set(handles.dt_unit,'String',['dt in m' TimeUnit]);%display dt in unit 10-3 of the time (e.g ms)
262set(handles.TimeUnit,'String',TimeUnit);
263%set(handles.CoordUnit,'String',CoordUnit)
264set(handles.SearchRange,'UserData', pxcm_search);
265
266% indicate the min and max indices i and j on the GUI
267set(handles.MinIndex_i,'String',num2str(MinIndex_i))
268set(handles.MaxIndex_i,'String',num2str(MaxIndex_i))
269set(handles.MinIndex_j,'String',num2str(MinIndex_j))
270set(handles.MaxIndex_j,'String',num2str(MaxIndex_j))
271
272
273%% set the civ_input options, depending on the input file content if a nc file has been opened
274ListOptions={'CheckCiv1', 'CheckFix1' 'CheckPatch1', 'CheckCiv2', 'CheckFix2', 'CheckPatch2'};
275checkbox=zeros(size(ListOptions));%default
276checkrefresh=0;
277if ind_opening==0  %case of image opening, start with Civ1
278    for index=1:numel(ListOptions)
279        checkbox(index)=get(handles.(ListOptions{index}),'Value');
280    end
281    index_max=find(checkbox, 1, 'last' );
282    if isempty(index_max),index_max=1;end
283    for index=1:index_max
284        set(handles.(ListOptions{index}),'Value',1)% select all operations starting from CIV1
285    end
286else  %case of netcdf file opening, start with the stage read in the file if the input file is being refreshed
287    if isequal(get(hhseries.REFRESH,'BackgroundColor'),[1 1 0]) &&...
288            ~(isfield(Param,'ActionInput') && isfield(Param.ActionInput,'ConfigSource'))
289            for index = 1:min(ind_opening,5)
290                set(handles.(ListOptions{index}),'value',0)
291                fill_civ_input(Data,handles); %fill civ_input with the parameters retrieved from an input Civ file
292            end
293            set(handles.ConfigSource,'String',FileInfo.FileName);
294            set(handles.(ListOptions{min(ind_opening+1,6)}),'value',1)
295            for index = ind_opening+2:6
296                set(handles.(ListOptions{index}),'value',0)
297            end
298            checkrefresh=1;
299    end
300    if ind_opening>=3
301        set(handles.CheckCiv3,'Visible','on')% make visible the switch 'iterate/repet' for Civ2.
302    else
303        set(handles.CheckCiv3,'Visible','off')
304    end
305end
306
307%% introduce the stored Civ parameters  if available (from previous input or ImportConfig in series)
308if ~checkrefresh && isfield(Param,'ActionInput')&& strcmp(Param.ActionInput.Program,Param.Action.ActionName)% the program fits with the stored data
309    fill_GUI(Param.ActionInput,hObject);%fill the GUI with the parameters retrieved from the input Param
310    hcheckgrid=findobj(handles.civ_input,'Tag','CheckGrid');
311    for ilist=1:numel(hcheckgrid)
312        if get(hcheckgrid(ilist),'Value')% if a grid is used, do not show Dx and Dy for an automatic grid
313            hparent=get(hcheckgrid(ilist),'parent');%handles of the parent panel
314            hchildren=get(hparent,'children');
315            handle_dx=findobj(hchildren,'tag','num_Dx');
316            handle_dy=findobj(hchildren,'tag','num_Dy');
317            handle_title_dx=findobj(hchildren,'tag','title_Dx');
318            handle_title_dy=findobj(hchildren,'tag','title_Dy');
319            set(handle_dx,'Visible','off');
320            set(handle_dy,'Visible','off');
321            set(handle_title_dy,'Visible','off');
322            set(handle_title_dx,'Visible','off');
323        end
324    end
325end
326
327%% set the reference indices from the input file indices
328if ~(isfield(Param,'ActionInput') && isfield(Param.ActionInput,'ConfigSource'))
329update_CivOptions(handles,ind_opening)% fill the menu of possible pairs
330end
331
332%% list the possible index pairs, depending on the option set in ListPairMode
333ListPairMode_Callback([], [], handles)
334%ListPairCiv1_Callback(hObject, eventdata, handles)
335
336%% set the GUI to modal: wait for OK to close
337set(handles.civ_input,'WindowStyle','modal')% Make the GUI modal
338drawnow
339uiwait(handles.civ_input);% wait for OK action to end the function
340
341
342%------------------------------------------------------------------------
343% --- Outputs from this function are returned to the command line.
344function varargout = civ_input_OutputFcn(hObject, eventdata, handles)
345%------------------------------------------------------------------------
346% Get default command line output from handles structure
347varargout{1}=[];% default output when civ_input is canceled (no 'OK')
348if ~isempty(handles)
349    varargout{1} = handles.output;
350    delete(handles.civ_input)
351end
352
353% --- Executes when user attempts to close get_field.
354function civ_input_CloseRequestFcn(hObject, eventdata, handles)
355if isequal(get(handles.get_field, 'waitstatus'), 'waiting')
356    % The GUI is still in UIWAIT, us UIRESUME
357    uiresume(handles.civ_input);
358else
359    % The GUI is no longer waiting, just close it
360    delete(handles.civ_input);
361end
362
363%------------------------------------------------------------------------
364% --- Executes on button press in SetDefaultParam.
365%------------------------------------------------------------------------
366function SetDefaultParam_Callback(hObject, eventdata, handles)
367
368Param.ConfigSource='\default';
369
370%% Civ1 parameters
371%Param.CheckCiv1=1;
372Param.Civ1.CorrBoxSize=[25 25];
373Param.Civ1.SearchBoxSize=[55 55];
374Param.Civ1.SearchBoxShift=[0 0];
375Param.Civ1.CorrSmooth=1;
376Param.Civ1.Dx=20;
377Param.Civ1.Dy=20;
378Param.Civ1.CheckGrid=0;
379Param.Civ1.CheckMask=0;
380Param.Civ1.Mask='';
381Param.Civ1.CheckThreshold=0;
382Param.Civ1.TestCiv1=0;
383
384%% Fix1 parameters
385%Param.CheckFix1=1;
386Param.Fix1.CheckFmin2=1;
387Param.Fix1.CheckF3=1;
388Param.Fix1.MinCorr=0.2000;
389
390%% Patch1 parameters
391%Param.CheckPatch1=1;
392Param.Patch1.FieldSmooth=10;
393Param.Patch1.MaxDiff=1.5000;
394Param.Patch1.SubDomainSize=1000;
395Param.Patch1.TestPatch1=0;
396
397%% Civ2 parameters
398%Param.CheckCiv2=1;
399Param.Civ2.CorrBoxSize=[21 21];
400Param.Civ2.SearchBoxSize=[27 27];
401Param.Civ2.CorrSmooth=1;
402Param.Civ2.Dx=10;
403Param.Civ2.Dy=10;
404Param.Civ2.CheckGrid=0;
405Param.Civ2.CheckMask=0;
406Param.Civ2.Mask='';
407Param.Civ2.CheckThreshold=0;
408Param.Civ2.TestCiv2=0;
409
410%% Fix2 parameters
411%Param.CheckFix2=1;
412Param.Fix2.CheckFmin2=1;
413Param.Fix2.CheckF4=1;
414Param.Fix2.CheckF3=1;
415Param.Fix2.MinCorr=0.2000;
416
417%% Patch2 parameters
418%Param.CheckPatch2=1;
419Param.Patch2.FieldSmooth=2;
420Param.Patch2.MaxDiff=1.5000;
421Param.Patch2.SubDomainSize=1000;
422Param.Patch2.TestPatch2=0;
423
424fill_GUI(Param,handles.civ_input)% fill the elements of the GUI series with the input parameters
425update_CivOptions(handles,0)
426
427% -----------------------------------------------------------------------
428% -----------------------------------------------------------------------
429% --- Open the help html file
430function MenuHelp_Callback(hObject, eventdata, handles)
431% -----------------------------------------------------------------------
432web('http://servforge.legi.grenoble-inp.fr/projects/soft-uvmat/wiki/UvmatHelp#Civ')
433
434%------------------------------------------------------------------------
435% --- Executes on carriage return on the subdir checkciv1 edit window
436function Civ1_ImageB_Callback(hObject, eventdata, handles)
437%------------------------------------------------------------------------
438SubDir=get(handles.Civ1_ImageB,'String');
439menu_str=get(handles.ListSubdirCiv1,'String');% read the list of subdirectories for update
440ichoice=find(strcmp(SubDir,menu_str),1);
441if isempty(ichoice)
442    ilist=numel(menu_str); %select 'new...' in the menu
443else
444    ilist=ichoice;
445end
446set(handles.ListSubdirCiv1,'Value',ilist)% select the selected subdir in the menu
447if get(handles.CheckCiv1,'Value')% if Civ1 is performed
448    set(handles.Civ2_ImageA,'String',SubDir);% set by default civ2 directory the same as civ1
449%     set(handles.ListSubdirCiv2,'Value',ilist)
450else % if Civ1 data already exist
451    errormsg=find_netcpair_civ(handles,1); %update the list of available index pairs in the new directory
452    if ~isempty(errormsg)
453    msgbox_uvmat('ERROR',errormsg)
454    end
455end
456
457%------------------------------------------------------------------------
458% --- Executes on carriage return on the SubDir checkciv1 edit window
459function Civ2_ImageA_Callback(hObject, eventdata, handles)
460%------------------------------------------------------------------------
461SubDir=get(handles.Civ1_ImageB,'String');
462menu_str=get(handles.ListSubdirCiv2,'String');% read the list of subdirectories for update
463ichoice=find(strcmp(SubDir,menu_str),1);
464if isempty(ichoice)
465    ilist=numel(menu_str); %select 'new...' in the menu
466else
467    ilist=ichoice;
468end
469set(handles.ListSubdirCiv2,'Value',ilist)% select the selected subdir in the menu
470%update the list of available pairs from netcdf files in the new directory
471if ~get(handles.CheckCiv2,'Value') && ~get(handles.CheckCiv1,'Value') && ~get(handles.CheckFix1,'Value') && ~get(handles.CheckPatch1,'Value')
472    errormsg=find_netcpair_civ(handles,2);
473        if ~isempty(errormsg)
474    msgbox_uvmat('ERROR',errormsg)
475    end
476end
477
478%------------------------------------------------------------------------
479% --- Executes on button press in CheckCiv1.
480function CheckCiv1_Callback(hObject, eventdata, handles)
481%------------------------------------------------------------------------
482update_CivOptions(handles,0)
483
484%------------------------------------------------------------------------
485% --- Executes on button press in CheckFix1.
486function CheckFix1_Callback(hObject, eventdata, handles)
487%------------------------------------------------------------------------
488update_CivOptions(handles,0)
489
490%------------------------------------------------------------------------
491% --- Executes on button press in CheckPatch1.
492function CheckPatch1_Callback(hObject, eventdata, handles)
493%------------------------------------------------------------------------
494update_CivOptions(handles,0)
495
496%------------------------------------------------------------------------
497% --- Executes on button press in CheckCiv2.
498function CheckCiv2_Callback(hObject, eventdata, handles)
499%------------------------------------------------------------------------
500update_CivOptions(handles,0)
501
502%------------------------------------------------------------------------
503% --- Executes on button press in CheckFix2.
504function CheckFix2_Callback(hObject, eventdata, handles)
505%------------------------------------------------------------------------
506update_CivOptions(handles,0)
507
508%------------------------------------------------------------------------
509% --- Executes on button press in CheckPatch2.
510function CheckPatch2_Callback(hObject, eventdata, handles)
511%------------------------------------------------------------------------
512update_CivOptions(handles,0)
513
514%------------------------------------------------------------------------
515% --- activated by any checkbox controling the selection of Civ1,Fix1,Patch1,Civ2,Fix2,Patch2
516function update_CivOptions(handles,opening)
517%------------------------------------------------------------------------
518if opening>0
519    set(handles.CheckCiv2,'UserData',opening)% store the info on the current status of the civ processing
520end
521checkbox=zeros(1,6);
522checkbox(1)=get(handles.CheckCiv1,'Value');
523checkbox(2)=get(handles.CheckFix1,'Value');
524checkbox(3)=get(handles.CheckPatch1,'Value');
525checkbox(4)=get(handles.CheckCiv2,'Value');
526checkbox(5)=get(handles.CheckFix2,'Value');
527checkbox(6)=get(handles.CheckPatch2,'Value');
528if opening==0
529    errormsg=find_netcpair_civ(handles,1); % select the available netcdf files
530    if ~isempty(errormsg)
531        msgbox_uvmat('ERROR',errormsg)
532    end
533end
534if max(checkbox(4:6))>0% case of civ2 pair choice needed
535    set(handles.TitlePairCiv2,'Visible','on')
536    set(handles.ListPairCiv2,'Visible','on')
537    if ~opening
538        errormsg=find_netcpair_civ(handles,2); % select the available netcdf files
539        if ~isempty(errormsg)
540            msgbox_uvmat('ERROR',errormsg)
541        end
542    end
543else
544    set(handles.ListPairCiv2,'Visible','off')
545end
546hseries=findobj(allchild(0),'Tag','series');% find the parent GUI 'series'
547hhseries=guidata(hseries); %handles of the elements in 'series'
548InputTable=get(hhseries.InputTable,'Data');
549if size(InputTable,1)>=1 && strcmp(InputTable{1,5},'.nc') && max(checkbox(1:3))==0 %&& get(handles.CheckCiv2,'UserData')==6,% no operation asked before Civ2 and input file ready for civ3
550    set(handles.CheckCiv3,'Visible','on')
551else
552    set(handles.CheckCiv3,'Visible','off')
553end
554
555%% set the visibility of the different panels
556options={'Civ1','Fix1','Patch1','Civ2','Fix2','Patch2'};
557for ilist=1:length(options)
558    if checkbox(ilist)
559        set(handles.(options{ilist}),'Visible','on')
560    else
561        set(handles.(options{ilist}),'Visible','off')
562    end
563end
564
565%------------------------------------------------------------------------
566% --- Executes on button press in OK: processing on local computer
567function OK_Callback(hObject, eventdata, handles)
568%------------------------------------------------------------------------
569
570ActionInput=read_GUI(handles.civ_input);% read the infos on the GUI civ_input
571
572%% correct input inconsistencies
573if isfield(ActionInput,'Civ1')
574    checkeven=(mod(ActionInput.Civ1.CorrBoxSize,2)==0);
575    ActionInput.Civ1.CorrBoxSize(checkeven)=ActionInput.Civ1.CorrBoxSize(checkeven)+1;% set correlation box sizes to odd values
576    ActionInput.Civ1.SearchBoxSize=max(ActionInput.Civ1.SearchBoxSize,ActionInput.Civ1.CorrBoxSize+8);% insure that the search box size is large enough
577    checkeven=(mod(ActionInput.Civ1.SearchBoxSize,2)==0);
578    ActionInput.Civ1.SearchBoxSize(checkeven)=ActionInput.Civ1.SearchBoxSize(checkeven)+1;% set search box sizes to odd values
579end
580if isfield(ActionInput,'Civ2')
581    checkeven=(mod(ActionInput.Civ2.CorrBoxSize,2)==0);
582    ActionInput.Civ2.CorrBoxSize(checkeven)=ActionInput.Civ2.CorrBoxSize(checkeven)+1;% set correlation box sizes to odd values
583    ActionInput.Civ2.SearchBoxSize=max(ActionInput.Civ2.SearchBoxSize,ActionInput.Civ2.CorrBoxSize+4);
584    checkeven=(mod(ActionInput.Civ2.SearchBoxSize,2)==0);
585    ActionInput.Civ2.SearchBoxSize(checkeven)=ActionInput.Civ2.SearchBoxSize(checkeven)+1;% set search box sizes to odd values
586end
587
588%% correct mask or grid name for Windows system (replace '\' by '/')
589if isfield(ActionInput,'Civ1')
590    if isfield(ActionInput.Civ1,'Mask')
591        ActionInput.Civ1.Mask=regexprep(ActionInput.Civ1.Mask,'\','/');
592    end
593    if isfield(ActionInput.Civ1,'Grid')
594        ActionInput.Civ1.Grid=regexprep(ActionInput.Civ1.Grid,'\','/');
595    end
596end
597if isfield(ActionInput,'Civ2')
598    if isfield(ActionInput.Civ2,'Mask')
599        ActionInput.Civ2.Mask=regexprep(ActionInput.Civ2.Mask,'\','/');
600    end
601    if isfield(ActionInput.Civ2,'Grid')
602        ActionInput.Civ2.Grid=regexprep(ActionInput.Civ2.Grid,'\','/');
603    end
604end
605
606%% exit the GUI and close it
607handles.output.ActionInput=ActionInput;
608guidata(hObject, handles);% Update handles structure
609uiresume(handles.civ_input);
610
611
612%------------------------------------------------------------------------
613% --- Executes on button press in ListCompareMode.
614function ListCompareMode_Callback(hObject, eventdata, handles)
615%------------------------------------------------------------------------
616ListCompareMode=get(handles.ListCompareMode,'String');
617option=ListCompareMode{get(handles.ListCompareMode,'Value')};
618hseries=findobj(allchild(0),'Tag','series');
619SeriesData=get(hseries,'UserData');
620check_nc=strcmp(SeriesData.FileType{1},'.nc');
621ImageType=SeriesData.FileType(2:end);
622if check_nc
623    ImageType=SeriesData.FileType(2:end);
624else
625    ImageType=SeriesData.FileType;
626end
627hhseries=guidata(hseries);
628InputTable=get(hhseries.InputTable,'Data');
629OriginIndex='off';
630PairIndices='off';
631DoubleInputSeries='off';
632switch option
633    case 'PIV'
634        PairIndices='on';% needs to define index pairs for PIV
635       
636    case 'PIV volume'
637        PairIndices='on';% needs to define index pairs for PIV
638        set(handles.ListPairMode,'Value',1)
639        set(handles.ListPairMode,'String',{'series(Di)'})
640        ListPairMode_Callback(hObject, eventdata, handles)
641    case 'displacement'
642        OriginIndex='on';%define a frame origin for displacement
643%     case 'shift'
644%         if numel(ImageType)==1
645%             fileinput=uigetfile_uvmat('pick a second file series for synchronous shift',InputTable{check_nc+1});
646%             if ~isempty(fileinput)
647%                 series( 'display_file_name',hhseries,fileinput,'append')
648%             end
649%             
650%             
651%         end
652end
653set(handles.num_OriginIndex,'Visible',OriginIndex)
654set(handles.OriginIndex_title,'Visible',OriginIndex)
655set(handles.PairIndices,'Visible',PairIndices)
656ListPairMode_Callback(hObject, eventdata, handles)
657       
658
659
660%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
661% Callbacks in the uipanel Pair Indices
662%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
663%------------------------------------------------------------------------
664% --- Executes on button press in ListPairMode.
665function ListPairMode_Callback(hObject, eventdata, handles)
666%------------------------------------------------------------------------
667compare_list=get(handles.ListCompareMode,'String');
668val=get(handles.ListCompareMode,'Value');
669compare=compare_list{val};
670if strcmp(compare,'displacement')||strcmp(compare,'shift')
671    mode='displacement';
672else
673    mode_list=get(handles.ListPairMode,'String');
674    if ischar(mode_list)
675        mode_list={mode_list};
676    end
677    mode_value=get(handles.ListPairMode,'Value');
678    mode=mode_list{mode_value};
679end
680% displ_num=[];%default
681ref_i=str2double(get(handles.ref_i,'String'));
682% last_i=str2num(get(handles.last_i,'String'));
683CivInputData=get(handles.civ_input,'UserData');
684TimeUnit=get(handles.TimeUnit,'String');
685checkframe=strcmp(TimeUnit,'frame');
686time=CivInputData.Time;
687siztime=size(CivInputData.Time);
688nbfield=siztime(1)-1;
689nbfield2=siztime(2)-1;
690indchosen=1;  %%first pair selected by default
691%displ_num used to define the indices of the civ_input pairs
692% in mode 'pair j1-j2', j1 and j2 are the file indices, else the indices
693% are relative to the reference indices ref_i and ref_j respectively.
694if isequal(mode,'pair j1-j2')
695    dt=1;
696    displ='';
697    index=0;
698    numlist_a=[];
699    numlist_B=[];
700    %get all the time intervals in bursts
701    displ_dt=1;%default
702    nbfield2=min(nbfield2,10);%limitate the number of pairs to 10x10
703    for numod_a=1:nbfield2-1 %nbfield2 always >=2 for 'pair j1-j2' mode
704        for numod_b=(numod_a+1):nbfield2
705            index=index+1;
706            numlist_a(index)=numod_a;
707            numlist_b(index)=numod_b;
708            if size(time,2)>1 && ~checkframe
709                dt(numod_a,numod_b)=CivInputData.Time(ref_i+1,numod_b+1)-CivInputData.Time(ref_i+1,numod_a+1);%first time interval dt
710                displ_dt(index)=dt(numod_a,numod_b);
711            else
712                displ_dt(index)=1;
713            end
714        end
715    end
716    [dtsort,indsort]=sort(displ_dt);
717    if ~isempty(numlist_a)
718        displ_num(1,:)=numlist_a(indsort);
719        displ_num(2,:)=numlist_b(indsort);
720    end
721    displ_num(3,:)=0;
722    displ_num(4,:)=0;
723    enable_j(handles, 'off')
724elseif isequal(mode,'series(Dj)') %| isequal(mode,'st_series(Dj)')
725    index=1:200;
726    displ_num(1,index)=-floor(index/2);
727    displ_num(2,index)=ceil(index/2);
728    displ_num(3:4,index)=zeros(2,200);
729    enable_j(handles, 'on')
730elseif isequal(mode,'series(Di)') %| isequal(mode,'st_series(Di)')
731%     index=1:200;
732%     displ_num(1:2,index)=zeros(2,200);
733%     displ_num(3,index)=-floor(index/2);
734%     displ_num(4,index)=ceil(index/2);
735    enable_i(handles, 'on')
736    if nbfield2 > 1
737        enable_j(handles, 'on')
738    else
739        enable_j(handles, 'off')
740    end
741elseif isequal(mode,'displacement')%the pairs have the same indices
742    displ_num(1,1)=0;
743    displ_num(2,1)=0;
744    displ_num(3,1)=0;
745    displ_num(4,1)=0;
746    if nbfield > 1 || nbfield==0
747        enable_i(handles, 'on')
748    else
749        enable_j(handles, 'off')
750    end
751    if nbfield2 > 1
752        enable_j(handles, 'on')
753    else
754        enable_j(handles, 'off')
755    end
756end
757%set(handles.ListPairCiv1,'UserData',displ_num);
758errormsg=find_netcpair_civ( handles,1);
759    if ~isempty(errormsg)
760    msgbox_uvmat('ERROR',errormsg)
761    end
762% find_netcpair_civ2(handles)
763
764function enable_i(handles, state)
765set(handles.itext,'Visible',state)
766% set(handles.MinIndex_i,'Visible',state)
767% set(handles.last_i,'Visible',state)
768% set(handles.incr_i,'Visible',state)
769set(handles.MaxIndex_i,'Visible',state)
770set(handles.ref_i,'Visible',state)
771
772function enable_j(handles, state)
773set(handles.jtext,'Visible',state)
774% set(handles.MinIndex_j,'Visible',state)
775% set(handles.last_j,'Visible',state)
776% set(handles.incr_j,'Visible',state)
777set(handles.MinIndex_j,'Visible',state)
778set(handles.MaxIndex_j,'Visible',state)
779set(handles.ref_j,'Visible',state)
780%hseries=findobj(allchild(0),'Tag','series');
781%hhseries=guidata(hseries);
782%series('enable_j',hhseries,state); %file input with xml reading  in uvmat, show the image in phys coordinates
783
784
785
786%------------------------------------------------------------------------
787% --- Executes on selection change in ListPairCiv1.
788function ListPairCiv1_Callback(hObject, eventdata, handles)
789%------------------------------------------------------------------------
790%reproduce by default the chosen pair in the checkciv2 menu
791list_pair=get(handles.ListPairCiv1,'String');%get the menu of image pairs
792PairString=list_pair{get(handles.ListPairCiv1,'Value')};
793
794[ind1,ind2]=...
795    find_pair_indices(PairString);
796hseries=findobj(allchild(0),'Tag','series');
797hhseries=guidata(hseries);
798set(hhseries.num_first_j,'String',num2str(ind1));
799set(hhseries.num_last_j,'String',num2str(ind2));
800set(hhseries.num_incr_j,'String',num2str(ind2-ind1));
801set(handles.ListPairCiv2,'Value',get(handles.ListPairCiv1,'Value'))%civ2 selection the same as civ& by default
802
803
804%------------------------------------------------------------------------
805% --- Executes on selection change in ListPairCiv2.
806function ListPairCiv2_Callback(hObject, eventdata, handles)
807%------------------------------------------------------------------------
808
809
810%------------------------------------------------------------------------
811function ref_i_Callback(hObject, eventdata, handles)
812%------------------------------------------------------------------------
813mode_list=get(handles.ListPairMode,'String');
814mode_value=get(handles.ListPairMode,'Value');
815mode=mode_list{mode_value};
816errormsg=find_netcpair_civ(handles,1);% update the menu of pairs depending on the available netcdf files
817if isequal(mode,'series(Di)') || ...% we do patch2 only
818        (get(handles.CheckCiv2,'Value')==0 && get(handles.CheckCiv1,'Value')==0 && get(handles.CheckFix1,'Value')==0 && get(handles.CheckPatch1,'Value')==0)
819    errormsg=find_netcpair_civ( handles,2);
820end
821if isempty(errormsg)
822    set(handles.ref_i,'BackgroundColor',[1 1 1])
823    set(handles.ref_j,'BackgroundColor',[1 1 1])
824else
825    msgbox_uvmat('ERROR',errormsg)
826end
827
828function ref_i_KeyPressFcn(hObject, eventdata, handles)
829set(hObject,'BackgroundColor',[1 0 1])
830       
831% %------------------------------------------------------------------------
832% function ref_j_Callback(hObject, eventdata, handles)
833% %------------------------------------------------------------------------
834% mode_list=get(handles.ListPairMode,'String');
835% mode_value=get(handles.ListPairMode,'Value');
836% mode=mode_list{mode_value};
837% errormsg='';
838% if isequal(get(handles.CheckCiv1,'Value'),0)|| isequal(mode,'series(Dj)')
839%     errormsg=find_netcpair_civ(handles,1);% update the menu of pairs depending on the available netcdf files
840% end
841% if isequal(mode,'series(Dj)') || ...
842%         (get(handles.CheckCiv2,'Value')==0 && get(handles.CheckCiv1,'Value')==0 && get(handles.CheckFix1,'Value')==0 && get(handles.CheckPatch1,'Value')==0)
843%     errormsg=find_netcpair_civ(handles,2);
844% end
845% if ~isempty(errormsg)
846%     msgbox_uvmat('ERROR',errormsg)
847% end
848%
849% function ref_j_KeyPressFcn(hObject, eventdata, handles)
850% set(handles.ref_j,'BackgroundColor',[1 0 1])
851%------------------------------------------------------------------------
852% determine the menu for checkciv1 pairs depending on existing netcdf file at the middle of
853% the field series set by MinIndex_i, incr, last_i
854% index=1: look for pairs for civ1
855% index=2: look for pairs for civ2
856function errormsg=find_netcpair_civ(handles,index)
857%------------------------------------------------------------------------
858set(gcf,'Pointer','watch')% set the mouse pointer to 'watch' (clock)
859
860%% initialisation
861errormsg='';
862CivInputData=get(handles.civ_input,'UserData');
863%browse=get(handles.RootPath,'UserData');
864compare_list=get(handles.ListCompareMode,'String');
865val=get(handles.ListCompareMode,'Value');
866compare=compare_list{val};
867if ~strcmp(compare,'displacement')%||strcmp(compare,'shift')
868 
869    mode_list=get(handles.ListPairMode,'String');
870    mode_value=get(handles.ListPairMode,'Value');
871    if isempty(mode_list)
872        return
873    end
874    mode=mode_list{mode_value};
875end
876nom_type_ima=CivInputData.NomTypeIma;
877menu_pair=get(handles.ListPairCiv1,'String');%previous menu of ListPairCiv1
878PairCiv1Init=menu_pair{get(handles.ListPairCiv1,'Value')};%previous choice of pair
879menu_pair=get(handles.ListPairCiv2,'String');%previous menu of ListPairCiv1
880PairCiv2Init=menu_pair{get(handles.ListPairCiv2,'Value')};%previous choice of pair
881
882%% determine nom_type_nc, nomenclature type of the .nc files:
883%[nom_type_nc]=nomtype2pair(nom_type_ima,mode);
884
885%% reads .nc subdirectoy and image numbers from the interface
886%SubDirImages=get(handles.Civ1_ImageA,'String');
887%TODO: determine
888%subdir_civ1=[SubDirImages get(handles.Civ1_ImageB,'String')];%subdirectory subdir_civ1 for the netcdf data
889%subdir_civ2=[SubDirImages get(handles.Civ2_ImageA,'String')];%subdirectory subdir_civ2 for the netcdf data
890ref_i=str2double(get(handles.ref_i,'String'));
891ref_j=[];
892if isequal(mode,'pair j1-j2')%|isequal(mode,'st_pair j1-j2')
893    ref_j=0;
894elseif strcmp(get(handles.ref_j,'Visible'),'on')
895    ref_j=str2double(get(handles.ref_j,'String'));
896end
897if isempty(ref_j)
898    ref_j=1;
899end
900CivInputData=get(handles.civ_input,'UserData');
901TimeUnit=get(handles.TimeUnit,'String');
902Time=CivInputData.Time;
903checkframe=strcmp(TimeUnit,'frame');
904
905%% case with no Civ1 operation, netcdf files need to exist for reading
906displ_pair={''};
907nbpair=200;%default
908select=ones(size(1:nbpair));%flag for displayed pairs =1 for display
909nbpair=200; %default
910
911%% determine the menu display in .ListPairCiv1
912switch mode
913    case 'series(Di)'
914        for ipair=1:nbpair
915            if select(ipair)
916                displ_pair{ipair}=['Di= ' num2str(-floor(ipair/2)) '|' num2str(ceil(ipair/2))];
917                if ~checkframe
918                    if size(Time,1)>=ref_i+1+ceil(ipair/2) && size(Time,2)>=ref_j+1&& ref_i-floor(ipair/2)>=0 && ref_j>=0
919                        dt=Time(ref_i+1+ceil(ipair/2),ref_j+1)-Time(ref_i+1-floor(ipair/2),ref_j+1);%Time interval dtref_j+1
920                        displ_pair{ipair}=[displ_pair{ipair} ' :dt= ' num2str(dt*1000)];
921                    end
922                else
923                    dt=ipair/1000;
924                    displ_pair{ipair}=[displ_pair{ipair} ' :dt= ' num2str(ipair)];
925                end
926            else
927                displ_pair{ipair}='...'; %pair not displayed in the menu
928            end
929        end
930    case 'series(Dj)'
931        for ipair=1:nbpair
932            if select(ipair)
933                displ_pair{ipair}=['Dj= ' num2str(-floor(ipair/2)) '|' num2str(ceil(ipair/2))];
934                if ~checkframe
935                    if size(Time,2)>=ref_j+1+ceil(ipair/2) && size(Time,1)>=ref_i+1 && ref_j-floor(ipair/2)>=0 && ref_i>=0
936                        dt=Time(ref_i+1,ref_j+1+ceil(ipair/2))-Time(ref_i+1,ref_j+1-floor(ipair/2));%Time interval dtref_j+1
937                        displ_pair{ipair}=[displ_pair{ipair} ' :dt= ' num2str(dt*1000)];
938                    end
939                else
940                    dt=ipair/1000;
941                    displ_pair{ipair}=[displ_pair{ipair} ' :dt= ' num2str(dt*1000)];
942                end
943            else
944                displ_pair{ipair}='...'; %pair not displayed in the menu
945            end
946        end
947    case 'pair j1-j2'%case of pairs
948%         MinIndex_j=CivInputData.MinIndex_j;
949%         MaxIndex_j=min(CivInputData.MaxIndex_j,10);%limitate the number of pairs to 10x10
950        MinIndex_j=str2num(get(handles.MinIndex_j,'String'));
951        MaxIndex_j=str2num(get(handles.MaxIndex_j,'String'));
952        index_pair=0;
953        %get all the Time intervals in bursts
954        for numod_a=MinIndex_j:MaxIndex_j-1 %nbfield2 always >=2 for 'pair j1-j2' mode
955            for numod_b=(numod_a+1):MaxIndex_j
956                index_pair=index_pair+1;
957                displ_pair{index_pair}=['j= ' num2stra(numod_a,nom_type_ima) '-' num2stra(numod_b,nom_type_ima)];
958                dt(index_pair)=numod_b-numod_a;%default dt
959                if size(Time,1)>ref_i && size(Time,2)>numod_b  % && ~checkframe
960                    dt(index_pair)=Time(ref_i+1,numod_b+1)-Time(ref_i+1,numod_a+1);% Time interval dt
961                    displ_pair{index_pair}=[displ_pair{index_pair} ' :dt= ' num2str(dt(index_pair)*1000)];
962                end
963            end
964           
965        end
966        [tild,indsort]=sort(dt);
967        displ_pair=displ_pair(indsort);
968    case 'displacement'
969        displ_pair={'Di=Dj=0'};
970end
971if index==1
972    set(handles.ListPairCiv1,'String',displ_pair');
973end
974
975%% determine the default selection in the pair menu for Civ1
976%ichoice=find(select,1);% index of first selected pair
977%if (isempty(ichoice) || ichoice < 1); ichoice=1; end;
978ichoice=find(strcmp(PairCiv1Init,displ_pair'),1);
979if ~isempty(ichoice)
980    set(handles.ListPairCiv1,'Value',ichoice);% first valid pair proposed by default in the menu
981else
982   set(handles.ListPairCiv1,'Value',1)
983end
984% if initial>nbpair || (numel(select)>=initial && ~isequal(select(initial),1))
985%     set(handles.ListPairCiv1,'Value',ichoice);% first valid pair proposed by default in the menu
986% end
987
988%% determine the default selection in the pair menu for Civ2
989if strcmp(get(handles.ListPairCiv2,'Visible'),'on')
990    ichoice=find(strcmp(PairCiv2Init,displ_pair'),1);
991    if ~isempty(ichoice)
992        set(handles.ListPairCiv2,'Value',ichoice);% first valid pair proposed by default in the menu
993    else
994        set(handles.ListPairCiv2,'Value',1)
995    end
996   
997    %
998    %     initial=get(handles.ListPairCiv2,'Value');
999    %
1000    %
1001    %     if initial>length(displ_pair')%|~isequal(select(initial),1)
1002    %         if ichoice <= length(displ_pair')
1003    %             set(handles.ListPairCiv2,'Value',ichoice);% same pair proposed by default for civ2
1004    %         else
1005    %             set(handles.ListPairCiv2,'Value',1);% same pair proposed by default for civ2
1006    %         end
1007    %     end
1008else
1009    set(handles.ListPairCiv2,'Value',get(handles.ListPairCiv1,'Value'))% initiate the choice of Civ2 as a reproduction of if civ1
1010end
1011set(handles.ListPairCiv2,'String',displ_pair');
1012set(gcf,'Pointer','arrow')% Indicate that the process is finished
1013
1014
1015   
1016% %------------------------------------------------------------------------   
1017% % call 'view_field.fig' to display the  field selected in the list of 'status'
1018% function open_view_field(hObject, eventdata)
1019% %------------------------------------------------------------------------
1020% list=get(hObject,'String');
1021% index=get(hObject,'Value');
1022% rootroot=get(hObject,'UserData');
1023% filename=list{index};
1024% ind_dot=strfind(filename,'...');
1025% filename=filename(1:ind_dot-1);
1026% filename=fullfile(rootroot,filename);
1027% delete(get(hObject,'parent'))%delete the display figure to stop the check process
1028% if exist(filename,'file')%visualise the vel field if it exists
1029%     uvmat(filename)
1030%     set(gcbo,'Value',1)
1031% end
1032
1033
1034%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1035% Callbacks in the uipanel Reference Indices
1036%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1037%------------------------------------------------------------------------
1038function MinIndex_i_Callback(hObject, eventdata, handles)
1039%------------------------------------------------------------------------
1040first_i=str2double(get(handles.MinIndex_i,'String'));
1041set(handles.ref_i,'String', num2str(first_i))% reference index for pair dt = first index
1042ref_i_Callback(hObject, eventdata, handles)%refresh dispaly of dt for pairs (in case of non constant dt)
1043
1044% %------------------------------------------------------------------------
1045% function MinIndex_j_Callback(hObject, eventdata, handles)
1046% %------------------------------------------------------------------------
1047% first_j=str2num(get(handles.MinIndex_j,'String'));
1048% set(handles.ref_j,'String', num2str(first_j))% reference index for pair dt = first index
1049% ref_j_Callback(hObject, eventdata, handles)%refresh dispaly of dt for pairs (in case of non constant dt)
1050
1051%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1052% Callbacks in the uipanel Civ1
1053%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1054%------------------------------------------------------------------------
1055% --- Executes on button press in SearchRange: determine the search range num_SearchBoxSize_1,num_SearchBoxSize_2
1056function SearchRange_Callback(hObject, eventdata, handles)
1057%------------------------------------------------------------------------
1058%determine pair numbers
1059if strcmp(get(handles.num_UMin,'Visible'),'off')
1060    set(handles.u_title,'Visible','on')
1061    set(handles.v_title,'Visible','on')
1062    set(handles.num_UMin,'Visible','on')
1063    set(handles.num_UMax,'Visible','on')
1064    set(handles.num_VMin,'Visible','on')
1065    set(handles.num_VMax,'Visible','on')
1066    %set(handles.CoordUnit,'Visible','on')
1067    %set(handles.TimeUnit,'Visible','on')
1068    %set(handles.slash_title,'Visible','on')
1069    set(handles.min_title,'Visible','on')
1070    set(handles.max_title,'Visible','on')
1071    set(handles.unit_title,'Visible','on')
1072else
1073    get_search_range(hObject, eventdata, handles)
1074end
1075
1076%------------------------------------------------------------------------
1077% ---  determine the search range num_SearchBoxSize_1,num_SearchBoxSize_2 and shift
1078function get_search_range(hObject, eventdata, handles)
1079%------------------------------------------------------------------------
1080param_civ1=read_GUI(handles.Civ1);
1081umin=param_civ1.UMin;
1082umax=param_civ1.UMax;
1083vmin=param_civ1.VMin;
1084vmax=param_civ1.VMax;
1085%switch min_title and max_title in case of error
1086if umax<=umin
1087    umin_old=umin;
1088    umin=umax;
1089    umax=umin_old;
1090    set(handles.num_UMin,'String', num2str(umin))
1091    set(handles.num_UMax,'String', num2str(umax))
1092end
1093if vmax<=vmin
1094    vmin_old=vmin;
1095    vmin=vmax;
1096    vmax=vmin_old;
1097    set(handles.num_VMin,'String', num2str(vmin))
1098    set(handles.num_VMax,'String', num2str(vmax))
1099end   
1100if ~(isempty(umin)||isempty(umax)||isempty(vmin)||isempty(vmax))
1101%     list_pair=get(handles.ListPairCiv1,'String');%get the menu of image pairs
1102%     index=get(handles.ListPairCiv1,'Value');
1103%     pair_string=list_pair{index};
1104%     time=get(handles.TimeSource,'UserData'); %get the set of times
1105%     pxcm=get(handles.SearchRange,'UserData');
1106%     mode_list=get(handles.ListPairMode,'String');
1107%     mode_value=get(handles.ListPairMode,'Value');
1108%     mode=mode_list{mode_value};     
1109%     if isequal (mode, 'series(Di)' )
1110%         ref_i=str2double(get(handles.ref_i,'String'));
1111%         num1=ref_i-floor(index/2);%  first image numbers
1112%         num2=ref_i+ceil(index/2);
1113%         num_a=1;
1114%         num_b=1;
1115%     elseif isequal (mode, 'series(Dj)')
1116%         num1=1;
1117%         num2=1;
1118%         ref_j=str2double(get(handles.ref_j,'String'));
1119%         num_a=ref_j-floor(index/2);%  first image numbers
1120%         num_b=ref_j+ceil(index/2);
1121%     elseif isequal(mode,'pair j1-j2') %case of bursts (png_old or png_2D)     
1122%         ref_i=str2double(get(handles.ref_i,'String'));
1123%         num1=ref_i;
1124%         num2=ref_i;
1125%                 r=regexp(pair_string,'(?<mode>(Di=)|(Dj=)) -*(?<num1>\d+)\|(?<num2>\d+)','names');
1126%         if isempty(r)
1127%             r=regexp(pair_string,'(?<num1>\d+)(?<mode>-)(?<num2>\d+)','names');
1128%         end 
1129%         num_a=str2num(r.num1);
1130%         num_b=str2num(r.num2);
1131%     end
1132%     dt=time(num2+1,num_b+1)-time(num1+1,num_a+1);
1133%     ibx=str2double(get(handles.num_CorrBoxSize_1,'String'));
1134%     iby=str2double(get(handles.num_CorrBoxSize_2,'String'));
1135%     umin=dt*pxcm*umin;
1136%     umax=dt*pxcm*umax;
1137%     vmin=dt*pxcm*vmin;
1138%     vmax=dt*pxcm*vmax;
1139    shiftx=round((umin+umax)/2);
1140    shifty=round((vmin+vmax)/2);
1141    isx=(umax+2-shiftx)*2+param_civ1.CorrBoxSize(1);
1142    isx=2*ceil(isx/2)+1;
1143    isy=(vmax+2-shifty)*2+param_civ1.CorrBoxSize(2);
1144    isy=2*ceil(isy/2)+1;
1145    set(handles.num_SearchBoxShift_1,'String',num2str(shiftx));
1146    set(handles.num_SearchBoxShift_2,'String',num2str(shifty));
1147    set(handles.num_SearchBoxSize_1,'String',num2str(isx));
1148    set(handles.num_SearchBoxSize_2,'String',num2str(isy));
1149end
1150
1151%------------------------------------------------------------------------
1152% --- Executes on selection in menu CorrSmooth.
1153function num_CorrSmooth_Callback(hObject, eventdata, handles)
1154set(handles.ConfigSource,'String','NEW')
1155set(handles.OK,'BackgroundColor',[1 0 1])
1156%------------------------------------------------------------------------
1157
1158% --- Executes on button press in CheckDeformation.
1159function CheckDeformation_Callback(hObject, eventdata, handles)
1160set(handles.ConfigSource,'String','NEW')
1161set(handles.OK,'BackgroundColor',[1 0 1])
1162
1163%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1164% Callbacks in the uipanel Fix1
1165%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1166%------------------------------------------------------------------------
1167% % --- Executes on button press in CheckMask.
1168% function get_mask_fix1_Callback(hObject, eventdata, handles)
1169% %------------------------------------------------------------------------
1170% maskval=get(handles.CheckMask,'Value');
1171% if isequal(maskval,0)
1172%     set(handles.Mask,'String','')
1173% else
1174%     mask_displ='no mask'; %default
1175%     filebase=get(handles.RootPath,'String');
1176%     [nbslice, flag_mask]=get_mask(filebase,handles);
1177%     if isequal(flag_mask,1)
1178%         mask_displ=[num2str(nbslice) 'mask'];
1179%     elseif get(handles.ListCompareMode,'Value')>1 & ~isequal(mask_displ,'no mask')% look for the second mask series
1180%         filebase_a=get(handles.RootFile_1,'String');
1181%         [nbslice_a, flag_mask_a]=get_mask(filebase_a,handles);
1182%         if isequal(flag_mask_a,0) || ~isequal(nbslice_a,nbslice)
1183%             mask_displ='no mask';
1184%         end
1185%     end
1186%     if isequal(mask_displ,'no mask')
1187%         [FileName, PathName, filterindex] = uigetfile( ...
1188%             {'*.png', ' (*.png)';
1189%             '*.png',  '.png files '; ...
1190%             '*.*', 'All Files (*.*)'}, ...
1191%             'Pick a mask file *.png',filebase);
1192%         mask_displ=fullfile(PathName,FileName);
1193%         if ~exist(mask_displ,'file')
1194%             mask_displ='no mask';
1195%         end
1196%     end
1197%     if isequal(mask_displ,'no mask')
1198%         set(handles.CheckMask,'Value',0)
1199%         set(handles.CheckMask,'Value',0)
1200%         set(handles.CheckMask,'Value',0)
1201%     else
1202%         %set(handles.CheckMask,'Value',1)
1203%         set(handles.CheckMask,'Value',1)
1204%     end
1205%     set(handles.Mask,'String',mask_displ)
1206%     set(handles.Mask,'String',mask_displ)
1207%     set(handles.Mask,'String',mask_displ)
1208% end
1209
1210%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1211% Callbacks in the uipanel Civ2
1212%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1213%------------------------------------------------------------------------
1214% --- Executes on button press in CheckMask: select box for mask option
1215function get_mask_civ2_Callback(hObject, eventdata, handles)
1216%------------------------------------------------------------------------
1217maskval=get(handles.CheckMask,'Value');
1218if isequal(maskval,0)
1219    set(handles.Mask,'String','')
1220else
1221    mask_displ='no mask'; %default
1222    filebase=get(handles.RootPath,'String');
1223    [nbslice, flag_mask]=get_mask(filebase,handles);
1224    if isequal(flag_mask,1)
1225        mask_displ=[num2str(nbslice) 'mask'];
1226    elseif get(handles.ListCompareMode,'Value')>1 & ~isequal(mask_displ,'no mask')% look for the second mask series
1227        filebase_a=get(handles.RootFile_1,'String');
1228        [nbslice_a, flag_mask_a]=get_mask(filebase_a,handles);
1229        if isequal(flag_mask_a,0) || ~isequal(nbslice_a,nbslice)
1230            mask_displ='no mask';
1231        end
1232    end
1233    if isequal(mask_displ,'no mask')
1234        [FileName, PathName, filterindex] = uigetfile( ...
1235            {'*.png', ' (*.png)';
1236            '*.png',  '.png files '; ...
1237            '*.*', 'All Files (*.*)'}, ...
1238            'Pick a mask file *.png',filebase);
1239        mask_displ=fullfile(PathName,FileName);
1240        if ~exist(mask_displ,'file')
1241            mask_displ='no mask';
1242        end
1243    end
1244    if isequal(mask_displ,'no mask')
1245        set(handles.CheckMask,'Value',0)
1246        set(handles.CheckMask,'Value',0)
1247    else
1248        set(handles.CheckMask,'Value',1)
1249    end
1250    set(handles.Mask,'String',mask_displ)
1251end
1252
1253% %------------------------------------------------------------------------
1254% % --- Executes on button press in CheckMask.
1255% function get_mask_fix2_Callback(hObject, eventdata, handles)
1256% %------------------------------------------------------------------------
1257% maskval=get(handles.CheckMask,'Value');
1258% if isequal(maskval,0)
1259%     set(handles.Mask,'String','')
1260% else
1261%     mask_displ='no mask'; %default
1262%     filebase=get(handles.RootPath,'String');
1263%     [nbslice, flag_mask]=get_mask(filebase,handles);
1264%     if isequal(flag_mask,1)
1265%         mask_displ=[num2str(nbslice) 'mask'];
1266%     elseif get(handles.ListCompareMode,'Value')>1 & ~isequal(mask_displ,'no mask')% look for the second mask series
1267%         filebase_a=get(handles.RootFile_1,'String');
1268%         [nbslice_a, flag_mask_a]=get_mask(filebase_a,handles);
1269%         if isequal(flag_mask_a,0) || ~isequal(nbslice_a,nbslice)
1270%             mask_displ='no mask';
1271%         end
1272%     end
1273%     if isequal(mask_displ,'no mask')
1274%         [FileName, PathName, filterindex] = uigetfile( ...
1275%             {'*.png', ' (*.png)';
1276%             '*.png',  '.png files '; ...
1277%             '*.*', 'All Files (*.*)'}, ...
1278%             'Pick a mask file *.png',filebase);
1279%         mask_displ=fullfile(PathName,FileName);
1280%         if ~exist(mask_displ,'file')
1281%             mask_displ='no mask';
1282%         end
1283%     end
1284%     if isequal(mask_displ,'no mask')
1285%         set(handles.CheckMask,'Value',0)
1286%     end
1287%     set(handles.Mask,'String',mask_displ)
1288% end
1289
1290%------------------------------------------------------------------------
1291% --- function called to look for mask files
1292function [nbslice, flag_mask]=get_mask(filebase,handles)
1293%------------------------------------------------------------------------
1294%detect mask files, images with appropriate file base
1295%[filebase '_' xx 'mask'], xx=nbslice
1296%flag_mask=1 indicates detection
1297
1298flag_mask=0;%default
1299nbslice=1;
1300
1301% subdir=get(handles.Civ1_ImageB,'String');
1302[Path,Name]=fileparts(filebase);
1303if ~isdir(Path)
1304    msgbox_uvmat('ERROR','no path for input files')
1305    return
1306end
1307% currentdir=pwd;
1308% cd(Path);%move in the dir of the root name filebase
1309maskfiles=dir(fullfile(Path,[Name '_*mask_*.png']));%look for mask files
1310% cd(currentdir);%come back to the current working directory
1311if ~isempty(maskfiles)
1312    %     msgbox_uvmat('ERROR','no mask available, to create it use Tools/Make mask in the upper menu bar of uvmat')
1313    % else
1314    flag_mask=1;
1315    maskname=maskfiles(1).name;% take the first mask file in the list
1316    [Path2,Name,ext]=fileparts(maskname);
1317    Namedouble=double(Name);
1318    val=(48>Namedouble)|(Namedouble>57);% select the non-numerical characters
1319    ind_mask=findstr('mask',Name);
1320    i=ind_mask-1;
1321    while val(i)==0 && i>0
1322        i=i-1;
1323    end
1324    nbslice=str2double(Name(i+1:ind_mask-1));
1325    if ~isnan(nbslice) && Name(i)=='_'
1326        flag_mask=1;
1327    else
1328        msgbox_uvmat('ERROR',['bad mask file ' Name ext ' found in ' Path2])
1329        return
1330        nbslice=1;
1331    end
1332end
1333
1334%------------------------------------------------------------------------
1335% --- function called to look for grid files
1336function [nbslice, flag_grid]=get_grid(filebase,handles)
1337%------------------------------------------------------------------------
1338flag_grid=0;%default
1339nbslice=1;
1340[Path,Name]=fileparts(filebase);
1341currentdir=pwd;
1342cd(Path);%move in the dir of the root name filebase
1343gridfiles=dir([Name '_*grid_*.grid']);%look for grid files
1344cd(currentdir);%come back to the current working directory
1345if ~isempty(gridfiles)
1346    flag_grid=1;
1347    gridname=gridfiles(1).name;% take the first grid file in the list
1348    [Path2,Name,ext]=fileparts(gridname);
1349    Namedouble=double(Name);
1350    val=(48>Namedouble)|(Namedouble>57);% select the non-numerical characters
1351    ind_grid=findstr('grid',Name);
1352    i=ind_grid-1;
1353    while val(i)==0 && i>0
1354        i=i-1;
1355    end
1356    nbslice=str2double(Name(i+1:ind_grid-1));
1357    if ~isnan(nbslice) && Name(i)=='_'
1358        flag_grid=1;
1359    else
1360        msgbox_uvmat('ERROR',['bad grid file ' Name ext ' found in ' Path2])
1361        return
1362        nbslice=1;
1363    end
1364end
1365
1366%------------------------------------------------------------------------
1367% --- transform numbers to letters
1368function str=num2stra(num,nom_type)
1369%------------------------------------------------------------------------
1370if isempty(nom_type)
1371    str='';
1372elseif strcmp(nom_type(end),'a')
1373    str=char(96+num);
1374elseif strcmp(nom_type(end),'A')
1375    str=char(96+num);
1376elseif isempty(nom_type(2:end))%a single index
1377    str='';
1378else
1379    str=num2str(num);
1380end
1381
1382% %------------------------------------------------------------------------
1383% % --- Executes on button press in ListSubdirCiv1.
1384% function ListSubdirCiv1_Callback(hObject, eventdata, handles)
1385% %------------------------------------------------------------------------
1386% list_subdir_civ1=get(handles.ListSubdirCiv1,'String');
1387% val=get(handles.ListSubdirCiv1,'Value');
1388% SubDir=list_subdir_civ1{val};
1389% if strcmp(SubDir,'new...')
1390%     if get(handles.CheckCiv1,'Value')
1391%         SubDir='CIV_INPUT'; %default subdirectory
1392%     else
1393%         msgbox_uvmat('ERROR','select CheckCiv1 to perform a new civ_input operation')
1394%         return
1395%     end   
1396% end
1397% set(handles.Civ1_ImageB,'String',SubDir);
1398% errormsg=find_netcpair_civ(handles,1);
1399% if ~isempty(errormsg)
1400%     msgbox_uvmat('ERROR',errormsg)
1401% end
1402%     
1403%------------------------------------------------------------------------
1404% % --- Executes on button press in ListSubdirCiv2.
1405% function ListSubdirCiv2_Callback(hObject, eventdata, handles)
1406% %------------------------------------------------------------------------
1407% list_subdir_civ2=get(handles.ListSubdirCiv2,'String');
1408% val=get(handles.ListSubdirCiv2,'Value');
1409% SubDir=list_subdir_civ2{val};
1410% if strcmp(SubDir,'new...')
1411%     if get(handles.CheckCiv2,'Value')
1412%         SubDir='CIV_INPUT'; %default subdirectory
1413%     else
1414%         msgbox_uvmat('ERROR','select CheckCiv2 to perform a new civ_input operation')
1415%         return
1416%     end
1417% end
1418% set(handles.Civ2_ImageA,'String',SubDir);
1419
1420%------------------------------------------------------------------------
1421% --- Executes on button press in CheckGrid.
1422function CheckGrid_Callback(hObject, eventdata, handles)
1423%------------------------------------------------------------------------
1424value=get(hObject,'Value');
1425hparent=get(hObject,'parent');%handles of the parent panel
1426hchildren=get(hparent,'children');
1427handle_txtbox=findobj(hchildren,'tag','Grid');% look for the grid name box in the same panel
1428handle_dx=findobj(hchildren,'tag','num_Dx');
1429handle_dy=findobj(hchildren,'tag','num_Dy');
1430handle_title_dx=findobj(hchildren,'tag','title_Dx');
1431handle_title_dy=findobj(hchildren,'tag','title_Dy');
1432testgrid=0;
1433filegrid='';
1434if value
1435        hseries=findobj(allchild(0),'Tag','series');
1436    hhseries=guidata(hseries);
1437    InputTable=get(hhseries.InputTable,'Data');
1438     ind_A=1;% line index of the (first) image series
1439    if strcmp(InputTable{1,5},'.nc');
1440        ind_A=2;
1441    end
1442    filebase=InputTable{ind_A,1};
1443    [nbslice, flag_grid]=get_grid(filebase,handles);% look for a grid with appropriate name
1444    if isequal(flag_grid,1)
1445        filegrid=[num2str(nbslice) 'grid'];
1446        testgrid=1;
1447    else % browse for a grid
1448        filegrid=get(hObject,'UserData');%look for previous grid name stored as UserData
1449        if exist(filegrid,'file')
1450            filebase=filegrid;
1451        end
1452       filegrid = uigetfile_uvmat('pick a grid file .grid:',filebase,'.grid');
1453        set(hObject,'UserData',filegrid);%store for future use
1454        if ~isempty(filegrid)
1455            testgrid=1;
1456        end
1457        set(hObject,'UserData',filegrid);%store for future use
1458    end
1459end
1460if testgrid
1461    set(handle_dx,'Visible','off');
1462    set(handle_dy,'Visible','off');
1463    set(handle_title_dy,'Visible','off');
1464    set(handle_title_dx,'Visible','off');
1465    set(handle_txtbox,'Visible','on')
1466    set(handle_txtbox,'String',filegrid)
1467else
1468    set(hObject,'Value',0);
1469    set(handle_dx,'Visible','on');
1470    set(handle_dy,'Visible','on');
1471    set(handle_title_dy,'Visible','on');
1472    set(handle_title_dx,'Visible','on');
1473    set(handle_txtbox,'Visible','off')
1474end
1475
1476%% if hObject is on the checkciv1 frame, duplicate action for checkciv2 frame
1477PanelName=get(hparent,'tag');
1478if strcmp(PanelName,'Civ1')
1479    hchildren=get(handles.Civ2,'children');
1480    handle_checkbox=findobj(hchildren,'tag','CheckGrid');
1481    handle_txtbox=findobj(hchildren,'tag','Grid');
1482    handle_dx=findobj(hchildren,'tag','num_Dx');
1483    handle_dy=findobj(hchildren,'tag','num_Dy');
1484    handle_title_dx=findobj(hchildren,'tag','title_Dx');
1485    handle_title_dy=findobj(hchildren,'tag','title_Dy');
1486    set(handle_checkbox,'UserData',filegrid);%store for future use
1487    if testgrid
1488        set(handle_checkbox,'Value',1);
1489        set(handle_dx,'Visible','off');
1490        set(handle_dy,'Visible','off');
1491        set(handle_title_dx,'Visible','off');
1492        set(handle_title_dy,'Visible','off');
1493        set(handle_txtbox,'Visible','on')
1494        set(handle_txtbox,'String',filegrid)
1495    end
1496end
1497set(hObject,'BackgroundColor',[1 0 1])
1498set(handles.ConfigSource,'String','NEW')
1499set(handles.OK,'BackgroundColor',[1 0 1])
1500%------------------------------------------------------------------------
1501% --- Executes on button press in CheckMask: common to all panels (civ1, Civ2..)
1502function CheckMask_Callback(hObject, eventdata, handles)
1503%------------------------------------------------------------------------
1504value=get(hObject,'Value');
1505hparent=get(hObject,'parent');
1506parent_tag=get(hparent,'Tag');
1507hchildren=get(hparent,'children');
1508handle_txtbox=findobj(hchildren,'tag','Mask');% look for the mask name box in the same panel
1509
1510testmask=0;
1511if value
1512    hseries=findobj(allchild(0),'Tag','series');
1513    hhseries=guidata(hseries);
1514    InputTable=get(hhseries.InputTable,'Data');
1515    ind_A=1;% line index of the (first) image series
1516    if strcmp(InputTable{1,5},'.nc');
1517        ind_A=2;
1518    end
1519    [nbslice, flag_mask]=get_mask(InputTable{ind_A,1},handles);% look for a mask with appropriate name
1520    if isequal(flag_mask,1)
1521        filemask=[num2str(nbslice) 'mask'];
1522        testmask=1;
1523    else % browse for a mask
1524%         filemask=get(hObject,'UserData');%look for previous mask name stored as UserData
1525%         if exist(filemask,'file')
1526%             filebase=filemask;
1527%         end
1528        filemask= uigetfile_uvmat('pick a mask image file:',InputTable{ind_A,1},'image');
1529        set(hObject,'UserData',filemask);%store for future use
1530        if ~isempty(filemask)
1531            testmask=1;
1532        end
1533    end
1534end
1535if testmask
1536    set(handles.Mask,'Visible','on')
1537    set(handles.Mask,'String',filemask)
1538    set(handles.CheckMask,'Value',1)
1539else
1540    set(hObject,'Value',0);
1541    set(handle_txtbox,'Visible','off')
1542end
1543set(handles.ConfigSource,'String','NEW')
1544set(handles.ConfigSource,'BackgroundColor',[1 0 1])
1545
1546% %------------------------------------------------------------------------
1547% % --- Executes on button press in get_gridpatch1.
1548% function get_gridpatch1_Callback(hObject, eventdata, handles)
1549% %------------------------------------------------------------------------
1550% filebase=get(handles.RootPath,'String');
1551% [FileName, PathName, filterindex] = uigetfile( ...
1552%     {'*.grid', ' (*.grid)';
1553%     '*.grid',  '.grid files '; ...
1554%     '*.*', 'All Files (*.*)'}, ...
1555%     'Pick a file',filebase);
1556% filegrid=fullfile(PathName,FileName);
1557% set(handles.grid_patch1,'string',filegrid);
1558% set(hObject,'BackgroundColor',[1 0 1])
1559
1560%------------------------------------------------------------------------
1561% --- STEREO Interp
1562function cmd=RUN_STINTERP(stinterpBin,filename_A_nc,filename_B_nc,filename_nc,nx_patch,ny_patch,rho_patch,subdomain_patch,thresh_value,xmlA,xmlB)
1563%------------------------------------------------------------------------
1564namelog=[filename_nc(1:end-3) '_stinterp.log'];
1565cmd=[stinterpBin ' -f1 ' filename_A_nc  ' -f2 ' filename_B_nc ' -f  ' filename_nc ...
1566    ' -m ' nx_patch  ' -n ' ny_patch ' -ro ' rho_patch ' -nopt ' subdomain_patch ' -c1 ' xmlA ' -c2 ' xmlB '  -xy  x -Nfy 1024 > ' namelog ' 2>&1']; % redirect standard output to the log file
1567
1568% %------------------------------------------------------------------------
1569% %--read images and convert them to the uint16 format used for PIV
1570% function A=read_image(filename,type_ima,num,movieobject)
1571% %------------------------------------------------------------------------
1572% %num is the view number needed for an avi movie
1573% switch type_ima
1574%     case 'movie'
1575%         A=read(movieobject,num);
1576%     case 'avi'
1577%         mov=aviread(filename,num);
1578%         A=frame2im(mov(1));
1579%     case 'multimage'
1580%         A=imread(filename,num);
1581%     case 'image'
1582%         A=imread(filename);
1583% end
1584% siz=size(A);
1585% if length(siz)==3;%color images
1586%     A=sum(double(A),3);
1587%     A=uint16(A);
1588% end
1589
1590
1591%------------------------------------------------------------------------
1592% --- Executes on button press in get_ref_fix1.
1593function get_ref_fix1_Callback(hObject, eventdata, handles)
1594%------------------------------------------------------------------------
1595filebase=get(handles.RootPath,'String');
1596[FileName, PathName, filterindex] = uigetfile( ...
1597    {'*.nc', ' (*.nc)';
1598    '*.nc',  'netcdf files '; ...
1599    '*.*', 'All Files (*.*)'}, ...
1600    'Pick a file',filebase);
1601
1602fileinput=[PathName FileName];
1603sizf=size(fileinput);
1604if (~ischar(fileinput)||~isequal(sizf(1),1)),return;end %stop if fileinput not a character string
1605%[Path,File,field_count,str2,str_a,str_b,ref.ext,ref.nom_type,ref.subdir]=name2display(fileinput);
1606[Path,ref.subdir,File,ref.num1,ref.num2,ref.num_a,ref.num_b,ref.ext,ref.nom_type]=fileparts_uvmat(fileinput);
1607ref.filebase=fullfile(Path,File);
1608% ref.num_a=stra2num(str_a);
1609% ref.num_b=stra2num(str_b);
1610% ref.num1=str2double(field_count);
1611% ref.num2=str2double(str2);
1612browse=[];%initialisation
1613if ~isequal(ref.ext,'.nc')
1614    msgbox_uvmat('ERROR','the reference file must be in netcdf format (*.nc)')
1615    return
1616end
1617set(handles.ref_fix1,'String',[fullfile(ref.subdir,File) '....nc']);
1618set(handles.ref_fix1,'UserData',ref)
1619menu_field{1}='civ1';
1620Data=nc2struct(fileinput,[]);
1621if isfield(Data,'patch') && isequal(Data.patch,1)
1622    menu_field{2}='filter1';
1623end
1624if isfield(Data,'civ2') && isequal(Data.civ2,1)
1625    menu_field{3}='civ2';
1626end
1627if isfield(Data,'patch2') && isequal(Data.patch2,1)
1628    menu_field{4}='filter2';
1629end
1630set(handles.field_ref1,'String',menu_field);
1631set(handles.field_ref1,'Value',length(menu_field));
1632set(handles.num_MinVel,'Value',2);
1633set(handles.num_MinVel,'String','1');%default threshold
1634set(handles.ref_fix1,'Enable','on')
1635
1636%------------------------------------------------------------------------
1637% --- Executes on button press in get_ref_fix2.
1638function get_ref_fix2_Callback(hObject, eventdata, handles)
1639%------------------------------------------------------------------------
1640if isequal(get(handles.get_ref_fix2,'Value'),1)
1641    filebase=get(handles.RootPath,'String');
1642    [FileName, PathName, filterindex] = uigetfile( ...
1643        {'*.nc', ' (*.nc)';
1644        '*.nc',  'netcdf files '; ...
1645        '*.*', 'All Files (*.*)'}, ...
1646        'Pick a file',filebase);
1647    fileinput=[PathName FileName];
1648    sizf=size(fileinput);
1649    if (~ischar(fileinput)||~isequal(sizf(1),1)),return;end %stop if fileinput not a character string
1650    %[Path,File,field_count,str2,str_a,str_b,ref.ext,ref.nom_type,ref.subdir]=name2display(fileinput);
1651    [Path,ref.subdir,File,ref.num1,ref.num2,ref.num_a,ref.num_b,ref.ext,ref.nom_type]=fileparts_uvmat(fileinput);
1652    ref.filebase=fullfile(Path,File);
1653    %     ref.num_a=stra2num(str_a);
1654    %     ref.num_b=stra2num(str_b);
1655    %     ref.num1=str2num(field_count);
1656    %     ref.num2=str2num(str2);
1657    browse=[];%initialisation
1658    if ~isequal(ref.ext,'.nc')
1659        msgbox_uvmat('ERROR','the reference file must be in netcdf format (*.nc)')
1660        return
1661    end
1662    set(handles.ref_fix2,'String',[fullfile(ref.subdir,File) '....nc']);
1663    set(handles.ref_fix2,'UserData',ref)
1664    menu_field{1}='civ1';
1665    Data=nc2struct(fileinput,[]);
1666    if isfield(Data,'patch') && isequal(Data.patch,1)
1667        menu_field{2}='filter1';
1668    end
1669    if isfield(Data,'civ2') && isequal(Data.civ2,1)
1670        menu_field{3}='civ2';
1671    end
1672    if isfield(Data,'patch2') && isequal(Data.patch2,1)
1673        menu_field{4}='filter2';
1674    end
1675    set(handles.field_ref2,'String',menu_field);
1676    set(handles.field_ref2,'Value',length(menu_field));
1677    set(handles.num_MinVel,'Value',2);
1678    set(handles.num_MinVel,'String','1');%default threshold
1679    set(handles.ref_fix2,'Enable','on')
1680    set(handles.ref_fix2,'Visible','on')
1681    set(handles.field_ref2,'Visible','on')
1682else
1683    set(handles.ref_fix2,'Visible','off')
1684    set(handles.field_ref2,'Visible','off')
1685end
1686
1687%------------------------------------------------------------------------
1688function ref_fix1_Callback(hObject, eventdata, handles)
1689%------------------------------------------------------------------------
1690set(handles.num_MinVel,'Value',1);
1691set(handles.field_ref1,'Value',1)
1692set(handles.field_ref1,'String',{' '})
1693set(handles.ref_fix1,'UserData',[]);
1694set(handles.ref_fix1,'String','');
1695set(handles.thresh_vel1,'String','0');
1696
1697%------------------------------------------------------------------------
1698function ref_fix2_Callback(hObject, eventdata, handles)
1699%------------------------------------------------------------------------
1700set(handles.num_MinVel,'Value',1);
1701set(handles.field_ref2,'Value',1)
1702set(handles.field_ref2,'String',{' '})
1703set(handles.ref_fix2,'UserData',[]);
1704set(handles.ref_fix2,'String','');
1705set(handles.num_MinVel,'String','0');
1706
1707%------------------------------------------------------------------------
1708% --- TO ABANDON Executes on button press in test_stereo1.
1709function CheckStereo_Callback(hObject, eventdata, handles)
1710%------------------------------------------------------------------------
1711hparent=get(hObject,'parent');
1712parent_tag=get(hparent,'Tag');
1713hchildren=get(hparent,'children');
1714handle_txtbox=findobj(hchildren,'tag','txt_Mask');
1715if isequal(get(hObject,'Value'),0)
1716    set(handles.num_SubDomainSize,'Visible','on')
1717    set(handles.num_FieldSmooth,'Visible','on')
1718else
1719    set(handles.num_SubDomainSize,'Visible','off')
1720    set(handles.num_FieldSmooth,'Visible','off')
1721end
1722
1723% %------------------------------------------------------------------------
1724% % --- Executes on button press in CheckStereo.
1725% function StereoCheck_Callback(hObject, eventdata, handles)
1726% %------------------------------------------------------------------------
1727% if isequal(get(handles.CheckStereo,'Value'),0)
1728%     set(handles.num_subdomainsize,'Visible','on')
1729%     set(handles.num_FieldSmooth,'Visible','on')
1730% else
1731
1732%     set(handles.num_subdomainsize,'Visible','off')
1733%     set(handles.num_FieldSmooth,'Visible','off')
1734% end
1735
1736
1737
1738%------------------------------------------------------------------------
1739%----function introduced for the correlation window figure, activated by deleting this window
1740function closeview_field(gcbo,eventdata)
1741%------------------------------------------------------------------------
1742hview_field=findobj(allchild(0),'tag','view_field');% look for view_field
1743if ~isempty(hview_field)
1744    delete(hview_field)
1745end
1746
1747%------------------------------------------------------------------------
1748% --- Executes on button press in CheckThreshold.
1749function CheckThreshold_Callback(hObject, eventdata, handles)
1750%------------------------------------------------------------------------
1751huipanel=get(hObject,'parent');
1752obj(1)=findobj(huipanel,'Tag','num_MinIma');
1753obj(2)=findobj(huipanel,'Tag','num_MaxIma');
1754obj(3)=findobj(huipanel,'Tag','title_Threshold');
1755if get(hObject,'Value')
1756    set(obj,'Visible','on')
1757else
1758    set(obj,'Visible','off')
1759end
1760set(handles.ConfigSource,'String','NEW')
1761set(handles.OK,'BackgroundColor',[1 0 1])
1762%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1763%%%%%%%%%%%%%%   TEST functions
1764%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1765%------------------------------------------------------------------------
1766% --- Executes on button press in TestCiv1: prepare the image correlation function
1767%     activated by mouse motion
1768function TestCiv1_Callback(hObject, eventdata, handles)
1769%------------------------------------------------------------------------
1770drawnow
1771if get(handles.TestCiv1,'Value')
1772    set(handles.TestCiv1,'BackgroundColor',[1 1 0])% paint TestCiv1 button to yellow to confirm civ launch 
1773    set(handles.CheckFix1,'value',0)% desactivate next step
1774    set(handles.CheckPatch1,'value',0)% desactivate next step
1775    set(handles.CheckCiv2,'value',0)% desactivate next step
1776    set(handles.CheckFix2,'value',0)% desactivate next step
1777    set(handles.CheckPatch2,'value',0)% desactivate next step
1778    update_CivOptions(handles,0)
1779      hseries=findobj(allchild(0),'Tag','series');
1780     Param=read_GUI(hseries);
1781     Param.Action.RUN=1;
1782     Param.ActionInput=read_GUI(handles.civ_input);
1783     if isfield(Param.ActionInput,'Fix1')
1784         Param.ActionInput=rmfield(Param.ActionInput,'Fix1');
1785     end
1786     if isfield(Param.ActionInput,'Patch1')
1787         Param.ActionInput=rmfield(Param.ActionInput,'Patch1');
1788     end
1789     if isfield(Param.ActionInput,'Civ2')%remove options that may be selected beyond Patch1
1790         Param.ActionInput=rmfield(Param.ActionInput,'Civ2');
1791     end
1792     if isfield(Param.ActionInput,'Fix2')
1793         Param.ActionInput=rmfield(Param.ActionInput,'Fix2');
1794     end
1795     if isfield(Param.ActionInput,'Patch2')
1796         Param.ActionInput=rmfield(Param.ActionInput,'Patch2');
1797     end
1798     if isfield(Param,'OutputSubDir')
1799     Param=rmfield(Param,'OutputSubDir'); %remove output file option from civ_series
1800     end
1801     Param.ActionInput.Civ1.CorrSmooth=0;% launch Civ1 with no data point (to get the image names for A and B)
1802     [Data,errormsg]=civ_series(Param);% get the civ1+fix1 results
1803     if ~isempty(errormsg), return, end % rmq: error msg displayed in civ_series
1804     
1805 %% create image data ImageData for display
1806     ImageData.ListVarName={'ny','nx','A'};
1807     ImageData.VarDimName= {'ny','nx',{'ny','nx'}};
1808     ImageData.A=imread(Data.Civ1_ImageA); % read the first image
1809     if ndims(ImageData.A)==3 %case of color image
1810         ImageData.VarDimName= {'ny','nx',{'ny','nx','rgb'}};
1811     end
1812     ImageData.ny=[size(ImageData.A,1) 1];
1813     ImageData.nx=[1 size(ImageData.A,2)];
1814     ImageData.CoordUnit='pixel';% used to set equal scaling for x and y in image dispa=ly
1815
1816     %% create the figure view_field for image visualization
1817     hview_field=view_field(ImageData); %view the image in the GUI view_field
1818     set(0,'CurrentFigure',hview_field)
1819     hhview_field=guihandles(hview_field);
1820     set(hview_field,'CurrentAxes',hhview_field.PlotAxes)
1821     ViewData=get(hview_field,'UserData');
1822     ViewData.CivHandle=handles.civ_input;% indicate the handle of the civ GUI in view_field
1823     ViewData.PlotAxes.X=Data.Civ1_X';
1824     ViewData.PlotAxes.Y=Data.Civ1_Y';
1825     ViewData.PlotAxes.B=imread(Data.Civ1_ImageB);%store the second image in the UserData of the GUI view_field
1826     set(hview_field,'UserData',ViewData)% store the info in the UserData of image view_field
1827   
1828    %% look for a current figure for image correlation display
1829    corrfig=findobj(allchild(0),'tag','corrfig');
1830    if isempty(corrfig)
1831        corrfig=figure;
1832        set(corrfig,'tag','corrfig')
1833        set(corrfig,'name','image correlation')
1834        set(corrfig,'DeleteFcn',{@closeview_field})%
1835        set(handles.TestCiv1,'BackgroundColor',[1 0 0])
1836    else
1837        set(handles.TestCiv1,'BackgroundColor',[1 0 0])% paint button to red
1838        corrfig=findobj(allchild(0),'tag','corrfig');% look for a current figure for image correlation display
1839        if ~isempty(corrfig)
1840            delete(corrfig)
1841        end
1842        hview_field=findobj(allchild(0),'tag','view_field');% look for view_field
1843        if ~isempty(hview_field)
1844            delete(hview_field)
1845        end
1846    end
1847else
1848    hview_field=findobj(allchild(0),'Tag','view_field'); %view the image in the GUI view_field
1849    if ~isempty(hview_field)
1850        delete(hview_field)
1851    end     
1852end
1853
1854% --------------------------------------------------------------------
1855% --- Executes on button press in TestPatch1.
1856% --------------------------------------------------------------------
1857function TestPatch1_Callback(hObject, eventdata, handles)
1858
1859if get(handles.TestPatch1,'Value')% if TestPatch1 is activated
1860     set(handles.TestPatch1,'BackgroundColor',[1 1 0])%paint TestPatch1 button in yellow to indicate activation
1861     set(handles.Civ1,'BackgroundColor',[1 1 0])% indicate civ1 calculation is performed
1862     hseries=findobj(allchild(0),'Tag','series');
1863     Param=read_GUI(hseries);
1864     Param.Action.RUN=1;
1865     Param.ActionInput=read_GUI(handles.civ_input);
1866     if isfield(Param.ActionInput,'Civ2')%remove options that may be selected beyond Patch1
1867         Param.ActionInput=rmfield(Param.ActionInput,'Civ2');
1868     end
1869     if isfield(Param.ActionInput,'Fix2')
1870         Param.ActionInput=rmfield(Param.ActionInput,'Fix2');
1871     end
1872     if isfield(Param.ActionInput,'Patch2')
1873         Param.ActionInput=rmfield(Param.ActionInput,'Patch2');
1874     end
1875     if isfield(Param,'OutputSubDir')
1876         Param=rmfield(Param,'OutputSubDir'); %remove output file option from civ_series
1877     end
1878     ParamPatch1=Param.ActionInput.Patch1; %store the patch1 parameters
1879     Param.ActionInput=rmfield(Param.ActionInput,'Patch1');% does not execute Patch
1880     Param.IndexRange.first_i=str2num(get(handles.ref_i,'String'));
1881     Param.IndexRange.last_i=Param.IndexRange.first_i;
1882     if strcmp(get(handles.ref_j,'Visible'),'on')
1883         Param.IndexRange.first_j=str2num(get(handles.ref_j,'String'));
1884         Param.IndexRange.last_j=Param.IndexRange.first_j;
1885     else
1886         Param.IndexRange.first_j=1;
1887         Param.IndexRange.last_j=1;
1888     end
1889     [Data,errormsg]=civ_series(Param);% get the civ1+fix1 results
1890     bckcolor=get(handles.civ_input,'Color');
1891     set(handles.Civ1,'BackgroundColor',bckcolor)% indicate civ1 calculation is finished
1892     
1893     %% prepare Param for iterative Patch processing without input file reading
1894     Param.Civ1_X=Data.Civ1_X;
1895     Param.Civ1_Y=Data.Civ1_Y;
1896     Param.Civ1_U=Data.Civ1_U;
1897     Param.Civ1_V=Data.Civ1_V;
1898     Param.Civ1_FF=Data.Civ1_FF;
1899     Param=rmfield(Param,'InputTable');%desactivate input file reading
1900    if isfield(Param.ActionInput,'Civ1')
1901        Param.ActionInput=rmfield(Param.ActionInput,'Civ1');%desactivate civ1: remove civ1 input param if relevant
1902    end
1903    if isfield(Param.ActionInput,'Fix1')
1904        Param.ActionInput=rmfield(Param.ActionInput,'Fix1');%desactivate fix1:remove fix1 input param if relevant
1905    end
1906    SmoothingParam=(ParamPatch1.FieldSmooth/10)*2.^(1:7);%scan the smoothing param from 1/10 to 12.8 current value
1907    NbGood=numel(find(Data.Civ1_FF==0));
1908    NbExclude=zeros(1,7);% initialize the set of smoothing parameters
1909    DiffVel=zeros(1,7);% initialize the rms difference between patch and civ
1910    Param.ActionInput.Patch1=ParamPatch1;% retrieve Patch1 parameters
1911    for irho=1:7
1912        Param.ActionInput.Patch1.FieldSmooth=SmoothingParam(irho);
1913        [Data,errormsg]= civ_series(Param);%apply the processing fct
1914        if ~isempty(errormsg)
1915            msgbox_uvmat('ERROR',errormsg)
1916            return
1917        end
1918        ind_good=find(Data.Civ1_FF==0);
1919        Civ1_U_Diff=Data.Civ1_U(ind_good)-Data.Civ1_U_smooth(ind_good);
1920        Civ1_V_Diff=Data.Civ1_V(ind_good)-Data.Civ1_V_smooth(ind_good);
1921        DiffVel(irho)=sqrt(mean(Civ1_U_Diff.*Civ1_U_Diff+Civ1_V_Diff.*Civ1_V_Diff));
1922        NbExclude(irho)=(NbGood-numel(ind_good))/NbGood;
1923    end
1924    figure(1)
1925    semilogx(SmoothingParam,DiffVel,'b',SmoothingParam,NbExclude,'r',SmoothingParam,0.2*ones(size(SmoothingParam)),'m')
1926    grid on
1927    legend('rms velocity diff. Patch1-Civ1 (pixels)','proportion of excluded vectors (between 0 to 1)','recommended diff Patch1-Civ1')
1928    xlabel('smoothing parameter')
1929    ylabel('smoothing effect')
1930    set(handles.TestPatch1,'BackgroundColor',[0 1 0])
1931else
1932    corrfig=findobj(allchild(0),'tag','corrfig');% look for a current figure for image correlation display
1933    if ~isempty(corrfig)
1934        delete(corrfig)
1935    end
1936    hview_field=findobj(allchild(0),'tag','view_field');% look for view_field
1937    if ~isempty(hview_field)
1938        delete(hview_field)
1939    end
1940end
1941
1942%------------------------------------------------------------------------
1943% --- Executes on button press in TestCiv2.
1944%------------------------------------------------------------------------
1945function TestCiv2_Callback(hObject, eventdata, handles)
1946drawnow
1947if get(handles.TestCiv2,'Value')
1948    set(handles.TestCiv2,'BackgroundColor',[1 1 0])% paint TestCiv1 button to yellow to confirm civ launch
1949    set(handles.CheckFix2,'value',0)% desactivate next step
1950    set(handles.CheckPatch2,'value',0)% desactivate next step
1951    update_CivOptions(handles,0)
1952      hseries=findobj(allchild(0),'Tag','series');
1953     Param=read_GUI(hseries);
1954     Param.Action.RUN=1;
1955     Param.ActionInput=read_GUI(handles.civ_input);
1956     if isfield(Param,'OutputSubDir')
1957     Param=rmfield(Param,'OutputSubDir'); %remove output file option from civ_series
1958     end
1959     Param.ActionInput.Civ2.CorrSmooth=0;% launch Civ2 with no data point (to get the image names for A and B)
1960     set(handles.Civ1,'BackgroundColor',[1 1 0])
1961     set(handles.Fix1,'BackgroundColor',[1 1 0])
1962     set(handles.Patch1,'BackgroundColor',[1 1 0])
1963     Param.IndexRange.first_i=str2num(get(handles.ref_i,'String'));
1964     Param.IndexRange.last_i=Param.IndexRange.first_i;
1965     if strcmp(get(handles.ref_j,'Visible'),'on')
1966         Param.IndexRange.first_j=str2num(get(handles.ref_j,'String'));
1967         Param.IndexRange.last_j=Param.IndexRange.first_j;
1968     else
1969         Param.IndexRange.first_j=1;
1970         Param.IndexRange.last_j=1;
1971     end
1972     [Data,errormsg]=civ_series(Param);% get the civ1+fix1 results
1973     
1974     %% create image data ImageData for display
1975     ImageData.ListVarName={'ny','nx','A'};
1976     ImageData.VarDimName= {'ny','nx',{'ny','nx'}};
1977     ImageData.A=imread(Data.Civ2_ImageA); % read the first image
1978     if ndims(ImageData.A)==3 %case of color image
1979         ImageData.VarDimName= {'ny','nx',{'ny','nx','rgb'}};
1980     end
1981     ImageData.ny=[size(ImageData.A,1) 1];
1982     ImageData.nx=[1 size(ImageData.A,2)];
1983     ImageData.CoordUnit='pixel';% used to set equal scaling for x and y in image dispa=ly
1984
1985     %% create the figure view_field for image visualization
1986    hview_field=view_field(ImageData); %view the image in the GUI view_field
1987    set(0,'CurrentFigure',hview_field)
1988    % plot the boundaries of the subdomains used for patch
1989    for isub=1:size(Data.Civ1_SubRange,3);
1990        pos_x=Data.Civ1_SubRange(1,1,isub);
1991        pos_y=Data.Civ1_SubRange(2,1,isub);
1992        width=Data.Civ1_SubRange(1,2,isub)-Data.Civ1_SubRange(1,1,isub);
1993        height=Data.Civ1_SubRange(2,2,isub)-Data.Civ1_SubRange(2,1,isub);
1994        rectangle('Position',[pos_x pos_y width height],'EdgeColor',[0 0 1])
1995    end
1996    hhview_field=guihandles(hview_field);%
1997    set(hview_field,'CurrentAxes',hhview_field.PlotAxes)
1998    ViewData=get(hview_field,'UserData'); % get the currently plotted field (the image A)
1999    % store info in the UserData of view-field
2000    ViewData.CivHandle=handles.civ_input;% indicate the handle of the civ GUI in view_field
2001    ViewData.PlotAxes.B=imread(Data.Civ2_ImageB);%store the second image in the UserData of the GUI view_field
2002    ViewData.PlotAxes.X=Data.Civ2_X';
2003    ViewData.PlotAxes.Y=Data.Civ2_Y';
2004    ViewData.PlotAxes.ShiftX=Data.Civ2_U';% shift at each point (from patch1) estimated by the preliminary run of civ2
2005    ViewData.PlotAxes.ShiftY=Data.Civ2_V';
2006    ViewData.PlotAxes.Civ1_SubRange=Data.Civ1_SubRange;
2007    ViewData.PlotAxes.Civ1_NbCentres=Data.Civ1_NbCentres;
2008    ViewData.PlotAxes.Civ1_Coord_tps=Data.Civ1_Coord_tps;
2009    ViewData.PlotAxes.Civ1_U_tps=Data.Civ1_U_tps;
2010    ViewData.PlotAxes.Civ1_V_tps=Data.Civ1_V_tps;
2011    ViewData.PlotAxes.Civ1_Dt=Data.Civ1_Dt;
2012    ViewData.PlotAxes.Civ2_Dt=Data.Civ2_Dt;
2013    set(hview_field,'UserData',ViewData)% store the info in the UserData of image view_field
2014    bckcolor=get(handles.civ_input,'Color');
2015    set(handles.Civ1,'BackgroundColor',bckcolor)% indicate civ1 calmculation is finished
2016    set(handles.Fix1,'BackgroundColor',bckcolor)
2017    set(handles.Patch1,'BackgroundColor',bckcolor)
2018    drawnow
2019   
2020    %% look for a current figure for image correlation display
2021    corrfig=findobj(allchild(0),'tag','corrfig');
2022    if isempty(corrfig)
2023        corrfig=figure;
2024        set(corrfig,'tag','corrfig')
2025        set(corrfig,'name','image correlation')
2026        set(corrfig,'DeleteFcn',{@closeview_field})%
2027        set(handles.TestCiv1,'BackgroundColor',[1 0 0])
2028    else
2029        set(handles.TestCiv1,'BackgroundColor',[1 0 0])% paint button to red
2030        corrfig=findobj(allchild(0),'tag','corrfig');% look for a current figure for image correlation display
2031        if ~isempty(corrfig)
2032            delete(corrfig)
2033        end
2034        hview_field=findobj(allchild(0),'tag','view_field');% look for view_field
2035        if ~isempty(hview_field)
2036            delete(hview_field)
2037        end
2038    end   
2039else
2040    hview_field=findobj(allchild(0),'Tag','view_field'); %view the image in the GUI view_field
2041    if ~isempty(hview_field)
2042        delete(hview_field)
2043    end     
2044end
2045
2046
2047% --- Executes on button press in TestPatch2.
2048function TestPatch2_Callback(hObject, eventdata, handles)
2049if get(handles.TestPatch2,'Value')% if TestPatch2 is activated
2050     set(handles.TestPatch2,'BackgroundColor',[1 1 0])%paint TestPatch2 button in yellow to indicate activation
2051     set(handles.Civ1,'BackgroundColor',[1 1 0])% indicate civ1 calculation is activated
2052     set(handles.Fix1,'BackgroundColor',[1 1 0])% indicate fix1 calculation is activated
2053     set(handles.Patch1,'BackgroundColor',[1 1 0])% indicate Patch1 calculation is activated
2054     set(handles.Civ2,'BackgroundColor',[1 1 0])% indicate civ2 calculation is activated
2055     set(handles.Fix2,'BackgroundColor',[1 1 0])% indicate fix2 calculation is activated
2056     hseries=findobj(allchild(0),'Tag','series');
2057     Param=read_GUI(hseries);
2058     Param.Action.RUN=1;
2059     Param.ActionInput=read_GUI(handles.civ_input);
2060     if isfield(Param,'OutputSubDir')
2061     Param=rmfield(Param,'OutputSubDir'); %remove output file option from civ_series
2062     end
2063     ParamPatch2=Param.ActionInput.Patch2; %store the patch1 parameters
2064     Param.ActionInput=rmfield(Param.ActionInput,'Patch2');% does not execute Patch
2065     Param.IndexRange.first_i=str2num(get(handles.ref_i,'String'));
2066     Param.IndexRange.last_i=Param.IndexRange.first_i;
2067     if strcmp(get(handles.ref_j,'Visible'),'on')
2068         Param.IndexRange.first_j=str2num(get(handles.ref_j,'String'));
2069         Param.IndexRange.last_j=Param.IndexRange.first_j;
2070     else
2071         Param.IndexRange.first_j=1;
2072         Param.IndexRange.last_j=1;
2073     end
2074     [Data,errormsg]=civ_series(Param);% get the civ1+fix1 results
2075     bckcolor=get(handles.civ_input,'Color');
2076     set(handles.Civ1,'BackgroundColor',bckcolor)% indicate civ1 calculation is finished
2077     set(handles.Fix1,'BackgroundColor',bckcolor)% indicate fix1 calculation is finished
2078     set(handles.Patch1,'BackgroundColor',bckcolor)% indicate Patch1 calculation is finished
2079     set(handles.Civ2,'BackgroundColor',bckcolor)% indicate civ2 calculation is finished
2080     set(handles.Fix2,'BackgroundColor',bckcolor)% indicate fix2 calculation is finished
2081     
2082     %% prepare Param for iterative Patch processing without input file reading
2083     Param.Civ2_X=Data.Civ2_X;
2084     Param.Civ2_Y=Data.Civ2_Y;
2085     Param.Civ2_U=Data.Civ2_U;
2086     Param.Civ2_V=Data.Civ2_V;
2087     Param.Civ2_FF=Data.Civ2_FF;
2088     Param=rmfield(Param,'InputTable');%desactivate input file reading
2089    if isfield(Param.ActionInput,'Civ1')
2090        Param.ActionInput=rmfield(Param.ActionInput,'Civ1');%desactivate civ1: remove civ1 input param if relevant
2091    end
2092    if isfield(Param.ActionInput,'Fix1')
2093        Param.ActionInput=rmfield(Param.ActionInput,'Fix1');%desactivate fix1:remove fix1 input param if relevant
2094    end
2095    if isfield(Param.ActionInput,'Patch1')
2096        Param.ActionInput=rmfield(Param.ActionInput,'Patch1');%desactivate fix1:remove fix1 input param if relevant
2097    end
2098    if isfield(Param.ActionInput,'Civ2')
2099        Param.ActionInput=rmfield(Param.ActionInput,'Civ2');%desactivate civ2: remove civ2 input param if relevant
2100    end
2101    if isfield(Param.ActionInput,'Fix2')
2102        Param.ActionInput=rmfield(Param.ActionInput,'Fix2');%desactivate fix1:remove fix1 input param if relevant
2103    end
2104    SmoothingParam=(ParamPatch2.FieldSmooth/10)*2.^(1:7);%scan the smoothing param from 1/10 to 12.8 current value
2105    NbGood=numel(find(Data.Civ2_FF==0));
2106    NbExclude=zeros(1,7);% initialize the set of smoothing parameters
2107    DiffVel=zeros(1,7);% initialize the rms difference between patch and civ
2108    Param.ActionInput.Patch2=ParamPatch2;% retrieve Patch2 parameters
2109    for irho=1:7
2110        Param.ActionInput.Patch2.FieldSmooth=SmoothingParam(irho);
2111        [Data,errormsg]= civ_series(Param);%apply the processing fct
2112        if ~isempty(errormsg)
2113            msgbox_uvmat('ERROR',errormsg)
2114            return
2115        end
2116        ind_good=find(Data.Civ2_FF==0);
2117        Civ2_U_Diff=Data.Civ2_U(ind_good)-Data.Civ2_U_smooth(ind_good);
2118        Civ2_V_Diff=Data.Civ2_V(ind_good)-Data.Civ2_V_smooth(ind_good);
2119        DiffVel(irho)=sqrt(mean(Civ2_U_Diff.*Civ2_U_Diff+Civ2_V_Diff.*Civ2_V_Diff));
2120        NbExclude(irho)=(NbGood-numel(ind_good))/NbGood;
2121    end
2122    figure(1)
2123    semilogx(SmoothingParam,DiffVel,'b',SmoothingParam,NbExclude,'r',SmoothingParam,0.1*ones(size(SmoothingParam)),'m')
2124    grid on
2125    legend('rms velocity diff. Patch2-Civ2 (pixels)','proportion of excluded vectors (between 0 to 1)','recommended value diff. Patch2-Civ2')
2126    xlabel('smoothing parameter')
2127    ylabel('smoothing effect')
2128    set(handles.TestPatch2,'BackgroundColor',[0 1 0])
2129else
2130    corrfig=findobj(allchild(0),'tag','corrfig');% look for a current figure for image correlation display
2131    if ~isempty(corrfig)
2132        delete(corrfig)
2133    end
2134    hview_field=findobj(allchild(0),'tag','view_field');% look for view_field
2135    if ~isempty(hview_field)
2136        delete(hview_field)
2137    end
2138end
2139   
2140
2141%'nomtype2pair': creates nomencalture for index pairs knowing the image nomenclature
2142%---------------------------------------------------------------------
2143function NomTypeNc=nomtype2pair(NomTypeIma,mode)
2144%---------------------------------------------------------------------           
2145% OUTPUT:
2146% NomTypeNc
2147%---------------------------------------------------------------------
2148% INPUT:
2149% 'NomTypeIma': string defining the kind of nomenclature used for images
2150
2151NomTypeNc=NomTypeIma;%default
2152switch mode
2153    case 'pair j1-j2'     
2154    if ~isempty(regexp(NomTypeIma,'a$'))
2155        NomTypeNc=[NomTypeIma 'b'];
2156    elseif ~isempty(regexp(NomTypeIma,'A$'))
2157        NomTypeNc=[NomTypeIma 'B'];
2158    else
2159        r=regexp(NomTypeIma,'(?<num1>\d+)_(?<num2>\d+)$','names');
2160        if ~isempty(r)
2161            NomTypeNc='_1_1-2';
2162        end
2163    end
2164    case 'series(Dj)' 
2165%         r=regexp(NomTypeIma,'(?<num1>\d+)_(?<num2>\d+)$','names');
2166%         if ~isempty(r)
2167            NomTypeNc='_1_1-2';
2168%         end
2169   case 'series(Di)'
2170        r=regexp(NomTypeIma,'(?<num1>\d+)_(?<num2>\d+)$','names');
2171        if ~isempty(r)
2172            NomTypeNc='_1-2_1';
2173        else
2174            NomTypeNc='_1-2';
2175        end
2176end
2177
2178
2179%------------------------------------------------------------------------
2180% --- determine the list of index pairs of processing file
2181function [ind1,ind2,mode]=...
2182    find_pair_indices(str_civ,i_series,j_series,MinIndex_i,MaxIndex_i,MinIndex_j,MaxIndex_j)
2183%------------------------------------------------------------------------
2184ind1='';
2185ind2='';
2186r=regexp(str_civ,'^\D(?<ind>[i|j])=( -| )(?<num1>\d+)\|(?<num2>\d+)','names');
2187if ~isempty(r)
2188    mode=['D' r.ind];
2189    ind1=stra2num(r.num1);
2190    ind2=stra2num(r.num2);
2191else
2192    mode='burst';
2193    r=regexp(str_civ,'^j= (?<num1>[a-z])-(?<num2>[a-z])','names');
2194    if ~isempty(r)
2195        NomTypeNc='_1ab';
2196    else
2197        r=regexp(str_civ,'^j= (?<num1>[A-Z])-(?<num2>[A-Z])','names');
2198        if ~isempty(r)
2199            NomTypeNc='_1AB';
2200        else
2201            r=regexp(str_civ,'^j= (?<num1>\d+)-(?<num2>\d+)','names');
2202            if ~isempty(r)
2203                NomTypeNc='_1_1-2';
2204            end           
2205        end
2206    end
2207    if isempty(r)
2208        display('wrong pair mode input option')
2209    else
2210    ind1=stra2num(r.num1);
2211    ind2=stra2num(r.num2);
2212    end
2213end
2214
2215%------------------------------------------------------------------------
2216% --- fill civ_input with the parameters retrieved from an input Civ file
2217%------------------------------------------------------------------------
2218function fill_civ_input(Data,handles)
2219
2220%% Civ param
2221% lists of parameters to enter
2222ListParamNum={'CorrBoxSize','SearchBoxSize','SearchBoxShift','Dx','Dy','Dz','MinIma','MaxIma'};% list of numerical values (to transform in strings)
2223ListParamValue={'CorrSmooth','CheckGrid','CheckMask','CheckThreshold'};
2224ListParamString={'Grid','Mask'};
2225% CorrSmooth ??
2226option={'Civ1','Civ2'};
2227for ichoice=1:2
2228    if isfield(Data,[option{ichoice} '_CorrBoxSize'])
2229        fill_panel(Data,handles,option{ichoice},ListParamNum,ListParamValue,ListParamString)
2230    end
2231end
2232
2233%% Fix param
2234option={'Fix1','Fix2'};
2235for ichoice=1:2
2236    if isfield(Data,[option{ichoice} '_CheckFmin2'])
2237        ListParamNum={'MinVel','MaxVel','MinCorr'};% list of numerical values (to transform in strings)
2238        ListParamValue={'CheckFmin2','CheckF3','CheckF4'};
2239        ListParamString={'ref_fix_1'};
2240        fill_panel(Data,handles,option{ichoice},ListParamNum,ListParamValue,ListParamString)
2241    end
2242end
2243
2244%% Patch param
2245option={'Patch1','Patch2'};
2246for ichoice=1:2
2247    if isfield(Data,[option{ichoice} '_FieldSmooth'])
2248        ListParamNum={'FieldSmooth','MaxDiff','SubDomainSize'};% list of numerical values (to transform in strings)
2249        ListParamValue={};
2250        ListParamString={};
2251        fill_panel(Data,handles,option{ichoice},ListParamNum,ListParamValue,ListParamString)
2252    end
2253end
2254%------------------------------------------------------------------------
2255% --- fill a panel of civ_input with the parameters retrieved from an input Civ file
2256%------------------------------------------------------------------------
2257function fill_panel(Data,handles,panel,ListParamNum,ListParamValue,ListParamString)
2258children=get(handles.(panel),'children');%handles of the children of the input GUI with handle 'GUI_handle'
2259handles_panel=[];
2260for ichild=1:numel(children)
2261    if ~isempty(get(children(ichild),'tag'))
2262        handles_panel.(get(children(ichild),'tag'))=children(ichild);
2263    end
2264end
2265for ilist=1:numel(ListParamNum)
2266    ParamName=ListParamNum{ilist};
2267    CivParamName=[panel '_' ParamName];
2268    if isfield(Data,CivParamName)
2269        for icoord=1:numel(Data.(CivParamName))
2270            if numel(Data.(CivParamName))>1
2271                Tag=['num_' ParamName '_' num2str(icoord)];
2272            else
2273                Tag=['num_' ParamName];
2274            end
2275            if isfield(handles_panel,Tag)
2276                set(handles_panel.(Tag),'String',num2str(Data.(CivParamName)(icoord)))
2277                set(handles_panel.(Tag),'Visible','on')
2278            end
2279        end
2280    end
2281end
2282for ilist=1:numel(ListParamValue)
2283    ParamName=ListParamValue{ilist};
2284    CivParamName=[panel '_' ParamName];
2285    if strcmp(ParamName,'CorrSmooth')
2286        ParamName=['num_' ParamName];
2287    end
2288    if isfield(Data,CivParamName)
2289        if isfield(handles_panel,ParamName)
2290            set(handles_panel.(ParamName),'Value',Data.(CivParamName))
2291        end
2292    end
2293end
2294for ilist=1:numel(ListParamString)
2295    ParamName=ListParamString{ilist};
2296    CivParamName=[panel '_' ParamName];
2297    if isfield(Data,CivParamName)
2298        if isfield(handles_panel,ParamName)
2299            set(handles_panel.(ParamName),'String',Data.(CivParamName))
2300        end
2301    end
2302end
2303
2304%------------------------------------------------------------------------
2305% --- Executes on button press in ImportParam.
2306%------------------------------------------------------------------------
2307function ImportParam_Callback(hObject, eventdata, handles)
2308hseries=findobj(allchild(0),'Tag','series');
2309hhseries=guidata(hseries);
2310InputTable=get(hhseries.InputTable,'Data');% read the input file(s) table in the GUI series
2311oldfile=InputTable{1,1};
2312if isempty(oldfile)
2313    % use a file name stored in prefdir
2314    dir_perso=prefdir;
2315    profil_perso=fullfile(dir_perso,'uvmat_perso.mat');
2316    if exist(profil_perso,'file')
2317        h=load (profil_perso);
2318        if isfield(h,'RootPath') && ischar(h.RootPath)
2319            oldfile=h.RootPath;
2320        end
2321    end
2322end
2323filexml=uigetfile_uvmat('pick a xml parameter file for civ',oldfile,'.xml');% get the xml file containing processing parameters
2324%proceed only if a file has been introduced by the browser
2325if ~isempty(filexml)
2326    Param=xml2struct(filexml);% read the input xml file as a Matlab structure
2327
2328   % Param.Action.RUN=0; %desactivate the input RUN=1
2329    if ~isfield(Param,'InputTable')||~isfield(Param,'IndexRange')
2330        msgbox_uvmat('ERROR','invalid config file: open a file in a folder ''/0_XML''')
2331        return
2332    end
2333    check_input=0;
2334    if isfield(Param,'ActionInput')
2335        if isfield(Param.ActionInput,'Program')&& strcmp(Param.ActionInput.Program,'civ_series')
2336            fill_GUI(Param.ActionInput,handles.civ_input)% fill the elements of the GUI series with the input parameters
2337            set(handles.ConfigSource,'String',filexml)
2338            check_input=1;
2339            update_CivOptions(handles,0)             
2340        end
2341    end
2342    if ~check_input
2343        msgbox_uvmat('ERROR','invalid config file (not for civ_series')
2344        return
2345    end
2346end
2347
2348% --- Executes on selection change in CheckCiv3.
2349function CheckCiv3_Callback(hObject, eventdata, handles)
2350
2351
2352%------------------------------------------------------------------------
2353% --- Executes on key press with selection of a uicontrol
2354%------------------------------------------------------------------------
2355function keyboard_callback(hObject,eventdata,handles)
2356   
2357ListExclude={'CheckCiv1','CheckFix1','CheckPatch1','CheckCiv2','CheckFix2','CheckPatch2','ref_i'};
2358if isempty(find(strcmp(get(gco,'Tag'),ListExclude),1))% if the selected uicontrol is not in the Exclude list
2359    set(handles.ConfigSource,'String','NEW')% indicate that the configuration is new
2360    set(handles.OK,'BackgroundColor',[1 0 1])%
2361    drawnow
2362end
Note: See TracBrowser for help on using the repository browser.