1 #include <iostream>
2 #include "brip_rect_mask.h"
3 
4 #ifdef _MSC_VER
5 #  include "vcl_msvc_warnings.h"
6 #endif
7 
8 std::map<brip_rect_mask::ang_id, std::string > brip_rect_mask::names_=std::map<brip_rect_mask::ang_id, std::string >();
9 std::map<brip_rect_mask::ang_id, float > brip_rect_mask::angles_=std::map<brip_rect_mask::ang_id, float >();
10 bool brip_rect_mask::is_init_ = false;
11 
12 //        0 0 - 0 0
13 //        0 - + - 0
14 //        - + + + -
15 //        0 - + - 0
16 //        0 0 - 0 0
17 //
18 static int cr1_5x5 [] =
19 {
20     0, 0,-1, 0, 0,
21     0,-1, 1,-1, 0,
22    -1, 1, 1, 1,-1 ,
23     0,-1, 1,-1, 0,
24     0, 0,-1, 0, 0
25 };
26 
27 //        0 - - - 0
28 //        - + + + -
29 //        - + + + -
30 //        - + + + -
31 //        0 - - - 0
32 //
33 static int s1_5x5 [] =
34 {
35     0,-1,-1,-1, 0,
36    -1, 1, 1, 1,-1,
37    -1, 1, 1, 1,-1,
38    -1, 1, 1, 1,-1,
39     0,-1,-1,-1, 0,
40 };
41 
42 //        0 - - - 0
43 //        - + + + -
44 //        0 - - - 0
45 //
46 static int r10a0_3x5 [] =
47 {
48     0,-1,-1,-1, 0,
49     -1, 1, 1, 1,-1,
50     0,-1,-1,-1, 0
51 };
52 
53 //        0 0 0 - 0
54 //        0 0 - + -
55 //        0 - + - 0
56 //        - + - 0 0
57 //        0 - 0 0 0
58 //
59 static int r10a45_5x5 [] =
60 {
61     0,0,0,-1,0,
62     0,0,-1,1,-1,
63     0,-1,1,-1,0,
64     -1,1,-1,0,0,
65     0,-1,0,0,0
66 };
67 
68 //     0 - - - - - - - 0
69 //     - + + + + + + + -
70 //     0 - - - - - - - 0
71 //
72 static int r30a0_3x9 [] =
73 {
74     0,-1,-1,-1,-1,-1,-1,-1,0,
75     -1,1,1,1,1,1,1,1,-1,
76     0,-1,-1,-1,-1,-1,-1,-1,0
77 };
78 
79 //     0 0 0 0 0 0 - - 0
80 //     0 0 0 - - - + + -
81 //     0 - - + + + - - 0
82 //     - + + - - - 0 0 0
83 //     0 - - 0 0 0 0 0 0
84 //
85 static int r30a22_5x9 [] =
86 {
87     0,0,0,0,0,0,-1,-1,0,
88     0,0,0,-1,-1,-1,1,1,-1,
89     0,-1,-1,1,1,1,-1,-1,0,
90     -1,1,1,-1,-1,-1,0,0,0,
91     0,-1,-1,0,0,0,0,0,0
92 };
93 
94 //       0 0 0 0 0 - 0
95 //       0 0 0 0 - + -
96 //       0 0 0 - + - 0
97 //       0 0 - + - 0 0
98 //       0 - + - 0 0 0
99 //       - + - 0 0 0 0
100 //       0 - 0 0 0 0 0
101 //
102 static int r30a45_7x7 [] =
103 {
104     0,0,0,0,0,-1,0,
105     0,0,0,0,-1,1,-1,
106     0,0,0,-1,1,-1,0,
107     0,0,-1,1,-1,0,0,
108     0,-1,1,-1,0,0,0,
109     -1,1,-1,0,0,0,0,
110     0,-1,0,0,0,0,0
111 };
112 
113 //     0 - - - - - - - 0
114 //     - + + + + + + + -
115 //     - + + + + + + + -
116 //     - + + + + + + + -
117 //     0 - - - - - - - 0
118 //
119 static int r31a0_5x9 [] =
120 {
121     0,-1,-1,-1,-1,-1,-1,-1,0,
122     -1,1,1,1,1,1,1,1,-1,
123     -1,1,1,1,1,1,1,1,-1,
124     -1,1,1,1,1,1,1,1,-1,
125     0,-1,-1,-1,-1,-1,-1,-1,0
126 };
127 
128 //     0 0 0 0 - - - - 0
129 //     0 - - - + + + + -
130 //     - + + + + + + + -
131 //     - + + + + - - - 0
132 //     0 - - - - 0 0 0 0
133 //
134 static int r31a22_5x9 [] =
135 {
136     0,0,0,0,-1,-1,-1,-1,0,
137     0,-1,-1,-1,1,1,1,1,-1,
138     -1,1,1,1,1,1,1,1,-1,
139     -1,1,1,1,1,-1,-1,-1,0,
140     0,-1,-1,-1,-1,0,0,0,0
141 };
142 
143 //       0 0 0 0 - - 0
144 //       0 0 0 - + + -
145 //       0 0 - + + + -
146 //       0 - + + + - 0
147 //       - + + + - 0 0
148 //       - + + - 0 0 0
149 //       0 - - 0 0 0 0
150 //
151 static int r31a45_7x7 [] =
152 {
153     0,0,0,0,-1,-1,0,
154     0,0,0,-1,1,1,-1,
155     0,0,-1,1,1,1,-1,
156     0,-1,1,1,1,-1,0,
157     -1,1,1,1,-1,0,0,
158     -1,1,1,-1,0,0,0,
159     0,-1,-1,0,0,0,0
160 };
161 
162 //     0 - - - - - - - 0
163 //     - + + + + + + + -
164 //     - + + + + + + + -
165 //     - + + + + + + + -
166 //     - + + + + + + + -
167 //     - + + + + + + + -
168 //     0 - - - - - - - 0
169 //
170 static int r32a0_7x9 [] =
171 {
172     0,-1,-1,-1,-1,-1,-1,-1,0,
173     -1,1,1,1,1,1,1,1,-1,
174     -1,1,1,1,1,1,1,1,-1,
175     -1,1,1,1,1,1,1,1,-1,
176     -1,1,1,1,1,1,1,1,-1,
177     -1,1,1,1,1,1,1,1,-1,
178     0,-1,-1,-1,-1,-1,-1,-1,0
179 };
180 
181 //     0 0 0 - - - - - 0
182 //     0 0 - + + + + + -
183 //     0 - + + + + + + -
184 //     - + + + + + + + -
185 //     - + + + + + + - 0
186 //     - + + + + + - 0 0
187 //     0 - - - - - 0 0 0
188 //
189 static int r32a22_7x9 [] =
190 {
191     0,0,0,-1,-1,-1,-1,-1,0,
192     0,0,-1,1,1,1,1,1,-1,
193     0,-1,1,1,1,1,1,1,-1,
194     -1,1,1,1,1,1,1,1,-1,
195     -1,1,1,1,1,1,1,-1,0,
196     -1,1,1,1,1,1,-1,0,0,
197     0,-1,-1,-1,-1,-1,0,0,0
198 };
199 
200 //     0 0 0 0 0 - 0 0 0
201 //     0 0 0 0 - + - 0 0
202 //     0 0 0 - + + + - 0
203 //     0 0 - + + + + + -
204 //     0 - + + + + + - 0
205 //     - + + + + + - 0 0
206 //     0 - + + + - 0 0 0
207 //     0 0 - + - 0 0 0 0
208 //     0 0 0 - 0 0 0 0 0
209 //
210 static int r32a45_9x9 [] =
211 {
212     0,0,0,0,0,-1,0,0,0,
213     0,0,0,0,-1,1,-1,0,0,
214     0,0,0,-1,1,1,1,-1,0,
215     0,0,-1,1,1,1,1,1,-1,
216     0,-1,1,1,1,1,1,-1,0,
217     -1,1,1,1,1,1,-1,0,0,
218     0,-1,1,1,1,-1,0,0,0,
219     0,0,-1,1,-1,0,0,0,0,
220     0,0,0,-1,0,0,0,0,0
221 };
222 
223 //  0 - - - - - - - - - - - 0
224 //  - + + + + + + + + + + + -
225 //  - + + + + + + + + + + + -
226 //  - + + + + + + + + + + + -
227 //  - - - - - - - - - - - - 0
228 //
229 static int r51a0_5x13[] =
230 {
231     0,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,0,
232     -1,1,1,1,1,1,1,1,1,1,1,1,-1,
233     -1,1,1,1,1,1,1,1,1,1,1,1,-1,
234     -1,1,1,1,1,1,1,1,1,1,1,1,-1,
235     0,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,0
236 };
237 
238 //  0 0 0 0 0 0 0 0 0 - - - 0
239 //  0 0 0 0 0 0 0 0 - + + + -
240 //  0 0 0 0 0 - - - + + + + -
241 //  0 0 0 - - + + + + + + + -
242 //  0 - - + + + + + + + - - 0
243 //  - + + + + + + + - - 0 0 0
244 //  - + + + + - - - 0 0 0 0 0
245 //  - + + + - 0 0 0 0 0 0 0 0
246 //  0 - - - 0 0 0 0 0 0 0 0 0
247 //
248 static int r51a22_9x13[] =
249 {
250     0,0,0,0,0,0,0,0,0,-1,-1,-1,0,
251     0,0,0,0,0,0,0,0,-1,1,1,1,-1,
252     0,0,0,0,0,-1,-1,-1,1,1,1,1,-1,
253     0,0,0,-1,-1,1,1,1,1,1,1,1,-1,
254     0,-1,-1,1,1,1,1,1,1,1,-1,-1,0,
255     -1,1,1,1,1,1,1,1,-1,-1,0,0,0,
256     -1,1,1,1,1,-1,-1,-1,0,0,0,0,0,
257     -1,1,1,1,-1,0,0,0,0,0,0,0,0,
258     0,-1,-1,-1,0,0,0,0,0,0,0,0,0
259 };
260 
261 //   0 0 0 0 0 0 0 0 - - 0
262 //   0 0 0 0 0 0 0 - + + -
263 //   0 0 0 0 0 0 - + + + -
264 //   0 0 0 0 0 - + + + - 0
265 //   0 0 0 0 - + + + - 0 0
266 //   0 0 0 - + + + - 0 0 0
267 //   0 0 - + + + - 0 0 0 0
268 //   0 - + + + - 0 0 0 0 0
269 //   - + + + - 0 0 0 0 0 0
270 //   - + + - 0 0 0 0 0 0 0
271 //   0 - - 0 0 0 0 0 0 0 0
272 //
273 static int r51a45_11x11[] =
274 {
275     0,0,0,0,0,0,0,0,-1,-1,0,
276     0,0,0,0,0,0,0,-1,1,1,-1,
277     0,0,0,0,0,0,-1,1,1,1,-1,
278     0,0,0,0,0,-1,1,1,1,-1,0,
279     0,0,0,0,-1,1,1,1,-1,0,0,
280     0,0,0,-1,1,1,1,-1,0,0,0,
281     0,0,-1,1,1,1,-1,0,0,0,0,
282     0,-1,1,1,1,-1,0,0,0,0,0,
283     -1,1,1,1,-1,0,0,0,0,0,0,
284     -1,1,1,-1,0,0,0,0,0,0,0,
285     0,-1,-1,0,0,0,0,0,0,0,0
286 };
287 
288 //  - - - - - - - - - - - - -
289 //  - + + + + + + + + + + + -
290 //  - + + + + + + + + + + + -
291 //  - + + + + + + + + + + + -
292 //  - + + + + + + + + + + + -
293 //  - + + + + + + + + + + + -
294 //  - - - - - - - - - - - - -
295 //
296 static int r52a0_7x13[] =
297 {
298     -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
299     -1,1,1,1,1,1,1,1,1,1,1,1,-1,
300     -1,1,1,1,1,1,1,1,1,1,1,1,-1,
301     -1,1,1,1,1,1,1,1,1,1,1,1,-1,
302     -1,1,1,1,1,1,1,1,1,1,1,1,-1,
303     -1,1,1,1,1,1,1,1,1,1,1,1,-1,
304     -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1
305 };
306 
307 #if 0 // not used
308 //  0 0 0 0 0 0 0 0 - - - - 0
309 //  0 0 0 0 0 - - + + + + + -
310 //  0 0 0 0 - + + + + + + + -
311 //  0 0 0 - + + + + + + + - -
312 //  0 - - + + + + + + + - - 0
313 //  - - + + + + + + + - 0 0 0
314 //  - + + + + + + + - 0 0 0 0
315 //  - + + + + + - - 0 0 0 0 0
316 //  0 - - - - 0 0 0 0 0 0 0 0
317 //
318 static int r52a22_9x13[] =
319 {
320     0,0,0,0,0,0,0,0,0,-1,-1,-1,0,
321     0,0,0,0,0,-1,-1,1,1,1,1,1,-1,
322     0,0,0,0,-1,1,1,1,1,1,1,1,-1,
323     0,0,0,-1,1,1,1,1,1,1,1,-1,-1,
324     0,-1,-1,1,1,1,1,1,1,1,-1,-1,0,
325     -1,-1,1,1,1,1,1,1,1,-1,0,0,0,
326     -1,1,1,1,1,1,1,1,-1,0,0,0,0,
327     -1,1,1,1,1,1,-1,-1,0,0,0,0,0,
328     0,-1,-1,-1,-1,0,0,0,0,0,0,0,0
329 };
330 #endif // 0
331 
332 //  0 0 0 0 0 0 0 0 0 - 0 0 0
333 //  0 0 0 0 0 0 0 0 - + - 0 0
334 //  0 0 0 0 0 0 0 - + + + - 0
335 //  0 0 0 0 0 0 - + + + + + -
336 //  0 0 0 0 0 - + + + + + - 0
337 //  0 0 0 0 - + + + + + - 0 0
338 //  0 0 0 - + + + + + - 0 0 0
339 //  0 0 - + + + + + - 0 0 0 0
340 //  0 - + + + + + - 0 0 0 0 0
341 //  - + + + + + - 0 0 0 0 0 0
342 //  0 - + + + - 0 0 0 0 0 0 0
343 //  0 0 - + - 0 0 0 0 0 0 0 0
344 //  0 0 0 - 0 0 0 0 0 0 0 0 0
345 //
346 static int r52a45_13x13[] =
347 {
348    0,0,0,0,0,0,0,0,0,-1,0,0,0,
349    0,0,0,0,0,0,0,0,-1,1,-1,0,0,
350    0,0,0,0,0,0,0,0,-1,1,1,1,-1,
351    0,0,0,0,0,0,-1,1,1,1,1,1,-1,
352    0,0,0,0,0,-1,1,1,1,1,1,-1,0,
353    0,0,0,0,-1,1,1,1,1,1,-1,0,0,
354    0,0,0,-1,1,1,1,1,1,-1,0,0,0,
355    0,0,-1,1,1,1,1,1,-1,0,0,0,0,
356    0,-1,1,1,1,1,1,-1,0,0,0,0,0,
357    -1,1,1,1,1,1,-1,0,0,0,0,0,0,
358    0,-1,1,1,1,-1,0,0,0,0,0,0,0,
359    0,0,-1,1,-1,0,0,0,0,0,0,0,0,
360    0,0,0,-1,0,0,0,0,0,0,0,0,0
361 };
362 
363 //  0 0 0 0 0 0 0 0 0 0 0
364 //  0 0 0 0 0 0 - - - - 0
365 //  0 0 0 0 0 - + + + + -
366 //  0 0 0 0 - + + + + + -
367 //  0 0 0 - + + + + + + -
368 //  0 0 - + + + + + + + -
369 //  0 0 - + + + + + + - 0
370 //  0 - + + + + + + - 0 0
371 //  0 - + + + + + + - 0 0
372 //  0 0 - + + + + - 0 0 0
373 //  0 0 0 - - - - 0 0 0 0
374 //
375 static int b0_11x11[] =
376 {
377     0,0,0,0,0,0,0,0,0,0,0,
378     0,0,0,0,0,0,-1,-1,-1,-1,0,
379     0,0,0,0,0,-1,1,1,1,1,-1,
380     0,0,0,0,-1,1,1,1,1,1,-1,
381     0,0,0,-1,1,1,1,1,1,1,-1,
382     0,0,-1,1,1,1,1,1,1,1,-1,
383     0,0,-1,1,1,1,1,1,1,-1,0,
384     0,-1,1,1,1,1,1,1,-1,0,0,
385     0,0,-1,1,1,1,1,-1,0,0,0,
386     0,0,0,-1,-1,-1,-1,0,0,0,0
387 };
388 
389 //    0 0 0 0 0 0 0 0 0
390 //    0 - - - - - 0 0 0
391 //    - + + + + + - 0 0
392 //    - + + + + + - 0 0
393 //    - + + + + + + - 0
394 //    0 - + + + + - 0 0
395 //    0 0 - + + + + - 0
396 //    0 0 0 - + + + - 0
397 //    0 0 0 0 - - - 0 0
398 //
399 static int b1_9x9[] =
400 {
401     0,0,0,0,0,0,0,0,0,
402     0,-1,-1,-1,-1,-1,0,0,0,
403     -1,1,1,1,1,1,-1,0,0,
404     -1,1,1,1,1,1,-1,0,0,
405     -1,1,1,1,1,1,1,-1,0,
406     0,-1,1,1,1,1,-1,0,0,
407     0,0,-1,1,1,1,1,-1,0,
408     0,0,0,-1,1,1,1,-1,0,
409     0,0,0,0,-1,-1,-1,0,0
410 };
411 
412 //  0 0 0 0 0 0 0 0 0 0 0
413 //  0 0 0 0 - - - - - - 0
414 //  0 0 0 - + + + + + + -
415 //  0 0 0 - + + + + + + -
416 //  0 0 - + + + + + + - 0
417 //  0 0 - + + + + + + - 0
418 //  0 - + + + + + + - 0 0
419 //  0 - + + + + + + - 0 0
420 //  - + + + + + + - 0 0 0
421 //  - + + + + + + - 0 0 0
422 //  0 - - - - - - 0 0 0 0
423 //
424 static int b0s_11x11[] =
425 {
426     0,0,0,0,0,0,0,0,0,0,0,
427     0,0,0,0,-1,-1,-1,-1,-1,-1,0,
428     0,0,0,-1,1,1,1,1,1,1,-1,
429     0,0,0,-1,1,1,1,1,1,1,-1,
430     0,0,-1,1,1,1,1,1,1,-1,0,
431     0,0,-1,1,1,1,1,1,1,-1,0,
432     0,-1,1,1,1,1,1,1,-1,0,0,
433     0,-1,1,1,1,1,1,1,-1,0,0,
434     -1,1,1,1,1,1,1,-1,0,0,0,
435     -1,1,1,1,1,1,1,-1,0,0,0,
436     0,-1,-1,-1,-1,-1,-1,0,0,0,0
437 };
438 
439 //    0 0 0 0 0 0 0 0 0
440 //    0 - - - - - 0 0 0
441 //    - + + + + + - 0 0
442 //    - + + + + + - 0 0
443 //    - + + + + + + - 0
444 //    0 - + + + + + + -
445 //    0 0 - + + + + + -
446 //    0 0 - + + + + + -
447 //    0 0 - - - - - - 0
448 //
449 static int b1s_9x9[] =
450 {
451     0,0,0,0,0,0,0,0,0,
452     0,-1,-1,-1,-1,-1,0,0,0,
453     -1,1,1,1,1,1,-1,0,0,
454     -1,1,1,1,1,1,-1,0,0,
455     -1,1,1,1,1,1,1,-1,0,
456     0,-1,1,1,1,1,1,1,-1,
457     0,0,-1,1,1,1,1,1,-1,
458     0,0,-1,1,1,1,1,1,-1,
459     0,0,-1,-1,-1,-1,-1,0,0
460 };
461 
462 // ====================   Corners ===========================
463 
464 //    - - - - -
465 //    - + + + +
466 //    - + + + 0
467 //    - + + 0 0
468 //    - + 0 0 0
469 static int c4_90_0_5x5[] =
470 {
471     -1,-1,-1,-1,-1,
472     -1,1,1,1,1,
473     -1,1,1,1,0,
474     -1,1,1,0,0,
475     -1,1,0,0,0
476 };
477 
478 //   0 0 0 0 - - -
479 //   0 0 0 - - - -
480 //   0 0 - + + + +
481 //   0 - + + + + 0
482 //   - + + + + 0 0
483 //
484 static int c4_45_0_5x7[] =
485 {
486     0,0,0,0,-1,-1,-1,
487     0,0,0,-1,-1,-1,-1,
488     0,0,-1,1,1,1,1,
489     0,-1,1,1,1,1,0,
490     -1,1,1,1,1,0,0
491 };
492 
493 //    0 0 0 0 0 0 0
494 //    0 0 0 - 0 0 0
495 //    0 0 - + - 0 0
496 //    0 - + + + - 0
497 //    - + + + + + -
498 //
499 static int c4_45_45_5x7[] =
500 {
501      0, 0, 0, 0, 0, 0, 0,
502      0, 0, 0,-1, 0, 0, 0,
503      0, 0,-1, 1,-1, 0, 0,
504      0,-1, 1, 1, 1,-1, 0,
505     -1, 1, 1, 1, 1, 1,-1
506 };
507 //====================== extrema ==========================
508 //   0 - 0
509 //   - + -
510 //   0 - 0
511 static int m1a0_3x3[] =
512 {
513      0, -1,  0,
514     -1,  1, -1,
515      0, -1,  0
516 };
517 
518 //   - + -
519 //   + + +
520 //   - + -
521 static int m4a0_3x3[] =
522 {
523     -1, 1,-1,
524      1, 1, 1,
525     -1, 1,-1
526 };
527 
528 //  0 0 - 0 0
529 //  0 - + - 0
530 //  - + + + -
531 //  0 - + - 0
532 //  0 0 - 0 0
533 static int m4sa0_5x5[] =
534 {
535      0, 0,-1, 0, 0,
536      0,-1, 1,-1, 0,
537     -1, 1, 1, 1,-1,
538      0,-1, 1,-1, 0,
539      0, 0,-1, 0, 0};
540 
541 // 0 0 0 - 0 0 0
542 // 0 0 - + - 0 0
543 // 0 - + + + - 0
544 // - + + + + + -
545 // 0 - + + + - 0
546 // 0 0 - + - 0 0
547 // 0 0 0 - 0 0 0
548 static int m7a0_7x7[] =
549 {
550      0, 0, 0,-1, 0, 0, 0,
551      0, 0,-1, 1,-1, 0, 0,
552      0,-1, 1, 1, 1,-1, 0,
553     -1, 1, 1, 1, 1, 1,-1,
554      0,-1, 1, 1, 1,-1, 0,
555      0, 0,-1, 1,-1, 0, 0,
556      0, 0, 0,-1, 0, 0, 0
557 };
558 
559 //=======================   edges =========================
560 
561 //   0 - 0
562 //   0 + 0
563 //   0 0 0
564 static int e2a0_3x3[] =
565 {
566     0,-1, 0,
567     0, 1, 0,
568     0, 0, 0
569 };
570 
571 //    - 0 0
572 //    0 + 0
573 //    0 0 0
574 static int e2a45_3x3[] =
575 {
576     -1, 0, 0,
577      0, 1, 0,
578      0, 0, 0
579 };
580 
581 //        - - -
582 //        + + +
583 //        + + +
584 
585 //
586 static int e3a0_3x3[] =
587 {
588     -1,-1,-1,
589      1, 1, 1,
590      1, 1, 1
591 };
592 
593 //  0 0 - + +
594 //  0 - + + 0
595 //  - + + 0 0
596 static int e3a45_3x5[] =
597 {
598      0, 0,-1, 1, 1,
599      0,-1, 1, 1, 0,
600     -1, 1, 1, 0, 0
601 };
602 
603 //       - - - - -
604 //       - - - - -
605 //       + + + + +
606 //       + + + + +
607 //       + + + + +
608 //
609 static int e5a0_5x5[] =
610 {
611     -1,-1,-1,-1,-1,
612     -1,-1,-1,-1,-1,
613     1,1,1,1,1,
614     1,1,1,1,1,
615     1,1,1,1,1
616 };
617 
618 #if 0 // not used
619 //   0 0 - - -
620 //   - - - - -
621 //   - - + + +
622 //   + + + + +
623 //   + + + 0 0
624 //
625 static int e5a22_5x5[] =
626 {
627     0,0,-1,-1,-1,
628     -1,-1,-1,-1,-1,
629     -1,-1,1,1,1,
630     1,1,1,1,1,
631     1,1,1,0,0
632 };
633 #endif
634 
635 //  0 - - - +
636 //  - - - + +
637 //  - - + + +
638 //  - + + + 0
639 //  + + + 0 0
640 //
641 static int e5a45_5x5[] =
642 {
643     0,-1,-1,-1,1,
644     -1,-1,-1,1,1,
645     -1,-1,1,1,1,
646     -1,1,1,1,0,
647     1,1,1,0,0
648 };
649 
650 //  - - - - - - - - - - -
651 //  - - - - - - - - - - -
652 //  + + + + + + + + + + +
653 //  + + + + + + + + + + +
654 //  + + + + + + + + + + +
655 //
656 static int e11a0_5x11[] =
657 {
658     -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
659     -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
660     1,1,1,1,1,1,1,1,1,1,1,
661     1,1,1,1,1,1,1,1,1,1,1,
662     1,1,1,1,1,1,1,1,1,1,1
663 };
664 //======================== region types ======================
665 //
666 //  all foreground
667 //   + + + + +
668 //   + + + + +
669 //   + + + + +
670 //   + + + + +
671 //   + + + + +
672 static int f5a0_5x5[] =
673 {
674     1, 1, 1, 1, 1,
675     1, 1, 1, 1, 1,
676     1, 1, 1, 1, 1,
677     1, 1, 1, 1, 1,
678     1, 1, 1, 1, 1
679 };
680 
681 //    0 + 0
682 //    + + +
683 //    0 + 0
684 static int f3a0_3x3[] =
685 {
686    0,1,0,
687    1,1,1,
688    0,1,0
689 };
690 
691 //  all background
692 //   - - - - -
693 //   - - - - -
694 //   - - - - -
695 //   - - - - -
696 //   - - - - -
697 static int b5a0_5x5[] =
698 {
699     -1,-1,-1,-1,-1,
700     -1,-1,-1,-1,-1,
701     -1,-1,-1,-1,-1,
702     -1,-1,-1,-1,-1,
703     -1,-1,-1,-1,-1
704 };
705 
706 //  all background
707 //  0 0 0 - 0 0 0
708 //  0 0 - - - 0 0
709 //  0 - - - - - 0
710 //  - - - - - - -
711 //  0 - - - - - 0
712 //  0 0 - - - 0 0
713 //  0 0 0 - 0 0 0
714 static int b7a0_7x7[] =
715 {
716      0, 0, 0,-1, 0, 0, 0,
717      0, 0,-1,-1,-1, 0, 0,
718      0,-1,-1,-1,-1,-1, 0,
719     -1,-1,-1,-1,-1,-1,-1,
720      0,-1,-1,-1,-1,-1, 0,
721      0, 0,-1,-1,-1, 0, 0,
722      0, 0, 0,-1, 0, 0, 0,
723 };
724 
725 // 0 0 0 - 0 0 0
726 // 0 0 - + - 0 0
727 // 0 - + + + - 0
728 // - + + + + + -
729 // 0 - + + + - 0
730 // 0 0 - + - 0 0
731 // 0 0 0 - 0 0 0
732 static int b7a1_7x7[] =
733 {
734      0, 0, 0,-1, 0, 0, 0,
735      0, 0,-1, 1,-1, 0, 0,
736      0,-1, 1, 1, 1,-1, 0,
737     -1, 1, 1, 1, 1, 1,-1,
738      0,-1, 1, 1, 1,-1, 0,
739      0, 0,-1, 1,-1, 0, 0,
740      0, 0, 0,-1, 0, 0, 0,
741 };
742 
743 //    0 - 0
744 //    - - -
745 //    0 - 0
746 static int b3a0_3x3[] =
747 {
748     0,-1, 0,
749    -1,-1,-1,
750     0,-1, 0
751 };
752 
reflect_about_vert(vnl_matrix<int> const & m)753 vnl_matrix<int> reflect_about_vert(vnl_matrix<int> const& m)
754 {
755   unsigned nc = m.cols(), nr = m.rows();
756   vnl_matrix<int> ref(nr, nc);
757   int rc = (nc-1)/2;
758   for (unsigned r = 0; r<nr; ++r)
759     for (int c = -rc; c<=rc; ++c)
760       ref[r][rc+c] = m[r][rc-c];
761   return ref;
762 }
763 
764 #if 0
765 vnl_matrix<int> reflect_about_vert_even(vnl_matrix<int> const& m)
766 {
767   unsigned nc = m.cols(), nr = m.rows();
768   vnl_matrix<int> ref(nr, nc);
769   int rc = nc/2;
770   for (unsigned r = 0; r<nr; ++r)
771     for (int c = -rc; c<=rc; ++c)
772       ref[r][rc+c] = m[r][rc-c];
773   return ref;
774 }
775 #endif
776 
reflect_about_horz(vnl_matrix<int> const & m)777 vnl_matrix<int> reflect_about_horz(vnl_matrix<int> const& m)
778 {
779   unsigned nc = m.cols(), nr = m.rows();
780   vnl_matrix<int> ref(nr, nc);
781   int rr = (nr-1)/2;
782   for (unsigned c = 0; c<nc; ++c)
783     for (int r = -rr; r<=rr; ++r)
784       ref[rr+r][c] = m[rr-r][c];
785   return ref;
786 }
787 
788 #if 0
789 vnl_matrix<int> reflect_about_horz_even(vnl_matrix<int> const& m)
790 {
791   unsigned nc = m.cols(), nr = m.rows();
792   vnl_matrix<int> ref(nr, nc);
793   int rr = nr-1/2;
794   for (unsigned c = 0; c<nc; ++c)
795     for (int r = -rr; r<=rr; ++r)
796       ref[rr+r][c] = m[rr-r][c];
797   return ref;
798 }
799 #endif
800 
brip_rect_mask(mask_id mid)801 brip_rect_mask::brip_rect_mask(mask_id mid)
802 {
803   switch (mid)
804     {
805     case cr1:{
806       vnl_matrix<int> cr1a0(cr1_5x5, 5, 5);
807       masks_[a0] =    cr1a0;
808       break;
809     }
810     case s1:{
811       vnl_matrix<int> s1a0(s1_5x5, 5, 5);
812       masks_[a0] =    s1a0;
813       break;
814     }
815     case b0:{
816       vnl_matrix<int> b0a0(b0_11x11, 11, 11);
817       masks_[a0] =    b0a0;
818       break;
819     }
820     case b1:{
821       vnl_matrix<int> b1a0(b1_9x9, 9, 9);
822       masks_[a0] =    b1a0;
823       break;
824     }
825     case b0s:{
826       vnl_matrix<int> b0sa0(b0s_11x11, 11, 11);
827       masks_[a0] =    b0sa0;
828       break;
829     }
830     case b1s:{
831       vnl_matrix<int> b1sa0(b1s_9x9, 9, 9);
832       masks_[a0] =    b1sa0;
833       break;
834     }
835     case r10:{
836       vnl_matrix<int> r10a0(r10a0_3x5, 3, 5), r10a45(r10a45_5x5, 5, 5);
837       masks_[a0] =    r10a0;
838       masks_[a45]  =  r10a45;
839       masks_[a90]  =  r10a0.transpose();
840       masks_[a135] =  reflect_about_vert(r10a45);
841       break;
842     }
843     case r30: {
844       vnl_matrix<int> r30a0(r30a0_3x9, 3, 9), r30a22(r30a22_5x9, 5, 9),
845         r30a45(r30a45_7x7, 7, 7);
846       masks_[a0] =    r30a0;
847       masks_[a22] =   r30a22;
848       masks_[a45] =   r30a45;
849       masks_[a67]  =  r30a22.transpose();
850       masks_[a90]  =  r30a0.transpose();
851       masks_[a112] =  reflect_about_vert(r30a22.transpose());
852       masks_[a135] =  reflect_about_vert(r30a45);
853       masks_[a157] =  reflect_about_horz(r30a22);
854       break;
855     }
856     case r31: {
857       vnl_matrix<int> r31a0(r31a0_5x9, 5, 9), r31a22(r31a22_5x9, 5, 9),
858         r31a45(r31a45_7x7, 7, 7);
859       masks_[a0] =    r31a0;
860       masks_[a22] =   r31a22;
861       masks_[a45] =   r31a45;
862       masks_[a67]  =  r31a22.transpose();
863       masks_[a90]  =  r31a0.transpose();
864       masks_[a112] =  reflect_about_vert(r31a22.transpose());
865       masks_[a135] =  reflect_about_vert(r31a45);
866       masks_[a157] =  reflect_about_horz(r31a22);
867       break;
868     }
869     case r32: {
870       vnl_matrix<int> r32a0(r32a0_7x9, 7, 9), r32a22(r32a22_7x9, 7, 9),
871         r32a45(r32a45_9x9, 9, 9);
872       masks_[a0] =    r32a0;
873       masks_[a22] =   r32a22;
874       masks_[a45] =   r32a45;
875       masks_[a67]  =  r32a22.transpose();
876       masks_[a90]  =  r32a0.transpose();
877       masks_[a112] =  reflect_about_vert(r32a22.transpose());
878       masks_[a135] =  reflect_about_vert(r32a45);
879       masks_[a157] =  reflect_about_horz(r32a22);
880       break;
881     }
882     case r51: {
883       vnl_matrix<int> r51a0(r51a0_5x13, 5, 13),  r51a22(r51a22_9x13, 9, 13),
884         r51a45(r51a45_11x11, 11, 11);
885       masks_[a0] =    r51a0;
886       masks_[a22] =   r51a22;
887       masks_[a45] =   r51a45;
888       masks_[a67]  =  r51a22.transpose();
889       masks_[a90]  =  r51a0.transpose();
890       masks_[a112] =  reflect_about_vert(r51a22.transpose());
891       masks_[a135] =  reflect_about_vert(r51a45);
892       masks_[a157] =  reflect_about_horz(r51a22);
893       break;
894     }
895     case r52: {
896       vnl_matrix<int> r52a0(r52a0_7x13, 7, 13),  r52a22(r51a22_9x13, 9, 13),
897         r52a45(r52a45_13x13, 13, 13);
898       masks_[a0] =    r52a0;
899       masks_[a22] =   r52a22;
900       masks_[a45] =   r52a45;
901       masks_[a67]  =  r52a22.transpose();
902       masks_[a90]  =  r52a0.transpose();
903       masks_[a112] =  reflect_about_vert(r52a22.transpose());
904       masks_[a135] =  reflect_about_vert(r52a45);
905       masks_[a157] =  reflect_about_horz(r52a22);
906       break;
907     }
908     case c4_90_0: {
909       vnl_matrix<int> c4_90_0a0(c4_90_0_5x5, 5, 5);
910       masks_[a0] =    c4_90_0a0;
911       masks_[a90] =   reflect_about_vert(c4_90_0a0);
912       masks_[a180] =   reflect_about_horz(c4_90_0a0);
913       masks_[a270] =   reflect_about_horz(reflect_about_vert(c4_90_0a0));
914       break;
915     }
916     case c4_45_0: {
917       vnl_matrix<int> c4_45_0a0(c4_45_0_5x7, 5, 7);
918       masks_[a0] =    c4_45_0a0;
919       masks_[a45]=    c4_45_0a0.transpose();
920       masks_[a90] =   reflect_about_vert(c4_45_0a0);
921       masks_[a135] =  reflect_about_vert(c4_45_0a0.transpose());
922       masks_[a180] =   reflect_about_horz(c4_45_0a0);
923       masks_[a225]= reflect_about_horz(reflect_about_vert(c4_45_0a0.transpose()));
924       masks_[a270] =  reflect_about_horz(reflect_about_vert(c4_45_0a0));
925       break;
926     }
927     case c4_45_45: {
928       vnl_matrix<int> c4_45_45a0(c4_45_45_5x7, 5, 7);
929       masks_[a0] =    c4_45_45a0;
930       masks_[a90] =   c4_45_45a0.transpose();
931       masks_[a180] =  reflect_about_horz(c4_45_45a0);
932       masks_[a270] =  reflect_about_horz(c4_45_45a0).transpose();
933       break;
934     }
935     case e2:{
936       vnl_matrix<int> e2a0(e2a0_3x3, 3, 3), e2a45(e2a45_3x3, 3, 3);
937       masks_[a0] =    e2a0;
938       masks_[a45] =   e2a45;
939       masks_[a90]  =  e2a0.transpose();
940       masks_[a135]  =  reflect_about_horz(e2a45);
941       masks_[a180]  =  reflect_about_horz(e2a0);
942       masks_[a225] =  reflect_about_vert(reflect_about_horz(e2a45));
943       masks_[a270]  =  reflect_about_vert(e2a0.transpose());
944       masks_[a315]  =  reflect_about_vert(e2a45.transpose());
945       break;
946     }
947     case e3:{
948       vnl_matrix<int> e3a0(e3a0_3x3, 3, 3), e3a45(e3a45_3x5, 3, 5);
949       masks_[a0] =    e3a0;
950       masks_[a45] =   e3a45;
951       masks_[a90]  =  e3a0.transpose();
952       masks_[a135]  =  reflect_about_horz(e3a45);
953       masks_[a180]  =  reflect_about_horz(e3a0);
954       masks_[a225] =  reflect_about_vert(reflect_about_horz(e3a45));
955       masks_[a270]  =  reflect_about_vert(e3a0.transpose());
956       masks_[a315]  =  reflect_about_vert(e3a45.transpose());
957       break;
958     }
959     case e5:{
960       vnl_matrix<int> e5a0(e5a0_5x5, 5, 5), e5a45(e5a45_5x5, 5, 5);
961       masks_[a0] =    e5a0;
962       masks_[a45] =   e5a45;
963       masks_[a90]  =  e5a0.transpose();
964       masks_[a135]  =  reflect_about_horz(e5a45);
965       masks_[a180]  =  reflect_about_horz(e5a0);
966       masks_[a225] =  reflect_about_vert(reflect_about_horz(e5a45));
967       masks_[a270]  =  reflect_about_vert(e5a0.transpose());
968       masks_[a315]  =  reflect_about_vert(e5a45.transpose());
969       break;
970     }
971     case e11:{
972       vnl_matrix<int> e11a0(e11a0_5x11, 5, 11);
973       masks_[a0] =    e11a0;
974       masks_[a90]  =  e11a0.transpose();
975       masks_[a180]  =  reflect_about_horz(e11a0);
976       masks_[a270]  =  reflect_about_vert(e11a0.transpose());
977       break;
978     }
979     case m1:{
980       vnl_matrix<int> m1a0(m1a0_3x3, 3, 3);
981       masks_[a0] =    m1a0;
982       break;
983     }
984     case m4:{
985       vnl_matrix<int> m4a0(m4a0_3x3, 3, 3);
986       masks_[a0] =    m4a0;
987       break;
988     }
989     case m4s:{
990       vnl_matrix<int> m4sa0(m4sa0_5x5, 5, 5);
991       masks_[a0] =    m4sa0;
992       break;
993     }
994     case m7:{
995       vnl_matrix<int> m7a0(m7a0_7x7, 7, 7);
996       masks_[a0] =    m7a0;
997       break;
998     }
999     case f3:{
1000       vnl_matrix<int> f3a0(f3a0_3x3, 3, 3);
1001       masks_[a0] =    f3a0;
1002       break;
1003     }
1004     case b3:{
1005       vnl_matrix<int> b3a0(b3a0_3x3, 3, 3);
1006       masks_[a0] =    b3a0;
1007       break;
1008     }
1009     case f5:{
1010       vnl_matrix<int> f5a0(f5a0_5x5, 5, 5);
1011       masks_[a0] =    f5a0;
1012       break;
1013     }
1014     case b5:{
1015       vnl_matrix<int> b5a0(b5a0_5x5, 5, 5);
1016       masks_[a0] =    b5a0;
1017       break;
1018     }
1019     case b7:{
1020       vnl_matrix<int> b7a0(b7a0_7x7, 7, 7);
1021       vnl_matrix<int> b7a1(b7a1_7x7, 7, 7);
1022       masks_[a0] =    b7a1; // unused
1023       masks_[a0] =    b7a0;
1024       break;
1025     }
1026 
1027     default:
1028       std::cout << "specified mask does not exist\n";
1029     };
1030 }
1031 
1032 bool brip_rect_mask::
find_ait(ang_id aid,std::map<ang_id,vnl_matrix<int>>::const_iterator & ait) const1033 find_ait(ang_id aid,
1034          std::map<ang_id, vnl_matrix<int> >::const_iterator& ait) const
1035 {
1036   ait = masks_.find(aid);
1037   if (ait == masks_.end())
1038     return false;
1039   return true;
1040 }
1041 
angle_id(unsigned angle_index) const1042 brip_rect_mask::ang_id brip_rect_mask::angle_id(unsigned angle_index) const
1043 {
1044   auto ait = masks_.begin();
1045   for (unsigned i = 0; i<angle_index; ++i)
1046     ++ait;
1047   return (*ait).first;
1048 }
1049 
set_angle_id(ang_id aid)1050 bool brip_rect_mask::set_angle_id(ang_id aid)
1051 {
1052   std::map<ang_id, vnl_matrix<int> >::const_iterator ait;
1053   bool found = find_ait(aid, ait);
1054   if (!found) {
1055     ru_ = 0; rv_ = 0;
1056     return false;
1057   }
1058   current_mask_ = (*ait).second;
1059   ru_ = (current_mask_.cols()-1)/2;
1060   rv_ = (current_mask_.rows()-1)/2;
1061   return true;
1062 }
1063 
init()1064 void brip_rect_mask::init()
1065 {
1066   if (!is_init_) {
1067     names_[a0]="0 deg";       angles_[a0]=0.0f;
1068     names_[a22]="22.5 deg";   angles_[a22]=22.5f;
1069     names_[a45]="45 deg";     angles_[a45]=45.0f;
1070     names_[a67]="67.5 deg";   angles_[a67]=67.5f;
1071     names_[a90]="90 deg";     angles_[a90]=90.0f;
1072     names_[a112]="112.5 deg"; angles_[a112]=112.5f;
1073     names_[a135]="135 deg";   angles_[a135]=135.0f;
1074     names_[a157]="157.5 deg"; angles_[a157]=157.5f;
1075     names_[a180]="180 deg";   angles_[a180]=180.0f;
1076     names_[a202]="202.5 deg"; angles_[a202]=202.5f;
1077     names_[a225]="225 deg";   angles_[a225]=225.0f;
1078     names_[a247]="247.5 deg"; angles_[a247]=247.5f;
1079     names_[a270]="270 deg";   angles_[a270]=270.0f;
1080     names_[a292]="292.5 deg"; angles_[a292]=292.5f;
1081     names_[a315]="315 deg";   angles_[a315]=315.0f;
1082     names_[a337]="337.5 deg"; angles_[a337]=337.5f;
1083     is_init_ = true;
1084   }
1085 }
1086 
name(ang_id aid)1087 std::string brip_rect_mask::name(ang_id aid)
1088 {
1089   init();
1090   std::map<ang_id, std::string >::const_iterator ait;
1091   ait = names_.find(aid);
1092   if (ait == names_.end())
1093     return "null";
1094   return (*ait).second;
1095  }
1096 
angle(ang_id aid)1097 float brip_rect_mask::angle(ang_id aid)
1098 {
1099   init();
1100   std::map<ang_id, float >::const_iterator ait;
1101   ait = angles_.find(aid);
1102   if (ait == angles_.end())
1103     return 0.0f;
1104   return (*ait).second;
1105  }
1106 
nplus() const1107 unsigned brip_rect_mask::nplus() const
1108 {
1109   unsigned np = 0;
1110   vnl_matrix<int> const& weights = current_mask_;
1111   for (int weight : weights)
1112     if (weight>0) ++np;
1113   return np;
1114 }
1115 
nminus() const1116 unsigned brip_rect_mask::nminus() const
1117 {
1118   unsigned np = 0;
1119   vnl_matrix<int> const& weights = current_mask_;
1120   for (int weight : weights)
1121     if (weight<0) ++np;
1122   return np;
1123 }
1124 
ang_diff(ang_id aid0,ang_id aid1)1125 float brip_rect_mask::ang_diff(ang_id aid0,ang_id aid1)
1126 {
1127   float diff = brip_rect_mask::angle(aid1)-brip_rect_mask::angle(aid0);
1128   if (diff>180.0f) diff-=360.0f;
1129   if (diff<-180.0f) diff+=360.0f;
1130   return diff;
1131 }
1132 
intersect(mask_id mid,ang_id aid0,unsigned short i0,unsigned short j0,ang_id aid1,unsigned short i1,unsigned short j1)1133 bool brip_rect_mask::intersect(mask_id mid,
1134                                ang_id aid0,
1135                                unsigned short i0, unsigned short j0,
1136                                ang_id aid1,
1137                                unsigned short i1, unsigned short j1)
1138 {
1139   brip_rect_mask m0(mid), m1(mid);
1140   m0.set_angle_id(aid0);
1141   m1.set_angle_id(aid1);
1142   unsigned ni0 = m0.ni(), nj0 = m0.nj(), ni1 = m1.ni(), nj1 = m1.nj();
1143   int  ru0 = (ni0-1)/2, rv0 = (nj0-1)/2;
1144   int ru1 = (ni1-1)/2, rv1 = (nj1-1)/2;
1145   for (int jr0 = -rv0; jr0<=rv0; ++jr0)
1146     for (int ir0 = -ru0; ir0<=ru0; ++ir0)
1147       if (m0(ir0,jr0)>0)
1148           for (int jr1 = -rv1; jr1<=rv1; ++jr1)
1149             for (int ir1 = -ru1; ir1<=ru1; ++ir1)
1150               if (m1(ir1,jr1)>0)
1151                 if ((i0+ir0)==(i1+ir1)&&(j0+jr0)==(j1+jr1))
1152                   return true;
1153   return false;
1154 }
1155 
intersect_domain(mask_id mid,ang_id aid0,unsigned short i0,unsigned short j0,ang_id aid1,unsigned short i1,unsigned short j1)1156 bool brip_rect_mask::intersect_domain(mask_id mid,
1157                                       ang_id aid0,
1158                                       unsigned short i0, unsigned short j0,
1159                                       ang_id aid1,
1160                                       unsigned short i1, unsigned short j1)
1161 {
1162   brip_rect_mask m0(mid), m1(mid);
1163   m0.set_angle_id(aid0);
1164   m1.set_angle_id(aid1);
1165   unsigned ni0 = m0.ni(), nj0 = m0.nj(), ni1 = m1.ni(), nj1 = m1.nj();
1166   int  ru0 = (ni0-1)/2, rv0 = (nj0-1)/2;
1167   int ru1 = (ni1-1)/2, rv1 = (nj1-1)/2;
1168   for (int jr0 = -rv0; jr0<=rv0; ++jr0)
1169     for (int ir0 = -ru0; ir0<=ru0; ++ir0)
1170       for (int jr1 = -rv1; jr1<=rv1; ++jr1)
1171         for (int ir1 = -ru1; ir1<=ru1; ++ir1)
1172           if ((i0+ir0)==(i1+ir1)&&(j0+jr0)==(j1+jr1))
1173             return true;
1174   return false;
1175 }
1176 
print(ang_id aid)1177 void brip_rect_mask::print(ang_id aid)
1178 {
1179   std::map<ang_id, vnl_matrix<int> >::const_iterator ait;
1180   bool found = find_ait(aid, ait);
1181   if (!found) {
1182     std::cout<< "no such angle\n";
1183     return;
1184   }
1185   vnl_matrix<int> msk = (*ait).second;
1186   int ri = (msk.cols()-1)/2, rj = (msk.rows()-1)/2;
1187   for (int jr = -rj; jr<=rj ; ++jr) {
1188     for (int ir = -ri; ir<= ri; ++ir)
1189     {
1190       int m = msk(jr+rj, ir+ri);
1191       if (m >0)
1192         std::cout << '+' << ' ';
1193       else if (m<0)
1194         std::cout << '-' << ' ';
1195       else
1196         std::cout << '0' << ' ';
1197     }
1198     std::cout << '\n';
1199   }
1200   std::cout<< '\n';
1201 }
1202 
operator <<(std::ostream & s,brip_rect_mask const & msk)1203 std::ostream& operator<<(std::ostream& s, brip_rect_mask const& msk)
1204 {
1205   s << "masks\n";
1206   auto& msk_nc = const_cast<brip_rect_mask&>(msk);
1207   unsigned nangles = msk.n_angles();
1208   for (unsigned a = 0; a<nangles; ++a) {
1209     brip_rect_mask::ang_id aid = msk.angle_id(a);
1210     msk_nc.set_angle_id(aid);
1211     unsigned ni =msk_nc.ni(), nj = msk_nc.nj();
1212     int ri = (ni-1)/2, rj = (nj-1)/2;
1213     for (int jr = -rj; jr<=rj ; ++jr) {
1214       for (int ir = -ri; ir<= ri; ++ir)
1215       {
1216         int m = msk_nc(ir,jr);
1217         if (m >0)
1218           s << '+' << ' ';
1219         else if (m<0)
1220           s << '-' << ' ';
1221         else
1222           s << '0' << ' ';
1223       }
1224       s << '\n';
1225     }
1226     s<< '\n';
1227   }
1228   return s;
1229 }
1230