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 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107 2108 2109 2110 2111 2112 2113 2114 2115 2116 2117 2118 2119 2120 2121 2122 2123 2124 2125 2126 2127 2128 2129 2130 2131 2132 2133 2134 2135 2136 2137 2138 2139 2140 2141 2142 2143 2144 2145 2146 2147 2148 2149 2150 2151 2152 2153 2154 2155 2156 2157 2158 2159 2160 2161 2162 2163 2164 2165 2166 2167 2168 2169 2170 2171 2172 2173 2174 2175 2176 2177 2178 2179 2180 2181 2182 2183 2184 2185 2186 2187 2188 2189 2190 2191 2192 2193 2194 2195 2196 2197 2198 2199 2200 2201 2202 2203 2204 2205 2206 2207 2208 2209 2210 2211 2212 2213 2214 2215 2216 2217 2218 2219 2220 2221 2222 2223 2224 2225 2226 2227 2228 2229 2230 2231 2232 2233 2234 2235 2236 2237 2238 2239 2240 2241 2242 2243 2244 2245 2246 2247 2248 2249 2250 2251 2252 2253 2254 2255 2256 2257 2258 2259 2260 2261 2262 2263 2264 2265 2266 2267 2268 2269 2270 2271 2272 2273 2274 2275 2276 2277 2278 2279 2280 2281 2282 2283 2284 2285 2286 2287 2288 2289 2290 2291 2292 2293 2294 2295 2296 2297 2298 2299 2300 2301 2302 2303 2304 2305 2306 2307 2308 2309 2310 2311 2312 2313 2314 2315 2316 2317 2318 2319 2320 2321 2322 2323 2324 2325 2326 2327 2328 2329 2330 2331 2332 2333 2334 2335 2336 2337 2338 2339 2340 2341 2342 2343 2344 2345 2346 2347 2348 2349 2350 2351 2352 2353 2354 2355 2356 2357 2358 2359 2360 2361 2362 2363 2364 2365 2366 2367 2368 2369 2370 2371 2372 2373 2374 2375 2376 2377 2378 2379 2380 2381 2382 2383 2384 2385 2386 2387 2388 2389 2390 2391 2392 2393 2394 2395 2396 2397 2398 2399 2400 2401 2402 2403 2404 2405 2406 2407 2408 2409 2410 2411 2412 2413 2414 2415 2416 2417 2418 2419 2420 2421 2422 2423 2424 2425 2426 2427 2428 2429 2430 2431 2432 2433 2434 2435 2436 2437 2438 2439 2440 2441 2442 2443 2444 2445 2446 2447 2448 2449 2450 2451 2452 2453 2454 2455 2456 2457 2458 2459 2460 2461 2462 2463 2464 2465 2466 2467 2468 2469 2470 2471 2472 2473 2474 2475 2476 2477 2478 2479 2480 2481 2482 2483 2484 2485 2486 2487 2488 2489 2490 2491 2492 2493 2494 2495 2496 2497 2498 2499 2500 2501 2502 2503 2504 2505 2506 2507 2508 2509 2510 2511 2512 2513 2514 2515 2516 2517 2518 2519 2520 2521 2522 2523 2524 2525 2526 2527 2528 2529 2530 2531 2532 2533 2534 2535 2536 2537 2538 2539 2540 2541 2542 2543 2544 2545 2546 2547 2548 2549 2550 2551 2552 2553 2554 2555 2556 2557 2558 2559 2560 2561 2562 2563 2564 2565 2566 2567 2568 2569 2570 2571 2572 2573 2574 2575 2576 2577 2578 2579 2580 2581 2582 2583 2584 2585 2586 2587 2588 2589 2590 2591 2592 2593 2594 2595 2596 2597 2598 2599 2600 2601 2602 2603 2604 2605 2606 2607 2608 2609 2610 2611 2612 2613 2614 2615 2616 2617 2618 2619 2620 2621 2622 2623 2624 2625 2626 2627 2628 2629 2630 2631 2632 2633 2634 2635 2636 2637 2638 2639 2640 2641 2642 2643 2644 2645 2646 2647 2648 2649 2650 2651 2652 2653 2654 2655 2656 2657 2658 2659 2660 2661 2662 2663 2664 2665 2666 2667 2668 2669 2670 2671 2672 2673 2674 2675 2676 2677 2678 2679 2680 2681 2682 2683 2684 2685 2686 2687 2688 2689 2690 2691 2692 2693 2694 2695 2696 2697 2698 2699 2700 2701 2702 2703 2704 2705 2706 2707 2708 2709 2710 2711 2712 2713 2714 2715 2716 2717 2718 2719 2720 2721 2722 2723 2724 2725 2726 2727 2728 2729 2730 2731 2732 2733 2734 2735 2736 2737 2738 2739 2740 2741 2742 2743 2744 2745 2746 2747 2748 2749 2750 2751 2752 2753 2754 2755 2756 2757 2758 2759 2760 2761 2762 2763 2764 2765 2766 2767 2768 2769 2770 2771 2772 2773 2774 2775 2776 2777 2778 2779 2780 2781 2782 2783 2784 2785 2786 2787 2788 2789 2790 2791 2792 2793 2794 2795 2796 2797 2798 2799 2800 2801 2802 2803 2804 2805 2806 2807 2808 2809 2810 2811 2812 2813 2814 2815 2816 2817 2818 2819 2820 2821 2822 2823 2824 2825 2826 2827 2828 2829 2830 2831 2832 2833 2834 2835 2836 2837 2838 2839 2840 2841 2842 2843 2844 2845 2846 2847 2848 2849 2850 2851 2852 2853 2854 2855 2856 2857 2858 2859 2860 2861 2862 2863 2864 2865 2866 2867 2868 2869 2870 2871 2872 2873 2874 2875 2876 2877 2878 2879 2880 2881 2882 2883 2884 2885 2886 2887 2888 2889 2890 2891 2892 2893 2894 2895 2896 2897 2898 2899 2900 2901 2902 2903 2904 2905 2906 2907 2908 2909 2910 2911 2912 2913 2914 2915 2916 2917 2918 2919 2920 2921 2922 2923 2924 2925 2926 2927 2928 2929 2930 2931 2932 2933 2934 2935 2936 2937 2938 2939 2940 2941 2942 2943 2944 2945 2946 2947 2948 2949 2950 2951 2952 2953 2954 2955 2956 2957 2958 2959 2960 2961 2962 2963 2964 2965 2966 2967 2968 2969 2970 2971 2972 2973 2974 2975
|
// Copyright (c) 1999-2005 INRIA Sophia-Antipolis (France).
// All rights reserved.
//
// This file is part of CGAL (www.cgal.org); you may redistribute it under
// the terms of the Q Public License version 1.0.
// See the file LICENSE.QPL distributed with CGAL.
//
// Licensees holding a valid commercial license may use this file in
// accordance with the commercial license agreement provided with the software.
//
// This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
// WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
//
// $URL: svn+ssh://scm.gforge.inria.fr/svn/cgal/branches/CGAL-3.2-branch/Triangulation_3/include/CGAL/Triangulation_data_structure_3.h $
// $Id: Triangulation_data_structure_3.h 28567 2006-02-16 14:30:13Z lsaboret $
//
//
// Author(s) : Monique Teillaud <Monique.Teillaud@sophia.inria.fr>
// Sylvain Pion <Sylvain.Pion@sophia.inria.fr>
//
// combinatorial triangulation of the boundary of a polytope
// of dimension d in dimension d+1
// for -1 <= d <= 3
//
// ============================================================================
#ifndef CGAL_TRIANGULATION_DATA_STRUCTURE_3_H
#define CGAL_TRIANGULATION_DATA_STRUCTURE_3_H
#include <CGAL/basic.h>
#include <utility>
#include <map>
#include <set>
#include <vector>
#include <CGAL/utility.h>
#if (!defined _MSC_VER || defined __INTEL_COMPILER) && !defined __sgi
# define CGAL_T3_USE_ITERATOR_AS_HANDLE
#endif
#include <CGAL/Triangulation_short_names_3.h>
#include <CGAL/triangulation_assertions.h>
#include <CGAL/Triangulation_utils_3.h>
#include <CGAL/Compact_container.h>
#include <CGAL/Triangulation_ds_cell_base_3.h>
#include <CGAL/Triangulation_ds_vertex_base_3.h>
#include <CGAL/Triangulation_ds_iterators_3.h>
#include <CGAL/Triangulation_ds_circulators_3.h>
CGAL_BEGIN_NAMESPACE
// TODO : noms : Vb != Vertex_base : clarifier.
template < class Vb = Triangulation_ds_vertex_base_3<>,
class Cb = Triangulation_ds_cell_base_3<> >
class Triangulation_data_structure_3
: public Triangulation_utils_3
{
typedef Triangulation_data_structure_3<Vb,Cb> Tds;
public:
typedef typename Vb::template Rebind_TDS<Tds>::Other Vertex;
typedef typename Cb::template Rebind_TDS<Tds>::Other Cell;
private:
typedef Compact_container<Cell> Cell_container;
typedef Compact_container<Vertex> Vertex_container;
friend class Triangulation_ds_facet_iterator_3<Tds>;
friend class Triangulation_ds_edge_iterator_3<Tds>;
friend class Triangulation_ds_cell_circulator_3<Tds>;
friend class Triangulation_ds_facet_circulator_3<Tds>;
public:
typedef typename Cell_container::size_type size_type;
typedef typename Cell_container::difference_type difference_type;
typedef typename Cell_container::iterator Cell_iterator;
typedef typename Vertex_container::iterator Vertex_iterator;
typedef Triangulation_ds_facet_iterator_3<Tds> Facet_iterator;
typedef Triangulation_ds_edge_iterator_3<Tds> Edge_iterator;
typedef Triangulation_ds_cell_circulator_3<Tds> Cell_circulator;
typedef Triangulation_ds_facet_circulator_3<Tds> Facet_circulator;
//private: // In 2D only :
typedef Triangulation_ds_face_circulator_3<Tds> Face_circulator;
#ifdef CGAL_T3_USE_ITERATOR_AS_HANDLE
typedef Vertex_iterator Vertex_handle;
typedef Cell_iterator Cell_handle;
#else
// Defining nested classes for the handles instead of typedefs
// considerably shortens the symbol names (and compile times).
// It makes error messages more readable as well.
class Vertex_handle {
Vertex_iterator _v;
public:
typedef Vertex value_type;
typedef value_type * pointer;
typedef value_type & reference;
typedef std::size_t size_type;
typedef std::ptrdiff_t difference_type;
typedef void iterator_category;
Vertex_handle() : _v() {}
Vertex_handle(Vertex_iterator v) : _v(v) {}
#ifndef CGAL_NO_DEPRECATED_CODE // must be kept
Vertex_handle(void * CGAL_triangulation_precondition_code(n)) : _v()
{ CGAL_triangulation_precondition(n == NULL); }
#endif
Vertex* operator->() const { return &*_v; }
Vertex& operator*() const { return *_v; }
bool operator==(Vertex_handle v) const { return _v == v._v; }
bool operator!=(Vertex_handle v) const { return _v != v._v; }
#ifndef CGAL_NO_DEPRECATED_CODE // must be kept
// For std::set and co.
bool operator<(Vertex_handle v) const { return &*_v < &*v._v; }
#endif
// Should be private to the TDS :
const Vertex_iterator & base() const { return _v; }
Vertex_iterator & base() { return _v; }
void * for_compact_container() const { return _v.for_compact_container(); }
void * & for_compact_container() { return _v.for_compact_container(); }
};
class Cell_handle {
Cell_iterator _c;
public:
typedef Cell value_type;
typedef value_type * pointer;
typedef value_type & reference;
typedef std::size_t size_type;
typedef std::ptrdiff_t difference_type;
typedef void iterator_category;
Cell_handle() : _c() {}
Cell_handle(Cell_iterator c) : _c(c) {}
Cell_handle(const Cell_circulator &c) : _c(c.base()._c) {}
Cell_handle(const Face_circulator &c) : _c(c.base()._c) {}
#ifndef CGAL_NO_DEPRECATED_CODE // must be kept
Cell_handle(void * CGAL_triangulation_precondition_code(n)) : _c()
{ CGAL_triangulation_precondition(n == NULL); }
#endif
Cell* operator->() const { return &*_c; }
Cell& operator*() const { return *_c; }
bool operator==(Cell_handle c) const { return _c == c._c; }
bool operator!=(Cell_handle c) const { return _c != c._c; }
#ifndef CGAL_NO_DEPRECATED_CODE // must be kept
// For std::set and co.
bool operator<(Cell_handle c) const { return &*_c < &*c._c; }
#endif
// These should be private to the TDS :
const Cell_iterator & base() const { return _c; }
Cell_iterator & base() { return _c; }
void * for_compact_container() const { return _c.for_compact_container(); }
void * & for_compact_container() { return _c.for_compact_container(); }
};
#endif
typedef std::pair<Cell_handle, int> Facet;
typedef Triple<Cell_handle, int, int> Edge;
public:
Triangulation_data_structure_3()
: _dimension(-2)
{}
Triangulation_data_structure_3(const Tds & tds)
{
copy_tds(tds);
}
Tds & operator= (const Tds & tds)
{
if (&tds != this) {
Tds tmp(tds);
swap(tmp);
}
return *this;
}
size_type number_of_vertices() const { return vertex_container().size(); }
int dimension() const {return _dimension;}
size_type number_of_cells() const
{
if ( dimension() < 3 ) return 0;
return cell_container().size();
}
size_type number_of_facets() const
{
if ( dimension() < 2 ) return 0;
return std::distance(facets_begin(), facets_end());
}
size_type number_of_edges() const
{
if ( dimension() < 1 ) return 0;
return std::distance(edges_begin(), edges_end());
}
// USEFUL CONSTANT TIME FUNCTIONS
// SETTING
void set_dimension(int n) { _dimension = n; }
Vertex_handle create_vertex(const Vertex &v)
{
return vertex_container().insert(v);
}
Vertex_handle create_vertex()
{
return vertex_container().construct_insert();
}
Vertex_handle create_vertex(const Vertex_handle& v)
{
return create_vertex(*v);
}
Cell_handle create_cell(const Cell &c)
{
return cell_container().insert(c);
}
Cell_handle create_cell()
{
return cell_container().construct_insert();
}
Cell_handle create_cell(const Cell_handle& c)
{
return create_cell(*c);
}
Cell_handle create_cell(const Vertex_handle& v0, const Vertex_handle& v1,
const Vertex_handle& v2, const Vertex_handle& v3)
{
return cell_container().construct_insert(v0, v1, v2, v3);
}
Cell_handle create_cell(const Vertex_handle& v0, const Vertex_handle& v1,
const Vertex_handle& v2, const Vertex_handle& v3,
const Cell_handle& n0, const Cell_handle& n1,
const Cell_handle& n2, const Cell_handle& n3)
{
return cell_container().construct_insert(v0, v1, v2, v3, n0, n1, n2, n3);
}
Cell_handle create_face()
{
CGAL_triangulation_precondition(dimension()<3);
return create_cell();
}
Cell_handle create_face(const Vertex_handle& v0, const Vertex_handle& v1,
const Vertex_handle& v2)
{
CGAL_triangulation_precondition(dimension()<3);
return cell_container().construct_insert(v0, v1, v2, Vertex_handle());
}
// The following functions come from TDS_2.
Cell_handle create_face(const Cell_handle& f0, int i0,
const Cell_handle& f1, int i1,
const Cell_handle& f2, int i2)
{
CGAL_triangulation_precondition(dimension() <= 2);
Cell_handle newf = create_face(f0->vertex(cw(i0)),
f1->vertex(cw(i1)),
f2->vertex(cw(i2)));
set_adjacency(newf, 2, f0, i0);
set_adjacency(newf, 0, f1, i1);
set_adjacency(newf, 1, f2, i2);
return newf;
}
Cell_handle create_face(const Cell_handle& f0, int i0,
const Cell_handle& f1, int i1)
{
CGAL_triangulation_precondition(dimension() <= 2);
Cell_handle newf = create_face(f0->vertex(cw(i0)),
f1->vertex(cw(i1)),
f1->vertex(ccw(i1)));
set_adjacency(newf, 2, f0, i0);
set_adjacency(newf, 0, f1, i1);
return newf;
}
Cell_handle create_face(const Cell_handle& f, int i, const Vertex_handle& v)
{
CGAL_triangulation_precondition(dimension() <= 2);
Cell_handle newf = create_face(f->vertex(cw(i)),
f->vertex(ccw(i)),
v);
set_adjacency(newf, 2, f, i);
return newf;
}
// not documented
void read_cells(std::istream& is, std::map< int, Vertex_handle > &V,
int & m, std::map< int, Cell_handle > &C );
// not documented
void print_cells(std::ostream& os,
const std::map<Vertex_handle, int> &V ) const;
// ACCESS FUNCTIONS
void delete_vertex( const Vertex_handle& v )
{
CGAL_triangulation_expensive_precondition( is_vertex(v) );
#ifdef CGAL_T3_USE_ITERATOR_AS_HANDLE
vertex_container().erase(v);
#else
vertex_container().erase(v.base());
#endif
}
void delete_cell( const Cell_handle& c )
{
CGAL_triangulation_expensive_precondition( dimension() != 3 ||
is_cell(c) );
CGAL_triangulation_expensive_precondition( dimension() != 2 ||
is_facet(c,3) );
CGAL_triangulation_expensive_precondition( dimension() != 1 ||
is_edge(c,0,1) );
CGAL_triangulation_expensive_precondition( dimension() != 0 ||
is_vertex(c->vertex(0)) );
#ifdef CGAL_T3_USE_ITERATOR_AS_HANDLE
cell_container().erase(c);
#else
cell_container().erase(c.base());
#endif
}
template <class InputIterator>
void delete_vertices(InputIterator begin, InputIterator end)
{
for(; begin != end; ++begin)
delete_vertex(*begin);
}
template <class InputIterator>
void delete_cells(InputIterator begin, InputIterator end)
{
for(; begin != end; ++begin)
delete_cell(*begin);
}
// QUERIES
bool is_vertex(const Vertex_handle& v) const;
bool is_edge(const Cell_handle& c, int i, int j) const;
bool is_edge(const Vertex_handle& u, const Vertex_handle& v, Cell_handle & c,
int & i, int & j) const;
bool is_edge(const Vertex_handle& u, const Vertex_handle& v) const;
bool is_facet(const Cell_handle& c, int i) const;
bool is_facet(const Vertex_handle& u, const Vertex_handle& v,
const Vertex_handle& w,
Cell_handle & c, int & i, int & j, int & k) const;
bool is_cell(const Cell_handle& c) const;
bool is_cell(const Vertex_handle& u, const Vertex_handle& v,
const Vertex_handle& w, const Vertex_handle& t,
Cell_handle & c, int & i, int & j, int & k, int & l) const;
bool is_cell(const Vertex_handle& u, const Vertex_handle& v,
const Vertex_handle& w, const Vertex_handle& t) const;
bool has_vertex(const Facet & f, const Vertex_handle& v, int & j) const;
bool has_vertex(const Cell_handle& c, int i,
const Vertex_handle& v, int & j) const;
bool has_vertex(const Facet & f, const Vertex_handle& v) const;
bool has_vertex(const Cell_handle& c, int i, const Vertex_handle& v) const;
bool are_equal(const Cell_handle& c, int i,
const Cell_handle& n, int j) const;
bool are_equal(const Facet & f, const Facet & g) const;
bool are_equal(const Facet & f, const Cell_handle& n, int j) const;
// MODIFY
bool flip(const Cell_handle& c, int i);
bool flip(const Facet &f)
{ return flip( f.first, f.second); }
void flip_flippable(const Cell_handle& c, int i);
void flip_flippable(const Facet &f)
{ flip_flippable( f.first, f.second ); }
bool flip(const Cell_handle& c, int i, int j);
bool flip(const Edge &e)
{ return flip( e.first, e.second, e.third ); }
void flip_flippable(const Cell_handle& c, int i, int j);
void flip_flippable(const Edge &e)
{ flip_flippable( e.first, e.second, e.third ); }
private:
// common to flip and flip_flippable
void flip_really(const Cell_handle& c, int i, const Cell_handle& n, int in);
void flip_really(const Cell_handle& c, int i, int j,
const Cell_handle& c1, const Vertex_handle& v1,
int i1, int j1, int next1,
const Cell_handle& c2, const Vertex_handle& v2,
int i2, int j2, int next2,
const Vertex_handle& v3);
Cell_handle create_star_3(const Vertex_handle& v, const Cell_handle& c,
int li, int prev_ind2 = -1);
Cell_handle create_star_2(const Vertex_handle& v,
const Cell_handle& c, int li);
public:
// Internal function : assumes the conflict cells are marked.
template <class CellIt>
Vertex_handle _insert_in_hole(CellIt cell_begin, CellIt cell_end,
const Cell_handle& begin, int i)
{
CGAL_triangulation_precondition(begin != Cell_handle());
// if begin == NULL (default arg), we could compute one by walking in
// CellIt. At the moment, the functionality is not available, you have
// to specify a starting facet.
Vertex_handle newv = create_vertex();
Cell_handle cnew;
if (dimension() == 3)
cnew = create_star_3(newv, begin, i);
else
cnew = create_star_2(newv, begin, i);
newv->set_cell(cnew);
delete_cells(cell_begin, cell_end);
return newv;
}
// Mark the cells in conflict, then calls the internal function.
template <class CellIt>
Vertex_handle insert_in_hole(CellIt cell_begin, CellIt cell_end,
const Cell_handle& begin, int i)
{
for (CellIt cit = cell_begin; cit != cell_end; ++cit)
(*cit)->set_in_conflict_flag(1);
return _insert_in_hole(cell_begin, cell_end, begin, i);
}
//INSERTION
Vertex_handle insert_in_cell(const Cell_handle& c);
Vertex_handle insert_in_facet(const Facet & f)
{ return insert_in_facet(f.first, f.second); }
Vertex_handle insert_in_facet(const Cell_handle& c, int i);
Vertex_handle insert_in_edge(const Edge & e)
{ return insert_in_edge(e.first, e.second, e.third); }
Vertex_handle insert_in_edge(const Cell_handle& c, int i, int j);
Vertex_handle insert_increase_dimension(Vertex_handle star =Vertex_handle());
// REMOVAL
private:
Cell_handle remove_degree_4(const Vertex_handle& v);
Cell_handle remove_degree_3(const Vertex_handle& v);
Cell_handle remove_degree_2(const Vertex_handle& v);
public:
Cell_handle remove_from_maximal_dimension_simplex(const Vertex_handle& v);
void remove_decrease_dimension(const Vertex_handle& v)
{
remove_decrease_dimension (v, v);
}
void remove_decrease_dimension(const Vertex_handle& v, const Vertex_handle &w);
// Change orientation of the whole TDS.
void reorient()
{
CGAL_triangulation_precondition(dimension() >= 1);
for (Cell_iterator i = cell_container().begin();
i != cell_container().end(); ++i)
change_orientation(i);
}
// ITERATOR METHODS
Cell_iterator cells_begin() const
{
if ( dimension() < 3 )
return cells_end();
return cell_container().begin();
}
Cell_iterator cells_end() const
{
return cell_container().end();
}
Cell_iterator raw_cells_begin() const
{
return cell_container().begin();
}
Cell_iterator raw_cells_end() const
{
return cell_container().end();
}
Facet_iterator facets_begin() const
{
if ( dimension() < 2 )
return facets_end();
return Facet_iterator(this);
}
Facet_iterator facets_end() const
{
return Facet_iterator(this, 1);
}
Edge_iterator edges_begin() const
{
if ( dimension() < 1 )
return edges_end();
return Edge_iterator(this);
}
Edge_iterator edges_end() const
{
return Edge_iterator(this,1);
}
Vertex_iterator vertices_begin() const
{
return vertex_container().begin();
}
Vertex_iterator vertices_end() const
{
return vertex_container().end();
}
// CIRCULATOR METHODS
// cells around an edge
Cell_circulator incident_cells(const Edge & e) const
{
CGAL_triangulation_precondition( dimension() == 3 );
return Cell_circulator(e);
}
Cell_circulator incident_cells(const Cell_handle& ce, int i, int j) const
{
CGAL_triangulation_precondition( dimension() == 3 );
return Cell_circulator(ce, i, j);
}
Cell_circulator incident_cells(const Edge &e, const Cell_handle& start) const
{
CGAL_triangulation_precondition( dimension() == 3 );
return Cell_circulator(e, start);
}
Cell_circulator incident_cells(const Cell_handle& ce, int i, int j,
const Cell_handle& start) const
{
CGAL_triangulation_precondition( dimension() == 3 );
return Cell_circulator(ce, i, j, start);
}
//facets around an edge
Facet_circulator incident_facets(const Edge & e) const
{
CGAL_triangulation_precondition( dimension() == 3 );
return Facet_circulator(e);
}
Facet_circulator incident_facets(const Cell_handle& ce, int i, int j) const
{
CGAL_triangulation_precondition( dimension() == 3 );
return Facet_circulator(ce, i, j);
}
Facet_circulator incident_facets(const Edge & e, const Facet & start) const
{
CGAL_triangulation_precondition( dimension() == 3 );
return Facet_circulator(e, start);
}
Facet_circulator incident_facets(const Cell_handle& ce, int i, int j,
const Facet & start) const
{
CGAL_triangulation_precondition( dimension() == 3 );
return Facet_circulator(ce, i, j, start);
}
Facet_circulator incident_facets(const Edge & e,
const Cell_handle& start, int f) const
{
CGAL_triangulation_precondition( dimension() == 3 );
return Facet_circulator(e, start, f);
}
Facet_circulator incident_facets(const Cell_handle& ce, int i, int j,
const Cell_handle& start, int f) const
{
CGAL_triangulation_precondition( dimension() == 3 );
return Facet_circulator(ce, i, j, start, f);
}
// 2D : circulates on the faces adjacent to a vertex.
Face_circulator incident_faces(const Vertex_handle& v) const
{
CGAL_triangulation_precondition( dimension() == 2 );
return Face_circulator(v, v->cell());
}
// around a vertex
private:
template <class IncidentCellIterator, class IncidentFacetIterator>
std::pair<IncidentCellIterator, IncidentFacetIterator>
incident_cells_3(const Vertex_handle& v, const Cell_handle& c,
std::pair<IncidentCellIterator,
IncidentFacetIterator> it) const
{
CGAL_triangulation_precondition(dimension() == 3);
// Flag values :
// 1 : incident cell already visited
// 0 : unknown
c->set_in_conflict_flag(1);
*it.first++ = c;
for (int i=0; i<4; ++i) {
if (c->vertex(i) == v)
continue;
Cell_handle next = c->neighbor(i);
if (c < next)
*it.second++ = Facet(c, i); // Incident facet.
if (next->get_in_conflict_flag() != 0)
continue;
it = incident_cells_3(v, next, it);
}
return it;
}
template <class OutputIterator>
void
incident_cells_2(const Vertex_handle& v, const Cell_handle& c,
OutputIterator cells) const
{
CGAL_triangulation_precondition(dimension() == 2);
// TODO : in 2D, there's no real need for conflict_flag, we could use
// a smarter algorithm. We could use the 2D Face_circulator.
// Should we just have this Face_circulator ?
// Flag values :
// 1 : incident cell already visited
// 0 : unknown
c->set_in_conflict_flag(1);
*cells++ = c;
for (int i=0; i<3; ++i) {
if (c->vertex(i) == v)
continue;
Cell_handle next = c->neighbor(i);
if (next->get_in_conflict_flag() != 0)
continue;
incident_cells_2(v, next, cells);
}
}
public:
template <class OutputIterator>
OutputIterator
incident_cells(const Vertex_handle& v, OutputIterator cells) const
{
CGAL_triangulation_precondition( v != Vertex_handle() );
CGAL_triangulation_expensive_precondition( is_vertex(v) );
if ( dimension() < 2 )
return cells;
std::vector<Cell_handle> tmp_cells;
tmp_cells.reserve(64);
if ( dimension() == 3 )
incident_cells_3(v, v->cell(),
std::make_pair(std::back_inserter(tmp_cells),
Emptyset_iterator()));
else
incident_cells_2(v, v->cell(), std::back_inserter(tmp_cells));
for(typename std::vector<Cell_handle>::iterator cit = tmp_cells.begin();
cit != tmp_cells.end(); ++cit) {
(*cit)->set_in_conflict_flag(0);
*cells++ = *cit;
}
return cells;
}
template <class OutputIterator>
OutputIterator
incident_facets(const Vertex_handle& v, OutputIterator facets) const
{
CGAL_triangulation_precondition( dimension() == 3 );
CGAL_triangulation_precondition( v != Vertex_handle() );
CGAL_triangulation_expensive_precondition( is_vertex(v) );
std::vector<Cell_handle> tmp_cells;
tmp_cells.reserve(64);
std::pair<std::back_insert_iterator<std::vector<Cell_handle> >,
OutputIterator> it (std::back_inserter(tmp_cells), facets);
it = incident_cells_3(v, v->cell(), it);
for(typename std::vector<Cell_handle>::iterator cit = tmp_cells.begin();
cit != tmp_cells.end(); ++cit) {
(*cit)->set_in_conflict_flag(0);
}
return it.second;
}
template <class OutputIterator>
OutputIterator
incident_vertices(const Vertex_handle& v, OutputIterator vertices) const
{
CGAL_triangulation_precondition( v != Vertex_handle() );
CGAL_triangulation_precondition( dimension() >= -1 );
CGAL_triangulation_expensive_precondition( is_vertex(v) );
CGAL_triangulation_expensive_precondition( is_valid() );
if (dimension() == -1)
return vertices;
if (dimension() == 0) {
*vertices++ = v->cell()->neighbor(0)->vertex(0);
return vertices;
}
if (dimension() == 1) {
CGAL_triangulation_assertion( number_of_vertices() >= 3);
Cell_handle n0 = v->cell();
Cell_handle n1 = n0->neighbor(1-n0->index(v));
*vertices++ = n0->vertex(1-n0->index(v));
*vertices++ = n1->vertex(1-n1->index(v));
return vertices;
}
// Get the incident cells.
std::vector<Cell_handle> tmp_cells;
tmp_cells.reserve(64);
incident_cells(v, std::back_inserter(tmp_cells));
std::set<Vertex_handle> tmp_vertices;
for(typename std::vector<Cell_handle>::iterator cit = tmp_cells.begin();
cit != tmp_cells.end(); ++cit) {
// Put all incident vertices in tmp_vertices.
for (int j=0; j<=dimension(); ++j)
if ((*cit)->vertex(j) != v)
tmp_vertices.insert((*cit)->vertex(j));
}
// Now output the vertices.
return std::copy(tmp_vertices.begin(), tmp_vertices.end(), vertices);
}
size_type degree(const Vertex_handle& v) const;
// CHECKING
bool is_valid(bool verbose = false, int level = 0) const;
bool is_valid(Vertex_handle v, bool verbose = false, int level = 0) const;
bool is_valid(Cell_handle c, bool verbose = false, int level = 0) const;
// Helping functions
Vertex_handle copy_tds(const Tds & tds,
Vertex_handle vert = Vertex_handle() );
// returns the new vertex corresponding to vert in the new tds
void swap(Tds & tds);
void clear();
void set_adjacency(const Cell_handle& c0, int i0,
const Cell_handle& c1, int i1) const
{
CGAL_triangulation_assertion(i0 >= 0 && i0 <= dimension());
CGAL_triangulation_assertion(i1 >= 0 && i1 <= dimension());
CGAL_triangulation_assertion(c0 != c1);
c0->set_neighbor(i0,c1);
c1->set_neighbor(i1,c0);
}
int mirror_index(Cell_handle c, int i) const
{
CGAL_triangulation_precondition ( i>=0 && i<4 );
return c->neighbor(i)->index(c);
}
Vertex_handle mirror_vertex(Cell_handle c, int i) const
{
return c->neighbor(i)->vertex(mirror_index(c, i));
}
Facet mirror_facet(Facet f) const
{
const Cell_handle& neighbor_cell = f.first->neighbor(f.second);
const int opposite_index = neighbor_cell->index(f.first);
return Facet(neighbor_cell, opposite_index);
}
private:
// Change the orientation of the cell by swapping indices 0 and 1.
void change_orientation(const Cell_handle& c) const
{
Vertex_handle tmp_v = c->vertex(0);
c->set_vertex(0, c->vertex(1));
c->set_vertex(1, tmp_v);
Cell_handle tmp_c = c->neighbor(0);
c->set_neighbor(0, c->neighbor(1));
c->set_neighbor(1, tmp_c);
}
// We need the const_cast<>s because TDS is not const-correct.
Cell_container & cell_container() { return _cell_container; }
Cell_container & cell_container() const
{ return const_cast<Tds*>(this)->_cell_container; }
Vertex_container & vertex_container() {return _vertex_container;}
Vertex_container & vertex_container() const
{ return const_cast<Tds*>(this)->_vertex_container; }
// in dimension i, number of vertices >= i+2
// ( the boundary of a simplex in dimension i+1 has i+2 vertices )
int _dimension;
Cell_container _cell_container;
Vertex_container _vertex_container;
// used by is-valid :
bool count_vertices(size_type &i, bool verbose = false, int level = 0) const;
// counts AND checks the validity
bool count_facets(size_type &i, bool verbose = false, int level = 0) const;
// counts but does not check
bool count_edges(size_type &i, bool verbose = false, int level = 0) const;
// counts but does not check
bool count_cells(size_type &i, bool verbose = false, int level = 0) const;
// counts AND checks the validity
};
template <class Vb, class Cb >
typename Triangulation_data_structure_3<Vb,Cb>::Cell_handle
Triangulation_data_structure_3<Vb,Cb>::
create_star_3(const Vertex_handle& v, const Cell_handle& c, int li,
int prev_ind2)
{
CGAL_triangulation_precondition( dimension() == 3);
CGAL_triangulation_precondition( c->get_in_conflict_flag() == 1);
CGAL_triangulation_precondition( c->neighbor(li)->get_in_conflict_flag()
!= 1);
Cell_handle cnew = create_cell(c->vertex(0),
c->vertex(1),
c->vertex(2),
c->vertex(3));
cnew->set_vertex(li, v);
const Cell_handle& c_li = c->neighbor(li);
set_adjacency(cnew, li, c_li, c_li->index(c));
// Look for the other neighbors of cnew.
for (int ii=0; ii<4; ++ii) {
if (ii == prev_ind2 || cnew->neighbor(ii) != Cell_handle())
continue;
cnew->vertex(ii)->set_cell(cnew);
// Indices of the vertices of cnew such that ii,vj1,vj2,li positive.
const Vertex_handle& vj1 = c->vertex(next_around_edge(ii, li));
const Vertex_handle& vj2 = c->vertex(next_around_edge(li, ii));
Cell_handle cur = c;
int zz = ii;
Cell_handle n = cur->neighbor(zz);
// turn around the oriented edge vj1 vj2
while ( n->get_in_conflict_flag() == 1) {
CGAL_triangulation_assertion( n != c );
cur = n;
zz = next_around_edge(n->index(vj1), n->index(vj2));
n = cur->neighbor(zz);
}
// Now n is outside region, cur is inside.
n->set_in_conflict_flag(0); // Reset the flag for boundary cells.
int jj1 = n->index(vj1);
int jj2 = n->index(vj2);
const Vertex_handle& vvv = n->vertex(next_around_edge(jj1, jj2));
Cell_handle nnn = n->neighbor(next_around_edge(jj2, jj1));
int zzz = nnn->index(vvv);
if (nnn == cur) {
// Neighbor relation is reciprocal, ie
// the cell we are looking for is not yet created.
nnn = create_star_3(v, nnn, zz, zzz);
}
set_adjacency(nnn, zzz, cnew, ii);
}
return cnew;
}
template <class Vb, class Cb >
typename Triangulation_data_structure_3<Vb,Cb>::Cell_handle
Triangulation_data_structure_3<Vb,Cb>::
create_star_2(const Vertex_handle& v, const Cell_handle& c, int li )
{
CGAL_triangulation_assertion( dimension() == 2 );
Cell_handle cnew;
// i1 i2 such that v,i1,i2 positive
int i1=ccw(li);
// traversal of the boundary of region in ccw order to create all
// the new facets
Cell_handle bound = c;
Vertex_handle v1 = c->vertex(i1);
int ind = c->neighbor(li)->index(c); // to be able to find the
// first cell that will be created
Cell_handle cur;
Cell_handle pnew = Cell_handle();
do {
cur = bound;
// turn around v2 until we reach the boundary of region
while ( cur->neighbor(cw(i1))->get_in_conflict_flag() == 1 ) {
// neighbor in conflict
cur = cur->neighbor(cw(i1));
i1 = cur->index( v1 );
}
cur->neighbor(cw(i1))->set_in_conflict_flag(0);
// here cur has an edge on the boundary of region
cnew = create_face( v, v1, cur->vertex( ccw(i1) ) );
set_adjacency(cnew, 0, cur->neighbor(cw(i1)),
cur->neighbor(cw(i1))->index(cur));
cnew->set_neighbor(1, Cell_handle());
cnew->set_neighbor(2, pnew);
// pnew is null at the first iteration
v1->set_cell(cnew);
//pnew->set_neighbor( cw(pnew->index(v1)), cnew );
if (pnew != Cell_handle()) { pnew->set_neighbor( 1, cnew );}
bound = cur;
i1 = ccw(i1);
v1 = bound->vertex(i1);
pnew = cnew;
//} while ( ( bound != c ) || ( li != cw(i1) ) );
} while ( v1 != c->vertex(ccw(li)) );
// missing neighbors between the first and the last created cells
cur = c->neighbor(li)->neighbor(ind); // first created cell
set_adjacency(cnew, 1, cur, 2);
return cnew;
}
template < class Vb, class Cb>
std::istream&
operator>>(std::istream& is, Triangulation_data_structure_3<Vb,Cb>& tds)
// reads :
// the dimension
// the number of vertices
// the number of cells
// the cells by the indices of their vertices
// the neighbors of each cell by their index in the preceding list of cells
// when dimension < 3 : the same with faces of maximal dimension
{
typedef Triangulation_data_structure_3<Vb,Cb> Tds;
typedef typename Tds::Vertex_handle Vertex_handle;
typedef typename Tds::Cell_handle Cell_handle;
tds.clear();
int n, d;
is >> d >> n;
tds.set_dimension(d);
if(n == 0)
return is;
std::map< int, Vertex_handle > V;
// creation of the vertices
for (int i=0; i < n; i++) {
// is >> p;
// V[i] = tds.create_vertex();
// V[i]->set_point(p);
V[i] = tds.create_vertex();
}
std::map< int, Cell_handle > C;
int m;
tds.read_cells(is, V, m, C);
CGAL_triangulation_assertion( tds.is_valid() );
return is;
}
template < class Vb, class Cb>
std::ostream&
operator<<(std::ostream& os, const Triangulation_data_structure_3<Vb,Cb> &tds)
// writes :
// the dimension
// the number of vertices
// the number of cells
// the cells by the indices of their vertices
// the neighbors of each cell by their index in the preceding list of cells
// when dimension < 3 : the same with faces of maximal dimension
{
typedef Triangulation_data_structure_3<Vb,Cb> Tds;
typedef typename Tds::Vertex_handle Vertex_handle;
typedef typename Tds::Vertex_iterator Vertex_iterator;
std::map<Vertex_handle, int> V;
// outputs dimension and number of vertices
int n = tds.number_of_vertices();
if (is_ascii(os))
os << tds.dimension() << std::endl << n << std::endl;
else
os << tds.dimension() << n;
if (n == 0)
return os;
// index the vertices
int i = 0;
for (Vertex_iterator it=tds.vertices_begin(); it != tds.vertices_end(); ++it)
V[it] = i++;
CGAL_triangulation_assertion( i == n );
tds.print_cells(os, V);
return os;
}
template < class Vb, class Cb>
bool
Triangulation_data_structure_3<Vb,Cb>::
is_vertex(const Vertex_handle& v) const
{
Vertex_iterator vit = vertices_begin();
while (vit != vertices_end() && v != vit)
++vit;
return v == vit;
}
template < class Vb, class Cb>
bool
Triangulation_data_structure_3<Vb,Cb>::
is_edge(const Vertex_handle& u, const Vertex_handle& v,
Cell_handle &c, int &i, int &j) const
// returns false when dimension <1 or when indices wrong
{
CGAL_triangulation_expensive_precondition( is_vertex(u) && is_vertex(v) );
if (u==v)
return false;
std::vector<Cell_handle> cells;
cells.reserve(64);
incident_cells(u, std::back_inserter(cells));
for (typename std::vector<Cell_handle>::iterator cit = cells.begin();
cit != cells.end(); ++cit)
if ((*cit)->has_vertex(v, j)) {
c = *cit;
i = c->index(u);
return true;
}
return false;
}
template < class Vb, class Cb>
bool
Triangulation_data_structure_3<Vb,Cb>::
is_edge(const Vertex_handle& u, const Vertex_handle& v) const
{
Cell_handle c;
int i, j;
return is_edge(u, v, c, i, j);
}
template < class Vb, class Cb>
bool
Triangulation_data_structure_3<Vb,Cb>::
is_edge(const Cell_handle& c, int i, int j) const
// returns false when dimension <1
{
if ( i==j ) return false;
if ( (i<0) || (j<0) ) return false;
if ( (dimension() == 1) && ((i>1) || (j>1)) ) return false;
if ( (dimension() == 2) && ((i>2) || (j>2)) ) return false;
if ((i>3) || (j>3)) return false;
for(Cell_iterator cit = cell_container().begin(); cit != cells_end(); ++cit)
if (c == cit)
return true;
return false;
}
template < class Vb, class Cb>
bool
Triangulation_data_structure_3<Vb,Cb>::
is_facet(const Vertex_handle& u, const Vertex_handle& v,
const Vertex_handle& w,
Cell_handle & c, int & i, int & j, int & k) const
// returns false when dimension <2 or when indices wrong
{
CGAL_triangulation_expensive_precondition( is_vertex(u) &&
is_vertex(v) &&
is_vertex(w) );
if ( u==v || u==w || v==w )
return false;
if (dimension() < 2)
return false;
std::vector<Cell_handle> cells;
cells.reserve(64);
incident_cells(u, std::back_inserter(cells));
for (typename std::vector<Cell_handle>::iterator cit = cells.begin();
cit != cells.end(); ++cit)
if ((*cit)->has_vertex(v, j) && (*cit)->has_vertex(w, k)) {
c = *cit;
i = c->index(u);
return true;
}
return false;
}
template < class Vb, class Cb>
bool
Triangulation_data_structure_3<Vb,Cb>::
is_facet(const Cell_handle& c, int i) const
// returns false when dimension <2
{
CGAL_triangulation_precondition(i>=0 && i<4);
if ( (dimension() == 2) && (i!=3) )
return false;
Cell_iterator cit = cell_container().begin(); // needs to work in dim 2.
while (cit != cells_end() && c != cit)
++cit;
return c == cit;
}
template < class Vb, class Cb>
bool
Triangulation_data_structure_3<Vb,Cb>::
is_cell( const Cell_handle& c ) const
// returns false when dimension <3
{
if (dimension() < 3)
return false;
Cell_iterator cit = cells_begin();
while (cit != cells_end() && c != cit)
++cit;
return c == cit;
}
template < class Vb, class Cb>
bool
Triangulation_data_structure_3<Vb,Cb>::
is_cell(const Vertex_handle& u, const Vertex_handle& v,
const Vertex_handle& w, const Vertex_handle& t,
Cell_handle & c, int & i, int & j, int & k, int & l) const
// returns false when dimension <3
{
CGAL_triangulation_expensive_precondition( is_vertex(u) &&
is_vertex(v) &&
is_vertex(w) &&
is_vertex(t) );
if ( u==v || u==w || u==t || v==w || v==t || w==t )
return false;
std::vector<Cell_handle> cells;
cells.reserve(64);
incident_cells(u, std::back_inserter(cells));
for (typename std::vector<Cell_handle>::iterator cit = cells.begin();
cit != cells.end(); ++cit)
if ((*cit)->has_vertex(v, j) && (*cit)->has_vertex(w, k) &&
(*cit)->has_vertex(t, l)) {
c = *cit;
i = c->index(u);
return true;
}
return false;
}
template < class Vb, class Cb>
bool
Triangulation_data_structure_3<Vb,Cb>::
is_cell(const Vertex_handle& u, const Vertex_handle& v,
const Vertex_handle& w, const Vertex_handle& t)
const
// returns false when dimension <3
{
Cell_handle c;
int i, j, k, l;
return is_cell(u, v, w, t, c, i, j, k, l);
}
template < class Vb, class Cb>
inline
bool
Triangulation_data_structure_3<Vb,Cb>::
has_vertex(const Cell_handle& c, int i, const Vertex_handle& v, int & j) const
// computes the index j of the vertex in the cell c giving the query
// facet (c,i)
// j has no meaning if false is returned
{
CGAL_triangulation_precondition( dimension() == 3 );
return ( c->has_vertex(v,j) && (j != i) );
}
template < class Vb, class Cb>
inline
bool
Triangulation_data_structure_3<Vb,Cb>::
has_vertex(const Cell_handle& c, int i, const Vertex_handle& v) const
// checks whether the query facet (c,i) has vertex v
{
CGAL_triangulation_precondition( dimension() == 3 );
int j;
return ( c->has_vertex(v,j) && (j != i) );
}
template < class Vb, class Cb>
inline
bool
Triangulation_data_structure_3<Vb,Cb>::
has_vertex(const Facet & f, const Vertex_handle& v, int & j) const
{
return has_vertex(f.first, f.second, v, j);
}
template < class Vb, class Cb>
inline
bool
Triangulation_data_structure_3<Vb,Cb>::
has_vertex(const Facet & f, const Vertex_handle& v) const
{
return has_vertex(f.first, f.second, v);
}
template < class Vb, class Cb>
bool
Triangulation_data_structure_3<Vb,Cb>::
are_equal(const Cell_handle& c, int i, const Cell_handle& n, int j) const
// tests whether facets c,i and n,j, have the same 3 vertices
// the triangulation is supposed to be valid, the orientation of the
// facets is not checked here
// the neighbor relations between c and n are not tested either,
// which allows to use this method before setting these relations
// (see remove in Delaunay_3)
// if ( c->neighbor(i) != n ) return false;
// if ( n->neighbor(j) != c ) return false;
{
CGAL_triangulation_precondition( dimension() == 3 );
if ( (c==n) && (i==j) ) return true;
int j1,j2,j3;
return( n->has_vertex( c->vertex((i+1)&3), j1 ) &&
n->has_vertex( c->vertex((i+2)&3), j2 ) &&
n->has_vertex( c->vertex((i+3)&3), j3 ) &&
( j1+j2+j3+j == 6 ) );
}
template < class Vb, class Cb>
bool
Triangulation_data_structure_3<Vb,Cb>::
are_equal(const Facet & f, const Facet & g) const
{
return are_equal(f.first, f.second, g.first, g.second);
}
template < class Vb, class Cb>
bool
Triangulation_data_structure_3<Vb,Cb>::
are_equal(const Facet & f, const Cell_handle& n, int j) const
{
return are_equal(f.first, f.second, n, j);
}
template < class Vb, class Cb>
bool
Triangulation_data_structure_3<Vb,Cb>::
flip( const Cell_handle& c, int i )
// returns false if the facet is not flippable
// true other wise and
// flips facet i of cell c
// c will be replaced by one of the new cells
{
CGAL_triangulation_precondition( (dimension() == 3) && (0<=i) && (i<4)
&& (number_of_vertices() > 6) );
CGAL_triangulation_expensive_precondition( is_cell(c) );
Cell_handle n = c->neighbor(i);
int in = n->index(c);
// checks that the facet is flippable,
// ie the future edge does not already exist
if (is_edge(c->vertex(i), n->vertex(in)))
return false;
flip_really(c,i,n,in);
return true;
}
template < class Vb, class Cb>
void
Triangulation_data_structure_3<Vb,Cb>::
flip_flippable(const Cell_handle& c, int i )
// flips facet i of cell c
// c will be replaced by one of the new cells
{
CGAL_triangulation_precondition( (dimension() == 3) && (0<=i) && (i<4)
&& (number_of_vertices() > 6) );
CGAL_triangulation_expensive_precondition( is_cell(c) );
Cell_handle n = c->neighbor(i);
int in = n->index(c);
// checks that the facet is flippable,
// ie the future edge does not already exist
CGAL_triangulation_expensive_precondition( !is_edge(c->vertex(i),
n->vertex(in)));
flip_really(c,i,n,in);
}
template < class Vb, class Cb>
inline
void
Triangulation_data_structure_3<Vb,Cb>::
flip_really( const Cell_handle& c, int i, const Cell_handle& n, int in )
// private - used by flip and flip_flippable
{
int i1 = (i+1)&3;
int i2 = (i+2)&3;
int i3 = (i+3)&3;
int in1 = n->index(c->vertex(i1));
int in2 = n->index(c->vertex(i2));
int in3 = n->index(c->vertex(i3));
set_adjacency(c, i, n->neighbor(in3), n->neighbor(in3)->index(n));
c->set_vertex( i3, n->vertex(in) );
set_adjacency(n, in, c->neighbor(i1), c->neighbor(i1)->index(c));
n->set_vertex( in1, c->vertex(i) );
Cell_handle cnew = create_cell(c->vertex(i), c->vertex(i1),
n->vertex(in), n->vertex(in3));
set_adjacency(cnew, 0, n->neighbor(in2), n->neighbor(in2)->index(n));
set_adjacency(cnew, 1, n, in2);
set_adjacency(cnew, 2, c->neighbor(i2), c->neighbor(i2)->index(c));
set_adjacency(cnew, 3, c, i2);
set_adjacency(c, i1, n, in3);
if ((i&1) != 0)
change_orientation(cnew);
c->vertex(i1)->set_cell(cnew);
c->vertex(i2)->set_cell(c);
n->vertex(in3)->set_cell(n);
// to be implemented : 2d case
// CGAL_triangulation_precondition( (0<=i) && (i<3) );
}
template < class Vb, class Cb>
bool
Triangulation_data_structure_3<Vb,Cb>::
flip( const Cell_handle& c, int i, int j )
// returns false if the edge is not flippable
// true otherwise and
// flips edge i,j of cell c
// c will be deleted
{
CGAL_triangulation_precondition( (dimension() == 3)
&& (0<=i) && (i<4)
&& (0<=j) && (j<4)
&& ( i != j )
&& (number_of_vertices() > 6) );
CGAL_triangulation_expensive_precondition( is_cell(c) );
// checks that the edge is flippable ie degree 3
int degree = 0;
Cell_circulator ccir = incident_cells(c,i,j);
Cell_circulator cdone = ccir;
do {
++degree;
++ccir;
} while ( ccir != cdone );
if ( degree != 3 ) return false;
int next = next_around_edge(i,j);
Cell_handle c1 = c->neighbor( next );
const Vertex_handle& v1 = c->vertex( next ); // will become vertex of c1
int i1 = c1->index( c->vertex(i) );
int j1 = c1->index( c->vertex(j) );
int next1 = next_around_edge(i1,j1);
Cell_handle c2 = c1->neighbor( next1 );
const Vertex_handle& v2 = c1->vertex( next1 ); // will become vertex of c2
int i2 = c2->index( c->vertex(i) );
int j2 = c2->index( c->vertex(j) );
int next2 = next_around_edge(i2,j2);
const Vertex_handle& v3 = c2->vertex( next2 );
// checks that the edge is flippable,
// is the future cells do not already exist
if ( is_cell(v1,v2,v3,c->vertex(i)) ) return false;
if ( is_cell(v1,v2,v3,c->vertex(j)) ) return false;
flip_really(c,i,j,c1,v1,i1,j1,next1,c2,v2,i2,j2,next2,v3);
return true;
}
template < class Vb, class Cb>
void
Triangulation_data_structure_3<Vb,Cb>::
flip_flippable( const Cell_handle& c, int i, int j )
// flips edge i,j of cell c
// c will be deleted
{
CGAL_triangulation_precondition( (dimension() == 3)
&& (0<=i) && (i<4)
&& (0<=j) && (j<4)
&& ( i != j )
&& (number_of_vertices() > 6) );
CGAL_triangulation_expensive_precondition( is_cell(c) );
// checks that the edge is flippable ie degree 3
CGAL_triangulation_precondition_code( int degree = 0; );
CGAL_triangulation_precondition_code
( Cell_circulator ccir = incident_cells(c,i,j); );
CGAL_triangulation_precondition_code( Cell_circulator cdone = ccir; );
CGAL_triangulation_precondition_code( do {
++degree;
++ccir;
} while ( ccir != cdone ); );
CGAL_triangulation_precondition( degree == 3 );
int next = next_around_edge(i,j);
Cell_handle c1 = c->neighbor( next );
const Vertex_handle& v1 = c->vertex( next ); // will become vertex of c1
int i1 = c1->index( c->vertex(i) );
int j1 = c1->index( c->vertex(j) );
int next1 = next_around_edge(i1,j1);
Cell_handle c2 = c1->neighbor( next1 );
const Vertex_handle& v2 = c1->vertex( next1 ); // will become vertex of c2
int i2 = c2->index( c->vertex(i) );
int j2 = c2->index( c->vertex(j) );
int next2 = next_around_edge(i2,j2);
const Vertex_handle& v3 = c2->vertex( next2 );
// checks that the edge is flippable,
// is the future cells do not already exist
CGAL_triangulation_expensive_precondition( !is_cell(v1,v2,v3,c->vertex(i)) );
CGAL_triangulation_expensive_precondition( !is_cell(v1,v2,v3,c->vertex(j)) );
flip_really(c,i,j,c1,v1,i1,j1,next1,c2,v2,i2,j2,next2,v3);
}
template < class Vb, class Cb>
inline
void
Triangulation_data_structure_3<Vb,Cb>::
flip_really( const Cell_handle& c, int i, int j,
const Cell_handle& c1, const Vertex_handle& v1,
int i1, int j1, int next1,
const Cell_handle& c2, const Vertex_handle& v2,
int i2, int j2, int next2,
const Vertex_handle& v3 )
{
c->vertex(i)->set_cell(c1);
c->vertex(j)->set_cell(c2);
c1->set_vertex( j1, v1 );
v1->set_cell(c1);
c2->set_vertex( i2, v2 );
v2->set_cell(c2);
set_adjacency(c1, next1,c2->neighbor(j2), c2->neighbor(j2)->index(c2));
set_adjacency(c2,c2->index(v1),c1->neighbor(i1),c1->neighbor(i1)->index(c1));
set_adjacency(c1, i1, c2, j2);
set_adjacency(c1, 6-i1-j1-next1, c->neighbor(j), c->neighbor(j)->index(c));
set_adjacency(c2, next2, c->neighbor(i), c->neighbor(i)->index(c));
v3->set_cell( c2 );
delete_cell( c );
}
template < class Vb, class Cb >
void
Triangulation_data_structure_3<Vb,Cb>::
read_cells(std::istream& is, std::map< int, Vertex_handle > &V,
int & m, std::map< int, Cell_handle > &C)
{
// creation of the cells and neighbors
switch (dimension()) {
case 3:
case 2:
case 1:
{
is >> m;
for(int i = 0; i < m; i++) {
Cell_handle c = create_cell();
for (int k=0; k<=dimension(); ++k) {
int ik;
is >> ik;
c->set_vertex(k, V[ik]);
V[ik]->set_cell(c);
}
C[i] = c;
}
for(int j = 0; j < m; j++) {
Cell_handle c = C[j];
for (int k=0; k<=dimension(); ++k) {
int ik;
is >> ik;
c->set_neighbor(k, C[ik]);
}
}
break;
}
case 0:
{
m = 2;
// CGAL_triangulation_assertion( n == 2 );
for (int i=0; i < 2; i++) {
Cell_handle c = create_face(V[i], Vertex_handle(), Vertex_handle());
C[i] = c;
V[i]->set_cell(c);
}
for (int j=0; j < 2; j++) {
Cell_handle c = C[j];
c->set_neighbor(0, C[1-j]);
}
break;
}
case -1:
{
m = 1;
// CGAL_triangulation_assertion( n == 1 );
Cell_handle c = create_face(V[0], Vertex_handle(), Vertex_handle());
C[0] = c;
V[0]->set_cell(c);
break;
}
}
}
template < class Vb, class Cb>
void
Triangulation_data_structure_3<Vb,Cb>::
print_cells(std::ostream& os, const std::map<Vertex_handle, int> &V ) const
{
std::map<Cell_handle, int > C;
int i = 0;
switch ( dimension() ) {
case 3:
{
int m = number_of_cells();
os << m;
if(is_ascii(os))
os << std::endl;
// write the cells
Cell_iterator it;
for(it = cells_begin(); it != cells_end(); ++it) {
C[it] = i++;
for(int j = 0; j < 4; j++){
os << V.find(it->vertex(j))->second;
if(is_ascii(os)) {
if ( j==3 )
os << std::endl;
else
os << ' ';
}
}
}
CGAL_triangulation_assertion( i == m );
// write the neighbors
for(it = cells_begin(); it != cells_end(); ++it) {
for (int j = 0; j < 4; j++) {
os << C[it->neighbor(j)];
if(is_ascii(os)){
if(j==3)
os << std::endl;
else
os << ' ';
}
}
}
break;
}
case 2:
{
int m = number_of_facets();
os << m;
if(is_ascii(os))
os << std::endl;
// write the facets
Facet_iterator it;
for(it = facets_begin(); it != facets_end(); ++it) {
C[(*it).first] = i++;
for(int j = 0; j < 3; j++){
os << V.find((*it).first->vertex(j))->second;
if(is_ascii(os)) {
if ( j==2 )
os << std::endl;
else
os << ' ';
}
}
}
CGAL_triangulation_assertion( i == m );
// write the neighbors
for(it = facets_begin(); it != facets_end(); ++it) {
for (int j = 0; j < 3; j++) {
os << C[(*it).first->neighbor(j)];
if(is_ascii(os)){
if(j==2)
os << std::endl;
else
os << ' ';
}
}
}
break;
}
case 1:
{
int m = number_of_edges();
os << m;
if(is_ascii(os))
os << std::endl;
// write the edges
Edge_iterator it;
for(it = edges_begin(); it != edges_end(); ++it) {
C[(*it).first] = i++;
for(int j = 0; j < 2; j++){
os << V.find((*it).first->vertex(j))->second;
if(is_ascii(os)) {
if ( j==1 )
os << std::endl;
else
os << ' ';
}
}
}
CGAL_triangulation_assertion( i == m );
// write the neighbors
for(it = edges_begin(); it != edges_end(); ++it) {
for (int j = 0; j < 2; j++) {
os << C[(*it).first->neighbor(j)];
if(is_ascii(os)){
if(j==1)
os << std::endl;
else
os << ' ';
}
}
}
break;
}
}
}
template <class Vb, class Cb >
typename Triangulation_data_structure_3<Vb,Cb>::Vertex_handle
Triangulation_data_structure_3<Vb,Cb>::
insert_in_cell(const Cell_handle& c)
{
CGAL_triangulation_precondition( dimension() == 3 );
CGAL_triangulation_precondition( c != Cell_handle() );
CGAL_triangulation_expensive_precondition( is_cell(c) );
Vertex_handle v = create_vertex();
Vertex_handle v0 = c->vertex(0);
Vertex_handle v1 = c->vertex(1);
Vertex_handle v2 = c->vertex(2);
Vertex_handle v3 = c->vertex(3);
Cell_handle n1 = c->neighbor(1);
Cell_handle n2 = c->neighbor(2);
Cell_handle n3 = c->neighbor(3);
// c will be modified to have v,v1,v2,v3 as vertices
Cell_handle c3 = create_cell(v0,v1,v2,v);
Cell_handle c2 = create_cell(v0,v1,v,v3);
Cell_handle c1 = create_cell(v0,v,v2,v3);
set_adjacency(c3, 0, c, 3);
set_adjacency(c2, 0, c, 2);
set_adjacency(c1, 0, c, 1);
set_adjacency(c2, 3, c3, 2);
set_adjacency(c1, 3, c3, 1);
set_adjacency(c1, 2, c2, 1);
set_adjacency(n1, n1->index(c), c1, 1);
set_adjacency(n2, n2->index(c), c2, 2);
set_adjacency(n3, n3->index(c), c3, 3);
c->set_vertex(0,v);
v0->set_cell(c1);
v->set_cell(c);
return v;
}
template <class Vb, class Cb >
typename Triangulation_data_structure_3<Vb,Cb>::Vertex_handle
Triangulation_data_structure_3<Vb,Cb>::
insert_in_facet(const Cell_handle& c, int i)
{ // inserts v in the facet opposite to vertex i of cell c
CGAL_triangulation_precondition( c != Cell_handle() );
CGAL_triangulation_precondition( dimension() >= 2 );
Vertex_handle v = create_vertex();
switch ( dimension() ) {
case 3:
{
CGAL_triangulation_expensive_precondition( is_cell(c) );
CGAL_triangulation_precondition( i == 0 || i == 1 ||
i == 2 || i == 3 );
// c will be modified to have v replacing vertex(i+3)
int i1,i2,i3;
if ( (i&1) == 0 ) {
i1=(i+1)&3; i2=(i+2)&3; i3=6-i-i1-i2;
}
else {
i1=(i+1)&3; i2=(i+3)&3; i3=6-i-i1-i2;
}
// i,i1,i2,i3 is well oriented
// so v will "replace" the vertices in this order
// when creating the new cells one after another from c
Vertex_handle vi=c->vertex(i);
Vertex_handle v1=c->vertex(i1);
Vertex_handle v2=c->vertex(i2);
Vertex_handle v3=c->vertex(i3);
// new cell with v in place of i1
Cell_handle nc = c->neighbor(i1);
Cell_handle cnew1 = create_cell(vi,v,v2,v3);
set_adjacency(cnew1, 1, nc, nc->index(c));
set_adjacency(cnew1, 3, c, i1);
v3->set_cell(cnew1);
// new cell with v in place of i2
nc = c->neighbor(i2);
Cell_handle cnew2 = create_cell(vi,v1,v,v3);
set_adjacency(cnew2, 2, nc, nc->index(c));
set_adjacency(cnew2, 3, c, i2);
set_adjacency(cnew1, 2, cnew2, 1);
// v replaces i3 in c
c->set_vertex(i3,v);
// other side of facet containing v
Cell_handle d = c->neighbor(i);
int j = d->index(c);
int j1=d->index(v1);// triangulation supposed to be valid
int j2=d->index(v2);
int j3=6-j-j1-j2;
// then the orientation of j,j1,j2,j3 depends on the parity
// of i-j
// new cell with v in place of j1
Cell_handle nd = d->neighbor(j1);
Cell_handle dnew1 = create_cell(d->vertex(j),v,v3,v2);
set_adjacency(dnew1, 1, nd, nd->index(d));
set_adjacency(dnew1, 2, d, j1);
set_adjacency(dnew1, 0, cnew1, 0);
// new cell with v in place of j2
nd = d->neighbor(j2);
Cell_handle dnew2 = create_cell(d->vertex(j),v1,v3,v);
set_adjacency(dnew2, 3, nd, nd->index(d));
set_adjacency(dnew2, 2, d, j2);
set_adjacency(dnew2, 0, cnew2, 0);
set_adjacency(dnew1, 3, dnew2, 1);
// v replaces i3 in d
d->set_vertex(j3,v);
v->set_cell(d);
break;
}
case 2:
{
CGAL_triangulation_expensive_precondition( is_facet(c,i) );
Cell_handle n = c->neighbor(2);
Cell_handle cnew = create_face(c->vertex(0),c->vertex(1),v);
set_adjacency(cnew, 2, n, n->index(c));
set_adjacency(cnew, 0, c, 2);
c->vertex(0)->set_cell(cnew);
n = c->neighbor(1);
Cell_handle dnew = create_face(c->vertex(0),v,c->vertex(2));
set_adjacency(dnew, 1, n, n->index(c));
set_adjacency(dnew, 0, c, 1);
set_adjacency(dnew, 2, cnew, 1);
c->set_vertex(0,v);
v->set_cell(c);
break;
}
}
return v;
}
template <class Vb, class Cb >
typename Triangulation_data_structure_3<Vb,Cb>::Vertex_handle
Triangulation_data_structure_3<Vb,Cb>::
insert_in_edge(const Cell_handle& c, int i, int j)
// inserts a vertex in the edge of cell c with vertices i and j
{
CGAL_triangulation_precondition( c != Cell_handle() );
CGAL_triangulation_precondition( i != j );
CGAL_triangulation_precondition( dimension() >= 1 );
switch ( dimension() ) {
case 3:
{
CGAL_triangulation_expensive_precondition( is_cell(c) );
CGAL_triangulation_precondition( i>=0 && i<=3 && j>=0 && j<=3 );
std::vector<Cell_handle > cells;
cells.reserve(32);
Cell_circulator ccir = incident_cells(c, i, j);
do {
Cell_handle cc = ccir;
cells.push_back(cc);
cc->set_in_conflict_flag(1);
++ccir;
} while (c != ccir);
return _insert_in_hole(cells.begin(), cells.end(), c, i);
}
case 2:
{
CGAL_triangulation_expensive_precondition( is_edge(c,i,j) );
Vertex_handle v = create_vertex();
int k=3-i-j; // index of the third vertex of the facet
Cell_handle d = c->neighbor(k);
int kd = d->index(c);
int id = d->index(c->vertex(i));
int jd = d->index(c->vertex(j));
Cell_handle cnew = create_cell();
cnew->set_vertex(i,c->vertex(i));
c->vertex(i)->set_cell(cnew);
cnew->set_vertex(j,v);
cnew->set_vertex(k,c->vertex(k));
c->set_vertex(i,v);
Cell_handle dnew = create_cell();
dnew->set_vertex(id,d->vertex(id));
// d->vertex(id)->cell() is cnew OK
dnew->set_vertex(jd,v);
dnew->set_vertex(kd,d->vertex(kd));
d->set_vertex(id,v);
Cell_handle nj = c->neighbor(j);
set_adjacency(cnew, i, c, j);
set_adjacency(cnew, j, nj, nj->index(c));
nj = d->neighbor(jd);
set_adjacency(dnew, id, d, jd);
set_adjacency(dnew, jd, nj, nj->index(d));
set_adjacency(cnew, k, dnew, kd);
v->set_cell(cnew);
return v;
}
default: // case 1:
{
Vertex_handle v = create_vertex();
CGAL_triangulation_expensive_precondition( is_edge(c,i,j) );
Cell_handle cnew = create_face(v, c->vertex(1), Vertex_handle());
c->vertex(1)->set_cell(cnew);
c->set_vertex(1,v);
set_adjacency(cnew, 0, c->neighbor(0), 1);
set_adjacency(cnew, 1, c, 0);
v->set_cell(cnew);
return v;
}
}
}
template <class Vb, class Cb >
typename Triangulation_data_structure_3<Vb,Cb>::Vertex_handle
Triangulation_data_structure_3<Vb,Cb>::
insert_increase_dimension(Vertex_handle star)
// star = vertex from which we triangulate the facet of the
// incremented dimension
// ( geometrically : star = infinite vertex )
// = NULL only used to insert the 1st vertex (dimension -2 to dimension -1)
// changes the dimension
{
CGAL_triangulation_precondition( dimension() < 3);
Vertex_handle v = create_vertex();
int dim = dimension();
if (dim != -2) {
CGAL_triangulation_precondition( star != Vertex_handle() );
// In this case, this precondition is not relatively expensive.
CGAL_triangulation_precondition( is_vertex(star) );
}
// this is set now, so that it becomes allowed to reorient
// new facets or cells by iterating on them (otherwise the
// dimension is too small)
set_dimension( dimension()+1 );
switch ( dim ) {
case -2:
// insertion of the first vertex
// ( geometrically : infinite vertex )
{
Cell_handle c = create_face(v, Vertex_handle(), Vertex_handle());
v->set_cell(c);
break;
}
case -1:
// insertion of the second vertex
// ( geometrically : first finite vertex )
{
Cell_handle d = create_face(v, Vertex_handle(), Vertex_handle());
v->set_cell(d);
set_adjacency(d, 0, star->cell(), 0);
break;
}
case 0:
// insertion of the third vertex
// ( geometrically : second finite vertex )
{
Cell_handle c = star->cell();
Cell_handle d = c->neighbor(0);
c->set_vertex(1,d->vertex(0));
d->set_vertex(1,v);
d->set_neighbor(1,c);
Cell_handle e = create_face( v, star, Vertex_handle() );
set_adjacency(e, 0, c, 1);
set_adjacency(e, 1, d, 0);
v->set_cell(d);
break;
}
case 1:
// general case : 4th vertex ( geometrically : 3rd finite vertex )
// degenerate cases geometrically : 1st non collinear vertex
{
Cell_handle c = star->cell();
int i = c->index(star); // i== 0 or 1
int j = (1-i);
Cell_handle d = c->neighbor(j);
c->set_vertex(2,v);
Cell_handle e = c->neighbor(i);
Cell_handle cnew = c;
Cell_handle enew = Cell_handle();
while( e != d ){
enew = create_cell();
enew->set_vertex(i,e->vertex(j));
enew->set_vertex(j,e->vertex(i));
enew->set_vertex(2,star);
set_adjacency(enew, i, cnew, j);
// false at the first iteration of the loop where it should
// be neighbor 2
// it is corrected after the loop
set_adjacency(enew, 2, e, 2);
// neighbor j will be set during next iteration of the loop
e->set_vertex(2,v);
e = e->neighbor(i);
cnew = enew;
}
d->set_vertex(2,v);
set_adjacency(enew, j, d, 2);
// corrections for star->cell() :
c = star->cell();
c->set_neighbor(2,c->neighbor(i)->neighbor(2));
c->set_neighbor(j,d);
v->set_cell(d);
break;
}
case 2:
// general case : 5th vertex ( geometrically : 4th finite vertex )
// degenerate cases : geometrically 1st non coplanar vertex
{
// used to store the new cells, in order to be able to traverse only
// them to find the missing neighbors.
std::vector<Cell_handle > new_cells;
new_cells.reserve(16);
Cell_iterator it = cells_begin();
// allowed since the dimension has already been set to 3
v->set_cell(it); // ok since there is at least one ``cell''
for(; it != cells_end(); ++it) {
// Here we must be careful since we create_cells in a loop controlled
// by an iterator. So we first take care of the cells newly created
// by the following test :
if (it->neighbor(0) == Cell_handle())
continue;
it->set_neighbor(3, Cell_handle());
it->set_vertex(3, v);
if ( ! it->has_vertex(star) ) {
Cell_handle cnew = create_cell( it->vertex(0), it->vertex(2),
it->vertex(1), star);
// The Intel compiler has a problem with passing "it" directly to
// function "set_adjacency": the adjacency is not changed.
Cell_handle ch_it = it;
set_adjacency(cnew, 3, ch_it, 3);
cnew->set_neighbor(0, Cell_handle());
new_cells.push_back(cnew);
}
}
// traversal of the new cells only, to add missing neighbors
for(typename std::vector<Cell_handle>::iterator ncit = new_cells.begin();
ncit != new_cells.end(); ++ncit) {
Cell_handle n = (*ncit)->neighbor(3); // opposite to star
for ( int i=0; i<3; i++ ) {
int j;
if ( i==0 ) j=0;
else j=3-i; // vertex 1 and vertex 2 are always switched when
// creating a new cell (see above)
Cell_handle c = n->neighbor(i)->neighbor(3);
if ( c != Cell_handle() ) {
// i.e. star is not a vertex of n->neighbor(i)
(*ncit)->set_neighbor(j, c);
// opposite relation will be set when ncit arrives on c
// this avoids to look for the correct index
// and to test whether *ncit already has neighbor i
}
else {
// star is a vertex of n->neighbor(i)
set_adjacency(*ncit, j, n->neighbor(i), 3);//neighbor opposite to v
}
}
}
}
}// end switch
return v;
}
template <class Vb, class Cb >
void
Triangulation_data_structure_3<Vb,Cb>::
remove_decrease_dimension(const Vertex_handle& v, const Vertex_handle &w)
{
CGAL_triangulation_expensive_precondition( is_valid() );
CGAL_triangulation_precondition( dimension() >= -1 );
CGAL_triangulation_precondition( dimension() != 1 ||
number_of_vertices() == 3);
CGAL_triangulation_precondition( number_of_vertices() >
(size_type) dimension() + 1 );
CGAL_triangulation_precondition( degree(v) == number_of_vertices()-1 );
if (dimension() <= 0) {
delete_cell(v->cell());
}
else {
// the cells incident to w are down graded one dimension
// the other cells are deleted
std::vector<Cell_handle> to_delete, to_downgrade;
for (Cell_iterator ib = cell_container().begin();
ib != cell_container().end(); ++ib) {
if ( ib->has_vertex(w) )
to_downgrade.push_back(ib);
else
to_delete.push_back(ib);
}
typename std::vector<Cell_handle>::iterator lfit=to_downgrade.begin();
for( ; lfit != to_downgrade.end(); ++lfit) {
Cell_handle f = *lfit;
int j = f->index(w);
int k; if (f->has_vertex(v, k)) f->set_vertex(k, w);
if (j != dimension()) {
f->set_vertex(j, f->vertex(dimension()));
f->set_neighbor(j, f->neighbor(dimension()));
if (dimension() >= 1)
change_orientation(f);
}
f->set_vertex(dimension(), Vertex_handle());
f->set_neighbor(dimension(), Cell_handle());
// Update vertex->cell() pointers.
for (int i = 0; i < dimension(); ++i)
f->vertex(i)->set_cell(f);
}
delete_cells(to_delete.begin(), to_delete.end());
}
delete_vertex(v);
set_dimension(dimension()-1);
CGAL_triangulation_postcondition(is_valid());
}
template <class Vb, class Cb >
typename Triangulation_data_structure_3<Vb,Cb>::Cell_handle
Triangulation_data_structure_3<Vb,Cb>::
remove_from_maximal_dimension_simplex(const Vertex_handle& v)
{
CGAL_triangulation_precondition(dimension() >= 1);
CGAL_triangulation_precondition(degree(v) == (size_type) dimension() + 1);
CGAL_triangulation_precondition(number_of_vertices() >
(size_type) dimension() + 1);
if (number_of_vertices() == (size_type) dimension() + 2) {
remove_decrease_dimension(v);
return Cell_handle();
}
if (dimension() == 3)
return remove_degree_4(v);
if (dimension() == 2)
return remove_degree_3(v);
// dimension() == 1
return remove_degree_2(v);
}
template <class Vb, class Cb >
typename Triangulation_data_structure_3<Vb,Cb>::Cell_handle
Triangulation_data_structure_3<Vb,Cb>::
remove_degree_2(const Vertex_handle& v)
{
CGAL_triangulation_precondition(dimension() == 1);
CGAL_triangulation_precondition(degree(v) == 2);
CGAL_triangulation_precondition(number_of_vertices() >= 4);
// Cells to be killed.
Cell_handle c0, c1;
// Indices of v in these cells.
int i0, i1;
c0 = v->cell();
i0 = c0->index(v);
c1 = c0->neighbor(1-i0);
i1 = c1->index(v);
// New cell : we copy the content of c0, so we keep the orientation.
Cell_handle newc = create_face(c0->vertex(0),
c0->vertex(1),
Vertex_handle());
newc->set_vertex(i0, c1->vertex(c1->index(c0)));
set_adjacency(newc, i0, c0->neighbor(i0), mirror_index(c0, i0));
set_adjacency(newc, 1-i0, c1->neighbor(i1), mirror_index(c1, i1));
newc->vertex(0)->set_cell(newc);
newc->vertex(1)->set_cell(newc);
delete_cell(c0);
delete_cell(c1);
delete_vertex(v);
return newc;
}
template <class Vb, class Cb >
typename Triangulation_data_structure_3<Vb,Cb>::Cell_handle
Triangulation_data_structure_3<Vb,Cb>::
remove_degree_3(const Vertex_handle& v)
{
CGAL_triangulation_precondition(dimension() == 2);
CGAL_triangulation_precondition(degree(v) == 3);
CGAL_triangulation_precondition(number_of_vertices() >= 5);
// Cells to be killed.
Cell_handle c0, c1, c2;
// Indices of v in these cells.
int i0, i1, i2;
c0 = v->cell();
i0 = c0->index(v);
c1 = c0->neighbor(cw(i0));
i1 = c1->index(v);
c2 = c0->neighbor(ccw(i0));
i2 = c2->index(v);
// New cell : we copy the content of c0, so we keep the orientation.
Cell_handle newc = create_face(c0->vertex(0),
c0->vertex(1),
c0->vertex(2));
newc->set_vertex(i0, c1->vertex(c1->index(c0)));
set_adjacency(newc, i0, c0->neighbor(i0), mirror_index(c0, i0));
set_adjacency(newc, cw(i0), c1->neighbor(i1), mirror_index(c1, i1));
set_adjacency(newc, ccw(i0), c2->neighbor(i2), mirror_index(c2, i2));
newc->vertex(0)->set_cell(newc);
newc->vertex(1)->set_cell(newc);
newc->vertex(2)->set_cell(newc);
delete_cell(c0);
delete_cell(c1);
delete_cell(c2);
delete_vertex(v);
return newc;
}
template <class Vb, class Cb >
typename Triangulation_data_structure_3<Vb,Cb>::Cell_handle
Triangulation_data_structure_3<Vb,Cb>::
remove_degree_4(const Vertex_handle& v)
{
CGAL_triangulation_precondition(dimension() == 3);
CGAL_triangulation_precondition(degree(v) == 4);
CGAL_triangulation_precondition(number_of_vertices() >= 6);
// Cells to be killed.
Cell_handle c0, c1, c2, c3;
// Indices of v in these cells.
int i0, i1, i2, i3;
c0 = v->cell();
i0 = c0->index(v);
c1 = c0->neighbor(i0^1);
i1 = c1->index(v);
c2 = c0->neighbor(i0^2);
i2 = c2->index(v);
c3 = c0->neighbor(i0^3);
i3 = c3->index(v);
// New cell : we copy the content of c0, so we keep the orientation.
Cell_handle newc = create_cell(c0->vertex(0),
c0->vertex(1),
c0->vertex(2),
c0->vertex(3));
newc->set_vertex(i0, c1->vertex(c1->index(c0)));
set_adjacency(newc, i0, c0->neighbor(i0), mirror_index(c0, i0));
set_adjacency(newc, i0^1, c1->neighbor(i1), mirror_index(c1, i1));
set_adjacency(newc, i0^2, c2->neighbor(i2), mirror_index(c2, i2));
set_adjacency(newc, i0^3, c3->neighbor(i3), mirror_index(c3, i3));
newc->vertex(0)->set_cell(newc);
newc->vertex(1)->set_cell(newc);
newc->vertex(2)->set_cell(newc);
newc->vertex(3)->set_cell(newc);
delete_cell(c0);
delete_cell(c1);
delete_cell(c2);
delete_cell(c3);
delete_vertex(v);
return newc;
}
template <class Vb, class Cb >
typename Triangulation_data_structure_3<Vb,Cb>::size_type
Triangulation_data_structure_3<Vb,Cb>::
degree(const Vertex_handle& v) const
{
Counting_output_iterator cnt;
return (int) incident_vertices(v, cnt).current_counter();
}
template <class Vb, class Cb >
bool
Triangulation_data_structure_3<Vb,Cb>::
is_valid(bool verbose, int level ) const
{
switch ( dimension() ) {
case 3:
{
size_type vertex_count;
if ( ! count_vertices(vertex_count,verbose,level) )
return false;
if ( number_of_vertices() != vertex_count ) {
if (verbose)
std::cerr << "wrong number of vertices" << std::endl;
CGAL_triangulation_assertion(false);
return false;
}
size_type cell_count;
if ( ! count_cells(cell_count,verbose,level) )
return false;
size_type edge_count;
if ( ! count_edges(edge_count,verbose,level) )
return false;
size_type facet_count;
if ( ! count_facets(facet_count,verbose,level) )
return false;
// Euler relation
if ( cell_count - facet_count + edge_count - vertex_count != 0 ) {
if (verbose)
std::cerr << "Euler relation unsatisfied" << std::endl;
CGAL_triangulation_assertion(false);
return false;
}
break;
}
case 2:
{
size_type vertex_count;
if ( ! count_vertices(vertex_count,verbose,level) )
return false;
if ( number_of_vertices() != vertex_count ) {
if (verbose)
std::cerr << "false number of vertices" << std::endl;
CGAL_triangulation_assertion(false);
return false;
}
size_type edge_count;
if ( ! count_edges(edge_count,verbose,level) )
return false;
// Euler for edges
if ( edge_count != 3 * vertex_count - 6 ) {
if (verbose)
std::cerr << "Euler relation unsatisfied - edges/vertices"
<< std::endl;
CGAL_triangulation_assertion(false);
return false;
}
size_type facet_count;
if ( ! count_facets(facet_count,verbose,level) )
return false;
// Euler for facets
if ( facet_count != 2 * vertex_count - 4 ) {
if (verbose)
std::cerr << "Euler relation unsatisfied - facets/vertices"
<< std::endl;
CGAL_triangulation_assertion(false);
return false;
}
break;
}
case 1:
{
size_type vertex_count;
if ( ! count_vertices(vertex_count,verbose,level) )
return false;
if ( number_of_vertices() != vertex_count ) {
if (verbose)
std::cerr << "false number of vertices" << std::endl;
CGAL_triangulation_assertion(false);
return false;
}
size_type edge_count;
if ( ! count_edges(edge_count,verbose,level) )
return false;
// Euler for edges
if ( edge_count != vertex_count ) {
if (verbose)
std::cerr << "false number of edges" << std::endl;
CGAL_triangulation_assertion(false);
return false;
}
break;
}
case 0:
{
if ( number_of_vertices() < 2 ) {
if (verbose)
std::cerr << "less than 2 vertices but dimension 0" << std::endl;
CGAL_triangulation_assertion(false);
return false;
}
// no break; continue
}
case -1:
{
if ( number_of_vertices() < 1 ) {
if (verbose)
std::cerr << "no vertex but dimension -1" << std::endl;
CGAL_triangulation_assertion(false);
return false;
}
// vertex count
size_type vertex_count;
if ( ! count_vertices(vertex_count,verbose,level) )
return false;
if ( number_of_vertices() != vertex_count ) {
if (verbose)
std::cerr << "false number of vertices" << std::endl;
CGAL_triangulation_assertion(false);
return false;
}
}
} // end switch
if (verbose)
std::cerr << "valid data structure" << std::endl;
return true;
}
template <class Vb, class Cb >
bool
Triangulation_data_structure_3<Vb,Cb>::
is_valid(Vertex_handle v, bool verbose, int level) const
{
bool result = v->is_valid(verbose,level);
result = result && v->cell()->has_vertex(v);
if ( ! result ) {
if ( verbose )
std::cerr << "invalid vertex" << std::endl;
CGAL_triangulation_assertion(false);
}
return result;
}
template <class Vb, class Cb >
bool
Triangulation_data_structure_3<Vb,Cb>::
is_valid(Cell_handle c, bool verbose, int level) const
{
if ( ! c->is_valid(verbose, level) )
return false;
switch (dimension()) {
case -2:
case -1:
{
if ( c->vertex(0) == Vertex_handle() ) {
if (verbose)
std::cerr << "vertex 0 NULL" << std::endl;
CGAL_triangulation_assertion(false);
return false;
}
is_valid(c->vertex(0),verbose,level);
if ( c->vertex(1) != Vertex_handle() || c->vertex(2) != Vertex_handle()) {
if (verbose)
std::cerr << "vertex 1 or 2 != NULL" << std::endl;
CGAL_triangulation_assertion(false);
return false;
}
if ( c->neighbor(0) != Cell_handle() ||
c->neighbor(1) != Cell_handle() ||
c->neighbor(2) != Cell_handle()) {
if (verbose)
std::cerr << "one neighbor != NULL" << std::endl;
CGAL_triangulation_assertion(false);
return false;
}
break;
}
case 0:
{
if ( c->vertex(0) == Vertex_handle() ) {
if (verbose)
std::cerr << "vertex 0 NULL" << std::endl;
CGAL_triangulation_assertion(false);
return false;
}
is_valid(c->vertex(0),verbose,level);
if ( c->neighbor (0) == Cell_handle() ) {
if (verbose)
std::cerr << "neighbor 0 NULL" << std::endl;
CGAL_triangulation_assertion(false);
return false;
}
if ( c->vertex(1) != Vertex_handle() ||
c->vertex(2) != Vertex_handle() ) {
if (verbose)
std::cerr << "vertex 1 or 2 != NULL" << std::endl;
CGAL_triangulation_assertion(false);
return false;
}
if ( c->neighbor(1) != Cell_handle() ||
c->neighbor(2) != Cell_handle() ) {
if (verbose)
std::cerr << "neighbor 1 or 2 != NULL" << std::endl;
CGAL_triangulation_assertion(false);
return false;
}
if ( ! c->neighbor(0)->has_vertex(c->vertex(0)) ) {
if (verbose)
std::cerr << "neighbor 0 does not have vertex 0" << std::endl;
CGAL_triangulation_assertion(false);
return false;
}
break;
}
case 1:
{
Vertex_handle v0 = c->vertex(0);
Vertex_handle v1 = c->vertex(1);
Cell_handle n0 = c->neighbor(0);
Cell_handle n1 = c->neighbor(1);
if ( v0 == Vertex_handle() || v1 == Vertex_handle() ) {
if (verbose)
std::cerr << "vertex 0 or 1 NULL" << std::endl;
CGAL_triangulation_assertion(false);
return false;
}
is_valid(c->vertex(0),verbose,level);
is_valid(c->vertex(1),verbose,level);
if ( n0 == Cell_handle() || n1 == Cell_handle() ) {
if (verbose)
std::cerr << "neighbor 0 or 1 NULL" << std::endl;
CGAL_triangulation_assertion(false);
return false;
}
if ( v0 != n1->vertex(1) ) {
if (verbose)
std::cerr << "neighbor 1 does not have vertex 0 as vertex 1"
<< std::endl;
CGAL_triangulation_assertion(false);
return false;
}
if ( v1 != n0->vertex(0) ) {
if (verbose)
std::cerr << "neighbor 0 does not have vertex 1 as vertex 0"
<< std::endl;
CGAL_triangulation_assertion(false);
return false;
}
if ( n0->neighbor(1) != c ) {
if (verbose)
std::cerr << "neighbor 0 does not have this as neighbor 1"
<< std::endl;
CGAL_triangulation_assertion(false);
return false;
}
if ( n1->neighbor(0) != c ) {
if (verbose)
std::cerr << "neighbor 1 does not have this as neighbor 0"
<< std::endl;
CGAL_triangulation_assertion(false);
return false;
}
break;
}
case 2:
{
if ( c->vertex(0) == Vertex_handle() ||
c->vertex(1) == Vertex_handle() ||
c->vertex(2) == Vertex_handle() ) {
if (verbose)
std::cerr << "vertex 0, 1, or 2 NULL" << std::endl;
CGAL_triangulation_assertion(false);
return false;
}
is_valid(c->vertex(0),verbose,level);
is_valid(c->vertex(1),verbose,level);
is_valid(c->vertex(2),verbose,level);
int in;
Cell_handle n;
for(int i = 0; i < 3; i++) {
n = c->neighbor(i);
if ( n == Cell_handle() ) {
if (verbose)
std::cerr << "neighbor " << i << " NULL" << std::endl;
CGAL_triangulation_assertion(false);
return false;
}
if ( ! n->has_vertex(c->vertex(cw(i)),in ) ) {
if (verbose)
std::cerr << "vertex " << cw(i)
<< " not vertex of neighbor " << i << std::endl;
CGAL_triangulation_assertion(false);
return false;
}
in = cw(in);
if ( n->neighbor(in) != c ) {
if (verbose)
std::cerr << "neighbor " << i
<< " does not have this as neighbor "
<< in << std::endl;
CGAL_triangulation_assertion(false);
return false;
}
if ( c->vertex(ccw(i)) != n->vertex(cw(in)) ) {
if (verbose)
std::cerr << "vertex " << ccw(i)
<< " is not vertex " << cw(in)
<< " of neighbor " << i << std::endl;
CGAL_triangulation_assertion(false);
return false;
}
}
break;
}
case 3:
{
int i;
for(i = 0; i < 4; i++) {
if ( c->vertex(i) == Vertex_handle() ) {
if (verbose)
std::cerr << "vertex " << i << " NULL" << std::endl;
CGAL_triangulation_assertion(false);
return false;
}
is_valid(c->vertex(i),verbose,level);
}
for(i = 0; i < 4; i++) {
Cell_handle n = c->neighbor(i);
if ( n == Cell_handle() ) {
if (verbose)
std::cerr << "neighbor " << i << " NULL" << std::endl;
CGAL_triangulation_assertion(false);
return false;
}
int in = 5;
// if ( ! n->has_neighbor(handle(), in) ) {
if ( n->neighbor(0) == c) in = 0;
if ( n->neighbor(1) == c) in = 1;
if ( n->neighbor(2) == c) in = 2;
if ( n->neighbor(3) == c) in = 3;
if (in == 5) {
if (verbose)
std::cerr << "neighbor of c has not c as neighbor" << std::endl;
CGAL_triangulation_assertion(false);
return false;
}
int j1n,j2n,j3n;
if ( ! n->has_vertex(c->vertex((i+1)&3),j1n) ) {
if (verbose) { std::cerr << "vertex " << ((i+1)&3)
<< " not vertex of neighbor "
<< i << std::endl; }
CGAL_triangulation_assertion(false);
return false;
}
if ( ! n->has_vertex(c->vertex((i+2)&3),j2n) ) {
if (verbose) { std::cerr << "vertex " << ((i+2)&3)
<< " not vertex of neighbor "
<< i << std::endl; }
CGAL_triangulation_assertion(false);
return false;
}
if ( ! n->has_vertex(c->vertex((i+3)&3),j3n) ) {
if (verbose) { std::cerr << "vertex " << ((i+3)&3)
<< " not vertex of neighbor "
<< i << std::endl; }
CGAL_triangulation_assertion(false);
return false;
}
if ( in+j1n+j2n+j3n != 6) {
if (verbose) { std::cerr << "sum of the indices != 6 "
<< std::endl; }
CGAL_triangulation_assertion(false);
return false;
}
// tests whether the orientations of this and n are consistent
if ( ((i+in)&1) == 0 ) { // i and in have the same parity
if ( j1n == ((in+1)&3) ) {
if ( ( j2n != ((in+3)&3) ) || ( j3n != ((in+2)&3) ) ) {
if (verbose)
std::cerr << " pb orientation with neighbor "
<< i << std::endl;
CGAL_triangulation_assertion(false);
return false;
}
}
if ( j1n == ((in+2)&3) ) {
if ( ( j2n != ((in+1)&3) ) || ( j3n != ((in+3)&3) ) ) {
if (verbose)
std::cerr << " pb orientation with neighbor "
<< i << std::endl;
CGAL_triangulation_assertion(false);
return false;
}
}
if ( j1n == ((in+3)&3) ) {
if ( ( j2n != ((in+2)&3) ) || ( j3n != ((in+1)&3) ) ) {
if (verbose)
std::cerr << " pb orientation with neighbor "
<< i << std::endl;
CGAL_triangulation_assertion(false);
return false;
}
}
}
else { // i and in do not have the same parity
if ( j1n == ((in+1)&3) ) {
if ( ( j2n != ((in+2)&3) ) || ( j3n != ((in+3)&3) ) ) {
if (verbose)
std::cerr << " pb orientation with neighbor "
<< i << std::endl;
CGAL_triangulation_assertion(false);
return false;
}
}
if ( j1n == ((in+2)&3) ) {
if ( ( j2n != ((in+3)&3) ) || ( j3n != ((in+1)&3) ) ) {
if (verbose)
std::cerr << " pb orientation with neighbor "
<< i << std::endl;
CGAL_triangulation_assertion(false);
return false;
}
}
if ( j1n == ((in+3)&3) ) {
if ( ( j2n != ((in+1)&3) ) || ( j3n != ((in+2)&3) ) ) {
if (verbose)
std::cerr << " pb orientation with neighbor "
<< i << std::endl;
CGAL_triangulation_assertion(false);
return false;
}
}
}
} // end looking at neighbors
}// end case dim 3
} // end switch
return true;
}
template <class Vb, class Cb >
typename Triangulation_data_structure_3<Vb,Cb>::Vertex_handle
Triangulation_data_structure_3<Vb,Cb>::
copy_tds(const Tds & tds, Vertex_handle vert )
// returns the new vertex corresponding to vert in the new tds
{
CGAL_triangulation_expensive_precondition( vert == Vertex_handle()
|| tds.is_vertex(vert) );
clear();
int n = tds.number_of_vertices();
set_dimension(tds.dimension());
// Number of pointers to cell/vertex to copy per cell.
int dim = std::max(1, dimension() + 1);
if (n == 0)
return vert;
// Create the vertices.
std::vector<Vertex_handle> TV(n);
int i = 0;
for (Vertex_iterator vit = tds.vertices_begin();
vit != tds.vertices_end(); ++vit)
TV[i++] = vit;
CGAL_triangulation_assertion( i == n );
std::map< Vertex_handle, Vertex_handle > V;
std::map< Cell_handle, Cell_handle > F;
for (i=0; i <= n-1; ++i)
V[ TV[i] ] = create_vertex(TV[i]);
// Create the cells.
for (Cell_iterator cit = tds.cell_container().begin();
cit != tds.cells_end(); ++cit) {
F[cit] = create_cell(cit);
for (int j = 0; j < dim; j++)
F[cit]->set_vertex(j, V[cit->vertex(j)] );
}
// Link the vertices to a cell.
for (Vertex_iterator vit2 = tds.vertices_begin();
vit2 != tds.vertices_end(); ++vit2)
V[vit2]->set_cell( F[vit2->cell()] );
// Hook neighbor pointers of the cells.
for (Cell_iterator cit2 = tds.cell_container().begin();
cit2 != tds.cells_end(); ++cit2) {
for (int j = 0; j < dim; j++)
F[cit2]->set_neighbor(j, F[cit2->neighbor(j)] );
}
CGAL_triangulation_postcondition( is_valid() );
return (vert != Vertex_handle()) ? V[vert] : vert;
}
template <class Vb, class Cb >
void
Triangulation_data_structure_3<Vb,Cb>::
swap(Tds & tds)
{
CGAL_triangulation_expensive_precondition(tds.is_valid() && is_valid());
std::swap(_dimension, tds._dimension);
cell_container().swap(tds.cell_container());
vertex_container().swap(tds.vertex_container());
}
template <class Vb, class Cb >
void
Triangulation_data_structure_3<Vb,Cb>::
clear()
{
cell_container().clear();
vertex_container().clear();
set_dimension(-2);
}
template <class Vb, class Cb >
bool
Triangulation_data_structure_3<Vb,Cb>::
count_vertices(size_type & i, bool verbose, int level) const
// counts AND checks the validity
{
i = 0;
for (Vertex_iterator it = vertices_begin(); it != vertices_end(); ++it) {
if ( ! is_valid(it,verbose,level) ) {
if (verbose)
std::cerr << "invalid vertex" << std::endl;
CGAL_triangulation_assertion(false);
return false;
}
++i;
}
return true;
}
template <class Vb, class Cb >
bool
Triangulation_data_structure_3<Vb,Cb>::
count_facets(size_type & i, bool verbose, int level) const
// counts but does not check
{
i = 0;
for (Facet_iterator it = facets_begin(); it != facets_end(); ++it) {
if ( ! is_valid((*it).first,verbose, level) ) {
if (verbose)
std::cerr << "invalid facet" << std::endl;
CGAL_triangulation_assertion(false);
return false;
}
++i;
}
return true;
}
template <class Vb, class Cb >
bool
Triangulation_data_structure_3<Vb,Cb>::
count_edges(size_type & i, bool verbose, int level) const
// counts but does not check
{
i = 0;
for (Edge_iterator it = edges_begin(); it != edges_end(); ++it) {
if ( ! is_valid((*it).first,verbose, level) ) {
if (verbose)
std::cerr << "invalid edge" << std::endl;
CGAL_triangulation_assertion(false);
return false;
}
++i;
}
return true;
}
template <class Vb, class Cb >
bool
Triangulation_data_structure_3<Vb,Cb>::
count_cells(size_type & i, bool verbose, int level) const
// counts AND checks the validity
{
i = 0;
for (Cell_iterator it = cells_begin(); it != cells_end(); ++it) {
if ( ! is_valid(it,verbose, level) ) {
if (verbose)
std::cerr << "invalid cell" << std::endl;
CGAL_triangulation_assertion(false);
return false;
}
++i;
}
return true;
}
CGAL_END_NAMESPACE
#endif // CGAL_TRIANGULATION_DATA_STRUCTURE_3_H
|