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

Last change on this file since 1147 was 1147, checked in by sommeria, 5 months ago

merge_proj repaired with multimask possibility

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