Changeset 507 for trunk/src/uvmat.m


Ignore:
Timestamp:
Jul 29, 2012, 11:18:31 PM (12 years ago)
Author:
sommeria
Message:

various improvments and corrections
dtatatree_browser tested

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/uvmat.m

    r503 r507  
    207207guidata(hObject, handles);
    208208
     209%% add the path to uvmat (useful if uvmat has been opened in the working directory and a working directory change occured)
     210path_uvmat=fileparts(which('uvmat'));
     211
    209212%% set the position of colorbar and ancillary GUIs:
    210213set(hObject,'Units','Normalized')
     
    237240
    238241%% TRANSFORM menu: builtin fcts
    239 menu_str={'';'phys';'px';'phys_polar'};
    240 UvData.OpenParam.NbBuiltin=numel(menu_str); %number of functions
    241 path_uvmat=fileparts(which('uvmat'));
    242 addpath (path_uvmat) ; %add the path to UVMAT, (useful in case of change of working directory after civ has been s opened in the working directory)
    243 addpath(fullfile(path_uvmat,'transform_field'))%add the path to transform functions,
    244 fct_handle{1,1}=[];
    245 testexist=zeros(size(menu_str'));%default
    246 testexist(1)=1;
    247 for ilist=2:length(menu_str)
    248     if exist(menu_str{ilist},'file')
    249         fct_handle{ilist,1}=str2func(menu_str{ilist});
    250         testexist(ilist)=1;
    251     else
    252         testexist(ilist)=0;
    253     end
    254 end
    255 rmpath(fullfile(path_uvmat,'transform_field'))
    256 
    257 %% load the list of previously browsed files in menus Open and Open_1
     242transform_menu={'';'phys';'px';'phys_polar'};
     243UvData.OpenParam.NbBuiltin=numel(transform_menu); %number of functions
     244path_list=(num2cell(blanks(UvData.OpenParam.NbBuiltin)))';%initialize a cell array of nbvar blanks
     245transform_path=fullfile(path_uvmat,'transform_field');
     246path_list{1}='';
     247path_list(2:end)=regexprep(path_list(2:end),' ',transform_path); % set transform_path to the path_list
     248
     249%% load the list of previously browsed files in menus Open, Open_1 and transform_fct
    258250 dir_perso=prefdir; % path to the directory .matlab for personal data
    259251 profil_perso=fullfile(dir_perso,'uvmat_perso.mat');% personal data file uvmauvmat_perso.mat' in .matlab
    260252 if exist(profil_perso,'file')
    261       h=load (profil_perso);
    262       if isfield(h,'MenuFile')
    263           for ifile=1:min(length(h.MenuFile),5)
    264               eval(['set(handles.MenuFile_' num2str(ifile) ',''Label'',h.MenuFile{ifile});'])
    265                eval(['set(handles.MenuFile_' num2str(ifile) '_1,''Label'',h.MenuFile{ifile});'])
    266           end
    267       end
    268       if isfield(h,'transform_fct') && iscell(h.transform_fct)
     253     h=load (profil_perso);
     254     if isfield(h,'MenuFile')
     255         for ifile=1:min(length(h.MenuFile),5)
     256             eval(['set(handles.MenuFile_' num2str(ifile) ',''Label'',h.MenuFile{ifile});'])
     257             eval(['set(handles.MenuFile_' num2str(ifile) '_1,''Label'',h.MenuFile{ifile});'])
     258         end
     259     end
     260     if isfield(h,'transform_fct') && iscell(h.transform_fct)
    269261         for ilist=1:length(h.transform_fct);
    270262             if exist(h.transform_fct{ilist},'file')
    271                 [path,file]=fileparts(h.transform_fct{ilist});
    272                 addpath(path)
    273                 h_func=str2func(file);
    274                 rmpath(path)
    275                 testexist=[testexist 1];
    276              else
    277                 file='';
    278                 h_func=[];
    279                 testexist=[testexist 0];
     263                 [path,file]=fileparts(h.transform_fct{ilist});
     264                 transform_menu=[transform_menu; {file}];
     265                 path_list=[path_list; {path}];
    280266             end
    281              fct_handle=[fct_handle; {h_func}]; %concatene the list of paths
    282              menu_str=[menu_str; {file}];
    283267         end
    284       end
     268     end
    285269 end
    286 menu_str=menu_str(testexist==1);%=menu_str(testexist~=0)
    287 fct_handle=fct_handle(testexist==1);
    288 menu_str=[menu_str;{'more...'}];
    289 set(handles.transform_fct,'String',menu_str)
    290 set(handles.transform_fct,'UserData',fct_handle)% store the list of path in UserData of ACTION
     270transform_menu=[transform_menu;{'more...'}];
     271set(handles.transform_fct,'String',transform_menu)
     272set(handles.transform_fct,'UserData',path_list)% store the list of path in UserData of ACTION
     273set(handles.path_transform,'String','')
     274set(handles.path_transform,'UserData',[])
    291275
    292276%% case of an input argument for uvmat
     
    700684        set(hfig,'WindowButtonUpFcn','mouse_down')%set mouse click action function
    701685    case 'xml'                % edit xml files
    702         if ~isempty(regexp(fileinput,'.project.xml$'))
     686        t=xmltree(fileinput);
     687        if strcmp(get(t,1,'name'),'Project')&& exist(regexprep(fileinput,'.xml$',''),'dir')
    703688            datatree_browser(fileinput)
    704689        else
     
    19771962end
    19781963
    1979 %% read the first input field if a filename has been introduced
     1964%% read the first input field
    19801965ParamIn.ColorVar='';%default variable name for vector color
    19811966frame_index=1;%default
    1982 if ~isempty(FileName)
    1983     FieldName='';%default
    1984     VelType='';%default
     1967% if ~isempty(FileName)
     1968FieldName='';%default
     1969VelType='';%default
    19851970%     FileType=UvData.FileType{1};
    1986     switch UvData.FileType{1}
    1987         case {'civx','civdata','netcdf'};
    1988             list_fields=get(handles.Fields,'String');% list menu fields
    1989   %          index_fields=get(handles.Fields,'Value');% selected string index
    1990             FieldName= list_fields{get(handles.Fields,'Value')}; % selected field
    1991             if ~strcmp(FieldName,'get_field...')
    1992                 if get(handles.FixVelType,'Value')
    1993                     VelTypeList=get(handles.VelType,'String');
    1994                     VelType=VelTypeList{get(handles.VelType,'Value')};
    1995                 end
     1971switch UvData.FileType{1}
     1972    case {'civx','civdata','netcdf'};
     1973        list_fields=get(handles.Fields,'String');% list menu fields
     1974%          index_fields=get(handles.Fields,'Value');% selected string index
     1975        FieldName= list_fields{get(handles.Fields,'Value')}; % selected field
     1976        if ~strcmp(FieldName,'get_field...')
     1977            if get(handles.FixVelType,'Value')
     1978                VelTypeList=get(handles.VelType,'String');
     1979                VelType=VelTypeList{get(handles.VelType,'Value')};
    19961980            end
    1997             if strcmp(FieldName,'velocity')
    1998                 list_code=get(handles.ColorCode,'String');% list menu fields
    1999                 index_code=get(handles.ColorCode,'Value');% selected string index
    2000                 if  ~strcmp(list_code{index_code},'black') &&  ~strcmp(list_code{index_code},'white')
    2001                     list_code=get(handles.ColorScalar,'String');% list menu fields
    2002                     index_code=get(handles.ColorScalar,'Value');% selected string index
    2003                     ParamIn.ColorVar= list_code{index_code}; % selected field
    2004                 end
     1981        end
     1982        if strcmp(FieldName,'velocity')
     1983            list_code=get(handles.ColorCode,'String');% list menu fields
     1984            index_code=get(handles.ColorCode,'Value');% selected string index
     1985            if  ~strcmp(list_code{index_code},'black') &&  ~strcmp(list_code{index_code},'white')
     1986                list_code=get(handles.ColorScalar,'String');% list menu fields
     1987                index_code=get(handles.ColorScalar,'Value');% selected string index
     1988                ParamIn.ColorVar= list_code{index_code}; % selected field
    20051989            end
    2006         case {'video','mmreader'}
    2007             ParamIn=UvData.MovieObject{1};     
    2008             if ~strcmp(NomType,'*')
    2009                 frame_index=num_j1;%frame index for movies or multimage
    2010             else
    2011                 frame_index=num_i1;
    2012             end
    2013         case 'multimage'
    2014             if ~strcmp(NomType,'*')
    2015                 frame_index=num_j1;%frame index for movies or multimage
    2016             else
    2017                 frame_index=num_i1;
    2018             end
    2019         case 'vol' %TODO: update
    2020             if isfield(UvData.XmlData,'Npy') && isfield(UvData.XmlData,'Npx')
    2021                 ParamIn.Npy=UvData.XmlData.Npy;
    2022                 ParamIn.Npx=UvData.XmlData.Npx;
    2023             else           
    2024                 errormsg='Npx and Npy need to be defined in the xml file for volume images .vol';
    2025                 return
    2026             end
    2027     end
    2028     if isstruct (ParamIn)
    2029     ParamIn.FieldName=FieldName;
    2030     ParamIn.VelType=VelType;
    2031     ParamIn.GUIName='get_field';
    2032     end
    2033     [Field{1},ParamOut,errormsg] = read_field(FileName,UvData.FileType{1},ParamIn,frame_index);
    2034     if ~isempty(errormsg)
    2035         errormsg=['error in reading ' FileName ': ' errormsg];
    2036         return
    2037     end 
    2038     if isfield(ParamOut,'Npx')&& isfield(ParamOut,'Npy')
    2039         set(handles.num_Npx,'String',num2str(ParamOut.Npx));% display image size on the interface
    2040         set(handles.num_Npy,'String',num2str(ParamOut.Npy));
    2041     end
    2042     if isfield(ParamOut,'TimeIndex')% case of time obtained from get_field
    2043         set(handles.i1,'String',num2str(ParamOut.TimeIndex))
    2044     end
    2045     if isfield(ParamOut,'TimeValue')
    2046         Field{1}.Time=ParamOut.TimeValue;% case of time obtained from get_field
    2047     end
    2048 end
     1990        end
     1991    case {'video','mmreader'}
     1992        ParamIn=UvData.MovieObject{1};     
     1993        if ~strcmp(NomType,'*')
     1994            frame_index=num_j1;%frame index for movies or multimage
     1995        else
     1996            frame_index=num_i1;
     1997        end
     1998    case 'multimage'
     1999        if ~strcmp(NomType,'*')
     2000            frame_index=num_j1;%frame index for movies or multimage
     2001        else
     2002            frame_index=num_i1;
     2003        end
     2004    case 'vol' %TODO: update
     2005        if isfield(UvData.XmlData,'Npy') && isfield(UvData.XmlData,'Npx')
     2006            ParamIn.Npy=UvData.XmlData.Npy;
     2007            ParamIn.Npx=UvData.XmlData.Npx;
     2008        else           
     2009            errormsg='Npx and Npy need to be defined in the xml file for volume images .vol';
     2010            return
     2011        end
     2012end
     2013if isstruct (ParamIn)
     2014ParamIn.FieldName=FieldName;
     2015ParamIn.VelType=VelType;
     2016ParamIn.GUIName='get_field';
     2017end
     2018[Field{1},ParamOut,errormsg] = read_field(FileName,UvData.FileType{1},ParamIn,frame_index);
     2019if ~isempty(errormsg)
     2020    errormsg=['error in reading ' FileName ': ' errormsg];
     2021    return
     2022end 
     2023if isfield(ParamOut,'Npx')&& isfield(ParamOut,'Npy')
     2024    set(handles.num_Npx,'String',num2str(ParamOut.Npx));% display image size on the interface
     2025    set(handles.num_Npy,'String',num2str(ParamOut.Npy));
     2026end
     2027if isfield(ParamOut,'TimeIndex')% case of time obtained from get_field
     2028    set(handles.i1,'String',num2str(ParamOut.TimeIndex))
     2029end
     2030if isfield(ParamOut,'TimeValue')
     2031    Field{1}.Time=ParamOut.TimeValue;% case of time obtained from get_field
     2032end
     2033Field{1}.ZIndex=z_index; %used for multiplane 3D calibration
     2034% end
    20492035
    20502036%% choose and read a second field FileName_1 if defined
     
    21272113        end
    21282114    end
     2115    Field{2}.ZIndex=z_index;%used for multi-plane 3D calibration
    21292116end
    21302117
     
    23132300
    23142301%% apply coordinate transform or other user fct
    2315 XmlData=[];%default
    2316 XmlData_1=[];%default
    2317 if isfield(UvData,'XmlData')%use geometry calib recorded from the ImaDoc xml file as first priority
    2318     XmlData=UvData.XmlData{1};
    2319     if numel(UvData.XmlData)==2
    2320         XmlData_1=UvData.XmlData{2};
    2321     end
    2322 end
    2323 choice_value=get(handles.transform_fct,'Value');
    2324 transform_list=get(handles.transform_fct,'UserData');
    2325 transform=transform_list{choice_value};%selected function handles
    2326 % z index
    2327 if ~isempty(FileName)
    2328     Field{1}.ZIndex=z_index;
    2329 end
     2302transform=get(handles.path_transform,'UserData');
    23302303if ~isempty(transform)
    2331     if length(Field)>=2
    2332         Field{2}.ZIndex=z_index;
    2333         [Field{1},Field{2}]=transform(Field{1},XmlData,Field{2},XmlData_1);
    2334         if isempty(Field{2})
     2304    XmlData=[];%default
     2305    XmlData_1=[];%default
     2306    if isfield(UvData,'XmlData')%use geometry calib recorded from the ImaDoc xml file as first priority
     2307        XmlData=UvData.XmlData{1};
     2308        if numel(UvData.XmlData)==2
     2309            XmlData_1=UvData.XmlData{2};
     2310        end
     2311    end
     2312    transform=get(handles.path_transform,'UserData');
     2313    nbre_arg=nargin(transform);
     2314    if length(Field)==2
     2315        if nbre_arg==4
     2316            [Field{1},Field{2}]=transform(Field{1},XmlData,Field{2},XmlData_1);
     2317        else
     2318            Field{1}=transform(Field{1},XmlData);
    23352319            Field(2)=[];
    23362320        end
    23372321    else
    2338         Field{1}=transform(Field{1},XmlData);
    2339     end
    2340 end   
     2322        if nbre_arg==1
     2323            Field{1}=transform(Field{1});%transform which does not need input parameter
     2324        else
     2325            Field{1}=transform(Field{1},XmlData);
     2326        end
     2327    end
     2328end
    23412329    %% check whether tps is needed, then calculate tps coefficients if needed
    23422330check_proj_tps=0;
     
    31003088    set(hhget_field.list_fig,'Value',1)
    31013089    set(hhget_field.list_fig,'String',{'uvmat'})
    3102     set(handles.transform_fct,'Value',1)% no transform by default
    3103     set(handles.path_transform,'String','')
     3090  %  set(handles.transform_fct,'Value',1)% no transform by default
     3091  %  set(handles.path_transform,'String','')
    31043092    return %no action
    31053093end
     
    32153203        set(hhget_field.list_fig,'Value',1)
    32163204        set(hhget_field.list_fig,'String',{'uvmat'})
    3217         set(handles.transform_fct,'Value',1)% no transform by default
    3218         set(handles.path_transform,'String','')
     3205%         set(handles.transform_fct,'Value',1)% no transform by default
     3206%         set(handles.path_transform,'String','')
    32193207        if check_new
    32203208            UvData.FileType{2}=UvData.FileType{1};
     
    35623550UvData=get(handles.uvmat,'UserData');
    35633551menu=get(handles.transform_fct,'String');
    3564 ind_coord=get(handles.transform_fct,'Value');
    3565 coord_option=menu{ind_coord};
    3566 list_transform=get(handles.transform_fct,'UserData');
    3567 ff=functions(list_transform{end}); 
    3568 if isequal(coord_option,'more...');
    3569     coord_fct='';
    3570     prompt = {'Enter the name of the transform function'};
    3571     dlg_title = 'user defined transform';
    3572     num_lines= 1;
     3552ichoice=get(handles.transform_fct,'Value');%item number in the menu
     3553transform_name=menu{ichoice};% choice of the transform fct
     3554list_path=get(handles.transform_fct,'UserData');
     3555
     3556%% add a new item to the menu if the option 'more...' has been selected
     3557if strcmp(transform_name,'more...');
    35733558    [FileName, PathName] = uigetfile( ...
    3574        {'*.m', ' (*.m)';
     3559        {'*.m', ' (*.m)';
    35753560        '*.m',  '.m files '; ...
    35763561        '*.*', 'All Files (*.*)'}, ...
    3577         'Pick a file', ff.file);
    3578     if isequal(PathName(end),'/')||isequal(PathName(end),'\')
    3579         PathName(end)=[];
    3580     end
    3581     transform_selected =fullfile(PathName,FileName);
    3582     if ~exist(transform_selected,'file')
    3583            return
    3584     end
    3585    [ppp,transform,ext_fct]=fileparts(FileName);% removes extension .m
    3586    if ~isequal(ext_fct,'.m')
     3562        'Pick the transform function', get(handles.path_transform,'String'));
     3563    path_transform_fct =fullfile(PathName,FileName);
     3564    if ~exist(path_transform_fct,'file')% cancel has been activated
     3565        return
     3566    end
     3567    if isempty(regexp(FileName,'.m$'))% detect file extension .m
    35873568        msgbox_uvmat('ERROR','a Matlab function .m must be introduced');
    35883569        return
    3589    end
    3590    menu=update_menu(handles.transform_fct,transform);%add the selected fct to the menu
    3591    ind_coord=get(handles.transform_fct,'Value');
    3592    addpath(PathName)
    3593    list_transform{ind_coord}=str2func(transform);% create the function handle corresponding to the newly seleced function
    3594    set(handles.transform_fct,'UserData',list_transform)
    3595    rmpath(PathName)
    3596    % save the new menu in the personal file 'uvmat_perso.mat'
    3597    dir_perso=prefdir;%personal Matalb directory
    3598    profil_perso=fullfile(dir_perso,'uvmat_perso.mat');
    3599    if exist(profil_perso,'file')
    3600        nb_builtin=UvData.OpenParam.NbBuiltin;
    3601        for ilist=nb_builtin+1:numel(list_transform)
    3602            ff=functions(list_transform{ilist});
    3603            transform_fct{ilist-nb_builtin}=ff.file;
    3604        end
     3570    else
     3571        transform_name=regexprep(FileName,'.m','');
     3572    end
     3573    ichoice=find(strcmp(transform_name,menu),1);%look for the selected fct in the existing menu
     3574    if isempty(ichoice)% if the item is not found, add it to the menu (before 'more...' and select it)
     3575        menu=[menu(1:end-1);{transform_name};{'more...'}];
     3576        ichoice=numel(menu)-1;   
     3577    end
     3578    list_path{ichoice}=PathName;%update the list fo fct paths
     3579   
     3580    % save the new menu in the personal file 'uvmat_perso.mat'
     3581    dir_perso=prefdir;%personal Matalb directory
     3582    profil_perso=fullfile(dir_perso,'uvmat_perso.mat');
     3583    if exist(profil_perso,'file')
     3584        nb_builtin=UvData.OpenParam.NbBuiltin;% number of 'builtin' (basic) transform fcts in uvmat
     3585        for ilist=nb_builtin+1:numel(list_path)
     3586            transform_fct{ilist-nb_builtin}=fullfile(list_path{ilist},menu{ilist});
     3587        end
    36053588        save (profil_perso,'transform_fct','-append'); %store the root name for future opening of uvmat
    3606    end   
    3607 end
    3608 
    3609 %% check the current path to the selected function
    3610 if isa(list_transform{ind_coord},'function_handle')
    3611     func=functions(list_transform{ind_coord});
    3612     set(handles.path_transform,'String',fileparts(func.file)); %show the path to the senlected function
    3613 else
    3614     set(handles.path_transform,'String','')
     3589    end
     3590end
     3591
     3592%% create the function handle of the selected fct
     3593if isempty(list_path{ichoice})% case of no selected fct
     3594    transform_handle=[];
     3595else
     3596    if ~exist(list_path{ichoice},'dir')
     3597        msgbox_uvmat('ERROR','invalid fct path: select the transform fct again with the option more...')
     3598        return
     3599    end
     3600    current_dir=pwd;%current working dir
     3601    cd(list_path{ichoice})
     3602    transform_handle=str2func(transform_name);
     3603    cd(current_dir)
     3604end
     3605set(handles.path_transform,'UserData',transform_handle)
     3606
     3607%% update the ToolTip string of the menu transform_fct with the first line of the selected fct file
     3608if isempty(list_path{ichoice})% case of no selected fct
     3609    set(handles.transform_fct,'ToolTipString','transform_fct:choose a transform function')
     3610else
     3611    try
     3612        [fid,errormsg] =fopen([fullfile(list_path{ichoice},transform_name) '.m']);
     3613        InputText=textscan(fid,'%s',1,'delimiter','\n');
     3614        fclose(fid)
     3615        set(handles.transform_fct,'ToolTipString',['transform_fct: ' InputText{1}{1}])% put the first line of the selected function as tooltip help
     3616    end
     3617end
     3618
     3619%% adapt the GUI to the input/output conditions of the selected transform fct
     3620if isempty(list_path{ichoice})% case of no selected fct
     3621    DataOut=[];
     3622else
     3623    if nargin(transform_handle)>1
     3624        if isfield(UvData,'XmlData')&&~isempty(UvData.XmlData)
     3625            XmlData=UvData.XmlData{1};
     3626            DataOut=feval(transform_handle,'*',XmlData);
     3627        end
     3628    end
    36153629end
    36163630
    36173631set(handles.CheckFixLimits,'Value',0)
    36183632set(handles.CheckFixLimits,'BackgroundColor',[0.7 0.7 0.7])
     3633
     3634%% execute the function to set input an output conditions
     3635
    36193636
    36203637%% delete drawn objects
     
    48564873end
    48574874
     4875
     4876% --------------------------------------------------------------------
     4877function MenuSetProject_Callback(hObject, eventdata, handles)
     4878RootPath=get(handles.RootPath,'String');
     4879ProjectDir = uigetdir(fileparts(fileparts(RootPath)), 'select the project source directory');
     4880datatree_browser(ProjectDir)
Note: See TracChangeset for help on using the changeset viewer.