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

Last change on this file since 1199 was 1199, checked in by sommeria, 5 hours ago

bugs repaired

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