-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathholefinder.m
269 lines (241 loc) · 8.55 KB
/
holefinder.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
%% This script detects holes in geometrymask and notes them with a number in 'holemask'
function [holemask, holenumber] = holefinder(geometrymask, gridpointX, gridpointY, nospace, nohole, space)
holemask = (-1) * ones(gridpointY,gridpointX);
%%. -1 is the temporary codeword for 'hey, there could be a hole!'
%%After the next operations all -1's will vanish, and at the end
%%there should just be 'nohole' and numbers from 1 to the number of holes,
%%which mark every hole.
%% First: no-conductor regions, which are connected to the border, are no holes ...
%%We identificate them like this: we go down one border and note regions without
%%geometry, then we go rowwise or columnwise into the chip and check if the
%%gridpoints in the new row/column are connected with region connected to
%%the nohole region detected during the last step.
%%We need to check this for every border, that measn 4 times.
%%left border
for i = 1:1:gridpointY
if geometrymask(i,1) == nospace
holemask(i,1) = nohole;
end
end
for j = 2:1:gridpointX
flag = 1;
while (flag == 1)
flag = 0;
for i = 2:1:gridpointY-1
if (holemask(i,j-1) == nohole) && (geometrymask(i,j) == nospace) && (holemask(i,j) == -1)
holemask(i,j) = nohole;
flag = 1;
end
if (holemask(i,j) == nohole) && (geometrymask(i-1,j) == nospace) && (holemask(i-1,j) == -1)
holemask(i-1,j) = nohole;
flag = 1;
end
if (holemask(i,j) == nohole) && (geometrymask(i+1,j) == nospace) && (holemask(i+1,j) == -1)
holemask(i+1,j) = nohole;
flag = 1;
end
end
end
end
%%right border
for i = 1:1:gridpointX
if geometrymask(i,gridpointX) == nospace
holemask(i,gridpointX) = nohole;
end
end
for j = gridpointX-1:-1:1
flag = 1;
while (flag == 1)
flag = 0;
for i = 2:1:gridpointY-1
if (holemask(i,j+1) == nohole) && (geometrymask(i,j) == nospace) && (holemask(i,j) == -1)
holemask(i,j) = nohole;
flag = 1;
end
if (holemask(i,j) == nohole) && (geometrymask(i-1,j) == nospace) && (holemask(i-1,j) == -1)
holemask(i-1,j) = nohole;
flag = 1;
end
if (holemask(i,j) == nohole) && (geometrymask(i+1,j) == nospace) && (holemask(i+1,j) == -1)
holemask(i+1,j) = nohole;
flag = 1;
end
end
end
end
%%upper border
for j = 1:1:gridpointX
if geometrymask(1,j) == nospace
holemask(1,j) = nohole;
end
end
for i = 2:1:gridpointY
flag = 1;
while (flag == 1)
flag = 0;
for j = 2:1:gridpointX-1
if (holemask(i-1,j) == nohole) && (geometrymask(i,j) == nospace) && (holemask(i,j) == -1)
holemask(i,j) = nohole;
flag = 1;
end
if (holemask(i,j) == nohole) && (geometrymask(i,j-1) == nospace) && (holemask(i,j-1) == -1)
holemask(i,j-1) = nohole;
flag = 1;
end
if (holemask(i,j) == nohole) && (geometrymask(i,j+1) == nospace) && (holemask(i,j+1) == -1)
holemask(i,j+1) = nohole;
flag = 1;
end
end
end
end
%%lower border
for j = 1:1:gridpointX
if geometrymask(gridpointY,j) == nospace
holemask(gridpointY,j) = nohole;
end
end
for i = gridpointY-1:-1:1
flag = 1;
while (flag == 1)
flag = 0;
for j = 2:1:gridpointX-1
if (holemask(i+1,j) == nohole) && (geometrymask(i,j) == nospace) && (holemask(i,j) == -1)
holemask(i,j) = nohole;
flag = 1;
end
if (holemask(i,j) == nohole) && (geometrymask(i,j-1) == nospace) && (holemask(i,j-1) == -1)
holemask(i,j-1) = nohole;
flag = 1;
end
if (holemask(i,j) == nohole) && (geometrymask(i,j+1) == nospace) && (holemask(i,j+1) == -1)
holemask(i,j+1) = nohole;
flag = 1;
end
end
end
end
%% Second: conducting regions are also no holes ...
holemask(geometrymask == space) = nohole;
%% Third: Classify compact holeregions
%%in 'holemask' there are holes where is written '-1'
%%Now we have to put the connected regions togethrer and note every hole with
%%a number from 1 to the number of holes.
%%We go trough the chip. If we hit a '-1' we do the same proecdure like
%%before, but now to identificate connected regions of -1. The -1 will be
%%replaced with the number of the hole.
holecount = 0; %%counter for the holes ...
for i = 2:1:gridpointY-1
for j = 2:1:gridpointX-1
if holemask(i,j) == -1;
%%So: if you hit a hole, put all adjacent -1's together and name them with the number 'holecount'
holecount = holecount + 1;
holemask (i,j) = holecount;
i2 = i;
j2 = j;
%%left to right:
flagx = 1;
while(flagx == 1)
flagx = 0;
flagy = 1;
while(flagy == 1)
if (holemask(i2,j2)==holecount) && (holemask(i2-1,j2)==-1)
holemask(i2-1,j2) = holecount;
end
if (holemask(i2,j2)==holecount) && (holemask(i2+1,j2)==-1)
holemask(i2+1,j2) = holecount;
end
if (holemask(i2,j2)==holecount) && (holemask(i2,j2-1)==-1)
holemask(i2,j2-1) = holecount;
end
if (holemask(i2,j2)==holecount) && (holemask(i2,j2+1)==-1)
holemask(i2,j2+1) = holecount;
flagx = 1;
tmpi2 = i2;
end
if holemask(i2+1,j2)==nohole
flagy = 0;
end
i2 = i2 + 1;
end
flagy = 1;
while(flagy == 1)
if (holemask(i2,j2)==holecount) && (holemask(i2-1,j2)==-1)
holemask(i2-1,j2) = holecount;
end
if (holemask(i2,j2)==holecount) && (holemask(i2+1,j2)==-1)
holemask(i2+1,j2) = holecount;
end
if (holemask(i2,j2)==holecount) && (holemask(i2,j2-1)==-1)
holemask(i2,j2-1) = holecount;
end
if (holemask(i2,j2)==holecount) && (holemask(i2,j2+1)==-1)
holemask(i2,j2+1) = holecount;
flagx = 1;
tmpi2 = i2;
end
if holemask(i2-1,j2)==nohole
flagy = 0;
end
i2 = i2 - 1;
end
j2 = j2 + 1;
i2 = tmpi2;
end
%%right to left:
flagx = 1;
while(flagx == 1)
flagx = 0;
flagy = 1;
while(flagy == 1)
flagy = 0;
if (holemask(i2,j2)==holecount) && (holemask(i2-1,j2)==-1)
holemask(i2-1,j2) = holecount;
end
if (holemask(i2,j2)==holecount) && (holemask(i2+1,j2)==-1)
holemask(i2+1,j2) = holecount;
end
if (holemask(i2,j2)==holecount) && (holemask(i2,j2-1)==-1)
holemask(i2,j2-1) = holecount;
flagx = 1;
tmpi2 = i2;
end
if (holemask(i2,j2)==holecount) && (holemask(i2,j2+1)==-1)
holemask(i2,j2+1) = holecount;
end
if holemask(i2+1,j2)==nohole
flagy = 0;
end
i2 = i2 + 1;
end
flagy = 1;
while(flagy == 1)
flagy = 0;
if (holemask(i2,j2)==holecount) && (holemask(i2-1,j2)==-1)
holemask(i2-1,j2) = holecount;
end
if (holemask(i2,j2)==holecount) && (holemask(i2+1,j2)==-1)
holemask(i2+1,j2) = holecount;
end
if (holemask(i2,j2)==holecount) && (holemask(i2,j2-1)==-1)
holemask(i2,j2-1) = holecount;
flagx = 1;
tmpi2 = i2;
end
if (holemask(i2,j2)==holecount) && (holemask(i2,j2+1)==-1)
holemask(i2,j2+1) = holecount;
end
if holemask(i2-1,j2)==nohole
flagy = 0;
end
i2 = i2 - 1;
end
j2 = j2 - 1;
i2 = tmpi2;
end
end
end
end
%% Define number of holes
holenumber = holecount;
end