00001 #include "brip_rect_mask.h"
00002
00003 #include <vcl_iostream.h>
00004
00005 vcl_map<brip_rect_mask::ang_id, vcl_string > brip_rect_mask::names_=vcl_map<brip_rect_mask::ang_id, vcl_string >();
00006 vcl_map<brip_rect_mask::ang_id, float > brip_rect_mask::angles_=vcl_map<brip_rect_mask::ang_id, float >();
00007 bool brip_rect_mask::is_init_ = false;
00008
00009
00010
00011
00012
00013
00014
00015 static int cr1_5x5 [] =
00016 {
00017 0, 0,-1, 0, 0,
00018 0,-1, 1,-1, 0,
00019 -1, 1, 1, 1,-1 ,
00020 0,-1, 1,-1, 0,
00021 0, 0,-1, 0, 0
00022 };
00023
00024
00025
00026
00027
00028
00029
00030 static int s1_5x5 [] =
00031 {
00032 0,-1,-1,-1, 0,
00033 -1, 1, 1, 1,-1,
00034 -1, 1, 1, 1,-1,
00035 -1, 1, 1, 1,-1,
00036 0,-1,-1,-1, 0,
00037 };
00038
00039
00040
00041
00042
00043 static int r10a0_3x5 [] =
00044 {
00045 0,-1,-1,-1, 0,
00046 -1, 1, 1, 1,-1,
00047 0,-1,-1,-1, 0
00048 };
00049
00050
00051
00052
00053
00054
00055
00056 static int r10a45_5x5 [] =
00057 {
00058 0,0,0,-1,0,
00059 0,0,-1,1,-1,
00060 0,-1,1,-1,0,
00061 -1,1,-1,0,0,
00062 0,-1,0,0,0
00063 };
00064
00065
00066
00067
00068
00069 static int r30a0_3x9 [] =
00070 {
00071 0,-1,-1,-1,-1,-1,-1,-1,0,
00072 -1,1,1,1,1,1,1,1,-1,
00073 0,-1,-1,-1,-1,-1,-1,-1,0
00074 };
00075
00076
00077
00078
00079
00080
00081
00082 static int r30a22_5x9 [] =
00083 {
00084 0,0,0,0,0,0,-1,-1,0,
00085 0,0,0,-1,-1,-1,1,1,-1,
00086 0,-1,-1,1,1,1,-1,-1,0,
00087 -1,1,1,-1,-1,-1,0,0,0,
00088 0,-1,-1,0,0,0,0,0,0
00089 };
00090
00091
00092
00093
00094
00095
00096
00097
00098
00099 static int r30a45_7x7 [] =
00100 {
00101 0,0,0,0,0,-1,0,
00102 0,0,0,0,-1,1,-1,
00103 0,0,0,-1,1,-1,0,
00104 0,0,-1,1,-1,0,0,
00105 0,-1,1,-1,0,0,0,
00106 -1,1,-1,0,0,0,0,
00107 0,-1,0,0,0,0,0
00108 };
00109
00110
00111
00112
00113
00114
00115
00116 static int r31a0_5x9 [] =
00117 {
00118 0,-1,-1,-1,-1,-1,-1,-1,0,
00119 -1,1,1,1,1,1,1,1,-1,
00120 -1,1,1,1,1,1,1,1,-1,
00121 -1,1,1,1,1,1,1,1,-1,
00122 0,-1,-1,-1,-1,-1,-1,-1,0
00123 };
00124
00125
00126
00127
00128
00129
00130
00131 static int r31a22_5x9 [] =
00132 {
00133 0,0,0,0,-1,-1,-1,-1,0,
00134 0,-1,-1,-1,1,1,1,1,-1,
00135 -1,1,1,1,1,1,1,1,-1,
00136 -1,1,1,1,1,-1,-1,-1,0,
00137 0,-1,-1,-1,-1,0,0,0,0
00138 };
00139
00140
00141
00142
00143
00144
00145
00146
00147
00148 static int r31a45_7x7 [] =
00149 {
00150 0,0,0,0,-1,-1,0,
00151 0,0,0,-1,1,1,-1,
00152 0,0,-1,1,1,1,-1,
00153 0,-1,1,1,1,-1,0,
00154 -1,1,1,1,-1,0,0,
00155 -1,1,1,-1,0,0,0,
00156 0,-1,-1,0,0,0,0
00157 };
00158
00159
00160
00161
00162
00163
00164
00165
00166
00167 static int r32a0_7x9 [] =
00168 {
00169 0,-1,-1,-1,-1,-1,-1,-1,0,
00170 -1,1,1,1,1,1,1,1,-1,
00171 -1,1,1,1,1,1,1,1,-1,
00172 -1,1,1,1,1,1,1,1,-1,
00173 -1,1,1,1,1,1,1,1,-1,
00174 -1,1,1,1,1,1,1,1,-1,
00175 0,-1,-1,-1,-1,-1,-1,-1,0
00176 };
00177
00178
00179
00180
00181
00182
00183
00184
00185
00186 static int r32a22_7x9 [] =
00187 {
00188 0,0,0,-1,-1,-1,-1,-1,0,
00189 0,0,-1,1,1,1,1,1,-1,
00190 0,-1,1,1,1,1,1,1,-1,
00191 -1,1,1,1,1,1,1,1,-1,
00192 -1,1,1,1,1,1,1,-1,0,
00193 -1,1,1,1,1,1,-1,0,0,
00194 0,-1,-1,-1,-1,-1,0,0,0
00195 };
00196
00197
00198
00199
00200
00201
00202
00203
00204
00205
00206
00207 static int r32a45_9x9 [] =
00208 {
00209 0,0,0,0,0,-1,0,0,0,
00210 0,0,0,0,-1,1,-1,0,0,
00211 0,0,0,-1,1,1,1,-1,0,
00212 0,0,-1,1,1,1,1,1,-1,
00213 0,-1,1,1,1,1,1,-1,0,
00214 -1,1,1,1,1,1,-1,0,0,
00215 0,-1,1,1,1,-1,0,0,0,
00216 0,0,-1,1,-1,0,0,0,0,
00217 0,0,0,-1,0,0,0,0,0
00218 };
00219
00220
00221
00222
00223
00224
00225
00226 static int r51a0_5x13[] =
00227 {
00228 0,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,0,
00229 -1,1,1,1,1,1,1,1,1,1,1,1,-1,
00230 -1,1,1,1,1,1,1,1,1,1,1,1,-1,
00231 -1,1,1,1,1,1,1,1,1,1,1,1,-1,
00232 0,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,0
00233 };
00234
00235
00236
00237
00238
00239
00240
00241
00242
00243
00244
00245 static int r51a22_9x13[] =
00246 {
00247 0,0,0,0,0,0,0,0,0,-1,-1,-1,0,
00248 0,0,0,0,0,0,0,0,-1,1,1,1,-1,
00249 0,0,0,0,0,-1,-1,-1,1,1,1,1,-1,
00250 0,0,0,-1,-1,1,1,1,1,1,1,1,-1,
00251 0,-1,-1,1,1,1,1,1,1,1,-1,-1,0,
00252 -1,1,1,1,1,1,1,1,-1,-1,0,0,0,
00253 -1,1,1,1,1,-1,-1,-1,0,0,0,0,0,
00254 -1,1,1,1,-1,0,0,0,0,0,0,0,0,
00255 0,-1,-1,-1,0,0,0,0,0,0,0,0,0
00256 };
00257
00258
00259
00260
00261
00262
00263
00264
00265
00266
00267
00268
00269
00270 static int r51a45_11x11[] =
00271 {
00272 0,0,0,0,0,0,0,0,-1,-1,0,
00273 0,0,0,0,0,0,0,-1,1,1,-1,
00274 0,0,0,0,0,0,-1,1,1,1,-1,
00275 0,0,0,0,0,-1,1,1,1,-1,0,
00276 0,0,0,0,-1,1,1,1,-1,0,0,
00277 0,0,0,-1,1,1,1,-1,0,0,0,
00278 0,0,-1,1,1,1,-1,0,0,0,0,
00279 0,-1,1,1,1,-1,0,0,0,0,0,
00280 -1,1,1,1,-1,0,0,0,0,0,0,
00281 -1,1,1,-1,0,0,0,0,0,0,0,
00282 0,-1,-1,0,0,0,0,0,0,0,0
00283 };
00284
00285
00286
00287
00288
00289
00290
00291
00292
00293 static int r52a0_7x13[] =
00294 {
00295 -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
00296 -1,1,1,1,1,1,1,1,1,1,1,1,-1,
00297 -1,1,1,1,1,1,1,1,1,1,1,1,-1,
00298 -1,1,1,1,1,1,1,1,1,1,1,1,-1,
00299 -1,1,1,1,1,1,1,1,1,1,1,1,-1,
00300 -1,1,1,1,1,1,1,1,1,1,1,1,-1,
00301 -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1
00302 };
00303
00304 #if 0 // not used
00305
00306
00307
00308
00309
00310
00311
00312
00313
00314
00315 static int r52a22_9x13[] =
00316 {
00317 0,0,0,0,0,0,0,0,0,-1,-1,-1,0,
00318 0,0,0,0,0,-1,-1,1,1,1,1,1,-1,
00319 0,0,0,0,-1,1,1,1,1,1,1,1,-1,
00320 0,0,0,-1,1,1,1,1,1,1,1,-1,-1,
00321 0,-1,-1,1,1,1,1,1,1,1,-1,-1,0,
00322 -1,-1,1,1,1,1,1,1,1,-1,0,0,0,
00323 -1,1,1,1,1,1,1,1,-1,0,0,0,0,
00324 -1,1,1,1,1,1,-1,-1,0,0,0,0,0,
00325 0,-1,-1,-1,-1,0,0,0,0,0,0,0,0
00326 };
00327 #endif // 0
00328
00329
00330
00331
00332
00333
00334
00335
00336
00337
00338
00339
00340
00341
00342
00343 static int r52a45_13x13[] =
00344 {
00345 0,0,0,0,0,0,0,0,0,-1,0,0,0,
00346 0,0,0,0,0,0,0,0,-1,1,-1,0,0,
00347 0,0,0,0,0,0,0,0,-1,1,1,1,-1,
00348 0,0,0,0,0,0,-1,1,1,1,1,1,-1,
00349 0,0,0,0,0,-1,1,1,1,1,1,-1,0,
00350 0,0,0,0,-1,1,1,1,1,1,-1,0,0,
00351 0,0,0,-1,1,1,1,1,1,-1,0,0,0,
00352 0,0,-1,1,1,1,1,1,-1,0,0,0,0,
00353 0,-1,1,1,1,1,1,-1,0,0,0,0,0,
00354 -1,1,1,1,1,1,-1,0,0,0,0,0,0,
00355 0,-1,1,1,1,-1,0,0,0,0,0,0,0,
00356 0,0,-1,1,-1,0,0,0,0,0,0,0,0,
00357 0,0,0,-1,0,0,0,0,0,0,0,0,0
00358 };
00359
00360
00361
00362
00363
00364
00365
00366
00367
00368
00369
00370
00371
00372 static int b0_11x11[] =
00373 {
00374 0,0,0,0,0,0,0,0,0,0,0,
00375 0,0,0,0,0,0,-1,-1,-1,-1,0,
00376 0,0,0,0,0,-1,1,1,1,1,-1,
00377 0,0,0,0,-1,1,1,1,1,1,-1,
00378 0,0,0,-1,1,1,1,1,1,1,-1,
00379 0,0,-1,1,1,1,1,1,1,1,-1,
00380 0,0,-1,1,1,1,1,1,1,-1,0,
00381 0,-1,1,1,1,1,1,1,-1,0,0,
00382 0,0,-1,1,1,1,1,-1,0,0,0,
00383 0,0,0,-1,-1,-1,-1,0,0,0,0
00384 };
00385
00386
00387
00388
00389
00390
00391
00392
00393
00394
00395
00396 static int b1_9x9[] =
00397 {
00398 0,0,0,0,0,0,0,0,0,
00399 0,-1,-1,-1,-1,-1,0,0,0,
00400 -1,1,1,1,1,1,-1,0,0,
00401 -1,1,1,1,1,1,-1,0,0,
00402 -1,1,1,1,1,1,1,-1,0,
00403 0,-1,1,1,1,1,-1,0,0,
00404 0,0,-1,1,1,1,1,-1,0,
00405 0,0,0,-1,1,1,1,-1,0,
00406 0,0,0,0,-1,-1,-1,0,0
00407 };
00408
00409
00410
00411
00412
00413
00414
00415
00416
00417
00418
00419
00420
00421 static int b0s_11x11[] =
00422 {
00423 0,0,0,0,0,0,0,0,0,0,0,
00424 0,0,0,0,-1,-1,-1,-1,-1,-1,0,
00425 0,0,0,-1,1,1,1,1,1,1,-1,
00426 0,0,0,-1,1,1,1,1,1,1,-1,
00427 0,0,-1,1,1,1,1,1,1,-1,0,
00428 0,0,-1,1,1,1,1,1,1,-1,0,
00429 0,-1,1,1,1,1,1,1,-1,0,0,
00430 0,-1,1,1,1,1,1,1,-1,0,0,
00431 -1,1,1,1,1,1,1,-1,0,0,0,
00432 -1,1,1,1,1,1,1,-1,0,0,0,
00433 0,-1,-1,-1,-1,-1,-1,0,0,0,0
00434 };
00435
00436
00437
00438
00439
00440
00441
00442
00443
00444
00445
00446 static int b1s_9x9[] =
00447 {
00448 0,0,0,0,0,0,0,0,0,
00449 0,-1,-1,-1,-1,-1,0,0,0,
00450 -1,1,1,1,1,1,-1,0,0,
00451 -1,1,1,1,1,1,-1,0,0,
00452 -1,1,1,1,1,1,1,-1,0,
00453 0,-1,1,1,1,1,1,1,-1,
00454 0,0,-1,1,1,1,1,1,-1,
00455 0,0,-1,1,1,1,1,1,-1,
00456 0,0,-1,-1,-1,-1,-1,0,0
00457 };
00458
00459
00460
00461
00462
00463
00464
00465
00466 static int c4_90_0_5x5[] =
00467 {
00468 -1,-1,-1,-1,-1,
00469 -1,1,1,1,1,
00470 -1,1,1,1,0,
00471 -1,1,1,0,0,
00472 -1,1,0,0,0
00473 };
00474
00475
00476
00477
00478
00479
00480
00481 static int c4_45_0_5x7[] =
00482 {
00483 0,0,0,0,-1,-1,-1,
00484 0,0,0,-1,-1,-1,-1,
00485 0,0,-1,1,1,1,1,
00486 0,-1,1,1,1,1,0,
00487 -1,1,1,1,1,0,0
00488 };
00489
00490
00491
00492
00493
00494
00495
00496 static int c4_45_45_5x7[] =
00497 {
00498 0, 0, 0, 0, 0, 0, 0,
00499 0, 0, 0,-1, 0, 0, 0,
00500 0, 0,-1, 1,-1, 0, 0,
00501 0,-1, 1, 1, 1,-1, 0,
00502 -1, 1, 1, 1, 1, 1,-1
00503 };
00504
00505
00506
00507
00508 static int m1a0_3x3[] =
00509 {
00510 0, -1, 0,
00511 -1, 1, -1,
00512 0, -1, 0
00513 };
00514
00515
00516
00517
00518 static int m4a0_3x3[] =
00519 {
00520 -1, 1,-1,
00521 1, 1, 1,
00522 -1, 1,-1
00523 };
00524
00525
00526
00527
00528
00529
00530 static int m4sa0_5x5[] =
00531 {
00532 0, 0,-1, 0, 0,
00533 0,-1, 1,-1, 0,
00534 -1, 1, 1, 1,-1,
00535 0,-1, 1,-1, 0,
00536 0, 0,-1, 0, 0};
00537
00538
00539
00540
00541
00542
00543
00544
00545 static int m7a0_7x7[] =
00546 {
00547 0, 0, 0,-1, 0, 0, 0,
00548 0, 0,-1, 1,-1, 0, 0,
00549 0,-1, 1, 1, 1,-1, 0,
00550 -1, 1, 1, 1, 1, 1,-1,
00551 0,-1, 1, 1, 1,-1, 0,
00552 0, 0,-1, 1,-1, 0, 0,
00553 0, 0, 0,-1, 0, 0, 0
00554 };
00555
00556
00557
00558
00559
00560
00561 static int e2a0_3x3[] =
00562 {
00563 0,-1, 0,
00564 0, 1, 0,
00565 0, 0, 0
00566 };
00567
00568
00569
00570
00571 static int e2a45_3x3[] =
00572 {
00573 -1, 0, 0,
00574 0, 1, 0,
00575 0, 0, 0
00576 };
00577
00578
00579
00580
00581
00582
00583 static int e3a0_3x3[] =
00584 {
00585 -1,-1,-1,
00586 1, 1, 1,
00587 1, 1, 1
00588 };
00589
00590
00591
00592
00593 static int e3a45_3x5[] =
00594 {
00595 0, 0,-1, 1, 1,
00596 0,-1, 1, 1, 0,
00597 -1, 1, 1, 0, 0
00598 };
00599
00600
00601
00602
00603
00604
00605
00606 static int e5a0_5x5[] =
00607 {
00608 -1,-1,-1,-1,-1,
00609 -1,-1,-1,-1,-1,
00610 1,1,1,1,1,
00611 1,1,1,1,1,
00612 1,1,1,1,1
00613 };
00614
00615 #if 0 // not used
00616
00617
00618
00619
00620
00621
00622 static int e5a22_5x5[] =
00623 {
00624 0,0,-1,-1,-1,
00625 -1,-1,-1,-1,-1,
00626 -1,-1,1,1,1,
00627 1,1,1,1,1,
00628 1,1,1,0,0
00629 };
00630 #endif
00631
00632
00633
00634
00635
00636
00637
00638 static int e5a45_5x5[] =
00639 {
00640 0,-1,-1,-1,1,
00641 -1,-1,-1,1,1,
00642 -1,-1,1,1,1,
00643 -1,1,1,1,0,
00644 1,1,1,0,0
00645 };
00646
00647
00648
00649
00650
00651
00652
00653 static int e11a0_5x11[] =
00654 {
00655 -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
00656 -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
00657 1,1,1,1,1,1,1,1,1,1,1,
00658 1,1,1,1,1,1,1,1,1,1,1,
00659 1,1,1,1,1,1,1,1,1,1,1
00660 };
00661
00662
00663
00664
00665
00666
00667
00668
00669 static int f5a0_5x5[] =
00670 {
00671 1, 1, 1, 1, 1,
00672 1, 1, 1, 1, 1,
00673 1, 1, 1, 1, 1,
00674 1, 1, 1, 1, 1,
00675 1, 1, 1, 1, 1
00676 };
00677
00678
00679
00680
00681 static int f3a0_3x3[] =
00682 {
00683 0,1,0,
00684 1,1,1,
00685 0,1,0
00686 };
00687
00688
00689
00690
00691
00692
00693
00694 static int b5a0_5x5[] =
00695 {
00696 -1,-1,-1,-1,-1,
00697 -1,-1,-1,-1,-1,
00698 -1,-1,-1,-1,-1,
00699 -1,-1,-1,-1,-1,
00700 -1,-1,-1,-1,-1
00701 };
00702
00703
00704
00705
00706
00707
00708
00709
00710
00711 static int b7a0_7x7[] =
00712 {
00713 0, 0, 0,-1, 0, 0, 0,
00714 0, 0,-1,-1,-1, 0, 0,
00715 0,-1,-1,-1,-1,-1, 0,
00716 -1,-1,-1,-1,-1,-1,-1,
00717 0,-1,-1,-1,-1,-1, 0,
00718 0, 0,-1,-1,-1, 0, 0,
00719 0, 0, 0,-1, 0, 0, 0,
00720 };
00721
00722
00723
00724
00725
00726
00727
00728
00729 static int b7a1_7x7[] =
00730 {
00731 0, 0, 0,-1, 0, 0, 0,
00732 0, 0,-1, 1,-1, 0, 0,
00733 0,-1, 1, 1, 1,-1, 0,
00734 -1, 1, 1, 1, 1, 1,-1,
00735 0,-1, 1, 1, 1,-1, 0,
00736 0, 0,-1, 1,-1, 0, 0,
00737 0, 0, 0,-1, 0, 0, 0,
00738 };
00739
00740
00741
00742
00743 static int b3a0_3x3[] =
00744 {
00745 0,-1, 0,
00746 -1,-1,-1,
00747 0,-1, 0
00748 };
00749
00750 vnl_matrix<int> reflect_about_vert(vnl_matrix<int> const& m)
00751 {
00752 unsigned nc = m.cols(), nr = m.rows();
00753 vnl_matrix<int> ref(nr, nc);
00754 int rc = (nc-1)/2;
00755 for (unsigned r = 0; r<nr; ++r)
00756 for (int c = -rc; c<=rc; ++c)
00757 ref[r][rc+c] = m[r][rc-c];
00758 return ref;
00759 }
00760
00761 #if 0
00762 vnl_matrix<int> reflect_about_vert_even(vnl_matrix<int> const& m)
00763 {
00764 unsigned nc = m.cols(), nr = m.rows();
00765 vnl_matrix<int> ref(nr, nc);
00766 int rc = nc/2;
00767 for (unsigned r = 0; r<nr; ++r)
00768 for (int c = -rc; c<=rc; ++c)
00769 ref[r][rc+c] = m[r][rc-c];
00770 return ref;
00771 }
00772 #endif
00773
00774 vnl_matrix<int> reflect_about_horz(vnl_matrix<int> const& m)
00775 {
00776 unsigned nc = m.cols(), nr = m.rows();
00777 vnl_matrix<int> ref(nr, nc);
00778 int rr = (nr-1)/2;
00779 for (unsigned c = 0; c<nc; ++c)
00780 for (int r = -rr; r<=rr; ++r)
00781 ref[rr+r][c] = m[rr-r][c];
00782 return ref;
00783 }
00784
00785 #if 0
00786 vnl_matrix<int> reflect_about_horz_even(vnl_matrix<int> const& m)
00787 {
00788 unsigned nc = m.cols(), nr = m.rows();
00789 vnl_matrix<int> ref(nr, nc);
00790 int rr = nr-1/2;
00791 for (unsigned c = 0; c<nc; ++c)
00792 for (int r = -rr; r<=rr; ++r)
00793 ref[rr+r][c] = m[rr-r][c];
00794 return ref;
00795 }
00796 #endif
00797
00798 brip_rect_mask::brip_rect_mask(mask_id mid)
00799 {
00800 switch (mid)
00801 {
00802 case cr1:{
00803 vnl_matrix<int> cr1a0(cr1_5x5, 5, 5);
00804 masks_[a0] = cr1a0;
00805 break;
00806 }
00807 case s1:{
00808 vnl_matrix<int> s1a0(s1_5x5, 5, 5);
00809 masks_[a0] = s1a0;
00810 break;
00811 }
00812 case b0:{
00813 vnl_matrix<int> b0a0(b0_11x11, 11, 11);
00814 masks_[a0] = b0a0;
00815 break;
00816 }
00817 case b1:{
00818 vnl_matrix<int> b1a0(b1_9x9, 9, 9);
00819 masks_[a0] = b1a0;
00820 break;
00821 }
00822 case b0s:{
00823 vnl_matrix<int> b0sa0(b0s_11x11, 11, 11);
00824 masks_[a0] = b0sa0;
00825 break;
00826 }
00827 case b1s:{
00828 vnl_matrix<int> b1sa0(b1s_9x9, 9, 9);
00829 masks_[a0] = b1sa0;
00830 break;
00831 }
00832 case r10:{
00833 vnl_matrix<int> r10a0(r10a0_3x5, 3, 5), r10a45(r10a45_5x5, 5, 5);
00834 masks_[a0] = r10a0;
00835 masks_[a45] = r10a45;
00836 masks_[a90] = r10a0.transpose();
00837 masks_[a135] = reflect_about_vert(r10a45);
00838 break;
00839 }
00840 case r30: {
00841 vnl_matrix<int> r30a0(r30a0_3x9, 3, 9), r30a22(r30a22_5x9, 5, 9),
00842 r30a45(r30a45_7x7, 7, 7);
00843 masks_[a0] = r30a0;
00844 masks_[a22] = r30a22;
00845 masks_[a45] = r30a45;
00846 masks_[a67] = r30a22.transpose();
00847 masks_[a90] = r30a0.transpose();
00848 masks_[a112] = reflect_about_vert(r30a22.transpose());
00849 masks_[a135] = reflect_about_vert(r30a45);
00850 masks_[a157] = reflect_about_horz(r30a22);
00851 break;
00852 }
00853 case r31: {
00854 vnl_matrix<int> r31a0(r31a0_5x9, 5, 9), r31a22(r31a22_5x9, 5, 9),
00855 r31a45(r31a45_7x7, 7, 7);
00856 masks_[a0] = r31a0;
00857 masks_[a22] = r31a22;
00858 masks_[a45] = r31a45;
00859 masks_[a67] = r31a22.transpose();
00860 masks_[a90] = r31a0.transpose();
00861 masks_[a112] = reflect_about_vert(r31a22.transpose());
00862 masks_[a135] = reflect_about_vert(r31a45);
00863 masks_[a157] = reflect_about_horz(r31a22);
00864 break;
00865 }
00866 case r32: {
00867 vnl_matrix<int> r32a0(r32a0_7x9, 7, 9), r32a22(r32a22_7x9, 7, 9),
00868 r32a45(r32a45_9x9, 9, 9);
00869 masks_[a0] = r32a0;
00870 masks_[a22] = r32a22;
00871 masks_[a45] = r32a45;
00872 masks_[a67] = r32a22.transpose();
00873 masks_[a90] = r32a0.transpose();
00874 masks_[a112] = reflect_about_vert(r32a22.transpose());
00875 masks_[a135] = reflect_about_vert(r32a45);
00876 masks_[a157] = reflect_about_horz(r32a22);
00877 break;
00878 }
00879 case r51: {
00880 vnl_matrix<int> r51a0(r51a0_5x13, 5, 13), r51a22(r51a22_9x13, 9, 13),
00881 r51a45(r51a45_11x11, 11, 11);
00882 masks_[a0] = r51a0;
00883 masks_[a22] = r51a22;
00884 masks_[a45] = r51a45;
00885 masks_[a67] = r51a22.transpose();
00886 masks_[a90] = r51a0.transpose();
00887 masks_[a112] = reflect_about_vert(r51a22.transpose());
00888 masks_[a135] = reflect_about_vert(r51a45);
00889 masks_[a157] = reflect_about_horz(r51a22);
00890 break;
00891 }
00892 case r52: {
00893 vnl_matrix<int> r52a0(r52a0_7x13, 7, 13), r52a22(r51a22_9x13, 9, 13),
00894 r52a45(r52a45_13x13, 13, 13);
00895 masks_[a0] = r52a0;
00896 masks_[a22] = r52a22;
00897 masks_[a45] = r52a45;
00898 masks_[a67] = r52a22.transpose();
00899 masks_[a90] = r52a0.transpose();
00900 masks_[a112] = reflect_about_vert(r52a22.transpose());
00901 masks_[a135] = reflect_about_vert(r52a45);
00902 masks_[a157] = reflect_about_horz(r52a22);
00903 break;
00904 }
00905 case c4_90_0: {
00906 vnl_matrix<int> c4_90_0a0(c4_90_0_5x5, 5, 5);
00907 masks_[a0] = c4_90_0a0;
00908 masks_[a90] = reflect_about_vert(c4_90_0a0);
00909 masks_[a180] = reflect_about_horz(c4_90_0a0);
00910 masks_[a270] = reflect_about_horz(reflect_about_vert(c4_90_0a0));
00911 break;
00912 }
00913 case c4_45_0: {
00914 vnl_matrix<int> c4_45_0a0(c4_45_0_5x7, 5, 7);
00915 masks_[a0] = c4_45_0a0;
00916 masks_[a45]= c4_45_0a0.transpose();
00917 masks_[a90] = reflect_about_vert(c4_45_0a0);
00918 masks_[a135] = reflect_about_vert(c4_45_0a0.transpose());
00919 masks_[a180] = reflect_about_horz(c4_45_0a0);
00920 masks_[a225]= reflect_about_horz(reflect_about_vert(c4_45_0a0.transpose()));
00921 masks_[a270] = reflect_about_horz(reflect_about_vert(c4_45_0a0));
00922 break;
00923 }
00924 case c4_45_45: {
00925 vnl_matrix<int> c4_45_45a0(c4_45_45_5x7, 5, 7);
00926 masks_[a0] = c4_45_45a0;
00927 masks_[a90] = c4_45_45a0.transpose();
00928 masks_[a180] = reflect_about_horz(c4_45_45a0);
00929 masks_[a270] = reflect_about_horz(c4_45_45a0).transpose();
00930 break;
00931 }
00932 case e2:{
00933 vnl_matrix<int> e2a0(e2a0_3x3, 3, 3), e2a45(e2a45_3x3, 3, 3);
00934 masks_[a0] = e2a0;
00935 masks_[a45] = e2a45;
00936 masks_[a90] = e2a0.transpose();
00937 masks_[a135] = reflect_about_horz(e2a45);
00938 masks_[a180] = reflect_about_horz(e2a0);
00939 masks_[a225] = reflect_about_vert(reflect_about_horz(e2a45));
00940 masks_[a270] = reflect_about_vert(e2a0.transpose());
00941 masks_[a315] = reflect_about_vert(e2a45.transpose());
00942 break;
00943 }
00944 case e3:{
00945 vnl_matrix<int> e3a0(e3a0_3x3, 3, 3), e3a45(e3a45_3x5, 3, 5);
00946 masks_[a0] = e3a0;
00947 masks_[a45] = e3a45;
00948 masks_[a90] = e3a0.transpose();
00949 masks_[a135] = reflect_about_horz(e3a45);
00950 masks_[a180] = reflect_about_horz(e3a0);
00951 masks_[a225] = reflect_about_vert(reflect_about_horz(e3a45));
00952 masks_[a270] = reflect_about_vert(e3a0.transpose());
00953 masks_[a315] = reflect_about_vert(e3a45.transpose());
00954 break;
00955 }
00956 case e5:{
00957 vnl_matrix<int> e5a0(e5a0_5x5, 5, 5), e5a45(e5a45_5x5, 5, 5);
00958 masks_[a0] = e5a0;
00959 masks_[a45] = e5a45;
00960 masks_[a90] = e5a0.transpose();
00961 masks_[a135] = reflect_about_horz(e5a45);
00962 masks_[a180] = reflect_about_horz(e5a0);
00963 masks_[a225] = reflect_about_vert(reflect_about_horz(e5a45));
00964 masks_[a270] = reflect_about_vert(e5a0.transpose());
00965 masks_[a315] = reflect_about_vert(e5a45.transpose());
00966 break;
00967 }
00968 case e11:{
00969 vnl_matrix<int> e11a0(e11a0_5x11, 5, 11);
00970 masks_[a0] = e11a0;
00971 masks_[a90] = e11a0.transpose();
00972 masks_[a180] = reflect_about_horz(e11a0);
00973 masks_[a270] = reflect_about_vert(e11a0.transpose());
00974 break;
00975 }
00976 case m1:{
00977 vnl_matrix<int> m1a0(m1a0_3x3, 3, 3);
00978 masks_[a0] = m1a0;
00979 break;
00980 }
00981 case m4:{
00982 vnl_matrix<int> m4a0(m4a0_3x3, 3, 3);
00983 masks_[a0] = m4a0;
00984 break;
00985 }
00986 case m4s:{
00987 vnl_matrix<int> m4sa0(m4sa0_5x5, 5, 5);
00988 masks_[a0] = m4sa0;
00989 break;
00990 }
00991 case m7:{
00992 vnl_matrix<int> m7a0(m7a0_7x7, 7, 7);
00993 masks_[a0] = m7a0;
00994 break;
00995 }
00996 case f3:{
00997 vnl_matrix<int> f3a0(f3a0_3x3, 3, 3);
00998 masks_[a0] = f3a0;
00999 break;
01000 }
01001 case b3:{
01002 vnl_matrix<int> b3a0(b3a0_3x3, 3, 3);
01003 masks_[a0] = b3a0;
01004 break;
01005 }
01006 case f5:{
01007 vnl_matrix<int> f5a0(f5a0_5x5, 5, 5);
01008 masks_[a0] = f5a0;
01009 break;
01010 }
01011 case b5:{
01012 vnl_matrix<int> b5a0(b5a0_5x5, 5, 5);
01013 masks_[a0] = b5a0;
01014 break;
01015 }
01016 case b7:{
01017 vnl_matrix<int> b7a0(b7a0_7x7, 7, 7);
01018 vnl_matrix<int> b7a1(b7a1_7x7, 7, 7);
01019 masks_[a0] = b7a1;
01020 masks_[a0] = b7a0;
01021 break;
01022 }
01023
01024 default:
01025 vcl_cout << "specified mask does not exist\n";
01026 };
01027 }
01028
01029 bool brip_rect_mask::
01030 find_ait(ang_id aid,
01031 vcl_map<ang_id, vnl_matrix<int> >::const_iterator& ait) const
01032 {
01033 ait = masks_.find(aid);
01034 if (ait == masks_.end())
01035 return false;
01036 return true;
01037 }
01038
01039 brip_rect_mask::ang_id brip_rect_mask::angle_id(unsigned angle_index) const
01040 {
01041 vcl_map<ang_id, vnl_matrix<int> >::const_iterator ait = masks_.begin();
01042 for (unsigned i = 0; i<angle_index; ++i)
01043 ++ait;
01044 return (*ait).first;
01045 }
01046
01047 bool brip_rect_mask::set_angle_id(ang_id aid)
01048 {
01049 vcl_map<ang_id, vnl_matrix<int> >::const_iterator ait;
01050 bool found = find_ait(aid, ait);
01051 if (!found) {
01052 ru_ = 0; rv_ = 0;
01053 return false;
01054 }
01055 current_mask_ = (*ait).second;
01056 ru_ = (current_mask_.cols()-1)/2;
01057 rv_ = (current_mask_.rows()-1)/2;
01058 return true;
01059 }
01060
01061 void brip_rect_mask::init()
01062 {
01063 if (!is_init_) {
01064 names_[a0]="0 deg"; angles_[a0]=0.0f;
01065 names_[a22]="22.5 deg"; angles_[a22]=22.5f;
01066 names_[a45]="45 deg"; angles_[a45]=45.0f;
01067 names_[a67]="67.5 deg"; angles_[a67]=67.5f;
01068 names_[a90]="90 deg"; angles_[a90]=90.0f;
01069 names_[a112]="112.5 deg"; angles_[a112]=112.5f;
01070 names_[a135]="135 deg"; angles_[a135]=135.0f;
01071 names_[a157]="157.5 deg"; angles_[a157]=157.5f;
01072 names_[a180]="180 deg"; angles_[a180]=180.0f;
01073 names_[a202]="202.5 deg"; angles_[a202]=202.5f;
01074 names_[a225]="225 deg"; angles_[a225]=225.0f;
01075 names_[a247]="247.5 deg"; angles_[a247]=247.5f;
01076 names_[a270]="270 deg"; angles_[a270]=270.0f;
01077 names_[a292]="292.5 deg"; angles_[a292]=292.5f;
01078 names_[a315]="315 deg"; angles_[a315]=315.0f;
01079 names_[a337]="337.5 deg"; angles_[a337]=337.5f;
01080 is_init_ = true;
01081 }
01082 }
01083
01084 vcl_string brip_rect_mask::name(ang_id aid)
01085 {
01086 init();
01087 vcl_map<ang_id, vcl_string >::const_iterator ait;
01088 ait = names_.find(aid);
01089 if (ait == names_.end())
01090 return "null";
01091 return (*ait).second;
01092 }
01093
01094 float brip_rect_mask::angle(ang_id aid)
01095 {
01096 init();
01097 vcl_map<ang_id, float >::const_iterator ait;
01098 ait = angles_.find(aid);
01099 if (ait == angles_.end())
01100 return 0.0f;
01101 return (*ait).second;
01102 }
01103
01104 unsigned brip_rect_mask::nplus() const
01105 {
01106 unsigned np = 0;
01107 vnl_matrix<int> const& weights = current_mask_;
01108 for (vnl_matrix<int>::const_iterator wit = weights.begin();
01109 wit != weights.end(); ++wit)
01110 if ((*wit)>0) ++np;
01111 return np;
01112 }
01113
01114 unsigned brip_rect_mask::nminus() const
01115 {
01116 unsigned np = 0;
01117 vnl_matrix<int> const& weights = current_mask_;
01118 for (vnl_matrix<int>::const_iterator wit = weights.begin();
01119 wit != weights.end(); ++wit)
01120 if ((*wit)<0) ++np;
01121 return np;
01122 }
01123
01124 float brip_rect_mask::ang_diff(ang_id aid0,ang_id aid1)
01125 {
01126 float diff = brip_rect_mask::angle(aid1)-brip_rect_mask::angle(aid0);
01127 if (diff>180.0f) diff-=360.0f;
01128 if (diff<-180.0f) diff+=360.0f;
01129 return diff;
01130 }
01131
01132 bool brip_rect_mask::intersect(mask_id mid,
01133 ang_id aid0,
01134 unsigned short i0, unsigned short j0,
01135 ang_id aid1,
01136 unsigned short i1, unsigned short j1)
01137 {
01138 brip_rect_mask m0(mid), m1(mid);
01139 m0.set_angle_id(aid0);
01140 m1.set_angle_id(aid1);
01141 unsigned ni0 = m0.ni(), nj0 = m0.nj(), ni1 = m1.ni(), nj1 = m1.nj();
01142 int ru0 = (ni0-1)/2, rv0 = (nj0-1)/2;
01143 int ru1 = (ni1-1)/2, rv1 = (nj1-1)/2;
01144 for (int jr0 = -rv0; jr0<=rv0; ++jr0)
01145 for (int ir0 = -ru0; ir0<=ru0; ++ir0)
01146 if (m0(ir0,jr0)>0)
01147 for (int jr1 = -rv1; jr1<=rv1; ++jr1)
01148 for (int ir1 = -ru1; ir1<=ru1; ++ir1)
01149 if (m1(ir1,jr1)>0)
01150 if ((i0+ir0)==(i1+ir1)&&(j0+jr0)==(j1+jr1))
01151 return true;
01152 return false;
01153 }
01154
01155 bool brip_rect_mask::intersect_domain(mask_id mid,
01156 ang_id aid0,
01157 unsigned short i0, unsigned short j0,
01158 ang_id aid1,
01159 unsigned short i1, unsigned short j1)
01160 {
01161 brip_rect_mask m0(mid), m1(mid);
01162 m0.set_angle_id(aid0);
01163 m1.set_angle_id(aid1);
01164 unsigned ni0 = m0.ni(), nj0 = m0.nj(), ni1 = m1.ni(), nj1 = m1.nj();
01165 int ru0 = (ni0-1)/2, rv0 = (nj0-1)/2;
01166 int ru1 = (ni1-1)/2, rv1 = (nj1-1)/2;
01167 for (int jr0 = -rv0; jr0<=rv0; ++jr0)
01168 for (int ir0 = -ru0; ir0<=ru0; ++ir0)
01169 for (int jr1 = -rv1; jr1<=rv1; ++jr1)
01170 for (int ir1 = -ru1; ir1<=ru1; ++ir1)
01171 if ((i0+ir0)==(i1+ir1)&&(j0+jr0)==(j1+jr1))
01172 return true;
01173 return false;
01174 }
01175
01176 void brip_rect_mask::print(ang_id aid)
01177 {
01178 vcl_map<ang_id, vnl_matrix<int> >::const_iterator ait;
01179 bool found = find_ait(aid, ait);
01180 if (!found) {
01181 vcl_cout<< "no such angle\n";
01182 return;
01183 }
01184 vnl_matrix<int> msk = (*ait).second;
01185 int ri = (msk.cols()-1)/2, rj = (msk.rows()-1)/2;
01186 for (int jr = -rj; jr<=rj ; ++jr) {
01187 for (int ir = -ri; ir<= ri; ++ir)
01188 {
01189 int m = msk(jr+rj, ir+ri);
01190 if (m >0)
01191 vcl_cout << '+' << ' ';
01192 else if (m<0)
01193 vcl_cout << '-' << ' ';
01194 else
01195 vcl_cout << '0' << ' ';
01196 }
01197 vcl_cout << '\n';
01198 }
01199 vcl_cout<< '\n';
01200 }
01201
01202 vcl_ostream& operator<<(vcl_ostream& s, brip_rect_mask const& msk)
01203 {
01204 s << "masks\n";
01205 brip_rect_mask& msk_nc = const_cast<brip_rect_mask&>(msk);
01206 unsigned nangles = msk.n_angles();
01207 for (unsigned a = 0; a<nangles; ++a) {
01208 brip_rect_mask::ang_id aid = msk.angle_id(a);
01209 msk_nc.set_angle_id(aid);
01210 unsigned ni =msk_nc.ni(), nj = msk_nc.nj();
01211 int ri = (ni-1)/2, rj = (nj-1)/2;
01212 for (int jr = -rj; jr<=rj ; ++jr) {
01213 for (int ir = -ri; ir<= ri; ++ir)
01214 {
01215 int m = msk_nc(ir,jr);
01216 if (m >0)
01217 s << '+' << ' ';
01218 else if (m<0)
01219 s << '-' << ' ';
01220 else
01221 s << '0' << ' ';
01222 }
01223 s << '\n';
01224 }
01225 s<< '\n';
01226 }
01227 return s;
01228 }