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

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