Changeset 507 for trunk/src/uvmat.m
- Timestamp:
- Jul 29, 2012, 11:18:31 PM (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/uvmat.m
r503 r507 207 207 guidata(hObject, handles); 208 208 209 %% add the path to uvmat (useful if uvmat has been opened in the working directory and a working directory change occured) 210 path_uvmat=fileparts(which('uvmat')); 211 209 212 %% set the position of colorbar and ancillary GUIs: 210 213 set(hObject,'Units','Normalized') … … 237 240 238 241 %% 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 242 transform_menu={'';'phys';'px';'phys_polar'}; 243 UvData.OpenParam.NbBuiltin=numel(transform_menu); %number of functions 244 path_list=(num2cell(blanks(UvData.OpenParam.NbBuiltin)))';%initialize a cell array of nbvar blanks 245 transform_path=fullfile(path_uvmat,'transform_field'); 246 path_list{1}=''; 247 path_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 258 250 dir_perso=prefdir; % path to the directory .matlab for personal data 259 251 profil_perso=fullfile(dir_perso,'uvmat_perso.mat');% personal data file uvmauvmat_perso.mat' in .matlab 260 252 if exist(profil_perso,'file') 261 262 263 264 265 266 267 268 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) 269 261 for ilist=1:length(h.transform_fct); 270 262 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}]; 280 266 end 281 fct_handle=[fct_handle; {h_func}]; %concatene the list of paths282 menu_str=[menu_str; {file}];283 267 end 284 268 end 285 269 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 ACTION270 transform_menu=[transform_menu;{'more...'}]; 271 set(handles.transform_fct,'String',transform_menu) 272 set(handles.transform_fct,'UserData',path_list)% store the list of path in UserData of ACTION 273 set(handles.path_transform,'String','') 274 set(handles.path_transform,'UserData',[]) 291 275 292 276 %% case of an input argument for uvmat … … 700 684 set(hfig,'WindowButtonUpFcn','mouse_down')%set mouse click action function 701 685 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') 703 688 datatree_browser(fileinput) 704 689 else … … 1977 1962 end 1978 1963 1979 %% read the first input field if a filename has been introduced1964 %% read the first input field 1980 1965 ParamIn.ColorVar='';%default variable name for vector color 1981 1966 frame_index=1;%default 1982 if ~isempty(FileName)1983 1984 1967 % if ~isempty(FileName) 1968 FieldName='';%default 1969 VelType='';%default 1985 1970 % 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 1971 switch 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')}; 1996 1980 end 1997 if strcmp(FieldName,'velocity')1998 list_code=get(handles.ColorCode,'String');% list menu fields1999 index_code=get(handles.ColorCode,'Value');% selected string index2000 if ~strcmp(list_code{index_code},'black') && ~strcmp(list_code{index_code},'white')2001 list_code=get(handles.ColorScalar,'String');% list menu fields2002 index_code=get(handles.ColorScalar,'Value');% selected string index2003 ParamIn.ColorVar= list_code{index_code}; % selected field2004 end1981 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 2005 1989 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 2012 end 2013 if isstruct (ParamIn) 2014 ParamIn.FieldName=FieldName; 2015 ParamIn.VelType=VelType; 2016 ParamIn.GUIName='get_field'; 2017 end 2018 [Field{1},ParamOut,errormsg] = read_field(FileName,UvData.FileType{1},ParamIn,frame_index); 2019 if ~isempty(errormsg) 2020 errormsg=['error in reading ' FileName ': ' errormsg]; 2021 return 2022 end 2023 if 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)); 2026 end 2027 if isfield(ParamOut,'TimeIndex')% case of time obtained from get_field 2028 set(handles.i1,'String',num2str(ParamOut.TimeIndex)) 2029 end 2030 if isfield(ParamOut,'TimeValue') 2031 Field{1}.Time=ParamOut.TimeValue;% case of time obtained from get_field 2032 end 2033 Field{1}.ZIndex=z_index; %used for multiplane 3D calibration 2034 % end 2049 2035 2050 2036 %% choose and read a second field FileName_1 if defined … … 2127 2113 end 2128 2114 end 2115 Field{2}.ZIndex=z_index;%used for multi-plane 3D calibration 2129 2116 end 2130 2117 … … 2313 2300 2314 2301 %% 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 2302 transform=get(handles.path_transform,'UserData'); 2330 2303 if ~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); 2335 2319 Field(2)=[]; 2336 2320 end 2337 2321 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 2328 end 2341 2329 %% check whether tps is needed, then calculate tps coefficients if needed 2342 2330 check_proj_tps=0; … … 3100 3088 set(hhget_field.list_fig,'Value',1) 3101 3089 set(hhget_field.list_fig,'String',{'uvmat'}) 3102 set(handles.transform_fct,'Value',1)% no transform by default3103 set(handles.path_transform,'String','')3090 % set(handles.transform_fct,'Value',1)% no transform by default 3091 % set(handles.path_transform,'String','') 3104 3092 return %no action 3105 3093 end … … 3215 3203 set(hhget_field.list_fig,'Value',1) 3216 3204 set(hhget_field.list_fig,'String',{'uvmat'}) 3217 set(handles.transform_fct,'Value',1)% no transform by default3218 set(handles.path_transform,'String','')3205 % set(handles.transform_fct,'Value',1)% no transform by default 3206 % set(handles.path_transform,'String','') 3219 3207 if check_new 3220 3208 UvData.FileType{2}=UvData.FileType{1}; … … 3562 3550 UvData=get(handles.uvmat,'UserData'); 3563 3551 menu=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; 3552 ichoice=get(handles.transform_fct,'Value');%item number in the menu 3553 transform_name=menu{ichoice};% choice of the transform fct 3554 list_path=get(handles.transform_fct,'UserData'); 3555 3556 %% add a new item to the menu if the option 'more...' has been selected 3557 if strcmp(transform_name,'more...'); 3573 3558 [FileName, PathName] = uigetfile( ... 3574 {'*.m', ' (*.m)';3559 {'*.m', ' (*.m)'; 3575 3560 '*.m', '.m files '; ... 3576 3561 '*.*', '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 3587 3568 msgbox_uvmat('ERROR','a Matlab function .m must be introduced'); 3588 3569 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 3605 3588 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 3590 end 3591 3592 %% create the function handle of the selected fct 3593 if isempty(list_path{ichoice})% case of no selected fct 3594 transform_handle=[]; 3595 else 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) 3604 end 3605 set(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 3608 if isempty(list_path{ichoice})% case of no selected fct 3609 set(handles.transform_fct,'ToolTipString','transform_fct:choose a transform function') 3610 else 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 3617 end 3618 3619 %% adapt the GUI to the input/output conditions of the selected transform fct 3620 if isempty(list_path{ichoice})% case of no selected fct 3621 DataOut=[]; 3622 else 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 3615 3629 end 3616 3630 3617 3631 set(handles.CheckFixLimits,'Value',0) 3618 3632 set(handles.CheckFixLimits,'BackgroundColor',[0.7 0.7 0.7]) 3633 3634 %% execute the function to set input an output conditions 3635 3619 3636 3620 3637 %% delete drawn objects … … 4856 4873 end 4857 4874 4875 4876 % -------------------------------------------------------------------- 4877 function MenuSetProject_Callback(hObject, eventdata, handles) 4878 RootPath=get(handles.RootPath,'String'); 4879 ProjectDir = uigetdir(fileparts(fileparts(RootPath)), 'select the project source directory'); 4880 datatree_browser(ProjectDir)
Note: See TracChangeset
for help on using the changeset viewer.