📄 editlines.m
字号:
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,'faston') )
pdata(7)=1;
elseif( strcmp(action,'fastoff') )
pdata(7)=0;
end
set(hparams,'userdata',pdata);
return;
end
if(strcmp(action,'multnanon')|strcmp(action,'multnanoff') )%toggle multnan's
% 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,'multnanon') )
pdata(8)=1;
elseif( strcmp(action,'multnanoff') )
pdata(8)=0;
end
set(hparams,'userdata',pdata);
return;
end
if(strcmp(action,'deleteon')|strcmp(action,'deleteoff') )%toggle delete mode
% 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,'deleteon') )
pdata(9)=0;
elseif( strcmp(action,'deleteoff') )
pdata(9)=1;
end
set(hparams,'userdata',pdata);
return;
end
if(strcmp(action,'addon')|strcmp(action,'addoff') )%toggle add mode
% 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,'addon') )
pdata(10)=0;
elseif( strcmp(action,'addoff') )
pdata(10)=1;
end
set(hparams,'userdata',pdata);
return;
end
if(strcmp(action,'linkmode')|strcmp(action,'polymode')) %toggle linkmode
% 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');
linkmode=pdata(3);
if( linkmode )
pdata(3)=0;
set(gcf,'pointer','arrow')
elseif( strcmp(action,'linkmode') )
pdata(3)=1;
set(gcf,'pointer','crosshair');
elseif( strcmp(action,'polymode') )
pdata(3)=-1;
set(gcf,'pointer','crosshair');
end
set(hparams,'userdata',pdata);
return;
end
% In linkmode, a singleclick can signify one of the following
% 1) if it occurs on a new line, then the line is selected as the active line
% 2) if it occurs on the active line and the active line is a polygon, then
% the polygon is broken at the clicked point
% 3) if it occurs on the active line and it is not a polygon, then it becomes
% one by linking its endpoints
if( strcmp(action,'link') )
el_link
return
end
%the next section breaks a line into two segments and anchors them together
if(strcmp(action,'autoseg'))
el_autoseg
return;
end
if( strcmp(action,'smooth')|strcmp(action,'smooth3') )
% turn off the window button functions
set(gcf,'windowbuttonupfcn','');
set(gcf,'windowbuttonmotionfcn','');
% 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;
elseif( strcmp(get(h(k),'string'),'yrag_hors') )
hhors=h(k);
found=found+1;
end
if( found== 5)
break;
end
end
end
end
dat=get(hstor,'userdata');
% the user data of hstor 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
% get the axes userdata which has the information on the clicked point
stuff=get(gca,'userdata');
% find the clicked point
stuff=get(gca,'userdata');
lit=stuff(1,1);
it=stuff(1,2:lit+1);
hline3=stuff(1,lit+7);
if( hline3 )
line_anchors=stuff(1,lit+8:length(stuff(1,:)));
nanchors=length(line_anchors)/2;
xa=line_anchors(1:2:2*nanchors);
ya=line_anchors(2:2:2*nanchors);
else
nanchors=0;
line_anchors=[];
end
%get the data from the current curve
hline=dat(1);
x=get(hline,'xdata');
y=get(hline,'ydata');
npts=length(x);
ispoly=0;
if(x(1)==x(npts) & y(1)==y(npts) )
ispoly=1;
end
% get the clicked point
xit=x(it);
yit=y(it);
% determine the indicies of the anchor points
ia=[];
xanch=[];
yanch=[];
if(nanchors)
for k=1:nanchors
indx=find(x==xa(k));
indy=find(y(indx)==ya(k));
if(~isempty(indy))
ia=[ia indx(indy) ];
xanch=[xanch xa(k)*ones(size(indy))];
yanch=[yanch ya(k)*ones(size(indy))];
end
end
end
% now merge these with segment boundaries
iseg=[1 find(isnan(x)) npts];
xseg=x(iseg);
yseg=y(iseg);
for k=1:length(iseg)
iseg(k) %%%%%%%%%%
ind=find(ia==iseg(k));
if(isempty(ind)) % accumulate if it is not already an anchor
ia=[ia iseg(k)];
xanch=[xanch xseg(k)];
yanch=[yanch yseg(k)];
end
end
% sort them
[ia,ind]=sort(ia);
xanch=xanch(ind);
yanch=yanch(ind);
% determine the range of points to be smoothed
% first we smooth only locally between anchors
if(strcmp(action,'smooth') )
i1=find(ia<it);
if(~isempty(i1)) i1=ia(i1(length(i1))); end
i2=find(ia>it);
if(~isempty(i2)) i2=ia(i2(1)); end
else
i1=surround(iseg,it);
if(~isempty(i1))
i2=iseg(i1+1);
i1=iseg(i1);
end
end
%adjust for nans
while(isnan(x(i1)))
i1=i1+1;
end
while(isnan(x(i2)))
i2=i2-1;
end
if(isempty(i1) | isempty(i2) | i1>=i2)
return;
end
% now smooth
% first form a replacement x which has a new point between every input point
x1=x(i1:i2);
x2=zeros(1,2*length(x1)-1);
x2(1:2:length(x2))=x1;
x2(2:2:length(x2))=.5*(x1(1:length(x1)-1)+x1(2:length(x1)));
%y2=spline(x(i1:i2),y(i1:i2),x2);
theta=45.;
xint= cos(theta*pi/180.)*x2 + sin(theta*pi/180.)*(i1:.5:i2);
xfake= cos(theta*pi/180.)*x(i1:i2) + sin(theta*pi/180.)*(i1:i2);
y2=spline(xfake,y(i1:i2),xint);
xnew=[x(1:i1-1) x2 x(i2+1:npts)];
ynew=[y(1:i1-1) y2 y(i2+1:npts)];
npts=length(xnew);
%
% redisplay the line
set(hline,'xdata',xnew,'ydata',ynew);% the current line
if( ispoly )
set(dat(7),'xdata',xnew(2:npts),'ydata',ynew(2:npts));
else
set(dat(7),'xdata',xnew,'ydata',ynew);
end
return;
end
%clear any and all anchors
if(strcmp(action,'clearanch')|strcmp(action,'clearallanch'))
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
dat=get(hstor,'userdata');
% the user data of hstor 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(isempty(dat) & strcmp(action,'clearanch'))
return;
end
if(~isempty(dat))
% store the undo information
% [npts x(1:npts) y(1:npts) dat]
x=get(dat(1),'xdata');
y=get(dat(1),'ydata');
set(hundo,'userdata',[length(x) x y dat]);
if(dat(8))
delete(dat(8));
dat(8)=0;
end
dat(9:length(dat))=[];
set(hstor,'userdata',dat);
end
anchors=get(hanchors,'userdata');
h=anchors(1);
if(strcmp(action,'clearallanch'))
nh=1;
hstart=0;
newanch=[];
while( h ~= 0 )
newanch=[newanch h 0];
npts=anchors(nh+1);
nh=nh+2*npts+2;
if( nh >length(anchors) )h=0;
else h=anchors(nh);
end
end
else
ind=find(dat(1)==anchors);
inext=ind+2+anchors(ind+1)*2;
newanch=[anchors(1:ind) 0 anchors(inext:length(anchors))];
end
set(hanchors,'userdata',newanch);
return;
end
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -