📄 editlines.m
字号:
end else % we are between anchors % determine which 2 anchors ind=surround(iasort,it); ia1=iasort(ind); ia2=iasort(ind+1); xdvec = zeros(1,npts); % start with zero ydvec = zeros(1,npts); % start with zero if( dragmode )%constant displacement xdvec(ia1+1:ia2-1)=xdisp*ones(size(ia1+1:ia2-1)); ydvec(ia1+1:ia2-1)=ydisp*ones(size(ia1+1:ia2-1)); else % compute the x displacement xinc1=xdisp/(it-ia1); xinc2=xdisp/(ia2-it); xdvec(ia1+1:ia2-1) = [(1:it-ia1)*xinc1 xdisp-(1:ia2-it-1)*xinc2]; % compute the y displacement yinc1=ydisp/(it-ia1); yinc2=ydisp/(ia2-it); ydvec(ia1+1:ia2-1) = [(1:it-ia1)*yinc1 ydisp-(1:ia2-it-1)*yinc2]; end x=x+xdvec; y=y+ydvec; if(fastopt) ind=find( (xdvec+ydvec)~= 0 ); xmoved=x(ind); ymoved=y(ind); end end end end % check for occurance of multiple nans in a row or at the beginning &/or end of % the line singnan=stuff(3,2); if(singnan) [x2,ikeep]=nanclear(x); else x2=x; ikeep=1:length(x); end if( length(x2)<npts ) if(~strcmp(action,'button2motion')) xit=x(it); yit=y(it); npts=length(x2); x=x2; y=y(ikeep); % if we changed the number of points then change 'it' as well lit=stuff(1,1); for k=1:lit ind=find( x==xit(k) ); i2=find( y(ind)==yit(k) ); it(k)=ind(i2); end stuff(1,2:lit+1)=it; set(gca,'userdata',stuff); else npts=length(x2); x=x2; y=y(ikeep); end endif( fastopt & ~linkmode & ~strcmp(action,'button2motion') ) set(hline2,'xdata',xmoved,'ydata',ymoved); set(hline2,'userdata',[x;y]); else set(hline,'xdata',x,'ydata',y); if( ispoly ) set(hline2,'xdata',x(2:npts),'ydata',y(2:npts)); else set(hline2,'xdata',x,'ydata',y); end end return;endif(strcmp(action,'stopmotion') ) % see if a significant motion occured. If it did not, call the appropriate % button up function. This is done to decrease the sensitivity of the % program to accidental small mouse motions % find the clicked point stuff=get(gca,'userdata'); lit=stuff(1,1); it=stuff(1,2:lit+1); hstor=stuff(1,lit+2); xit=stuff(1,lit+3); yit=stuff(1,lit+4); hline=stuff(1,lit+5); hline2=stuff(1,lit+6); hline3=stuff(1,lit+7); if( hline3 ) line_anchors=stuff(1,lit+8:length(stuff(1,:))); nanchors=length(line_anchors)/2; else nanchors=0; line_anchors=[]; end xonly=stuff(2,1); yonly=stuff(2,2); killrd=stuff(2,3); ispoly=stuff(2,4); locate=stuff(2,5); htext=stuff(2,6); dragmode=stuff(2,7); linkmode=stuff(2,8); fastopt=stuff(3,1); pt=get(gca,'currentpoint'); xpt=pt(1,1); ypt=pt(1,2); %delete any locate text that may be on if(htext) delete(htext) htext=0; stuff(2,6)=0; set(gca,'userdata',stuff); end % get the lines data %x=get(hline,'xdata'); %y=get(hline,'ydata'); %npts=length(x); % get the button flag=get(gcf,'selectiontype'); if( strcmp(flag,'normal') ) d=sqrt( (xpt-xit)^2 + (ypt-yit)^2 ); if( d>.1*killrd ) set(gcf,'windowbuttonmotionfcn',''); set(gcf,'windowbuttonupfcn',''); % test for fastopt if(fastopt) xy=get(hline2,'userdata'); set(hline,'xdata',xy(1,:),'ydata',xy(2,:)); if( ispoly ) set(hline2,'xdata',xy(1,2:npts),'ydata',xy(2,2:npts)); else set(hline2,'xdata',xy(1,:),'ydata',xy(2,:)); end end return; else set(gcf,'windowbuttonmotionfcn',''); set(gcf,'windowbuttonupfcn',''); editlines('undo'); if(~linkmode & ~smoothmode ) editlines('button1up'); elseif( linkmode==-1) editlines('linkpoly'); elseif( smoothmode ) editlines('smooth'); end end elseif( strcmp(flag,'alt') ) d=sqrt( (xpt-xit)^2 + (ypt-yit)^2 ); if( d>.1*killrd ) set(gcf,'windowbuttonmotionfcn',''); set(gcf,'windowbuttonupfcn',''); % test for fastopt if(fastopt) xy=get(hline2,'userdata'); set(hline,'xdata',xy(1,:),'ydata',xy(2,:)); if( ispoly ) set(hline2,'xdata',xy(1,2:npts),'ydata',xy(2,2:npts)); else set(hline2,'xdata',xy(1,:),'ydata',xy(2,:)); end end return; else editlines('undo'); if(~linkmode & ~smoothmode ) editlines('button3up'); elseif( linkmode) editlines('autoseg'); elseif( smoothmode ) editlines('smooth3'); end end end set(gcf,'windowbuttonmotionfcn',''); return;endif(strcmp(action,'xonly')) %toggle xonly % Get the storage bucket h=get(gcf,'children'); for k=1:length(h) if( strcmp(get(h(k),'type'),'uicontrol') ) if( strcmp(get(h(k),'style'),'text') ) if( strcmp(get(h(k),'string'),'yrag_params') ) hparams=h(k); break; end end end end % get the parameters pdata=get(hparams,'userdata'); xonly=pdata(1); if( xonly ) pdata(1)=0; else pdata(1)=1; end set(hparams,'userdata',pdata); return;endif(strcmp(action,'yonly')) %toggle yonly % Get the storage bucket h=get(gcf,'children'); for k=1:length(h) if( strcmp(get(h(k),'type'),'uicontrol') ) if( strcmp(get(h(k),'style'),'text') ) if( strcmp(get(h(k),'string'),'yrag_params') ) hparams=h(k); break; end end end end % get the parameters pdata=get(hparams,'userdata'); yonly=pdata(2); if( yonly ) pdata(2)=0; else pdata(2)=1; end set(hparams,'userdata',pdata); return;endif(strcmp(action,'xandy')) %toggle yonly % Get the storage bucket h=get(gcf,'children'); for k=1:length(h) if( strcmp(get(h(k),'type'),'uicontrol') ) if( strcmp(get(h(k),'style'),'text') ) if( strcmp(get(h(k),'string'),'yrag_params') ) hparams=h(k); break; end end end end % get the parameters pdata=get(hparams,'userdata'); xonly=pdata(1); yonly=pdata(2); pdata(1)=0; pdata(2)=0; set(hparams,'userdata',pdata); return;endif(strcmp(action,'locate')|strcmp(action,'locateon')|strcmp(action,'locateoff'))%toggle locate % Get the storage bucket h=get(gcf,'children'); for k=1:length(h) if( strcmp(get(h(k),'type'),'uicontrol') ) if( strcmp(get(h(k),'style'),'text') ) if( strcmp(get(h(k),'string'),'yrag_params') ) hparams=h(k); break; end end end end % get the parameters pdata=get(hparams,'userdata'); if(strcmp(action,'locate')) locate=pdata(4); if( locate ) pdata(4)=0; else pdata(4)=1; end elseif(strcmp(action,'locateon')) pdata(4)=1; else pdata(4)=0; end set(hparams,'userdata',pdata); return;endif(strcmp(action,'dragmode')|strcmp(action,'elasticdrag')|... strcmp(action,'constantdrag')) %toggle dragmode % Get the storage bucket h=get(gcf,'children'); for k=1:length(h) if( strcmp(get(h(k),'type'),'uicontrol') ) if( strcmp(get(h(k),'style'),'text') ) if( strcmp(get(h(k),'string'),'yrag_params') ) hparams=h(k); break; end end end end % get the parameters pdata=get(hparams,'userdata'); dragmode=pdata(5); if(strcmp(action,'dragmode')) if( dragmode ) pdata(5)=0; else pdata(5)=1; end elseif(strcmp(action,'elasticdrag')) pdata(5)=0; elseif(strcmp(action,'constantdrag')) pdata(5)=1; end set(hparams,'userdata',pdata); return;endif( strcmp(action,'undo') )% the previous action is undone by restroing things to the state saved at the last % buttondown % Get the storage buckets h=get(gcf,'children'); found=0; for k=1:length(h) if( strcmp(get(h(k),'type'),'uicontrol') ) if( strcmp(get(h(k),'style'),'text') ) if( strcmp(get(h(k),'string'),'yrag') ) hstor=h(k); found=found+1; elseif( strcmp(get(h(k),'string'),'yrag_params') ) hparams=h(k); found=found+1; elseif( strcmp(get(h(k),'string'),'yrag_anchors') ) hanchors=h(k); found=found+1; elseif( strcmp(get(h(k),'string'),'yrag_undo') ) hundo=h(k); found=found+1; end if( found== 4) break; end end end end % get the undo information undostuff=get(hundo,'userdata'); if(isempty(undostuff)) return; end flag=isinf(undostuff); flag=find(flag==1); if(isempty(flag)) otherstuff=[]; else otherstuff=undostuff(flag+1:length(undostuff)); undostuff=undostuff(1:flag-1); end % get the line data npts=undostuff(1); x=undostuff(2:npts+1); y=undostuff(npts+2:2*npts+1); ispoly=0; if( x(1)==x(npts) & y(1)==y(npts) )ispoly=1;end % get dat dat=undostuff(2*npts+2:length(undostuff)); % get baddat baddat=get(hstor,'userdata'); % dat is the user data of hstor and is: % dat(1) = handle of the selected line % dat(2) = original linestyle % dat(3) = original linewidth % dat(4:6) = original color % dat(7) = handle of duplicate line % dat(8) = handle of the anchor line % dat(9:length(dat)) = (x,y)'s of the anchors of the selected line if(dat(8)) line_anchors=dat(9:length(dat)); nanchors=length(line_anchors)/2; end set(dat(1),'xdata',x,'ydata',y); if( ispoly ) set(dat(7),'xdata',x(2:npts),'ydata',y(2:npts)); else set(dat(7),'xdata',x,'ydata',y); end if( dat(8) ) %make sure dat(8) still exists hkids=get(gca,'children'); ind=find(dat(8)==hkids); if(isempty(ind)) hline3 = line(line_anchors(1:2:2*nanchors),line_anchors... (2:2:2*nanchors),'color',[1 0 0],'marker','o','markersize',12,... 'linestyle','none','erasemode','xor'); dat(8)=hline3; end set(dat(8),'xdata',line_anchors(1:2:2*nanchors),'ydata',... line_anchors(2:2:2*nanchors)); elseif(baddat(8)) delete(baddat(8)); end set(hstor,'userdata',dat); % deal withthe otherstuff if(~isempty(otherstuff)) hline=otherstuff(1); n2=otherstuff(2); x2=otherstuff(3:2+n2); y2=otherstuff(3+n2:2*n2+2); set(hline,'xdata',x2,'ydata',y2); end return;endif(strcmp(action,'smoothon')|strcmp(action,'smoothoff')|... strcmp(action,'linkon')|strcmp(action,'linkoff') ) %toggle smoothmode % Get the storage bucket h=get(gcf,'children'); for k=1:length(h) if( strcmp(get(h(k),'type'),'uicontrol') ) if( strcmp(get(h(k),'style'),'text') ) if( strcmp(get(h(k),'string'),'yrag_params') ) hparams=h(k); break; end end end end % get the parameters pdata=get(hparams,'userdata'); if( strcmp(action,'smoothon') ) %see if linkmode is on and turn it off if(pdata(3)) editlines('linkoff'); end pdata(6)=1; set(gcf,'pointer','circle'); elseif( strcmp(action,'smoothoff') ) pdata(6)=0; set(gcf,'pointer','arrow'); elseif( strcmp(action,'linkon') ) %see if smoothmode is on and turn it off if(pdata(6)) editlines('smoothoff'); end pdata(3)=1; set(gcf,'pointer','crosshair'); elseif( strcmp(action,'linkoff') ) pdata(3)=0; set(gcf,'pointer','arrow'); end set(hparams,'userdata',pdata); return;endif(strcmp(action,'faston')|strcmp(action,'fastoff') )%toggle fastopt % Get the storage bucket h=get(gcf,'children'); for k=1:length(h) if( strcmp(get(h(k),'type'),'uicontrol') )
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -