Changeset 39 for trunk/src/uvmat.m


Ignore:
Timestamp:
Mar 9, 2010, 5:46:24 PM (14 years ago)
Author:
sommeria
Message:

civ: bug corrected for civ in batch
series and uvmat: further improvement and debugging for the menu of field transforms

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/uvmat.m

    r38 r39  
    195195%-------------------------------------------------------------------
    196196%WARNING: avoid the second input parameter, leads to erros
    197 global dircur dir_opening
     197global dircur dir_opening nb_builtin
    198198% Choose default command menuline output for uvmat
    199199handles.output = hObject;
     
    221221set(hObject,'WindowButtonDownFcn',{'mouse_down'})%set mouse click action function
    222222set(hObject,'WindowButtonUpFcn',{'mouse_up',handles})
    223 %set(hObject,'ResizeFcn',{@resize_uvmat})
     223
     224%TRANSFORM menu: loads the information stored in prefdir to initiate the browser and the list of functions
     225menu_str={'';'phys';'px';'phys_polar'};
     226nb_builtin=numel(menu_str); %number of functions
     227[path_uvmat,name,ext]=fileparts(which('uvmat'));
     228addpath(fullfile(path_uvmat,'transform_field'))
     229fct_handle{1,1}=[];
     230testexist(1)=1;
     231for ilist=2:length(menu_str)
     232    if exist(menu_str{ilist},'file')
     233        fct_handle{ilist,1}=str2func(menu_str{ilist});
     234        testexist(ilist)=1;
     235    else
     236        testexist(ilist)=0;
     237    end
     238%     fct_handle{ilist,1}=fullfile(path_uvmat,'transform_field');%path to  the transform functions path_transform;
     239end
     240rmpath(fullfile(path_uvmat,'transform_field'))
    224241
    225242%load the list of previously browsed files in menus Open and Open_1
     
    247264          set(handles.MenuFile_5,'Label',h.MenuFile_5);
    248265          set(handles.MenuFile_5_1,'Label',h.MenuFile_5);
    249      end
     266      end
     267      if isfield(h,'transform_fct') && iscell(h.transform_fct)
     268         for ilist=1:length(h.transform_fct);
     269             [path,file]=fileparts(h.transform_fct{ilist});
     270             addpath(path)
     271             if exist(file,'file')
     272                h_func=str2func(file);
     273                testexist=[testexist 1];
     274             else
     275                h_func=[];
     276                testexist=[testexist 0];
     277             end
     278             fct_handle=[fct_handle; {h_func}];%concatene the list of paths
     279             rmpath(path)
     280             menu_str=[menu_str; {file}];
     281         end
     282      end
    250283 end
     284menu_str=menu_str(find(testexist));
     285fct_handle=fct_handle(find(testexist));
     286menu_str=[menu_str;{'more...'}];
     287set(handles.transform_fct,'String',menu_str)
     288set(handles.transform_fct,'UserData',fct_handle)% store the list of path in UserData of ACTION
    251289 
    252290%initiates menu of vector colors
     
    259297[errormsg,date_str]=check_functions;%check the path of the functions called by uvmat.m
    260298
    261 %check the path of menu_coord transform
    262 %set(handles.menu_coord,'String',{'';'phys';'px';'more...'})
     299%check the path of transform_fct transform
     300%set(handles.transform_fct,'String',{'';'phys';'px';'more...'})
    263301% path_fct{1}='';
    264302% path_fct{2}=fileparts(path_to_uvmat);
    265303% path_fct{3}=fileparts(path_to_uvmat);
    266304% path_fct{4}=fileparts(path_to_uvmat);
    267 % set(handles.menu_coord,'UserData',path_fct)
     305% set(handles.transform_fct,'UserData',path_fct)
    268306
    269307%case of an input argument for uvmat
     
    303341    if ~isempty(Field)
    304342        set(handles.Fields,'Value',1)
    305         set(handles.Fields,'String',{'get_field...'})
    306 %         set(handles.Fields,'Value',2)% option 'get_field...'     
     343        set(handles.Fields,'String',{'get_field...'})   
    307344        set(handles.Fields,'UserData',Field)
    308345        testinputfield=1;
     
    344381    end
    345382end
    346 
    347 %TRANSFORM menu: loads the information stored in prefdir to initiate the browser and the list of functions
    348 menu_str={'';'phys';'px';'phys_polar'};
    349 nb_builtin=numel(menu_str); %number of functions
    350 [path_uvmat,name,ext]=fileparts(which('uvmat'));
    351 addpath(fullfile(path_uvmat,'transform_field'))
    352 fct_handle{1,1}=[];
    353 testexist(1)=1;
    354 for ilist=2:length(menu_str)
    355     if exist(menu_str{ilist},'file')
    356         fct_handle{ilist,1}=str2func(menu_str{ilist});
    357         testexist(ilist)=1;
    358     else
    359         testexist(ilist)=0;
    360     end
    361 %     fct_handle{ilist,1}=fullfile(path_uvmat,'transform_field');%path to  the transform functions path_transform;
    362 end
    363 rmpath(fullfile(path_uvmat,'transform_field'))
    364 % read the list of functions stored in the personal file 'uvmat_perso.mat' in prefdir
    365 dir_perso=prefdir;
    366 profil_perso=fullfile(dir_perso,'uvmat_perso.mat');
    367 if exist(profil_perso,'file')
    368     h=load (profil_perso);
    369     if isfield(h,'transform_fct') && iscell(h.transform_fct)
    370          for ilist=1:length(h.transform_fct)
    371              [path,file]=fileparts(h.transform{ilist});
    372              addpath(path)
    373              if exist(file,'file')
    374                 h_func=str2func(path);
    375                 testexist=[testexist 1];
    376              else
    377                 h_func=[];
    378                 testexist=[testexist 0];
    379              end
    380              fct_handle=[fct_handle; {h_func}];%concatene the list of paths
    381              rmpath(path)
    382             % fct_path=[fct_path; {path}];%concatene the list of paths
    383              menu_str=[menu_str; {file}];
    384          end
    385     end
    386 end
    387 menu_str=menu_str(find(testexist));
    388 fct_handle=fct_handle(find(testexist));
    389 menu_str=[menu_str;{'more...'}];
    390 set(handles.menu_coord,'String',menu_str)
    391 set(handles.menu_coord,'UserData',fct_handle)% store the list of path in UserData of ACTION
    392383
    393384set_vec_col_bar(handles)
     
    790781        set(handles.pxcm,'String','')
    791782        set(handles.pycm,'String','')
    792         set(handles.menu_coord,'Value',1); %  no transform by default
     783        set(handles.transform_fct,'Value',1); %  no transform by default
    793784    else
    794785        if (isfield(GeometryCalib,'R')& ~isequal(GeometryCalib.R(2,1),0) & ~isequal(GeometryCalib.R(1,2),0)) |...
     
    802793            set(handles.pycm,'String',num2str(pixcmy))
    803794        end
    804         set(handles.menu_coord,'Value',2); % phys transform by default
     795        set(handles.transform_fct,'Value',2); % phys transform by default
    805796        if isfield(GeometryCalib,'SliceCoord')
    806797           siz=size(GeometryCalib.SliceCoord);
     
    15161507        end
    15171508        %px to phys or other transform on field
    1518          menu_transform=get(handles.menu_coord,'String');
    1519         choice_value=get(handles.menu_coord,'Value');
    1520         transform_name=menu_transform{choice_value};%name of the transform fct  given by the menu 'menu_coord'
    1521         transform_list=get(handles.menu_coord,'UserData');
     1509         menu_transform=get(handles.transform_fct,'String');
     1510        choice_value=get(handles.transform_fct,'Value');
     1511        transform_name=menu_transform{choice_value};%name of the transform fct  given by the menu 'transform_fct'
     1512        transform_list=get(handles.transform_fct,'UserData');
    15221513        transform=transform_list{choice_value};
    15231514        if  ~isequal(transform_name,'') && ~isequal(transform_name,'px')
     
    17501741
    17511742%px to phys or other transform on field
    1752 menu_transform=get(handles.menu_coord,'String');
    1753 choice_value=get(handles.menu_coord,'Value');
    1754 transform_name=menu_transform{choice_value};%name of the transform fct  given by the menu 'menu_coord'
    1755 transform_list=get(handles.menu_coord,'UserData');
     1743menu_transform=get(handles.transform_fct,'String');
     1744choice_value=get(handles.transform_fct,'Value');
     1745transform_name=menu_transform{choice_value};%name of the transform fct  given by the menu 'transform_fct'
     1746transform_list=get(handles.transform_fct,'UserData');
    17561747transform=transform_list{choice_value};
    17571748if  ~isequal(transform_name,'') && ~isequal(transform_name,'px')
     
    20342025            [Field{2},var_detect]=nc2struct(filename_1,SubField.ListVarName); %read the corresponding input data               
    20352026            Field{2}.VarAttribute=SubField.VarAttribute;
    2036 %             if isequal(get(hhget_field.menu_coord,'Visible'),'on')
    2037 %                 list_transform=get(hhget_field.menu_coord,'String');
    2038 %                 val_list=get(hhget_field.menu_coord,'Value');
     2027%             if isequal(get(hhget_field.transform_fct,'Visible'),'on')
     2028%                 list_transform=get(hhget_field.transform_fct,'String');
     2029%                 val_list=get(hhget_field.transform_fct,'Value');
    20392030%                 transf=list_transform{val_list};
    20402031%                 if ~isempty(transf)
     
    21712162   XmlData_1=UvData.XmlData_1;
    21722163end
    2173 menu_transform=get(handles.menu_coord,'String');
    2174 choice_value=get(handles.menu_coord,'Value');
    2175 %transform=menu_transform{choice_value};%name of the transform fct  given by the menu 'menu_coord'
    2176 transform_list=get(handles.menu_coord,'UserData')
    2177 transform=transform_list{choice_value}%selected function handles
     2164menu_transform=get(handles.transform_fct,'String');
     2165choice_value=get(handles.transform_fct,'Value');
     2166%transform=menu_transform{choice_value};%name of the transform fct  given by the menu 'transform_fct'
     2167transform_list=get(handles.transform_fct,'UserData');
     2168transform=transform_list{choice_value};%selected function handles
    21782169
    21792170% z index
     
    21902181        end
    21912182    else
    2192         'TESTrun'
    21932183        Field{1}=transform(Field{1},XmlData);
    2194          Field{1}
    21952184    end
    21962185end
     
    40033992
    40043993%-------------------------------------------------------------
    4005 % --- Executes on selection change in menu_coord.
    4006 function menu_coord_Callback(hObject, eventdata, handles)
     3994% --- Executes on selection change in transform_fct.
     3995function transform_fct_Callback(hObject, eventdata, handles)
    40073996%-------------------------------------------------------------
    4008 huvmat=get(handles.menu_coord,'parent');
    4009 menu=get(handles.menu_coord,'String');
    4010 ind_coord=get(handles.menu_coord,'Value');
     3997global nb_builtin
     3998
     3999huvmat=get(handles.transform_fct,'parent');
     4000menu=get(handles.transform_fct,'String');
     4001ind_coord=get(handles.transform_fct,'Value');
    40114002coord_option=menu{ind_coord};
    4012 list_transform=get(handles.menu_coord,'UserData');
    4013    
     4003list_transform=get(handles.transform_fct,'UserData');
     4004ff=functions(list_transform{end}) 
    40144005if isequal(coord_option,'more...');
    40154006    coord_fct='';
    4016     dir_perso=prefdir;
    4017     profil_perso=fullfile(dir_perso,'uvmat_perso.mat');
    4018     if exist(profil_perso,'file')
    4019           h=load (profil_perso);
    4020          if isfield(h,'coord_fct')
    4021                 coord_fct=h.coord_fct;
    4022          end
    4023     end
     4007
     4008%     if exist(profil_perso,'file')
     4009%           h=load (profil_perso);
     4010%          if isfield(h,'transform_fct')
     4011%                 transform_fct=h.transform_fct;
     4012%          end
     4013%     end
    40244014    prompt = {'Enter the name of the transform function'};
    40254015    dlg_title = 'user defined transform';
     
    40294019        '*.m',  '.m files '; ...
    40304020        '*.*', 'All Files (*.*)'}, ...
    4031         'Pick a file', coord_fct);
     4021        'Pick a file', ff.file);
    40324022    if isequal(PathName(end),'/')||isequal(PathName(end),'\')
    40334023        PathName(end)=[];
    40344024    end
    4035     coord_fct=fullfile(PathName,FileName);
    4036     if ~exist(coord_fct,'file')
    4037            msgbox_uvmat('ERROR',['image procesing fct ' coord_fct ' not found'])
    4038     else
    4039        [ppp,transform]=fileparts(FileName);% removes extension .m
    4040        menu=update_menu(handles.menu_coord,transform);%add the selected fct to the menu
    4041        ind_coord=get(handles.menu_coord,'Value');
    4042        addpath(PathName)
    4043        list_transform{ind_coord}=str2func(transform);% create the function handle corresponding to the newly seleced function
    4044        set(handles.menu_coord,'UserData',list_transform)
    4045        rmpath(PathName)
    4046        if exist(profil_perso,'file')
    4047             save (profil_perso,'coord_fct','-append'); %store the root name for future opening of uvmat
    4048         end
    4049     end   
     4025    transform_selected =fullfile(PathName,FileName);
     4026    if ~exist(transform_selected,'file')
     4027%            msgbox_uvmat('ERROR',['procesing fct ' transform_selected ' not found'])
     4028           return
     4029    end
     4030   [ppp,transform,ext_fct]=fileparts(FileName);% removes extension .m
     4031   if ~isequal(ext_fct,'.m')
     4032        msgbox_uvmat('ERROR','a Matlab function .m must be introduced');
     4033        return
     4034   end
     4035   menu=update_menu(handles.transform_fct,transform);%add the selected fct to the menu
     4036   ind_coord=get(handles.transform_fct,'Value');
     4037   addpath(PathName)
     4038   list_transform{ind_coord}=str2func(transform);% create the function handle corresponding to the newly seleced function
     4039   set(handles.transform_fct,'UserData',list_transform)
     4040   rmpath(PathName)
     4041   % save the new menu in the personal file 'uvmat_perso.mat'
     4042   dir_perso=prefdir;%personal Matalb directory
     4043   profil_perso=fullfile(dir_perso,'uvmat_perso.mat');
     4044   if exist(profil_perso,'file')
     4045       for ilist=nb_builtin+1:numel(list_transform)
     4046           ff=functions(list_transform{ilist});
     4047           transform_fct{ilist-nb_builtin}=ff.file;
     4048       end
     4049        save (profil_perso,'transform_fct','-append'); %store the root name for future opening of uvmat
     4050   end   
    40504051end
    40514052
    40524053%check the current path to the selected function
    4053 func=functions(list_transform{ind_coord})
     4054func=functions(list_transform{ind_coord});
    40544055set(handles.path_transform,'String',fileparts(func.file)); %show the path to the senlected function
    40554056%CurrentPath=fileparts(which(coord_option));
     
    48084809param.filter1=get(handles.filter1,'Value');
    48094810param.filter2=get(handles.filter2,'Value');
    4810 param.menu_coord_str=get(handles.menu_coord,'String');
    4811 param.menu_coord_val=get(handles.menu_coord,'Value');
     4811param.menu_coord_str=get(handles.transform_fct,'String');
     4812param.menu_coord_val=get(handles.transform_fct,'Value');
    48124813
    48134814series(param); %run the series interface
     
    48624863%--------------------------------------------------------------------------
    48634864function enable_transform(handles,state)
    4864 set(handles.menu_coord,'Visible',state)
     4865set(handles.transform_fct,'Visible',state)
    48654866set(handles.TRANSFORM_txt,'Visible',state)   
    4866 set(handles.menu_coord,'Visible',state) 
     4867set(handles.transform_fct,'Visible',state) 
    48674868set(handles.path_transform,'Visible',state)
    48684869set(handles.pxcmx_txt,'Visible',state)
Note: See TracChangeset for help on using the changeset viewer.