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

Last change on this file since 1163 was 1163, checked in by sommeria, 2 months ago

SearchBoxSize? changed to SearchRange? in civ, possibility of a grid set by a netcdf file

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