📄 routine.m
字号:
function routine(action)% ROUTINE Handles different subfunctions of GUI.% All the software included in this package is presented as is.% It may be distributed freely. The author can, however, not be% held responsible for any problems whatever.% % Designed by Johan Baeten.% Last updated: 22-03-2000% Johan.baeten@mech.kuleuven.ac.be% Put stringvariables like action(1:9) at the end % -> ohterwise an error will occurglobal MENUBARHANDLES global SUBMENUHANDLESglobal FITHANDLESglobal UICTRHANDLESglobal XSIZEglobal YSIZEglobal IMAGENAMEglobal NEWIMAGENAMEglobal MAINFIGglobal VIEWSIZEglobal NUMBER % only in this m-fileglobal FILENAMEglobal FILECHANGEDglobal NR_OF_FITS;maxnrofpoints = 12;setting('showtitle');if strcmp(action,'selectpoints'), if strcmp(IMAGENAME,'noname.pgm'), seterror(' There is no image presently loaded. First open an image, then try again.'); else set(FITHANDLES,'visible','on'); set(SUBMENUHANDLES(6),'enable','off'); seterror([' Make a list of points using ''Clear List'', ''Add'' and ''Delete''.',... ' Then press ''Fit'' to see a fit trough these points.']); endelseif strcmp(action,'done'), seterror(' ... Closing interactive fit controls.'); set(FITHANDLES(1:4,:),'visible','off'); set(SUBMENUHANDLES(6),'enable','on');elseif strcmp(action,'new'), if get(FITHANDLES(1,12),'value')==0, seterror(' ... List of points was already empty.'); else seterror(' ... Clearing list of points.'); set(FITHANDLES(3:4,1:maxnrofpoints),'string','','value',-1); set(FITHANDLES(1,12),'value',0); FILENAME = '*.mat'; FILECHANGED = 0; setting('showtitle'); hpunten = findobj(get(gca,'children'),'type','line'); delete(hpunten); endelseif strcmp(action,'add'), nrofpoints = get(FITHANDLES(1,12),'value'); if (nrofpoints < maxnrofpoints), setting('menubarenableoff'); seterror(' Select a point in the image or press the number in the list'); set(FITHANDLES(1,1:7),'enable','off'); set(FITHANDLES(1,17:18),'enable','off');% set(UICTRHANDLES(2:4),'enable','off'); set(FITHANDLES(1,8), 'string','Stop Adding', ... 'callback','routine(''stopadding'')'); set(FITHANDLES(2,nrofpoints+1),'enable','on'); set(MAINFIG,'pointer','crosshair'); set(MAINFIG,'Windowbuttondownfcn','routine(''voegpunttoe'')'); else routine('stopadding'); seterror(' Maximum number of points reached! Use ''New'' or ''Delete''.'); end elseif strcmp(action,'voegpunttoe'), nrofpoints = get(FITHANDLES(1,12),'value'); [x_size,y_size]=size(get(MAINFIG,'userdata')); p=get(gca,'currentpoint'); x=p(1,1); y = p(1,2); xl = get(gca,'xlim'); yl = get(gca,'ylim'); % range for pixels from 1 to 128 e.g pixels 64 lies just befor the index 64 if ((x >= xl(1)) & (x<= xl(2)) & (y >= yl(1)) & (y <= yl(2))), nrofpoints = nrofpoints + 1; set(FITHANDLES(2,nrofpoints),'enable','off'); set(FITHANDLES(1,12),'value',nrofpoints); x=x-0.5; y=y-0.5; set(FITHANDLES(2,nrofpoints),'enable','off'); set(FITHANDLES(3,nrofpoints),'string',num2str(x),'value',x); set(FITHANDLES(4,nrofpoints),'string',num2str(y),'value',y); routine('plotpunten'); if (nrofpoints < maxnrofpoints), set(FITHANDLES(2,nrofpoints+1),'enable','on'); else routine('stopadding'); seterror(' Maximum number of points reached.'); end FILECHANGED = 1; end elseif strcmp(action,'plotpunten'), nrofpoints = get(FITHANDLES(1,12),'value'); if nrofpoints > 0, for i = 1:nrofpoints, xc(i) = get(FITHANDLES(3,i),'value')+0.5; yc(i) = get(FITHANDLES(4,i),'value')+0.5; end hpunten = findobj(get(gca,'children'),'marker','o'); l= length(hpunten); if l == 0, % no plotted points found hold on, plot(xc,yc,'ro'), hold off; else if l > 1, seterror(' Message: More handles found then needed, taking first one ...'); end set(hpunten(1),'xdata',xc,'ydata',yc); end endelseif strcmp(action,'stopadding'), set(MAINFIG,'Windowbuttondownfcn','','pointer','arrow'); setting('menubarenableon'); set(FITHANDLES(2,1:maxnrofpoints),'enable','off'); set(FITHANDLES(1,1:7),'enable','on'); set(FITHANDLES(1,17:18),'enable','on');% set(UICTRHANDLES(2:4),'enable','on'); set(FITHANDLES(1,8), 'string','Close', ... 'callback','routine(''done'')');% if strcmp(get(SUBMENUHANDLES(2),'label'),'Zoom Off'),% setting('togglezoomfunction');% endelseif strcmp(action,'delete'), seterror(' Point to a previous selected point in the image or press a number in the list to be deleted'); setting('menubarenableoff'); set(FITHANDLES(1,1:7),'enable','off'); set(FITHANDLES(1,17:18),'enable','off');% set(UICTRHANDLES(2:4),'enable','off'); set(FITHANDLES(1,8), 'string','Cancel Delete','callback','routine(''canceldelete'')'); nrofpoints = get(FITHANDLES(1,12),'value'); if (nrofpoints == 0), seterror(' There is nothing to delete! Press ''Cancel Delete'''); else set(FITHANDLES(2,1:nrofpoints),'enable','on'); set(MAINFIG,'WindowButtonDownFcn','routine(''deletebypointing'')'); endelseif strcmp(action,'canceldelete'), routine('stopadding');elseif strcmp(action,'deletebypointing'), nrofpoints = get(FITHANDLES(1,12),'value'); p=get(gca,'currentpoint'); x=p(1,1); y = p(1,2); xl = get(gca,'xlim'); yl = get(gca,'ylim'); if ((x >= xl(1)) & (x<= xl(2)) & (y >= yl(1)) & (y <= yl(2))), x=x-0.5; y=y-0.5; for i = 1:nrofpoints, xp(i) = get(FITHANDLES(3,i),'value'); yp(i) = get(FITHANDLES(4,i),'value'); end marge = (xl(2)-xl(1))/50; nr = 0; for i = 1 : nrofpoints, if (abs(x-xp(i)) < marge) & (abs(y-yp(i)) < marge), nr = i; end end if nr == 0, seterror(' No point found in this area.'); else hulpstr = ['point',num2str(nr)]; routine(hulpstr); end FILECHANGED = 1; end elseif strcmp(action,'move'), nrofpoints = get(FITHANDLES(1,12),'value'); if (nrofpoints == 0), seterror(' There is nothing to edit or move!'); else setting('menubarenableoff'); set(FITHANDLES(1,1:7),'enable','off'); set(FITHANDLES(1,17:18),'enable','off');% set(UICTRHANDLES(2:4),'enable','off'); set(FITHANDLES(1,8), 'string','Stop Editing','callback','routine(''stopadding'')'); seterror(' Edit a point in the list or move a point in the image by ''dragging''.'); set(FITHANDLES(2,1:nrofpoints),'enable','on'); set(MAINFIG,'pointer','arrow',... 'WindowbuttonUpfcn','',... 'Windowbuttondownfcn','routine(''beweegpunt'')'); endelseif strcmp(action,'beweegpunt'), nrofpoints = get(FITHANDLES(1,12),'value'); p=get(gca,'currentpoint'); x=p(1,1); y = p(1,2); xl = get(gca,'xlim'); yl = get(gca,'ylim'); if ((x >= xl(1)) & (x<= xl(2)) & (y >= yl(1)) & (y <= yl(2))), x=x-0.5; y=y-0.5; for i = 1:nrofpoints, xp(i) = get(FITHANDLES(3,i),'value'); yp(i) = get(FITHANDLES(4,i),'value'); end marge = (xl(2)-xl(1))/50; nr = 0; for i = 1 : nrofpoints, if (abs(x-xp(i)) < marge) & (abs(y-yp(i)) < marge), nr = i; end end if nr == 0, seterror(' No point found in this area.'); else NUMBER = nr; set(MAINFIG,'pointer','cross'); hold on, plot(xp(nr)+0.5,yp(nr)+0.5,'rx'),hold off; cbstr =['routine(''wijzigpunt'');routine(''plotpunten'');routine(''move'')']; set(MAINFIG,'WindowButtonUpFcn',cbstr);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -