0001 function [A,numprofiles,numpoints,closed]=cutarea(A,numprofiles,numpoints,closed,prevplot,root);
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013 hold on
0014 loop=1;
0015
0016
0017 for i=1:numprofiles
0018 plot(A(i).x,A(i).y,'-rs','MarkerSize',10);
0019 end
0020
0021 points=[];
0022
0023
0024 while loop
0025
0026
0027 if numprofiles==0
0028 disp('no profile present')
0029 return
0030 end
0031 if numpoints<3
0032 disp('at least two points are needed')
0033 return
0034 end
0035
0036
0037 if isempty(points)
0038 title('click on the first tip, RETURN to exit','FontSize',14)
0039 elseif length(points)==1
0040 title('click on the second tip, RETURN to exit','FontSize',14)
0041 else
0042 title('click in the middle of the area to be cut, RETURN to exit','FontSize',14)
0043 end
0044
0045 [xi,yi] = ginput(1);
0046
0047 if ~isempty(xi)
0048
0049
0050 if isempty(points)
0051 [profsel indsel]=closestpoint(A,numprofiles,xi,yi);
0052 if ((closed(profsel) & length(A(profsel).x)<4) | (~closed(profsel) & length(A(profsel).x)<3)),
0053 disp('the selected profile has less than 3 points, make another selection');
0054 else
0055 selection=profsel;
0056 points(end+1)=indsel;
0057 plot(A(selection).x,A(selection).y,'-b','MarkerSize',10);
0058 text(A(selection).x(indsel),A(selection).y(indsel),num2str(1),'FontSize',14,'background',[0.7 0.7 0.9]);
0059 end
0060 else
0061
0062 [profsel indsel]=closestpoint(A(selection),1,xi,yi);
0063 if ismember(indsel,points)
0064 disp('the selected points must be distinct')
0065 else
0066
0067 if length(points)==1,
0068 points(end+1)=indsel;
0069 text(A(selection).x(indsel),A(selection).y(indsel),num2str(2),'FontSize',14,'background',[0.7 0.7 0.9]);
0070
0071 else
0072 p1=points(1); p2=points(2); p3=indsel;
0073 x=A(selection).x; y=A(selection).y;
0074 if p1<p2
0075 if p3>p1 & p3<p2
0076 if closed(selection)
0077
0078 n=length(A(selection).x);
0079 A(selection).x=[A(selection).x(p2:end-1,1);A(selection).x(1:p1,1)];
0080 A(selection).y=[A(selection).y(p2:end-1,1);A(selection).y(1:p1,1)];
0081 numpoints=numpoints-(n-length(A(selection).x));
0082 closed(selection)=0;
0083 else
0084
0085 A(selection).x=x(1:p1);
0086 A(selection).y=y(1:p1);
0087 A(end+1).x=x(p2:end);
0088 A(end).y=y(p2:end);
0089 A(end).density=A(selection).density;
0090 A(end).name=A(selection).name;
0091 numprofiles=numprofiles+1;
0092 numpoints=numpoints-(p2-p1-1);
0093 end
0094 else
0095
0096 n=length(A(selection).x);
0097 A(selection).x=x(p1:p2);
0098 A(selection).y=y(p1:p2);
0099 numpoints=numpoints-(n-length(A(selection).x));
0100 closed(selection)=0;
0101 end
0102 else
0103 if p3>p2 & p3<p1
0104 if closed(selection)
0105
0106 n=length(A(selection).x);
0107 A(selection).x=[A(selection).x(p1:end-1,1);A(selection).x(1:p2,1)];
0108 A(selection).y=[A(selection).y(p1:end-1,1);A(selection).y(1:p2,1)];
0109 numpoints=numpoints-(n-length(A(selection).x));
0110 closed(selection)=0;
0111 else
0112
0113 A(selection).x=x(1:p2);
0114 A(selection).y=y(1:p2);
0115 A(end+1).x=x(p1:end);
0116 A(end).y=y(p1:end);
0117 A(end).density=A(selection).density;
0118 A(end).name=A(selection).name;
0119 numprofiles=numprofiles+1;
0120 numpoints=numpoints-(p1-p2-1);
0121 end
0122 else
0123
0124 n=length(A(selection).x);
0125 x(1:p2-1)=[];x(p1-p2+2:end)=[];
0126 y(1:p2-1)=[];y(p1-p2+2:end)=[];
0127 A(selection).x=x;
0128 A(selection).y=y;
0129 numpoints=numpoints-(n-length(A(selection).x));
0130 closed(selection)=0;
0131 end
0132 end
0133
0134 undoplots(prevplot);
0135 for i=1:numprofiles
0136 plot(A(i).x,A(i).y,'-rs','MarkerSize',10);
0137 end
0138 points=[];
0139 end
0140 end
0141 end
0142 else
0143
0144 loop=0;
0145 end
0146 end
0147 end