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

Last change on this file since 865 was 862, checked in by sommeria, 10 years ago

bugs repaired

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