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 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508
|
C
C The following code was excerpted from: cvdec2.f
C
SUBROUTINE CVDEC2(ANGSPC,ANGTOL,NVC,NPOLG,NVERT,MAXVC,MAXHV,MAXPV,
$ MAXIW,MAXWK,VCL,REGNUM,HVL,PVL,IANG,IWK,WK)
IMPLICIT LOGICAL (A-Z)
INTEGER MAXHV,MAXIW,MAXPV,MAXVC,MAXWK,NPOLG,NVC,NVERT
INTEGER HVL(MAXHV),IWK(MAXIW),PVL(4,MAXPV),REGNUM(MAXHV)
DOUBLE PRECISION ANGSPC,ANGTOL,IANG(MAXPV),VCL(2,MAXVC),WK(MAXWK)
C
C Written and copyright by:
C Barry Joe, Dept. of Computing Science, Univ. of Alberta
C Edmonton, Alberta, Canada T6G 2H1
C Phone: (403) 492-5757 Email: barry@cs.ualberta.ca
C
C Purpose: Decompose general polygonal region (which is decomposed
C into simple polygons on input) into convex polygons using
C vertex coordinate list, head vertex list, and polygon vertex
C list data structures.
C
C Input parameters:
C ANGSPC - angle spacing parameter in radians used in controlling
C vertices to be considered as an endpoint of a separator
C ANGTOL - angle tolerance parameter in radians used in accepting
C separator(s)
C NVC - number of vertex coordinates or positions used in VCL
C array
C NPOLG - number of polygonal subregions or positions used in
C HVL array
C NVERT - number of polygon vertices or positions used in PVL
C array
C MAXVC - maximum size available for VCL array, should be >=
C number of vertex coordinates required for decomposition
C MAXHV - maximum size available for HVL, REGNUM arrays, should
C be >= number of polygons required for decomposition
C MAXPV - maximum size available for PVL, IANG arrays; should be
C >= number of polygon vertices required for decomposition
C MAXIW - maximum size available for IWK array; should be about
C 3 times maximum number of vertices in any polygon
C MAXWK - maximum size available for WK array; should be about
C 5 times maximum number of vertices in any polygon
C VCL(1:2,1:NVC) - vertex coordinate list
C REGNUM(1:NPOLG) - region numbers
C HVL(1:NPOLG) - head vertex list
C PVL(1:4,1:NVERT),IANG(1:NVERT) - polygon vertex list and
C interior angles; see routine DSPGDC for more details
C [Note: The data structures should be as output from routine
C SPDEC2.]
C
C Updated parameters:
C NVC,NPOLG,NVERT,VCL,REGNUM,HVL,PVL,IANG
C
C Working parameters:
C IWK(1:MAXIW) - integer work array
C WK(1:MAXWK) - double precision work array
C
C Abnormal return:
C IERR is set to 3, 4, 5, 6, 7, 206, 207, 208, 209, 210, or 212
C
C Routines called:
C INSED2, RESVRT
C
INTEGER IERR
DOUBLE PRECISION PI,TOL
COMMON /GERROR/ IERR
COMMON /GCONST/ PI,TOL
SAVE /GERROR/,/GCONST/
C
INTEGER V,W1,W2
DOUBLE PRECISION PIPTOL
C
C For each reflex vertex, resolve it with one or two separators
C and update VCL, HVL, PVL, IANG.
C
PIPTOL = PI + TOL
V = 1
10 CONTINUE
IF (V .GT. NVERT) RETURN
IF (IANG(V) .GT. PIPTOL) THEN
CALL RESVRT(V,ANGSPC,ANGTOL,NVC,NVERT,MAXVC,MAXPV,MAXIW,
$ MAXWK,VCL,PVL,IANG,W1,W2,IWK,WK)
IF (IERR .NE. 0) RETURN
CALL INSED2(V,W1,NPOLG,NVERT,MAXHV,MAXPV,VCL,REGNUM,HVL,
$ PVL,IANG)
IF (IERR .NE. 0) RETURN
IF (W2 .GT. 0) CALL INSED2(V,W2,NPOLG,NVERT,MAXHV,MAXPV,
$ VCL,REGNUM,HVL,PVL,IANG)
IF (IERR .NE. 0) RETURN
ENDIF
V = V + 1
GO TO 10
END
C
C The following code was excerpted from: dsmcpr.f
C
SUBROUTINE DSMCPR(NHOLE,NVBC,VCL,MAXHV,MAXPV,MAXHO,NVC,NPOLG,
$ NVERT,NHOLA,REGNUM,HVL,PVL,IANG,HOLV)
IMPLICIT LOGICAL (A-Z)
INTEGER MAXHO,MAXHV,MAXPV,NHOLA,NHOLE,NPOLG,NVC,NVERT
INTEGER HVL(NHOLE+1),HOLV(MAXHO),NVBC(NHOLE+1),PVL(4,MAXPV)
INTEGER REGNUM(1)
DOUBLE PRECISION IANG(MAXPV),VCL(2,*)
C
C Written and copyright by:
C Barry Joe, Dept. of Computing Science, Univ. of Alberta
C Edmonton, Alberta, Canada T6G 2H1
C Phone: (403) 492-5757 Email: barry@cs.ualberta.ca
C
C Purpose: Initialize the polygonal decomposition data structure
C given a multiply-connected polygonal region with 1 outer
C boundary curve and 0 or more inner boundary curves of holes.
C
C Input parameters:
C NHOLE - number of holes in region
C NVBC(1:NHOLE+1) - number of vertices per boundary curve; first
C boundary curve is the outer boundary of the region
C VCL(1:2,1:NVC) - vertex coordinates of boundary curves in CCW
C order; NVC = NVBC(1) + ... + NVBC(NHOLE+1); positions 1
C to NVBC(1) of VCL contain the vertex coordinates of the
C outer boundary in CCW order; positions NVBC(1)+1 to
C NVBC(1)+NVBC(2) contain the vertex coordinates of the
C first hole boundary in CCW order, etc.
C MAXHV - maximum size available for HVL, REGNUM arrays, should
C be >= NHOLE + 1
C MAXPV - maximum size available for PVL, IANG arrays; should be
C >= NVC
C MAXHO - maximum size available for HOLV array; should be
C >= NHOLE*2
C
C Output parameters:
C NVC - number of vertex coordinates, set to sum of NVBC(I)
C NPOLG - number of polygonal subregions, set to 1
C NVERT - number of vertices in PVL, set to NVC
C NHOLA - number of attached holes, set to 0
C REGNUM(1:1) - region number of only subregion, set to 1
C [Note: Above 4 parameters are for consistency with DSPGDC.]
C HVL(1:NHOLE+1) - head vertex list; first entry is the head
C vertex (index in PVL) of outer boundary curve; next
C NHOLE entries contain the head vertex of a hole
C PVL(1:4,1:NVC),IANG(1:NVC) - polygon vertex list and interior
C angles; vertices of outer boundary curve are in CCW order
C followed by vertices of each hole in CW hole; vertices
C of each polygon are in a circular linked list; see
C routine DSPGDC for more details of this data structure
C HOLV(1:NHOLE*2) - indices in PVL of top and bottom vertices of
C holes; first (last) NHOLE entries are for top (bottom)
C vertices; top (bottom) vertices are sorted in decreasing
C (increasing) lexicographic (y,x) order of coordinates
C
C Abnormal return:
C IERR is set to 2, 4, or 5
C
C Routines called:
C ANGLE, HOLVRT
C
INTEGER IERR
COMMON /GERROR/ IERR
SAVE /GERROR/
C
INTEGER EDGV,LOC,POLG,SUCC
PARAMETER (LOC = 1, POLG = 2, SUCC = 3, EDGV = 4)
C
INTEGER I,IV,IVS,J,LV,LVP,LVS,NV,NVS
DOUBLE PRECISION ANGLE
C
NVC = 0
DO 10 I = 1,NHOLE+1
NVC = NVC + NVBC(I)
10 CONTINUE
NPOLG = 1
NVERT = NVC
NHOLA = 0
REGNUM(1) = 1
IF (NHOLE + 1 .GT. MAXHV) THEN
IERR = 4
RETURN
ELSE IF (NVC .GT. MAXPV) THEN
IERR = 5
RETURN
ELSE IF (NHOLE + NHOLE .GT. MAXHO) THEN
IERR = 2
RETURN
ENDIF
C
C Initialize HVL, PVL arrays.
C
20 CONTINUE
HVL(1) = 1
NV = NVBC(1)
DO 30 I = 1,NV
PVL(LOC,I) = I
PVL(POLG,I) = 1
PVL(SUCC,I) = I + 1
PVL(EDGV,I) = 0
30 CONTINUE
PVL(SUCC,NV) = 1
DO 50 J = 1,NHOLE
HVL(J+1) = NV + 1
NVS = NV + NVBC(J+1)
DO 40 I = NV+1,NVS
PVL(LOC,I) = I
PVL(POLG,I) = 1
PVL(SUCC,I) = I - 1
PVL(EDGV,I) = 0
40 CONTINUE
PVL(SUCC,NV+1) = NVS
NV = NVS
50 CONTINUE
C
C Initialize IANG array.
C
DO 70 I = 1,NHOLE+1
J = HVL(I)
LVP = PVL(LOC,J)
IV = PVL(SUCC,J)
LV = PVL(LOC,IV)
60 CONTINUE
IVS = PVL(SUCC,IV)
LVS = PVL(LOC,IVS)
IANG(IV) = ANGLE(VCL(1,LVP),VCL(2,LVP),VCL(1,LV),VCL(2,LV),
$ VCL(1,LVS),VCL(2,LVS))
IF (IV .EQ. J) GO TO 70
LVP = LV
IV = IVS
LV = LVS
GO TO 60
70 CONTINUE
C
C Initialize HOLV array.
C
IF (NHOLE .GT. 0) CALL HOLVRT(NHOLE,VCL,HVL(2),PVL,HOLV)
END
C
C The following code was excerpted from: edght.f
C
SUBROUTINE EDGHT(A,B,V,N,HTSIZ,MAXEDG,HDFREE,LAST,HT,EDGE,W)
IMPLICIT LOGICAL (A-Z)
INTEGER A,B,HDFREE,HTSIZ,LAST,MAXEDG,N,V,W
INTEGER EDGE(4,MAXEDG),HT(0:HTSIZ-1)
C
C Written and copyright by:
C Barry Joe, Dept. of Computing Science, Univ. of Alberta
C Edmonton, Alberta, Canada T6G 2H1
C Phone: (403) 492-5757 Email: barry@cs.ualberta.ca
C
C Purpose: Search in hash table HT for record in EDGE containing
C key (A,B).
C
C Input parameters:
C A,B - vertex indices, > 0, of edge (also key of hash table)
C V - value associated with edge
C N - upper bound on A, B
C HTSIZ - size of hash table HT
C MAXEDG - maximum size available for EDGE array
C HDFREE - head pointer to linked list of free entries of EDGE
C array due to deletions
C LAST - index of last entry used in EDGE array
C HT(0:HTSIZ-1) - hash table of head pointers (direct chaining
C with ordered lists is used)
C EDGE(1:4,1:MAXEDG) - entries of hash table records;
C EDGE(1,I) = MIN(A,B); EDGE(2,I) = MAX(A,B);
C EDGE(3,I) = V; EDGE(4,I) = link
C [Note: Before first call to this routine, HDFREE, LAST, and
C entries of HT should be set to 0.]
C
C Updated parameters:
C HDFREE,LAST - at least one of these is updated
C HT,EDGE - if key with A,B is found then this record is deleted
C from hash table, else record is inserted in hash table
C
C Output parameters:
C W - EDGE(3,INDEX), where INDEX is index of record, if found;
C else 0
C
C Abnormal return:
C IERR is set to 1
C
INTEGER IERR
COMMON /GERROR/ IERR
SAVE /GERROR/
C
INTEGER AA,BB,BPTR,K,NEWP,PTR
C
IF (A .LT. B) THEN
AA = A
BB = B
ELSE
AA = B
BB = A
ENDIF
K = MOD(AA*N + BB, HTSIZ)
BPTR = -1
PTR = HT(K)
10 CONTINUE
IF (PTR .NE. 0) THEN
IF (EDGE(1,PTR) .GT. AA) THEN
GO TO 20
ELSE IF (EDGE(1,PTR) .EQ. AA) THEN
IF (EDGE(2,PTR) .GT. BB) THEN
GO TO 20
ELSE IF (EDGE(2,PTR) .EQ. BB) THEN
IF (BPTR .EQ. -1) THEN
HT(K) = EDGE(4,PTR)
ELSE
EDGE(4,BPTR) = EDGE(4,PTR)
ENDIF
EDGE(4,PTR) = HDFREE
HDFREE = PTR
W = EDGE(3,PTR)
RETURN
ENDIF
ENDIF
BPTR = PTR
PTR = EDGE(4,PTR)
GO TO 10
ENDIF
20 CONTINUE
IF (HDFREE .GT. 0) THEN
NEWP = HDFREE
HDFREE = EDGE(4,HDFREE)
ELSE
LAST = LAST + 1
NEWP = LAST
IF (LAST .GT. MAXEDG) THEN
IERR = 1
RETURN
ENDIF
ENDIF
IF (BPTR .EQ. -1) THEN
HT(K) = NEWP
ELSE
EDGE(4,BPTR) = NEWP
ENDIF
EDGE(1,NEWP) = AA
EDGE(2,NEWP) = BB
EDGE(3,NEWP) = V
EDGE(4,NEWP) = PTR
W = 0
END
C
C The following code was excerpted from: fndsep.f
C
SUBROUTINE FNDSEP(ANGAC1,XR,YR,NVRT,XC,YC,IVIS,THETA,NV,IV,
$ VCL,PVL,IANG,ANGSEP,I1,I2,WKANG)
IMPLICIT LOGICAL (A-Z)
INTEGER I1,I2,NV,NVRT
INTEGER IV(0:NV),IVIS(0:NVRT),PVL(4,*)
DOUBLE PRECISION ANGAC1,ANGSEP,XR,YR,IANG(*),THETA(0:NVRT)
DOUBLE PRECISION VCL(2,*),WKANG(0:NV),XC(0:NVRT),YC(0:NVRT)
C
C Written and copyright by:
C Barry Joe, Dept. of Computing Science, Univ. of Alberta
C Edmonton, Alberta, Canada T6G 2H1
C Phone: (403) 492-5757 Email: barry@cs.ualberta.ca
C
C Purpose: Find 1 or 2 separators which can resolve reflex vertex
C (XR,YR) using a max-min angle criterion from list of vertices
C in increasing polar angle w.r.t. reflex vertex. Preference
C is given to 1 separator.
C
C Input parameters:
C ANGAC1 - angle tolerance parameter used for preference
C in accepting one separator
C XR,YR - coordinates of reflex vertex
C NVRT - (number of vertices) - 1
C XC(0:NVRT), YC(0:NVRT) - vertex coordinates of possible
C endpoints of a separator
C IVIS(0:NVRT) - contains information about the vertices of
C XC, YC arrays w.r.t. the polygon vertex list; if
C IVIS(I) > 0 then vertex (XC(I),YC(I)) has index IVIS(I)
C in PVL; if IVIS(I) < 0 then vertex (XC(I),YC(I)) is on
C the edge joining vertices with indices -IVIS(I) and
C SUCC(-IVIS(I)) in PVL
C THETA(0:NVRT) - polar angles of vertices in increasing order;
C THETA(NVRT) is the interior angle of reflex vertex;
C THETA(I), I >= 0, is the polar angle of (XC(I),YC(I))
C w.r.t. reflex vertex
C NV - (number of vertices to be considered as endpoint of a
C separator) - 1
C IV(0:NV) - indices of vertices in XC, YC arrays to be
C considered as endpoint of a separator; angle between
C consecutive vertices is assumed to be < 180 degrees
C VCL(1:2,1:*) - vertex coordinate list
C PVL(1:4,1:*),IANG(1:*) - polygon vertex list, interior angles
C
C Output parameters:
C ANGSEP - minimum of the 4 or 7 angles at the boundary
C resulting from 1 or 2 separators, respectively
C I1,I2 - indices of endpoints of separators in XC, YC arrays;
C I2 = -1 if there is only one separator, else I1 < I2
C
C Working parameters:
C WKANG(0:NV) - working array for angles
C
C Routines called:
C MINANG
C
DOUBLE PRECISION PI,TOL
COMMON /GCONST/ PI,TOL
SAVE /GCONST/
C
INTEGER I,II,K,L,M,NL,NR,P,Q,R
DOUBLE PRECISION ANG,ANGSP2,MINANG,PHI
C
C Determine the vertices in the inner cone - indices P to Q.
C
I = 0
P = -1
PHI = THETA(NVRT) - PI + TOL
10 CONTINUE
IF (P .GE. 0) GO TO 20
IF (THETA(IV(I)) .GE. PHI) THEN
P = I
ELSE
I = I + 1
ENDIF
GO TO 10
20 CONTINUE
I = NV
Q = -1
PHI = PI - TOL
30 CONTINUE
IF (Q .GE. 0) GO TO 40
IF (THETA(IV(I)) .LE. PHI) THEN
Q = I
ELSE
I = I - 1
ENDIF
GO TO 30
40 CONTINUE
C
C Use the max-min angle criterion to find the best separator
C in inner cone.
C
ANGSEP = 0.0D0
DO 50 I = P,Q
K = IV(I)
ANG = MINANG(XR,YR,XC(K),YC(K),IVIS(K),THETA(K),THETA(NVRT),
$ VCL,PVL,IANG)
IF (ANG .GT. ANGSEP) THEN
ANGSEP = ANG
II = IV(I)
ENDIF
50 CONTINUE
ANGSP2 = ANGSEP
IF (ANGSEP .GE. ANGAC1) GO TO 110
C
C If the best separator in inner cone is not 'good' enough,
C use max-min angle criterion to try to find a better pair
C of separators from the right and left cones.
C
NR = 0
NL = 0
DO 60 R = 0,P-1
WKANG(R) = 0.0D0
IF (THETA(IV(R)) .GT. ANGSEP) THEN
K = IV(R)
ANG = MINANG(XR,YR,XC(K),YC(K),IVIS(K),THETA(K),THETA(NVRT),
$ VCL,PVL,IANG)
IF (ANG .GT. ANGSEP) THEN
NR = NR + 1
WKANG(R) = ANG
ENDIF
ENDIF
60 CONTINUE
IF (NR .EQ. 0) GO TO 110
PHI = THETA(NVRT) - ANGSEP
DO 70 L = Q+1,NV
WKANG(L) = 0.0D0
IF (THETA(IV(L)) .LT. PHI) THEN
K = IV(L)
ANG = MINANG(XR,YR,XC(K),YC(K),IVIS(K),THETA(K),THETA(NVRT),
$ VCL,PVL,IANG)
IF (ANG .GT. ANGSEP) THEN
NL = NL + 1
WKANG(L) = ANG
ENDIF
ENDIF
70 CONTINUE
IF (NL .EQ. 0) GO TO 110
C
C Check all possible pairs for the best pair of separators
C in the right and left cones.
C
M = NV
DO 100 R = P-1,0,-1
IF (M .GT. Q .AND. WKANG(R) .GT. ANGSP2) THEN
PHI = THETA(IV(R))
80 CONTINUE
IF (M .GT. Q .AND. (WKANG(M) .LE. ANGSP2 .OR.
$ THETA(IV(M)) - PHI .GT. PI - TOL)) THEN
M = M - 1
GO TO 80
ENDIF
DO 90 L = Q+1,M
IF (WKANG(L) .GT. ANGSP2) THEN
ANG = MIN(THETA(IV(L)) - PHI, WKANG(R), WKANG(L))
IF (ANG .GT. ANGSP2) THEN
ANGSP2 = ANG
I1 = IV(R)
I2 = IV(L)
ENDIF
ENDIF
90 CONTINUE
ENDIF
100 CONTINUE
C
C Choose 1 or 2 separators based on max-min angle criterion or
C ANGAC1 parameter.
C
110 CONTINUE
IF (ANGSP2 .LE. ANGSEP) THEN
I1 = II
I2 = -1
ELSE
ANGSEP = ANGSP2
ENDIF
END
C
C The following code was excerpted from: holvrt.f
C
SUBROUTINE HOLVRT(NHOLE,VCL,HVL,PVL,HOLV)
IMPLICIT LOGICAL (A-Z)
INTEGER NHOLE
INTEGER HOLV(NHOLE*2),HVL(NHOLE),PVL(4,*)
DOUBLE PRECISION VCL(2,*)
C
C Written and copyright by:
C Barry Joe, Dept. of Computing Science, Univ. of Alberta
C Edmonton, Alberta, Canada T6G 2H1
C Phone: (403) 492-5757 Email: barry@cs.ualberta.ca
C
C Purpose: Determine top and bottom vertices of holes in polygonal
C region(s), and sort top vertices in decreasing (y,x) order
C and bottom vertices in increasing (y,x) order.
C
C Input parameters:
C NHOLE - number of holes in region(s)
C VCL(1:2,1:*) - vertex coordinate list
C HVL(1:NHOLE) - head vertex list; HVL(I) is index in PVL of
C head vertex of Ith hole
C PVL(1:4,1:*) - polygon vertex list; see routine DSPGDC
C
C Output parameters:
C HOLV(1:NHOLE*2) - indices in PVL of top and bottom vertices of
C holes; first (last) NHOLE entries are for top (bottom)
C vertices; top (bottom) vertices are sorted in decreasing
C (increasing) lexicographic (y,x) order of coordinates
C
INTEGER EDGV,LOC,POLG,SUCC
PARAMETER (LOC = 1, POLG = 2, SUCC = 3, EDGV = 4)
C
INTEGER HV,I,IMAX,IMIN,IV,J,LV,NHP1
DOUBLE PRECISION X,XMAX,XMIN,Y,YMAX,YMIN
C
C Determine top and bottom vertices of holes.
C
IMIN = HVL(1)
IMAX = HVL(1)
XMIN = VCL(1,PVL(LOC,HVL(1)))
YMIN = VCL(2,PVL(LOC,HVL(1)))
XMAX = XMIN
YMAX = YMIN
DO 20 I = 1,NHOLE
HV = HVL(I)
IV = HV
10 CONTINUE
LV = PVL(LOC,IV)
IF (IV .EQ. HV) THEN
IMIN = IV
IMAX = IV
XMIN = VCL(1,LV)
YMIN = VCL(2,LV)
XMAX = XMIN
YMAX = YMIN
ELSE
X = VCL(1,LV)
Y = VCL(2,LV)
IF (Y .LT. YMIN .OR. Y .EQ. YMIN .AND. X .LT. XMIN) THEN
IMIN = IV
XMIN = X
YMIN = Y
ELSE IF (Y .GT. YMAX .OR. Y .EQ. YMAX .AND. X .GT. XMAX)
$ THEN
IMAX = IV
XMAX = X
YMAX = Y
ENDIF
ENDIF
IV = PVL(SUCC,IV)
IF (IV .NE. HV) GO TO 10
HOLV(I) = IMAX
HOLV(I+NHOLE) = IMIN
20 CONTINUE
C
C Use linear insertion sort to sort the top vertices of holes
C in decreasing (y,x) order, then bottom vertices in increasing
C (y,x) order. It is assumed NHOLE is small.
C
DO 40 I = 2,NHOLE
HV = HOLV(I)
LV = PVL(LOC,HV)
X = VCL(1,LV)
Y = VCL(2,LV)
J = I
30 CONTINUE
IV = HOLV(J-1)
LV = PVL(LOC,IV)
IF (Y .GT. VCL(2,LV) .OR. Y .EQ. VCL(2,LV) .AND.
$ X .GT. VCL(1,LV)) THEN
HOLV(J) = IV
J = J - 1
IF (J .GT. 1) GO TO 30
ENDIF
HOLV(J) = HV
40 CONTINUE
C
NHP1 = NHOLE + 1
DO 60 I = NHP1+1,NHOLE+NHOLE
HV = HOLV(I)
LV = PVL(LOC,HV)
X = VCL(1,LV)
Y = VCL(2,LV)
J = I
50 CONTINUE
IV = HOLV(J-1)
LV = PVL(LOC,IV)
IF (Y .LT. VCL(2,LV) .OR. Y .EQ. VCL(2,LV) .AND.
$ X .LT. VCL(1,LV)) THEN
HOLV(J) = IV
J = J - 1
IF (J .GT. NHP1) GO TO 50
ENDIF
HOLV(J) = HV
60 CONTINUE
END
C
C The following code was excerpted from: insed2.f
C
SUBROUTINE INSED2(V,W,NPOLG,NVERT,MAXHV,MAXPV,VCL,REGNUM,HVL,
$ PVL,IANG)
IMPLICIT LOGICAL (A-Z)
INTEGER MAXHV,MAXPV,NPOLG,NVERT,V,W
INTEGER HVL(MAXHV),PVL(4,MAXPV)
INTEGER REGNUM(MAXHV)
DOUBLE PRECISION IANG(MAXPV),VCL(2,*)
C
C Written and copyright by:
C Barry Joe, Dept. of Computing Science, Univ. of Alberta
C Edmonton, Alberta, Canada T6G 2H1
C Phone: (403) 492-5757 Email: barry@cs.ualberta.ca
C
C Purpose: Insert edge joining vertices V, W into head vertex
C list and polygon vertex list data structures.
C
C Input parameters:
C V,W - indices in PVL of vertices which are the endpoints
C of an edge to be added to decomposition
C NPOLG - number of positions used in HVL array
C NVERT - number of positions used in PVL array
C MAXHV - maximum size available for HVL array
C MAXPV - maximum size available for PVL array
C VCL(1:2,1:*) - vertex coordinate list
C REGNUM(1:NPOLG) - region numbers
C HVL(1:NPOLG) - head vertex list
C PVL(1:4,1:NVERT),IANG(1:NVERT) - polygon vertex list and
C interior angles
C
C Updated parameters:
C REGNUM,HVL,PVL,IANG
C
C Abnormal return:
C IERR is set to 4 or 5
C
C Routines called:
C ANGLE
C
INTEGER IERR,IPRT,MSGLVL
COMMON /GERROR/ IERR
COMMON /GPRINT/ IPRT,MSGLVL
SAVE /GERROR/,/GPRINT/
C
INTEGER EDGV,LOC,POLG,SUCC
PARAMETER (LOC = 1, POLG = 2, SUCC = 3, EDGV = 4)
C
INTEGER I,L,LV,LW,VV,WW
DOUBLE PRECISION ANGLE
C
IF (NPOLG .GE. MAXHV) THEN
IERR = 4
RETURN
ELSE IF (NVERT+2 .GT. MAXPV) THEN
IERR = 5
RETURN
ENDIF
C
C Split linked list of vertices of the polygon containing vertices
C V and W into two linked list of vertices of polygons with common
C edge joining V and W.
C
NVERT = NVERT + 2
VV = NVERT - 1
WW = NVERT
LV = PVL(LOC,V)
LW = PVL(LOC,W)
PVL(LOC,VV) = LV
PVL(LOC,WW) = LW
PVL(POLG,WW) = PVL(POLG,V)
PVL(SUCC,VV) = PVL(SUCC,V)
PVL(SUCC,WW) = PVL(SUCC,W)
PVL(SUCC,V) = WW
PVL(SUCC,W) = VV
PVL(EDGV,VV) = PVL(EDGV,V)
PVL(EDGV,WW) = PVL(EDGV,W)
PVL(EDGV,V) = W
PVL(EDGV,W) = V
IF (PVL(EDGV,VV) .GT. 0) PVL(EDGV,PVL(EDGV,VV)) = VV
IF (PVL(EDGV,WW) .GT. 0) PVL(EDGV,PVL(EDGV,WW)) = WW
L = PVL(LOC,PVL(SUCC,VV))
IANG(VV) = ANGLE(VCL(1,LW),VCL(2,LW),VCL(1,LV),VCL(2,LV),
$ VCL(1,L),VCL(2,L))
IANG(V) = IANG(V) - IANG(VV)
L = PVL(LOC,PVL(SUCC,WW))
IANG(WW) = ANGLE(VCL(1,LV),VCL(2,LV),VCL(1,LW),VCL(2,LW),
$ VCL(1,L),VCL(2,L))
IANG(W) = IANG(W) - IANG(WW)
NPOLG = NPOLG + 1
I = VV
10 CONTINUE
PVL(POLG,I) = NPOLG
I = PVL(SUCC,I)
IF (I .NE. VV) GO TO 10
HVL(PVL(POLG,V)) = V
HVL(NPOLG) = VV
REGNUM(NPOLG) = REGNUM(PVL(POLG,V))
C
END
C
C The following code was excerpted from: insvr2.f
C
SUBROUTINE INSVR2(XI,YI,WP,NVC,NVERT,MAXVC,MAXPV,VCL,PVL,IANG,W)
IMPLICIT LOGICAL (A-Z)
INTEGER MAXPV,MAXVC,NVC,NVERT,PVL(4,MAXPV),W,WP
DOUBLE PRECISION IANG(MAXPV),VCL(2,MAXVC),XI,YI
C
C Written and copyright by:
C Barry Joe, Dept. of Computing Science, Univ. of Alberta
C Edmonton, Alberta, Canada T6G 2H1
C Phone: (403) 492-5757 Email: barry@cs.ualberta.ca
C
C Purpose: Insert point (XI,YI) into vertex coordinate list and
C polygon vertex list data structures.
C
C Input parameters:
C XI,YI - coordinates of point to be inserted
C WP - index of vertex in PVL which is to be the predecessor
C vertex of the inserted vertex
C NVC - number of positions used in VCL array
C NVERT - number of positions used in PVL array
C MAXVC - maximum size available for VCL array
C MAXPV - maximum size available for PVL array
C VCL(1:2,1:NVC) - vertex coordinate list
C PVL(1:4,1:NVERT),IANG(1:NVERT) - polygon vertex list and
C interior angles
C
C Updated parameters:
C NVC,NVERT,VCL,PVL,IANG
C
C Output parameter:
C W - index of inserted vertex in PVL
C
C Abnormal return:
C IERR is set to 3 or 5
C
INTEGER IERR
DOUBLE PRECISION PI,TOL
COMMON /GERROR/ IERR
COMMON /GCONST/ PI,TOL
SAVE /GERROR/,/GCONST/
C
INTEGER EDGV,LOC,POLG,SUCC
PARAMETER (LOC = 1, POLG = 2, SUCC = 3, EDGV = 4)
C
INTEGER WS,WW,WWP,WWS
C
IF (NVC .GE. MAXVC) THEN
IERR = 3
RETURN
ELSE IF (NVERT+2 .GT. MAXPV) THEN
IERR = 5
RETURN
ENDIF
C
C Update linked list of vertices of polygon containing vertex WP.
C
NVC = NVC + 1
VCL(1,NVC) = XI
VCL(2,NVC) = YI
WS = PVL(SUCC,WP)
NVERT = NVERT + 1
W = NVERT
PVL(LOC,W) = NVC
PVL(POLG,W) = PVL(POLG,WP)
PVL(SUCC,WP) = W
PVL(SUCC,W) = WS
IANG(W) = PI
PVL(EDGV,W) = PVL(EDGV,WP)
C
C If edge containing (XI,YI) is shared by another polygon,
C then also update linked list of vertices of that polygon.
C
IF (PVL(EDGV,WP) .GT. 0) THEN
WWS = PVL(EDGV,WP)
WWP = PVL(SUCC,WWS)
NVERT = NVERT + 1
WW = NVERT
PVL(LOC,WW) = NVC
PVL(POLG,WW) = PVL(POLG,WWS)
PVL(SUCC,WWS) = WW
PVL(SUCC,WW) = WWP
IANG(WW) = PI
PVL(EDGV,WP) = WW
PVL(EDGV,WW) = WP
PVL(EDGV,WWS) = W
ENDIF
END
C
C The following code was excerpted from: jnhole.f
C
SUBROUTINE JNHOLE(ITOPHV,ANGSPC,ANGTOL,NVC,NVERT,MAXVC,MAXPV,
$ MAXIW,MAXWK,VCL,HVL,PVL,IANG,IWK,WK)
IMPLICIT LOGICAL (A-Z)
INTEGER ITOPHV,MAXIW,MAXPV,MAXVC,MAXWK,NVC,NVERT
INTEGER HVL(*),IWK(MAXIW),PVL(4,MAXPV)
DOUBLE PRECISION ANGSPC,ANGTOL,IANG(MAXPV),VCL(2,MAXVC),WK(MAXWK)
C
C Written and copyright by:
C Barry Joe, Dept. of Computing Science, Univ. of Alberta
C Edmonton, Alberta, Canada T6G 2H1
C Phone: (403) 492-5757 Email: barry@cs.ualberta.ca
C
C Purpose: Join hole boundary to boundary of polygon containing hole
C by finding a cut edge originating from the top vertex of hole
C to a point on outer polygon boundary above it.
C
C Input parameters:
C ITOPHV - index in PVL of top vertex of hole
C ANGSPC - angle spacing parameter used in controlling the
C vertices to be considered as an endpoint of a separator
C ANGTOL - angle tolerance parameter used in accepting
C separator(s)
C NVC - number of positions used in VCL array
C NVERT - number of positions used in PVL array
C MAXVC - maximum size available for VCL array
C MAXPV - maximum size available for PVL array
C MAXIW - maximum size available for IWK array; should be about
C 3 times number of vertices in outer polygon
C MAXWK - maximum size available for WK array; should be about
C 5 times number of vertices in outer polygon
C VCL(1:2,1:NVC) - vertex coordinate list
C HVL(1:*) - head vertex list
C PVL(1:4,1:NVERT),IANG(1:NVERT) - polygon vertex list and
C interior angles
C
C Updated parameters:
C NVC,NVERT,VCL,PVL,IANG
C
C Working parameters:
C IWK(1:MAXIW) - integer work array
C WK(1:MAXWK) - double precision work array
C
C Abnormal return:
C IERR is set to 3, 5, 6, 7, 206 to 210, 212, 218, or 219
C
C Routines called:
C ANGLE, RESVRT
C
INTEGER IERR,IPRT,MSGLVL
DOUBLE PRECISION PI,TOL
COMMON /GERROR/ IERR
COMMON /GCONST/ PI,TOL
COMMON /GPRINT/ IPRT,MSGLVL
SAVE /GERROR/,/GCONST/,/GPRINT/
C
INTEGER EDGV,LOC,POLG,SUCC
PARAMETER (LOC = 1, POLG = 2, SUCC = 3, EDGV = 4)
C
INTEGER HV,ILFT,IPOLY,IRGT,IV,IVS,L,LV,LW,SUCCIL,SUCCIR
INTEGER VP,VR,VS,VV,W,WW
DOUBLE PRECISION ANGLE,DY,S,SLFT,SRGT,XINT,XLFT,XRGT,XT,XV,XVS
DOUBLE PRECISION YLFT,YRGT,YT,YTMTOL,YTPTOL,YV,YVS
C
IF (NVC+3 .GT. MAXVC) THEN
IERR = 3
RETURN
ELSE IF (NVERT+5 .GT. MAXPV) THEN
IERR = 5
RETURN
ENDIF
C
C Determine 'closest' vertices on outer boundary which are to the
C left and right of top vertex of hole and on the horizontal line
C through top vertex. The two closest vertices must be on edges
C which intersect the horizontal line and are partially above the
C line. Ties are broken (in the case of a vertex on a cut edge)
C by choosing the vertex on the edge of maximum or minimum dx/dy
C slope depending on whether the vertex is to the left or right
C of top vertex, respectively.
C
IPOLY = PVL(POLG,ITOPHV)
LV = PVL(LOC,ITOPHV)
XT = VCL(1,LV)
YT = VCL(2,LV)
DY = 0.0D0
HV = HVL(IPOLY)
IV = HV
YV = VCL(2,PVL(LOC,IV))
SLFT = 0.0
SRGT = 0.0
10 CONTINUE
IV = PVL(SUCC,IV)
YVS = VCL(2,PVL(LOC,IV))
DY = MAX(DY,ABS(YVS-YV))
YV = YVS
IF (IV .NE. HV) GO TO 10
YTMTOL = YT - TOL*DY
YTPTOL = YT + TOL*DY
ILFT = 0
IRGT = 0
XLFT = 0.0D0
XRGT = 0.0D0
HV = HVL(IPOLY)
IV = HV
LV = PVL(LOC,IV)
XV = VCL(1,LV)
YV = VCL(2,LV)
20 CONTINUE
IVS = PVL(SUCC,IV)
LV = PVL(LOC,IVS)
XVS = VCL(1,LV)
YVS = VCL(2,LV)
IF (YV .LE. YTPTOL .AND. YVS .GT. YTPTOL) THEN
IF (YV .GE. YTMTOL) THEN
IF (XV .GT. XT) THEN
IF (XV .LT. XRGT .OR. IRGT .EQ. 0) THEN
IRGT = IV
XRGT = XV
YRGT = YV
SRGT = (XVS - XV)/(YVS - YV)
ELSE IF (XV .EQ. XRGT) THEN
S = (XVS - XV)/(YVS - YV)
IF (S .LT. SRGT) THEN
IRGT = IV
YRGT = YV
SRGT = S
ENDIF
ENDIF
ENDIF
ELSE
XINT = (YT - YV)*(XVS - XV)/(YVS - YV) + XV
IF (XINT .GT. XT) THEN
IF (XINT .LT. XRGT .OR. IRGT .EQ. 0) THEN
IRGT = IV
XRGT = XINT
YRGT = YT
ENDIF
ENDIF
ENDIF
ELSE IF (YV .GT. YTPTOL .AND. YVS .LE. YTPTOL) THEN
IF (YVS .GE. YTMTOL) THEN
IF (XVS .LT. XT) THEN
IF (XVS .GT. XLFT .OR. ILFT .EQ. 0) THEN
ILFT = IV
XLFT = XVS
YLFT = YVS
SLFT = (XVS - XV)/(YVS - YV)
ELSE IF (XVS .EQ. XLFT) THEN
S = (XVS - XV)/(YVS - YV)
IF (S .GT. SLFT) THEN
ILFT = IV
YLFT = YVS
SLFT = S
ENDIF
ENDIF
ENDIF
ELSE
XINT = (YT - YV)*(XVS - XV)/(YVS - YV) + XV
IF (XINT .LT. XT) THEN
IF (XINT .GT. XLFT .OR. ILFT .EQ. 0) THEN
ILFT = IV
XLFT = XINT
YLFT = YT
ENDIF
ENDIF
ENDIF
ENDIF
IV = IVS
XV = XVS
YV = YVS
IF (IV .NE. HV) GO TO 20
C
IF (ILFT .EQ. 0 .OR. IRGT .EQ. 0) THEN
IERR = 218
RETURN
ENDIF
C
C Temporarily modify PVL to pass the subregion 'above' top vertex
C of hole to routine RESVRT. The top vertex is the reflex vertex
C passed to RESVRT (in the temporary subregion, it has interior
C angle PI). This causes one separator to be chosen by RESVRT
C and its other endpoint is above the top vertex.
C
SUCCIL = PVL(SUCC,ILFT)
SUCCIR = PVL(SUCC,IRGT)
VCL(1,NVC+2) = XLFT
VCL(2,NVC+2) = YLFT
VCL(1,NVC+3) = XRGT
VCL(2,NVC+3) = YRGT
VP = NVERT + 3
VR = NVERT + 4
VS = NVERT + 5
IANG(VR) = ANGLE(XLFT,YLFT,XT,YT,XRGT,YRGT)
IF (IANG(VR) .LT. PI - TOL .OR. IANG(VR) .GT. PI + TOL) THEN
IERR = 219
RETURN
ENDIF
PVL(LOC,VP) = NVC + 2
PVL(POLG,VP) = IPOLY
PVL(SUCC,VP) = VR
PVL(EDGV,VP) = 0
PVL(LOC,VR) = PVL(LOC,ITOPHV)
PVL(POLG,VR) = IPOLY
PVL(SUCC,VR) = VS
PVL(EDGV,VR) = 0
PVL(LOC,VS) = NVC + 3
PVL(POLG,VS) = IPOLY
PVL(SUCC,VS) = SUCCIR
PVL(EDGV,VS) = PVL(EDGV,IRGT)
PVL(SUCC,ILFT) = VP
LV = PVL(LOC,ILFT)
IANG(VP) = ANGLE(VCL(1,LV),VCL(2,LV),XLFT,YLFT,XT,YT)
LV = PVL(LOC,SUCCIR)
IANG(VS) = ANGLE(XT,YT,XRGT,YRGT,VCL(1,LV),VCL(2,LV))
W = 0
CALL RESVRT(VR,ANGSPC,ANGTOL,NVC,NVERT,MAXVC,MAXPV,MAXIW,MAXWK,
$ VCL,PVL,IANG,W,WW,IWK,WK)
C
C Remove temporary modification to PVL. There are three cases
C depending on where the endpoint of separator is located:
C successor of closest vertex to the right of top vertex,
C predecessor of closest vertex to the left of top vertex,
C or neither of these.
C
IF (PVL(SUCC,VS) .EQ. W) THEN
PVL(SUCC,ILFT) = SUCCIL
PVL(SUCC,IRGT) = W
PVL(EDGV,IRGT) = PVL(EDGV,VS)
IF (PVL(EDGV,IRGT) .GT. 0) PVL(EDGV,PVL(EDGV,IRGT)) = IRGT
ELSE IF (PVL(SUCC,ILFT) .EQ. W) THEN
PVL(SUCC,W) = SUCCIL
ELSE
PVL(SUCC,ILFT) = SUCCIL
ENDIF
IF (IERR .NE. 0) RETURN
C
C Update PVL with cut edge, i.e. join linked lists of vertices
C of the hole polygon and the outer boundary polygon into one
C linked list of vertices by adding the cut edge from the top
C vertex of hole to the vertex on the outer boundary.
C
NVERT = NVERT + 2
VV = NVERT - 1
WW = NVERT
LV = PVL(LOC,ITOPHV)
LW = PVL(LOC,W)
PVL(LOC,VV) = LV
PVL(LOC,WW) = LW
PVL(POLG,VV) = IPOLY
PVL(POLG,WW) = IPOLY
PVL(SUCC,VV) = PVL(SUCC,ITOPHV)
PVL(SUCC,WW) = PVL(SUCC,W)
PVL(SUCC,ITOPHV) = WW
PVL(SUCC,W) = VV
PVL(EDGV,VV) = PVL(EDGV,ITOPHV)
PVL(EDGV,WW) = PVL(EDGV,W)
PVL(EDGV,ITOPHV) = W
PVL(EDGV,W) = ITOPHV
IF (PVL(EDGV,VV) .GT. 0) PVL(EDGV,PVL(EDGV,VV)) = VV
IF (PVL(EDGV,WW) .GT. 0) PVL(EDGV,PVL(EDGV,WW)) = WW
L = PVL(LOC,PVL(SUCC,VV))
IANG(VV) = ANGLE(VCL(1,LW),VCL(2,LW),VCL(1,LV),VCL(2,LV),
$ VCL(1,L),VCL(2,L))
IANG(ITOPHV) = IANG(ITOPHV) - IANG(VV)
L = PVL(LOC,PVL(SUCC,WW))
IANG(WW) = ANGLE(VCL(1,LV),VCL(2,LV),VCL(1,LW),VCL(2,LW),
$ VCL(1,L),VCL(2,L))
IANG(W) = IANG(W) - IANG(WW)
C
END
C
C The following code was excerpted from: minang.f
C
DOUBLE PRECISION FUNCTION MINANG(XR,YR,XS,YS,IND,ALPHA,THETA,
$ VCL,PVL,IANG)
IMPLICIT LOGICAL (A-Z)
INTEGER IND,PVL(4,*)
DOUBLE PRECISION ALPHA,IANG(*),THETA,VCL(2,*),XR,XS,YR,YS
C
C Written and copyright by:
C Barry Joe, Dept. of Computing Science, Univ. of Alberta
C Edmonton, Alberta, Canada T6G 2H1
C Phone: (403) 492-5757 Email: barry@cs.ualberta.ca
C
C Purpose: Determine the minimum of the 4 angles at the boundary
C resulting from using edge joining vertices (XR,YR) and
C (XS,YS) as a separator.
C
C Input parameters:
C XR,YR - coordinates of reflex vertex
C XS,YS - coordinates of other endpoint of possible separator
C IND - if positive then (XS,YS) has index IND in PVL; else
C (XS,YS) is on edge joining vertices with indices -IND
C and SUCC(-IND) in PVL
C ALPHA - polar angle of (XS,YS) w.r.t. (XR,YR)
C THETA - interior angle at reflex vertex
C VCL(1:2,1:*) - vertex coordinate list
C PVL(1:4,1:*),IANG(1:*) - polygon vertex list, interior angles
C
C Returned function value:
C MINANG - minimum of the 4 angles in radians
C
C Routines called:
C ANGLE
C
DOUBLE PRECISION PI,TOL
COMMON /GCONST/ PI,TOL
SAVE /GCONST/
C
INTEGER EDGV,LOC,POLG,SUCC
PARAMETER (LOC = 1, POLG = 2, SUCC = 3, EDGV = 4)
C
INTEGER J,L
DOUBLE PRECISION ANG,ANGLE,BETA1
C
IF (IND .GT. 0) THEN
J = PVL(SUCC,IND)
ANG = IANG(IND)
ELSE
J = PVL(SUCC,-IND)
ANG = PI
ENDIF
L = PVL(LOC,J)
BETA1 = ANGLE(XR,YR,XS,YS,VCL(1,L),VCL(2,L))
MINANG = MIN(ALPHA, THETA - ALPHA, ANG - BETA1, BETA1)
END
C
C The following code was excerpted from: resvrt.f
C
SUBROUTINE RESVRT(VR,ANGSPC,ANGTOL,NVC,NVERT,MAXVC,MAXPV,MAXIW,
$ MAXWK,VCL,PVL,IANG,W1,W2,IWK,WK)
IMPLICIT LOGICAL (A-Z)
INTEGER MAXIW,MAXPV,MAXVC,MAXWK,NVC,NVERT,VR,W1,W2
INTEGER IWK(MAXIW),PVL(4,MAXPV)
DOUBLE PRECISION ANGSPC,ANGTOL,IANG(MAXPV),VCL(2,MAXVC),WK(MAXWK)
C
C Written and copyright by:
C Barry Joe, Dept. of Computing Science, Univ. of Alberta
C Edmonton, Alberta, Canada T6G 2H1
C Phone: (403) 492-5757 Email: barry@cs.ualberta.ca
C
C Purpose: Resolve reflex vertex of simply connected polygon with
C one or two separators. The reflex vertex must be a 'simple'
C vertex of the polygon.
C
C Input parameters:
C VR - index in PVL of reflex vertex
C ANGSPC - angle spacing parameter used in controlling the
C vertices to be considered as an endpoint of a separator
C ANGTOL - angle tolerance parameter used in accepting
C separator(s)
C NVC - number of positions used in VCL array
C NVERT - number of positions used in PVL array
C MAXVC - maximum size available for VCL array
C MAXPV - maximum size available for PVL array
C MAXIW - maximum size available for IWK array; should be about
C 3 times number of vertices in polygon
C MAXWK - maximum size available for WK array; should be about
C 5 times number of vertices in polygon
C VCL(1:2,1:NVC) - vertex coordinate list
C PVL(1:4,1:NVERT),IANG(1:NVERT) - polygon vertex list and
C interior angles
C
C Updated parameters:
C NVC,NVERT,VCL,PVL,IANG - are updated if INSVR2 is called
C
C Output parameters:
C W1 - index in PVL of vertex which is the endpoint of separator
C in inner cone or right cone w.r.t. reflex vertex
C W2 - 0 if there is only one separator; else index in PVL of
C vertex which is endpoint of 2nd separator in left cone
C
C Working parameters:
C IWK(1:MAXIW) - integer work array
C WK(1:MAXWK) - double precision work array
C
C Abnormal return:
C IERR is set to 3, 5, 6, 7, 206, 207, 208, 209, 210, or 212
C
C Routines called:
C FNDSEP, INSVR2, VISPOL, VISVRT, VORNBR
C
INTEGER IERR
COMMON /GERROR/ IERR
SAVE /GERROR/
C
INTEGER EDGV,LOC,POLG,SUCC
PARAMETER (LOC = 1, POLG = 2, SUCC = 3, EDGV = 4)
C
INTEGER I,I1,I2,IVIS,IVOR,IVRT,L,MAXN,NVIS,NVOR,NVRT,NVSVRT
INTEGER THETA,V,WKANG,XC,XVOR,YC,YVOR
DOUBLE PRECISION ANGSEP,XR,YR
C
C Determine number of vertices in polygon containing reflex vertex.
C
NVRT = 0
V = VR
10 CONTINUE
V = PVL(SUCC,V)
IF (V .NE. VR) THEN
NVRT = NVRT + 1
GO TO 10
ENDIF
MAXN = NVRT + INT(IANG(VR)/ANGSPC)
L = PVL(LOC,VR)
XR = VCL(1,L)
YR = VCL(2,L)
C
C Set up work arrays for routine VISPOL, and determine whether there
C is enough workspace. XC, YC are d.p. arrays of length NVRT in WK,
C used for the coordinates of the polygon containing the reflex
C vertex. MAXN positions are reserved for XC, YC since this is the
C maximum space required by routine VISVRT. IVIS is an integer array
C of length MAXN in IWK. IVRT is an integer array of length NVRT in
C IWK used temporarily for storing indices of vertices in PVL.
C
IF (MAXN + NVRT .GT. MAXIW) THEN
IERR = 6
RETURN
ELSE IF (MAXN + MAXN .GT. MAXWK) THEN
IERR = 7
RETURN
ENDIF
IVIS = 1
IVRT = IVIS + MAXN
XC = 1
YC = XC + MAXN
V = PVL(SUCC,VR)
DO 20 I = 0,NVRT-1
L = PVL(LOC,V)
WK(XC+I) = VCL(1,L)
WK(YC+I) = VCL(2,L)
IWK(IVRT+I) = V
V = PVL(SUCC,V)
20 CONTINUE
CALL VISPOL(XR,YR,NVRT-1,WK(XC),WK(YC),NVIS,IWK(IVIS))
IF (IERR .NE. 0) RETURN
C
C XC, YC now contain visibility polygon coordinates. Update MAXN
C and set up d.p. array THETA of length MAXN in WK for routine
C VISVRT. Elements of IVIS are changed to indices of PVL after call.
C
MAXN = MAXN - NVRT + NVIS + 1
THETA = YC + MAXN
IF (THETA + MAXN - 1 .GT. MAXWK) THEN
IERR = 7
RETURN
ENDIF
CALL VISVRT(ANGSPC,XR,YR,NVIS,WK(XC),WK(YC),IWK(IVIS),MAXN-1,
$ NVSVRT,WK(THETA))
WK(THETA+NVSVRT) = IANG(VR)
DO 30 I = IVIS,IVIS+NVSVRT
L = IWK(I)
IF (L .GE. 0) THEN
IWK(I) = IWK(IVRT+L)
ELSE
IWK(I) = -IWK(IVRT-L-1)
ENDIF
30 CONTINUE
C
C XC, YC now contain coord. of visible vertices to be considered
C as an endpoint of a separator. Set up work arrays for routine
C VORNBR. Integer array IVOR and d.p. arrays XVOR, YVOR, each of
C length NVSVRT+1, are added at the end of IWK and WK arrays.
C
IVOR = IVIS + NVSVRT + 1
XVOR = THETA + NVSVRT + 1
YVOR = XVOR + NVSVRT + 1
IF (IVOR + NVSVRT .GT. MAXIW) THEN
IERR = 6
RETURN
ELSE IF (YVOR + NVSVRT .GT. MAXWK) THEN
IERR = 7
RETURN
ENDIF
CALL VORNBR(XR,YR,NVSVRT,WK(XC),WK(YC),NVOR,IWK(IVOR),WK(XVOR),
$ WK(YVOR))
IF (IERR .NE. 0) RETURN
C
C Set up d.p. array WKANG of length NVOR+1 <= NVSVRT+1 in WK for
C routine FNDSEP. Only Voronoi neighbours are considered as an
C endpoint of a separator in the first call to FNDSEP. If the
C minimum angle created at the boundary by the separator(s) is too
C small, then a second call is made to FNDSEP in which all visible
C vertices are considered as an endpoint of a separator.
C
WKANG = XVOR
IF (IWK(IVOR+NVOR) .EQ. NVSVRT) NVOR = NVOR - 1
IF (IWK(IVOR) .EQ. 0) THEN
IVOR = IVOR + 1
NVOR = NVOR - 1
ENDIF
CALL FNDSEP(ANGTOL+ANGTOL,XR,YR,NVSVRT,WK(XC),WK(YC),IWK(IVIS),
$ WK(THETA),NVOR,IWK(IVOR),VCL,PVL,IANG,ANGSEP,I1,I2,WK(WKANG))
IF (ANGSEP .LT. ANGTOL) THEN
IVRT = IVIS + NVSVRT + 1
DO 40 I = 1,NVSVRT-1
IWK(IVRT+I-1) = I
40 CONTINUE
CALL FNDSEP(ANGTOL+ANGTOL,XR,YR,NVSVRT,WK(XC),WK(YC),IWK(IVIS),
$ WK(THETA),NVSVRT-2,IWK(IVRT),VCL,PVL,IANG,ANGSEP,I1,I2,
$ WK(WKANG))
ENDIF
C
C Insert endpoint(s) of separator(s) in vertex coordinate list and
C polygon vertex list data structures, if they are not yet there.
C
IF (I2 .EQ. -1) THEN
W2 = 0
ELSE IF (IWK(IVIS+I2) .LT. 0) THEN
CALL INSVR2(WK(XC+I2),WK(YC+I2),-IWK(IVIS+I2),NVC,NVERT,MAXVC,
$ MAXPV,VCL,PVL,IANG,W2)
IF (IERR .NE. 0) RETURN
ELSE
W2 = IWK(IVIS+I2)
ENDIF
IF (IWK(IVIS+I1) .LT. 0) THEN
CALL INSVR2(WK(XC+I1),WK(YC+I1),-IWK(IVIS+I1),NVC,NVERT,MAXVC,
$ MAXPV,VCL,PVL,IANG,W1)
IF (IERR .NE. 0) RETURN
ELSE
W1 = IWK(IVIS+I1)
ENDIF
END
C
C The following code was excerpted from: spdec2.f
C
SUBROUTINE SPDEC2(ANGSPC,ANGTOL,NVC,NPOLG,NVERT,NHOLE,NHOLA,MAXVC,
$ MAXHV,MAXPV,MAXIW,MAXWK,HOLV,VCL,REGNUM,HVL,PVL,IANG,IWK,WK)
IMPLICIT LOGICAL (A-Z)
INTEGER MAXHV,MAXIW,MAXPV,MAXVC,MAXWK,NHOLA,NHOLE,NPOLG,NVC,NVERT
INTEGER HOLV(*),HVL(MAXHV),IWK(MAXIW),PVL(4,MAXPV),REGNUM(MAXHV)
DOUBLE PRECISION ANGSPC,ANGTOL,IANG(MAXPV),VCL(2,MAXVC),WK(MAXWK)
C
C Written and copyright by:
C Barry Joe, Dept. of Computing Science, Univ. of Alberta
C Edmonton, Alberta, Canada T6G 2H1
C Phone: (403) 492-5757 Email: barry@cs.ualberta.ca
C
C Purpose: Decompose general polygonal region with interfaces and
C holes into simple polygons using vertex coordinate list,
C head vertex list, and polygon vertex list data structures.
C
C Input parameters:
C ANGSPC - angle spacing parameter in radians used in controlling
C vertices to be considered as an endpoint of a separator
C ANGTOL - angle tolerance parameter in radians used in accepting
C separator(s)
C NVC - number of vertex coordinates or positions used in VCL
C array
C NPOLG - number of polygonal subregions or positions used in
C HVL array
C NVERT - number of polygon vertices or positions used in PVL
C array
C NHOLE - number of holes and hole interfaces
C NHOLA - number of 'attached' holes; these holes are attached
C to the outer boundary of a subregion through vertices
C or cut interfaces and have their edges in consecutive
C order on the boundary
C MAXVC - maximum size available for VCL array, should be >=
C number of vertex coordinates required for decomposition
C MAXHV - maximum size available for HVL, REGNUM arrays, should
C be >= number of polygons required for decomposition
C MAXPV - maximum size available for PVL, IANG arrays; should be
C >= number of polygon vertices required for decomposition
C MAXIW - maximum size available for IWK array; should be about
C 3 times maximum number of vertices in any polygon
C MAXWK - maximum size available for WK array; should be about
C 5 times maximum number of vertices in any polygon
C HOLV(1:NHOLE*2+NHOLA) - indices in PVL of bottom or top vertex
C of holes; first (next) NHOLE entries are for top (bottom)
C vertices of holes and hole interfaces, with top (bottom)
C vertices sorted in decreasing (increasing) lexicographic
C (y,x) order of coord; last NHOLA entries are for attached
C holes; if bottom vertex of attached hole is a simple
C vertex of boundary curve containing the hole then entry
C contains index of bottom vertex otherwise entry contains
C index of top vertex (which is simple)
C VCL(1:2,1:NVC) - vertex coordinate list
C REGNUM(1:NPOLG) - region numbers
C HVL(1:NPOLG) - head vertex list
C PVL(1:4,1:NVERT),IANG(1:NVERT) - polygon vertex list and
C interior angles; see routine DSPGDC for more details
C [Note: The data structures should be as output from routines
C DSMCPR or DSPGDC.]
C
C Updated parameters:
C NVC,NPOLG,NVERT,VCL,REGNUM,HVL,PVL,IANG
C
C Working parameters:
C IWK(1:MAXIW) - integer work array
C WK(1:MAXWK) - double precision work array
C
C Abnormal return:
C IERR is set to 3, 4, 5, 6, 7, 206 to 210, 212, 218, or 219
C
C Routines called:
C INSED2, JNHOLE, RESVRT
C
INTEGER IERR
DOUBLE PRECISION PI,TOL
COMMON /GERROR/ IERR
COMMON /GCONST/ PI,TOL
SAVE /GERROR/,/GCONST/
C
INTEGER EDGV,LOC,POLG,SUCC
PARAMETER (LOC = 1, POLG = 2, SUCC = 3, EDGV = 4)
C
INTEGER I,J,P,VR,W1,W2
DOUBLE PRECISION PIPTOL
LOGICAL CI,CJ
C
C For each simple hole, find cut edge from top vertex of hole to
C a point on the outer boundary above top vertex, and update
C VCL, HVL, PVL, IANG.
C
PIPTOL = PI + TOL
DO 10 I = 1,NHOLE
CALL JNHOLE(HOLV(I),ANGSPC,ANGTOL,NVC,NVERT,MAXVC,MAXPV,MAXIW,
$ MAXWK,VCL,HVL,PVL,IANG,IWK,WK)
IF (IERR .NE. 0) RETURN
10 CONTINUE
C
C Resolve remaining vertices in HOLV array if they are reflex
C vertices. These vertices may no longer be reflex if they are the
C endpoint of a cut edge from the top vertex of another hole or
C of a previous separator.
C
DO 20 I = NHOLE+1,NHOLE+NHOLE+NHOLA
VR = HOLV(I)
IF (IANG(VR) .GT. PIPTOL) THEN
CALL RESVRT(VR,ANGSPC,ANGTOL,NVC,NVERT,MAXVC,MAXPV,MAXIW,
$ MAXWK,VCL,PVL,IANG,W1,W2,IWK,WK)
IF (IERR .NE. 0) RETURN
CALL INSED2(VR,W1,NPOLG,NVERT,MAXHV,MAXPV,VCL,REGNUM,HVL,
$ PVL,IANG)
IF (IERR .NE. 0) RETURN
IF (W2 .GT. 0) CALL INSED2(VR,W2,NPOLG,NVERT,MAXHV,MAXPV,
$ VCL,REGNUM,HVL,PVL,IANG)
IF (IERR .NE. 0) RETURN
ENDIF
20 CONTINUE
IF (NHOLA .EQ. 0) RETURN
C
C Check that polygons are simple. If polygon is simply-connected and
C not simple then find a simple reflex vertex in polygon to resolve.
C
P = 1
30 CONTINUE
IF (P .GT. NPOLG) RETURN
I = HVL(P)
40 CONTINUE
IF (PVL(POLG,PVL(EDGV,I)) .EQ. P) GO TO 50
I = PVL(SUCC,I)
IF (I .NE. HVL(P)) GO TO 40
P = P + 1
GO TO 30
50 CONTINUE
CI = .TRUE.
60 CONTINUE
J = PVL(SUCC,I)
CJ = (PVL(POLG,PVL(EDGV,J)) .EQ. P)
IF (CI .OR. CJ .OR. IANG(J) .LE. PIPTOL) THEN
I = J
CI = CJ
GO TO 60
ENDIF
VR = J
CALL RESVRT(VR,ANGSPC,ANGTOL,NVC,NVERT,MAXVC,MAXPV,MAXIW,
$ MAXWK,VCL,PVL,IANG,W1,W2,IWK,WK)
IF (IERR .NE. 0) RETURN
CALL INSED2(VR,W1,NPOLG,NVERT,MAXHV,MAXPV,VCL,REGNUM,HVL,
$ PVL,IANG)
IF (IERR .NE. 0) RETURN
IF (W2 .GT. 0) CALL INSED2(VR,W2,NPOLG,NVERT,MAXHV,MAXPV,
$ VCL,REGNUM,HVL,PVL,IANG)
IF (IERR .NE. 0) RETURN
GO TO 30
END
|