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 2976 2977 2978 2979 2980 2981 2982 2983 2984 2985 2986 2987 2988 2989 2990 2991 2992 2993 2994 2995 2996 2997 2998 2999 3000 3001 3002 3003 3004 3005 3006 3007 3008 3009 3010 3011 3012 3013 3014 3015 3016 3017 3018 3019 3020 3021 3022 3023 3024 3025 3026 3027 3028 3029 3030 3031 3032 3033 3034 3035 3036 3037 3038 3039 3040 3041 3042 3043 3044 3045 3046 3047 3048 3049 3050 3051 3052 3053 3054 3055 3056 3057 3058 3059 3060 3061 3062 3063 3064 3065 3066 3067 3068 3069 3070 3071 3072 3073 3074 3075 3076 3077 3078 3079 3080 3081 3082 3083 3084 3085 3086 3087 3088 3089 3090 3091 3092 3093 3094 3095 3096 3097 3098 3099 3100 3101 3102 3103 3104 3105 3106 3107 3108 3109 3110 3111 3112 3113 3114 3115 3116 3117 3118 3119 3120 3121 3122 3123 3124 3125 3126 3127 3128 3129 3130 3131 3132 3133 3134 3135 3136 3137 3138 3139 3140 3141 3142 3143 3144 3145 3146 3147 3148 3149 3150 3151 3152 3153 3154 3155 3156 3157 3158 3159 3160 3161 3162 3163 3164 3165 3166 3167 3168 3169 3170 3171 3172 3173 3174 3175 3176 3177 3178 3179 3180 3181 3182 3183 3184 3185 3186 3187 3188 3189 3190 3191 3192 3193 3194 3195 3196 3197 3198 3199 3200 3201 3202 3203 3204 3205 3206 3207 3208 3209 3210 3211 3212 3213 3214 3215 3216 3217 3218 3219 3220 3221 3222 3223 3224 3225 3226 3227 3228 3229 3230 3231 3232 3233 3234 3235 3236 3237 3238 3239 3240 3241 3242 3243 3244 3245 3246 3247 3248 3249 3250 3251 3252 3253 3254 3255 3256 3257 3258 3259 3260 3261 3262 3263 3264 3265 3266 3267 3268 3269 3270 3271 3272 3273 3274 3275 3276 3277 3278 3279 3280 3281 3282 3283 3284 3285 3286 3287 3288 3289 3290 3291 3292 3293 3294 3295 3296 3297 3298 3299 3300 3301 3302 3303 3304 3305 3306 3307 3308 3309 3310 3311 3312 3313 3314 3315 3316 3317 3318 3319 3320 3321 3322 3323 3324 3325 3326 3327 3328 3329 3330 3331 3332 3333 3334 3335 3336 3337 3338 3339 3340 3341 3342 3343 3344 3345 3346 3347 3348 3349 3350 3351 3352 3353 3354 3355 3356 3357 3358 3359 3360 3361 3362 3363 3364 3365 3366 3367 3368 3369 3370 3371 3372 3373 3374 3375 3376 3377 3378 3379 3380 3381 3382 3383 3384 3385 3386 3387 3388 3389 3390 3391 3392 3393 3394 3395 3396 3397 3398 3399 3400 3401 3402 3403 3404 3405 3406 3407 3408 3409 3410 3411
|
/**
* @file thdb1d.cxx
*/
/* Copyright (C) 2004 Stacho Mudrak
*
* $Date: $
* $RCSfile: $
* $Revision: $
*
* --------------------------------------------------------------------
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
* --------------------------------------------------------------------
*/
#include "thdb1d.h"
#include "thsurvey.h"
#include "thobjectname.h"
#include <stdlib.h>
#include "thsvxctrl.h"
#include "thdataobject.h"
#include "thdatabase.h"
#include "thdataleg.h"
#include "thexception.h"
#include "thdata.h"
#include "thinfnan.h"
#include <math.h>
#include <set>
#include "thpoint.h"
#include "thlogfile.h"
#include "thsurface.h"
#include "thlocale.h"
#include "thinit.h"
#include "thconfig.h"
#include "thtrans.h"
#include "loch/lxMath.h"
#include "thcs.h"
#include "extern/quickhull/QuickHull.hpp"
#ifdef THMSVC
#define hypot _hypot
#endif
//#define THUSESVX
//#define THDEBUG
thdb1d::thdb1d()
{
this->db = NULL;
this->tree_legs = NULL;
this->num_tree_legs = 0;
this->lsid = 0;
this->nlength = 0.0;
this->tree_arrows = NULL;
this->tree_nodes = NULL;
this->min_year = thnan;
this->max_year = thnan;
this->d3_data_parsed = false;
}
void thdb1ds::export_mp_flags(FILE * out)
{
fprintf(out, "ATTR__stationflag_splay := %s;\n", (this->is_temporary() ? "true" : "false"));
}
void thdb1ds::set_temporary(const char * name)
{
temps = TT_TEMPSTATION_NONE;
if (name != NULL) {
switch (name[0]) {
case '.':
temps = TT_TEMPSTATION_FEATURE;
break;
case '-':
temps = TT_TEMPSTATION_WALL;
break;
}
}
}
thdb1d::~thdb1d()
{
delete [] this->tree_legs;
delete [] this->tree_arrows;
delete [] this->tree_nodes;
}
void thdb1d::assigndb(thdatabase * dbptr)
{
this->db = dbptr;
}
void thdb1d::scan_data()
{
thdb_object_list_type::iterator obi = this->db->object_list.begin();
thdataleg_list::iterator lei;
thdatafix_list::iterator fii;
thdatamark_list::iterator mii;
thdatass_list::iterator ssi;
thdataextend_list::iterator xi;
thdataequate_list::iterator eqi;
thstdims_list::iterator di;
double meridian_convergence = thcfg.get_outcs_convergence(), declin, leggridmc, lastleggridmc(0.0);
int lastleggridmccs = TTCS_LOCAL;
thdata * dp;
unsigned used_declination = 0;
unsigned long prevlsid;
double dcc, sindecl, cosdecl, tmpx, tmpy;
thdb1ds * tsp1, * tsp2; // Temporary stations.
this->min_year = thnan;
this->max_year = thnan;
obi = this->db->object_list.begin();
while (obi != this->db->object_list.end()) {
if ((*obi)->get_class_id() == TT_DATA_CMD) {
dp = (thdata *)(*obi);
if (dp->date.is_defined()) {
double syear, eyear;
syear = dp->date.get_start_year();
eyear = syear;
if (dp->date.is_interval())
eyear = dp->date.get_end_year();
if (thisnan(this->min_year)) {
this->min_year = syear;
this->max_year = eyear;
} else {
if (this->min_year > syear) this->min_year = syear;
if (this->max_year < eyear) this->max_year = eyear;
}
}
bool dpdeclindef;
double dpdeclin;
dpdeclin = 0.0;
dpdeclindef = false;
if (dp->date.is_defined() && (thcfg.get_outcs_mag_decl(dp->date.get_average_year(), dpdeclin)))
dpdeclindef = true;
// scan data shots
lei = dp->leg_list.begin();
try {
while(lei != dp->leg_list.end()) {
if (lei->is_valid) {
// thdataleg * lf = &(*lei);
lei->from.id = this->insert_station(lei->from, lei->psurvey, dp, 3);
lei->to.id = this->insert_station(lei->to, lei->psurvey, dp, 3);
if (((strcmp(lei->from.name,".") == 0) || (strcmp(lei->from.name,"-") == 0)) && ((strcmp(lei->to.name,".") == 0) || (strcmp(lei->to.name,"-") == 0)))
ththrow(("shot between stations without names not allowed"))
if ((strcmp(lei->from.name,"-") == 0) || (strcmp(lei->to.name,"-") == 0) || (strcmp(lei->from.name,".") == 0) || (strcmp(lei->to.name,".") == 0)) {
lei->flags |= TT_LEGFLAG_SPLAY;
lei->walls = TT_FALSE;
}
this->leg_vec.push_back(thdb1dl(&(*lei),dp,lei->psurvey));
// check station marks
tsp1 = &(this->station_vec[lei->from.id - 1]);
tsp2 = &(this->station_vec[lei->to.id - 1]);
if (lei->s_mark > (unsigned int)tsp1->mark)
tsp1->mark = lei->s_mark;
if (lei->s_mark > (unsigned int)tsp2->mark)
tsp2->mark = lei->s_mark;
// set underground station flag
if ((lei->flags & TT_LEGFLAG_SURFACE) == 0) {
tsp1->flags |= TT_STATIONFLAG_UNDERGROUND;
tsp2->flags |= TT_STATIONFLAG_UNDERGROUND;
}
// check the length
if ((lei->data_type == TT_DATATYPE_NORMAL) ||
(lei->data_type == TT_DATATYPE_DIVING) ||
(lei->data_type == TT_DATATYPE_CYLPOLAR)) {
if (thisnan(lei->length) && (!thisnan(lei->tocounter)) &&
(!thisnan(lei->fromcounter))) {
lei->length = lei->tocounter - lei->fromcounter;
lei->length_sd = lei->counter_sd;
}
}
// check depth change
if (lei->data_type == TT_DATATYPE_DIVING) {
if (!thisnan(lei->depthchange))
dcc = lei->depthchange;
else
dcc = lei->todepth - lei->fromdepth;
lei->depthchange = dcc;
if (fabs(dcc) > lei->length)
ththrow(("length reading is less than change in depth"))
}
// check backwards compass reading
if ((lei->data_type == TT_DATATYPE_NORMAL) ||
(lei->data_type == TT_DATATYPE_DIVING) ||
(lei->data_type == TT_DATATYPE_CYLPOLAR)) {
if (!thisnan(lei->backbearing)) {
if (thisnan(lei->bearing)) {
lei->backbearing -= 180.0;
if (lei->backbearing < 0)
lei->backbearing += 360.0;
lei->bearing = lei->backbearing;
}
else {
lei->backbearing -= 180.0;
if (lei->backbearing < 0)
lei->backbearing += 360.0;
// calculate average of two angles
//lei->bearing += lei->backbearing;
//lei->bearing = lei->bearing / 2.0;
double sumx, sumy;
sumx = cos((90.0 - lei->bearing)/180.0*THPI) + cos((90.0 - lei->backbearing)/180.0*THPI);
sumy = sin((90.0 - lei->bearing)/180.0*THPI) + sin((90.0 - lei->backbearing)/180.0*THPI);
lei->bearing = 90.0 - (atan2(sumy, sumx) / THPI * 180.0);
if (lei->bearing < 0.0)
lei->bearing += 360.0;
}
}
}
// check backwards gradient reading
if (lei->data_type == TT_DATATYPE_NORMAL) {
if (!thisnan(lei->backgradient)) {
if (thisnan(lei->gradient)) {
lei->backgradient = - lei->backgradient;
lei->gradient = lei->backgradient;
}
else {
if ((thisinf(lei->gradient) == 0) &&
(thisinf(lei->backgradient) == 0)) {
lei->backgradient = - lei->backgradient;
lei->gradient += lei->backgradient;
lei->gradient = lei->gradient / 2.0;
}
else {
if (thisinf(lei->gradient) != -thisinf(lei->backgradient))
ththrow(("invalid plumbed shot"))
}
}
}
}
// calculate leg total length and std
switch (lei->data_type) {
case TT_DATATYPE_NORMAL:
lei->total_length = lei->length;
lei->total_bearing = (thisnan(lei->bearing) ? 0.0 : lei->bearing);
if (!lei->direction) {
lei->total_bearing += 180.0;
if (lei->total_bearing >= 360.0)
lei->total_bearing -= 360.0;
}
lei->total_gradient = (thisinf(lei->gradient) == 1 ? 90.0
: (thisinf(lei->gradient) == -1 ? -90.0
: lei->gradient));
if (!lei->direction)
lei->total_gradient *= -1.0;
lei->total_dz = lei->total_length * cos(lei->total_gradient/180*THPI);
lei->total_dx = lei->total_dz * sin(lei->total_bearing/180*THPI);
lei->total_dy = lei->total_dz * cos(lei->total_bearing/180*THPI);
lei->total_dz = lei->total_length * sin(lei->total_gradient/180*THPI);
lei->plumbed = (thisinf(lei->gradient) != 0);
if (lei->infer_plumbs && (!lei->plumbed)) {
lei->plumbed = (lei->gradient == -90.0) || (lei->gradient == 90.0);
}
break;
case TT_DATATYPE_DIVING:
lei->total_length = lei->length;
lei->total_bearing = (thisnan(lei->bearing) ? 0.0 : lei->bearing);
if (!lei->direction) {
lei->total_bearing += 180.0;
if (lei->total_bearing >= 360.0)
lei->total_bearing -= 360.0;
}
lei->total_gradient = asin(lei->depthchange / lei->length) / THPI * 180.0;
if (!lei->direction)
lei->total_gradient *= -1.0;
lei->total_dz = lei->total_length * cos(lei->total_gradient/180*THPI);
lei->total_dx = lei->total_dz * sin(lei->total_bearing/180*THPI);
lei->total_dy = lei->total_dz * cos(lei->total_bearing/180*THPI);
lei->total_dz = lei->total_length * sin(lei->total_gradient/180*THPI);
if (lei->infer_plumbs && (!lei->plumbed)) {
lei->plumbed = (lei->depthchange == lei->length) && (lei->depthchange != 0.0);
}
break;
case TT_DATATYPE_CYLPOLAR:
lei->total_length = sqrt(thnanpow2(lei->length) + thnanpow2(lei->depthchange));
lei->total_bearing = (thisnan(lei->bearing) ? 0.0 : lei->bearing);
if (!lei->direction) {
lei->total_bearing += 180.0;
if (lei->total_bearing >= 360.0)
lei->total_bearing -= 360.0;
}
lei->total_gradient = atan2(lei->depthchange, lei->length) / THPI * 180.0;
if (!lei->direction)
lei->total_gradient *= -1.0;
lei->total_dz = lei->total_length * cos(lei->total_gradient/180*THPI);
lei->total_dx = lei->total_dz * sin(lei->total_bearing/180*THPI);
lei->total_dy = lei->total_dz * cos(lei->total_bearing/180*THPI);
lei->total_dz = lei->total_length * sin(lei->total_gradient/180*THPI);
if (lei->infer_plumbs && (!lei->plumbed)) {
lei->plumbed = (lei->length == 0.0) && (lei->depthchange != 0.0);
}
break;
case TT_DATATYPE_CARTESIAN:
lei->total_dx = (lei->direction ? 1.0 : -1.0) * lei->dx;
lei->total_dy = (lei->direction ? 1.0 : -1.0) * lei->dy;
lei->total_dz = (lei->direction ? 1.0 : -1.0) * lei->dz;
lei->total_length = thdxyz2length(lei->total_dx,lei->total_dy,lei->total_dz);
lei->total_bearing = thdxyz2bearing(lei->total_dx,lei->total_dy,lei->total_dz);
lei->total_gradient = thdxyz2clino(lei->total_dx,lei->total_dy,lei->total_dz);
if (lei->infer_plumbs && (!lei->plumbed)) {
lei->plumbed = (lei->dx == 0.0) && (lei->dy == 0.0) && (lei->dz != 0.0);
}
break;
}
leggridmc = 0.0;
if (lei->gridcs != TTCS_LOCAL) {
if (lei->gridcs != lastleggridmccs) {
if (lei->gridcs == thcfg.outcs) {
lastleggridmc = meridian_convergence;
} else {
lastleggridmc = thcfg.get_cs_convergence(lei->gridcs);
}
lastleggridmccs = lei->gridcs;
}
leggridmc = lastleggridmc;
}
if ((leggridmc != 0.0) || (meridian_convergence != 0.0) || (!thisnan(lei->declination)) || dpdeclindef) {
declin = meridian_convergence - leggridmc;
if (!thisnan(lei->declination)) {
declin += lei->declination;
used_declination |= 2;
} else if (dpdeclindef) {
lei->implicit_declination = dpdeclin;
declin += dpdeclin;
used_declination |= 4;
} else {
used_declination |= 1;
}
lei->total_bearing += declin;
if (lei->total_bearing >= 360.0)
lei->total_bearing -= 360.0;
if (lei->total_bearing < 0.0)
lei->total_bearing += 360.0;
cosdecl = cos(declin/180*THPI);
sindecl = sin(declin/180*THPI);
tmpx = lei->total_dx;
tmpy = lei->total_dy;
lei->total_dx = (cosdecl * tmpx) + (sindecl * tmpy);
lei->total_dy = (cosdecl * tmpy) - (sindecl * tmpx);
}
lei->adj_dx = lei->total_dx;
lei->adj_dy = lei->total_dy;
lei->adj_dz = lei->total_dz;
lei->calc_total_stds();
}
lei++;
}
}
catch (...)
threthrow(("%s [%d]", lei->srcf.name, lei->srcf.line));
// scan data fixes
fii = dp->fix_list.begin();
thdb1ds * tmps;
unsigned olevel, nlevel;
try {
while(fii != dp->fix_list.end()) {
fii->station.id = this->insert_station(fii->station, fii->psurvey, dp, 2);
tmps = &(this->station_vec[fii->station.id - 1]);
tmps->flags |= TT_STATIONFLAG_FIXED;
if (fii->srcf.context != NULL) {
if (tmps->fixcontext != NULL) {
if (tmps->fixcontext->fsptr == NULL)
olevel = 0;
else
olevel = tmps->fixcontext->fsptr->level;
if (fii->srcf.context->fsptr == NULL)
nlevel = 0;
else
nlevel = fii->srcf.context->fsptr->level;
if (nlevel <= olevel) {
tmps->fixcontext = fii->srcf.context;
}
} else {
tmps->fixcontext = fii->srcf.context;
}
}
fii++;
}
}
catch (...)
threthrow(("%s [%d]", fii->srcf.name, fii->srcf.line));
}
obi++;
}
// process equates separately
obi = this->db->object_list.begin();
while (obi != this->db->object_list.end()) {
if ((*obi)->get_class_id() == TT_DATA_CMD) {
dp = (thdata *)(*obi);
// scan data equates
eqi = dp->equate_list.begin();
try {
while(eqi != dp->equate_list.end()) {
prevlsid = this->lsid;
eqi->station.id = this->insert_station(eqi->station, eqi->psurvey, dp, 1);
if ((prevlsid < eqi->station.id) && (eqi->station.survey != NULL))
thwarning(("%s [%d] -- equate used to define new station (%s@%s)", eqi->srcf.name, eqi->srcf.line, eqi->station.name, eqi->station.survey));
eqi++;
}
}
catch (...)
threthrow(("%s [%d]", eqi->srcf.name, eqi->srcf.line));
}
obi++;
}
// after scanning
obi = this->db->object_list.begin();
while (obi != this->db->object_list.end()) {
if ((*obi)->get_class_id() == TT_SURVEY_CMD) {
thsurvey * srv = (thsurvey *) (*obi);
if (!srv->entrance.is_empty()) {
srv->entrance.id = this->get_station_id(srv->entrance, srv);
if (srv->entrance.id == 0) {
if (srv->entrance.survey == NULL)
ththrow(("station doesn't exist -- %s", srv->entrance.name))
else
ththrow(("station doesn't exist -- %s@%s", srv->entrance.name, srv->entrance.survey))
}
// set entrance flag & comment to given station
this->station_vec[srv->entrance.id-1].flags |= TT_STATIONFLAG_ENTRANCE;
if (strlen(srv->title) > 0)
this->station_vec[srv->entrance.id-1].comment = srv->title;
else
this->station_vec[srv->entrance.id-1].comment = srv->name;
}
}
if ((*obi)->get_class_id() == TT_DATA_CMD) {
dp = (thdata *)(*obi);
// scan data stations
ssi = dp->ss_list.begin();
try {
while(ssi != dp->ss_list.end()) {
ssi->station.id = this->get_station_id(ssi->station, ssi->psurvey);
if (ssi->station.id == 0) {
if (ssi->station.survey == NULL)
ththrow(("station doesn't exist -- %s", ssi->station.name))
else
ththrow(("station doesn't exist -- %s@%s", ssi->station.name, ssi->station.survey))
}
// set station flags and comment
else {
if (ssi->comment != NULL)
this->station_vec[ssi->station.id-1].comment = ssi->comment;
this->station_vec[ssi->station.id-1].explored = ssi->explored;
this->station_vec[ssi->station.id-1].flags |= ssi->flags;
// set station attributes
this->m_station_attr.insert_object(NULL, (long) ssi->station.id);
thdatass_attr_map::iterator ami;
for(ami = ssi->attr.begin(); ami != ssi->attr.end(); ami++) {
this->m_station_attr.insert_attribute(ami->first.c_str(), ami->second);
}
}
ssi++;
}
}
catch (...)
threthrow(("%s [%d]", ssi->srcf.name, ssi->srcf.line));
// scan data marks
mii = dp->mark_list.begin();
try {
while(mii != dp->mark_list.end()) {
mii->station.id = this->get_station_id(mii->station, mii->psurvey);
if (mii->station.id == 0) {
if (mii->station.survey == NULL)
ththrow(("station doesn't exist -- %s", mii->station.name))
else
ththrow(("station doesn't exist -- %s@%s", mii->station.name, mii->station.survey))
}
// set station flags and comment
else {
thdb1ds * markst = &(this->station_vec[mii->station.id - 1]);
markst->mark_station = true;
if (markst->mark < mii->mark)
markst->mark = mii->mark;
}
mii++;
}
}
catch (...)
threthrow(("%s [%d]", mii->srcf.name, mii->srcf.line));
// scan extends
xi = dp->extend_list.begin();
try {
while(xi != dp->extend_list.end()) {
if (!xi->to.is_empty()) {
xi->to.id = this->get_station_id(xi->to, xi->psurvey);
if (xi->to.id == 0) {
if (xi->to.survey == NULL)
ththrow(("station doesn't exist -- %s", xi->to.name))
else
ththrow(("station doesn't exist -- %s@%s", xi->to.name, xi->to.survey))
}
}
xi->from.id = this->get_station_id(xi->from, xi->psurvey);
if (xi->from.id == 0) {
if (xi->from.survey == NULL)
ththrow(("station doesn't exist -- %s", xi->from.name))
else
ththrow(("station doesn't exist -- %s@%s", xi->from.name, xi->from.survey))
}
xi++;
}
}
catch (...)
threthrow(("%s [%d]", xi->srcf.name, xi->srcf.line));
// scan dimensions
di = dp->dims_list.begin();
try {
while(di != dp->dims_list.end()) {
di->station.id = this->get_station_id(di->station, di->psurvey);
if (di->station.id == 0) {
if (di->station.survey == NULL)
ththrow(("station doesn't exist -- %s", di->station.name))
else
ththrow(("station doesn't exist -- %s@%s", di->station.name, di->station.survey))
}
di++;
}
}
catch (...)
threthrow(("%s [%d]", di->srcf.name, di->srcf.line));
dp->complete_dimensions();
}
obi++;
}
if (((used_declination & 1) != 0) && ((used_declination & 4) != 0))
thwarning(("unable to determine magnetic declination for undated surveys"))
thcfg.log_outcs(this->min_year, this->max_year);
}
void thdb1d::process_data()
{
this->scan_data();
this->find_loops();
this->close_loops();
if (thini.loopc == THINIT_LOOPC_SURVEX) {
thsvxctrl survex;
try {
survex.process_survey_data(this->db);
} catch (...) {
thwarning((thexc.get_desc()))
}
}
this->process_survey_stat();
this->postprocess_objects();
this->process_xelev();
}
unsigned long thdb1d::get_station_id(thobjectname on, thsurvey * ps)
{
unsigned long csurvey_id = this->db->get_survey_id(on.survey, ps);
thdb1d_station_map_type::iterator sti;
sti = this->station_map.find(thobjectid(on.name, csurvey_id));
if (sti == this->station_map.end())
return 0;
else
return sti->second;
}
void thdb1ds::set_parent_data(class thdata * pd, unsigned pd_priority) {
if (pd_priority > this->data_priority) {
this->data.clear();
this->data_priority = pd_priority;
}
if (pd_priority == this->data_priority)
this->data.push_back(pd);
}
unsigned long thdb1d::insert_station(class thobjectname on, class thsurvey * ps, class thdata * pd, unsigned pd_priority)
{
bool is_temp = false;
if ((strcmp(on.name,"-") == 0) || (strcmp(on.name,".") == 0)) {
is_temp = true;
}
// first insert object into database
ps = this->db->get_survey(on.survey, ps);
unsigned long csurvey_id = (ps == NULL) ? 0 : ps->id;
on.survey = NULL;
if (!is_temp) {
thdb1d_station_map_type::iterator sti;
sti = this->station_map.find(thobjectid(on.name, csurvey_id));
if (sti != this->station_map.end()) {
this->station_vec[sti->second - 1].set_parent_data(pd,pd_priority);
return sti->second;
}
if (!(this->db->insert_datastation(on, ps))) {
if (on.survey != NULL)
ththrow(("object already exist -- %s@%s", on.name, on.survey))
else
ththrow(("object already exist -- %s", on.name))
}
}
this->lsid++;
this->station_vec.push_back(thdb1ds(on.name, ps));
thdb1ds * cstation = &(this->station_vec[this->lsid - 1]);
if (!is_temp) {
this->station_map[thobjectid(on.name, csurvey_id)] = this->lsid;
} else {
cstation->set_temporary(on.name);
}
cstation->set_parent_data(pd,pd_priority);
return this->lsid;
}
void thdb1d::self_print(FILE * outf)
{
unsigned int sid;
fprintf(outf,"survey stations\n");
thdb1ds * sp;
for (sid = 0; sid < this->lsid; sid++) {
sp = & (this->station_vec[sid]);
fprintf(outf,"\t%d:%ld\t%s@%s\t%.2f\t%.2f\t%.2f", sid + 1, sp->uid, sp->name,
sp->survey->full_name, sp->x, sp->y, sp->z);
fprintf(outf,"\tflags:");
if (sp->flags & TT_STATIONFLAG_ENTRANCE)
fprintf(outf,"E");
if (sp->flags & TT_STATIONFLAG_CONT)
fprintf(outf,"C");
if (sp->flags & TT_STATIONFLAG_FIXED)
fprintf(outf,"F");
if (sp->flags & TT_STATIONFLAG_UNDERGROUND)
fprintf(outf,"U");
fprintf(outf,"\tmark:");
switch (sp->mark) {
case TT_DATAMARK_FIXED:
fprintf(outf,"fixed");
break;
case TT_DATAMARK_PAINTED:
fprintf(outf,"painted");
break;
case TT_DATAMARK_TEMP:
fprintf(outf,"temporary");
break;
case TT_DATAMARK_NATURAL:
fprintf(outf,"natural");
break;
}
if (sp->comment != NULL)
fprintf(outf,"\t\"%s\"", sp->comment);
fprintf(outf,"\n");
}
fprintf(outf,"end -- survey stations\n");
}
unsigned long thdb1d::get_tree_size()
{
if (this->tree_legs == NULL)
this->process_tree();
return this->num_tree_legs;
}
thdb1dl ** thdb1d::get_tree_legs()
{
if (this->tree_legs == NULL)
this->process_tree();
return this->tree_legs;
}
void thdb1d_equate_nodes(thdb1d * thisdb, thdb1d_tree_node * n1, thdb1d_tree_node * n2)
{
if (n1->uid == n2->uid)
return;
thdb1d_tree_node * n3;
if (n1->is_fixed && n2->is_fixed) {
ththrow(("equate of two fixed stations -- %s@%s and %s@%s",
thisdb->station_vec[n1->id - 1].name,
thisdb->station_vec[n1->id - 1].survey->get_full_name(),
thisdb->station_vec[n2->id - 1].name,
thisdb->station_vec[n2->id - 1].survey->get_full_name()));
}
if (n1->id == n2->id) {
ththrow(("equate of two identical stations -- %s@%s and %s@%s",
thisdb->station_vec[n1->id - 1].name,
thisdb->station_vec[n1->id - 1].survey->get_full_name(),
thisdb->station_vec[n2->id - 1].name,
thisdb->station_vec[n2->id - 1].survey->get_full_name()));
}
// vymeni ich ak uid1 nie je fixed
if ((n2->is_fixed) && (!n1->is_fixed)) {
n3 = n1;
n1 = n2;
n2 = n3;
}
// priradi uid1 do uid2
n2->uid = n1->uid;
n3 = n2->prev_eq;
while (n3 != NULL) {
n3->uid = n1->uid;
n3 = n3->prev_eq;
}
n3 = n2->next_eq;
while (n3 != NULL) {
n3->uid = n1->uid;
n3 = n3->next_eq;
}
// teraz spojme n1->prev s n2->next
while (n1->prev_eq != NULL) {
n1 = n1->prev_eq;
}
while (n2->next_eq != NULL) {
n2 = n2->next_eq;
}
n1->prev_eq = n2;
n2->next_eq = n1;
}
void thdb1d::process_tree()
{
size_t tn_legs = this->leg_vec.size();
size_t tn_stations = this->station_vec.size();
#ifdef THDEBUG
thprintf("\n\nscanning centreline tree\n");
#else
thprintf("scanning centreline tree ... ");
thtext_inline = true;
#endif
thdb1d_tree_node * nodes = new thdb1d_tree_node [tn_stations];
this->tree_nodes = nodes;
thdb1d_tree_arrow * arrows = new thdb1d_tree_arrow [2 * tn_legs];
this->tree_arrows = arrows;
thdb1d_tree_node * n1, * n2, * n3, * current_node = NULL;
thdb1d_tree_arrow * a1, * a2;
unsigned long i, ii;
bool any_fixed = false;
// let's parse all nodes
for(i = 0, ii = 1, n1 = nodes; i < tn_stations; i++, n1++, ii++) {
n1->id = ii;
n1->uid = ii;
n1->is_fixed = ((this->station_vec[i].flags & TT_STATIONFLAG_FIXED) != 0);
// if (n1->is_fixed)
// thprintf("FX: %s@%s\n", this->station_vec[i].name, this->station_vec[i].survey->full_name);
if (n1->is_fixed)
any_fixed = true;
}
// let's parse all equates
thdb_object_list_type::iterator obi = this->db->object_list.begin();
thdataequate_list::iterator eqi;
thdata * dp;
int last_eq = -1;
while (obi != this->db->object_list.end()) {
if ((*obi)->get_class_id() == TT_DATA_CMD) {
dp = (thdata *)(*obi);
eqi = dp->equate_list.begin();
last_eq = -1;
while(eqi != dp->equate_list.end()) {
if (eqi->eqid != last_eq) {
n1 = nodes + (eqi->station.id - 1);
last_eq = eqi->eqid;
}
else {
n2 = nodes + (eqi->station.id - 1);
thdb1d_equate_nodes(this,n1,n2);
}
eqi++;
}
}
obi++;
}
// now let's equate infer legs, zero lengthed
thdb1d_leg_vec_type::iterator iil;
for(iil = this->leg_vec.begin(); iil != this->leg_vec.end(); iil++) {
if (iil->leg->infer_equates) {
if (iil->leg->total_length == 0.0) {
thdb1d_equate_nodes(this, nodes + (iil->leg->from.id - 1),
nodes + (iil->leg->to.id - 1));
}
}
}
// write uid into original database
for(i = 0, n1 = nodes; i < tn_stations; i++, n1++) {
this->station_vec[i].uid = n1->uid;
}
// go leg by leg and fill arrows
for(iil = this->leg_vec.begin(), a1 = arrows; iil != this->leg_vec.end(); iil++) {
if (iil->leg->infer_equates)
if (iil->leg->total_length == 0.0)
continue;
a2 = a1 + 1;
a1->negative = a2;
a1->leg = &(*iil);
a1->start_node = nodes + (nodes[iil->leg->from.id - 1].uid - 1);
a1->end_node = nodes + (nodes[iil->leg->to.id - 1].uid - 1);
// if ((iil->leg->data_type == TT_DATATYPE_NOSURVEY) &&
// ((!a1->start_node->is_fixed) || (!a1->end_node->is_fixed))) {
//// thprintf("%s@%s - %s@%s\n", iil->leg->from.name, iil->leg->from.survey, iil->leg->to.name, iil->leg->to.survey);
// ththrow(("unsurveyed shot between unfixed stations -- %s [%d]",
// iil->leg->srcf.name, iil->leg->srcf.line
// ));
// }
if (iil->leg->data_type == TT_DATATYPE_NOSURVEY) {
a1->is_nosurvey = true;
a2->is_nosurvey = true;
}
// hide splay-ed flags from extended elevation2
//if ((iil->leg->flags && TT_LEGFLAG_SPLAY) != 0) {
// iil->leg->extend |= TT_EXTENDFLAG_HIDE;
// a2->extend |= TT_EXTENDFLAG_HIDE;
// a1->extend |= TT_EXTENDFLAG_HIDE;
//}
a2->negative = a1;
a2->leg = a1->leg;
a2->start_node = a1->end_node;
a2->end_node = a1->start_node;
a2->is_reversed = true;
// assign nodes
a1->next_arrow = a1->start_node->first_arrow;
a1->start_node->first_arrow = a1;
a2->next_arrow = a2->start_node->first_arrow;
a2->start_node->first_arrow = a2;
a1->start_node->narrows++;
a2->start_node->narrows++;
a1 += 2;
}
// process the tree
// 1. set all nodes without legs as attached
for(i = 0, n1 = nodes; i < tn_stations; i++, n1++) {
if (n1->id != n1->uid)
n1->is_attached = true;
else if ((n1->first_arrow == NULL) && (n1->is_fixed))
n1->is_attached = true;
}
unsigned long series = 0, component = 0, tarrows = 0, last_series = 0;
bool component_break = true;
this->tree_legs = new thdb1dl* [tn_legs];
thdb1dl ** current_leg = this->tree_legs;
while (tarrows < tn_legs) {
if (component_break) {
// let's find starting node
n2 = NULL;
n3 = NULL;
bool n2null = true;
for(i = 0, n1 = nodes; i < tn_stations; i++, n1++) {
if (!n1->is_attached) {
if (n2null) {
n2 = n1;
n3 = n1;
n2null = false;
}
if (n1->is_fixed) {
n2 = n1;
break;
}
}
}
// something is wrong
if (n2 == NULL) {
ththrow(("a software BUG is present (" __FILE__ ":%d)", __LINE__));
//#ifdef THDEBUG
// thprintf("warning -- not all stations connected to the network\n");
//#endif
break;
}
if ((!n2->is_fixed) && (any_fixed || (component > 0))) {
ththrow(("can not connect %s@%s to centerline network",
this->station_vec[n3->id - 1].name,
this->station_vec[n3->id - 1].survey->get_full_name()));
}
current_node = n2;
current_node->is_attached = true;
component++;
if (series == last_series)
series++;
component_break = false;
#ifdef THDEBUG
thprintf("component %d -- %d (%s@%s)\n", component, current_node->id,
this->station_vec[current_node->id - 1].name,
this->station_vec[current_node->id - 1].survey->get_full_name());
#endif
} // end of tremaux
// let's make move
if (current_node->last_arrow == NULL)
current_node->last_arrow = current_node->first_arrow;
else
current_node->last_arrow = current_node->last_arrow->next_arrow;
// skip discovery arrows or nosurvey arrows, if station on the other site is not connected
while ((current_node->last_arrow != NULL) && (
(current_node->last_arrow->is_discovery) ||
((current_node->last_arrow->is_nosurvey) &&
(!current_node->last_arrow->end_node->is_attached))
))
current_node->last_arrow = current_node->last_arrow->next_arrow;
if (current_node->last_arrow == NULL) {
// go back
if (current_node->back_arrow == NULL)
component_break = true;
else {
current_node = current_node->back_arrow->end_node;
#ifdef THDEBUG
thprintf("%d (%s@%s) <-\n", current_node->id,
this->station_vec[current_node->id - 1].name,
this->station_vec[current_node->id - 1].survey->get_full_name());
#endif
}
}
else {
// go forward
// check if not already discovered
current_node->last_arrow->negative->is_discovery = true;
tarrows++;
*current_leg = current_node->last_arrow->leg;
#ifdef THDEBUG
thdb1dl * prev_leg = *current_leg;
#endif
(*current_leg)->reverse = current_node->last_arrow->is_reversed;
(*current_leg)->series_id = series;
last_series = series;
(*current_leg)->component_id = component;
current_leg++;
#ifdef THDEBUG
thprintf("-> %d (%s@%s) [%d %s %d, series %d, arrow %d]\n", current_node->last_arrow->end_node->id,
this->station_vec[current_node->last_arrow->end_node->id - 1].name,
this->station_vec[current_node->last_arrow->end_node->id - 1].survey->get_full_name(),
prev_leg->leg->from.id,
(prev_leg->reverse ? "<=" : "=>"),
prev_leg->leg->to.id,
series, tarrows);
#endif
if (!current_node->last_arrow->end_node->is_attached) {
current_node->last_arrow->end_node->back_arrow =
current_node->last_arrow->negative;
current_node = current_node->last_arrow->end_node;
current_node->is_attached = true;
if (current_node->narrows != 2)
series++;
}
else
series++;
}
}
this->num_tree_legs = tarrows;
#ifdef THDEBUG
thprintf("\nend of scanning data tree\n\n");
#else
thprintf("done\n");
thtext_inline = false;
#endif
}
void thdb1d__scan_survey_station_limits(thsurvey * ss, thdb1ds * st, bool is_under) {
if (st->is_temporary()) return;
if (ss->stat.station_state == 0) {
if (is_under)
ss->stat.station_state = 2;
else
ss->stat.station_state = 1;
ss->stat.station_top = st;
ss->stat.station_bottom = st;
ss->stat.station_south = st;
ss->stat.station_north = st;
ss->stat.station_east = st;
ss->stat.station_west = st;
} else if (is_under && (ss->stat.station_state == 1)) {
ss->stat.station_state = 2;
ss->stat.station_top = st;
ss->stat.station_bottom = st;
ss->stat.station_south = st;
ss->stat.station_north = st;
ss->stat.station_east = st;
ss->stat.station_west = st;
} else if (is_under || (ss->stat.station_state == 1)) {
ss->stat.station_state = 2;
if (ss->stat.station_top->z < st->z)
ss->stat.station_top = st;
if (ss->stat.station_bottom->z > st->z)
ss->stat.station_bottom = st;
if (ss->stat.station_east->x < st->x)
ss->stat.station_east = st;
if (ss->stat.station_west->x > st->x)
ss->stat.station_west = st;
if (ss->stat.station_north->y < st->y)
ss->stat.station_north = st;
if (ss->stat.station_south->y > st->y)
ss->stat.station_south = st;
}
}
void thdb1d__scan_data_station_limits(thdata * ss, thdb1ds * st, bool is_under) {
if (ss->stat_st_state == 0) {
if (is_under)
ss->stat_st_state = 2;
else
ss->stat_st_state = 1;
ss->stat_st_top = st;
ss->stat_st_bottom = st;
// ss->stat_st_south = st;
// ss->stat_st_north = st;
// ss->stat_st_east = st;
// ss->stat_st_west = st;
} else if (is_under && (ss->stat_st_state == 1)) {
ss->stat_st_state = 2;
ss->stat_st_top = st;
ss->stat_st_bottom = st;
// ss->stat_st_south = st;
// ss->stat_st_north = st;
// ss->stat_st_east = st;
// ss->stat_st_west = st;
} else if (is_under || (ss->stat_st_state == 1)) {
ss->stat_st_state = 2;
if (ss->stat_st_top->z < st->z)
ss->stat_st_top = st;
if (ss->stat_st_bottom->z > st->z)
ss->stat_st_bottom = st;
// if (ss->stat_st_east->x < st->x)
// ss->stat_st_east = st;
// if (ss->stat_st_west->x > st->x)
// ss->stat_st_west = st;
// if (ss->stat_st_north->y < st->y)
// ss->stat_st_north = st;
// if (ss->stat_st_south->y > st->y)
// ss->stat_st_south = st;
}
}
void thdb1d::process_survey_stat() {
#ifdef THDEBUG
thprintf("\n\ncalculating basic statistics\n");
#else
thprintf("calculating basic statistics ... ");
thtext_inline = true;
#endif
thsurvey * ss;
// prejde vsetky legy a spocita ich a dlzky pre kazde survey
// do ktoreho patria
thdb1d_leg_vec_type::iterator lit = this->leg_vec.begin();
while (lit != this->leg_vec.end()) {
// skusi ci je duplikovane
if ((lit->leg->flags & TT_LEGFLAG_SPLAY) != 0)
lit->data->stat_splaylength += lit->leg->total_length;
else if ((lit->leg->flags & TT_LEGFLAG_DUPLICATE) != 0)
lit->data->stat_dlength += lit->leg->total_length;
// ak nie skusi ci je surface
else if ((lit->leg->flags & TT_LEGFLAG_SURFACE) != 0)
lit->data->stat_slength += lit->leg->total_length;
// inak prida do length
else {
lit->data->stat_length += lit->leg->total_length;
this->nlength += lit->leg->total_length;
// check if approximate length
if ((lit->leg->flags & TT_LEGFLAG_APPROXIMATE) != 0)
lit->data->stat_alength += lit->leg->total_length;
}
// stations
if ((lit->leg->flags & TT_LEGFLAG_SPLAY) == 0) {
if ((lit->leg->flags & TT_LEGFLAG_SURFACE) != 0) {
thdb1d__scan_data_station_limits(lit->data, &(this->station_vec[lit->leg->from.id - 1]), false);
thdb1d__scan_data_station_limits(lit->data, &(this->station_vec[lit->leg->to.id - 1]), false);
} else {
thdb1d__scan_data_station_limits(lit->data, &(this->station_vec[lit->leg->from.id - 1]), true);
thdb1d__scan_data_station_limits(lit->data, &(this->station_vec[lit->leg->to.id - 1]), true);
}
}
ss = lit->survey;
while (ss != NULL) {
// skusi ci nie je splay
if ((lit->leg->flags & TT_LEGFLAG_SPLAY) != 0)
ss->stat.length_splay += lit->leg->total_length;
// skusi ci je duplikovane
else if ((lit->leg->flags & TT_LEGFLAG_DUPLICATE) != 0)
ss->stat.length_duplicate += lit->leg->total_length;
// ak nie skusi ci je surface
else if ((lit->leg->flags & TT_LEGFLAG_SURFACE) != 0)
ss->stat.length_surface += lit->leg->total_length;
// inak prida do length
else {
if ((lit->leg->flags & TT_LEGFLAG_APPROXIMATE) != 0)
ss->stat.length_approx += lit->leg->total_length;
ss->stat.length += lit->leg->total_length;
}
if ((lit->leg->flags & TT_LEGFLAG_SPLAY) == 0) {
if ((lit->leg->flags & TT_LEGFLAG_SURFACE) != 0) {
thdb1d__scan_survey_station_limits(ss, &(this->station_vec[lit->leg->from.id - 1]), false);
thdb1d__scan_survey_station_limits(ss, &(this->station_vec[lit->leg->to.id - 1]), false);
} else {
thdb1d__scan_survey_station_limits(ss, &(this->station_vec[lit->leg->from.id - 1]), true);
thdb1d__scan_survey_station_limits(ss, &(this->station_vec[lit->leg->to.id - 1]), true);
}
}
ss->stat.num_shots++;
ss = ss->fsptr;
}
lit++;
}
// prejde vsetky stations a spocita ich a nastavi limitne stations
// pricom ak najde prvu povrchovu, tak nastvi vsetky s nou
// ak najde podzemnu a ma niekde povrchovu -> nastavi podzemnu
thdb1d_station_vec_type::iterator sit = this->station_vec.begin();
while (sit != this->station_vec.end()) {
ss = sit->survey;
while (ss != NULL) {
if (!thisnan(sit->explored))
ss->stat.length_explored += sit->explored;
if ((sit->flags & TT_STATIONFLAG_ENTRANCE) > 0) {
ss->stat.num_entrances++;
}
ss->stat.num_stations++;
ss = ss->fsptr;
}
sit++;
}
// prejde vsetky continuations a prepocita explore length
thdb_object_list_type::iterator obi = this->db->object_list.begin();
thpoint * pt;
while (obi != this->db->object_list.end()) {
if ((*obi)->get_class_id() == TT_POINT_CMD) {
pt = (thpoint *)(*obi);
ss = pt->fsptr;
if ((pt->type == TT_POINT_TYPE_CONTINUATION) && (!thisnan(pt->xsize))) {
while (ss != NULL) {
ss->stat.length_explored += pt->xsize;
ss = ss->fsptr;
}
}
}
obi++;
}
#ifdef THDEBUG
thprintf("\nend of basic statistics calculation\n\n");
#else
thprintf("done\n");
thtext_inline = false;
#endif
}
struct thlc_leg
{
unsigned long from_uid, to_uid, from_id, to_id;
thlc_leg * prev_series_leg, * next_series_leg;
thdb1dl * dbleg;
};
struct thlc_cross
{
unsigned long id, station_uid, narrows, dm_dist;
bool is_fixed, dm_target;
thlc_cross * dm_cross, * dm_next;
struct thlc_cross_arrow * first_arrow, * last_arrow, * dm_arrow;
};
struct thlc_series
{
unsigned long from, to, numlegs, id;
thlc_cross * from_cross, * to_cross;
thlc_leg * first_leg, * last_leg;
bool is_active;
};
struct thlc_cross_arrow
{
thlc_cross * target;
thlc_cross_arrow * prev_arrow, * next_arrow;
thlc_series * series;
bool reverse;
};
struct thlc_loop
{
thlc_cross * from_cross, * to_cross;
thlc_cross_arrow * first_arrow, * last_arrow;
unsigned long minid, size, id;
#ifdef THDEBUG
bool is_new;
long old_id;
#endif
};
bool operator < (
const struct thlc_loop & l1,
const struct thlc_loop & l2)
{
bool direction;
thlc_cross_arrow * l1a, * l2a;
if (l1.size < l2.size)
return true;
else if (l1.size > l2.size)
return false;
// neostava nam nic ine ako porovnavat po seriach
if (l1.from_cross->id != l1.to_cross->id) {
// l1 otovreny okruh
if (l2.from_cross->id == l2.to_cross->id)
return false;
if (l1.minid < l2.minid)
return true;
if (l1.minid > l2.minid)
return false;
if (l1.to_cross->id == l2.to_cross->id)
direction = true;
else
direction = false;
// porovname seriu za seriou, vratime false ak nebude mensia
l1a = l1.first_arrow;
l2a = (direction ? l2.first_arrow : l2.last_arrow);
while ((l1a != NULL) && (l2a != NULL)) {
if (l1a->series->id > l2a->series->id)
return false;
if (l1a->series->id < l2a->series->id)
return true;
l1a = l1a->next_arrow;
l2a = (direction ? l2a->next_arrow : l2a->prev_arrow);
if ((l1a == NULL) && (l2a != NULL))
return true;
if ((l1a != NULL) && (l2a == NULL))
return false;
}
//#ifdef THDEBUG
// thprintf("LOOP EQUAL: %ld == %ld\n", l1.id, l2.id);
//#endif
return false;
} else {
// l1 uzavrety okruh
if (l2.from_cross->id != l2.to_cross->id)
return true;
if (l1.minid < l2.minid)
return true;
if (l1.minid > l2.minid)
return false;
// v obidvoch najde minid hranu a na zaklade jej orientacie
// urci direction v dvojke
l1a = l1.first_arrow;
while (l1a->series->id != l1.minid) {
l1a = l1a->next_arrow;
}
l2a = l2.first_arrow;
while (l2a->series->id != l2.minid) {
l2a = l2a->next_arrow;
}
if (l1a->reverse != l2a->reverse)
direction = false;
else
direction = true;
#define nextstep {\
l1a = l1a->next_arrow; \
if (l1a == NULL) l1a = l1.first_arrow; \
l2a = (direction ? l2a->next_arrow : l2a->prev_arrow); \
if (l2a == NULL) l2a = (direction ? l2.first_arrow : l2.last_arrow); \
if ((l1a->series->id == l1.minid) && (l2a->series->id != l2.minid)) \
return true; \
if ((l1a->series->id != l1.minid) && (l2a->series->id == l2.minid)) \
return false; \
if (l1a->series->id < l2a->series->id) return true; \
if (l1a->series->id > l2a->series->id) return false; \
}
nextstep;
while (l1a->series->id != l1.minid) nextstep;
//#ifdef THDEBUG
// thprintf("LOOP EQUAL: %ld == %ld\n", l1.id, l2.id);
//#endif
return false;
}
}
long chledala_chledala(thlc_cross * kde, unsigned long kde_size, thlc_cross * co, thlc_cross * odkial, std::list<thlc_cross_arrow> & vysledok)
{
long result = -1;
unsigned long i;
thlc_cross * cc, * lastcc;
#ifdef THDEBUG
thprintf("\nLOOP SEARCH: %ld -> %ld\n", odkial->id, co == NULL ? -1 : long(co->id));
#endif
// initiaze targets
if (co == NULL) {
for (i = 0; i < kde_size; i++) {
cc = &(kde[i]);
cc->dm_target = cc->is_fixed;
}
} else {
for (i = 0; i < kde_size; i++)
kde[i].dm_target = false;
co->dm_target = true;
}
// reset other tree variables
for (i = 0; i < kde_size; i++) {
cc = &(kde[i]);
cc->dm_arrow = NULL;
cc->dm_dist = 0;
cc->dm_cross = NULL;
}
lastcc = odkial;
lastcc->dm_next = NULL;
cc = odkial;
// modified Djikstra-Moore algorithm
thlc_cross_arrow * ca;
thlc_cross * cmin_cross = NULL, * nc;
bool vykasli_sa;
unsigned long cmin = 0;
#define check_cmin(cross) {\
if (cross->dm_target) {\
if (cmin_cross == NULL) { \
cmin = cross->dm_dist; \
cmin_cross = cross; \
} else if (cmin > cross->dm_dist) {\
cmin = cross->dm_dist; \
cmin_cross = cross; \
} \
} \
}
while (cc != NULL) {
ca = cc->first_arrow;
while ((ca != NULL) && (!cc->dm_target)) {
if ((ca->series->is_active) && (ca->target->id != odkial->id)) {
if (ca->target->dm_cross != NULL) {
// sme vo vrchole, v ktorom sme uz boli, takze iba skontrolujeme,
// ci tam nie sme rychlejsie
if (ca->target->dm_dist > (cc->dm_dist + ca->series->numlegs)) {
ca->target->dm_arrow = ca;
ca->target->dm_cross = cc;
ca->target->dm_dist = cc->dm_dist + ca->series->numlegs;
check_cmin(ca->target);
}
} else {
// dostali sme sa do noveho vrcholu, nastavime mu co treba a
// pridame si ho do vrcholov na preskumanie
ca->target->dm_arrow = ca;
ca->target->dm_cross = cc;
ca->target->dm_dist = cc->dm_dist + ca->series->numlegs;
check_cmin(ca->target);
lastcc->dm_next = ca->target;
lastcc = lastcc->dm_next;
lastcc->dm_next = NULL;
}
}
ca = ca->next_arrow;
}
// skontroluje, ci ma zmysel este hladat
if (cmin_cross != NULL) {
nc = cc->dm_next;
vykasli_sa = true;
while (nc != NULL) {
vykasli_sa = vykasli_sa && (cmin <= nc->dm_dist);
nc = nc->dm_next;
}
if (vykasli_sa)
cc->dm_next = NULL;
}
cc = cc->dm_next;
}
if (cmin_cross != NULL) {
result = cmin;
cc = cmin_cross;
ca = cc->dm_arrow;
while (ca != NULL) {
vysledok.insert(vysledok.begin(),*ca);
#ifdef THDEBUG
thprintf("%d - %d : %s%d\n",
ca->reverse ? ca->series->to : ca->series->from,
ca->reverse ? ca->series->from : ca->series->to,
ca->reverse ? "R" : "N",
ca->series->id
);
#endif
cc = cc->dm_cross;
ca = cc->dm_arrow;
}
}
return result;
}
void thdb1d::find_loops()
{
size_t nlegs = this->get_tree_size(),
nstations = this->station_vec.size(), numseries,
i, lastcross, nseries, nloops, loopid;
thdb1dl ** legs = this->get_tree_legs(), ** curleg, * cleg;
thdb1d_tree_node * nodes = this->get_tree_nodes(), * from_node;
long * crossst = NULL, * curcrossst,
lastlegseries, currentcross;
#ifdef THDEBUG
thprintf("\n\nsearching for centerline loops\n");
#else
thprintf("searching for centerline loops ... ");
thtext_inline = true;
#endif
if (nstations > 0)
crossst = new long [nstations];
thlc_leg * lclegs = NULL, * clcleg = NULL, * prevlcleg = NULL;
if (nlegs > 0)
lclegs = new thlc_leg [nlegs];
thlc_cross * lccrosses = NULL, * clccross;
thlc_cross_arrow * lccrossarrows = NULL, * cca;
thlc_series tmpseries, * curseries, * prevseries;
std::vector<thlc_series> lcseries;
thdb1d_loop tdbloop;
#ifdef THDEBUG
thdb1d_loop_list_type::iterator dbli;
#endif
thdb1d_loop_leg tdbloopleg, * ptdbl;
std::list<thlc_cross_arrow> from2fixv, to2fixv, closev, loopsv;
std::list<thlc_cross_arrow>::iterator it;
std::set<thlc_loop>::iterator lsi;
#ifdef THDEBUG
std::list<thlc_loop> all_loop_list;
unsigned long prev_set_size;
std::list<thlc_loop>::iterator lli;
#endif
std::set<thlc_loop> all_loop_set;
long from2fixl, to2fixl, closel;
thlc_cross_arrow tmpca;
thlc_loop tmploop;
// resetuje crossst
lastcross = 0;
#define setcrossst(uid) {\
currentcross = crossst[uid-1];\
if (currentcross < 0) {\
crossst[uid-1] = lastcross;\
currentcross = lastcross;\
lastcross++;\
}}
for (i = 0, curcrossst = crossst; i < nstations; i++, curcrossst++)
*curcrossst = -1;
curleg = legs;
i = 0;
lastlegseries = -1;
curseries = NULL;
numseries = 0;
clcleg = lclegs;
while ((nlegs > 0) && ((*curleg)->leg->data_type == TT_DATATYPE_NOSURVEY)) {
nlegs--;
curleg++;
}
if (nlegs == 0)
goto LC_COORD_CALC;
while (i < nlegs) {
while ((nlegs > i) && ((*curleg)->leg->data_type == TT_DATATYPE_NOSURVEY)) {
nlegs--;
curleg++;
}
if (nlegs == i)
break;
// nastavi clcleg
cleg = (*curleg);
clcleg->dbleg = cleg;
clcleg->next_series_leg = NULL;
if (cleg->reverse) {
clcleg->from_id = cleg->leg->to.id;
clcleg->to_id = cleg->leg->from.id;
} else {
clcleg->from_id = cleg->leg->from.id;
clcleg->to_id = cleg->leg->to.id;
}
clcleg->from_uid = this->station_vec[clcleg->from_id - 1].uid;
clcleg->to_uid = this->station_vec[clcleg->to_id - 1].uid;
if (clcleg->from_uid == clcleg->to_uid) {
ththrow(("shot between two equal stations -- %s@%s and %s@%s",
this->station_vec[clcleg->from_id - 1].name,
this->station_vec[clcleg->from_id - 1].survey->get_full_name(),
this->station_vec[clcleg->to_id - 1].name,
this->station_vec[clcleg->to_id - 1].survey->get_full_name()));
}
from_node = &(nodes[clcleg->from_uid - 1]);
if ((lastlegseries != long(cleg->series_id)) ||
from_node->is_fixed || (from_node->narrows != 2)) {
// zacina sa ina seria
lcseries.push_back(tmpseries);
curseries = &(lcseries[numseries]);
curseries->id = numseries;
if (numseries > 0) {
prevseries = &(lcseries[long(numseries) - 1]);;
} else {
prevseries = NULL;
}
numseries++;
clcleg->prev_series_leg = NULL;
curseries->first_leg = clcleg;
curseries->last_leg = clcleg;
curseries->numlegs = 1;
setcrossst(clcleg->from_uid);
curseries->from = currentcross;
if (prevseries != NULL) {
setcrossst(prevlcleg->to_uid);
prevseries->to = currentcross;
}
} else {
// nezacina sa ina seria
curseries->last_leg = clcleg;
clcleg->prev_series_leg = prevlcleg;
prevlcleg->next_series_leg = clcleg;
curseries->numlegs++;
}
lastlegseries = long(cleg->series_id);
curleg++;
prevlcleg = clcleg;
clcleg++;
i++;
}
if (curseries != NULL) {
setcrossst(prevlcleg->to_uid);
curseries->to = currentcross;
};
nseries = lcseries.size();
lccrosses = new thlc_cross [lastcross];
for (i = 0, curcrossst = crossst; i < nstations; i++, curcrossst++) {
if (*curcrossst > -1) {
clccross = &(lccrosses[*curcrossst]);
clccross->id = *curcrossst;
clccross->station_uid = i + 1;
clccross->narrows = 0;
clccross->first_arrow = NULL;
clccross->last_arrow = NULL;
clccross->is_fixed = nodes[i].is_fixed;
}
}
// vytvori strom krizovatiek
i = 0;
lccrossarrows = new thlc_cross_arrow [2 * nseries];
cca = lccrossarrows;
while (i < nseries) {
curseries = &(lcseries[i]);
curseries->from_cross = &(lccrosses[curseries->from]);
curseries->to_cross = &(lccrosses[curseries->to]);
cca->prev_arrow = NULL;
cca->next_arrow = NULL;
if (curseries->from_cross->last_arrow == NULL) {
curseries->from_cross->first_arrow = cca;
} else {
cca->prev_arrow = curseries->from_cross->last_arrow;
curseries->from_cross->last_arrow->next_arrow = cca;
}
curseries->from_cross->last_arrow = cca;
curseries->from_cross->narrows++;
cca->target = curseries->to_cross;
cca->series = curseries;
cca->reverse = false;
cca++;
cca->prev_arrow = NULL;
cca->next_arrow = NULL;
if (curseries->to_cross->last_arrow == NULL) {
curseries->to_cross->first_arrow = cca;
} else {
cca->prev_arrow = curseries->to_cross->last_arrow;
curseries->to_cross->last_arrow->next_arrow = cca;
}
curseries->to_cross->last_arrow = cca;
curseries->to_cross->narrows++;
cca->target = curseries->from_cross;
cca->series = curseries;
cca->reverse = true;
cca++;
i++;
}
#ifdef THDEBUG
thprintf("\n\n\nLOOP CLOSURE DEBUG\n");
thprintf("\nCROSSES:\n");
for (i = 0; i < lastcross; i++) {
thprintf("%ld: %s %ld [",i, lccrosses[i].is_fixed ? "F" : "V", lccrosses[i].narrows);
cca = lccrosses[i].first_arrow;
while (cca != NULL) {
thprintf("%s%ld", cca->prev_arrow == NULL ? "" : " ", cca->target->id);
cca = cca->next_arrow;
}
thprintf("] %s@%s\n",
this->station_vec[lccrosses[i].station_uid - 1].name,
this->station_vec[lccrosses[i].station_uid - 1].survey->name);
}
thprintf("\nSERIES:\n");
for (i = 0; i < nseries; i++) {
thprintf("%ld: %ld - %ld [%ld legs",i,lcseries[i].from,lcseries[i].to,lcseries[i].numlegs);
clcleg = lcseries[i].first_leg;
if (clcleg != NULL) {
thprintf(": %s@%s",
this->station_vec[clcleg->from_uid - 1].name,
this->station_vec[clcleg->from_uid - 1].survey->name);
}
while (clcleg != NULL) {
thprintf(" - %s@%s",
this->station_vec[clcleg->to_uid - 1].name,
this->station_vec[clcleg->to_uid - 1].survey->name);
clcleg = clcleg->next_series_leg;
}
thprintf("]\n");
}
#endif
// najde okruhy
nloops = 0;
// urobi preprocessing serii
for(i = 0; i < nseries; i++) {
curseries = &(lcseries[i]);
curseries->is_active = true;
// ak neni fixnuty a ma len jeden arrow - deaktivujeme
if (((!(curseries->from_cross->is_fixed)) &&
(curseries->from_cross->narrows == 1)) ||
((!(curseries->to_cross->is_fixed)) &&
(curseries->to_cross->narrows == 1)))
curseries->is_active = false;
// ak ma oba konce fixnute alebo totozne, spravi z nej okruh
if ((curseries->from_cross->is_fixed && curseries->to_cross->is_fixed) ||
(curseries->from == curseries->to)) {
tmpca.series = curseries;
tmpca.reverse = false;
tmpca.prev_arrow = NULL;
tmpca.next_arrow = NULL;
tmploop.first_arrow = &(*loopsv.insert(loopsv.end(),tmpca));
tmploop.last_arrow = tmploop.first_arrow;
tmploop.from_cross = curseries->from_cross;
tmploop.to_cross = curseries->to_cross;
tmploop.minid = curseries->id;
tmploop.size = curseries->numlegs;
tmploop.id = nloops++;
#ifdef THDEBUG
prev_set_size = all_loop_set.size();
#endif
all_loop_set.insert(tmploop);
#ifdef THDEBUG
lsi = all_loop_set.find(tmploop);
tmploop.old_id = lsi->id;
if (prev_set_size < all_loop_set.size())
tmploop.is_new = true;
else
tmploop.is_new = false;
all_loop_list.insert(all_loop_list.end(),tmploop);
#endif
curseries->is_active = false;
}
}
// najde okruh ku kazdej serii
for (i = 0; i < nseries; i++) {
curseries = &(lcseries[i]);
if (!curseries->is_active)
continue;
curseries->is_active = false;
//#ifdef THDEBUG
// thprintf("\nNEW SERIES: %ld -> %ld", curseries->from, curseries->to);
//#endif
// najde najblizsi pevny bod ku from
from2fixv.clear();
if (!curseries->from_cross->is_fixed)
from2fixl = chledala_chledala(lccrosses, lastcross, NULL, curseries->from_cross, from2fixv);
else
from2fixl = 0;
// najde najblizsti pevny bod ku to
to2fixv.clear();
if (!curseries->to_cross->is_fixed)
to2fixl = chledala_chledala(lccrosses, lastcross, NULL, curseries->to_cross, to2fixv);
else
to2fixl = 0;
// najde najkratsiu cestu z from do to
closev.clear();
closel = chledala_chledala(lccrosses, lastcross, curseries->from_cross, curseries->to_cross, closev);
// vytvori okruh
if (((from2fixl >= 0) && (to2fixl >= 0)) || (closel > 0)) {
// vlozime do okruhu sucasnu hranu
tmpca.series = curseries;
tmpca.reverse = false;
tmpca.prev_arrow = NULL;
tmpca.next_arrow = NULL;
tmploop.first_arrow = &(*loopsv.insert(loopsv.end(),tmpca));
tmploop.last_arrow = tmploop.first_arrow;
tmploop.from_cross = curseries->from_cross;
tmploop.to_cross = curseries->to_cross;
tmploop.minid = curseries->id;
tmploop.size = curseries->numlegs;
tmploop.id = nloops++;
#define checktmploop(ca) {\
if (tmploop.minid > ca.series->id) \
tmploop.minid = ca.series->id; \
tmploop.size += ca.series->numlegs; \
}
if ((closel > 0) && (((from2fixl + to2fixl) >= closel) || (from2fixl < 0) || (to2fixl < 0))) {
// vytvorime uzavrety okruh
it = closev.begin();
while (it != closev.end()) {
tmpca = *it;
tmploop.last_arrow->next_arrow = &(*loopsv.insert(loopsv.end(),tmpca));
tmploop.last_arrow->next_arrow->prev_arrow = tmploop.last_arrow;
tmploop.last_arrow = tmploop.last_arrow->next_arrow;
tmploop.last_arrow->next_arrow = NULL;
checktmploop(tmpca);
it++;
}
tmploop.from_cross = curseries->from_cross;
tmploop.to_cross = curseries->from_cross;
#ifdef THDEBUG
prev_set_size = all_loop_set.size();
#endif
all_loop_set.insert(tmploop);
#ifdef THDEBUG
lsi = all_loop_set.find(tmploop);
tmploop.old_id = lsi->id;
if (prev_set_size < all_loop_set.size())
tmploop.is_new = true;
else
tmploop.is_new = false;
all_loop_list.insert(all_loop_list.end(),tmploop);
#endif
} else {
// vytvorime otvoreny okruh
it = from2fixv.begin();
while (it != from2fixv.end()) {
tmpca = *it;
tmpca.reverse = !tmpca.reverse;
if (tmpca.reverse)
tmploop.from_cross = tmpca.series->to_cross;
else
tmploop.from_cross = tmpca.series->from_cross;
tmploop.first_arrow->prev_arrow = &(*loopsv.insert(loopsv.end(),tmpca));
tmploop.first_arrow->prev_arrow->next_arrow = tmploop.first_arrow;
tmploop.first_arrow = tmploop.first_arrow->prev_arrow;
tmploop.first_arrow->prev_arrow = NULL;
checktmploop(tmpca);
it++;
}
it = to2fixv.begin();
while (it != to2fixv.end()) {
tmpca = *it;
if (tmpca.reverse)
tmploop.to_cross = tmpca.series->from_cross;
else
tmploop.to_cross = tmpca.series->to_cross;
tmploop.last_arrow->next_arrow = &(*loopsv.insert(loopsv.end(),tmpca));
tmploop.last_arrow->next_arrow->prev_arrow = tmploop.last_arrow;
tmploop.last_arrow = tmploop.last_arrow->next_arrow;
tmploop.last_arrow->next_arrow = NULL;
checktmploop(tmpca);
it++;
}
#ifdef THDEBUG
prev_set_size = all_loop_set.size();
#endif
all_loop_set.insert(tmploop);
#ifdef THDEBUG
lsi = all_loop_set.find(tmploop);
tmploop.old_id = lsi->id;
if (prev_set_size < all_loop_set.size())
tmploop.is_new = true;
else
tmploop.is_new = false;
all_loop_list.insert(all_loop_list.end(),tmploop);
#endif
}
}
curseries->is_active = true;
}
#ifdef THDEBUG
// vypise okruhy na zaklade serii
lli = all_loop_list.begin();
i = 0;
thprintf("\nSERIES LOOPS:\n");
while (lli != all_loop_list.end()) {
lsi = all_loop_set.find(*lli);
thprintf("%ld[%ld] %s %s %ld: ", lli->id, lli->old_id, lli->is_new ? "NEW" : "OLD" , lli->from_cross->id != lli->to_cross->id ? "OPN" : "CLS", lli->size);
cca = lli->first_arrow;
if (cca->reverse) {
thprintf("%d(%s@%s)", cca->series->to,
this->station_vec[cca->series->to_cross->station_uid - 1].name,
this->station_vec[cca->series->to_cross->station_uid - 1].survey->name);
} else {
thprintf("%d(%s@%s)", cca->series->from,
this->station_vec[cca->series->from_cross->station_uid - 1].name,
this->station_vec[cca->series->from_cross->station_uid - 1].survey->name);
}
while (cca != NULL) {
if (cca->reverse) {
thprintf("[%d(%s@%s)] - %d(%s@%s)", cca->series->to,
this->station_vec[cca->series->to_cross->station_uid - 1].name,
this->station_vec[cca->series->to_cross->station_uid - 1].survey->name, cca->series->from,
this->station_vec[cca->series->from_cross->station_uid - 1].name,
this->station_vec[cca->series->from_cross->station_uid - 1].survey->name);
} else {
thprintf("[%d(%s@%s)] - %d(%s@%s)", cca->series->from,
this->station_vec[cca->series->from_cross->station_uid - 1].name,
this->station_vec[cca->series->from_cross->station_uid - 1].survey->name, cca->series->to,
this->station_vec[cca->series->to_cross->station_uid - 1].name,
this->station_vec[cca->series->to_cross->station_uid - 1].survey->name);
}
cca = cca->next_arrow;
}
thprintf("\n");
lli++;
i++;
}
#endif
// zapise si okruhy do premennych databazy
lsi = all_loop_set.begin();
loopid = 0;
while (lsi != all_loop_set.end()) {
// vypise ci je open alebo close, nastavi
tdbloop.from = &(this->station_vec[lsi->from_cross->station_uid - 1]);
tdbloop.to = &(this->station_vec[lsi->to_cross->station_uid - 1]);
if (tdbloop.from->uid == tdbloop.to->uid)
tdbloop.open = false;
else
tdbloop.open = true;
tdbloop.nlegs = 0;
tdbloop.first_leg = NULL;
tdbloop.last_leg = NULL;
cca = lsi->first_arrow;
while (cca != NULL) {
clcleg = cca->reverse ? cca->series->last_leg : cca->series->first_leg;
while (clcleg != NULL) {
tdbloopleg.leg = clcleg->dbleg->leg;
tdbloopleg.reverse = clcleg->dbleg->reverse;
if (cca->reverse)
tdbloopleg.reverse = !tdbloopleg.reverse;
ptdbl = &(* this->loop_leg_list.insert(this->loop_leg_list.end(),tdbloopleg));
if (tdbloop.nlegs == 0) {
tdbloop.first_leg = ptdbl;
tdbloop.last_leg = ptdbl;
ptdbl->next_leg = NULL;
ptdbl->prev_leg = NULL;
} else {
tdbloop.last_leg->next_leg = ptdbl;
ptdbl->prev_leg = tdbloop.last_leg;
ptdbl->next_leg = NULL;
tdbloop.last_leg = ptdbl;
}
tdbloop.nlegs++;
clcleg = cca->reverse ? clcleg->prev_series_leg : clcleg->next_series_leg;
}
cca = cca->next_arrow;
}
tdbloop.id = ++loopid;
this->loop_list.insert(this->loop_list.end(), tdbloop);
lsi++;
}
#ifdef THDEBUG
thprintf("\nSHOT LOOPS:\n");
dbli = this->loop_list.begin();
i = 0;
while (dbli != this->loop_list.end()) {
thprintf("%ld %s %ld: %s@%s", i, dbli->open ? "OPN" : "CLS", dbli->nlegs,
dbli->from->name, dbli->from->survey->name);
ptdbl = dbli->first_leg;
while (ptdbl != NULL) {
if (ptdbl->reverse) {
thprintf(" - %s@%s",
this->station_vec[this->station_vec[ptdbl->leg->from.id - 1].uid - 1].name,
this->station_vec[this->station_vec[ptdbl->leg->from.id - 1].uid - 1].survey->name);
} else {
thprintf(" - %s@%s",
this->station_vec[this->station_vec[ptdbl->leg->to.id - 1].uid - 1].name,
this->station_vec[this->station_vec[ptdbl->leg->to.id - 1].uid - 1].survey->name);
}
ptdbl = ptdbl->next_leg;
}
thprintf("\n");
dbli++;
i++;
}
#endif
LC_COORD_CALC:
delete [] crossst;
delete [] lclegs;
delete [] lccrosses;
delete [] lccrossarrows;
#ifdef THDEBUG
thprintf("\nEND OF LOOP CLOSURE DEBUG\n");
#endif
#ifdef THDEBUG
thprintf("\nend of loops searching\n\n");
#else
thprintf("done\n");
thtext_inline = false;
#endif
}
void thdb1d::close_loops()
{
unsigned long nlegs = this->get_tree_size(),
nstations = this->station_vec.size();
long i;
#ifdef THDEBUG
thprintf("\n\ncalculating station coordinates\n");
#else
thprintf("calculating station coordinates ... ");
thtext_inline = true;
#endif
// * priradi suradnice UID fixnym bodom
thdata * dp;
bool anyfixed = false;
thdb_object_list_type::iterator obi = this->db->object_list.begin();
thdatafix_list::iterator fii;
thdb1ds * ps;
thdataobject * cx1, * cx2;
thdb1ds * tmps;
double avg_error = 0.0, avg_error_sum = 0.0;
while (obi != this->db->object_list.end()) {
if ((*obi)->get_class_id() == TT_DATA_CMD) {
dp = (thdata *)(*obi);
fii = dp->fix_list.begin();
while(fii != dp->fix_list.end()) {
tmps = &(this->station_vec[fii->station.id - 1]);
cx1 = tmps->fixcontext;
cx2 = fii->srcf.context;
if (((cx1 == NULL) && (cx2 == NULL)) || ((cx1 != NULL) && (cx2 != NULL) && (cx1->id == cx2->id))) {
ps = &(this->station_vec[this->station_vec[fii->station.id - 1].uid - 1]);
ps->placed = 1;
ps->fixed = true;
anyfixed = true;
ps->x = fii->x;
ps->y = fii->y;
ps->z = fii->z;
if (!thisnan(fii->sdx)) {
ps->sdx = fii->sdx;
ps->sdy = fii->sdy;
ps->sdz = fii->sdz;
}
}
fii++;
}
}
obi++;
}
// * zrata okruhy (err_(dx|dy|dz), (err|src)_length)
// * a potom vyrovna okruhy (nastavi legs)
double src_dx, src_dy, src_dz, dst_dx, dst_dy, dst_dz, sum_length,
dx, dy, dz, sum_sdx, sum_sdy, sum_sdz, sumlegs, err_dx, err_dy, err_dz;
thdb1d_loop_list_type::iterator li;
thdb1d_loop_leg * ll; unsigned mode;
#ifdef THDEBUG
#define nmodes 3
#else
#define nmodes 2
#endif
for (mode = 0; mode < nmodes; mode++) {
li = this->loop_list.begin();
while (li != this->loop_list.end()) {
sum_sdx = 0.0;
sum_sdy = 0.0;
sum_sdz = 0.0;
src_dx = 0.0;
src_dy = 0.0;
src_dz = 0.0;
if (li->open) {
dst_dx = li->to->x - li->from->x;
dst_dy = li->to->y - li->from->y;
dst_dz = li->to->z - li->from->z;
if (!li->from->adjusted) {
sum_sdx += li->from->sdx * li->from->sdx;
sum_sdx += li->from->sdy * li->from->sdy;
sum_sdx += li->from->sdz * li->from->sdz;
}
if (!li->to->adjusted) {
sum_sdx += li->to->sdx * li->to->sdx;
sum_sdx += li->to->sdy * li->to->sdy;
sum_sdx += li->to->sdz * li->to->sdz;
}
} else {
dst_dx = 0.0;
dst_dy = 0.0;
dst_dz = 0.0;
}
// prvy prechod - spocita chyby a sumu odchylok
sumlegs = 0.0;
sum_length = 0.0;
ll = li->first_leg;
while (ll != NULL) {
if (ll->reverse) {
dx = - ll->leg->adj_dx;
dy = - ll->leg->adj_dy;
dz = - ll->leg->adj_dz;
} else {
dx = ll->leg->adj_dx;
dy = ll->leg->adj_dy;
dz = ll->leg->adj_dz;
}
sum_length += ll->leg->total_length;
if (ll->leg->adjusted) {
dst_dx -= dx;
dst_dy -= dy;
dst_dz -= dz;
} else {
src_dx += dx;
src_dy += dy;
src_dz += dz;
if (!ll->leg->plumbed) {
sum_sdx += ll->leg->total_sdx;
sum_sdy += ll->leg->total_sdy;
}
sum_sdz += ll->leg->total_sdz;
}
sumlegs += 1.0;
ll = ll->next_leg;
}
// zapise do statistiky
#ifdef THDEBUG
if (mode == 2) {
thprintf("CORRECTION: %7.4f%% -> %7.4f%%\n",
li->src_length > 0 ? 100.0 * li->err_length / li->src_length : 0.0,
li->src_length > 0 ? 100.0 * sqrt(pow(dst_dx - src_dx,2.0) + pow(dst_dy - src_dy,2.0) + pow(dst_dz - src_dz,2.0)) / li->src_length : 0.0);
}
else
#endif
if (mode == 0) {
li->src_length = sum_length;
li->err_dx = dst_dx - src_dx;
li->err_dy = dst_dy - src_dy;
li->err_dz = dst_dz - src_dz;
li->err_length = sqrt(li->err_dx * li->err_dx + li->err_dy * li->err_dy + li->err_dz * li->err_dz);
if (sum_length > 0.0) {
li->err = 100.0 * (li->err_length / sum_length);
avg_error += sumlegs * li->err;
avg_error_sum += sumlegs;
ll = li->first_leg;
while (ll != NULL) {
if ((ll->leg->loop == NULL) || (ll->leg->loop->err < li->err)) {
ll->leg->loop = &(*li);
}
ll = ll->next_leg;
}
}
// vyrovna okruh
} else {
err_dx = dst_dx - src_dx;
err_dy = dst_dy - src_dy;
err_dz = dst_dz - src_dz;
// ak je okruh otvoreny a std > 0, adjustne koncove body
if (li->open) {
if (!li->from->adjusted) {
if (sum_sdx > 0.0)
li->from->x -= err_dx * li->from->sdx / sum_sdx;
if (sum_sdy > 0.0)
li->from->y -= err_dy * li->from->sdy / sum_sdy;
if (sum_sdz > 0.0)
li->from->z -= err_dz * li->from->sdz / sum_sdz;
li->from->adjusted = true;
}
if (!li->to->adjusted) {
if (sum_sdx > 0.0)
li->to->x += err_dx * li->to->sdx / sum_sdx;
if (sum_sdy > 0.0)
li->to->y += err_dy * li->to->sdy / sum_sdy;
if (sum_sdz > 0.0)
li->to->z += err_dz * li->to->sdz / sum_sdz;
li->to->adjusted = true;
}
}
ll = li->first_leg;
while (ll != NULL) {
if (!ll->leg->adjusted) {
#define ORIENT (ll->reverse ? -1.0 : 1.0)
if (sum_sdx > 0.0)
ll->leg->adj_dx += ORIENT * err_dx * (ll->leg->plumbed ? 0.0 : ll->leg->total_sdx) / sum_sdx;
else
ll->leg->adj_dx += ORIENT * err_dx / sumlegs;
if (sum_sdy > 0.0)
ll->leg->adj_dy += ORIENT * err_dy * (ll->leg->plumbed ? 0.0 : ll->leg->total_sdy) / sum_sdy;
else
ll->leg->adj_dy += ORIENT * err_dy / sumlegs;
if (sum_sdz > 0.0)
ll->leg->adj_dz += ORIENT * err_dz * ll->leg->total_sdz / sum_sdz;
else
ll->leg->adj_dz += ORIENT * err_dz / sumlegs;
ll->leg->adjusted = true;
#ifdef THDEBUG
thprintf("ADJLEG %s@%s - %s@%s: %.2f,%.2f,%.2f -> %.2f,%.2f,%.2f\n", this->station_vec[ll->leg->from.id - 1].name, this->station_vec[ll->leg->from.id - 1].survey->name, this->station_vec[ll->leg->to.id - 1].name, this->station_vec[ll->leg->to.id - 1].survey->name,
ll->leg->total_dx, ll->leg->total_dy, ll->leg->total_dz,
ll->leg->adj_dx, ll->leg->adj_dy, ll->leg->adj_dz);
#endif
}
ll = ll->next_leg;
}
} // koniec vyrovnavanie
li++;
} // koniec cyklu okruhov
} // koniec modoveho cyklu
// * spocita suradnice UID bodom, tak ze prejde vsetky legy a
// * poojde z UID na UID
thdb1ds * froms, * tos;
thdb1dl ** legs = this->get_tree_legs(), * cleg;
long unrecover = -1;
for (i = 0; (unsigned long) i < nlegs; i++) {
legs[i]->leg->adjusted = false;
}
for (i = 0; (unsigned long) i < nlegs; i++) {
cleg = legs[i];
if (cleg->reverse) {
froms = &(this->station_vec[this->station_vec[cleg->leg->to.id - 1].uid - 1]);
tos = &(this->station_vec[this->station_vec[cleg->leg->from.id - 1].uid - 1]);
} else {
froms = &(this->station_vec[this->station_vec[cleg->leg->from.id - 1].uid - 1]);
tos = &(this->station_vec[this->station_vec[cleg->leg->to.id - 1].uid - 1]);
}
if (cleg->leg->data_type == TT_DATATYPE_NOSURVEY) {
// ak je no-survey, nastavi mu total statistiku
cleg->leg->total_dx = tos->x - froms->x;
cleg->leg->total_dy = tos->y - froms->y;
cleg->leg->total_dz = tos->z - froms->z;
// najprv horizontalnu dlzku
cleg->leg->total_length = hypot(cleg->leg->total_dx, cleg->leg->total_dy);
cleg->leg->total_bearing = atan2(cleg->leg->total_dx, cleg->leg->total_dy) / THPI * 180.0;
if (cleg->leg->total_bearing < 0.0)
cleg->leg->total_bearing += 360.0;
cleg->leg->total_gradient = atan2(cleg->leg->total_dz, cleg->leg->total_length) / THPI * 180.0;
// potom celkovu dlzku
cleg->leg->total_length = hypot(cleg->leg->total_length, cleg->leg->total_dz);
continue;
}
if ((i == 0) && (!anyfixed)) {
froms->placed = 1;
froms->x = 0.0;
froms->y = 0.0;
froms->z = 0.0;
}
#ifdef THDEBUG
thprintf("LEG: %s@%s [%ld] (from %s@%s [%ld])\n",
tos->name, tos->survey->name, tos->uid, froms->name, froms->survey->name, froms->uid
);
#endif
if (froms->placed == 0)
ththrow(("a software BUG is present (" __FILE__ ":%d)", __LINE__));
if (tos->placed == 0) {
tos->placed += 1;
if (cleg->reverse) {
tos->x = froms->x - cleg->leg->adj_dx;
tos->y = froms->y - cleg->leg->adj_dy;
tos->z = froms->z - cleg->leg->adj_dz;
} else {
tos->x = froms->x + cleg->leg->adj_dx;
tos->y = froms->y + cleg->leg->adj_dy;
tos->z = froms->z + cleg->leg->adj_dz;
}
}
else {
tos->placed += 1;
err_dx = (tos->x - froms->x) - (cleg->reverse ? -1.0 : 1.0) * cleg->leg->adj_dx;
err_dy = (tos->y - froms->y) - (cleg->reverse ? -1.0 : 1.0) * cleg->leg->adj_dy;
err_dz = (tos->z - froms->z) - (cleg->reverse ? -1.0 : 1.0) * cleg->leg->adj_dz;
double err = hypot(hypot(err_dx, err_dy), err_dz);
if ((err >= 1e-4) && (i > unrecover)) {
#ifdef THDEBUG
thprintf("ERRLEG %s@%s - %s@%s: %.2f,%.2f,%.2f\n",
froms->name, froms->survey->name, tos->name, tos->survey->name,
err_dx, err_dy, err_dz);
#endif
// mame problem - musime spravit nasledovne
thdb1ds * errst, * lastst;
errst = tos;
lastst = tos;
long start_i, end_i;
start_i = 0;
end_i = i;
sumlegs = 0.0; sum_sdx = 0.0; sum_sdy = 0.0; sum_sdz = 0.0;
// 1. najst zamery, na ktore chyby rozlozime
for (i = end_i; i >= start_i; i--) {
cleg = legs[i];
if (cleg->reverse) {
froms = &(this->station_vec[this->station_vec[cleg->leg->to.id - 1].uid - 1]);
tos = &(this->station_vec[this->station_vec[cleg->leg->from.id - 1].uid - 1]);
} else {
froms = &(this->station_vec[this->station_vec[cleg->leg->from.id - 1].uid - 1]);
tos = &(this->station_vec[this->station_vec[cleg->leg->to.id - 1].uid - 1]);
}
if ((!cleg->leg->adjusted) && (tos->uid == lastst->uid)) {
sumlegs += 1.0;
if (!cleg->leg->plumbed) {
sum_sdx += cleg->leg->total_sdx;
sum_sdy += cleg->leg->total_sdy;
}
sum_sdz += cleg->leg->total_sdz;
cleg->leg->to_be_adjusted = true;
} else {
cleg->leg->to_be_adjusted = false;
}
if (tos->uid == lastst->uid) {
lastst = froms;
if ((froms->placed > 1) || (froms->fixed) || (froms->uid == errst->uid)) {
start_i = i;
}
}
if (tos->placed > 0)
tos->placed--;
}
// 2. rozlozit chybu na zamery
for (i = start_i; i <= end_i; i++) {
cleg = legs[i];
if (cleg->leg->to_be_adjusted) {
#define ORIENT2 (cleg->reverse ? -1.0 : 1.0)
#ifdef THDEBUG
thprintf("ADJLEG %s@%s - %s@%s: %.2f,%.2f,%.2f", this->station_vec[cleg->leg->from.id - 1].name, this->station_vec[cleg->leg->from.id - 1].survey->name, this->station_vec[cleg->leg->to.id - 1].name, this->station_vec[cleg->leg->to.id - 1].survey->name,
cleg->leg->adj_dx, cleg->leg->adj_dy, cleg->leg->adj_dz);
#endif
if (sum_sdx > 0.0)
cleg->leg->adj_dx += ORIENT2 * err_dx * (cleg->leg->plumbed ? 0.0 : cleg->leg->total_sdx) / sum_sdx;
else
cleg->leg->adj_dx += ORIENT2 * err_dx / sumlegs;
if (sum_sdy > 0.0)
cleg->leg->adj_dy += ORIENT2 * err_dy * (cleg->leg->plumbed ? 0.0 : cleg->leg->total_sdy) / sum_sdy;
else
cleg->leg->adj_dy += ORIENT2 * err_dy / sumlegs;
if (sum_sdz > 0.0)
cleg->leg->adj_dz += ORIENT2 * err_dz * cleg->leg->total_sdz / sum_sdz;
else
cleg->leg->adj_dz += ORIENT2 * err_dz / sumlegs;
cleg->leg->adjusted = true;
#ifdef THDEBUG
thprintf(" -> %.2f,%.2f,%.2f\n",
cleg->leg->adj_dx, cleg->leg->adj_dy, cleg->leg->adj_dz);
#endif
}
}
// 3. ratat este raz
i = start_i - 1;
if (sumlegs < 1.0) {
#ifdef THDEBUG
thprintf("ERRLEG UNRECOVERED!\n");
#endif
unrecover = end_i;
}
}
}
}
// * potom priradi suradnice nie UID bodom
for(i = 0; (unsigned long)i < nstations; i++) {
ps = &(this->station_vec[i]);
froms = &(this->station_vec[ps->uid - 1]);
if (ps->placed == 0) {
ps->placed++;
ps->x = froms->x;
ps->y = froms->y;
ps->z = froms->z;
if (ps->placed == 0) {
// ththrow(("a software BUG is present (" __FILE__ ":%d)", __LINE__));
ththrow(("can not connect %s@%s to centerline network",
this->station_vec[i].name,
this->station_vec[i].survey->get_full_name()));
}
}
}
#ifdef THDEBUG
thprintf("\nend of station coordinates calculation\n\n");
#else
thprintf("done\n");
thtext_inline = false;
#endif
if (avg_error_sum > 0.0) {
thprintf("average loop error: %.2f%%\n", (avg_error / avg_error_sum));
}
}
struct thdb1d_lpr {
thdb1d_loop * li;
double err;
};
int comp_lpr(const void * l1, const void * l2) {
if (((thdb1d_lpr*)l1)->err > ((thdb1d_lpr*)l2)->err)
return -1;
else if (((thdb1d_lpr*)l1)->err < ((thdb1d_lpr*)l2)->err)
return 1;
else return 0;
}
void thdb1d::print_loops() {
thdb1d_loop_list_type::iterator lii = this->loop_list.begin();
if (lii == this->loop_list.end())
return;
unsigned long i, nloops;
thdb1d_loop * li;
nloops = this->loop_list.size();
thdb1d_lpr * lpr = new thdb1d_lpr [nloops];
i = 0;
while (lii != this->loop_list.end()) {
lpr[i].li = &(*lii);
if (lii->src_length > 0.0)
lpr[i].err = lii->err_length / lii->src_length;
else
lpr[i].err = 0.0;
i++;
lii++;
}
qsort(lpr,nloops,sizeof(thdb1d_lpr),comp_lpr);
thdb1d_loop_leg * ll;
thsurvey * ss;
int totlen = 6 - strlen(thdeflocale.format_length_units()) + 1;
thdb1ds * ps;
unsigned long psid, prev_psid, first_psid;
thlog.printf("\n\n######################### loop errors ##########################\n");
thlog.printf( "REL-ERR ABS-ERR TOTAL-L STS X-ERROR Y-ERROR Z-ERROR STATIONS\n");
for (i = 0; i < nloops; i++) {
li = lpr[i].li;
thlog.printf("%6.2f%% %s%s %s%s %3ld %s%s %s%s %s%s [",
li->src_length > 0.0 ? 100.0 * li->err_length / li->src_length : 0.0,
thdeflocale.format_length(li->err_length,1,totlen), thdeflocale.format_length_units(),
thdeflocale.format_length(li->src_length,1,totlen), thdeflocale.format_length_units(),
li->nlegs,
thdeflocale.format_length(li->err_dx,1,totlen), thdeflocale.format_length_units(),
thdeflocale.format_length(li->err_dy,1,totlen), thdeflocale.format_length_units(),
thdeflocale.format_length(li->err_dz,1,totlen), thdeflocale.format_length_units());
ll = li->first_leg;
ss = NULL;
if (ll->reverse)
psid = ll->leg->to.id;
else
psid = ll->leg->from.id;
ps = &(this->station_vec[psid - 1]);
first_psid = psid;
thlog.printf("%s", ps->name);
if ((ss == NULL) || (ss->id != ps->survey->id)) {
ss = ps->survey;
thlog.printf("@%s", ss->get_full_name());
}
prev_psid = psid;
while (ll != NULL) {
if (ll->reverse)
psid = ll->leg->to.id;
else
psid = ll->leg->from.id;
if (prev_psid != psid) {
ps = &(this->station_vec[psid - 1]);
thlog.printf(" = %s", ps->name);
if (ss->id != ps->survey->id) {
ss = ps->survey;
thlog.printf("@%s", ss->get_full_name());
}
}
if (ll->reverse)
psid = ll->leg->from.id;
else
psid = ll->leg->to.id;
ps = &(this->station_vec[psid - 1]);
thlog.printf(" - %s", ps->name);
if (ss->id != ps->survey->id) {
ss = ps->survey;
thlog.printf("@%s", ss->get_full_name());
}
if ((ll->next_leg == NULL) && (!li->open)) {
if (first_psid != psid) {
psid = first_psid;
ps = &(this->station_vec[psid - 1]);
thlog.printf(" = %s", ps->name);
if (ss->id != ps->survey->id) {
ss = ps->survey;
thlog.printf("@%s", ss->get_full_name());
}
}
}
prev_psid = psid;
ll = ll->next_leg;
}
thlog.printf("]\n");
}
thlog.printf("##################### end of loop errors #######################\n");
delete [] lpr;
}
thdb3ddata * thdb1d::get_3d_surface() {
this->get_3d();
return &(this->d3_surface);
}
thdb3ddata * thdb1d::get_3d_splay() {
this->get_3d();
return &(this->d3_splay);
}
thdb3ddata * thdb1d::get_3d_walls() {
this->get_3d();
return &(this->d3_walls);
}
thdb3ddata * thdb1d::get_3d() {
// vrati 3D data - ale len tie, ktore su oznacene
if (this->d3_data_parsed)
return &(this->d3_data);
this->d3_data_parsed = true;
unsigned long nlegs = this->get_tree_size(),
nstat = this->station_vec.size(), i, last_st, cur_st;
if (nstat <= 0)
return &(this->d3_data);
// najprv tam vlozi meracske bodiky
thdb3dvx ** station_in = new thdb3dvx* [nstat];
// najprv podzemne data
for (i = 0; i < nstat; i++)
station_in[i] = NULL;
#define get_3d_check_station(id) { \
if (station_in[id] == NULL) { \
station_in[id] = this->d3_data.insert_vertex( \
this->station_vec[id].x, \
this->station_vec[id].y, \
this->station_vec[id].z, \
(void *) &(this->station_vec[id])); \
} \
}
// polygony tam vlozi ako linestripy (data poojdu na thdb1dl)
last_st = nstat;
thdb3dfc * fc = NULL, * secfc = NULL, * endsfc = NULL;
thdb3dvx * fsecvx[10], * tsecvx[10];
thdb1dl ** tlegs = this->get_tree_legs();
double secx[10], secy[10], secXx, secXy, secXz,
secYx, secYy, secYz;
thdb1ds * fromst, * tost;
int secn, j, prevj, nextj;
for(i = 0; i < nlegs; i++, tlegs++) {
if ((*tlegs)->survey->is_selected() && (((*tlegs)->leg->flags & TT_LEGFLAG_SURFACE) == 0) && (((*tlegs)->leg->flags & TT_LEGFLAG_SPLAY) == 0)) {
cur_st = this->station_vec[((*tlegs)->reverse ? (*tlegs)->leg->to.id : (*tlegs)->leg->from.id) - 1].uid - 1;
get_3d_check_station(cur_st);
if (cur_st != last_st) {
fc = this->d3_data.insert_face(THDB3DFC_LINE_STRIP);
fc->insert_vertex(station_in[cur_st], (void *) *tlegs);
}
last_st = this->station_vec[((*tlegs)->reverse ? (*tlegs)->leg->from.id : (*tlegs)->leg->to.id) - 1].uid - 1;
get_3d_check_station(last_st);
fc->insert_vertex(station_in[last_st], (void *) *tlegs);
// tu vygeneruje LRUD obalku
if ((*tlegs)->leg->walls == TT_FALSE) goto SKIP_WALLS;
#define secpt(N,X,Y) secx[N] = X; secy[N] = Y;
switch ((*tlegs)->leg->shape) {
case TT_DATALEG_SHAPE_DIAMOND:
secpt(0,0.5,0.0);
secpt(1,1.0,0.5);
secpt(2,0.5,1.0);
secpt(3,0.0,0.5);
secn = 4;
break;
case TT_DATALEG_SHAPE_OCTAGON:
secpt(0,0.292893218813,0.0);
secpt(1,0.707106781167,0.0);
secpt(2,1.0,0.292893218813);
secpt(3,1.0,0.707106781167);
secpt(4,0.707106781167,1.0);
secpt(5,0.292893218813,1.0);
secpt(6,0.0,0.707106781167);
secpt(7,0.0,0.292893218813);
secn = 8;
break;
case TT_DATALEG_SHAPE_TRIANGLE:
secpt(0,0.0,0.0);
secpt(1,1.0,0.0);
secpt(2,0.5,1.0);
secn = 3;
break;
case TT_DATALEG_SHAPE_TUNNEL:
secpt(0,0.0,0.0);
secpt(1,1.0,0.0);
secpt(2,0.904508497187,0.61803398875);
secpt(3,0.654508497187,1.0);
secpt(4,0.345491502823,1.0);
secpt(5,0.095491502823,0.61803398875);
secn = 6;
break;
case TT_DATALEG_SHAPE_RECTANGLE:
default:
secpt(0,0.0,0.0);
secpt(1,1.0,0.0);
secpt(2,1.0,1.0);
secpt(3,0.0,1.0);
secn = 4;
break;
}
// spocitame si X a Y section vectors
secXx = cos((*tlegs)->leg->total_bearing / 180.0 * THPI);
secXy = -sin((*tlegs)->leg->total_bearing / 180.0 * THPI);
secXz = 0;
if (fabs((*tlegs)->leg->total_gradient) < (*tlegs)->leg->vtresh) {
secYx = 0.0;
secYy = 0.0;
secYz = 1.0;
} else {
secYx = -sin((*tlegs)->leg->total_gradient / 180.0 * THPI) * sin((*tlegs)->leg->total_bearing / 180.0 * THPI);
secYy = -sin((*tlegs)->leg->total_gradient / 180.0 * THPI) * cos((*tlegs)->leg->total_bearing / 180.0 * THPI);
secYz = cos((*tlegs)->leg->total_gradient / 180.0 * THPI);
}
secfc = this->d3_walls.insert_face(THDB3DFC_TRIANGLE_STRIP);
endsfc = this->d3_walls.insert_face(THDB3DFC_TRIANGLES);
// vypocitame a vlozime body aj s normalami
fromst = &(this->station_vec[(*tlegs)->leg->from.id - 1]);
tost = &(this->station_vec[(*tlegs)->leg->to.id - 1]);
//#define SYMPASSAGES
for(j = 0; j < secn; j++) {
fsecvx[j] = this->d3_walls.insert_vertex(
#ifdef SYMPASSAGES
fromst->x -
(*tlegs)->leg->from_left * secXx -
(*tlegs)->leg->from_down * secYx +
secx[j] * ((*tlegs)->leg->from_left + (*tlegs)->leg->from_right) * secXx +
secy[j] * ((*tlegs)->leg->from_up + (*tlegs)->leg->from_down) * secYx,
fromst->y -
(*tlegs)->leg->from_left * secXy -
(*tlegs)->leg->from_down * secYy +
secx[j] * ((*tlegs)->leg->from_left + (*tlegs)->leg->from_right) * secXy +
secy[j] * ((*tlegs)->leg->from_up + (*tlegs)->leg->from_down) * secYy,
fromst->z -
(*tlegs)->leg->from_left * secXz -
(*tlegs)->leg->from_down * secYz +
secx[j] * ((*tlegs)->leg->from_left + (*tlegs)->leg->from_right) * secXz +
secy[j] * ((*tlegs)->leg->from_up + (*tlegs)->leg->from_down) * secYz,
#else
fromst->x +
(secx[j] < 0.5 ? (*tlegs)->leg->from_left : (*tlegs)->leg->from_right) * (secx[j] - 0.5) / 0.5 * secXx +
(secy[j] < 0.5 ? (*tlegs)->leg->from_down : (*tlegs)->leg->from_up) * (secy[j] - 0.5) / 0.5 * secYx,
fromst->y +
(secx[j] < 0.5 ? (*tlegs)->leg->from_left : (*tlegs)->leg->from_right) * (secx[j] - 0.5) / 0.5 * secXy +
(secy[j] < 0.5 ? (*tlegs)->leg->from_down : (*tlegs)->leg->from_up) * (secy[j] - 0.5) / 0.5 * secYy,
fromst->z +
(secx[j] < 0.5 ? (*tlegs)->leg->from_left : (*tlegs)->leg->from_right) * (secx[j] - 0.5) / 0.5 * secXz +
(secy[j] < 0.5 ? (*tlegs)->leg->from_down : (*tlegs)->leg->from_up) * (secy[j] - 0.5) / 0.5 * secYz,
#endif
NULL);
tsecvx[j] = this->d3_walls.insert_vertex(
#ifdef SYMPASSAGES
tost->x -
(*tlegs)->leg->to_left * secXx -
(*tlegs)->leg->to_down * secYx +
secx[j] * ((*tlegs)->leg->to_left + (*tlegs)->leg->to_right) * secXx +
secy[j] * ((*tlegs)->leg->to_up + (*tlegs)->leg->to_down) * secYx,
tost->y -
(*tlegs)->leg->to_left * secXy -
(*tlegs)->leg->to_down * secYy +
secx[j] * ((*tlegs)->leg->to_left + (*tlegs)->leg->to_right) * secXy +
secy[j] * ((*tlegs)->leg->to_up + (*tlegs)->leg->to_down) * secYy,
tost->z -
(*tlegs)->leg->to_left * secXz -
(*tlegs)->leg->to_down * secYz +
secx[j] * ((*tlegs)->leg->to_left + (*tlegs)->leg->to_right) * secXz +
secy[j] * ((*tlegs)->leg->to_up + (*tlegs)->leg->to_down) * secYz,
#else
tost->x +
(secx[j] < 0.5 ? (*tlegs)->leg->to_left : (*tlegs)->leg->to_right) * (secx[j] - 0.5) / 0.5 * secXx +
(secy[j] < 0.5 ? (*tlegs)->leg->to_down : (*tlegs)->leg->to_up) * (secy[j] - 0.5) / 0.5 * secYx,
tost->y +
(secx[j] < 0.5 ? (*tlegs)->leg->to_left : (*tlegs)->leg->to_right) * (secx[j] - 0.5) / 0.5 * secXy +
(secy[j] < 0.5 ? (*tlegs)->leg->to_down : (*tlegs)->leg->to_up) * (secy[j] - 0.5) / 0.5 * secYy,
tost->z +
(secx[j] < 0.5 ? (*tlegs)->leg->to_left : (*tlegs)->leg->to_right) * (secx[j] - 0.5) / 0.5 * secXz +
(secy[j] < 0.5 ? (*tlegs)->leg->to_down : (*tlegs)->leg->to_up) * (secy[j] - 0.5) / 0.5 * secYz,
#endif
NULL);
}
// spocitame normaly na vrcholoch
prevj = secn - 1;
for(j = 0; j < secn; j++) {
nextj = j + 1;
if (nextj == secn) nextj = 0;
// zrata normalu medzi vrcholmi prevj - j - nextj
lxVec v1, v2, v3;
v1 = lxVec(fsecvx[j]->x - fsecvx[prevj]->x, fsecvx[j]->y - fsecvx[prevj]->y, fsecvx[j]->z - fsecvx[prevj]->z);
v2 = lxVec(fsecvx[j]->x - fsecvx[nextj]->x, fsecvx[j]->y - fsecvx[nextj]->y, fsecvx[j]->z - fsecvx[nextj]->z);
v3 = lxVec(fsecvx[j]->x - tsecvx[j]->x, fsecvx[j]->y - tsecvx[j]->y, fsecvx[j]->z - tsecvx[j]->z);
v1 = v1 ^ v3; v1.Normalize();
v2 = v2 ^ v3; v2.Normalize();
v3 = v1 - v2; v3.Normalize();
fsecvx[j]->insert_normal(v3.x, v3.y, v3.z);
v1 = lxVec(tsecvx[j]->x - tsecvx[prevj]->x, tsecvx[j]->y - tsecvx[prevj]->y, tsecvx[j]->z - tsecvx[prevj]->z);
v2 = lxVec(tsecvx[j]->x - tsecvx[nextj]->x, tsecvx[j]->y - tsecvx[nextj]->y, tsecvx[j]->z - tsecvx[nextj]->z);
v3 = lxVec(tsecvx[j]->x - fsecvx[j]->x, tsecvx[j]->y - fsecvx[j]->y, tsecvx[j]->z - fsecvx[j]->z);
v1 = v1 ^ v3; v1.Normalize();
v2 = v2 ^ v3; v2.Normalize();
v3 = v2 - v1; v3.Normalize();
tsecvx[j]->insert_normal(v3.x, v3.y, v3.z);
if (j > 1) {
endsfc->insert_vertex(fsecvx[0],NULL);
endsfc->insert_vertex(fsecvx[j - 1],NULL);
endsfc->insert_vertex(fsecvx[j],NULL);
endsfc->insert_vertex(tsecvx[0],NULL);
endsfc->insert_vertex(tsecvx[j],NULL);
endsfc->insert_vertex(tsecvx[j - 1],NULL);
}
prevj = j;
}
// vlozime triangle strip
for(j = 0; j < secn; j++) {
secfc->insert_vertex(fsecvx[j],NULL);
secfc->insert_vertex(tsecvx[j],NULL);
}
secfc->insert_vertex(fsecvx[0],NULL);
secfc->insert_vertex(tsecvx[0],NULL);
// koniec generovania LRUD obalky
SKIP_WALLS:;
}
}
// potom povrchove data
for (i = 0; i < nstat; i++)
station_in[i] = NULL;
#undef get_3d_check_station
#define get_3d_check_station(id) { \
if (station_in[id] == NULL) { \
station_in[id] = this->d3_surface.insert_vertex( \
this->station_vec[id].x, \
this->station_vec[id].y, \
this->station_vec[id].z, \
(void *) &(this->station_vec[id])); \
} \
}
// polygony tam vlozi ako linestripy (data poojdu na thdb1dl)
last_st = nstat;
fc = NULL;
tlegs = this->get_tree_legs();
for(i = 0; i < nlegs; i++, tlegs++) {
if ((*tlegs)->survey->is_selected() && (((*tlegs)->leg->flags & TT_LEGFLAG_SURFACE) != 0) && (((*tlegs)->leg->flags & TT_LEGFLAG_SPLAY) == 0)) {
cur_st = this->station_vec[((*tlegs)->reverse ? (*tlegs)->leg->to.id : (*tlegs)->leg->from.id) - 1].uid - 1;
get_3d_check_station(cur_st);
if (cur_st != last_st) {
fc = this->d3_surface.insert_face(THDB3DFC_LINE_STRIP);
fc->insert_vertex(station_in[cur_st], (void *) *tlegs);
}
last_st = this->station_vec[((*tlegs)->reverse ? (*tlegs)->leg->from.id : (*tlegs)->leg->to.id) - 1].uid - 1;
get_3d_check_station(last_st);
fc->insert_vertex(station_in[last_st], (void *) *tlegs);
}
}
// potom splay data
for (i = 0; i < nstat; i++)
station_in[i] = NULL;
#undef get_3d_check_station
#define get_3d_check_station(id) { \
if (station_in[id] == NULL) { \
station_in[id] = this->d3_splay.insert_vertex( \
this->station_vec[id].x, \
this->station_vec[id].y, \
this->station_vec[id].z, \
(void *) &(this->station_vec[id])); \
} \
}
// polygony tam vlozi ako linestripy (data poojdu na thdb1dl)
last_st = nstat;
fc = NULL;
tlegs = this->get_tree_legs();
for(i = 0; i < nlegs; i++, tlegs++) {
if ((*tlegs)->survey->is_selected() && (((*tlegs)->leg->flags & TT_LEGFLAG_SPLAY) != 0)) {
cur_st = this->station_vec[((*tlegs)->reverse ? (*tlegs)->leg->to.id : (*tlegs)->leg->from.id) - 1].uid - 1;
get_3d_check_station(cur_st);
if (cur_st != last_st) {
fc = this->d3_splay.insert_face(THDB3DFC_LINE_STRIP);
fc->insert_vertex(station_in[cur_st], (void *) *tlegs);
}
last_st = this->station_vec[((*tlegs)->reverse ? (*tlegs)->leg->from.id : (*tlegs)->leg->to.id) - 1].uid - 1;
get_3d_check_station(last_st);
fc->insert_vertex(station_in[last_st], (void *) *tlegs);
}
}
// meracske body tam vlozi ako body (data na dbdb1ds)
delete [] station_in;
return &(this->d3_data);
}
void thdb1d::postprocess_objects()
{
thdb_object_list_type::iterator obi = this->db->object_list.begin();
while (obi != this->db->object_list.end()) {
switch ((*obi)->get_class_id()) {
case TT_SURFACE_CMD:
((thsurface*)(*obi))->check_stations();
break;
}
obi++;
}
// zrata priemerne dlzky shotov pre vsetky stations kvuoli interpolacii
thdb1d_tree_arrow * arrow;
thdb1d_tree_node * node, * nodes = this->get_tree_nodes();
thdb1ds * s;
double numl;
for(unsigned long i = 0; i < this->station_vec.size(); i++) {
s = &(this->station_vec[i]);
if (s->uid < (i + 1)) {
s->asl = this->station_vec[s->uid - 1].asl;
} else {
s->asl = 0.0;
numl = 0;
node = &(nodes[i]);
arrow = node->first_arrow;
while (arrow != NULL) {
if ((arrow->leg->leg->flags & TT_LEGFLAG_SURFACE) == 0) {
s->asl += arrow->leg->leg->total_length;
numl += 1.0;
}
arrow = arrow->next_arrow;
}
if (s->asl == 0.0)
s->asl = thnan;
else
s->asl /= numl;
}
}
}
void thdb1d::process_xelev()
{
unsigned long tn_legs = this->leg_vec.size();
unsigned long tn_stations = this->station_vec.size();
#ifdef THDEBUG
thprintf("\n\nprocessing extended elevation\n");
#else
thprintf("processing extended elevation ... ");
thtext_inline = true;
#endif
// PREPROCESS
thdataextend_list::iterator xi;
thdb1ds * st1;
thdata * dp;
thdb1d_tree_node * nodes = this->get_tree_nodes(), * from_node, * to_node;
thdb1d_tree_arrow * carrow;
thbuffer tmpbf;
thdb_object_list_type::iterator obi = this->db->object_list.begin();
while (obi != this->db->object_list.end()) {
switch ((*obi)->get_class_id()) {
case TT_DATA_CMD:
try {
dp = (thdata *)(*obi);
xi = dp->extend_list.begin();
while(xi != dp->extend_list.end()) {
if (!xi->to.is_empty()) {
// find shot to apply extend to
from_node = nodes + (nodes[xi->from.id - 1].uid - 1);
to_node = nodes + (nodes[xi->to.id - 1].uid - 1);
carrow = from_node->first_arrow;
while (carrow != NULL) {
if (carrow->end_node->uid == to_node->uid)
break;
carrow = carrow->next_arrow;
}
if (carrow == NULL) {
tmpbf = xi->from.name;
if (xi->from.survey != NULL) {
tmpbf += "@";
tmpbf += xi->from.survey;
}
tmpbf += " - ";
tmpbf += xi->to.name;
if (xi->to.survey != NULL) {
tmpbf += "@";
tmpbf += xi->to.survey;
}
ththrow(("survey shot not found -- %s", tmpbf.get_buffer()))
} else {
// the leg is in carrow - set its extend
if ((xi->extend & TT_EXTENDFLAG_DIRECTION) != 0) {
carrow->leg->leg->extend &= ~TT_EXTENDFLAG_DIRECTION;
carrow->extend &= ~TT_EXTENDFLAG_DIRECTION;
}
carrow->extend |= xi->extend;
switch (xi->extend) {
case TT_EXTENDFLAG_LEFT:
if (carrow->is_reversed)
carrow->leg->leg->extend |= TT_EXTENDFLAG_RIGHT;
else
carrow->leg->leg->extend |= TT_EXTENDFLAG_LEFT;
break;
case TT_EXTENDFLAG_RIGHT:
if (carrow->is_reversed)
carrow->leg->leg->extend |= TT_EXTENDFLAG_LEFT;
else
carrow->leg->leg->extend |= TT_EXTENDFLAG_RIGHT;
break;
case TT_EXTENDFLAG_VERTICAL:
carrow->leg->leg->extend |= TT_EXTENDFLAG_VERTICAL;
carrow->negative->extend |= TT_EXTENDFLAG_VERTICAL;
break;
default:
carrow->leg->leg->extend |= xi->extend;
}
}
} else {
// add station extend attribute
st1 = &(this->station_vec[xi->from.id - 1]);
from_node = nodes + (nodes[xi->from.id - 1].uid - 1);
if ((xi->extend & TT_EXTENDFLAG_DIRECTION) != 0) {
st1->extend &= ~TT_EXTENDFLAG_DIRECTION;
}
st1->extend |= xi->extend;
if ((xi->extend & TT_EXTENDFLAG_IGNORE) != 0) {
carrow = from_node->first_arrow;
while (carrow != NULL) {
carrow->leg->leg->extend |= TT_EXTENDFLAG_IGNORE;
carrow->extend |= TT_EXTENDFLAG_IGNORE;
carrow->negative->extend |= TT_EXTENDFLAG_IGNORE;
carrow = carrow->next_arrow;
}
}
if ((xi->extend & TT_EXTENDFLAG_HIDE) != 0) {
carrow = from_node->first_arrow;
while (carrow != NULL) {
carrow->leg->leg->extend |= TT_EXTENDFLAG_HIDE;
carrow->extend |= TT_EXTENDFLAG_HIDE;
carrow->negative->extend |= TT_EXTENDFLAG_HIDE;
carrow = carrow->next_arrow;
}
}
if (xi->extend == TT_EXTENDFLAG_BREAK) {
carrow = from_node->first_arrow;
while (carrow != NULL) {
carrow->extend |= TT_EXTENDFLAG_BREAK;
carrow = carrow->next_arrow;
}
}
}
xi++;
}
}
catch (...)
threthrow(("%s [%d]", xi->srcf.name, xi->srcf.line));
break;
}
obi++;
}
// PREPARE tree for new tremaux
// is_attached to false
unsigned long i;
thdb1d_tree_node * n1, * current_node = NULL;
thdb1d_tree_arrow * a1, * a2;
// vsetky is discovery na false
a1 = this->tree_arrows;
for(i = 0; i < tn_legs; i++) {
a1->is_discovery = false; a1++;
a1->is_discovery = false; a1++;
}
// poojde v modoch normal/ignoreignore
// FIND ROOT STATION AND FIRST SHOT
// + traverse all stations
// + find start in survey in highest level
// + find top entrance
// + find top station
//
// SHOT:
// + find free start shot
// + find free non ignore shot (ak nie ignoreignore)
// EXTEND FROM ROOT
// until everything is calculated
unsigned long tarrows = 0;
bool component_break = true;
bool ignorant_mode = false, just_started = true;
int default_left(1), go_left; // -1 - left, 1 - right, 0 - vertical
int start_level, clevel;
double cxx = 0.0;
while (tarrows < tn_legs) {
if (component_break) {
for(i = 0, n1 = nodes; i < tn_stations; i++, n1++) {
n1->is_attached = false;
}
a1 = this->tree_arrows;
start_level = 0;
a2 = NULL;
for(i = 0; i < 2 * tn_legs; i++) {
if (!a1->is_discovery) {
// only ignore shots left
clevel = 0;
if ((a1->leg->leg->extend & TT_EXTENDFLAG_IGNORE) == 0) {
// non ignore shots left
clevel = 1;
// dead end station
if (a1->start_node->narrows == 1)
clevel = 2;
// entrance station left
if ((this->station_vec[(a1->is_reversed ? (a1->leg->leg->to.id) : (a1->leg->leg->from.id)) - 1].flags & TT_STATIONFLAG_ENTRANCE) != 0)
clevel = 3;
// start station left
if ((this->station_vec[a1->start_node->uid - 1].extend & TT_EXTENDFLAG_START) != 0)
clevel = 4;
// start shot left
if ((a1->extend & TT_EXTENDFLAG_START) != 0)
clevel = 5;
if (a1->start_node->xx_touched)
clevel = 6;
}
if (clevel > start_level) {
start_level = clevel;
a2 = a1;
} else if ((clevel == start_level) && ((a2 == NULL) || (this->station_vec[a1->start_node->uid - 1].z > this->station_vec[a2->start_node->uid - 1].z))) {
a2 = a1;
}
}
a1++;
}
if (start_level == 0)
ignorant_mode = true;
// set up current_node & current_node->last_arrow
if (a2 == NULL) {
thwarning(("not all shots attached to extended elevation"));
break;
}
current_node = a2->start_node;
current_node->last_arrow = a2;
current_node->is_attached = true;
current_node->back_arrow = NULL;
cxx = current_node->xx;
component_break = false;
if (!current_node->xx_touched) {
switch (this->station_vec[current_node->uid - 1].extend & TT_EXTENDFLAG_DIRECTION) {
case TT_EXTENDFLAG_LEFT:
case TT_EXTENDFLAG_REVERSE:
current_node->xx_left = -1;
break;
case TT_EXTENDFLAG_VERTICAL:
current_node->xx_left = 0;
break;
}
}
default_left = current_node->xx_left;
just_started = true;
#ifdef THDEBUG
thprintf("START -- %d (%s@%s)\n", current_node->id,
this->station_vec[current_node->id - 1].name,
this->station_vec[current_node->id - 1].survey->get_full_name());
#endif
}
if (just_started) {
just_started = false;
} else {
// let's make move
bool try_first;
try_first = true;
if (current_node->last_arrow == NULL) {
try_first = false;
current_node->last_arrow = current_node->first_arrow;
}
// find arrow that is not discovery and not ignored (if not ignorant mode)
while (current_node->last_arrow != NULL) {
if ((!current_node->last_arrow->is_discovery) &&
(ignorant_mode || (((current_node->last_arrow->extend & TT_EXTENDFLAG_IGNORE) == 0) && ((current_node->last_arrow->extend & TT_EXTENDFLAG_BREAK) == 0))))
break;
current_node->last_arrow = current_node->last_arrow->next_arrow;
if (try_first && (current_node->last_arrow == NULL)) {
try_first = false;
current_node->last_arrow = current_node->first_arrow;
}
}
}
if (current_node->last_arrow == NULL) {
// go back
if (current_node->back_arrow == NULL)
component_break = true;
else {
current_node = current_node->back_arrow->end_node;
cxx = current_node->xx;
default_left = current_node->xx_left;
#ifdef THDEBUG
thprintf("%d (%s@%s) <-\n", current_node->id,
this->station_vec[current_node->id - 1].name,
this->station_vec[current_node->id - 1].survey->get_full_name());
#endif
}
} else {
// go forward
current_node->last_arrow->is_discovery = true;
current_node->last_arrow->negative->is_discovery = true;
tarrows++;
// set start x
if (current_node->last_arrow->is_reversed)
current_node->last_arrow->leg->leg->txx = cxx;
else
current_node->last_arrow->leg->leg->fxx = cxx;
// change cxx
switch (this->station_vec[current_node->last_arrow->end_node->uid - 1].extend & TT_EXTENDFLAG_DIRECTION) {
case TT_EXTENDFLAG_REVERSE:
default_left = -default_left;
break;
case TT_EXTENDFLAG_LEFT:
default_left = -1;
break;
case TT_EXTENDFLAG_RIGHT:
default_left = 1;
break;
case TT_EXTENDFLAG_VERTICAL:
default_left = 0;
break;
}
current_node->last_arrow->end_node->xx_left = default_left;
go_left = default_left;
if ((current_node->last_arrow->extend &
(TT_EXTENDFLAG_LEFT | TT_EXTENDFLAG_RIGHT
| TT_EXTENDFLAG_REVERSE | TT_EXTENDFLAG_VERTICAL)) == 0) {
switch (current_node->last_arrow->leg->leg->extend & TT_EXTENDFLAG_DIRECTION) {
case TT_EXTENDFLAG_LEFT:
go_left = -1;
if (current_node->last_arrow->is_reversed)
go_left = -go_left;
break;
case TT_EXTENDFLAG_RIGHT:
go_left = 1;
if (current_node->last_arrow->is_reversed)
go_left = -go_left;
break;
case TT_EXTENDFLAG_REVERSE:
go_left = -go_left;
break;
case TT_EXTENDFLAG_VERTICAL:
go_left = 0;
break;
}
} else {
switch (current_node->last_arrow->extend & TT_EXTENDFLAG_DIRECTION) {
case TT_EXTENDFLAG_REVERSE:
go_left = -go_left;
break;
case TT_EXTENDFLAG_LEFT:
go_left = -1;
break;
case TT_EXTENDFLAG_RIGHT:
go_left = 1;
break;
case TT_EXTENDFLAG_VERTICAL:
go_left = 0;
break;
}
}
cxx += double(go_left) * hypot(current_node->last_arrow->leg->leg->total_dx, current_node->last_arrow->leg->leg->total_dy);
// set end x
if (current_node->last_arrow->is_reversed)
current_node->last_arrow->leg->leg->fxx = cxx;
else
current_node->last_arrow->leg->leg->txx = cxx;
#ifdef THDEBUG
thprintf("-> %d (%s@%s)\n", current_node->last_arrow->end_node->id,
this->station_vec[current_node->last_arrow->end_node->id - 1].name,
this->station_vec[current_node->last_arrow->end_node->id - 1].survey->get_full_name());
#endif
if (!current_node->last_arrow->end_node->is_attached) {
current_node->last_arrow->end_node->back_arrow =
current_node->last_arrow->negative;
current_node = current_node->last_arrow->end_node;
current_node->xx = cxx;
if (!current_node->extendx_ok) {
current_node->extendx = cxx;
current_node->extendx_ok = true;
}
current_node->is_attached = true;
current_node->xx_touched = true;
} else {
cxx = current_node->xx;
}
}
} // END OF TREMAUX
#ifdef THDEBUG
thprintf("\nend of extended elevation\n");
#else
thprintf("done\n");
thtext_inline = false;
#endif
}
thdb3ddata * thdb1ds::get_3d_outline() {
if (this->d3_parsed)
return &(this->d3_outline);
this->d3_parsed = true;
using namespace quickhull;
QuickHull<double> qh; // Could be double as well
std::vector<Vector3<double>> pointCloud, originalPointCloud;
std::vector<thdb3dvx*> originalPointCloudUse;
thdb1d_tree_node * n;
thdb1d_tree_arrow * a;
thdb1ds * tt;
n = &(thdb.db1d.tree_nodes[this->uid - 1]);
Vector3<double> fv(this->x, this->y, this->z), tv, txv;
// TODO: Add points to point cloud
// traverse all splay shots from given station, calculate normalized position and add
size_t splaycnt = 0, undercnt = 0;
for(a = n->first_arrow; a != NULL; a = a->next_arrow) {
if ((a->leg->leg->flags & TT_LEGFLAG_SURFACE) == 0) {
tt = &(thdb.db1d.station_vec[a->end_node->uid - 1]);
tv = Vector3<double>(tt->x, tt->y, tt->z);
txv = tv - fv;
try {
txv.normalize();
pointCloud.push_back(txv);
originalPointCloud.push_back(tv);
originalPointCloudUse.push_back(NULL);
if ((a->leg->leg->flags & TT_LEGFLAG_SPLAY) != 0) splaycnt++;
else undercnt++;
} catch (...) {}
}
}
// if there are more then 1 underground shots from this station, add it
if (undercnt > 0) {
pointCloud.push_back(Vector3<double>(0.0, 0.0, 0.0));
originalPointCloud.push_back(fv);
originalPointCloudUse.push_back(NULL);
}
if (splaycnt > 0) {
auto hull = qh.getConvexHull(pointCloud, true, true);
auto indexBuffer = hull.getIndexBuffer();
thdb3dvx * cvx;
thdb3dfc * cfc;
// Read vertices & triangles to d3_outline
if (indexBuffer.size() > 2) {
for(size_t i = 0; i < indexBuffer.size(); i++) {
if (originalPointCloudUse[indexBuffer[i]] == 0) {
Vector3<double> origpos = originalPointCloud[indexBuffer[i]];
cvx = this->d3_outline.insert_vertex(origpos.x, origpos.y, origpos.z);
originalPointCloudUse[indexBuffer[i]] = cvx;
}
}
cfc = this->d3_outline.insert_face(THDB3DFC_TRIANGLES);
for(size_t i = 0; i < indexBuffer.size(); i++) {
cfc->insert_vertex(originalPointCloudUse[indexBuffer[i]]);
}
}
}
return &(this->d3_outline);
}
|