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

Last change on this file since 1153 was 1153, checked in by sommeria, 3 months ago

civ3 improved

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