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

Last change on this file since 1097 was 1097, checked in by sommeria, 3 years ago

various bug repairs

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