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

Last change on this file since 935 was 932, checked in by sommeria, 8 years ago

writting access improved

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