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

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

bugs corrected in fix in civ_series. vectors set to 0 inside mask

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