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 3412 3413 3414 3415 3416 3417 3418 3419 3420 3421 3422 3423 3424 3425 3426 3427 3428 3429 3430 3431 3432 3433 3434 3435 3436 3437 3438 3439 3440 3441 3442 3443 3444 3445 3446 3447 3448 3449 3450 3451 3452 3453 3454 3455 3456 3457 3458 3459 3460 3461 3462 3463 3464 3465 3466 3467 3468 3469 3470 3471 3472 3473 3474 3475 3476 3477 3478 3479 3480 3481 3482 3483 3484 3485 3486 3487 3488 3489 3490 3491 3492 3493 3494 3495 3496 3497 3498 3499 3500 3501 3502 3503 3504 3505 3506 3507 3508 3509 3510 3511 3512 3513 3514 3515 3516 3517 3518 3519 3520 3521 3522 3523 3524 3525 3526 3527 3528 3529 3530 3531 3532 3533 3534 3535 3536 3537 3538 3539 3540 3541 3542 3543 3544 3545 3546 3547 3548 3549 3550 3551 3552 3553 3554 3555 3556 3557 3558 3559 3560 3561 3562 3563 3564 3565 3566 3567 3568 3569 3570 3571 3572 3573 3574 3575 3576 3577 3578 3579 3580 3581 3582 3583 3584 3585 3586 3587 3588 3589 3590 3591 3592 3593 3594 3595 3596 3597 3598 3599 3600 3601 3602 3603 3604 3605 3606 3607 3608 3609 3610 3611 3612 3613 3614 3615 3616 3617 3618 3619 3620 3621 3622 3623 3624 3625 3626 3627 3628 3629 3630 3631 3632 3633 3634 3635 3636 3637 3638 3639 3640 3641 3642 3643 3644 3645 3646 3647 3648 3649 3650 3651 3652 3653 3654 3655 3656 3657 3658 3659 3660 3661 3662 3663 3664 3665 3666 3667 3668 3669 3670 3671 3672 3673 3674 3675 3676 3677 3678 3679 3680 3681 3682 3683 3684 3685 3686 3687 3688 3689 3690 3691 3692 3693 3694 3695 3696 3697 3698 3699 3700 3701 3702 3703 3704 3705 3706 3707 3708 3709 3710 3711 3712 3713 3714 3715 3716 3717 3718 3719 3720 3721 3722 3723 3724 3725 3726 3727 3728 3729 3730 3731 3732 3733 3734 3735 3736 3737 3738 3739 3740 3741 3742 3743 3744 3745 3746 3747 3748 3749 3750 3751 3752 3753 3754 3755 3756 3757 3758 3759 3760 3761 3762 3763 3764 3765 3766 3767 3768 3769 3770 3771 3772 3773 3774 3775 3776 3777 3778 3779 3780 3781 3782 3783 3784 3785 3786 3787 3788 3789 3790 3791 3792 3793 3794 3795 3796 3797 3798 3799 3800 3801 3802 3803 3804 3805 3806 3807 3808 3809 3810 3811 3812 3813 3814 3815 3816 3817 3818 3819 3820 3821 3822 3823 3824 3825 3826 3827 3828 3829 3830 3831 3832 3833 3834 3835 3836 3837 3838 3839 3840 3841 3842 3843 3844 3845 3846 3847 3848 3849 3850 3851 3852 3853 3854 3855 3856 3857 3858 3859 3860 3861 3862 3863 3864 3865 3866 3867 3868 3869 3870 3871 3872 3873 3874 3875 3876 3877 3878 3879 3880 3881 3882 3883 3884 3885 3886 3887 3888 3889 3890 3891 3892 3893 3894 3895 3896 3897 3898 3899 3900 3901 3902 3903 3904 3905 3906 3907 3908 3909 3910 3911 3912 3913 3914 3915 3916 3917 3918 3919 3920 3921 3922 3923 3924 3925 3926 3927 3928 3929 3930 3931 3932 3933 3934 3935 3936 3937 3938 3939 3940 3941 3942 3943 3944 3945 3946 3947 3948 3949 3950 3951 3952 3953 3954 3955 3956 3957 3958 3959 3960 3961 3962 3963 3964 3965 3966 3967 3968 3969 3970 3971 3972 3973 3974 3975 3976 3977 3978 3979 3980 3981 3982 3983 3984 3985 3986 3987 3988 3989 3990 3991 3992 3993 3994 3995 3996 3997 3998 3999 4000 4001 4002 4003 4004 4005 4006 4007 4008 4009 4010 4011 4012 4013 4014 4015 4016 4017 4018 4019 4020 4021 4022 4023 4024 4025 4026 4027 4028 4029 4030 4031 4032 4033 4034 4035 4036 4037 4038 4039 4040 4041 4042 4043 4044 4045 4046 4047 4048 4049 4050 4051 4052 4053 4054 4055 4056 4057 4058 4059 4060 4061 4062 4063 4064 4065 4066 4067 4068 4069 4070 4071 4072 4073 4074 4075 4076 4077 4078 4079 4080 4081 4082 4083 4084 4085 4086 4087 4088 4089 4090 4091 4092 4093 4094 4095 4096 4097 4098 4099 4100 4101 4102 4103 4104 4105 4106 4107 4108 4109 4110 4111 4112 4113 4114 4115 4116 4117 4118 4119 4120 4121 4122 4123 4124 4125 4126 4127 4128 4129 4130 4131 4132 4133 4134 4135 4136 4137 4138 4139 4140 4141 4142 4143 4144 4145 4146 4147 4148 4149 4150 4151 4152 4153 4154 4155 4156 4157 4158 4159 4160 4161 4162 4163 4164 4165 4166 4167 4168 4169 4170 4171 4172 4173 4174 4175 4176 4177 4178 4179 4180 4181 4182 4183 4184 4185 4186 4187 4188 4189 4190 4191 4192 4193 4194 4195 4196 4197 4198 4199 4200 4201 4202 4203 4204 4205 4206 4207 4208 4209 4210 4211 4212 4213 4214 4215 4216 4217 4218 4219 4220 4221 4222 4223 4224 4225 4226 4227 4228 4229 4230 4231 4232 4233 4234 4235 4236 4237 4238 4239 4240 4241 4242 4243 4244 4245 4246 4247 4248 4249 4250 4251 4252 4253 4254 4255 4256 4257 4258 4259 4260 4261 4262 4263 4264 4265 4266 4267 4268 4269 4270 4271 4272 4273 4274 4275 4276 4277 4278 4279 4280 4281 4282 4283 4284 4285 4286 4287 4288 4289 4290 4291 4292 4293 4294 4295 4296 4297 4298 4299 4300 4301 4302 4303 4304 4305 4306 4307 4308 4309 4310 4311 4312 4313 4314 4315 4316 4317 4318 4319 4320 4321 4322 4323 4324 4325 4326 4327 4328 4329 4330 4331 4332 4333 4334 4335 4336 4337 4338 4339 4340 4341 4342 4343 4344 4345 4346 4347 4348 4349 4350 4351 4352 4353 4354 4355 4356 4357 4358 4359 4360 4361 4362 4363 4364 4365 4366 4367 4368 4369 4370 4371 4372 4373 4374 4375 4376 4377 4378 4379 4380 4381 4382 4383 4384 4385 4386 4387 4388 4389 4390 4391 4392 4393 4394 4395 4396 4397 4398 4399 4400 4401 4402 4403 4404 4405 4406 4407 4408 4409 4410 4411 4412 4413 4414 4415 4416 4417 4418 4419 4420 4421 4422 4423 4424 4425 4426 4427 4428 4429 4430 4431 4432 4433 4434 4435 4436 4437 4438 4439 4440 4441 4442 4443 4444 4445 4446 4447 4448 4449 4450 4451 4452 4453 4454 4455 4456 4457 4458 4459 4460 4461 4462 4463 4464 4465 4466 4467 4468 4469 4470 4471 4472 4473 4474 4475 4476 4477 4478 4479 4480 4481 4482 4483 4484 4485 4486 4487 4488 4489 4490 4491 4492 4493 4494 4495 4496 4497 4498 4499 4500 4501 4502 4503 4504 4505 4506 4507 4508 4509 4510 4511 4512 4513 4514 4515 4516 4517 4518 4519 4520 4521 4522 4523 4524 4525 4526 4527 4528 4529 4530 4531 4532 4533 4534 4535 4536 4537 4538 4539 4540 4541 4542 4543 4544 4545 4546 4547 4548 4549 4550 4551 4552 4553 4554 4555 4556 4557 4558 4559 4560 4561 4562 4563 4564 4565 4566 4567 4568 4569 4570 4571 4572 4573 4574 4575 4576 4577 4578 4579 4580 4581 4582 4583 4584 4585 4586 4587 4588 4589 4590 4591 4592 4593 4594 4595 4596 4597 4598 4599 4600 4601 4602 4603 4604 4605 4606 4607 4608 4609 4610 4611 4612 4613 4614 4615 4616 4617 4618 4619 4620 4621 4622 4623 4624 4625 4626 4627 4628 4629 4630 4631 4632 4633 4634 4635 4636 4637 4638 4639 4640 4641 4642 4643 4644 4645 4646 4647 4648 4649 4650 4651 4652 4653 4654 4655 4656 4657 4658 4659 4660 4661 4662 4663 4664 4665 4666 4667 4668 4669 4670 4671 4672 4673 4674 4675 4676 4677 4678 4679 4680 4681 4682 4683 4684 4685 4686 4687 4688 4689 4690 4691 4692 4693 4694 4695 4696 4697 4698 4699 4700 4701 4702 4703 4704 4705 4706 4707 4708 4709 4710 4711 4712 4713 4714 4715 4716 4717 4718 4719 4720 4721 4722 4723 4724 4725 4726 4727 4728 4729 4730 4731 4732 4733 4734 4735 4736 4737 4738 4739 4740 4741 4742 4743 4744 4745 4746 4747 4748 4749 4750 4751 4752 4753 4754 4755 4756 4757 4758 4759 4760 4761 4762 4763 4764 4765 4766 4767 4768 4769 4770 4771 4772 4773 4774 4775 4776 4777 4778 4779 4780 4781 4782 4783 4784 4785 4786 4787 4788 4789 4790 4791 4792 4793 4794 4795 4796 4797 4798 4799 4800 4801 4802 4803 4804 4805 4806 4807 4808 4809 4810 4811 4812 4813 4814 4815 4816 4817 4818 4819 4820 4821 4822 4823 4824 4825 4826 4827 4828 4829 4830 4831 4832 4833 4834 4835 4836 4837 4838 4839 4840 4841 4842 4843 4844 4845 4846 4847 4848 4849 4850 4851 4852 4853 4854 4855 4856 4857 4858 4859 4860 4861 4862 4863 4864 4865 4866 4867 4868 4869 4870 4871 4872 4873 4874 4875 4876 4877 4878 4879 4880 4881 4882 4883 4884 4885 4886 4887 4888 4889 4890 4891 4892 4893 4894 4895 4896 4897 4898 4899 4900 4901 4902 4903 4904 4905 4906 4907 4908 4909 4910 4911 4912 4913 4914 4915 4916 4917 4918 4919 4920 4921 4922 4923 4924 4925 4926 4927 4928 4929
|
/*
* plotX11_3D.c - X11 routines for 3D plots
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include "plotX11.h"
#include "CNplot.h"
#define MAX_ARR_SIZE 1000
#define X_AXIS 1
#define Y_AXIS 2
#define Z_AXIS 3
/*
* FORWARD DECLARATIONS
*/
void PXdrawplotX3D();
static void initXplot3D();
static void drawXplot3D();
static void plotX3D_labels();
static void plotX3D_guides();
static void plotX3D_poly_guides();
static void drawX3D_frame();
static void paintX3D_inner_planes();
static void drawX3D_static_axes();
static void drawX3D_dynamic_axes();
static void drawX3D_axis();
static void plotX3D_ticks();
static void plotX3D_Auto_ticks();
static void plotX3D_User_ticks();
static void drawX3D_line();
static void paintX3D_poly4();
static void plotX3D_ticklabel();
static int ticklabel_overlap();
static void plotX3D_label();
static void plotX3D();
static void plotX3D_grid();
static void plotX3D_mesh4D();
static void plotX3D_mesh4D_cube();
static void plotX3D_vectors();
static void plotX3D_boundary();
static void plotX3D_trias();
static void plotX3D_rects();
static void plotX3D_polys();
static void plotX3D_single_solid_tria();
static void plotX3D_single_solid_rect();
static void plotX3D_single_solid_poly();
static void plotX3D_single_fill_tria();
static void plotX3D_single_fill_rect();
static void plotX3D_single_fill_poly();
static void plotX3D_nodes();
static void plotX3D_dataset_curves();
static void plotX3D_curve();
static void fillX3D_curve();
static void plotX3D_spline_curve();
static void plotX3D_markers();
static void plotX3D_pointIDs();
static void plotX3D_nodeIDs();
static void plotX3D_triaIDs();
static void plotX3D_rectIDs();
static void annotateX3D();
static void plotX3D_single_annotation();
static void plotX3D_annot_rect();
static void plotX3D_annot_line();
static void plotX3D_annot_arrow();
static void plotX3D_arrow();
static void plotX3D_annot_point();
static void plotX3D_annot_text();
static void clipX3D_in_xmin();
static void clipX3D_in_ymin();
static void clipX3D_in_zmin();
static void clipX3D_in_xmax();
static void clipX3D_in_ymax();
static void clipX3D_in_zmax();
static void plotX3D_sidelabels();
static void trn_world_to_X11();
/* Plot variables */
static short grid;
static short clip;
static short xabs, yabs, zabs;
static short xlog, ylog, zlog;
static short xticks, yticks, zticks;
static short xautorange, yautorange, zautorange;
static double xscale, yscale, zscale;
static short overlay;
static int plotlabels;
static char xlabel[MAXCHR];
static char ylabel[MAXCHR];
static char zlabel[MAXCHR];
static char toplabel[MAXCHR];
static char *comment;
static char *subtitle;
static short printdate;
static short axis_label; /* Label the axes */
static short axis_movement; /* Axis response to changing views */
static short axis_guides; /* Draw axis guides */
static short paint_cube; /* Paint the background */
static short hiddenline; /* Do hiddenline plots */
static short quick_sort; /* Use quicksort algorithm */
static short nosort; /* Don't sort */
/* The plotset */
static CNplotsetptr plotdata=NULL;
/* contour steps */
static CNcontstepptr cstephead=NULL;
static CNcontstepptr csteptail=NULL;
/* Contour dptr */
static CNdatasetptr contour_dptr=NULL;
/* The real-world dimensions of the plot */
static double xmin, xmax, ymin, ymax, zmin, zmax;
/* The view transformation matrix */
static CNmatrix view_transfo;
/*
* draw the plot
*/
void PXdrawplotX3D(pdata,
prtdate,
disp, wind, pix, gc0, gc1, font0, font1, width, height,
xxmin, xxmax, xymin, xymax, frame_only)
CNplotsetptr pdata;
int prtdate;
Display *disp;
Window wind;
Pixmap pix;
GC gc0, gc1;
XFontStruct *font0, *font1;
int width, height;
int *xxmin, *xxmax, *xymin, *xymax;
int frame_only;
{
XRectangle rectangles[1];
/* Initialize static global variables */
initXplot3D(pdata, prtdate,
disp, wind, pix, gc0, gc1, font0, font1, width, height);
/* clip if necessary */
if (clip) {
rectangles[0].x = 0;
rectangles[0].y = 0;
rectangles[0].width = width;
rectangles[0].height = height;
XSetClipRectangles(display,gc ,1,0,rectangles,1,Unsorted);
XSetClipRectangles(display,gcl,1,0,rectangles,1,Unsorted);
}
/* Draw the plot */
drawXplot3D(frame_only);
/* Unclip */
if (clip) {
XSetClipMask(display,gc ,None);
XSetClipMask(display,gcl,None);
}
/* return xxmin, xxmax etc */
*xxmin = Xxmin;
*xxmax = Xxmax;
*xymin = Xymin;
*xymax = Xymax;
}
/*
* initialize the plot window
*/
static void initXplot3D(pdata,
prtdate,
disp, wind, pix, gc0, gc1, font0, font1, width, height)
CNplotsetptr pdata;
int prtdate;
Display *disp;
Window wind;
Pixmap pix;
GC gc0, gc1;
XFontStruct *font0, *font1;
int width, height;
{
int PXquery_labels();
void PXcheck_viewport();
void PXconvert_viewport_to_log();
double bxmin, bxmax, bymin, bymax, bzmin, bzmax;
double lxmin, lxmax, lymin, lymax, lzmin, lzmax;
int Xxwid, Xywid;
char label[CN_MAXCHAR];
/* Copy the variables to the static variables first */
plotdata = pdata;
/* Initialize some other plot variables */
grid = plotdata->plot_pr.grid;
xabs = plotdata->plot_pr.xabs;
yabs = plotdata->plot_pr.yabs;
zabs = plotdata->plot_pr.zabs;
xlog = plotdata->plot_pr.xlog;
ylog = plotdata->plot_pr.ylog;
zlog = plotdata->plot_pr.zlog;
xticks = plotdata->plot_pr.xticks;
yticks = plotdata->plot_pr.yticks;
zticks = plotdata->plot_pr.zticks;
xautorange = plotdata->plot_pr.xautorange;
yautorange = plotdata->plot_pr.yautorange;
zautorange = plotdata->plot_pr.zautorange;
xscale = plotdata->plot_pr.xscale; if (xscale <= 0) xscale = 1.0;
yscale = plotdata->plot_pr.yscale; if (yscale <= 0) yscale = 1.0;
zscale = plotdata->plot_pr.zscale; if (zscale <= 0) zscale = 1.0;
overlay = plotdata->plot_pr.overlay;
clip = CN_TRUE;
axis_label = plotdata->view_pr->axis_label;
axis_movement = plotdata->view_pr->axis_movement;
axis_guides = plotdata->view_pr->axis_guides;
paint_cube = plotdata->view_pr->paint_cube;
hiddenline = plotdata->view_pr->hiddenline;
quick_sort = CN_TRUE;
nosort = CN_FALSE;
printdate = prtdate;
plotlabels = PXquery_labels(plotdata);
/* User-specified axis labels? */
if (plotdata->plot_pr.xlabelhead != NULL) {
xlog = CN_FALSE;
xabs = CN_FALSE;
}
if (plotdata->plot_pr.ylabelhead != NULL) {
ylog = CN_FALSE;
yabs = CN_FALSE;
}
if (plotdata->plot_pr.zlabelhead != NULL) {
zlog = CN_FALSE;
zabs = CN_FALSE;
}
/* xlabel */
if (plotdata->plot_pr.xlabel == NULL)
(void) strcpy(xlabel , CN_DEF_XLABEL);
else
(void) strcpy(xlabel , plotdata->plot_pr.xlabel);
if (xscale != 1.0) {
(void) sprintf(label," (x %g)",xscale);
(void) strcat(xlabel, label);
}
/* ylabel */
if (plotdata->plot_pr.ylabel == NULL)
(void) strcpy(ylabel , CN_DEF_YLABEL);
else
(void) strcpy(ylabel , plotdata->plot_pr.ylabel);
if (yscale != 1.0) {
(void) sprintf(label," (x %g)",yscale);
(void) strcat(ylabel, label);
}
/* zlabel */
if (plotdata->plot_pr.zlabel == NULL)
(void) strcpy(zlabel , CN_DEF_ZLABEL);
else
(void) strcpy(zlabel , plotdata->plot_pr.zlabel);
if (zscale != 1.0) {
(void) sprintf(label," (x %g)",zscale);
(void) strcat(zlabel, label);
}
/* Toplabel */
if (plotdata->plot_pr.toplabel == NULL)
(void) strcpy(toplabel , CN_DEF_TLABEL);
else
(void) strcpy(toplabel , plotdata->plot_pr.toplabel);
/* Comment & subtitle */
comment = plotdata->plot_pr.comment;
subtitle= plotdata->plot_pr.subtitle;
/* Copy the X11-data to static variables */
display = disp;
window = wind;
pixmap = pix;
font_info = font0;
lblfont_info = font1;
gc = gc0;
gcl = gc1;
font_height = font_info->max_bounds.ascent +
font_info->max_bounds.descent;
font_width = font_info->max_bounds.rbearing -
font_info->max_bounds.lbearing;
lblfont_height=lblfont_info->max_bounds.ascent +
lblfont_info->max_bounds.descent;
/* Reset the plotset boundaries */
CNset_plotset_boundaries(pdata,
&bxmin, &bxmax, &bymin, &bymax, &bzmin, &bzmax);
/* The viewport */
xmin = plotdata->plot_pr.vxmin;
xmax = plotdata->plot_pr.vxmax;
ymin = plotdata->plot_pr.vymin;
ymax = plotdata->plot_pr.vymax;
zmin = plotdata->plot_pr.vzmin;
zmax = plotdata->plot_pr.vzmax;
/*
* Check and fix the viewport
*/
PXcheck_viewport(&xmin,&xmax,bxmin,bxmax,&xlog,xabs,CN_FALSE,"x");
plotdata->plot_pr.vxmax = xmax;
plotdata->plot_pr.vxmin = xmin;
plotdata->plot_pr.xlog = xlog;
PXcheck_viewport(&ymin,&ymax,bymin,bymax,&ylog,yabs,CN_FALSE,"y");
plotdata->plot_pr.vymax = ymax;
plotdata->plot_pr.vymin = ymin;
plotdata->plot_pr.ylog = ylog;
PXcheck_viewport(&zmin,&zmax,bzmin,bzmax,&zlog,zabs,CN_FALSE,"z");
plotdata->plot_pr.vzmax = zmax;
plotdata->plot_pr.vzmin = zmin;
plotdata->plot_pr.zlog = zlog;
/*
* If log axes then convert the boundary values.
* The axes will be drawn from lxmin-lxmax,lymin-lymax,lzmin-lzmax;
* this is as if a linear set of axes was specified with those
* boundaries. However, the curves to be plotted in the plot() routine
* still have to be adjusted for log-scale
*/
PXconvert_viewport_to_log(&lxmin, &lxmax, xmin, xmax, xlog, xautorange);
PXconvert_viewport_to_log(&lymin, &lymax, ymin, ymax, ylog, yautorange);
PXconvert_viewport_to_log(&lzmin, &lzmax, zmin, zmax, zlog, zautorange);
xmin = lxmin;
xmax = lxmax;
ymin = lymin;
ymax = lymax;
zmin = lzmin;
zmax = lzmax;
/* Save the plot viewport */
plotdata->plot_pr.pxmin = xmin;
plotdata->plot_pr.pxmax = xmax;
plotdata->plot_pr.pymin = ymin;
plotdata->plot_pr.pymax = ymax;
plotdata->plot_pr.pzmin = zmin;
plotdata->plot_pr.pzmax = zmax;
/* Recalculate the view_transfo - but don't adjust the window */
CNreinitialize_view(pdata->view_pr,xmin,xmax,ymin,ymax,zmin,zmax);
/* The view transformation */
CNcopy_matrix(view_transfo, pdata->view_pr->view_transfo);
/*
* Initialize dimensions
* Use a square viewport
* the square width is the smaller of (width,height)
*/
Width = width;
Height= height;
Xxmin = DEFAULT_BDR_DIM;
Xymin = DEFAULT_BDR_DIM;
Xxwid = Width - 2*DEFAULT_BDR_DIM;
if (plotlabels) Xxwid -= plotlabels*LABEL_WIDTH;
Xywid = Height - 2*DEFAULT_BDR_DIM;
if (Xxwid < 0) Xxwid = DEFAULT_BDR_DIM;
if (Xywid < 0) Xywid = DEFAULT_BDR_DIM;
Xxmax = Xxmin + Xxwid;
Xymax = Xymin + Xywid;
/*
* The size of the plot is Xxwid x Xywid (Xxwid = Xywid);
* try to fit the plot in the center of the window defined by
* (0,0) - (Width, Height)
*/
if (Xywid > Xxwid) {
Xywid = Xxwid;
Xymin = (int)(0.5*(Xymin + Xymax) - 0.5*Xywid);
Xymax = Xymin + Xywid;
}
if (Xywid < Xxwid) {
Xxwid = Xywid;
Xxmin = (int)(0.5*(Xxmin + Xxmax) - 0.5*Xxwid);
Xxmax = Xxmin + Xxwid;
}
}
/*
* Draw the plot in X11
* The axes could be dynamic, that is, they adjust to a changing view
* or static meaning they are fixed to certain coordinates.
*/
static void drawXplot3D(frame_only)
int frame_only;
{
CNcoord pta, ptb, ptc, ptd;
void PXfind_outer_axes();
/* Set contour levels for the contour-type datasets */
cstephead = NULL;
csteptail = NULL;
PXquery_contours(plotdata,&cstephead,&csteptail,&contour_dptr);
/*
* Find the outer-most points on the axes according to view
*/
PXfind_outer_axes(xmin, ymin, zmin, xmax, ymax, zmax, view_transfo,
&pta, &ptb, &ptc, &ptd);
/* Put on labels */
plotX3D_labels();
/*
* Now draw the axes
*/
/* Paint the background of the cube if necessary */
if (paint_cube) paintX3D_inner_planes(&pta, &ptb, &ptc, &ptd);
/* Draw the frame with dotted lines for back-side axes */
drawX3D_frame(&pta, &ptb, &ptc, &ptd, 0);
if (frame_only) return;
/*
* Draw the plot
*/
plotX3D();
/*
* Draw the annotations
*/
annotateX3D();
/*
* Redraw the axes
*/
/* Redraw the frame to account for axes obscured during data plotting */
drawX3D_frame(&pta, &ptb, &ptc, &ptd, 1);
/* Put on the labels */
if (axis_label) {
if (axis_movement == 1)
drawX3D_static_axes();
else
drawX3D_dynamic_axes(&pta, &ptb, &ptc, &ptd);
}
/* Delete contour step-levels */
CNdelete_contstep_list(&cstephead, &csteptail);
}
/*
* DRAW LABELS
*/
static void plotX3D_labels()
{
char time[MAXCHR];
int text_len, text_width, text_xpos, text_ypos;
/* Top Label */
text_len = strlen(toplabel);
text_width = XTextWidth(font_info,toplabel,text_len);
text_xpos = (Xxmin + Xxmax - text_width)/2;
text_ypos = Xymin - (font_height+lblfont_height);
if (window)
XDrawString(display,window,gc,text_xpos,text_ypos,toplabel,text_len);
if (pixmap)
XDrawString(display,pixmap,gc,text_xpos,text_ypos,toplabel,text_len);
/* Comment */
if (comment != NULL) {
text_len = strlen(comment);
text_width = XTextWidth(font_info,comment,text_len);
text_xpos = Width - 10 - text_width;
text_ypos = 1.2*font_height;
if (window)
XDrawString(display,window,gc,text_xpos,text_ypos,comment,text_len);
if (pixmap)
XDrawString(display,pixmap,gc,text_xpos,text_ypos,comment,text_len);
}
/* Subtitle */
if (subtitle != NULL) {
text_len = strlen(subtitle);
text_width = XTextWidth(lblfont_info,subtitle,text_len);
text_xpos = (Xxmin + Xxmax - text_width)/2;
text_ypos = Xymin - lblfont_height;
if (window)
XDrawString(display,window,gcl,text_xpos,text_ypos,subtitle,text_len);
if (pixmap)
XDrawString(display,pixmap,gcl,text_xpos,text_ypos,subtitle,text_len);
}
/* Draw the plot labels */
if (plotlabels) plotX3D_sidelabels();
/* put on a time label */
if (printdate) {
CNget_localtime(time,MAXCHR);
text_len = strlen(time);
text_width = XTextWidth(font_info,time,text_len);
text_xpos = 10 ;
text_ypos = 1.2*font_height;
XSetForeground(display,gc,background_pixel);
if (window)
XFillRectangle(display,window,gc, text_xpos, 0, text_width, text_ypos);
if (pixmap)
XFillRectangle(display,pixmap,gc, text_xpos, 0, text_width, text_ypos);
XSetForeground(display,gc,foreground_pixel);
if (window)
XDrawString(display,window,gc,text_xpos,text_ypos,time,text_len);
if (pixmap)
XDrawString(display,pixmap,gc,text_xpos,text_ypos,time,text_len);
}
/* Draw a set of guides */
if (axis_guides) plotX3D_guides();
}
/*
* Draw a set of small axes to use as a guide
*/
static void plotX3D_guides()
{
char labelx[10];
char labely[10];
char labelz[10];
int text_len, text_width, text_xpos, text_ypos;
double x0,y0,vx_x,vx_y,vy_x,vy_y,vz_x,vz_y;
double dx,dy,dz,delt;
double min_x, min_y, wid_x, wid_y, MAXLEN;
/* Initialize the labels */
(void) strcpy(labelx, "X");
(void) strcpy(labely, "Y");
(void) strcpy(labelz, "Z");
/*
if (strlen(xlabel) > 0) labelx[0] = xlabel[0];
if (strlen(ylabel) > 0) labely[0] = ylabel[0];
if (strlen(zlabel) > 0) labelz[0] = zlabel[0];
*/
wid_x = 100.0;
wid_y = 100.0;
min_x = 10.0;
min_y = Height - wid_y - 2.5*font_height;
MAXLEN = 40.0;
(void) PXlinetypX(CN_LN_SOLID, 2);
XSetForeground(display,gc,background_pixel);
if (window)
XFillRectangle(display,window,gc,
(int)(min_x),(int)(min_y),(int)(wid_x),(int)(wid_y));
if (pixmap)
XFillRectangle(display,pixmap,gc,
(int)(min_x),(int)(min_y),(int)(wid_x),(int)(wid_y));
XSetForeground(display,gc,foreground_pixel);
/* Figure out the 3D vectors, i.e. X,Y,Z, axis directions */
delt = MAXOF3(xmax-xmin, ymax-ymin, zmax-zmin);
trn_world_to_X11(0.0 ,0.0 ,0.0, &x0,&y0);
trn_world_to_X11(delt ,0.0 ,0.0, &vx_x,&vx_y);
trn_world_to_X11(0.0 ,delt ,0.0, &vy_x,&vy_y);
trn_world_to_X11(0.0 ,0.0 ,delt ,&vz_x,&vz_y);
/* Get the direction vectors */
vx_x -= x0; vx_y -= y0; dx = sqrt(vx_x*vx_x + vx_y*vx_y);
vy_x -= x0; vy_y -= y0; dy = sqrt(vy_x*vy_x + vy_y*vy_y);
vz_x -= x0; vz_y -= y0; dz = sqrt(vz_x*vz_x + vz_y*vz_y);
/* Scale the vectors */
if (dx > 1e-2) { vx_x = MAXLEN*vx_x/dx; vx_y = MAXLEN*vx_y/dx;}
if (dy > 1e-2) { vy_x = MAXLEN*vy_x/dy; vy_y = MAXLEN*vy_y/dy;}
if (dz > 1e-2) { vz_x = MAXLEN*vz_x/dz; vz_y = MAXLEN*vz_y/dz;}
/* Now draw the lines */
x0 = min_x + 0.5*wid_x;
y0 = min_y + 0.5*wid_y;
if (window) {
XDrawLine(display,window,gc,
(int)(x0),(int)(y0),(int)(x0+vx_x),(int)(y0+vx_y));
XDrawLine(display,window,gc,
(int)(x0),(int)(y0),(int)(x0+vy_x),(int)(y0+vy_y));
XDrawLine(display,window,gc,
(int)(x0),(int)(y0),(int)(x0+vz_x),(int)(y0+vz_y));
}
if (pixmap) {
XDrawLine(display,pixmap,gc,
(int)(x0),(int)(y0),(int)(x0+vx_x),(int)(y0+vx_y));
XDrawLine(display,pixmap,gc,
(int)(x0),(int)(y0),(int)(x0+vy_x),(int)(y0+vy_y));
XDrawLine(display,pixmap,gc,
(int)(x0),(int)(y0),(int)(x0+vz_x),(int)(y0+vz_y));
}
/* Draw polygons representing the planes */
plotX3D_poly_guides(x0,y0,vx_x,vx_y,vy_x,vy_y,vz_x,vz_y);
/* Put on axis labels */
text_len = strlen(labelx);
text_width = XTextWidth(lblfont_info,labelx,text_len);
text_xpos = (int)(x0 + 1.2*vx_x - 0.5*text_width);
text_ypos = (int)(y0 + 1.2*vx_y + 0.5*lblfont_height);
if (window)
XDrawString(display,window,gcl,text_xpos,text_ypos,labelx,text_len);
if (pixmap)
XDrawString(display,pixmap,gcl,text_xpos,text_ypos,labelx,text_len);
text_xpos = (int)(x0 + 1.2*vy_x - 0.5*text_width);
text_ypos = (int)(y0 + 1.2*vy_y + 0.5*lblfont_height);
if (window)
XDrawString(display,window,gcl,text_xpos,text_ypos,labely,text_len);
if (pixmap)
XDrawString(display,pixmap,gcl,text_xpos,text_ypos,labely,text_len);
text_xpos = (int)(x0 + 1.2*vz_x - 0.5*text_width);
text_ypos = (int)(y0 + 1.2*vz_y + 0.5*lblfont_height);
if (window)
XDrawString(display,window,gcl,text_xpos,text_ypos,labelz,text_len);
if (pixmap)
XDrawString(display,pixmap,gcl,text_xpos,text_ypos,labelz,text_len);
(void) PXlinetypX(CN_LN_SOLID, 1);
}
/*
* Draw a set of small axes to use as a guide
*/
static void plotX3D_poly_guides(x0,y0,vx_x,vx_y,vy_x,vy_y,vz_x,vz_y)
double x0,y0,vx_x,vx_y,vy_x,vy_y,vz_x,vz_y;
{
#define XY 1
#define XZ 2
#define YZ 3
XPoint xz_plane[5], yz_plane[5], xy_plane[5];
CNcoord xz_point, yz_point, xy_point;
int arr[3], i;
int fillcolor, linecolor;
double LEN=0.5;
/* Build polygons to represent the planes */
xz_plane[0].x=(int)(x0); xz_plane[0].y=(int)(y0);
xz_plane[1].x=(int)(x0+LEN*vx_x); xz_plane[1].y=(int)(y0+LEN*vx_y);
xz_plane[2].x=(int)(x0+LEN*vx_x+LEN*vz_x); xz_plane[2].y=(int)(y0+LEN*vx_y+LEN*vz_y);
xz_plane[3].x=(int)(x0+LEN*vz_x); xz_plane[3].y=(int)(y0+LEN*vz_y);
xz_plane[4].x=(int)(x0); xz_plane[4].y=(int)(y0);
yz_plane[0].x=(int)(x0); yz_plane[0].y=(int)(y0);
yz_plane[1].x=(int)(x0+LEN*vy_x); yz_plane[1].y=(int)(y0+LEN*vy_y);
yz_plane[2].x=(int)(x0+LEN*vy_x+LEN*vz_x); yz_plane[2].y=(int)(y0+LEN*vy_y+LEN*vz_y);
yz_plane[3].x=(int)(x0+LEN*vz_x); yz_plane[3].y=(int)(y0+LEN*vz_y);
yz_plane[4].x=(int)(x0); yz_plane[4].y=(int)(y0);
xy_plane[0].x=(int)(x0); xy_plane[0].y=(int)(y0);
xy_plane[1].x=(int)(x0+LEN*vx_x); xy_plane[1].y=(int)(y0+LEN*vx_y);
xy_plane[2].x=(int)(x0+LEN*vx_x+LEN*vy_x); xy_plane[2].y=(int)(y0+LEN*vx_y+LEN*vy_y);
xy_plane[3].x=(int)(x0+LEN*vy_x); xy_plane[3].y=(int)(y0+LEN*vy_y);
xy_plane[4].x=(int)(x0); xy_plane[4].y=(int)(y0);
/* Figure out the order of the planes by comparing z-values of points */
xz_point.x = 1.0; xz_point.y = 0.0; xz_point.z = 1.0;
yz_point.x = 0.0; yz_point.y = 1.0; yz_point.z = 1.0;
xy_point.x = 1.0; xy_point.y = 1.0; xy_point.z = 0.0;
xz_point = CNtransform_point(&xz_point,view_transfo);
yz_point = CNtransform_point(&yz_point,view_transfo);
xy_point = CNtransform_point(&xy_point,view_transfo);
if ((xy_point.z > xz_point.z) && (xy_point.z > yz_point.z)) {
arr[0] = XY;
arr[1] = (xz_point.z > yz_point.z) ? XZ : YZ;
arr[2] = (xz_point.z > yz_point.z) ? YZ : XZ;
} else if ((xz_point.z > xy_point.z) && (xz_point.z > yz_point.z)) {
arr[0] = XZ;
arr[1] = (xy_point.z > yz_point.z) ? XY : YZ;
arr[2] = (xy_point.z > yz_point.z) ? YZ : XY;
} else {
arr[0] = YZ;
arr[1] = (xy_point.z > xz_point.z) ? XY : XZ;
arr[2] = (xy_point.z > xz_point.z) ? XZ : XY;
}
/* Reset the linetype */
(void) PXlinetypX(CN_LN_SOLID, 1);
/* Now draw small filled polygons */
fillcolor = PXpolyColorIndexX(1); /* yellow */
linecolor = PXpolyColorIndexX(4); /* red */
for (i=2; i>=0; i--) {
switch (arr[i]) {
case XY :
PXfillX_polygon(xy_plane,5,
CN_FILL_SOLID,fillcolor,CN_LN_SOLID,linecolor,1);
break;
case XZ :
PXfillX_polygon(xz_plane,5,
CN_FILL_SOLID,fillcolor,CN_LN_SOLID,linecolor,1);
break;
case YZ :
default :
PXfillX_polygon(yz_plane,5,
CN_FILL_SOLID,fillcolor,CN_LN_SOLID,linecolor,1);
break;
}
}
/* Reset */
PXsetColorX(0);
}
/*
* DRAW AXIS FRAME AND PANELS
*/
/*
* Draw the frame of the cube using given coordinates.
* The axes on the back side of the cube are dotted
*/
static void drawX3D_frame(pta, ptb, ptc, ptd, outside)
CNcoord *pta, *ptb, *ptc, *ptd;
int outside;
{
CNcoord pte, ptf, ptg, pth;
CNcoord ptft, ptht;
/*
* pts a-d are 4 points on the outer frame
* e and g are points on the outside of the frame.
* f and h are points on the inside of the frame.
* either h or f could be obscured (i.e. in the inner corner)
*
* ______ /|\e
* a |\ .\ e / | \
* | \ . \ / | \
* | h\_____\ g a|. |f .|g
* b |..|... | | ./ \. |
* \ | f. | | /.h.\ |
* \| .| b|/ . \|
* ------ \ . /d
* c d \ . /
* c\./
*
* identify e and f from a-d
* e is diagonally opposite to c
* f is diagonally opposite to c, but with the same z-value
* g has a different z-value compared to d
* h has a different z-value compared to c
*/
pte.x = (ptc->x == xmin) ? xmax : xmin;
pte.y = (ptc->y == ymin) ? ymax : ymin;
pte.z = (ptc->z == zmin) ? zmax : zmin;
ptf.x = pte.x;
ptf.y = pte.y;
ptf.z = ptc->z;
ptg.x = ptd->x;
ptg.y = ptd->y;
ptg.z = (ptd->z == zmin) ? zmax : zmin;
pth.x = ptc->x;
pth.y = ptc->y;
pth.z = (ptc->z == zmin) ? zmax : zmin;
/* Check to see which of (f,h) is on the inside corner of the box */
ptft = CNtransform_point(&ptf,view_transfo);
ptht = CNtransform_point(&pth,view_transfo);
if (ptft.z > ptht.z) {
/* f is on the outside, and h is on the inside */
/* Draw the inner-three axes : h-a, h-g, h-c */
if (!outside) {
drawX3D_line(pth.x, pth.y, pth.z, pta->x,pta->y,pta->z, CN_GD_DOTTED, 1);
drawX3D_line(pth.x, pth.y, pth.z, ptc->x,ptc->y,ptc->z, CN_GD_DOTTED, 1);
drawX3D_line(pth.x, pth.y, pth.z, ptg.x, ptg.y, ptg.z, CN_GD_DOTTED, 1);
}
/* Draw the outer-three axes : f-e, f-d, f-b */
drawX3D_line(ptf.x, ptf.y, ptf.z, ptb->x,ptb->y,ptb->z, CN_LN_SOLID, 1);
drawX3D_line(ptf.x, ptf.y, ptf.z, ptd->x,ptd->y,ptd->z, CN_LN_SOLID, 1);
drawX3D_line(ptf.x, ptf.y, ptf.z, pte.x, pte.y, pte.z, CN_LN_SOLID, 1);
} else {
/* h is on the outside, and f is on the inside */
/* Draw the inner-three axes : f-e, f-d, f-b */
if (!outside) {
drawX3D_line(ptf.x, ptf.y, ptf.z, ptb->x,ptb->y,ptb->z, CN_GD_DOTTED, 1);
drawX3D_line(ptf.x, ptf.y, ptf.z, ptd->x,ptd->y,ptd->z, CN_GD_DOTTED, 1);
drawX3D_line(ptf.x, ptf.y, ptf.z, pte.x, pte.y, pte.z, CN_GD_DOTTED, 1);
}
/* Draw the outer-three axes : h-a, h-g, h-c */
drawX3D_line(pth.x, pth.y, pth.z, pta->x,pta->y,pta->z, CN_LN_SOLID, 1);
drawX3D_line(pth.x, pth.y, pth.z, ptc->x,ptc->y,ptc->z, CN_LN_SOLID, 1);
drawX3D_line(pth.x, pth.y, pth.z, ptg.x, ptg.y, ptg.z, CN_LN_SOLID, 1);
}
/* Draw the upper-three axes : a-e, e-g, g-d */
if (!outside) {
drawX3D_line(pta->x,pta->y,pta->z,pte.x, pte.y, pte.z, CN_LN_SOLID, 1);
drawX3D_line(pte.x, pte.y, pte.z, ptg.x, ptg.y, ptg.z, CN_LN_SOLID, 1);
drawX3D_line(ptg.x, ptg.y, ptg.z, ptd->x,ptd->y,ptd->z, CN_LN_SOLID, 1);
}
/* Draw the outer-three frames */
drawX3D_line(pta->x,pta->y,pta->z,ptb->x,ptb->y,ptb->z, CN_LN_SOLID, 1);
drawX3D_line(ptb->x,ptb->y,ptb->z,ptc->x,ptc->y,ptc->z, CN_LN_SOLID, 1);
drawX3D_line(ptc->x,ptc->y,ptc->z,ptd->x,ptd->y,ptd->z, CN_LN_SOLID, 1);
}
/* Paint the back-planes of the cube */
/*ARGSUSED*/
static void paintX3D_inner_planes(pta, ptb, ptc, ptd)
CNcoord *pta, *ptb, *ptc, *ptd;
{
double xtmp, ytmp, ztmp;
/*
* Draw the xy-plane first
*/
ztmp = (ptb->z == zmin) ? zmin : zmax;
paintX3D_poly4(xmin,ymin,ztmp,
xmax,ymin,ztmp,
xmax,ymax,ztmp,
xmin,ymax,ztmp);
/*
* Now draw the xz-plane
*/
ytmp = (ptc->y == ymin) ? ymax : ymin;
paintX3D_poly4(xmin,ytmp,zmin,
xmax,ytmp,zmin,
xmax,ytmp,zmax,
xmin,ytmp,zmax);
/*
* Now draw the yz-plane
*/
xtmp = (ptc->x == xmin) ? xmax : xmin;
paintX3D_poly4(xtmp,ymin,zmin,
xtmp,ymax,zmin,
xtmp,ymax,zmax,
xtmp,ymin,zmax);
}
/*
* DRAW LABELLED AXES
*/
/*
* Draw the axes of the cube using given coordinates
* These axes are fixed to certain coordinates and do not
* change with the view
*/
static void drawX3D_static_axes()
{
/* Draw the x-axis */
drawX3D_axis(X_AXIS,
xmin,ymax,zmin,xmax,ymax,zmin,
0.0 ,ymax-ymin,0.0 ,
0.0 ,0.0 ,zmin-zmax,
xticks, xautorange, xlog, xmin, xmax, xlabel, xscale,
plotdata->plot_pr.xlabelhead, plotdata->plot_pr.xlabeltail);
/* Draw the y-axis */
drawX3D_axis(Y_AXIS,
xmax,ymin,zmin,xmax,ymax,zmin,
xmax-xmin,0.0 ,0.0 ,
0.0 ,0.0 ,zmin-zmax,
yticks, yautorange, ylog, ymin, ymax, ylabel, yscale,
plotdata->plot_pr.ylabelhead, plotdata->plot_pr.ylabeltail);
/* Draw the z-axis */
drawX3D_axis(Z_AXIS,
xmax,ymin,zmin,xmax,ymin,zmax,
0.0 ,ymin-ymax,0.0 ,
xmax-xmin,0.0 ,0.0 ,
zticks, zautorange, zlog, zmin, zmax, zlabel, zscale,
plotdata->plot_pr.zlabelhead, plotdata->plot_pr.zlabeltail);
}
/*
* Draw the outer axes of the cube using given coordinates
* These axes are dynamic, that is, they depend on the view orientation
*/
static void drawX3D_dynamic_axes(pta, ptb, ptc, ptd)
CNcoord *pta, *ptb, *ptc, *ptd;
{
/* B - C is a vector that points from C to B */
/* Draw the z-axis */
drawX3D_axis(Z_AXIS,
pta->x,pta->y,pta->z,ptb->x,ptb->y,ptb->z,
ptb->x-ptc->x,ptb->y-ptc->y,ptb->z-ptc->z,
ptc->x-ptd->x,ptc->y-ptd->y,ptc->z-ptd->z,
zticks, zautorange, zlog, pta->z, ptb->z, zlabel, zscale,
plotdata->plot_pr.zlabelhead, plotdata->plot_pr.zlabeltail);
/* Draw the x and y axes */
if (ptb->x == ptc->x) {
/* b-c is y-axis, c-d is x-axis */
/* Draw the y-axis */
drawX3D_axis(Y_AXIS,
ptb->x,ptb->y,ptb->z,ptc->x,ptc->y,ptc->z,
ptc->x-ptd->x,ptc->y-ptd->y,ptc->z-ptd->z,
ptb->x-pta->x,ptb->y-pta->y,ptb->z-pta->z,
yticks, yautorange, ylog, ptb->y, ptc->y, ylabel, yscale,
plotdata->plot_pr.ylabelhead, plotdata->plot_pr.ylabeltail);
/* Draw the x-axis */
drawX3D_axis(X_AXIS,
ptc->x,ptc->y,ptc->z,ptd->x,ptd->y,ptd->z,
ptc->x-ptb->x,ptc->y-ptb->y,ptc->z-ptb->z,
ptb->x-pta->x,ptb->y-pta->y,ptb->z-pta->z,
xticks, xautorange, xlog, ptc->x, ptd->x, xlabel, xscale,
plotdata->plot_pr.xlabelhead, plotdata->plot_pr.xlabeltail);
} else {
/* b-c is x-axis, c-d is y-axis */
/* Draw the x-axis */
drawX3D_axis(X_AXIS,
ptb->x,ptb->y,ptb->z,ptc->x,ptc->y,ptc->z,
ptc->x-ptd->x,ptc->y-ptd->y,ptc->z-ptd->z,
ptb->x-pta->x,ptb->y-pta->y,ptb->z-pta->z,
xticks, xautorange, xlog, ptb->x, ptc->x, xlabel, xscale,
plotdata->plot_pr.xlabelhead, plotdata->plot_pr.xlabeltail);
/* Draw the y-axis */
drawX3D_axis(Y_AXIS,
ptc->x,ptc->y,ptc->z,ptd->x,ptd->y,ptd->z,
ptc->x-ptb->x,ptc->y-ptb->y,ptc->z-ptb->z,
ptb->x-pta->x,ptb->y-pta->y,ptb->z-pta->z,
yticks, yautorange, ylog, ptc->y, ptd->y, ylabel, yscale,
plotdata->plot_pr.ylabelhead, plotdata->plot_pr.ylabeltail);
}
}
/* Draw the axis - parallel to a given axis */
static void drawX3D_axis(axis,
xa,ya,za,xb,yb,zb,
vx, vy, vz,
vbx, vby, vbz,
nticks, autorange, plog, min, max, label, scale,
labelhead, labeltail)
int axis; /* X-axis, Y-axis, Z-axis */
double xa,ya,za,xb,yb,zb; /* Start, end points */
double vx,vy,vz; /* Vector for drawing tick-marks */
double vbx,vby,vbz; /* Direction of remaining axis */
int nticks;
short autorange;
short plog;
double min, max;
char *label;
double scale;
CNaxislabelptr labelhead, labeltail;
{
double xm0, ym0, zm0, xm1, ym1, zm1, x0, y0, x1, y1;
double xm2, ym2, zm2, x2, y2;
double tmp;
CNcoord vtick, vaxis;
int parallel=0;
/*
* Rearrange min and max
*/
if (max < min) {
tmp=xb ; xb =xa ; xa =tmp;
tmp=yb ; yb =ya ; ya =tmp;
tmp=zb ; zb =za ; za =tmp;
tmp=max; max=min; min=tmp;
}
/*
* There are 2 vectors of importance.
* The first is the vector giving the direction of the axis = vaxis
* The second is the vector giving the direction of the tick-marks = vtick
* vaxis can be bidirectional, but the direction of vtick is important.
*
* /\ va
* \
* /\
* vt \
* \
* /
*/
/*
* Find the direction of the tickmarks in X-coordinates.
* This means that the vector (vx,vy,vz) must be converted.
* Don't normalize the vector yet
*/
xm0 = xa; ym0 = ya; zm0 = za;
xm1 = xa+vx; ym1 = ya+vy; zm1 = za+vz;
trn_world_to_X11(xm0,ym0,zm0,&x0,&y0);
trn_world_to_X11(xm1,ym1,zm1,&x1,&y1);
vtick.x = x1-x0;
vtick.y = y1-y0;
vtick.z = 0.0;
/*
* Find the direction of the axis in X-coordinates.
* Again this requires a vector transformation.
* Don't normalize the vector yet
*/
xm1 = 0.5*(xa+xb);
ym1 = 0.5*(ya+yb);
zm1 = 0.5*(za+zb);
trn_world_to_X11(xm1,ym1,zm1,&x1,&y1);
vaxis.x = x1-x0;
vaxis.y = y1-y0;
vaxis.z = 0.0;
#ifdef DEBUG
(void) printf("vtick=(%g %g %g)\n",vtick.x,vtick.y,vtick.z);
(void) printf("vaxis=(%g %g %g)\n",vaxis.x,vaxis.y,vaxis.z);
#endif
/* Don't draw the axis if the axis points out of the 2D page */
if (CNvector_lengthsq(&vaxis) < 1.0e-5) return;
/*
* Flag if the axis-vector is the same as the tick vector
* This should only happen when theta=0 or 180, where theta is the view
* angle from the x-y plane
*/
#ifdef DEBUG
(void) printf("theta=%g\n",sin(CNvector_angle(&vaxis,&vtick)));
#endif
parallel = fabs(sin(CNvector_angle(&vaxis,&vtick))) < 1.0e-5;
if (parallel || (CNvector_lengthsq(&vtick) < 1.0e-5)) {
xm2 = xa+vbx; ym2 = ya+vby; zm2 = za+vbz;
trn_world_to_X11(xm2,ym2,zm2,&x2,&y2);
vtick.x = x2-x0;
vtick.y = y2-y0;
vtick.z = 0.0;
}
/* Normalize the vectors */
(void) CNnormalize_vector(&vtick);
(void) CNnormalize_vector(&vaxis);
/* Put on the label */
plotX3D_label(label,x1,y1,&vaxis,&vtick);
/* Draw tickmarks and tick labels */
if (labelhead != NULL) {
/* Tickmarks based on user-specification */
plotX3D_User_ticks(axis,xa,ya,za,xb,yb,zb,&vaxis,&vtick,
labelhead,labeltail);
} else if (!autorange && !plog) {
/* Linear, fixed tickmarks */
plotX3D_ticks(xa,ya,za,xb,yb,zb,min,max,&vaxis,&vtick,nticks,plog,scale);
} else {
/* If xlog then do lots of tiny tickmarks */
plotX3D_Auto_ticks(axis,xa,ya,za,xb,yb,zb,min,max,&vaxis,&vtick,
autorange,plog,scale);
}
/* Draw the main line */
drawX3D_line(xa,ya,za,xb,yb,zb,CN_LN_SOLID,2);
}
/*
* Draw the tickmarks using simple linear interpolation
* i.e. there are NTICK number of tickmarks.
* This is NEVER used with log-scale
*/
static void plotX3D_ticks(xa,ya,za,xb,yb,zb,
min,max,vaxis,vtick,nticks,plog,scale)
double xa,ya,za,xb,yb,zb;
double min,max;
CNcoord *vtick, *vaxis;
int nticks;
short plog;
double scale;
{
double xm0, ym0, zm0, x0, y0, x1, y1, vallbl;
int i;
int explabel, precision;
PXlabel axislabels[PX_MAX_LABELS];
int nlabels=0;
/* Draw tickmarks */
(void) PXlinetypX(CN_LN_SOLID, 1);
for (i=0; i<=nticks; i++) {
xm0 = xa + i*(xb-xa)/(double)nticks;
ym0 = ya + i*(yb-ya)/(double)nticks;
zm0 = za + i*(zb-za)/(double)nticks;
trn_world_to_X11(xm0,ym0,zm0,&x0,&y0);
x1 = x0 + vtick->x*7.0;
y1 = y0 + vtick->y*7.0;
if (window)
XDrawLine(display,window,gc,
(int)(x0),(int)(y0),(int)(x1),(int)(y1));
if (pixmap)
XDrawLine(display,pixmap,gc,
(int)(x0),(int)(y0),(int)(x1),(int)(y1));
x1 = x0 + vtick->x*10.0;
y1 = y0 + vtick->y*10.0;
vallbl = min + i*(max-min)/(double)nticks;
/* Put on a label */
if (plog) vallbl = pow(10.0,vallbl);
vallbl = vallbl/scale;
PXadd_axislabel(axislabels, &nlabels, PX_MAX_LABELS,
vallbl, (double)x1, (double)y1);
}
/* Now work on the labels */
if (nlabels > 0) {
PXfind_axis_precision(axislabels, nlabels, &precision, &explabel);
for (i=0; i<nlabels; i++) {
plotX3D_ticklabel(axislabels[i].value,
axislabels[i].x,
axislabels[i].y,
(char *)NULL,
vaxis, vtick, precision, explabel);
}
}
}
/*
* Draw the tickmarks with automatic ranging
* i.e. there are major and minor tickmarks.
*/
/*ARGSUSED*/
static void plotX3D_Auto_ticks(axis,xa,ya,za,xb,yb,zb,min,max,vaxis,vtick,
autorange,plog,scale)
int axis;
double xa,ya,za,xb,yb,zb;
double min,max;
CNcoord *vtick, *vaxis;
short autorange;
short plog;
double scale;
{
void PXget_autorange();
double dmin, dmax, dmin2, dmax2;
double dtmp, dt, delta;
double xm0, ym0, zm0, x0, y0, x1, y1;
int i, itick, nticks, tck;
int explabel, precision;
PXlabel axislabels[PX_MAX_LABELS];
int nlabels=0, doplot;
double vallbl;
/*
* LINEAR SCALE
* Start with a linear range (e.g. xmin = 0.05 xmax = 50.0)
* Autoranging => dmin = 0.05 dmax = 50.0
* dmin2= 0.0 dmax2= 50.0
* delta= 10.0
* => get scales at x=0,10,20,30,40,50
*
* LOG SCALES
* Start with a linear range (e.g. xmin = 0.05 xmax = 50.0)
* For log scale, these numbers are converted first to logarithmic values
* during initialization (e.g. xmin = -1.3 xmax = 1.7 )
* The autoranging forces => dmin = -1.3 dmax = 1.7
* dmin2= -2.0 dmax2= 2.0
* delta= 1.0
* => get scales at x=-2,-1,0,1,2
* So all I have to do is plot the scales in log10 increments
*/
/*
* This does not work too well if (xmax-xmin) << xmin
* because of floating point errors.
*/
/* Get the rounded intervals */
PXget_autorange(min,max,
&dmin,&dmax,&dmin2,&dmax2,&delta,
plog,autorange);
/* If dmin2=dmin then subtract delta from dmin2 so that dmin2 < dmin */
/* This is used to get the leftmost tick label on the plot */
if (dmin2==dmin) dmin2 -= delta;
/*
* Draw in label at beginning of plot boundary
*/
/* Reset tick length */
tck = 8;
/* The position of the dmin tickmark on the axis */
switch (axis) {
case X_AXIS : xm0=dmin; ym0=ya; zm0=za; break;
case Y_AXIS : xm0=xa; ym0=dmin; zm0=za; break;
case Z_AXIS :
default : xm0=xa; ym0=ya; zm0=dmin; break;
}
trn_world_to_X11(xm0,ym0,zm0,&x0,&y0);
x1 = x0 + vtick->x*(tck+2);
y1 = y0 + vtick->y*(tck+2);
/* Put on the first tick */
vallbl = dmin;
if (plog) vallbl = pow(10.0,vallbl);
vallbl = vallbl/scale;
PXadd_axislabel(axislabels, &nlabels, PX_MAX_LABELS,
vallbl, (double)x1, (double)y1);
/* Draw the tickmarks from dmin2 to dmax2 - dtmp is distance from dmin2 */
if (delta <= 0.0) nticks = 0;
else nticks = (int)((dmax2 - dmin2)/delta) + 1;
for (itick=0; itick<nticks; itick++) {
dtmp = itick*delta;
for (i=1; i<=10; i++) {
/* distance from dtmp - actual phy loc is dt+dtmp+dmin2 */
dt = i*0.1*delta;
if (plog) dt = log10((double)i);
if (plog && i==1) continue; /* Don't do this case */
/* Don't draw if this is outside the plot boundaries */
if (dt+dtmp+dmin2 < dmin || dt+dtmp+dmin2 > dmax) continue;
/* The length of the tick depends on i */
if (i==10) tck = 8; /* major tick */
else if (i==5 ) tck = 6; /* major sub-tick */
else tck = 4; /* minor tick */
/* The position of the tickmark on the axis */
switch (axis) {
case X_AXIS : xm0=dt+dtmp+dmin2; ym0=ya; zm0=za; break;
case Y_AXIS : xm0=xa; ym0=dt+dtmp+dmin2; zm0=za; break;
case Z_AXIS :
default : xm0=xa; ym0=ya; zm0=dt+dtmp+dmin2; break;
}
trn_world_to_X11(xm0,ym0,zm0,&x0,&y0);
x1 = x0 + vtick->x*tck;
y1 = y0 + vtick->y*tck;
/* Draw the ticks */
if (window)
XDrawLine(display,window,gc,
(int)(x0),(int)(y0),(int)(x1),(int)(y1));
if (pixmap)
XDrawLine(display,pixmap,gc,
(int)(x0),(int)(y0),(int)(x1),(int)(y1));
/* Draw labels */
if (i==10) {
x1 = x0 + vtick->x*(tck+2);
y1 = y0 + vtick->y*(tck+2);
vallbl = dt+dtmp+dmin2;
if (fabs(vallbl/delta) < 1e-10) vallbl=0.0; /* If x~=0 print 0 */
if (plog) vallbl = pow(10.0,vallbl);
vallbl = vallbl/scale;
PXadd_axislabel(axislabels, &nlabels, PX_MAX_LABELS,
vallbl, (double)x1, (double)y1);
}
}
}
/*
* Draw in label at end of plot boundaries
*/
/* Reset tick length */
tck = 8;
/* The position of the dmax tickmark on the axis */
switch (axis) {
case X_AXIS : xm0=dmax; ym0=ya; zm0=za; break;
case Y_AXIS : xm0=xa; ym0=dmax; zm0=za; break;
case Z_AXIS :
default : xm0=xa; ym0=ya; zm0=dmax; break;
}
trn_world_to_X11(xm0,ym0,zm0,&x0,&y0);
x1 = x0 + vtick->x*(tck+2);
y1 = y0 + vtick->y*(tck+2);
/* Put on the last tick */
vallbl = dmax;
if (plog) vallbl = pow(10.0,vallbl);
vallbl = vallbl/scale;
PXadd_axislabel(axislabels, &nlabels, PX_MAX_LABELS,
vallbl, (double)x1, (double)y1);
/* Now work on the labels */
if (nlabels > 0) {
PXfind_axis_precision(axislabels, nlabels, &precision, &explabel);
for (i=0; i<nlabels; i++) {
doplot = CN_TRUE;
if (i==0) {
/* Don't plot the 1st label if it is too close to the second */
if (nlabels >= 2) {
if (EQUAL(axislabels[i].value, axislabels[i+1].value))
doplot = CN_FALSE;
else if (ticklabel_overlap(axislabels[i],axislabels[i+1],
precision, explabel))
doplot = CN_FALSE;
}
} else if (i==nlabels-1) {
/* Don't plot the 1st label if it is too close to the second */
if (nlabels >= 2) {
if (EQUAL(axislabels[i].value, axislabels[i-1].value))
doplot = CN_FALSE;
else if (ticklabel_overlap(axislabels[i],axislabels[i-1],
precision, explabel))
doplot = CN_FALSE;
}
}
if (doplot)
plotX3D_ticklabel(axislabels[i].value,
axislabels[i].x,
axislabels[i].y,
(char *)NULL,
vaxis, vtick, precision, explabel);
}
}
}
/*
* Draw the tickmarks and labels using user-specified labels
* This is NEVER used with log-scale
*/
/*ARGSUSED*/
static void plotX3D_User_ticks(axis,
xa,ya,za,xb,yb,zb,
vaxis,vtick,
labelhead, labeltail)
int axis;
double xa,ya,za,xb,yb,zb;
CNcoord *vtick, *vaxis;
CNaxislabelptr labelhead, labeltail;
{
CNaxislabelptr Aptr;
double xm0, ym0, zm0, x0, y0, x1, y1;
char label[CN_MAXCHAR];
int outside;
/* Draw tickmarks */
(void) PXlinetypX(CN_LN_SOLID, 1);
for (Aptr=labelhead; Aptr!=NULL; Aptr=Aptr->next) {
/* Get the axis coordinates and check if it is out of bounds */
xm0 = xa;
ym0 = ya;
zm0 = za;
outside = CN_FALSE;
switch (axis) {
case X_AXIS : xm0 = Aptr->pos;
if ((xm0 > xa && xm0 > xb) || (xm0 < xa && xm0 < xb))
outside = CN_TRUE;
break;
case Y_AXIS : ym0 = Aptr->pos;
if ((ym0 > ya && ym0 > yb) || (ym0 < ya && ym0 < yb))
outside = CN_TRUE;
break;
case Z_AXIS :
default : zm0 = Aptr->pos;
if ((zm0 > za && zm0 > zb) || (zm0 < za && zm0 < zb))
outside = CN_TRUE;
break;
}
/* The tick is out of bounds */
if (outside) continue;
/* Translate to X11 coordinates */
trn_world_to_X11(xm0,ym0,zm0,&x0,&y0);
x1 = x0 + vtick->x*7.0;
y1 = y0 + vtick->y*7.0;
/* Draw the tick */
if (window)
XDrawLine(display,window,gc,
(int)(x0),(int)(y0),(int)(x1),(int)(y1));
if (pixmap)
XDrawLine(display,pixmap,gc,
(int)(x0),(int)(y0),(int)(x1),(int)(y1));
/* Put on a label */
x1 = x0 + vtick->x*10.0;
y1 = y0 + vtick->y*10.0;
(void) strcpy(label, Aptr->name);
plotX3D_ticklabel(0.0, x1, y1, label,
vaxis, vtick, 4, CN_FALSE);
}
}
/*
* Convenient X11 drawing functions
*/
/* Draw a line of given thickness in 3D */
static void drawX3D_line(x1, y1, z1, x2, y2, z2, linetyp, ithk)
double x1, y1, z1, x2, y2, z2;
int linetyp, ithk;
{
double xa, ya, xb, yb;
trn_world_to_X11(x1,y1,z1,&xa,&ya);
trn_world_to_X11(x2,y2,z2,&xb,&yb);
/* draw the line */
(void) PXlinetypX(linetyp, ithk);
if (window)
XDrawLine(display,window,gc,
(int)(xa),(int)(ya),(int)(xb),(int)(yb));
if (pixmap)
XDrawLine(display,pixmap,gc,
(int)(xa),(int)(ya),(int)(xb),(int)(yb));
(void) PXlinetypX(CN_LN_SOLID, 1);
}
/* Draw a filled polygon */
static void paintX3D_poly4(x1,y1,z1,x2,y2,z2,x3,y3,z3,x4,y4,z4)
double x1,y1,z1,x2,y2,z2,x3,y3,z3,x4,y4,z4;
{
XPoint points[5];
double x,y;
/* Translate the points into X-coordinates */
trn_world_to_X11(x1,y1,z1,&x,&y);
points[0].x = (int)(x);
points[0].y = (int)(y);
points[4].x = (int)(x);
points[4].y = (int)(y);
trn_world_to_X11(x2,y2,z2,&x,&y);
points[1].x = (int)(x);
points[1].y = (int)(y);
trn_world_to_X11(x3,y3,z3,&x,&y);
points[2].x = (int)(x);
points[2].y = (int)(y);
trn_world_to_X11(x4,y4,z4,&x,&y);
points[3].x = (int)(x);
points[3].y = (int)(y);
/* Now draw the polygon */
XSetForeground(display,gc,colors[PX_MAX_NAMED_COLORS]);
if (window)
XFillPolygon(display,window,gc,points,5,Convex,CoordModeOrigin);
if (pixmap)
XFillPolygon(display,pixmap,gc,points,5,Convex,CoordModeOrigin);
XSetForeground(display,gc,foreground_pixel);
}
/* plot the tick label on an axis at the given x-y coordinates */
/*ARGSUSED*/
static void plotX3D_ticklabel(vallbl,xpos,ypos,label,
vaxis,vtick,precision,explabel)
double vallbl;
double xpos,ypos;
char *label;
CNcoord *vaxis; /* Axis vector (normalized) */
CNcoord *vtick; /* Tickmark vector (normalized) */
int precision, explabel;
{
int text_len, text_width, text_xpos, text_ypos;
char text[MAXCHR];
char exponent[MAXCHR];
char nonexponent[MAXCHR];
int isexp=CN_FALSE;
/*
* |vtick->x| > |vtick->y| , vtick->x>0 left justified, vertical_centered
* |vtick->x| > |vtick->y| , vtick->x<0 right justified, vertical_centered
* |vtick->x| < |vtick->y| , vtick->y>0 center justified, top_justified
* |vtick->x| < |vtick->y| , vtick->y<0 center justified, bottom_justified
*/
if (explabel)
(void) sprintf(text,"%.*e",precision,vallbl);
else
(void) sprintf(text,"%.*g",precision,vallbl);
if (label != NULL) (void)strcpy(text,label);
/* Check for exponents */
if (label == NULL)
PXmodify_explabel(text, exponent, nonexponent, &isexp, CN_FALSE);
/* Draw the string */
text_len = strlen(text);
text_width = XTextWidth(lblfont_info,text,text_len);
if ((fabs(vtick->x)>fabs(vtick->y)) || (fabs(vaxis->y)>10*fabs(vaxis->x))){
/* center-vertical justified */
if (vtick->x > 0.0)
text_xpos = (int)(xpos);
else
text_xpos = (int)(xpos) - text_width;
text_ypos = (int)(ypos) + 0.5*lblfont_height;
} else {
/* center-horizontal justified */
text_xpos = (int)(xpos) - text_width/2;
if (vtick->y > 0.0)
text_ypos = (int)(ypos) + 1.0*lblfont_height;
else
text_ypos = (int)(ypos);
}
if (window)
XDrawString(display,window,gcl,text_xpos,text_ypos,text,text_len);
if (pixmap)
XDrawString(display,pixmap,gcl,text_xpos,text_ypos,text,text_len);
}
/* check overlap of 2 labels */
static int ticklabel_overlap(label1, label2, precision, explabel)
PXlabel label1, label2;
int precision, explabel;
{
char text1[MAXCHR];
char text2[MAXCHR];
char exponent[MAXCHR];
char nonexponent[MAXCHR];
int isexp = CN_FALSE;
int overlap = CN_FALSE;
int text1_width, text2_width, text_width, text_spacing;
int tick_xdist, tick_ydist;
/* Assume that the two labels are not of equal value */
if (explabel) {
(void) sprintf(text1,"%.*e",precision,label1.value);
(void) sprintf(text2,"%.*e",precision,label2.value);
} else {
(void) sprintf(text1,"%.*g",precision,label1.value);
(void) sprintf(text2,"%.*g",precision,label2.value);
}
/* Modify the labels - strip characters from exponents */
PXmodify_explabel(text1, exponent, nonexponent, &isexp, CN_FALSE);
PXmodify_explabel(text2, exponent, nonexponent, &isexp, CN_FALSE);
/* Calculate text widths */
text1_width = XTextWidth(font_info,text1,strlen(text1));
text2_width = XTextWidth(font_info,text2,strlen(text2));
text_spacing = 1;
text_width = 0.5*(text1_width + text2_width) + text_spacing;
/* Calculate spacing between ticks */
tick_xdist = fabs(label1.x - label2.x);
tick_ydist = fabs(label1.y - label2.y);
if ((tick_ydist < font_height) && (tick_xdist < text_width))
overlap = CN_TRUE;
else
overlap = CN_FALSE;
/* Return */
return(overlap);
}
/* plot a label on an axis at the given x-y coordinates */
/*ARGSUSED*/
static void plotX3D_label(text,x,y,vaxis,vtick)
char *text;
double x,y;
CNcoord *vaxis; /* Axis vector (normalized) */
CNcoord *vtick; /* Tickmark vector (normalized) */
{
int text_len, text_width, text_xpos, text_ypos;
double scale=0.8;
/*
* |vtick->x| > |vtick->y| , vtick->x>0 left justified, vertical_centered
* |vtick->x| > |vtick->y| , vtick->x<0 right justified, vertical_centered
* |vtick->x| < |vtick->y| , vtick->y>0 center justified, top_justified
* |vtick->x| < |vtick->y| , vtick->y<0 center justified, bottom_justified
*/
/* Now figure out where the label is to be put */
if (fabs(vaxis->y) > 10*fabs(vaxis->x)) {
x += vtick->x*33.0*scale;
y += vtick->y*33.0*scale;
} else if (fabs(vaxis->y) > 5*fabs(vaxis->x)) {
x += vtick->x*32.0*scale;
y += vtick->y*32.0*scale;
} else if (fabs(vaxis->y) > 2*fabs(vaxis->x)) {
x += vtick->x*31.0*scale;
y += vtick->y*31.0*scale;
} else if (fabs(vaxis->y) > 0.5*fabs(vaxis->x)) {
x += vtick->x*30.0*scale;
y += vtick->y*30.0*scale;
} else if (fabs(vaxis->y) > 0.2*fabs(vaxis->x)) {
x += vtick->x*29.0*scale;
y += vtick->y*29.0*scale;
} else if (fabs(vaxis->y) > 0.1*fabs(vaxis->x)) {
x += vtick->x*28.0*scale;
y += vtick->y*28.0*scale;
} else {
x += vtick->x*26.0*scale;
y += vtick->y*26.0*scale;
}
text_len = strlen(text);
text_width = XTextWidth(font_info,text,text_len);
/* Figure out the text-position */
if ((fabs(vtick->x)>fabs(vtick->y)) || (fabs(vaxis->y)>10*fabs(vaxis->x))){
/* center-vertical justified */
if (vtick->x > 0.0)
text_xpos = (int)(x);
else
text_xpos = (int)(x) - text_width;
text_ypos = (int)(y + 0.5*font_height);
} else {
/* center-horizontal justified */
text_xpos = (int)(x) - text_width/2;
if (vtick->y > 0.0)
text_ypos = (int)(y + 1.0*font_height);
else
text_ypos = (int)(y);
}
if (window)
XDrawString(display,window,gc,text_xpos,text_ypos,text,text_len);
if (pixmap)
XDrawString(display,pixmap,gc,text_xpos,text_ypos,text,text_len);
}
/*
* PLOT DATA
*/
/* draw the plot */
static void plotX3D()
{
CNdslistptr DS, ds;
CNdatasetptr Dptr;
int colrinc=0, lineinc=0;
int contfill, meshplot;
int PARENT_FOUND;
/*
* Plot set - draw the grid if that exists
*/
for (DS=plotdata->datahead; DS!=NULL; DS=DS->next) {
if (DS->Dptr->grid && DS->Dptr->datatype == CN_GRID4D)
plotX3D_grid(DS->Dptr->grid,
DS->Dptr->data_pr.contintrp,
DS->Dptr->data_pr.contclip,
DS->Dptr->data_pr.meshplot);
}
/*
* Plot set - draw the mesh4D grid and related quants if that exists
*/
for (DS=plotdata->datahead; DS!=NULL; DS=DS->next) {
if (DS->Dptr->mesh4D)
plotX3D_mesh4D(DS->Dptr);
}
/*
* Plot set - covers multiple plots
* Draw the colored fills first, because if drawn later
* the fills will obscure the drawn curves.
*/
/*
* Draw the boundary if that is available
* If this is a PIF-type mesh use the parent's boundary
*/
for (DS=plotdata->datahead; DS!=NULL; DS=DS->next) {
if (!( (DS->Dptr->datatype == CN_PIF_PARENT) ||
(DS->Dptr->datatype == CN_PIF_CHILD && DS->Dptr->parent) ||
(DS->Dptr->datatype == CN_CONTOUR && DS->Dptr->parent) ||
(DS->Dptr->datatype == CN_VECTOR && DS->Dptr->parent) ) )
continue;
if (DS->Dptr->parent != NULL) {
/* Check to see if the parent is in the list */
PARENT_FOUND = CN_FALSE;
for (ds=plotdata->datahead; ds!=NULL && !PARENT_FOUND; ds=ds->next)
if (ds->Dptr == DS->Dptr->parent) PARENT_FOUND = CN_TRUE;
/* Select the dptr from which to get plot instructions */
Dptr = PARENT_FOUND ? DS->Dptr->parent : DS->Dptr;
/* Now draw the boundary */
plotX3D_boundary(DS->Dptr->parent,
(int)Dptr->data_pr.boundary,
(int)Dptr->data_pr.fillbnd,
(int)Dptr->data_pr.pr_rgID,
1,0);
} else {
plotX3D_boundary(DS->Dptr,
(int)DS->Dptr->data_pr.boundary,
(int)DS->Dptr->data_pr.fillbnd,
(int)DS->Dptr->data_pr.pr_rgID,
1,0);
}
}
/*
* Draw colored contour fills or hiddenline triangles/rectangles
*/
for (DS=plotdata->datahead; DS!=NULL; DS=DS->next) {
/* Draw colored triangles/rectangles but not the curves */
contfill = ( (DS->Dptr->data_pr.contstyle == CN_FILLCONT) ||
(DS->Dptr->data_pr.contstyle == CN_LNFILLCONT) );
meshplot = DS->Dptr->data_pr.contstyle == CN_PLOTMESH;
meshplot = meshplot | DS->Dptr->data_pr.meshplot;
if (contfill || meshplot) {
plotX3D_trias(DS->Dptr, contfill, meshplot);
plotX3D_rects(DS->Dptr, contfill, meshplot);
plotX3D_polys(DS->Dptr, contfill, meshplot);
}
}
/*
* Now draw the contour and mesh datasets
*/
colrinc = 0;
lineinc = 0;
for (DS=plotdata->datahead; DS!=NULL; DS=DS->next) {
/* Now draw the contour curves */
if (DS->Dptr->datatype == CN_CONTOUR) {
contfill = DS->Dptr->data_pr.contstyle == CN_FILLCONT;
meshplot = DS->Dptr->data_pr.contstyle == CN_PLOTMESH;
/*EMPTY*/
if (contfill || meshplot) {
/*
* Don't draw curves for this dataset
*
* Note however that if data_pr.contstyle == CN_LINECONT,
* and data_pr.meshplot = ON, then both the mesh and the
* contours will be drawn.
*/
;
} else {
/* Draw the curve set */
plotX3D_dataset_curves(DS->Dptr,colrinc,lineinc);
if (!overlay) {
colrinc = 0;
lineinc = 0;
} else if (DS->Dptr->data_pr.linetypes == 1) {
colrinc = colrinc ++;
lineinc = lineinc ++;
} else {
colrinc = colrinc + 3;
lineinc = lineinc + 3;
}
}
}
}
/*
* Now draw the rest of the datasets
*/
colrinc = 0;
lineinc = 0;
for (DS=plotdata->datahead; DS!=NULL; DS=DS->next) {
/* Don't draw contours */
if (DS->Dptr->datatype == CN_CONTOUR) continue;
/* Draw the curve set */
plotX3D_dataset_curves(DS->Dptr,colrinc,lineinc);
if (DS->Dptr->curvehead != NULL) {
if (!overlay) {
colrinc = 0;
lineinc = 0;
} else {
colrinc ++;
lineinc ++;
}
}
}
/*
* Plot set - draw the vectors if that exists
*/
for (DS=plotdata->datahead; DS!=NULL; DS=DS->next) {
if (DS->Dptr->vecbox)
plotX3D_vectors(DS->Dptr->vecbox,
(int) DS->Dptr->data_pr.vlog,
(double) DS->Dptr->data_pr.vscale,
(double) DS->Dptr->data_pr.vlogscale,
(int) DS->Dptr->data_pr.vhead,
(int) DS->Dptr->data_pr.vtail);
}
/*
* Draw the element ID's if necessary
* curve-point ID's are plotted together with curves
*/
for (DS=plotdata->datahead; DS!=NULL; DS=DS->next) {
/* Set the Dptr */
Dptr = DS->Dptr;
/* Mesh-based Vectors are treated differently */
if (DS->Dptr->datatype == CN_VECTOR && DS->Dptr->parent != NULL)
Dptr = DS->Dptr->parent;
/* Draw ID's for hierarchical meshes */
if (DS->Dptr->data_pr.pr_ptID) {
if (DS->Dptr->parent != NULL)
plotX3D_pointIDs(DS->Dptr->parent->pointhead,
DS->Dptr->parent->pointtail, CN_FALSE);
else
plotX3D_pointIDs(Dptr->pointhead, Dptr->pointtail, CN_FALSE);
}
if (DS->Dptr->data_pr.pr_ndID)
plotX3D_nodeIDs (Dptr->nodehead, Dptr->nodetail);
if (DS->Dptr->data_pr.pr_trID)
plotX3D_triaIDs (Dptr->triahead, Dptr->triatail);
if (DS->Dptr->data_pr.pr_rtID)
plotX3D_rectIDs (Dptr->recthead, Dptr->recttail);
}
}
/*
* Plot the grid in X11
*/
static void plotX3D_grid(grid, contintrp, contclip, meshplot)
CNgrid4Dptr grid;
short contintrp;
short contclip;
short meshplot;
{
void PXidentify_view_planes();
CNsliceptr slice=NULL;
CNrectptr R;
CNtriaptr T;
int verbose=0;
int xminin, xmaxin, yminin, ymaxin, zminin, zmaxin;
double cxmin, cxmax, cymin, cymax, czmin, czmax, ctmin, ctmax;
double tmp;
short logx=0, logy=0, logz=0, logt=0;
int clipz=1;
int linetype, linecolor, filltype, fillcolor;
/* Initialize colors and line/fill types */
filltype = CN_FILL_NONE;
linetype = CN_LN_SOLID;
fillcolor = PXpolyColorIndexX(1); /* yellow */
linecolor = PXpolyColorIndexX(4); /* red */
/*
* Identify the inner and outer planes in the current view
*/
PXidentify_view_planes(grid->xmin, grid->xmax,
grid->ymin, grid->ymax,
grid->zmin, grid->zmax,
&xminin, &xmaxin, &yminin, &ymaxin, &zminin, &zmaxin,
view_transfo);
/* clipping boundaries */
cxmin = ((xlog) ? pow(10.0,xmin) : xmin);
cxmax = ((xlog) ? pow(10.0,xmax) : xmax);
cymin = ((ylog) ? pow(10.0,ymin) : ymin);
cymax = ((ylog) ? pow(10.0,ymax) : ymax);
czmin = ((zlog) ? pow(10.0,zmin) : zmin);
czmax = ((zlog) ? pow(10.0,zmax) : zmax);
ctmin = -CN_LARGE;
ctmax = CN_LARGE;
/*
* X slice
*/
if (xminin) {
/* Draw the surface at x=xmax */
tmp = grid->xmax;
if (tmp > cxmax) tmp = cxmax;
} else {
/* Draw the surface at x=xmin */
tmp = grid->xmin;
if (tmp < cxmin) tmp = cxmin;
}
if ((slice = CNslice_grid4D_x(grid,tmp,(int)contintrp,verbose)) != NULL) {
/* Loop through the rectangles */
for (R=slice->recthead; R!=NULL; R=R->next) {
/* Quick check to see if the rectangle is in-bounds */
if (!CNrect_in_bounds(R,
cxmin,cxmax,cymin,cymax,czmin,czmax,ctmin,ctmax)) continue;
/* Plot the color fills */
plotX3D_single_fill_rect(R,
cxmin,cxmax,cymin,cymax,czmin,czmax,ctmin,ctmax,
logx, logy, logz, logt, contclip, 1);
/* Plot the mesh */
if (meshplot)
plotX3D_single_solid_rect(R,
cxmin,cxmax,cymin,cymax,czmin,czmax,ctmin,ctmax,
logx, logy, logz, logt, clipz,
filltype, fillcolor, linetype, linecolor, 1);
}
/* Loop through the triangles */
for (T=slice->triahead; T!=NULL; T=T->next) {
/* Quick check to see if the triangle is in-bounds */
if (!CNtria_in_bounds(T,
cxmin,cxmax,cymin,cymax,czmin,czmax,ctmin,ctmax)) continue;
/* Plot the color fills */
plotX3D_single_fill_tria(T,
cxmin,cxmax,cymin,cymax,czmin,czmax,ctmin,ctmax,
logx, logy, logz, logt, contclip, 1);
/* Plot the mesh */
if (meshplot)
plotX3D_single_solid_tria(T,
cxmin,cxmax,cymin,cymax,czmin,czmax,ctmin,ctmax,
logx, logy, logz, logt, clipz,
filltype, fillcolor, linetype, linecolor, 1);
}
/* Delete the slice */
CNdelete_slice(slice);
}
/*
* Y slice
*/
if (yminin) {
/* Draw the surface at y=ymax */
tmp = grid->ymax;
if (tmp > cymax) tmp = cymax;
} else {
/* Draw the surface at y=ymin */
tmp = grid->ymin;
if (tmp < cymin) tmp = cymin;
}
if ((slice = CNslice_grid4D_y(grid,tmp,(int)contintrp,verbose)) != NULL) {
/* Loop through the rectangles */
for (R=slice->recthead; R!=NULL; R=R->next) {
/* Quick check to see if the rectangle is in-bounds */
if (!CNrect_in_bounds(R,
cxmin,cxmax,cymin,cymax,czmin,czmax,ctmin,ctmax)) continue;
/* Plot the color fills */
plotX3D_single_fill_rect(R,
cxmin,cxmax,cymin,cymax,czmin,czmax,ctmin,ctmax,
logx, logy, logz, logt, contclip, 1);
/* Plot the mesh */
if (meshplot)
plotX3D_single_solid_rect(R,
cxmin,cxmax,cymin,cymax,czmin,czmax,ctmin,ctmax,
logx, logy, logz, logt, clipz,
filltype, fillcolor, linetype, linecolor, 1);
}
/* Loop through the triangles */
for (T=slice->triahead; T!=NULL; T=T->next) {
/* Quick check to see if the triangle is in-bounds */
if (!CNtria_in_bounds(T,
cxmin,cxmax,cymin,cymax,czmin,czmax,ctmin,ctmax)) continue;
/* Plot the color fills */
plotX3D_single_fill_tria(T,
cxmin,cxmax,cymin,cymax,czmin,czmax,ctmin,ctmax,
logx, logy, logz, logt, contclip, 1);
/* Plot the mesh */
if (meshplot)
plotX3D_single_solid_tria(T,
cxmin,cxmax,cymin,cymax,czmin,czmax,ctmin,ctmax,
logx, logy, logz, logt, clipz,
filltype, fillcolor, linetype, linecolor, 1);
}
/* Delete the slice */
CNdelete_slice(slice);
}
/*
* Z slice
*/
if (zminin) {
/* Draw the surface at z=zmax */
tmp = grid->zmax;
if (tmp > czmax) tmp = czmax;
} else {
/* Draw the surface at z=zmin */
tmp = grid->zmin;
if (tmp < czmin) tmp = czmin;
}
if ((slice = CNslice_grid4D_z(grid,tmp,(int)contintrp,verbose)) != NULL) {
/* Loop through the rectangles */
for (R=slice->recthead; R!=NULL; R=R->next) {
/* Quick check to see if the rectangle is in-bounds */
if (!CNrect_in_bounds(R,
cxmin,cxmax,cymin,cymax,czmin,czmax,ctmin,ctmax)) continue;
/* Plot the color fills */
plotX3D_single_fill_rect(R,
cxmin,cxmax,cymin,cymax,czmin,czmax,ctmin,ctmax,
logx, logy, logz, logt, contclip, 1);
/* Plot the mesh */
if (meshplot)
plotX3D_single_solid_rect(R,
cxmin,cxmax,cymin,cymax,czmin,czmax,ctmin,ctmax,
logx, logy, logz, logt, clipz,
filltype, fillcolor, linetype, linecolor, 1);
}
/* Loop through the triangles */
for (T=slice->triahead; T!=NULL; T=T->next) {
/* Quick check to see if the triangle is in-bounds */
if (!CNtria_in_bounds(T,
cxmin,cxmax,cymin,cymax,czmin,czmax,ctmin,ctmax)) continue;
/* Plot the color fills */
plotX3D_single_fill_tria(T,
cxmin,cxmax,cymin,cymax,czmin,czmax,ctmin,ctmax,
logx, logy, logz, logt, contclip, 1);
/* Plot the mesh */
if (meshplot)
plotX3D_single_solid_tria(T,
cxmin,cxmax,cymin,cymax,czmin,czmax,ctmin,ctmax,
logx, logy, logz, logt, clipz,
filltype, fillcolor, linetype, linecolor, 1);
}
/* Delete the slice */
CNdelete_slice(slice);
}
}
/*
* Plot the mesh4D in X11
*/
static void plotX3D_mesh4D(dptr)
CNdatasetptr dptr;
{
void PXidentify_view_planes();
CNmesh4Dptr mesh4D_grid=NULL, mesh4D_quant=NULL;
CNcubeptr cubehead=NULL, cubetail=NULL;
CNblockptr blockhead=NULL,blocktail=NULL, B;
int verbose=0;
int xminin, xmaxin, yminin, ymaxin, zminin, zmaxin;
double cxmin, cxmax, cymin, cymax, czmin, czmax, ctmin, ctmax;
short contclip, meshplot;
int dosort=1;
/* Error check */
if (dptr->mesh4D == NULL) return;
contclip = dptr->data_pr.contclip;
meshplot = dptr->data_pr.meshplot;
if (dptr->datatype != CN_MESH4D_P && dptr->datatype != CN_MESH4D_C) return;
if (dptr->datatype == CN_MESH4D_C) {
if (dptr->parent == NULL || dptr->parent->mesh4D == NULL) return;
mesh4D_grid = dptr->parent->mesh4D;
mesh4D_quant = dptr->mesh4D;
} else if (dptr->datatype == CN_MESH4D_P) {
mesh4D_grid = dptr->mesh4D;
mesh4D_quant = NULL;
meshplot = CN_TRUE;
} else {
return;
}
/*
* Identify the inner and outer planes in the current view
*/
PXidentify_view_planes(mesh4D_grid->xmin, mesh4D_grid->xmax,
mesh4D_grid->ymin, mesh4D_grid->ymax,
mesh4D_grid->zmin, mesh4D_grid->zmax,
&xminin, &xmaxin, &yminin, &ymaxin, &zminin, &zmaxin,
view_transfo);
/* clipping boundaries */
cxmin = ((xlog) ? pow(10.0,xmin) : xmin);
cxmax = ((xlog) ? pow(10.0,xmax) : xmax);
cymin = ((ylog) ? pow(10.0,ymin) : ymin);
cymax = ((ylog) ? pow(10.0,ymax) : ymax);
czmin = ((zlog) ? pow(10.0,zmin) : zmin);
czmax = ((zlog) ? pow(10.0,zmax) : zmax);
ctmin = -CN_LARGE;
ctmax = CN_LARGE;
/* Find the rectangles/triangles that are exposed */
CNslice_mesh4D(mesh4D_grid, mesh4D_quant,
&blockhead, &blocktail, &cubehead, &cubetail,
cxmin,cxmax,cymin,cymax,czmin,czmax,
xminin,xmaxin,yminin,ymaxin,zminin,zmaxin,verbose);
if (cubehead == NULL) return;
/* Sort the blocks */
if (dosort) {
if (quick_sort)
CNdo_quick_sort_blocks(&blockhead, &blocktail,
view_transfo, xlog, ylog, zlog);
else
CNbubble_sort_blocks( &blockhead, &blocktail,
view_transfo, xlog, ylog, zlog);
}
/* Loop through the blocks */
for (B=blockhead; B!=NULL; B=B->next) {
if (B->cube == NULL) continue;
/* Plot a cube */
plotX3D_mesh4D_cube(B,
cxmin,cxmax,cymin,cymax,czmin,czmax,ctmin,ctmax,
xminin, xmaxin, yminin, ymaxin, zminin, zmaxin,
mesh4D_grid, mesh4D_quant, contclip, meshplot);
}
/* Delete the blocks, cubes and rectangles */
CNdelete_block_list(&blockhead, &blocktail);
CNdelete_cube_list (&cubehead , &cubetail);
}
/*
* Plot a single mesh-cube
*/
static void plotX3D_mesh4D_cube(B,
cxmin, cxmax, cymin, cymax, czmin, czmax, ctmin, ctmax,
xminin, xmaxin, yminin, ymaxin, zminin, zmaxin,
mesh4D_grid, mesh4D_quant, contclip, meshplot)
CNblockptr B;
double cxmin, cxmax, cymin, cymax, czmin, czmax, ctmin, ctmax;
int xminin, xmaxin, yminin, ymaxin, zminin, zmaxin;
CNmesh4Dptr mesh4D_grid, mesh4D_quant;
short contclip, meshplot;
{
CNpolyptr polyhead=NULL, polytail=NULL, P; /* List of polygons */
CNnodeptr nodehead=NULL, nodetail=NULL; /* List of nodes */
CNpointptr pointhead=NULL,pointtail=NULL; /* List of points */
int dosort=0;
int clipz=1;
int nocont, noplot, color;
int filltype, fillcolor, linetype, linecolor;
if (B == NULL || B->cube == NULL) return;
/*
* Get the list of polygons on the cube
*/
CNfind_exposed_faces_of_cube(B, mesh4D_grid,
&polyhead, &polytail,
&nodehead, &nodetail,
&pointhead, &pointtail,
xminin, xmaxin,
yminin, ymaxin,
zminin, zmaxin, &dosort);
/* Sort the polygons */
if (dosort) {
if (quick_sort)
CNdo_quick_sort_polys(&polyhead, &polytail,
view_transfo, xlog, ylog, zlog);
else
CNbubble_sort_polys( &polyhead, &polytail,
view_transfo, xlog, ylog, zlog);
}
/* Draw each polygon in the prism */
for (P=polyhead; P!=NULL; P=P->next) {
/*
* Get the plotting parameters for this material
* nocont - don't draw contours (just draw surface)
* noplot - don't draw the polygon at all
* color - fill color (if the surface is to be drawn)
*/
CNmesh4D_mat_options(P->region,
mesh4D_grid->regionhead, mesh4D_grid->regiontail,
&nocont, &noplot, &color);
if (noplot) continue;
/* Plot the color fills (only for quant-type meshes) */
if (mesh4D_quant && !nocont)
plotX3D_single_fill_poly(P,
cxmin,cxmax,cymin,cymax,czmin,czmax,ctmin,ctmax,
contclip, 1);
/* Plot the mesh (must do this for grid) */
if ((meshplot) || (mesh4D_quant && nocont)) {
filltype = CN_FILL_SOLID;
if (mesh4D_quant && !nocont) filltype = CN_FILL_NONE;
fillcolor = PXpolyColorIndexX(color);
linetype = (meshplot) ? CN_LN_SOLID : CN_LN_NONE;
linecolor = PXpolyColorIndexX(4); /* red */
plotX3D_single_solid_poly(P,
cxmin,cxmax,cymin,cymax,czmin,czmax,ctmin,ctmax,
clipz,
filltype, fillcolor, linetype, linecolor, 1);
}
}
/* Delete the polygons, nodes, points */
CNdelete_poly_list(&polyhead, &polytail);
CNdelete_node_list(&nodehead, &nodetail);
CNdelete_point_list(&pointhead, &pointtail);
}
/*
* Plot the vectors in X11
*/
static void plotX3D_vectors(Vbox, vlog, vscale, vlogscale, vhead, vtail)
CNvecboxptr Vbox;
int vlog;
double vscale, vlogscale;
int vhead, vtail;
{
CNvecptr Vptr;
double px, py, pz;
double vx, vy, vz;
double x1, y1, x2, y2;
double vmin;
double cxmin, cxmax, cymin, cymax, czmin, czmax;
int p1_clipped=CN_FALSE, p2_clipped=CN_FALSE;
if (Vbox == NULL) return;
if (vlog) {
vmin = 0.1*Vbox->vlen_min;
if (vmin == 0.0) vmin = 1.0;
}
/* Clipping boundary */
cxmin = ((xlog) ? pow(10.0,xmin) : xmin);
cxmax = ((xlog) ? pow(10.0,xmax) : xmax);
cymin = ((ylog) ? pow(10.0,ymin) : ymin);
cymax = ((ylog) ? pow(10.0,ymax) : ymax);
czmin = ((zlog) ? pow(10.0,zmin) : zmin);
czmax = ((zlog) ? pow(10.0,zmax) : zmax);
/* Go thru the vectors */
for (Vptr=Vbox->vectorhead; Vptr!=NULL; Vptr=Vptr->next) {
/* Check plot flag */
if (Vptr->noplot) continue;
if ( (Vptr->x < cxmin || Vptr->x > cxmax) ||
(Vptr->y < cymin || Vptr->y > cymax) ||
(Vptr->z < czmin || Vptr->z > czmax) ) continue;
/* Scale the vector starting point */
px = (xlog) ? CNlog10(Vptr->x) : Vptr->x;
py = (ylog) ? CNlog10(Vptr->y) : Vptr->y;
pz = (zlog) ? CNlog10(Vptr->z) : Vptr->z;
trn_world_to_X11(px,py,pz,&x1,&y1);
/* Scale to the dimensions of the plot specified in the Vbox */
if (vlog) {
vx = CNveclog10(Vptr->vx/vmin) * vlogscale;
vy = CNveclog10(Vptr->vy/vmin) * vlogscale;
vz = CNveclog10(Vptr->vz/vmin) * vlogscale;
} else {
vx = Vptr->vx * vscale;
vy = Vptr->vy * vscale;
vz = Vptr->vz * vscale;
}
/* Scale the vector ending point */
px = (xlog) ? CNlog10(Vptr->x + vx) : Vptr->x + vx;
py = (ylog) ? CNlog10(Vptr->y + vy) : Vptr->y + vy;
pz = (zlog) ? CNlog10(Vptr->z + vz) : Vptr->z + vz;
trn_world_to_X11(px,py,pz,&x2,&y2);
/* Draw the arrow */
plotX3D_arrow(x1,y1,x2,y2,
p1_clipped, p2_clipped,
(char *)NULL,
(int)Vbox->linetype,
(int)Vbox->linecolor,
(int)Vbox->linewidth,
(int)( vtail ? Vbox->marktype : CN_MK_NONE ),
1,
(int)Vbox->markcolor,vhead);
}
}
/*
* Plot the boundary in X11
*/
/*ARGSUSED*/
static void plotX3D_boundary(Dptr, boundary, fillbnd, pr_rgID, fill, drawlabel)
CNdatasetptr Dptr;
int boundary, fillbnd, pr_rgID;
int fill, drawlabel;
{
CNregionptr R;
CNpolyptr P;
CNnodeptr node_head=NULL, node_tail=NULL, N;
double cxmin, cxmax, cymin, cymax, czmin, czmax, ctmin, ctmax;
if (Dptr->regionhead == NULL) return;
if (boundary==CN_FALSE && fillbnd==FALSE) return;
/* The linetype is solid */
XSetLineAttributes(display,gc,1,LineSolid,CapButt,JoinBevel);
PXsetColorX(0);
/* Reset the fill - if the boundary is False then don't fill */
if (fillbnd == CN_FALSE) fill=CN_FALSE;
/*
* Clipping Boundary
*/
cxmin = ((xlog) ? pow(10.0,xmin) : xmin);
cxmax = ((xlog) ? pow(10.0,xmax) : xmax);
cymin = ((ylog) ? pow(10.0,ymin) : ymin);
cymax = ((ylog) ? pow(10.0,ymax) : ymax);
czmin = - CN_LARGE;
czmax = CN_LARGE;
ctmin = - CN_LARGE;
ctmax = CN_LARGE;
/* now print out the boundary segments in each region */
for (R=Dptr->regionhead; R!=NULL; R=R->next) {
for (P=R->polyhead; P!=NULL; P=P->next) {
/* Clip the polygon */
CNclip_poly(P, &node_head, &node_tail,
cxmin, cxmax, cymin, cymax, czmin, czmax, ctmin, ctmax,
1, 1, 0, 0, 0);
/* Adjust the z and t values of the nodes */
for (N=node_head; N!=NULL; N=N->next) {
N->coord->z = ((zlog) ? pow(10.0,zmin) : zmin);
N->t = ((zlog) ? pow(10.0,zmin) : zmin);
}
/* Plot the nodes */
plotX3D_nodes(node_head, node_tail,
fill ? CN_FILL_SOLID : CN_FILL_NONE,
PXpolyColorIndexX(R->color),
boundary ? CN_LN_SOLID : CN_LN_NONE, 0, 1, 0);
/* Delete the node-list */
CNremove_node_list(&node_head, &node_tail);
}
}
}
/*
* Plot the triangular mesh in X11
*/
static void plotX3D_trias(Dptr,contfill,meshplot)
CNdatasetptr Dptr;
int contfill; /* Draw multi-colored triangles */
int meshplot; /* Draw only the mesh */
{
CNtriaptr T;
double cxmin, cxmax, cymin, cymax, czmin, czmax, ctmin, ctmax;
int hdnline;
int clipz=1;
int linetype, linecolor, filltype, fillcolor;
if (Dptr->triahead == NULL) return;
/* Initialize colors and line/fill types */
hdnline = hiddenline || Dptr->view_pr->hiddenline;
if (contfill) hdnline = CN_FALSE;
filltype = (hdnline) ? CN_FILL_SOLID : CN_FILL_NONE;
linetype = CN_LN_SOLID;
fillcolor = PXpolyColorIndexX(1); /* yellow */
linecolor = PXpolyColorIndexX(4); /* red */
/* Sort these triangles */
if (contfill || hiddenline || Dptr->view_pr->hiddenline) {
/* sort the mesh */
if (quick_sort)
CNdo_quick_sort_trias(&(Dptr->triahead),
&(Dptr->triatail),
view_transfo, xlog, ylog, zlog);
else
CNbubble_sort_trias( &(Dptr->triahead),
&(Dptr->triatail),
view_transfo, xlog, ylog, zlog);
}
/*
* Clipping Boundary
*/
cxmin = ((xlog) ? pow(10.0,xmin) : xmin);
cxmax = ((xlog) ? pow(10.0,xmax) : xmax);
cymin = ((ylog) ? pow(10.0,ymin) : ymin);
cymax = ((ylog) ? pow(10.0,ymax) : ymax);
czmin = - CN_LARGE;
czmax = CN_LARGE;
ctmin = ((zlog) ? pow(10.0,zmin) : zmin);
ctmax = ((zlog) ? pow(10.0,zmax) : zmax);
/* Loop through the triangles */
for (T=Dptr->triahead; T!=NULL; T=T->next) {
/* Quick check to see if the triangle is in-bounds */
if (!CNtria_in_bounds(T,
cxmin,cxmax,cymin,cymax,czmin,czmax,ctmin,ctmax)) continue;
/* Draw a fill triangle with gradated colors */
if (contfill) {
plotX3D_single_fill_tria(T,
cxmin, cxmax, cymin, cymax,
czmin, czmax, ctmin, ctmax,
Dptr->data_pr.logx,
Dptr->data_pr.logy,
0,
Dptr->data_pr.logz,
Dptr->data_pr.contclip, 0);
}
/* Draw a mesh triangle */
if (meshplot) {
plotX3D_single_solid_tria(T,
cxmin, cxmax, cymin, cymax,
czmin, czmax, ctmin, ctmax,
Dptr->data_pr.logx,
Dptr->data_pr.logy,
0,
Dptr->data_pr.logz,
clipz,
filltype, fillcolor, linetype, linecolor, 0);
}
}
/* Reset color */
PXsetColorX(0);
}
/*
* Plot the rectangular mesh in X11
*/
static void plotX3D_rects(Dptr,contfill,meshplot)
CNdatasetptr Dptr;
int contfill; /* Draw multi-colored rectangles*/
int meshplot; /* Draw only the mesh */
{
CNrectptr R;
double cxmin, cxmax, cymin, cymax, czmin, czmax, ctmin, ctmax;
int hdnline;
int clipz=0;
int linetype, linecolor, filltype, fillcolor;
if (Dptr->recthead == NULL) return;
/* Initialize colors and line/fill types */
hdnline = hiddenline || Dptr->view_pr->hiddenline;
if (contfill) hdnline = CN_FALSE;
filltype = (hdnline) ? CN_FILL_SOLID : CN_FILL_NONE;
linetype = CN_LN_SOLID;
fillcolor = PXpolyColorIndexX(1); /* yellow */
linecolor = PXpolyColorIndexX(4); /* red */
/* Sort these rectangles */
if (contfill || hiddenline || Dptr->view_pr->hiddenline) {
/* sort the mesh */
if (quick_sort)
CNdo_quick_sort_rects(&(Dptr->recthead),
&(Dptr->recttail),
view_transfo, xlog, ylog, zlog);
else
CNbubble_sort_rects( &(Dptr->recthead),
&(Dptr->recttail),
view_transfo, xlog, ylog, zlog);
}
/*
* Clipping Boundary
*/
cxmin = ((xlog) ? pow(10.0,xmin) : xmin);
cxmax = ((xlog) ? pow(10.0,xmax) : xmax);
cymin = ((ylog) ? pow(10.0,ymin) : ymin);
cymax = ((ylog) ? pow(10.0,ymax) : ymax);
czmin = - CN_LARGE;
czmax = CN_LARGE;
ctmin = ((zlog) ? pow(10.0,zmin) : zmin);
ctmax = ((zlog) ? pow(10.0,zmax) : zmax);
/* Loop through the rectangles */
for (R=Dptr->recthead; R!=NULL; R=R->next) {
/* Quick check to see if the rectangle is in-bounds */
if (!CNrect_in_bounds(R,
cxmin,cxmax,cymin,cymax,czmin,czmax,ctmin,ctmax)) continue;
/* Draw a fill rectangle with gradated colors */
if (contfill) {
plotX3D_single_fill_rect(R,
cxmin, cxmax, cymin, cymax,
czmin, czmax, ctmin, ctmax,
Dptr->data_pr.logx,
Dptr->data_pr.logy,
0,
Dptr->data_pr.logz,
Dptr->data_pr.contclip, 0);
}
/* Draw a mesh rectangle */
if (meshplot) {
plotX3D_single_solid_rect(R,
cxmin, cxmax, cymin, cymax,
czmin, czmax, ctmin, ctmax,
Dptr->data_pr.logx,
Dptr->data_pr.logy,
0,
Dptr->data_pr.logz,
clipz,
filltype, fillcolor, linetype, linecolor, 0);
}
}
/* Reset color */
PXsetColorX(0);
}
/*
* Plot the polygonal mesh in X11
*/
static void plotX3D_polys(Dptr,contfill,meshplot)
CNdatasetptr Dptr;
int contfill; /* Draw multi-colored polygons */
int meshplot; /* Draw only the mesh */
{
CNpolyptr P;
double cxmin, cxmax, cymin, cymax, czmin, czmax, ctmin, ctmax;
int clipz=1;
int dosort=1;
int nocont, noplot, color;
int linetype, linecolor, filltype, fillcolor;
if (Dptr->polyhead == NULL) return;
/* Sort these polygons */
if (dosort) {
if (quick_sort)
CNdo_quick_sort_polys(&(Dptr->polyhead),
&(Dptr->polytail),
view_transfo, xlog, ylog, zlog);
else
CNbubble_sort_polys( &(Dptr->polyhead),
&(Dptr->polytail),
view_transfo, xlog, ylog, zlog);
}
/*
* Clipping Boundary
*/
cxmin = ((xlog) ? pow(10.0,xmin) : xmin);
cxmax = ((xlog) ? pow(10.0,xmax) : xmax);
cymin = ((ylog) ? pow(10.0,ymin) : ymin);
cymax = ((ylog) ? pow(10.0,ymax) : ymax);
czmin = ((zlog) ? pow(10.0,zmin) : zmin);
czmax = ((zlog) ? pow(10.0,zmax) : zmax);
ctmin = - CN_LARGE;
ctmax = CN_LARGE;
/* Loop through the polygons */
for (P=Dptr->polyhead; P!=NULL; P=P->next) {
/*
* Get the plotting parameters for this material
* nocont - don't draw contours (just draw surface)
* noplot - don't draw the polygon at all
* color - fill color (if the surface is to be drawn)
*/
CNmesh4D_mat_options(P->region,
Dptr->regionhead, Dptr->regiontail,
&nocont, &noplot, &color);
if (noplot) continue;
/* Plot parameters */
filltype = CN_FILL_SOLID;
fillcolor = PXpolyColorIndexX(color);
linetype = (meshplot) ? CN_LN_SOLID : CN_LN_NONE;
linecolor = PXpolyColorIndexX(4); /* red */
/* Draw a fill rectangle with gradated colors */
if (contfill && !nocont) {
plotX3D_single_fill_poly(P,
cxmin, cxmax, cymin, cymax,
czmin, czmax, ctmin, ctmax,
Dptr->data_pr.contclip, 1);
filltype = CN_FILL_NONE;
}
/* Draw a mesh rectangle */
plotX3D_single_solid_poly(P,
cxmin, cxmax, cymin, cymax,
czmin, czmax, ctmin, ctmax,
clipz,
filltype, fillcolor, linetype, linecolor, 1);
}
/* Reset color */
PXsetColorX(0);
}
/*
* Plot a single solid triangle
*/
static void plotX3D_single_solid_tria(T,
cxmin, cxmax, cymin, cymax,
czmin, czmax, ctmin, ctmax,
logx, logy, logz, logt,
clipz,
filltype, fillcolor,
linetype, linecolor,
draw_points)
CNtriaptr T;
double cxmin, cxmax, cymin, cymax, czmin, czmax, ctmin, ctmax;
short logx, logy, logz, logt;
int clipz;
int filltype, fillcolor;
int linetype, linecolor;
int draw_points;
{
CNnodeptr node_head=NULL, node_tail=NULL;
/* Check the triangle */
if (T == NULL) return;
/* Clip the triangle */
CNclip_tria(T, &node_head, &node_tail,
cxmin, cxmax, cymin, cymax, czmin, czmax, ctmin, ctmax,
1, 1, clipz, 1,
logx, logy, logz, logt, 0);
if (node_head == NULL) return;
/* Plot the nodes */
plotX3D_nodes(node_head, node_tail,
filltype, fillcolor, linetype, linecolor, 1, draw_points);
/* Delete the node-list */
CNremove_node_list(&node_head, &node_tail);
}
/*
* Plot a single solid rectangle
*/
static void plotX3D_single_solid_rect(R,
cxmin, cxmax, cymin, cymax,
czmin, czmax, ctmin, ctmax,
logx, logy, logz, logt,
clipz,
filltype, fillcolor,
linetype, linecolor,
draw_points)
CNrectptr R;
double cxmin, cxmax, cymin, cymax, czmin, czmax, ctmin, ctmax;
short logx, logy, logz, logt;
int clipz;
int filltype, fillcolor;
int linetype, linecolor;
int draw_points;
{
CNnodeptr node_head=NULL, node_tail=NULL;
/* Check the rectangle */
if (R == NULL) return;
/* Clip the rectangle */
CNclip_rect(R, &node_head, &node_tail,
cxmin, cxmax, cymin, cymax, czmin, czmax, ctmin, ctmax,
1, 1, clipz, 1,
logx, logy, logz, logt, 0);
if (node_head == NULL) return;
/* Plot the nodes */
plotX3D_nodes(node_head, node_tail,
filltype, fillcolor, linetype, linecolor, 1, draw_points);
/* Delete the node-list */
CNremove_node_list(&node_head, &node_tail);
}
/*
* Plot a single solid polygon
*/
static void plotX3D_single_solid_poly(P,
cxmin, cxmax, cymin, cymax,
czmin, czmax, ctmin, ctmax,
clipz,
filltype, fillcolor,
linetype, linecolor,
draw_points)
CNpolyptr P;
double cxmin, cxmax, cymin, cymax, czmin, czmax, ctmin, ctmax;
int clipz;
int filltype, fillcolor;
int linetype, linecolor;
int draw_points;
{
CNnodeptr node_head=NULL, node_tail=NULL;
/* Check the polygon */
if (P == NULL) return;
/* Clip the polygon */
CNclip_poly(P, &node_head, &node_tail,
cxmin, cxmax, cymin, cymax, czmin, czmax, ctmin, ctmax,
1, 1, clipz, 1, 0);
if (node_head == NULL) return;
/* Plot the nodes */
plotX3D_nodes(node_head, node_tail,
filltype, fillcolor, linetype, linecolor, 1, draw_points);
/* Delete the node-list */
CNremove_node_list(&node_head, &node_tail);
}
/*
* Draw fill colors in a triangle
*/
/*ARGSUSED*/
static void plotX3D_single_fill_tria(T,
cxmin, cxmax, cymin, cymax,
czmin, czmax, ctmin, ctmax,
logx, logy, logz, logt,
contclip, draw_points)
CNtriaptr T;
double cxmin, cxmax, cymin, cymax, czmin, czmax, ctmin, ctmax;
short logx, logy, logz, logt;
short contclip;
int draw_points;
{
CNcontstepptr C;
CNnodeptr node_head=NULL, node_tail=NULL;
double tmin, tmax, min, max;
int i, colr, nctrs;
/* Check the triangle */
if (T == NULL) return;
/* If the nocont flag is set, skip */
if (T->nocont) return;
/* Get the min and max of the triangle */
CNget_tria_tmaxmin(T,&tmin,&tmax);
/*
* The contour steps are calculated outside so that there is
* a common steps for all the contour datasets
*/
nctrs = CNcount_contsteps(cstephead, csteptail) - 1;
/* Loop through the contours - min of 2 steps */
i = 0;
for (C=cstephead; C!=NULL; C=C->next) {
/*
* There will be nctrs+1 bands; make sure each of these
* has a distinct color.
* Scale the colors from 1 to 32
*/
colr = (int)((double)(i*(PX_MAX_FILL_COLORS-1))/(double)nctrs) + 1;
/* Increment the step number */
i++;
/* Set the clipping levels */
/*
* The contour steps selected in CNselect_contour_step()
* do not necessarily cover the whole range [tmin..tmax],
* i.e. cstephead->value approx cmin, and csteptail->value approx cmax
* However in PXquery_contours() an additional step corresponding
* to the the max step size CN_LARGE is automatically added.
*/
if (C->prev == NULL) {
max = C->value;
min = -CN_LARGE;
if (contclip) continue;
} else {
max = C->value;
min = C->prev->value;
if (contclip && max==CN_LARGE) continue;
}
/* Clip the triangle */
/*EMPTY*/
if (tmax < min || tmin > max) {
/* Don't do anything */
;
} else {
if (min < ctmin) min = ctmin;
if (max > ctmax) max = ctmax;
/* Clip the triangle */
CNclip_tria(T, &node_head, &node_tail,
cxmin, cxmax, cymin, cymax, czmin, czmax, min, max,
1, 1, 1, 1,
logx, logy, logz, logt, 0);
/* Plot the nodes */
plotX3D_nodes(node_head, node_tail,
CN_FILL_SOLID, PXfillColorIndex(colr),
CN_LN_NONE, 0, 1, draw_points);
/* Delete the node-list */
CNremove_node_list(&node_head, &node_tail);
}
}
}
/*
* Draw fill colors in a rectangle
*/
/*ARGSUSED*/
static void plotX3D_single_fill_rect(R,
cxmin, cxmax, cymin, cymax,
czmin, czmax, ctmin, ctmax,
logx, logy, logz, logt,
contclip, draw_points)
CNrectptr R;
double cxmin, cxmax, cymin, cymax, czmin, czmax, ctmin, ctmax;
short logx, logy, logz, logt;
short contclip;
int draw_points;
{
CNcontstepptr C;
CNnodeptr node_head=NULL, node_tail=NULL;
double tmin, tmax, min, max;
int i, colr, nctrs;
/* Check the rectangle */
if (R == NULL) return;
/* Get the min and max of the rectangle */
CNget_rect_tmaxmin(R,&tmin,&tmax);
/*
* The contour steps are calculated outside so that there is
* a common steps for all the contour datasets
*/
nctrs = CNcount_contsteps(cstephead, csteptail) - 1;
/* Loop through the contours - min of 2 ctrs */
i = 0;
for (C=cstephead; C!=NULL; C=C->next) {
/*
* There will be nctrs+1 bands; make sure each of these
* has a distinct color.
* Scale the colors from 1 to 32
*/
colr = (int)((double)(i*(PX_MAX_FILL_COLORS-1))/(double)nctrs) + 1;
/* Increment the step number */
i++;
/* Set the clipping levels */
/*
* The contour steps selected in CNselect_contour_step()
* do not necessarily cover the whole range [tmin..tmax],
* i.e. cstephead->value approx cmin, and csteptail->value approx cmax
* However in PXquery_contours() an additional step corresponding
* to the the max step size CN_LARGE is automatically added.
*/
if (C->prev == NULL) {
max = C->value;
min = -CN_LARGE;
if (contclip) continue;
} else {
max = C->value;
min = C->prev->value;
if (contclip && max==CN_LARGE) continue;
}
/* Clip the rectangle */
/*EMPTY*/
if (tmax < min || tmin > max) {
/* Don't do anything */
;
} else {
if (min < ctmin) min = ctmin;
if (max > ctmax) max = ctmax;
/* Clip the rectangle */
CNclip_rect(R, &node_head, &node_tail,
cxmin, cxmax, cymin, cymax, czmin, czmax, min, max,
1, 1, 1, 1,
logx, logy, logz, logt, 0);
/* Plot the nodes */
plotX3D_nodes(node_head, node_tail,
CN_FILL_SOLID, PXfillColorIndex(colr),
CN_LN_NONE,0,1,draw_points);
/* Delete the node-list */
CNremove_node_list(&node_head, &node_tail);
}
}
}
/*
* Draw fill colors in a polygon
*/
/*ARGSUSED*/
static void plotX3D_single_fill_poly(P,
cxmin, cxmax, cymin, cymax,
czmin, czmax, ctmin, ctmax,
contclip, draw_points)
CNpolyptr P;
double cxmin, cxmax, cymin, cymax, czmin, czmax, ctmin, ctmax;
short contclip;
int draw_points;
{
CNcontstepptr C;
CNnodeptr node_head=NULL, node_tail=NULL;
double tmin, tmax, min, max;
int i, colr, nctrs;
/* Check the polygon */
if (P == NULL) return;
/* Get the min and max of the polygon */
CNget_poly_tmaxmin(P,&tmin,&tmax);
/*
* The contour steps are calculated outside so that there is
* a common steps for all the contour datasets
*/
nctrs = CNcount_contsteps(cstephead, csteptail) - 1;
/* Loop through the contours - min of 2 ctrs */
i = 0;
for (C=cstephead; C!=NULL; C=C->next) {
/*
* There will be nctrs+1 bands; make sure each of these
* has a distinct color.
* Scale the colors from 1 to 32
*/
colr = (int)((double)(i*(PX_MAX_FILL_COLORS-1))/(double)nctrs) + 1;
/* Increment the step number */
i++;
/* Set the clipping levels */
/*
* The contour steps selected in CNselect_contour_step()
* do not necessarily cover the whole range [tmin..tmax],
* i.e. cstephead->value approx cmin, and csteptail->value approx cmax
* However in PXquery_contours() an additional step corresponding
* to the the max step size CN_LARGE is automatically added.
*/
if (C->prev == NULL) {
max = C->value;
min = -CN_LARGE;
if (contclip) continue;
} else {
max = C->value;
min = C->prev->value;
if (contclip && max==CN_LARGE) continue;
}
/* Clip the polygon */
/*EMPTY*/
if (tmax < min || tmin > max) {
/* Don't do anything */
;
} else {
if (min < ctmin) min = ctmin;
if (max > ctmax) max = ctmax;
/* Clip the polygon */
CNclip_poly(P, &node_head, &node_tail,
cxmin, cxmax, cymin, cymax, czmin, czmax, min, max,
1, 1, 1, 1, 0);
/* Plot the nodes */
plotX3D_nodes(node_head, node_tail,
CN_FILL_SOLID, PXfillColorIndex(colr),
CN_LN_NONE,0,1,draw_points);
/* Delete the node-list */
CNremove_node_list(&node_head, &node_tail);
}
}
}
/*
* Plot a list of nodes
*/
/*ARGSUSED*/
static void plotX3D_nodes(node_head, node_tail,
filltype, fillcolor, linestyle, linecolor, linethick,
draw_points)
CNnodeptr node_head, node_tail;
int filltype, fillcolor, linestyle, linecolor, linethick;
int draw_points;
{
CNnodeptr N;
CNpointptr pt_head=NULL, pt_tail=NULL, P;
XPoint points[MAX_ARR_SIZE];
double cxmin,cxmax,cymin,cymax,czmin,czmax;
double px, py, pz;
double x, y;
int count;
/* return now if there is nothing to plot */
if (node_head == NULL) return;
/* if filltype and linestyle are both NONE (0), return now */
if ((filltype==CN_FILL_NONE) && (linestyle==CN_LN_NONE)) return;
/* rescale points, save in pointlist */
for (N=node_head; N!=NULL; N=N->next) {
/* Scale the point to the plot window */
px = (xlog) ? CNlog10(N->coord->x) : N->coord->x;
py = (ylog) ? CNlog10(N->coord->y) : N->coord->y;
pz = (zlog) ? CNlog10(N->t ) : N->t ;
if (draw_points)
pz = (zlog) ? CNlog10(N->coord->z) : N->coord->z;
trn_world_to_X11(px,py,pz,&x,&y);
/* Put the point in the list */
(void) CNinsert_tailpoint(&pt_head, &pt_tail, x, y, 0.0, 0);
}
/* Plot window boundaries */
cxmin = 0.0;
cxmax = (double) Width;
cymin = 0.0;
cymax = (double) Height;
czmin = -0.1; /* Not used */
czmax = 0.1; /* Not used */
/* Clip the pointlist against the plot boundary */
CNclip_pointlist(&pt_head,&pt_tail,
cxmin,cxmax,cymin,cymax,czmin,czmax,1,1,0,0);
if (pt_head == NULL) return;
/* Now transfer the list to an array */
count=0;
for (P=pt_head; P!=NULL && count<MAX_ARR_SIZE; P=P->next) {
points[count].x = (int)(P->x);
points[count].y = (int)(P->y);
count++;
}
/* Fill the polygon */
PXfillX_polygon(points, count,
filltype, fillcolor, linestyle, linecolor, linethick);
/* Delete the point-list */
CNdelete_point_list(&pt_head, &pt_tail);
}
/*
* Draw a set of curves in a dataset
*/
static void plotX3D_dataset_curves(dptr, colrinc, lineinc)
CNdatasetptr dptr;
int colrinc, lineinc;
{
CNcurveptr C;
int contour, contlbl, spline, hdnline, applyfill, pr_ptID;
/* Check the dataset first */
if (dptr == NULL || dptr->curvehead == NULL) return;
/* Initialize */
contour = dptr->datatype==CN_CONTOUR;
contlbl = dptr->data_pr.contlabel;
spline = dptr->data_pr.splinetyp;
hdnline = hiddenline || dptr->view_pr->hiddenline;
applyfill = dptr->data_pr.applyfill;
pr_ptID = dptr->data_pr.pr_ptID;
/* Sort these curves - don't sort contours */
if ((hiddenline || dptr->view_pr->hiddenline) && !nosort && !contour) {
/* sort the mesh */
if (quick_sort)
CNdo_quick_sort_curves(&(dptr->curvehead),
&(dptr->curvetail),
view_transfo, xlog, ylog, zlog);
else
CNbubble_sort_curves( &(dptr->curvehead),
&(dptr->curvetail),
view_transfo, xlog, ylog, zlog);
}
/* Go thru each set of curves */
for (C=dptr->curvehead; C!=NULL; C=C->next) {
/*
* Plot the curve
*/
if (dptr->data_pr.splinetyp == CN_SP_NONE) {
/* Plot the curve along the given (real) data-points */
plotX3D_curve(C,
colrinc,lineinc,
contour,contlbl,hdnline,applyfill,pr_ptID);
} else {
/* Plot the curve using spline-approximated data-points */
plotX3D_spline_curve(C,
spline,colrinc,lineinc,
contour,contlbl,hdnline,applyfill,pr_ptID);
}
}
}
/*
* Plot the curve in X11
*/
/*ARGSUSED*/
static void plotX3D_curve(C, colrinc, lineinc,
contour, contlbl, hiddenline, applyfill, pr_ptID)
CNcurveptr C;
int colrinc, lineinc, contour, contlbl, hiddenline, applyfill, pr_ptID;
{
CNpointptr pt_head=NULL, pt_tail=NULL, P;
XPoint points[MAX_ARR_SIZE];
double x,y;
int count, maxpts, linepat;
int linetype, linecolor, marktype, markcolor, fillcolor, filltype;
int marksize;
double cxmin,cxmax,cymin,cymax,czmin,czmax;
if (C==NULL || C->pointhead==NULL) return;
/*
* Make a copy of the points in the curve
*/
CNcopy_abslog_pointlist(&pt_head, &pt_tail,
C->pointhead, C->pointtail,
xabs, yabs, zabs, xlog, ylog, zlog);
if (pt_head == NULL) return;
/*
* Add a new point if the filltype is non-zero
*/
if (C->curv_pr.filltype != CN_FILL_NONE || hiddenline) {
(void) CNinsert_tailpoint(&pt_head, &pt_tail,
pt_head->x,
pt_head->y,
pt_head->z,
pt_head->ID);
}
/*
* Clip the curve against the domain boundaries first
*/
/* Domain boundaries */
cxmin = xmin;
cxmax = xmax;
cymin = ymin;
cymax = ymax;
czmin = zmin;
czmax = zmax;
/* Clip - this modifies the temporary point list */
CNclip_pointlist(&pt_head,&pt_tail,
cxmin,cxmax,cymin,cymax,czmin,czmax,1,1,1,0);
if (pt_head == NULL) return;
/*
* Another clipping - this time, clip against the plot window.
* If this is NOT done, the Xpoint array will be filled with
* negative/large numbers corresponding to points outside the
* drawing area, which slows down the drawing significantly!
*/
/* rescale points, save in array */
for (P=pt_head; P!=NULL; P=P->next) {
trn_world_to_X11(P->x,P->y,P->z,&x,&y);
P->x = x;
P->y = y;
P->z = 0.0;
}
/* Plot window boundaries */
cxmin = 0.0;
cxmax = (double) Width;
cymin = 0.0;
cymax = (double) Height;
czmin = -0.1; /* Not used */
czmax = 0.1; /* Not used */
/* Clip - this modifies the temporary point list */
CNclip_pointlist(&pt_head,&pt_tail,
cxmin,cxmax,cymin,cymax,czmin,czmax,1,1,0,0);
if (pt_head == NULL) return;
/*
* Set the properties of the curve.
*/
/* Set the line type */
linetype = C->curv_pr.linetype;
if (linetype != 0) linetype += lineinc;
/* Set the line color */
linecolor = C->curv_pr.linecolor;
if (linecolor > 0) linecolor += colrinc;
/* Set the marker type */
marktype = C->curv_pr.marktype;
if (marktype != 0) marktype += lineinc;
/* Set the marker size */
marksize = C->curv_pr.marksize;
/* Set the marker color */
markcolor = C->curv_pr.markcolor;
if (markcolor > 0) markcolor += colrinc;
/* Set the filltype - special treatment for hiddenline */
filltype = C->curv_pr.filltype;
if (hiddenline && C->curv_pr.filltype==CN_FILL_NONE)
filltype = CN_FILL_SOLID;
if (!applyfill) filltype = CN_FILL_NONE;
/* Set the fill color */
fillcolor = C->curv_pr.fillcolor;
if (filltype != CN_FILL_NONE) {
/* Fill the curve first */
fillX3D_curve(pt_head,pt_tail,filltype,fillcolor);
/* Set the linecolor now */
PXlineColorX(linecolor);
/* Reset the outline color if necessary */
if (hiddenline) PXlineColorX(4);
} else {
/* Set the linecolor now */
PXlineColorX(linecolor);
}
/*
* The X server has a practical limit on the number of points that
* can be plotted with one call. Find this limit and workaround if
* the limit is less than the no of elements in the permanent array.
*/
maxpts = XMaxRequestSize(display) - 3;
if (maxpts > MAX_ARR_SIZE) maxpts = MAX_ARR_SIZE;
/* Set the linetype and width */
linepat = PXlinetypX(linetype,C->curv_pr.linewidth);
/* First point */
P = pt_head;
/* go thru loop until we run out of points */
while (P != NULL && linepat) {
/* set count to 0 */
count = 0;
/* save points in array */
for ( ; P!=NULL && count<maxpts; P=P->next) {
points[count].x = (int)(P->x);
points[count].y = (int)(P->y);
count++;
}
if (count>0) {
if (count == 1) {
/*
* Some machines (IBM6000) don't like having an array with
* only one point
*/
if (window)
XDrawPoint(display,window,gc,points[0].x,points[0].y);
if (pixmap)
XDrawPoint(display,pixmap,gc,points[0].x,points[0].y);
} else {
/* plot the points */
if (window)
XDrawLines(display,window,gc,points,count,CoordModeOrigin);
if (pixmap)
XDrawLines(display,pixmap,gc,points,count,CoordModeOrigin);
}
}
/* if there are more points to come, repeat the last point */
if (P != NULL) P = P->prev;
}
/* Reset the linetype */
(void) PXlinetypX(CN_LN_SOLID,1);
/* Draw the markers - send the original list */
plotX3D_markers(C->pointhead, C->pointtail,
marktype, marksize, markcolor, pr_ptID, contour);
/* Delete the point-list */
CNdelete_point_list(&pt_head, &pt_tail);
/* Reset color */
PXsetColorX(0);
}
/*
* Fill the curve in X11
* The pointlist has already been scaled and clipped against
* the domain and plot boundaries
*/
/*ARGSUSED*/
static void fillX3D_curve(pt_head, pt_tail, filltype, fillcolor)
CNpointptr pt_head, pt_tail;
int filltype, fillcolor;
{
CNpointptr P;
XPoint points[MAX_ARR_SIZE];
int count;
if (pt_head == NULL) return;
/* If the curve is not to be filled then get out now */
if (filltype == CN_FILL_NONE) return;
/* save points in array */
count = 0;
for (P=pt_head; (P!=NULL) && (count<MAX_ARR_SIZE); P=P->next) {
points[count].x = (int)(P->x);
points[count].y = (int)(P->y);
count++;
}
/* Fill the polygon */
PXfillX_polygon(points,count,
filltype, PXpolyColorIndexX(fillcolor),CN_LN_NONE,0,1);
}
/*
* Plot the curve in X11
*/
/*ARGSUSED*/
static void plotX3D_spline_curve(C, splinetype, colrinc, lineinc,
contour, contlbl, hiddenline, applyfill,
pr_ptID)
CNcurveptr C;
int splinetype;
int colrinc, lineinc, contour, contlbl, hiddenline, applyfill, pr_ptID;
{
CNpointptr pt_head=NULL, pt_tail=NULL, P;
XPoint points[MAX_ARR_SIZE];
double *xarr, *yarr, *zarr, *xs, *ys, *zs;
double dist;
double x,y;
int npts, nspts, ndiv = 20, closed = 0;
int count, i, maxpts, linepat;
int linetype, linecolor, marktype, markcolor, fillcolor, filltype;
int marksize;
double cxmin,cxmax,cymin,cymax,czmin,czmax;
if (C==NULL || C->pointhead==NULL) return;
/*
* Make a copy of the points in the curve
*/
CNcopy_abslog_pointlist(&pt_head, &pt_tail,
C->pointhead, C->pointtail,
xabs, yabs, zabs, xlog, ylog, zlog);
/* Count the number of points in the curve */
npts = CNcount_points(pt_head, pt_tail);
/*
* Allocate double-precision arrays to hold x, y, z values
* for the original and interpolated data
*/
xarr = CNcreate_1D_double_array(npts);
yarr = CNcreate_1D_double_array(npts);
zarr = CNcreate_1D_double_array(npts);
xs = CNcreate_1D_double_array(npts*(ndiv+5));
ys = CNcreate_1D_double_array(npts*(ndiv+5));
zs = CNcreate_1D_double_array(npts*(ndiv+5));
/* Copy the data from the curve to the arrays */
i=0;
for (P=pt_head; P!=NULL; P=P->next) {
xarr[i] = P->x;
yarr[i] = P->y;
zarr[i] = P->z;
i++;
}
/* Distance between 1st and last point */
closed = 0;
dist = (xarr[0] - xarr[npts-1])*(xarr[0] - xarr[npts-1]) +
(yarr[0] - yarr[npts-1])*(yarr[0] - yarr[npts-1]) +
(zarr[0] - zarr[npts-1])*(zarr[0] - zarr[npts-1]);
if (dist < CN_SMALL) closed = 1;
if (C->curv_pr.filltype != CN_FILL_NONE || hiddenline) closed=1;
if (closed && dist<CN_SMALL && npts>1) npts--;
/* Interpolate using splines */
CNcreate_spline(xarr,npts,xs,&nspts,ndiv,splinetype,closed);
CNcreate_spline(yarr,npts,ys,&nspts,ndiv,splinetype,closed);
CNcreate_spline(zarr,npts,zs,&nspts,ndiv,splinetype,closed);
/* Transfer the arrays to back to a pointlist */
CNdelete_point_list(&pt_head,&pt_tail);
for (i=0; i<nspts; i++)
(void) CNinsert_tailpoint(&pt_head,&pt_tail,xs[i],ys[i],zs[i],i);
/* Make sure the closed curve is really closed - this comes from */
/* a problem with the spline interpolation */
if (closed)
(void) CNinsert_tailpoint(&pt_head,&pt_tail,xs[0],ys[0],zs[0],i);
/*
* Clip the curve against the domain boundaries first
*/
/* Domain boundaries */
cxmin = xmin;
cxmax = xmax;
cymin = ymin;
cymax = ymax;
czmin = zmin;
czmax = zmax;
/* Clip - this modifies the temporary point list */
CNclip_pointlist(&pt_head,&pt_tail,
cxmin,cxmax,cymin,cymax,czmin,czmax,1,1,1,0);
if (pt_head == NULL) return;
/*
* Another clipping - this time, clip against the plot window.
* If this is NOT done, the Xpoint array will be filled with
* negative/large numbers corresponding to points outside the
* drawing area, which slows down the drawing significantly!
*/
/* rescale points, save in array */
for (P=pt_head; P!=NULL; P=P->next) {
trn_world_to_X11(P->x,P->y,P->z,&x,&y);
P->x = x;
P->y = y;
P->z = 0.0;
}
/* Plot window boundaries */
cxmin = 0.0;
cxmax = (double) Width;
cymin = 0.0;
cymax = (double) Height;
czmin = -0.1; /* Not used */
czmax = 0.1; /* Not used */
/* Clip - this modifies the temporary point list */
CNclip_pointlist(&pt_head,&pt_tail,
cxmin,cxmax,cymin,cymax,czmin,czmax,1,1,0,0);
if (pt_head == NULL) return;
/*
* Set the properties of the curve.
*/
/* Set the line type */
linetype = C->curv_pr.linetype;
if (linetype != 0) linetype += lineinc;
/* Set the line color */
linecolor = C->curv_pr.linecolor;
if (linecolor > 0) linecolor += colrinc;
/* Set the line type */
marktype = C->curv_pr.marktype;
if (marktype != 0) marktype += lineinc;
/* Set the marker size */
marksize = C->curv_pr.marksize;
/* Set the marker color */
markcolor = C->curv_pr.markcolor;
if (markcolor > 0) markcolor += colrinc;
/* Set the filltype - special treatment for hiddenline */
filltype = C->curv_pr.filltype;
if (hiddenline && C->curv_pr.filltype==CN_FILL_NONE)
filltype = CN_FILL_SOLID;
if (!applyfill) filltype = CN_FILL_NONE;
/* Set the fill color */
fillcolor = C->curv_pr.fillcolor;
if (filltype != CN_FILL_NONE) {
/* Fill the curve first */
fillX3D_curve(pt_head,pt_tail,filltype,fillcolor);
/* Set the linecolor now */
PXlineColorX(linecolor);
/* Reset the outline color if necessary */
if (hiddenline) PXlineColorX(4);
} else {
/* Set the linecolor now */
PXlineColorX(linecolor);
}
/*
* The X server has a practical limit on the number of points that
* can be plotted with one call. Find this limit and workaround if
* the limit is less than the no of elements in the permanent array.
*/
maxpts = XMaxRequestSize(display) - 3;
if (maxpts > MAX_ARR_SIZE) maxpts = MAX_ARR_SIZE;
/* Set the linepattern and linewidth */
linepat = PXlinetypX(linetype,C->curv_pr.linewidth);
/*
* Can only plot some 1000-or-so points at a time, so
* go thru loop until we run out of points.
* P = running count of points
* count = points plotted during each major loop iteration
*/
P = pt_head;
/* go thru loop until we run out of points */
while ((P!=NULL) && linepat) {
/* set count to 0 */
count = 0;
/* save points in array */
for ( ; P!=NULL && count<maxpts; P=P->next) {
points[count].x = (int)(P->x);
points[count].y = (int)(P->y);
count++;
}
if (count > 0) {
if (count == 1) {
/*
* Some machines (IBM6000) don't like having an array with
* only one point
*/
if (window)
XDrawPoint(display,window,gc,points[0].x,points[0].y);
if (pixmap)
XDrawPoint(display,pixmap,gc,points[0].x,points[0].y);
} else {
/* plot the points */
if (window)
XDrawLines(display,window,gc,points,count,CoordModeOrigin);
if (pixmap)
XDrawLines(display,pixmap,gc,points,count,CoordModeOrigin);
}
}
/* if there are more points to come, repeat the last point */
if (P != NULL) P=P->prev;
}
/* Reset the linetype */
(void) PXlinetypX(CN_LN_SOLID,1);
/* Draw the markers */
plotX3D_markers(C->pointhead, C->pointtail,
marktype, marksize, markcolor, pr_ptID, contour);
/* Free the arrays */
CNfree_1D_double_array(xarr);
CNfree_1D_double_array(yarr);
CNfree_1D_double_array(zarr);
CNfree_1D_double_array(xs);
CNfree_1D_double_array(ys);
CNfree_1D_double_array(zs);
/* Delete the point-list */
CNdelete_point_list(&pt_head, &pt_tail);
/* Reset color */
PXsetColorX(0);
}
/*
* Plot the curve markers in X11
*/
/*ARGSUSED*/
static void plotX3D_markers(pointhead,pointtail,
marktype,marksize,markcolor,
pr_ptID,contour)
CNpointptr pointhead, pointtail;
int marktype, marksize,markcolor;
int pr_ptID, contour;
{
CNpointptr P, pt_head=NULL, pt_tail=NULL;
double px, py, pz;
double x,y;
double cxmin, cxmax, cymin, cymax, czmin, czmax;
double pxmin, pxmax, pymin, pymax;
if (pointhead == NULL) return;
/*
* Make a copy of the points in the curve
*/
CNcopy_abslog_pointlist(&pt_head, &pt_tail,
pointhead, pointtail,
xabs, yabs, zabs, xlog, ylog, zlog);
/* Set the linetype, width and marker color */
(void) PXlinetypX(CN_LN_SOLID,1);
PXlineColorX(markcolor);
/* Domain (Clip) boundaries */
cxmin = xmin;
cxmax = xmax;
cymin = ymin;
cymax = ymax;
czmin = zmin;
czmax = zmax;
/* Plot boundaries */
pxmin = 0.0;
pxmax = (double) Width;
pymin = 0.0;
pymax = (double) Height;
for (P=pt_head; P!=NULL && marktype!=CN_MK_NONE; P=P->next) {
if (P->x < cxmin || P->x > cxmax) continue;
if (P->y < cymin || P->y > cymax) continue;
if (P->z < czmin || P->z > czmax) continue;
/* rescale points */
px = P->x;
py = P->y;
pz = P->z;
trn_world_to_X11(px,py,pz,&x,&y);
/* plot the points only when the point is inside the window */
if (x < pxmin || x > pxmax) continue;
if (y < pymin || y > pymax) continue;
/* plot the marker */
PXmarkerX(marktype,marksize,(int)(x),(int)(y));
}
/* Draw curve-point ID's */
if (pr_ptID && !contour)
plotX3D_pointIDs(pt_head, pt_tail, CN_TRUE);
/* Delete the point-list */
CNdelete_point_list(&pt_head, &pt_tail);
/* Reset */
PXsetColorX(0);
}
/*
* LABELS
*/
/*
* Plot the point ID labels in X11
*/
/*ARGSUSED*/
static void plotX3D_pointIDs(pt_head,pt_tail,nolog)
CNpointptr pt_head, pt_tail;
int nolog;
{
CNpointptr P;
double x,y;
char label[CN_MAXCHAR];
int text_xpos, text_ypos, text_len;
double rxmin, rxmax, rymin, rymax;
double cxmin, cxmax, cymin, cymax, czmin, czmax;
double px, py, pz;
if (pt_head == NULL) return;
/* Boundary */
rxmin = 0;
rxmax = Width;
rymin = 0;
rymax = Height;
/* Clip boundaries */
if (nolog) {
cxmin = xmin;
cxmax = xmax;
cymin = ymin;
cymax = ymax;
czmin = zmin;
czmax = zmax;
} else {
cxmin = ((xlog) ? pow(10.0,xmin) : xmin);
cxmax = ((xlog) ? pow(10.0,xmax) : xmax);
cymin = ((ylog) ? pow(10.0,ymin) : ymin);
cymax = ((ylog) ? pow(10.0,ymax) : ymax);
czmin = ((zlog) ? pow(10.0,zmin) : zmin);
czmax = ((zlog) ? pow(10.0,zmax) : zmax);
}
/* Set the linetype, width and color */
(void) PXlinetypX(CN_LN_SOLID,1);
PXlineColorX(0);
/* Go thru each point */
for (P=pt_head; P!=NULL; P=P->next) {
/* Check to see if the point is in bounds */
if ( !( (P->x < cxmin) || (P->x > cxmax) ||
(P->y < cymin) || (P->y > cymax) ||
(P->z < czmin) || (P->z > czmax) ) ) {
if (nolog) {
px = P->x;
py = P->y;
pz = P->z;
} else {
px = (xlog) ? CNlog10(P->x) : P->x;
py = (ylog) ? CNlog10(P->y) : P->y;
pz = (zlog) ? CNlog10(P->z) : P->z;
}
trn_world_to_X11(px,py,pz,&x,&y);
/* Print the label only if the point is in bounds */
if (x > rxmin && x < rxmax && y > rymin && y < rymax) {
(void) sprintf(label,"P%d",P->ID);
text_len = strlen(label);
text_xpos = x;
text_ypos = y;
if (window)
XDrawString(display,window,gcl,text_xpos,text_ypos,label,text_len);
if (pixmap)
XDrawString(display,pixmap,gcl,text_xpos,text_ypos,label,text_len);
}
}
}
}
/*
* Plot the node ID labels in X11
*/
/*ARGSUSED*/
static void plotX3D_nodeIDs(nd_head,nd_tail)
CNnodeptr nd_head, nd_tail;
{
CNnodeptr N;
double x,y;
char label[CN_MAXCHAR];
int text_xpos, text_ypos, text_len, text_width;
double rxmin, rxmax, rymin, rymax;
double cxmin, cxmax, cymin, cymax, czmin, czmax;
double px, py, pz;
if (nd_head == NULL) return;
/* Boundary */
rxmin = 0;
rxmax = Width;
rymin = 0;
rymax = Height;
/* Clip boundaries */
cxmin = ((xlog) ? pow(10.0,xmin) : xmin);
cxmax = ((xlog) ? pow(10.0,xmax) : xmax);
cymin = ((ylog) ? pow(10.0,ymin) : ymin);
cymax = ((ylog) ? pow(10.0,ymax) : ymax);
czmin = ((zlog) ? pow(10.0,zmin) : zmin);
czmax = ((zlog) ? pow(10.0,zmax) : zmax);
/* Set the linetype, width and color */
(void) PXlinetypX(CN_LN_SOLID,1);
PXlineColorX(0);
/*
* Multiple nodes could share a single point so be smart about this
*/
/* Reset all the point-flags */
for (N=nd_head; N!=NULL; N=N->next) N->coord->flag = 0;
/* Go thru each node */
for (N=nd_head; N!=NULL; N=N->next) {
/* Check to see if the node is in bounds */
if ( !( (N->coord->x < cxmin) || (N->coord->x > cxmax) ||
(N->coord->y < cymin) || (N->coord->y > cymax) ||
(N->t < czmin) || (N->t > czmax) ) ) {
px = (xlog) ? CNlog10(N->coord->x) : N->coord->x;
py = (ylog) ? CNlog10(N->coord->y) : N->coord->y;
pz = (zlog) ? CNlog10(N->t ) : N->t;
trn_world_to_X11(px,py,pz,&x,&y);
/* Print the label only if the node is in bounds */
if (x > rxmin && x < rxmax && y > rymin && y < rymax) {
(void) sprintf(label,"N%d",N->ID);
text_len = strlen(label);
text_width = XTextWidth(lblfont_info,label,text_len);
text_xpos = x - text_width - 1;
text_ypos = y + N->coord->flag*lblfont_height;
if (window)
XDrawString(display,window,gcl,text_xpos,text_ypos,label,text_len);
if (pixmap)
XDrawString(display,pixmap,gcl,text_xpos,text_ypos,label,text_len);
/* Increment the point-flag */
(N->coord->flag)++;
}
}
}
/* Reset all the point-flags */
for (N=nd_head; N!=NULL; N=N->next) N->coord->flag = 0;
}
/*
* Plot the triangle ID labels in X11
*/
/*ARGSUSED*/
static void plotX3D_triaIDs(tr_head,tr_tail)
CNtriaptr tr_head, tr_tail;
{
CNtriaptr T;
double x,y,midx,midy,midz;
char label[CN_MAXCHAR];
int text_xpos, text_ypos, text_len, text_width;
double rxmin, rxmax, rymin, rymax;
double cxmin, cxmax, cymin, cymax, czmin, czmax;
double px, py, pz;
if (tr_head == NULL) return;
/* Boundary */
rxmin = 0;
rxmax = Width;
rymin = 0;
rymax = Height;
/* Clip boundaries */
cxmin = ((xlog) ? pow(10.0,xmin) : xmin);
cxmax = ((xlog) ? pow(10.0,xmax) : xmax);
cymin = ((ylog) ? pow(10.0,ymin) : ymin);
cymax = ((ylog) ? pow(10.0,ymax) : ymax);
czmin = ((zlog) ? pow(10.0,zmin) : zmin);
czmax = ((zlog) ? pow(10.0,zmax) : zmax);
/* Set the linetype, width and color */
(void) PXlinetypX(CN_LN_SOLID,1);
PXlineColorX(0);
/* Go thru each triangle */
for (T=tr_head; T!=NULL; T=T->next) {
/* Get the x-y-t value of the triangle-midpoint */
midx = T->n1->coord->x + T->n2->coord->x + T->n3->coord->x;
midy = T->n1->coord->y + T->n2->coord->y + T->n3->coord->y;
midz = T->n1->t + T->n2->t + T->n3->t ;
midx = midx/3.0;
midy = midy/3.0;
midz = midz/3.0;
/* Check to see if the point is in bounds */
if ( !( (midx < cxmin) || (midx > cxmax) ||
(midy < cymin) || (midy > cymax) ||
(midz < czmin) || (midz > czmax) ) ) {
px = (xlog) ? CNlog10(midx) : midx;
py = (ylog) ? CNlog10(midy) : midy;
pz = (zlog) ? CNlog10(midz) : midz;
trn_world_to_X11(px,py,pz,&x,&y);
/* Print the label only if the point is in bounds */
if (x > rxmin && x < rxmax && y > rymin && y < rymax) {
(void) sprintf(label,"T%d",T->ID);
text_len = strlen(label);
text_width = XTextWidth(lblfont_info,label,text_len);
text_xpos = x - 0.5*text_width;
text_ypos = y + 0.5*lblfont_info->max_bounds.ascent;
if (window)
XDrawString(display,window,gcl,text_xpos,text_ypos,label,text_len);
if (pixmap)
XDrawString(display,pixmap,gcl,text_xpos,text_ypos,label,text_len);
}
}
}
}
/*
* Plot the rectangle ID labels in X11
*/
/*ARGSUSED*/
static void plotX3D_rectIDs(rt_head,rt_tail)
CNrectptr rt_head, rt_tail;
{
CNrectptr R;
double x,y,midx,midy,midz;
char label[CN_MAXCHAR];
int text_xpos, text_ypos, text_len, text_width;
double rxmin, rxmax, rymin, rymax;
double cxmin, cxmax, cymin, cymax, czmin, czmax;
double px, py, pz;
if (rt_head == NULL) return;
/* Boundary */
rxmin = 0;
rxmax = Width;
rymin = 0;
rymax = Height;
/* Clip boundaries */
cxmin = ((xlog) ? pow(10.0,xmin) : xmin);
cxmax = ((xlog) ? pow(10.0,xmax) : xmax);
cymin = ((ylog) ? pow(10.0,ymin) : ymin);
cymax = ((ylog) ? pow(10.0,ymax) : ymax);
czmin = ((zlog) ? pow(10.0,zmin) : zmin);
czmax = ((zlog) ? pow(10.0,zmax) : zmax);
/* Set the linetype, width and color */
(void) PXlinetypX(CN_LN_SOLID,1);
PXlineColorX(0);
/* Go thru each rectangle */
for (R=rt_head; R!=NULL; R=R->next) {
/* Get the x-y-t value of the rectangle-midpoint */
midx = R->n1->coord->x + R->n2->coord->x +
R->n3->coord->x + R->n4->coord->y;
midy = R->n1->coord->y + R->n2->coord->y +
R->n3->coord->y + R->n4->coord->y;
midz = R->n1->t + R->n2->t + R->n3->t + R->n4->t;
midx = midx/4.0;
midy = midy/4.0;
midz = midz/4.0;
/* Check to see if the point is in bounds */
if ( !( (midx < cxmin) || (midx > cxmax) ||
(midy < cymin) || (midy > cymax) ||
(midz < czmin) || (midz > czmax) ) ) {
px = (xlog) ? CNlog10(midx) : midx;
py = (ylog) ? CNlog10(midy) : midy;
pz = (zlog) ? CNlog10(midz) : midz;
trn_world_to_X11(px,py,pz,&x,&y);
/* Print the label only if the point is in bounds */
if (x > rxmin && x < rxmax && y > rymin && y < rymax) {
(void) sprintf(label,"R%d",R->ID);
text_len = strlen(label);
text_width = XTextWidth(lblfont_info,label,text_len);
text_xpos = x - 0.5*text_width;
text_ypos = y + 0.5*lblfont_info->max_bounds.ascent;
if (window)
XDrawString(display,window,gcl,text_xpos,text_ypos,label,text_len);
if (pixmap)
XDrawString(display,pixmap,gcl,text_xpos,text_ypos,label,text_len);
}
}
}
}
/*
* ANNOTATIONS
*/
/*
* Plot annotations
*/
static void annotateX3D()
{
CNannotptr AP;
CNdslistptr DS;
/* Plot the annotations in each dataset */
for (DS=plotdata->datahead; DS!=NULL; DS=DS->next)
if (DS->Dptr->data_pr.plotannot) {
for (AP=DS->Dptr->annothead; AP!=NULL; AP=AP->next)
plotX3D_single_annotation(AP);
}
/* Plot the annotations in the plotset */
for (AP=plotdata->annothead; AP!=NULL; AP=AP->next)
plotX3D_single_annotation(AP);
}
/*
* Plot a single annotation
*/
static void plotX3D_single_annotation(AP)
CNannotptr AP;
{
if (AP == NULL) return;
switch (AP->type) {
case CN_AN_RECT : /* Draw a rectangle */
plotX3D_annot_rect(AP);
break;
case CN_AN_LINE : /* Draw a line */
plotX3D_annot_line(AP);
break;
case CN_AN_ARROW: /* Draw a arrow */
plotX3D_annot_arrow(AP);
break;
case CN_AN_POINT: /* Draw a point */
plotX3D_annot_point(AP);
break;
case CN_AN_TEXT : /* Draw a text label */
plotX3D_annot_text(AP);
break;
default : break;
}
}
/*
* Plot an annotation rectangle
*/
static void plotX3D_annot_rect(AP)
CNannotptr AP;
{
XPoint points[MAX_ARR_SIZE];
double px,py,pz,x1,y1,x2,y2,x,y;
int i, npts=0;
double rxmin, rxmax, rymin, rymax;
double bxmin, bxmax, bymin, bymax;
double xc, yc;
CNpointptr pt_head=NULL, pt_tail=NULL, P;
double cxmin,cxmax,cymin,cymax,czmin,czmax;
int text_len, text_width, text_xpos, text_ypos;
/*
* The annotated object can be specified either
* (a) position relative to data coordinates
* (b) absolute position in percentage of width/height
*/
if (AP->property.absolute) {
/* Rescale the points - the values are in percentages */
x1 = AP->pt1.x * Width;
y1 = Height - (AP->pt1.y * Height);
x2 = AP->pt2.x * Width;
y2 = Height - (AP->pt2.y * Height);
/* Clipping boundary */
rxmin = 0;
rxmax = Width;
rymin = 0;
rymax = Height;
/* Check to see if the box is inside the plot area */
if ((y1 < rymin && y2 < rymin) || (y1 > rymax && y2 > rymax)) return;
if ((x1 < rxmin && x2 < rxmin) || (x1 > rxmax && x2 > rxmax)) return;
/* Get the dimensions of the box */
bxmin = (x1 < x2) ? x1 : x2;
bxmax = (x1 < x2) ? x2 : x1;
bymin = (y1 < y2) ? y1 : y2;
bymax = (y1 < y2) ? y2 : y1;
/* Clipping boundaries */
if (bxmin < rxmin) bxmin = rxmin;
if (bxmax > rxmax) bxmax = rxmax;
if (bymin < rymin) bymin = rymin;
if (bymax > rymax) bymax = rymax;
/* Save points in an array */
i = 0;
points[i].x = bxmin; points[i].y = bymin; i++;
points[i].x = bxmax; points[i].y = bymin; i++;
points[i].x = bxmax; points[i].y = bymax; i++;
points[i].x = bxmin; points[i].y = bymax; i++;
points[i].x = bxmin; points[i].y = bymin; i++;
npts = i;
} else {
/* Insert points */
(void) CNinsert_point(&pt_head, &pt_tail,
AP->pt1.x,AP->pt1.y,AP->pt1.z,0);
(void) CNinsert_point(&pt_head, &pt_tail,
AP->pt1.x,AP->pt2.y,AP->pt1.z,0);
(void) CNinsert_point(&pt_head, &pt_tail,
AP->pt2.x,AP->pt2.y,AP->pt2.z,0);
(void) CNinsert_point(&pt_head, &pt_tail,
AP->pt2.x,AP->pt1.y,AP->pt2.z,0);
(void) CNinsert_point(&pt_head, &pt_tail,
AP->pt1.x,AP->pt1.y,AP->pt1.z,0);
/* Clip boundaries */
cxmin = ((xlog) ? pow(10.0,xmin) : xmin);
cxmax = ((xlog) ? pow(10.0,xmax) : xmax);
cymin = ((ylog) ? pow(10.0,ymin) : ymin);
cymax = ((ylog) ? pow(10.0,ymax) : ymax);
czmin = ((zlog) ? pow(10.0,zmin) : zmin);
czmax = ((zlog) ? pow(10.0,zmax) : zmax);
if (AP->property.doclip) {
/* Clip - this modifies on the temporary point list */
CNclip_pointlist(&pt_head,&pt_tail,
cxmin,cxmax,cymin,cymax,czmin,czmax,1,1,1,0);
}
if (pt_head == NULL) return;
/*
* Another clipping - this time, clip against the plot window.
* If this is NOT done, the Xpoint array will be filled with
* negative/large numbers corresponding to points outside the
* drawing area, which slows down the drawing significantly!
*/
/* rescale points, save in array */
for (P=pt_head; P!=NULL; P=P->next) {
px = (xlog) ? CNlog10(P->x) : P->x;
py = (ylog) ? CNlog10(P->y) : P->y;
pz = (zlog) ? CNlog10(P->z) : P->z;
trn_world_to_X11(px,py,pz,&x,&y);
P->x = x;
P->y = y;
P->z = 0.0;
}
/* Plot window boundaries */
cxmin = 0.0;
cxmax = (double) Width;
cymin = 0.0;
cymax = (double) Height;
czmin = -0.1; /* Not used */
czmax = 0.1; /* Not used */
/* Clip - this modifies the temporary point list */
CNclip_pointlist(&pt_head,&pt_tail,
cxmin,cxmax,cymin,cymax,czmin,czmax,1,1,0,0);
if (pt_head == NULL) return;
/* save points in array */
for (P=pt_head; P!=NULL && npts<MAX_ARR_SIZE; P=P->next) {
points[npts].x = (int)(P->x);
points[npts].y = (int)(P->y);
npts++;
}
}
/* Fill the polygon */
PXfillX_polygon(points, npts,
(int) AP->property.filltype,
PXpolyColorIndexX( (int) AP->property.fillcolor ),
(int) AP->property.linetype,
(int) AP->property.linecolor,
(int) AP->property.linewidth);
if (npts<=1) return;
/* Get the polygon center */
xc = yc = 0.0;
for (i=0; i<npts; i++) {
xc += points[i].x;
yc += points[i].y;
}
if ((points[npts-1].x==points[0].x) && (points[npts-1].y==points[0].y)) {
xc -= points[0].x;
yc -= points[0].y;
xc = xc/(double)(npts-1);
yc = yc/(double)(npts-1);
} else {
xc = xc/(double)(npts);
yc = yc/(double)(npts);
}
/* If there is text attached, draw it */
if (AP->property.linelabel) {
/* Set the text color */
if ((AP->property.filltype!=CN_FILL_NONE) && (AP->property.fillcolor==0))
XSetForeground(display,gcl,colors[1]);
else
XSetForeground(display,gcl,colors[0]);
/* Draw the label centered, in the middle of the box */
text_len = strlen(AP->property.linelabel);
text_width = XTextWidth(lblfont_info,AP->property.linelabel,text_len);
text_xpos = xc - 0.5*text_width;
text_ypos = yc + 0.5*lblfont_info->max_bounds.ascent;
if (window)
XDrawString(display,window,gcl,
text_xpos,text_ypos,AP->property.linelabel,text_len);
if (pixmap)
XDrawString(display,pixmap,gcl,
text_xpos,text_ypos,AP->property.linelabel,text_len);
/* Reset the text color */
XSetForeground(display,gcl,colors[0]);
}
/* Delete the point-list */
CNdelete_point_list(&pt_head, &pt_tail);
}
/*
* Plot an annotation line
*/
static void plotX3D_annot_line(AP)
CNannotptr AP;
{
double rxmin,rxmax,rymin,rymax;
double cxmin,cxmax,cymin,cymax,czmin,czmax;
double px,py,pz,x1,y1,z1,x2,y2,z2;
int pat;
int p1_clipped=CN_FALSE, p2_clipped=CN_FALSE;
int text_len, text_width, text_xpos, text_ypos;
/*
* The annotated object can be specified either
* (a) position relative to data coordinates
* (b) absolute position in percentage of width/height
*/
/* Clipping boundary */
rxmin = 0;
rxmax = Width;
rymin = 0;
rymax = Height;
if (AP->property.absolute) {
/* Rescale the points - the values are in percentages */
x1 = AP->pt1.x * Width;
y1 = Height - (AP->pt1.y * Height);
x2 = AP->pt2.x * Width;
y2 = Height - (AP->pt2.y * Height);
} else {
/* Get the dimensions of the line */
x1 = AP->pt1.x;
y1 = AP->pt1.y;
z1 = AP->pt1.z;
x2 = AP->pt2.x;
y2 = AP->pt2.y;
z2 = AP->pt2.z;
/* Do pre-clipping aaginst the real-world boundaries */
if (AP->property.doclip) {
/* Clipping boundary */
cxmin = ((xlog) ? pow(10.0,xmin) : xmin);
cxmax = ((xlog) ? pow(10.0,xmax) : xmax);
cymin = ((ylog) ? pow(10.0,ymin) : ymin);
cymax = ((ylog) ? pow(10.0,ymax) : ymax);
czmin = ((zlog) ? pow(10.0,zmin) : zmin);
czmax = ((zlog) ? pow(10.0,zmax) : zmax);
if ((x1 <=cxmin && x2 <=cxmin) || (x1 >=cxmax && x2 >=cxmax)) return;
if ((y1 <=cymin && y2 <=cymin) || (y1 >=cymax && y2 >=cymax)) return;
if ((z1 <=czmin && z2 <=czmin) || (z1 >=czmax && z2 >=czmax)) return;
clipX3D_in_xmin(&x1,&y1,&z1,&x2,&y2,&z2,cxmin,&p1_clipped,&p2_clipped);
clipX3D_in_ymin(&x1,&y1,&z1,&x2,&y2,&z2,cymin,&p1_clipped,&p2_clipped);
clipX3D_in_zmin(&x1,&y1,&z1,&x2,&y2,&z2,czmin,&p1_clipped,&p2_clipped);
clipX3D_in_xmax(&x1,&y1,&z1,&x2,&y2,&z2,cxmax,&p1_clipped,&p2_clipped);
clipX3D_in_ymax(&x1,&y1,&z1,&x2,&y2,&z2,cymax,&p1_clipped,&p2_clipped);
clipX3D_in_zmax(&x1,&y1,&z1,&x2,&y2,&z2,czmax,&p1_clipped,&p2_clipped);
if ((x1 <=cxmin && x2 <=cxmin) || (x1 >=cxmax && x2 >=cxmax)) return;
if ((y1 <=cymin && y2 <=cymin) || (y1 >=cymax && y2 >=cymax)) return;
if ((z1 <=czmin && z2 <=czmin) || (z1 >=czmax && z2 >=czmax)) return;
}
/* rescale points */
px = (xlog) ? CNlog10(x1) : x1;
py = (ylog) ? CNlog10(y1) : y1;
pz = (zlog) ? CNlog10(z1) : z1;
trn_world_to_X11(px,py,pz,&x1,&y1);
/* rescale points */
px = (xlog) ? CNlog10(x2) : x2;
py = (ylog) ? CNlog10(y2) : y2;
pz = (zlog) ? CNlog10(z2) : z2;
trn_world_to_X11(px,py,pz,&x2,&y2);
}
/* Check to see if the line is inside the plot area */
if ((x1 < rxmin && x2 < rxmin) || (x1 > rxmax && x2 > rxmax)) return;
if ((y1 < rymin && y2 < rymin) || (y1 > rymax && y2 > rymax)) return;
/* Do another clipping */
clipX3D_in_xmin(&x1,&y1,&z1,&x2,&y2,&z2,rxmin,&p1_clipped,&p2_clipped);
clipX3D_in_ymin(&x1,&y1,&z1,&x2,&y2,&z2,rymin,&p1_clipped,&p2_clipped);
clipX3D_in_xmax(&x1,&y1,&z1,&x2,&y2,&z2,rxmax,&p1_clipped,&p2_clipped);
clipX3D_in_ymax(&x1,&y1,&z1,&x2,&y2,&z2,rymax,&p1_clipped,&p2_clipped);
/* Set the line characteristics */
pat = PXlinetypX((int)AP->property.linetype, (int)AP->property.linewidth);
PXlineColorX((int)AP->property.linecolor);
if (pat) {
if (window)
XDrawLine(display,window,gc, (int)x1,(int)y1,(int)x2,(int)y2);
if (pixmap)
XDrawLine(display,pixmap,gc, (int)x1,(int)y1,(int)x2,(int)y2);
}
/* Draw the markers */
if ((AP->property.marktype != CN_MK_NONE) && (!p1_clipped || !p2_clipped)) {
(void) PXlinetypX(CN_LN_SOLID,1);
PXlineColorX(AP->property.markcolor);
if (!p1_clipped) PXmarkerX((int)AP->property.marktype,
(int)AP->property.marksize,(int)x1,(int)y1);
if (!p2_clipped) PXmarkerX((int)AP->property.marktype,
(int)AP->property.marksize,(int)x2,(int)y2);
}
/* If there is text attached, draw it */
if (!p1_clipped && AP->property.linelabel) {
/* Text justification is based on comparison of x1, x2 */
text_len = strlen(AP->property.linelabel);
text_width = XTextWidth(lblfont_info,AP->property.linelabel,text_len);
if (x1 > x2) {
/* Left-justified */
text_xpos = x1 + 6;
text_ypos = y1 + 0.5*lblfont_info->max_bounds.ascent;
} else if (x1 == x2) {
/* Center-justified */
text_xpos = x1 - 0.5*text_width;
if (y1 > y2)
text_ypos = y1 + 1.5*lblfont_info->max_bounds.ascent;
else
text_ypos = y1 - 1.5*lblfont_info->max_bounds.ascent;
} else {
/* Right-justified */
text_xpos = x1 - text_width - 6;
text_ypos = y1 + 0.5*lblfont_info->max_bounds.ascent;
}
if (window)
XDrawString(display,window,gcl,
text_xpos,text_ypos,AP->property.linelabel,text_len);
if (pixmap)
XDrawString(display,pixmap,gcl,
text_xpos,text_ypos,AP->property.linelabel,text_len);
}
/* Reset */
PXlineColorX(0);
}
/*
* Plot an annotation arrow
*/
static void plotX3D_annot_arrow(AP)
CNannotptr AP;
{
double cxmin,cxmax,cymin,cymax,czmin,czmax;
double px,py,pz,x1,y1,z1,x2,y2,z2;
int p1_clipped=CN_FALSE, p2_clipped=CN_FALSE;
/*
* The annotated object can be specified either
* (a) position relative to data coordinates
* (b) absolute position in percentage of width/height
*/
if (AP->property.absolute) {
/* Rescale the points - the values are in percentages */
x1 = AP->pt1.x * Width;
y1 = Height - (AP->pt1.y * Height);
x2 = AP->pt2.x * Width;
y2 = Height - (AP->pt2.y * Height);
} else {
/* Get the dimensions of the line */
x1 = AP->pt1.x;
y1 = AP->pt1.y;
z1 = AP->pt1.z;
x2 = AP->pt2.x;
y2 = AP->pt2.y;
z2 = AP->pt2.z;
/* Do pre-clipping aaginst the real-world boundaries */
if (AP->property.doclip) {
/* Clipping boundary */
cxmin = ((xlog) ? pow(10.0,xmin) : xmin);
cxmax = ((xlog) ? pow(10.0,xmax) : xmax);
cymin = ((ylog) ? pow(10.0,ymin) : ymin);
cymax = ((ylog) ? pow(10.0,ymax) : ymax);
czmin = ((zlog) ? pow(10.0,zmin) : zmin);
czmax = ((zlog) ? pow(10.0,zmax) : zmax);
if ((x1 <=cxmin && x2 <=cxmin) || (x1 >=cxmax && x2 >=cxmax)) return;
if ((y1 <=cymin && y2 <=cymin) || (y1 >=cymax && y2 >=cymax)) return;
if ((z1 <=czmin && z2 <=czmin) || (z1 >=czmax && z2 >=czmax)) return;
clipX3D_in_xmin(&x1,&y1,&z1,&x2,&y2,&z2,cxmin,&p1_clipped,&p2_clipped);
clipX3D_in_ymin(&x1,&y1,&z1,&x2,&y2,&z2,cymin,&p1_clipped,&p2_clipped);
clipX3D_in_zmin(&x1,&y1,&z1,&x2,&y2,&z2,czmin,&p1_clipped,&p2_clipped);
clipX3D_in_xmax(&x1,&y1,&z1,&x2,&y2,&z2,cxmax,&p1_clipped,&p2_clipped);
clipX3D_in_ymax(&x1,&y1,&z1,&x2,&y2,&z2,cymax,&p1_clipped,&p2_clipped);
clipX3D_in_zmax(&x1,&y1,&z1,&x2,&y2,&z2,czmax,&p1_clipped,&p2_clipped);
if ((x1 <=cxmin && x2 <=cxmin) || (x1 >=cxmax && x2 >=cxmax)) return;
if ((y1 <=cymin && y2 <=cymin) || (y1 >=cymax && y2 >=cymax)) return;
if ((z1 <=czmin && z2 <=czmin) || (z1 >=czmax && z2 >=czmax)) return;
}
/* rescale points */
px = (xlog) ? CNlog10(x1) : x1;
py = (ylog) ? CNlog10(y1) : y1;
pz = (zlog) ? CNlog10(z1) : z1;
trn_world_to_X11(px,py,pz,&x1,&y1);
/* rescale points */
px = (xlog) ? CNlog10(x2) : x2;
py = (ylog) ? CNlog10(y2) : y2;
pz = (zlog) ? CNlog10(z2) : z2;
trn_world_to_X11(px,py,pz,&x2,&y2);
}
/* Draw the arrow */
plotX3D_arrow(x1,y1,x2,y2,
p1_clipped, p2_clipped,
AP->property.linelabel,
(int)AP->property.linetype,
(int)AP->property.linecolor,
(int)AP->property.linewidth,
(int)AP->property.marktype,
(int)AP->property.marksize,
(int)AP->property.markcolor,1);
}
/*
* Draw an arrow
*/
static void plotX3D_arrow(x1,y1,x2,y2,
p1_clipped, p2_clipped,
linelabel,
linetype,linecolor,linewidth,
marktype,marksize,markcolor,
arrowhead)
double x1,y1,x2,y2;
int p1_clipped, p2_clipped;
char *linelabel;
int linetype,linecolor,linewidth;
int marktype,marksize,markcolor;
int arrowhead;
{
double rxmin, rxmax, rymin, rymax;
int pat;
double vx, vy, vd;
double xa, ya, xb, yb, xc, yc;
double z1=0.0, z2=0.0;
int text_len, text_width, text_xpos, text_ypos;
/* Clipping boundary */
rxmin = 0;
rxmax = Width-0;
rymin = 0;
rymax = Height-0;
/* Check to see if the line is inside the plot area */
if ((x1 < rxmin && x2 < rxmin) || (x1 > rxmax && x2 > rxmax)) return;
if ((y1 < rymin && y2 < rymin) || (y1 > rymax && y2 > rymax)) return;
/* Clip the arrow against the plot boundaries */
clipX3D_in_xmin(&x1,&y1,&z1,&x2,&y2,&z2,rxmin,&p1_clipped,&p2_clipped);
clipX3D_in_ymin(&x1,&y1,&z1,&x2,&y2,&z2,rymin,&p1_clipped,&p2_clipped);
clipX3D_in_xmax(&x1,&y1,&z1,&x2,&y2,&z2,rxmax,&p1_clipped,&p2_clipped);
clipX3D_in_ymax(&x1,&y1,&z1,&x2,&y2,&z2,rymax,&p1_clipped,&p2_clipped);
/* Draw the arrow origin */
(void) PXlinetypX(CN_LN_SOLID,1);
PXlineColorX(markcolor);
if (!p1_clipped) PXmarkerX(marktype,marksize,(int)x1,(int)y1);
/* Draw the arrow line */
pat = PXlinetypX(linetype, linewidth);
PXlineColorX(linecolor);
if (pat) {
if (window)
XDrawLine(display,window,gc, (int)x1,(int)y1,(int)x2,(int)y2);
if (pixmap)
XDrawLine(display,pixmap,gc, (int)x1,(int)y1,(int)x2,(int)y2);
}
/* Draw the arrow head */
if (!p2_clipped && arrowhead) {
/* Draw the arrow head */
(void) PXlinetypX(CN_LN_SOLID,linewidth);
vx = x2-x1;
vy = y2-y1;
vd = sqrt(vx*vx + vy*vy);
if (vd > 5.0) {
xa = x2 - 5.0*vx/vd;
ya = y2 - 5.0*vy/vd;
xb = xa - 2.0*vy/vd;
yb = ya + 2.0*vx/vd;
xc = xa + 2.0*vy/vd;
yc = ya - 2.0*vx/vd;
if (window) {
XDrawLine(display,window,gc, (int)x2, (int)y2, (int)xb, (int)yb);
XDrawLine(display,window,gc, (int)x2, (int)y2, (int)xc, (int)yc);
}
if (pixmap) {
XDrawLine(display,pixmap,gc, (int)x2, (int)y2, (int)xb, (int)yb);
XDrawLine(display,pixmap,gc, (int)x2, (int)y2, (int)xc, (int)yc);
}
}
}
/* If there is text attached, draw it */
if (!p1_clipped && linelabel) {
/* Text justification is based on comparison of x1, x2 */
text_len = strlen(linelabel);
text_width = XTextWidth(lblfont_info,linelabel,text_len);
if (x1 > x2) {
/* Left-justified */
text_xpos = x1 + 6;
text_ypos = y1 + 0.5*lblfont_info->max_bounds.ascent;
} else if (x1 == x2) {
/* Center-justified */
text_xpos = x1 - 0.5*text_width;
if (y1 > y2)
text_ypos = y1 + 1.5*lblfont_info->max_bounds.ascent;
else
text_ypos = y1 - 1.5*lblfont_info->max_bounds.ascent;
} else {
/* Right-justified */
text_xpos = x1 - text_width - 6;
text_ypos = y1 + 0.5*lblfont_info->max_bounds.ascent;
}
if (window)
XDrawString(display,window,gcl,
text_xpos,text_ypos,linelabel,text_len);
if (pixmap)
XDrawString(display,pixmap,gcl,
text_xpos,text_ypos,linelabel,text_len);
}
/* Reset */
PXlineColorX(0);
(void) PXlinetypX(CN_LN_SOLID,1);
}
/*
* Plot an annotation point
*/
static void plotX3D_annot_point(AP)
CNannotptr AP;
{
double px,py,pz,x1,y1;
double rxmin, rxmax, rymin, rymax;
double cxmin,cxmax,cymin,cymax,czmin,czmax;
int text_xpos, text_ypos, text_len;
/*
* The annotated object can be specified either
* (a) position relative to data coordinates
* (b) absolute position in percentage of width/height
*/
/* Clipping boundary */
rxmin = 0;
rxmax = Width;
rymin = 0;
rymax = Height;
if (AP->property.absolute) {
/* Rescale the points - the values are in percentages */
x1 = AP->pt1.x * Width;
y1 = Height - (AP->pt1.y * Height);
} else {
/* Do a pre-clipping */
if (AP->property.doclip) {
/* Clipping boundary */
cxmin = ((xlog) ? pow(10.0,xmin) : xmin);
cxmax = ((xlog) ? pow(10.0,xmax) : xmax);
cymin = ((ylog) ? pow(10.0,ymin) : ymin);
cymax = ((ylog) ? pow(10.0,ymax) : ymax);
czmin = ((zlog) ? pow(10.0,zmin) : zmin);
czmax = ((zlog) ? pow(10.0,zmax) : zmax);
if ((AP->pt1.x < cxmin || AP->pt1.x > cxmax) ||
(AP->pt1.y < cymin || AP->pt1.y > cymax) ||
(AP->pt1.z < czmin || AP->pt1.z > czmax))
return;
}
/* rescale points */
px = (xlog) ? CNlog10(AP->pt1.x) : AP->pt1.x;
py = (ylog) ? CNlog10(AP->pt1.y) : AP->pt1.y;
pz = (zlog) ? CNlog10(AP->pt1.z) : AP->pt1.z;
trn_world_to_X11(px,py,pz,&x1,&y1);
}
/* Draw the markers */
if ((rxmin < x1 && x1 < rxmax) && (rymin < y1 && y1 < rymax)) {
(void) PXlinetypX(CN_LN_SOLID,1);
PXlineColorX(AP->property.markcolor);
PXmarkerX((int)AP->property.marktype,
(int)AP->property.marksize,(int)x1,(int)y1);
/* If there is text attached, draw it */
if (AP->property.linelabel) {
/* Left-justified, left of the point */
text_len = strlen(AP->property.linelabel);
text_xpos = x1 + 6;
text_ypos = y1 + 0.5*lblfont_info->max_bounds.ascent;
if (window)
XDrawString(display,window,gcl,
text_xpos,text_ypos,AP->property.linelabel,text_len);
if (pixmap)
XDrawString(display,pixmap,gcl,
text_xpos,text_ypos,AP->property.linelabel,text_len);
}
}
/* Reset */
PXlineColorX(0);
}
/*
* Plot an annotation label
*/
static void plotX3D_annot_text(AP)
CNannotptr AP;
{
double px,py,pz,x1,y1;
double rxmin, rxmax, rymin, rymax;
double cxmin,cxmax,cymin,cymax,czmin,czmax;
int text_len, text_width, text_xpos, text_ypos;
/*
* The annotated object can be specified either
* (a) position relative to data coordinates
* (b) absolute position in percentage of width/height
*/
/* Clipping boundary */
rxmin = 0;
rxmax = Width;
rymin = 0;
rymax = Height;
if (AP->property.absolute) {
/* Rescale the points - the values are in percentages */
x1 = AP->pt1.x * Width;
y1 = Height - (AP->pt1.y * Height);
} else {
/* Do a pre-clipping */
if (AP->property.doclip) {
/* Clipping boundary */
cxmin = ((xlog) ? pow(10.0,xmin) : xmin);
cxmax = ((xlog) ? pow(10.0,xmax) : xmax);
cymin = ((ylog) ? pow(10.0,ymin) : ymin);
cymax = ((ylog) ? pow(10.0,ymax) : ymax);
czmin = ((zlog) ? pow(10.0,zmin) : zmin);
czmax = ((zlog) ? pow(10.0,zmax) : zmax);
if ((AP->pt1.x < cxmin || AP->pt1.x > cxmax) ||
(AP->pt1.y < cymin || AP->pt1.y > cymax) ||
(AP->pt1.z < czmin || AP->pt1.z > czmax))
return;
}
/* rescale points */
px = (xlog) ? CNlog10(AP->pt1.x) : AP->pt1.x;
py = (ylog) ? CNlog10(AP->pt1.y) : AP->pt1.y;
pz = (zlog) ? CNlog10(AP->pt1.z) : AP->pt1.z;
trn_world_to_X11(px,py,pz,&x1,&y1);
}
/* Draw the markers */
if ((rxmin < x1 && x1 < rxmax) && (rymin < y1 && y1 < rymax)) {
if (AP->property.linelabel) {
(void) PXlinetypX(CN_LN_SOLID,1);
PXlineColorX(0);
text_len = strlen(AP->property.linelabel);
text_width = XTextWidth(lblfont_info,AP->property.linelabel,text_len);
text_xpos = x1 - text_width/2;
text_ypos = y1 + 0.5*lblfont_info->max_bounds.ascent;
if (window)
XDrawString(display,window,gcl,
text_xpos,text_ypos,AP->property.linelabel,text_len);
if (pixmap)
XDrawString(display,pixmap,gcl,
text_xpos,text_ypos,AP->property.linelabel,text_len);
}
}
}
/*
* Clip a line against xmin
*/
static void clipX3D_in_xmin(x1,y1,z1,x2,y2,z2,rxmin,p1_clipped,p2_clipped)
double *x1, *y1, *z1, *x2, *y2, *z2, rxmin;
int *p1_clipped, *p2_clipped;
{
double t;
/* Clip the line against rxmin */
if (*x1 < rxmin && *x2 > rxmin) {
t = (rxmin - *x1)/(*x2 - *x1);
*x1 = *x1 + t*(*x2 - *x1);
*y1 = *y1 + t*(*y2 - *y1);
*z1 = *z1 + t*(*z2 - *z1);
if (*x1 < rxmin) *x1 = rxmin;
*p1_clipped = CN_TRUE;
} else if (*x2 < rxmin && *x1 > rxmin) {
t = (rxmin - *x2)/(*x1 - *x2);
*x2 = *x2 + t*(*x1 - *x2);
*y2 = *y2 + t*(*y1 - *y2);
*z2 = *z2 + t*(*z1 - *z2);
if (*x2 < rxmin) *x2 = rxmin;
*p2_clipped = CN_TRUE;
}
}
/*
* Clip a line against ymin
*/
static void clipX3D_in_ymin(x1,y1,z1,x2,y2,z2,rymin,p1_clipped,p2_clipped)
double *x1, *y1, *z1, *x2, *y2, *z2, rymin;
int *p1_clipped, *p2_clipped;
{
clipX3D_in_xmin(y1,x1,z1,y2,x2,z2,rymin,p1_clipped,p2_clipped);
}
/*
* Clip a line against zmin
*/
static void clipX3D_in_zmin(x1,y1,z1,x2,y2,z2,rzmin,p1_clipped,p2_clipped)
double *x1, *y1, *z1, *x2, *y2, *z2, rzmin;
int *p1_clipped, *p2_clipped;
{
clipX3D_in_xmin(z1,y1,x1,z2,y2,x2,rzmin,p1_clipped,p2_clipped);
}
/*
* Clip a line against xmax
*/
static void clipX3D_in_xmax(x1,y1,z1,x2,y2,z2,rxmax,p1_clipped,p2_clipped)
double *x1, *y1, *z1, *x2, *y2, *z2, rxmax;
int *p1_clipped, *p2_clipped;
{
double t;
/* Clip the line against rxmax */
if (*x1 < rxmax && *x2 > rxmax) {
t = (rxmax - *x2)/(*x1 - *x2);
*x2 = *x2 + t*(*x1 - *x2);
*y2 = *y2 + t*(*y1 - *y2);
*z2 = *z2 + t*(*z1 - *z2);
if (*x2 > rxmax) *x2 = rxmax;
*p2_clipped = CN_TRUE;
} else if (*x2 < rxmax && *x1 > rxmax) {
t = (rxmax - *x1)/(*x2 - *x1);
*x1 = *x1 + t*(*x2 - *x1);
*y1 = *y1 + t*(*y2 - *y1);
*z1 = *z1 + t*(*z2 - *z1);
if (*x1 > rxmax) *x1 = rxmax;
*p1_clipped = CN_TRUE;
}
}
/*
* Clip a line against ymax
*/
static void clipX3D_in_ymax(x1,y1,z1,x2,y2,z2,rymax,p1_clipped,p2_clipped)
double *x1, *y1, *z1, *x2, *y2, *z2, rymax;
int *p1_clipped, *p2_clipped;
{
clipX3D_in_xmax(y1,x1,z1,y2,x2,z2,rymax,p1_clipped,p2_clipped);
}
/*
* Clip a line against zmax
*/
static void clipX3D_in_zmax(x1,y1,z1,x2,y2,z2,rzmax,p1_clipped,p2_clipped)
double *x1, *y1, *z1, *x2, *y2, *z2, rzmax;
int *p1_clipped, *p2_clipped;
{
clipX3D_in_xmax(z1,y1,x1,z2,y2,x2,rzmax,p1_clipped,p2_clipped);
}
/*
* LABELS
*/
/*
* Plot line labels on the side if necessary
*/
static void plotX3D_sidelabels()
{
short contclip;
int xoffset;
int LABEL_FOUND = CNplotset_has_linelabels(plotdata);
int FCONT_FOUND = CNplotset_has_colored_contours(plotdata);
/* Plot linelabels if necessary */
if (LABEL_FOUND) {
xoffset = 10;
if (FCONT_FOUND) xoffset += LABEL_WIDTH + 20;
PXplotX_linelabels(plotdata, hiddenline,
Xxmin, Xxmax, Xymin, Xymax, xoffset);
}
/* Plot colored scales if necessary */
if (FCONT_FOUND) {
xoffset = 10;
contclip = CN_FALSE;
if (contour_dptr) contclip = contour_dptr->data_pr.contclip;
PXplotX_contscale(cstephead, csteptail,
Xxmin, Xxmax, Xymin, Xymax, xoffset, contclip);
}
}
/*
* Translation
*/
/*
* Translate world to X11 coordinates and apply log options
* This is for local use only because it uses local static variables.
*/
static void trn_world_to_X11(x, y, z, X, Y)
double x, y, z; /* Real-world coordinates */
double *X, *Y; /* X11-coordinates after transformation */
{
CNmatrix ndc_to_x11;
CNcoord newpt, ndcpt, point;
/*
* This transfo gets the coordinates in normalized device units (NDC)
*/
point.x = x;
point.y = y;
point.z = z;
ndcpt = CNtransform_point(&point,view_transfo);
/*
* Need one more transformation to map from unit coordinates to X11
* coords
*/
CNscale_window_to_viewport(ndc_to_x11,
0.0, 1.0, 0.0, 1.0,
(double)Xxmin, (double)Xxmax,
(double)Xymax, (double)Xymin);
newpt = CNtransform_point(&ndcpt,ndc_to_x11);
*X = newpt.x;
*Y = newpt.y;
}
|