% ----------------------- PreparePoints.m ------------------------- % % function [xout,yout,newcn] = PreparePoints(mouse,x,y,closed,cn,corners) % % inputs: mouse = 1 if mouse input required, 0 otherwise % x,y : ignored if mouse==1, else list of points % closed = 1 if curve should be closed, else 0 % cn = list of indices of preestablished corners (ignored if % mouse==1 % corners = 0 if no automatic corner detection, otherwise % its the threshold in radians for defining a corner % % outputs: xout,yout : list of points, with xout(n)==xout(1), % yout(n)==yout(1) if closed==1 % newcn : list of indices of corners in order % function [xout,yout,newcn] = PreparePoints(mouse,x,y,closed,cn,corners) if mouse==1 [x,y,cn]=GetMousePts; end % search for repeated points and delete them as they will mess up the spline: i=1; while i=length(x) x=x(1:i);y=y(1:i); else x=[x(1:i),x(i+2:length(x))]; y=[y(1:i),y(i+2:length(y))]; end for j=1:length(cn) if cn(j)>i cn(j)=cn(j)-1; end end else i=i+1; end end if (closed==1)&(x(length(x))==x(1))&(y(length(y))==y(1)) % we're not ready for beginning and end equal x=x(1:length(x)-1); y=y(1:length(y)-1); end % find new corners if corners > 0 if corners>0 [CornersFound]=FindCorners(x,y,corners,closed); else CornersFound=[]; end % interleave cn and CornersFound to create newcn i=1;j=1; n=length(cn); m=length(CornersFound); newcn=[]; while (i<=n)&(j<=m) if cn(i)CornersFound(j) newcn=[newcn,CornersFound(j)]; j=j+1; else %they're equal newcn=[newcn,cn(i)]; i=i+1; j=j+1; end end if i<=n newcn=[newcn,cn(i:n)]; elseif j<=m newcn=[newcn,CornersFound(j:m)]; end if closed==1 xout=[x,x(1)];yout=[y,y(1)]; if length(newcn)>0 if newcn(1)==1 newcn=[newcn,length(xout)]; end end else xout=x;yout=y; if length(newcn)==0 newcn=[1,length(x)]; else if newcn(1)~=1 newcn=[1,newcn]; end if newcn(length(newcn))~=length(x) newcn=[newcn,length(x)]; end end end % search for repeat corners and discard: j=1; while j