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

Last change on this file since 986 was 979, checked in by sommeria, 8 years ago

phantom added, series corrected

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