1 | function [A,numprofiles,numpoints,closed]=cutarea(A,numprofiles,numpoints,closed,prevplot,root,options)
|
---|
2 | %CUTAREA - cut several point of a profile
|
---|
3 | %
|
---|
4 | %
|
---|
5 | % this script is used by exptool as an elementary operation
|
---|
6 | % on an ARGUS profile. The user must click 3 times to select the
|
---|
7 | % area to be removed. Twice to select the tips and one to select
|
---|
8 | % the part of the profile to be removed
|
---|
9 | %
|
---|
10 | % Usage:
|
---|
11 | % [A,numprofiles,numpoints,closed]=cutarea(A,numprofiles,numpoints,closed,prevplot,root,options)
|
---|
12 |
|
---|
13 | hold on
|
---|
14 | loop=1;
|
---|
15 |
|
---|
16 | %plot squares
|
---|
17 | for i=1:numprofiles
|
---|
18 | plot(A(i).x,A(i).y,'color',getfieldvalue(options,'color'),'LineStyle',getfieldvalue(options,'LineStyle'),'LineWidth',getfieldvalue(options,'LineWidth'),...
|
---|
19 | 'MarkerEdgeColor',getfieldvalue(options,'MarkerEdgeColor'),'MarkerSize',getfieldvalue(options,'MarkerSize'),'Marker',getfieldvalue(options,'Marker'));
|
---|
20 | end
|
---|
21 |
|
---|
22 | points=[];
|
---|
23 |
|
---|
24 | %loop (at least 3 clicks needed)
|
---|
25 | while loop
|
---|
26 |
|
---|
27 | %some checks
|
---|
28 | if numprofiles==0
|
---|
29 | disp('no profile present, exiting...')
|
---|
30 | return
|
---|
31 | end
|
---|
32 | if numpoints<3
|
---|
33 | disp('at least two points are needed, exiting...')
|
---|
34 | return
|
---|
35 | end
|
---|
36 |
|
---|
37 | %select a point
|
---|
38 | if isempty(points)
|
---|
39 | title('click on the first tip, RETURN to exit','FontSize',14)
|
---|
40 | elseif length(points)==1
|
---|
41 | title('click on the second tip, RETURN to exit','FontSize',14)
|
---|
42 | else
|
---|
43 | title('click in the middle of the area to be cut, RETURN to exit','FontSize',14)
|
---|
44 | end
|
---|
45 |
|
---|
46 | [xi,yi] = ginput(1);
|
---|
47 |
|
---|
48 | if ~isempty(xi)
|
---|
49 | %get the closest point
|
---|
50 | %first time, look at all profiles
|
---|
51 | if isempty(points)
|
---|
52 | [profsel indsel]=closestpoint(A,numprofiles,xi,yi);
|
---|
53 | if ((closed(profsel) & length(A(profsel).x)<4) | (~closed(profsel) & length(A(profsel).x)<3)),
|
---|
54 | disp('the selected profile has less than 3 points, make another selection');
|
---|
55 | else
|
---|
56 | selection=profsel;
|
---|
57 | points(end+1)=indsel;
|
---|
58 | plot(A(profsel).x,A(profsel).y,...
|
---|
59 | 'color',getfieldvalue(options,'selectioncolor'),'LineStyle',getfieldvalue(options,'LineStyle'),'LineWidth',getfieldvalue(options,'LineWidth'));
|
---|
60 | text(A(selection).x(indsel),A(selection).y(indsel),num2str(1),'FontSize',14,'background',[0.7 0.7 0.9]);
|
---|
61 | end
|
---|
62 | else
|
---|
63 | %get the 2d or 3d point for the given contou
|
---|
64 | [profsel indsel]=closestpoint(A(selection),1,xi,yi);
|
---|
65 | if ismember(indsel,points)
|
---|
66 | disp('the selected points must be distinct')
|
---|
67 | else
|
---|
68 | %second click?
|
---|
69 | if length(points)==1,
|
---|
70 | points(end+1)=indsel;
|
---|
71 | text(A(selection).x(indsel),A(selection).y(indsel),num2str(2),'FontSize',14,'background',[0.7 0.7 0.9]);
|
---|
72 | %third click?
|
---|
73 | else
|
---|
74 | p1=points(1); p2=points(2); p3=indsel;
|
---|
75 | x=A(selection).x; y=A(selection).y;
|
---|
76 | if p1<p2
|
---|
77 | if p3>p1 & p3<p2
|
---|
78 | if closed(selection)
|
---|
79 | %open the profile
|
---|
80 | n=length(A(selection).x);
|
---|
81 | A(selection).x=[A(selection).x(p2:end-1,1);A(selection).x(1:p1,1)];
|
---|
82 | A(selection).y=[A(selection).y(p2:end-1,1);A(selection).y(1:p1,1)];
|
---|
83 | numpoints=numpoints-(n-length(A(selection).x));
|
---|
84 | closed(selection)=0;
|
---|
85 | else
|
---|
86 | %cut in 2 profiles
|
---|
87 | A(selection).x=x(1:p1);
|
---|
88 | A(selection).y=y(1:p1);
|
---|
89 | closed(selection)=0;
|
---|
90 | A(end+1).x=x(p2:end);
|
---|
91 | A(end).y=y(p2:end);
|
---|
92 | A(end).density=A(selection).density;
|
---|
93 | A(end).name=A(selection).name;
|
---|
94 | closed(end+1)=0;
|
---|
95 | numprofiles=numprofiles+1;
|
---|
96 | numpoints=numpoints-(p2-p1-1);
|
---|
97 | end
|
---|
98 | else
|
---|
99 | %only point removal
|
---|
100 | n=length(A(selection).x);
|
---|
101 | A(selection).x=x(p1:p2);
|
---|
102 | A(selection).y=y(p1:p2);
|
---|
103 | numpoints=numpoints-(n-length(A(selection).x));
|
---|
104 | closed(selection)=0;
|
---|
105 | end
|
---|
106 | else
|
---|
107 | if p3>p2 & p3<p1
|
---|
108 | if closed(selection)
|
---|
109 | %open the profile
|
---|
110 | n=length(A(selection).x);
|
---|
111 | A(selection).x=[A(selection).x(p1:end-1,1);A(selection).x(1:p2,1)];
|
---|
112 | A(selection).y=[A(selection).y(p1:end-1,1);A(selection).y(1:p2,1)];
|
---|
113 | numpoints=numpoints-(n-length(A(selection).x));
|
---|
114 | closed(selection)=0;
|
---|
115 | else
|
---|
116 | %cut in 2 profiles
|
---|
117 | closed(selection)=0;
|
---|
118 | A(selection).x=x(1:p2);
|
---|
119 | A(selection).y=y(1:p2);
|
---|
120 | A(end+1).x=x(p1:end);
|
---|
121 | A(end).y=y(p1:end);
|
---|
122 | A(end).density=A(selection).density;
|
---|
123 | A(end).name=A(selection).name;
|
---|
124 | closed(end+1)=0;
|
---|
125 | numprofiles=numprofiles+1;
|
---|
126 | numpoints=numpoints-(p1-p2-1);
|
---|
127 | end
|
---|
128 | else
|
---|
129 | %only point removal
|
---|
130 | n=length(A(selection).x);
|
---|
131 | x(1:p2-1)=[];x(p1-p2+2:end)=[];%it should have been x(p2+1:end)
|
---|
132 | y(1:p2-1)=[];y(p1-p2+2:end)=[];
|
---|
133 | A(selection).x=x;
|
---|
134 | A(selection).y=y;
|
---|
135 | numpoints=numpoints-(n-length(A(selection).x));
|
---|
136 | closed(selection)=0;
|
---|
137 | end
|
---|
138 | end
|
---|
139 |
|
---|
140 | %plot new profile
|
---|
141 | undoplots(prevplot);
|
---|
142 | for i=1:numprofiles
|
---|
143 | plot(A(i).x,A(i).y,'color',getfieldvalue(options,'color'),'LineStyle',getfieldvalue(options,'LineStyle'),'LineWidth',getfieldvalue(options,'LineWidth'),...
|
---|
144 | 'MarkerEdgeColor',getfieldvalue(options,'MarkerEdgeColor'),'MarkerSize',getfieldvalue(options,'MarkerSize'),'Marker',getfieldvalue(options,'Marker'));
|
---|
145 | end
|
---|
146 | points=[];
|
---|
147 |
|
---|
148 | end
|
---|
149 | end
|
---|
150 | end
|
---|
151 | else
|
---|
152 | %RETRUN-> quit
|
---|
153 | loop=0;
|
---|
154 | end
|
---|
155 | end
|
---|
156 | end
|
---|