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

Last change on this file since 1019 was 1018, checked in by sommeria, 6 years ago

extract_rdvision fixed

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