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
|
/*=========================================================================
Program: Visualization Toolkit
Module: vtkSurfaceLICMapper.cxx
Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
All rights reserved.
See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notice for more information.
=========================================================================*/
#include "vtkSurfaceLICMapper.h"
#include "vtkActor.h"
#include "vtkBase64Utilities.h"
#include "vtkBoundingBox.h"
#include "vtkCellData.h"
#include "vtkCompositeDataIterator.h"
#include "vtkCompositeDataSet.h"
#include "vtkFloatArray.h"
#include "vtkFrameBufferObject2.h"
#include "vtkGarbageCollector.h"
#include "vtkGenericDataObjectReader.h"
#include "vtkImageData.h"
#include "vtkInformation.h"
#include "vtkLineIntegralConvolution2D.h"
#include "vtkMath.h"
#include "vtkMatrix3x3.h"
#include "vtkMatrix4x4.h"
#include "vtkMinimalStandardRandomSequence.h"
#include "vtkNew.h"
#include "vtkNoise200x200.h"
#include "vtkObjectFactory.h"
#include "vtkOpenGLActor.h"
#include "vtkOpenGLCamera.h"
#include "vtkOpenGLError.h"
#include "vtkOpenGLRenderUtilities.h"
#include "vtkOpenGLRenderWindow.h"
#include "vtkOpenGLShaderCache.h"
#include "vtkPainterCommunicator.h"
#include "vtkPixelBufferObject.h"
#include "vtkPixelExtent.h"
#include "vtkPointData.h"
#include "vtkPolyData.h"
#include "vtkProperty.h"
#include "vtkRenderer.h"
#include "vtkScalarsToColors.h"
#include "vtkShaderProgram.h"
#include "vtkSurfaceLICComposite.h"
#include "vtkTextureObject.h"
#include "vtkTextureObjectVS.h"
#include <cassert>
#include <cstring>
#include <algorithm>
#include <limits>
#include <vector>
#include <deque>
#include <cstdlib>
using std::vector;
using std::deque;
using std::string;
typedef vtkLineIntegralConvolution2D vtkLIC2D;
// use parallel timer for benchmarks and scaling
// if not defined vtkTimerLOG is used.
// #define vtkSurfaceLICMapperTIME
#if !defined(vtkSurfaceLICMapperTIME)
#include "vtkTimerLog.h"
#endif
// write intermediate results to disk for debugging
#define vtkSurfaceLICMapperDEBUG 0
#if vtkSurfaceLICMapperDEBUG >= 2
#include "vtkTextureIO.h"
#include <sstream>
using std::ostringstream;
//----------------------------------------------------------------------------
static
string mpifn(vtkPainterCommunicator *comm, const char *fn)
{
ostringstream oss;
oss << comm->GetRank() << "_" << fn;
return oss.str();
}
#endif
// Enable stream min/max computations. Streaming is accomplished
// via PBO+glReadPixels to read just the regions we are updating.
// Without streaming PBO+glGetTexImage is used to uplaod the entire
// screen sized texture, of which (in parallel) we are updating only
// a small part of.
#define STREAMING_MIN_MAX
// store depths in a texture. if not a renderbuffer object is used.
// NOTE: this must be on because of a slight diffference in how
// texture filtering is implemented by os mesa.
#define USE_DEPTH_TEXTURE
//#include "vtkSurfaceLICMapper_GeomFs.h"
//#include "vtkSurfaceLICMapper_GeomVs.h"
#include "vtkSurfaceLICMapper_SC.h"
#include "vtkSurfaceLICMapper_CE.h"
#include "vtkSurfaceLICMapper_DCpy.h"
namespace vtkSurfaceLICMapperUtil
{
inline
double vtkClamp(double val, const double& min, const double& max)
{
val = (val < min)? min : val;
val = (val > max)? max : val;
return val;
}
// Description
// find min/max of unmasked fragments across all regions
// download the entire screen then search each region
void FindMinMax(
vtkTextureObject *tex,
deque<vtkPixelExtent> &blockExts,
float &min,
float &max)
{
// download entire screen
vtkPixelBufferObject *pbo = tex->Download();
float *pHSLColors = static_cast<float*>(pbo->MapPackedBuffer());
// search regions
int size0 = tex->GetWidth();
size_t nBlocks = blockExts.size();
for (size_t e=0; e<nBlocks; ++e)
{
const vtkPixelExtent &blockExt = blockExts[e];
for (int j=blockExt[2]; j<=blockExt[3]; ++j)
{
for (int i=blockExt[0]; i<=blockExt[1]; ++i)
{
size_t id = 4*(size0*j+i);
if (pHSLColors[id+3] != 0.0f)
{
float L = pHSLColors[id+2];
min = min > L ? L : min;
max = max < L ? L : max;
}
}
}
}
pbo->UnmapPackedBuffer();
pbo->Delete();
#if vtkSurfaceLICMapperDEBUG >= 1
cerr << "min=" << min << " max=" << max << endl;
#endif
}
// Description
// find min/max of unmasked fragments across all regions
// download each search each region individually
void StreamingFindMinMax(
vtkFrameBufferObject2 *fbo,
deque<vtkPixelExtent> &blockExts,
float &min,
float &max)
{
size_t nBlocks = blockExts.size();
// initiate download
fbo->ActivateReadBuffer(1U);
vtkStaticCheckFrameBufferStatusMacro(GL_FRAMEBUFFER);
vector<vtkPixelBufferObject*> pbos(nBlocks, NULL);
for (size_t e=0; e<nBlocks; ++e)
{
pbos[e] = fbo->Download(
blockExts[e].GetData(),
VTK_FLOAT,
4,
GL_FLOAT,
GL_RGBA);
}
fbo->RemoveTexColorAttachment(GL_DRAW_FRAMEBUFFER, 0U);
fbo->RemoveTexColorAttachment(GL_DRAW_FRAMEBUFFER, 1U);
fbo->DeactivateDrawBuffers();
fbo->DeactivateReadBuffer();
// map search and release each region
for (size_t e=0; e<nBlocks; ++e)
{
vtkPixelBufferObject *&pbo = pbos[e];
float *pColors = (float*)pbo->MapPackedBuffer();
size_t n = blockExts[e].Size();
for (size_t i = 0; i<n; ++i)
{
if (pColors[4*i+3] != 0.0f)
{
float L = pColors[4*i+2];
min = min > L ? L : min;
max = max < L ? L : max;
}
}
pbo->UnmapPackedBuffer();
pbo->Delete();
pbo = NULL;
}
#if vtkSurfaceLICMapperDEBUG >= 1
cerr << "min=" << min << " max=" << max << endl;
#endif
}
/**
integer log base 2
*/
int ilog2(unsigned int n)
{
if (n == 0)
{
return -1;
}
unsigned int r = 0;
while ((n >>= 1))
{
r += 1;
}
return r;
}
/**
An interface to a random number generator. We can't use
c stdlib since we're not gauranteed to get consistent.
sequences across platform or library version and that
would prevent consistent output during regression tests.
*/
class RandomNumberGeneratorInterface
{
public:
RandomNumberGeneratorInterface()
{
this->RNG = vtkMinimalStandardRandomSequence::New();
}
~RandomNumberGeneratorInterface()
{
this->RNG->Delete();
}
/**
Seed the random number generator
*/
void SetSeed(int seedVal)
{
#if 0
srand(seedVal);
#else
this->RNG->SetSeed(seedVal);
#endif
}
/**
Get a random number in the range of 0 to 1.
*/
double GetRandomNumber()
{
#if 0
double val = static_cast<double>(rand())/RAND_MAX;
#else
double val = this->RNG->GetValue();
this->RNG->Next();
#endif
return val;
}
private:
void operator=(const RandomNumberGeneratorInterface &); // not implemented
RandomNumberGeneratorInterface(const RandomNumberGeneratorInterface &); // not implemented
private:
vtkMinimalStandardRandomSequence *RNG;
};
/**
2D Noise Generator. Generate arrays for use as noise texture
in the LIC algorithm. Can generate noise with uniform or Gaussian
distributions, with a desired number of noise levels, and a
desired frequency (f < 1 is impulse noise).
*/
class RandomNoise2D
{
public:
RandomNoise2D(){}
// Description:
// Generate a patch of random gray scale values along with an
// alpha channel (in vtk array format). The data should be
// deleted by later calling DeleteValues. Grain size and sideLen
// may be modified to match the noise generator requirements,
// returned arrays will be sized accordingly.
//
// type - UNIFORM=0, GAUSSIAN=1, PERLIN=2
// sideLen - side length of square patch in pixels (in/out)
// grainSize - grain size of noise values in pixels (in/out)
// nLevels - number of noise intesity levels
// minNoiseVal - set the min for noise pixels (position distribution)
// maxNoiseVal - set the max for noise pixels (position distribution)
// impulseProb - probability of impulse noise,1 touches every pixel
// impulseBgNoiseVal - set the background color for impulse noise
// seed - seed for random number generator
enum {
UNIFORM = 0,
GAUSSIAN = 1,
PERLIN = 2
};
float *Generate(
int type,
int &sideLen,
int &grainLize,
float minNoiseVal,
float maxNoiseVal,
int nLevels,
double impulseProb,
float impulseBgNoiseVal,
int seed);
// Description
// Delete the passed in array of values.
void DeleteValues(unsigned char *vals){ free(vals); }
private:
// Description:
// Generate noise with a uniform distribution.
float *GenerateUniform(
int sideLen,
int grainLize,
float minNoiseVal,
float maxNoiseVal,
int nLevels,
double impulseProb,
float impulseBgNoiseVal,
int seed);
// Description:
// Generate noise with a Gaussian distribution.
float *GenerateGaussian(
int sideLen,
int grainLize,
float minNoiseVal,
float maxNoiseVal,
int nLevels,
double impulseProb,
float impulseBgNoiseVal,
int seed);
// Description:
// Generate Perlin noise with a Gaussian distribution.
float *GeneratePerlin(
int sideLen,
int grainLize,
float minNoiseVal,
float maxNoiseVal,
int nLevels,
double impulseProb,
float impulseBgNoiseVal,
int seed);
// Description:
// A way of controling the probability (from 0.0 to 1.0) that you
// generate values. returns 1 if you should generate a value.
// for example this is used to control the frequency of impulse
// noise.
int ShouldGenerateValue(double prob);
// Description:
// Get a valid the length of the side of the patch and grains size in pixels
// given a desired patch side length and a grain size. This ensures that all
// grains are the same size.
void GetValidDimensionAndGrainSize(int type, int &dim, int &grainSize);
private:
RandomNumberGeneratorInterface ValueGen;
RandomNumberGeneratorInterface ProbGen;
};
//-----------------------------------------------------------------------------
void RandomNoise2D::GetValidDimensionAndGrainSize(int type, int &sideLen, int &grainSize)
{
// perlin noise both side len and grain size need to be powers of 2
if (type == PERLIN)
{
sideLen = 1 << ilog2(sideLen);
grainSize = 1 << ilog2(grainSize);
}
// grains can't be larger than the patch
if (sideLen < grainSize)
{
sideLen = grainSize;
}
// generate noise with agiven grainSize size on the patch
if (sideLen % grainSize)
{
// grainSize is not an even divsior of sideLen, adjust sideLen to
// next larger even divisor
sideLen = grainSize * (sideLen/grainSize + 1);
}
}
//-----------------------------------------------------------------------------
int RandomNoise2D::ShouldGenerateValue(double prob)
{
if (this->ProbGen.GetRandomNumber() > (1.0 - prob))
{
return 1;
}
return 0;
}
//-----------------------------------------------------------------------------
float *RandomNoise2D::Generate(
int type,
int &sideLen,
int &grainSize,
float minNoiseVal,
float maxNoiseVal,
int nLevels,
double impulseProb,
float impulseBgNoiseVal,
int seed)
{
this->GetValidDimensionAndGrainSize(type, sideLen, grainSize);
switch (type)
{
case GAUSSIAN:
return this->GenerateGaussian(
sideLen,
grainSize,
minNoiseVal,
maxNoiseVal,
nLevels,
impulseProb,
impulseBgNoiseVal,
seed);
case UNIFORM:
return this->GenerateUniform(
sideLen,
grainSize,
minNoiseVal,
maxNoiseVal,
nLevels,
impulseProb,
impulseBgNoiseVal,
seed);
case PERLIN:
return this->GeneratePerlin(
sideLen,
grainSize,
minNoiseVal,
maxNoiseVal,
nLevels,
impulseProb,
impulseBgNoiseVal,
seed);
}
return NULL;
}
//-----------------------------------------------------------------------------
float *RandomNoise2D::GenerateUniform(
int sideLen,
int grainSize,
float minNoiseVal,
float maxNoiseVal,
int nLevels,
double impulseProb,
float impulseBgNoiseVal,
int seed)
{
// generate a patch of single pixel random values
// with a uniform distribution and fixed number of levels
nLevels = nLevels < 1 ? 1 : nLevels;
int maxLevel = nLevels-1;
float delta = maxLevel != 0 ? 1.0f/maxLevel : 0.0f;
minNoiseVal = minNoiseVal < 0.0f ? 0.0f : minNoiseVal;
maxNoiseVal = maxNoiseVal > 1.0f ? 1.0f : maxNoiseVal;
float noiseRange = maxNoiseVal - minNoiseVal;
impulseProb = impulseProb < 0.0 ? 0.0 : impulseProb;
impulseProb = impulseProb > 1.0 ? 1.0 : impulseProb;
impulseBgNoiseVal = impulseBgNoiseVal < 0.0f ? 0.0f : impulseBgNoiseVal;
impulseBgNoiseVal = impulseBgNoiseVal > 1.0f ? 1.0f : impulseBgNoiseVal;
this->ValueGen.SetSeed(seed);
this->ProbGen.SetSeed(seed);
const int sdim = sideLen/grainSize;
const int sdim2 = sdim*sdim;
float *rvals=(float*)malloc(sdim2*sizeof(float));
for (int i=0; i<sdim2; ++i)
{
rvals[i] = impulseBgNoiseVal;
}
for (int j=0; j<sdim; ++j)
{
for (int i=0; i<sdim; ++i)
{
int idx=j*sdim+i;
if ((impulseProb == 1.0) || this->ShouldGenerateValue(impulseProb))
{
int l = static_cast<int>(this->ValueGen.GetRandomNumber()*nLevels);
l = l > maxLevel ? maxLevel : l; // needed for 1.0
rvals[idx] = nLevels == 1 ? maxNoiseVal : minNoiseVal + (l*delta) * noiseRange;
}
}
}
// map single pixel random values onto a patch of values of
// the requested grain size
const int ncomp = 2;
const int dim2 = sideLen*sideLen;
const int ntup = ncomp*dim2;
float *noise = (float*)malloc(ntup*sizeof(float));
for (int j=0; j<sideLen; ++j)
{
for (int i=0; i<sideLen; ++i)
{
int idx=ncomp*(j*sideLen+i);
int ii = i/grainSize;
int jj = j/grainSize;
int iidx = jj*sdim+ii;
noise[idx] = rvals[iidx];
noise[idx+1] = 1.0f; // alpha
}
}
free(rvals);
return noise;
}
//-----------------------------------------------------------------------------
float *RandomNoise2D::GenerateGaussian(
int sideLen,
int grainSize,
float minNoiseVal,
float maxNoiseVal,
int nLevels,
double impulseProb,
float impulseBgNoiseVal,
int seed)
{
// the distribution becomes Gaussian as N goes to infinity
const int N = 2048;
// generate a patch of single pixel random values
// with a gaussian distribution
impulseProb = impulseProb < 0.0 ? 0.0 : impulseProb;
impulseProb = impulseProb > 1.0 ? 1.0 : impulseProb;
impulseBgNoiseVal = impulseBgNoiseVal < 0.0f ? 0.0f : impulseBgNoiseVal;
impulseBgNoiseVal = impulseBgNoiseVal > 1.0f ? 1.0f : impulseBgNoiseVal;
this->ValueGen.SetSeed(seed);
this->ProbGen.SetSeed(seed);
const int sdim = sideLen/grainSize;
const int sdim2 = sdim*sdim;
float *rvals = (float*)malloc(sdim2*sizeof(float));
for (int i=0; i<sdim2; ++i)
{
rvals[i] = 0.0f;
}
for (int j=0; j<sdim; ++j)
{
for (int i=0; i<sdim; ++i)
{
int idx = j*sdim+i;
if ((impulseProb == 1.0) || this->ShouldGenerateValue(impulseProb))
{
double val = 0.0;
for (int q=0; q<N; ++q)
{
val += this->ValueGen.GetRandomNumber();
}
rvals[idx] = static_cast<float>(val);
}
}
}
// normalize noise field from eps to nLevels onto 0 to 1
// and restrict to the requested number of levels
// min/max
float minVal = static_cast<float>(N+1);
float maxVal = 0.0f;
for (int i=0; i<sdim2; ++i)
{
// for impulseProb < 1 background is 0 but pixels that are touched
// have a much larger value, after normalization the gaussian
// distribution is compressed and localized near 1. We can fix this
// by ignoring zero values.
minVal = impulseProb == 1.0 ?
(rvals[i] < minVal ? rvals[i] : minVal) :
(rvals[i] < minVal && rvals[i] > 0.0f ? rvals[i] : minVal);
maxVal = rvals[i]>maxVal ? rvals[i] : maxVal;
}
float maxMinDiff = maxVal-minVal;
// because we ignore zero when impulseProb<1 we have to be careful
// here so that we can support one noise level.
minVal = maxMinDiff == 0.0f ? 0.0f : minVal;
maxMinDiff = maxMinDiff == 0.0f ? (maxVal == 0.0f ? 1.0f : maxVal) : maxMinDiff;
nLevels = nLevels < 1 ? 1 : nLevels;
int maxLevel = nLevels-1;
float delta = maxLevel != 0 ? 1.0f/maxLevel : 0.0f;
minNoiseVal = minNoiseVal < 0.0f ? 0.0f : minNoiseVal;
maxNoiseVal = maxNoiseVal > 1.0f ? 1.0f : maxNoiseVal;
float noiseRange = maxNoiseVal - minNoiseVal;
for (int i=0; i<sdim2; ++i)
{
// normalize
float val = rvals[i] < minVal ? rvals[i] : (rvals[i] - minVal)/maxMinDiff;
// restrict
int l = static_cast<int>(val*nLevels);
l = l > maxLevel ? maxLevel : l;
rvals[i]
= rvals[i] < minVal ? impulseBgNoiseVal
: nLevels == 1 ? maxNoiseVal : minNoiseVal + (l*delta) * noiseRange;
}
// map single pixel random values onto a patch of values of
// the requested grain size
const int ncomp = 2;
const int dim2 = sideLen*sideLen;
const int ntup = ncomp*dim2;
float *noise = (float*)malloc(ntup*sizeof(float));
for (int j=0; j<sideLen; ++j)
{
for (int i=0; i<sideLen; ++i)
{
int idx = ncomp*(j*sideLen+i);
int ii = i/grainSize;
int jj = j/grainSize;
int iidx = jj*sdim+ii;
noise[idx] = rvals[iidx];
noise[idx+1] = 1.0; // alpha
}
}
free(rvals);
return noise;
}
//-----------------------------------------------------------------------------
float *RandomNoise2D::GeneratePerlin(
int sideLen,
int grainSize,
float minNoiseVal,
float maxNoiseVal,
int nLevels,
double impulseProb,
float impulseBgNoiseVal,
int seed)
{
// note: requires power of 2 sideLen, and sideLen > grainSize
const int ncomp = 2;
const int dim2 = sideLen*sideLen;
const int ntup = ncomp*dim2;
float *noise = static_cast<float*>(malloc(ntup*sizeof(float)));
for (int i=0; i<ntup; i+=2)
{
noise[i ] = 0.0f;
noise[i+1] = 1.0f; // alpha channel
}
impulseProb = impulseProb < 0.0 ? 0.0 : impulseProb;
impulseProb = impulseProb > 1.0 ? 1.0 : impulseProb;
impulseBgNoiseVal = impulseBgNoiseVal < 0.0f ? 0.0f : impulseBgNoiseVal;
impulseBgNoiseVal = impulseBgNoiseVal > 1.0f ? 1.0f : impulseBgNoiseVal;
minNoiseVal = minNoiseVal < 0.0f ? 0.0f : minNoiseVal;
maxNoiseVal = maxNoiseVal > 1.0f ? 1.0f : maxNoiseVal;
//int nIter = ilog2(static_cast<unsigned int>(sideLen-1<nLevels ? sideLen-1 : nLevels));
int nIter = ilog2(static_cast<unsigned int>(grainSize));
for (int w=0; w<nIter; ++w)
{
// reduce range with grain size
float levelNoiseMin = 0.0f;
float levelNoiseMax = 0.1f + 0.9f/static_cast<float>(1<<(nIter-1-w));
//float levelNoiseMax = 1.0f - levelNoiseMin;
// generate a level of noise
int levelGrainSize = 1<<w;
float *levelNoise = GenerateGaussian(
sideLen,
levelGrainSize,
levelNoiseMin,
levelNoiseMax,
nLevels,
impulseProb,
impulseBgNoiseVal,
seed);
/*// smooth
int nsp = w;
for (int k=0; k<nsp; ++k)
{
for (int j=0; j<sideLen; ++j)
{
for (int i=0; i<sideLen; ++i)
{
float K[9] = {
0.0191724, 0.100120, 0.0191724,
0.1001200, 0.522831, 0.1001200,
0.0191724, 0.100120, 0.0191724
};
float val=0.0;
for (int q=0; q<3; ++q)
{
for (int p=0; p<3; ++p)
{
int ii = i+p-1;
ii = ii < 0 ? i : ii;
ii = ii >= sideLen ? i : ii;
int jj = j+q-1;
jj = jj < 0 ? j : jj;
jj = jj >= sideLen ? j : jj;
int idx = 2*(sideLen*jj+ii);
val += levelNoise[idx]*K[q*3+p];
}
}
levelNoise[2*(sideLen*j+i)] = val;
}
}
}*/
// accumulate
for (int i=0; i<ntup; i+=2)
{
noise[i] += levelNoise[i];
}
free(levelNoise);
}
// normalize
float minVal = static_cast<float>(nIter+1);
float maxVal = 0.0f;
for (int i=0; i<ntup; i+=2)
{
float val = noise[i];
minVal = val<minVal ? val : minVal;
maxVal = val>maxVal ? val : maxVal;
}
float maxMinDiff = maxVal - minVal;
if ( maxMinDiff <= 0.0f )
{
maxMinDiff = 1.0f;
minVal = 0.0f;
}
for (int i=0; i<ntup; i+=2)
{
noise[i] = (noise[i] - minVal) / maxMinDiff;
}
return noise;
}
/**
Load a predefiined texture that has been "pickled" in a string.
This texture is 200x200 pixles, has a Gaussian distribution, and
intensities ranging between 0 and 206. This is the texture that
is used when GenerateNoiseTexture is disabled.
*/
vtkImageData *vtkGetNoiseResource()
{
std::string base64string;
for (unsigned int cc=0; cc < file_noise200x200_vtk_nb_sections; cc++)
{
base64string += reinterpret_cast<const char*>(file_noise200x200_vtk_sections[cc]);
}
unsigned char* binaryInput
= new unsigned char[file_noise200x200_vtk_decoded_length + 10];
unsigned long binarylength = vtkBase64Utilities::Decode(
reinterpret_cast<const unsigned char*>(base64string.c_str()),
static_cast<unsigned long>(base64string.length()),
binaryInput);
assert("check valid_length"
&& (binarylength == file_noise200x200_vtk_decoded_length));
vtkGenericDataObjectReader* reader = vtkGenericDataObjectReader::New();
reader->ReadFromInputStringOn();
reader->SetBinaryInputString(
reinterpret_cast<char*>(binaryInput),
static_cast<int>(binarylength));
reader->Update();
vtkImageData* data = vtkImageData::New();
data->ShallowCopy(reader->GetOutput());
delete [] binaryInput;
reader->Delete();
return data;
}
};
using namespace vtkSurfaceLICMapperUtil;
/**
Internal data
*/
class vtkSurfaceLICMapper::vtkInternals
{
public:
vtkWeakPointer<vtkOpenGLRenderWindow> Context;
bool GLSupport;
int Viewsize[2];
long long LastInputDataSetMTime;
long long LastPropertyMTime;
long long LastLUTMTime;
deque<vtkPixelExtent> BlockExts;
vtkPixelExtent DataSetExt;
bool ContextNeedsUpdate;
bool OutputDataNeedsUpdate;
bool CommunicatorNeedsUpdate;
bool GeometryNeedsUpdate;
bool GatherNeedsUpdate;
bool LICNeedsUpdate;
bool ColorNeedsUpdate;
vtkPainterCommunicator *Communicator;
#ifdef USE_DEPTH_TEXTURE
vtkSmartPointer<vtkTextureObject> DepthImage;
#else
vtkSmartPointer<vtkRenderbuffer> DepthImage;
#endif
vtkSmartPointer<vtkTextureObject> GeometryImage;
vtkSmartPointer<vtkTextureObject> VectorImage;
vtkSmartPointer<vtkTextureObject> CompositeVectorImage;
vtkSmartPointer<vtkTextureObject> MaskVectorImage;
vtkSmartPointer<vtkTextureObject> CompositeMaskVectorImage;
vtkSmartPointer<vtkTextureObject> NoiseImage;
vtkSmartPointer<vtkTextureObject> LICImage;
vtkSmartPointer<vtkTextureObject> RGBColorImage;
vtkSmartPointer<vtkTextureObject> HSLColorImage;
vtkSmartPointer<vtkImageData> Noise;
vtkSmartPointer<vtkFrameBufferObject2> FBO;
vtkOpenGLHelper *ColorPass;
vtkOpenGLHelper *ColorEnhancePass;
vtkOpenGLHelper *CopyPass;
vtkSmartPointer<vtkSurfaceLICComposite> Compositor;
vtkSmartPointer<vtkLineIntegralConvolution2D> LICer;
int FieldAssociation;
int FieldAttributeType;
std::string FieldName;
bool FieldNameSet;
bool HasVectors;
// Description:
// Constructor
vtkInternals()
{
this->Viewsize[0] = this->Viewsize[1] = 0;
this->LastInputDataSetMTime = 0;
this->LastPropertyMTime = 0;
this->LastLUTMTime = 0;
this->GLSupport = false;
this->ContextNeedsUpdate = true;
this->OutputDataNeedsUpdate = true;
this->CommunicatorNeedsUpdate = true;
this->GeometryNeedsUpdate = true;
this->LICNeedsUpdate = true;
this->GatherNeedsUpdate = true;
this->ColorNeedsUpdate = true;
this->Communicator = new vtkPainterCommunicator;
this->HasVectors = false;
this->FieldNameSet = false;
this->FieldAttributeType = 0;
this->FieldAssociation = 0;
this->ColorPass = NULL;
this->ColorEnhancePass = NULL;
this->CopyPass = NULL;
}
// Description:
// Destructor
~vtkInternals()
{
this->ClearGraphicsResources();
if (this->ColorPass)
{
delete this->ColorPass;
}
if (this->ColorEnhancePass)
{
delete this->ColorEnhancePass;
}
if (this->CopyPass)
{
delete this->CopyPass;
}
this->ColorPass = NULL;
this->ColorEnhancePass = NULL;
this->CopyPass = NULL;
delete this->Communicator;
}
// Description:
// Check for OpenGL support
static bool IsSupported(vtkOpenGLRenderWindow *context)
{
if (context == NULL)
{
vtkGenericWarningMacro("OpenGL render window required");
return false;
}
bool lic2d = vtkLineIntegralConvolution2D::IsSupported(context);
bool floatFormats
= vtkTextureObject::IsSupported(context, true, true, false);
bool renderbuffer = true;
#if !defined(USE_DEPTH_TEXTURE)
renderbuffer = vtkRenderbuffer::IsSupported(context);
#endif
bool support = lic2d && floatFormats && renderbuffer;
if (!support)
{
vtkGenericWarningMacro(
<< "SurfaceLIC is not supported" << endl
<< context->GetClassName() << endl
<< "LIC support = " << lic2d << endl
<< "floating point texture formats = " << floatFormats << endl
<< "render buffers = " << renderbuffer);
return false;
}
return true;
}
// Description:
// Free textures and shader programs we're holding a reference to.
void ClearGraphicsResources()
{
this->ClearTextures();
this->Compositor = NULL;
this->LICer = NULL;
this->FBO = NULL;
}
// Description:
// Free textures we're holding a reference to.
void ClearTextures()
{
this->DepthImage = NULL;
this->GeometryImage = NULL;
this->VectorImage = NULL;
this->MaskVectorImage = NULL;
this->CompositeVectorImage = NULL;
this->CompositeMaskVectorImage = NULL;
this->NoiseImage = NULL;
this->LICImage = NULL;
this->RGBColorImage = NULL;
this->HSLColorImage = NULL;
}
// Description:
// Allocate textures.
void AllocateTextures(
vtkOpenGLRenderWindow *context,
int *viewsize)
{
this->AllocateDepthTexture(context, viewsize, this->DepthImage);
this->AllocateTexture(context, viewsize, this->GeometryImage, vtkTextureObject::Nearest);
this->AllocateTexture(context, viewsize, this->VectorImage, vtkTextureObject::Linear);
this->AllocateTexture(context, viewsize, this->MaskVectorImage, vtkTextureObject::Linear);
this->AllocateTexture(context, viewsize, this->CompositeVectorImage, vtkTextureObject::Linear);
this->AllocateTexture(context, viewsize, this->CompositeMaskVectorImage, vtkTextureObject::Linear);
this->AllocateTexture(context, viewsize, this->LICImage, vtkTextureObject::Nearest);
this->AllocateTexture(context, viewsize, this->RGBColorImage, vtkTextureObject::Nearest);
this->AllocateTexture(context, viewsize, this->HSLColorImage, vtkTextureObject::Nearest);
}
// Description:
// Allocate a size texture, store in the given smart pointer.
void AllocateTexture(
vtkOpenGLRenderWindow *context,
int *viewsize,
vtkSmartPointer<vtkTextureObject> &tex,
int filter = vtkTextureObject::Nearest)
{
if ( !tex )
{
vtkTextureObject * newTex = vtkTextureObject::New();
newTex->SetContext(context);
newTex->SetBaseLevel(0);
newTex->SetMaxLevel(0);
newTex->SetWrapS(vtkTextureObject::ClampToEdge);
newTex->SetWrapT(vtkTextureObject::ClampToEdge);
newTex->SetMinificationFilter(filter);
newTex->SetMagnificationFilter(filter);
newTex->SetBorderColor(0.0f, 0.0f, 0.0f, 0.0f);
newTex->Create2D(viewsize[0], viewsize[1], 4, VTK_FLOAT, false);
newTex->SetAutoParameters(0);
tex = newTex;
newTex->Delete();
}
}
// Description:
// Allocate a size texture, store in the given smart pointer.
#ifdef USE_DEPTH_TEXTURE
void AllocateDepthTexture(
vtkOpenGLRenderWindow *context,
int *viewsize,
vtkSmartPointer<vtkTextureObject> &tex)
{
if ( !tex )
{
vtkTextureObject * newTex = vtkTextureObject::New();
newTex->SetContext(context);
newTex->AllocateDepth(viewsize[0], viewsize[1], vtkTextureObject::Float32);
newTex->SetAutoParameters(0);
tex = newTex;
newTex->Delete();
}
}
#else
void AllocateDepthTexture(
vtkOpenGLRenderWindow *context,
int *viewsize,
vtkSmartPointer<vtkRenderbuffer> &buf)
{
if ( !buf )
{
vtkRenderbuffer * newBuf = vtkRenderbuffer::New();
newBuf->SetContext(context);
newBuf->CreateDepthAttachment(viewsize[0], viewsize[1]);
buf = newBuf;
newBuf->Delete();
}
}
#endif
// Description:
// After LIC has been computed reset/clean internal state
void Updated()
{
this->ContextNeedsUpdate = false;
this->OutputDataNeedsUpdate = false;
this->CommunicatorNeedsUpdate = false;
this->GeometryNeedsUpdate = false;
this->GatherNeedsUpdate = false;
this->LICNeedsUpdate = false;
this->ColorNeedsUpdate = false;
}
// Description:
// Force all stages to re-execute. Necessary if the
// context or communicator changes.
void UpdateAll()
{
this->ContextNeedsUpdate = true;
this->OutputDataNeedsUpdate= true;
this->CommunicatorNeedsUpdate= true;
this->GeometryNeedsUpdate= true;
this->GatherNeedsUpdate= true;
this->LICNeedsUpdate= true;
this->ColorNeedsUpdate= true;
}
// Description:
// Convert viewport to texture coordinates
void ViewportQuadTextureCoords(GLfloat *tcoords)
{
tcoords[0] = tcoords[2] = 0.0f;
tcoords[1] = tcoords[3] = 1.0f;
}
// Description:
// Convert a viewport to a bounding box and it's texture coordinates for a
// screen size texture.
void ViewportQuadPoints(const vtkPixelExtent &viewportExt, GLfloat *quadpts)
{
viewportExt.GetData(quadpts);
}
// Description:
// Convert a viewport to a bounding box and it's texture coordinates for a
// screen size texture.
void ViewportQuadTextureCoords(
const vtkPixelExtent &viewExt,
const vtkPixelExtent &viewportExt,
GLfloat *tcoords)
{
GLfloat viewsize[2];
viewExt.Size(viewsize);
// cell to node
vtkPixelExtent next(viewportExt);
next.CellToNode();
next.GetData(tcoords);
tcoords[0] = tcoords[0]/viewsize[0];
tcoords[1] = tcoords[1]/viewsize[0];
tcoords[2] = tcoords[2]/viewsize[1];
tcoords[3] = tcoords[3]/viewsize[1];
}
// Description:
// Convert the entire view to a bounding box and it's texture coordinates for
// a screen size texture.
void ViewQuadPoints(GLfloat *quadpts)
{
quadpts[0] = quadpts[2] = 0.0f;
quadpts[1] = quadpts[3] = 1.0f;
}
// Description:
// Convert the entire view to a bounding box and it's texture coordinates for
// a screen size texture.
void ViewQuadTextureCoords(GLfloat *tcoords)
{
tcoords[0] = tcoords[2] = 0.0f;
tcoords[1] = tcoords[3] = 1.0f;
}
// Description:
// Render a quad (to trigger a shader to run)
void RenderQuad(
const vtkPixelExtent &viewExt,
const vtkPixelExtent &viewportExt,
vtkOpenGLHelper *cbo)
{
// cell to node
vtkPixelExtent next(viewportExt);
next.CellToNode();
GLfloat quadPts[4];
next.GetData(quadPts);
GLfloat quadTCoords[4];
this->ViewportQuadTextureCoords(viewExt, viewportExt, quadTCoords);
float tcoords[] = {
quadTCoords[0], quadTCoords[2],
quadTCoords[1], quadTCoords[2],
quadTCoords[1], quadTCoords[3],
quadTCoords[0], quadTCoords[3]};
float verts[] = {
quadTCoords[0]*2.0-1.0, quadTCoords[2]*2.0-1.0, 0.0f,
quadTCoords[1]*2.0-1.0, quadTCoords[2]*2.0-1.0, 0.0f,
quadTCoords[1]*2.0-1.0, quadTCoords[3]*2.0-1.0, 0.0f,
quadTCoords[0]*2.0-1.0, quadTCoords[3]*2.0-1.0, 0.0f};
vtkOpenGLRenderUtilities::RenderQuad(verts, tcoords,
cbo->Program, cbo->VAO);
vtkOpenGLStaticCheckErrorMacro("failed at RenderQuad");
}
// always return true as these state monitors do not exist in the
// new backend
bool LightingChanged()
{
return true;
}
bool ViewChanged()
{
return true;
}
bool BackgroundChanged(vtkRenderer *)
{
return true;
}
// Description:
// Compute the index into the 4x4 OpenGL ordered matrix.
inline
int idx(int row, int col) { return 4*col+row; }
// Description:
// given a axes aligned bounding box in
// normalized device coordinates test for
// view frustum visibility.
// if all points are outside one of the
// view frustum planes then this box
// is not visible. we might have false
// positive where more than one clip
// plane intersects the box.
bool VisibilityTest(double ndcBBox[24])
{
// check all points in the direction d
// at the same time.
for (int d=0; d<3; ++d)
{
if (((ndcBBox[ d] < -1.0)
&& (ndcBBox[3 + d] < -1.0)
&& (ndcBBox[6 + d] < -1.0)
&& (ndcBBox[9 + d] < -1.0)
&& (ndcBBox[12 + d] < -1.0)
&& (ndcBBox[15 + d] < -1.0)
&& (ndcBBox[18 + d] < -1.0)
&& (ndcBBox[21 + d] < -1.0))
||((ndcBBox[ d] > 1.0)
&& (ndcBBox[3 + d] > 1.0)
&& (ndcBBox[6 + d] > 1.0)
&& (ndcBBox[9 + d] > 1.0)
&& (ndcBBox[12 + d] > 1.0)
&& (ndcBBox[15 + d] > 1.0)
&& (ndcBBox[18 + d] > 1.0)
&& (ndcBBox[21 + d] > 1.0)) )
{
return false;
}
}
return true;
}
// Description:
// Given world space bounds,
// compute bounding boxes in clip and normalized device
// coordinates and perform view frustum visiblity test.
// return true if the bounds are visible. If so the passed
// in extent object is initialized with the corresponding
//screen space extents.
bool ProjectBounds(
double PMV[16],
int viewsize[2],
double bounds[6],
vtkPixelExtent &screenExt)
{
// this is how to get the 8 corners of a bounding
// box from the VTK bounds
int bbIds[24] = {
0,2,4,
1,2,4,
1,3,4,
0,3,4,
0,2,5,
1,2,5,
1,3,5,
0,3,5
};
// normalized device coordinate bounding box
double ndcBBox[24];
for (int q = 0; q<8; ++q)
{
int qq = 3*q;
// bounding box corner
double wx = bounds[bbIds[qq ]];
double wy = bounds[bbIds[qq+1]];
double wz = bounds[bbIds[qq+2]];
// to clip coordinates
ndcBBox[qq ] = wx * PMV[idx(0,0)] + wy * PMV[idx(0,1)] + wz * PMV[idx(0,2)] + PMV[idx(0,3)];
ndcBBox[qq+1] = wx * PMV[idx(1,0)] + wy * PMV[idx(1,1)] + wz * PMV[idx(1,2)] + PMV[idx(1,3)];
ndcBBox[qq+2] = wx * PMV[idx(2,0)] + wy * PMV[idx(2,1)] + wz * PMV[idx(2,2)] + PMV[idx(2,3)];
double ndcw = wx * PMV[idx(3,0)] + wy * PMV[idx(3,1)] + wz * PMV[idx(3,2)] + PMV[idx(3,3)];
// TODO
// if the point is past the near clipping plane
// we need to do something more robust. this ensures
// the correct result but its inefficient
if (ndcw < 0.0)
{
screenExt = vtkPixelExtent(viewsize[0], viewsize[1]);
//cerr << "W<0!!!!!!!!!!!!!" << endl;
return true;
}
// to normalized device coordinates
ndcw = (ndcw == 0.0 ? 1.0 : 1.0/ndcw);
ndcBBox[qq ] *= ndcw;
ndcBBox[qq+1] *= ndcw;
ndcBBox[qq+2] *= ndcw;
}
// compute screen extent only if the object
// is inside the view frustum.
if (VisibilityTest(ndcBBox))
{
// these bounds are visible. compute screen
// space exents
double vx = viewsize[0] - 1.0;
double vy = viewsize[1] - 1.0;
double vx2 = viewsize[0] * 0.5;
double vy2 = viewsize[1] * 0.5;
vtkBoundingBox box;
for (int q=0; q<8; ++q)
{
int qq = 3*q;
double sx = (ndcBBox[qq ] + 1.0) * vx2;
double sy = (ndcBBox[qq+1] + 1.0) * vy2;
box.AddPoint(
vtkClamp(sx, 0.0, vx),
vtkClamp(sy, 0.0, vy),
0.0);
}
// to screen extent
const double *s0 = box.GetMinPoint();
const double *s1 = box.GetMaxPoint();
screenExt[0] = static_cast<int>(s0[0]);
screenExt[1] = static_cast<int>(s1[0]);
screenExt[2] = static_cast<int>(s0[1]);
screenExt[3] = static_cast<int>(s1[1]);
return true;
}
// these bounds aren't visible
return false;
}
// Description:
// Compute screen space extents for each block in the input
// dataset and for the entire dataset. Only visible blocks
// are used in the computations.
int ProjectBounds(
vtkRenderer *ren,
vtkActor *actor,
vtkDataObject *dobj,
int viewsize[2],
vtkPixelExtent &dataExt,
deque<vtkPixelExtent> &blockExts)
{
// get the modelview projection matrix
vtkNew<vtkMatrix4x4> tmpMatrix;
vtkOpenGLCamera *oglCam =
vtkOpenGLCamera::SafeDownCast(ren->GetActiveCamera());
vtkMatrix4x4 *wcdc;
vtkMatrix4x4 *wcvc;
vtkMatrix3x3 *norms;
vtkMatrix4x4 *vcdc;
oglCam->GetKeyMatrices(ren,wcvc,norms,vcdc,wcdc);
if (!actor->GetIsIdentity())
{
vtkMatrix4x4 *mcwc;
vtkMatrix3x3 *anorms;
((vtkOpenGLActor *)actor)->GetKeyMatrices(mcwc,anorms);
vtkMatrix4x4::Multiply4x4(mcwc, wcdc, tmpMatrix.GetPointer());
}
else
{
tmpMatrix->DeepCopy(wcdc);
}
/*
for ( int c = 0; c < 4; c ++ )
{
for ( int r = 0; r < 4; r ++ )
{
PMV[c*4+r]
= P[idx(r,0)] * MV[idx(0,c)]
+ P[idx(r,1)] * MV[idx(1,c)]
+ P[idx(r,2)] * MV[idx(2,c)]
+ P[idx(r,3)] * MV[idx(3,c)];
}
}
*/
// dataset case
vtkDataSet* ds = dynamic_cast<vtkDataSet*>(dobj);
if (ds && ds->GetNumberOfCells())
{
double bounds[6];
ds->GetBounds(bounds);
if ( vtkBoundingBox::IsValid(bounds)
&& this->ProjectBounds(tmpMatrix->Element[0], viewsize, bounds, dataExt) )
{
// the dataset is visible
// add its extent
blockExts.push_back(dataExt);
return 1;
}
//cerr << "ds " << ds << " not visible " << endl;
return 0;
}
// composite dataset case
vtkCompositeDataSet* cd = dynamic_cast<vtkCompositeDataSet*>(dobj);
if (cd)
{
// process each block's bounds
vtkBoundingBox bbox;
vtkCompositeDataIterator* iter = cd->NewIterator();
for (iter->InitTraversal(); !iter->IsDoneWithTraversal(); iter->GoToNextItem())
{
ds = dynamic_cast<vtkDataSet*>(iter->GetCurrentDataObject());
if (ds && ds->GetNumberOfCells())
{
double bounds[6];
ds->GetBounds(bounds);
vtkPixelExtent screenExt;
if ( vtkBoundingBox::IsValid(bounds)
&& this->ProjectBounds(tmpMatrix->Element[0], viewsize, bounds, screenExt) )
{
// this block is visible
// save it's screen extent
// and accumulate its bounds
blockExts.push_back(screenExt);
bbox.AddBounds(bounds);
}
//else { cerr << "leaf " << ds << " not visible " << endl << endl;}
}
}
iter->Delete();
// process accumulated dataset bounds
double bounds[6];
bbox.GetBounds(bounds);
if ( vtkBoundingBox::IsValid(bounds)
&& this->ProjectBounds(tmpMatrix->Element[0], viewsize, bounds, dataExt) )
{
return 1;
}
return 0;
}
//cerr << "ds " << ds << " no cells " << endl;
return 0;
}
// Description:
// Shrink an extent to tightly bound non-zero values
void GetPixelBounds(float *rgba, int ni, vtkPixelExtent &ext)
{
vtkPixelExtent text;
for (int j=ext[2]; j<=ext[3]; ++j)
{
for (int i=ext[0]; i<=ext[1]; ++i)
{
if (rgba[4*(j*ni+i)+3] > 0.0f)
{
text[0] = text[0] > i ? i : text[0];
text[1] = text[1] < i ? i : text[1];
text[2] = text[2] > j ? j : text[2];
text[3] = text[3] < j ? j : text[3];
}
}
}
ext = text;
}
// Description:
// Shrink a set of extents to tightly bound non-zero values
// cull extent if it's empty
void GetPixelBounds(float *rgba, int ni, deque<vtkPixelExtent> &blockExts)
{
vector<vtkPixelExtent> tmpExts(blockExts.begin(),blockExts.end());
blockExts.clear();
size_t nBlocks = tmpExts.size();
for (size_t b=0; b<nBlocks; ++b)
{
vtkPixelExtent &tmpExt = tmpExts[b];
GetPixelBounds(rgba, ni, tmpExt);
if (!tmpExt.Empty())
{
blockExts.push_back(tmpExt);
}
}
}
};
//----------------------------------------------------------------------------
vtkObjectFactoryNewMacro(vtkSurfaceLICMapper);
//----------------------------------------------------------------------------
vtkSurfaceLICMapper::vtkSurfaceLICMapper()
{
this->Internals = new vtkInternals();
this->Output = 0;
this->Enable = 1;
this->AlwaysUpdate = 0;
this->StepSize = 1;
this->NumberOfSteps = 20;
this->NormalizeVectors = 1;
this->EnhancedLIC = 1;
this->EnhanceContrast = 0;
this->LowLICContrastEnhancementFactor = 0.0;
this->HighLICContrastEnhancementFactor = 0.0;
this->LowColorContrastEnhancementFactor = 0.0;
this->HighColorContrastEnhancementFactor = 0.0;
this->AntiAlias = 0;
this->ColorMode = COLOR_MODE_BLEND;
this->LICIntensity = 0.8;
this->MapModeBias = 0.0;
this->GenerateNoiseTexture = 0;
this->NoiseType = NOISE_TYPE_GAUSSIAN;
this->NoiseTextureSize = 200;
this->MinNoiseValue = 0.0;
this->MaxNoiseValue = 0.8;
this->NoiseGrainSize = 1;
this->NumberOfNoiseLevels = 256;
this->ImpulseNoiseProbability = 1.0;
this->ImpulseNoiseBackgroundValue = 0.0;
this->NoiseGeneratorSeed = 1;
this->MaskOnSurface = 0;
this->MaskThreshold = 0.0;
this->MaskIntensity = 0.0;
this->MaskColor[0] = 0.5;
this->MaskColor[1] = 0.5;
this->MaskColor[2] = 0.5;
this->CompositeStrategy = COMPOSITE_AUTO;
this->SetInputArrayToProcess(0,0,0,
vtkDataObject::FIELD_ASSOCIATION_POINTS_THEN_CELLS,
vtkDataSetAttributes::VECTORS);
// we always want texture coordinates
// they are the vector field we LIC on
this->ForceTextureCoordinates = true;
}
//----------------------------------------------------------------------------
vtkSurfaceLICMapper::~vtkSurfaceLICMapper()
{
#if vtkSurfaceLICMapperDEBUG >= 1
cerr << "=====vtkSurfaceLICMapper::~vtkSurfaceLICMapper" << endl;
#endif
this->ReleaseGraphicsResources(this->Internals->Context);
delete this->Internals;
if (this->Output)
{
this->Output->Delete();
this->Output = 0;
}
}
void vtkSurfaceLICMapper::ShallowCopy(vtkAbstractMapper *mapper)
{
vtkSurfaceLICMapper *m = vtkSurfaceLICMapper::SafeDownCast(mapper);
if ( m != NULL )
{
this->SetScalarVisibility(m->GetScalarVisibility());
this->SetNumberOfSteps(m->GetNumberOfSteps());
this->SetStepSize(m->GetStepSize());
this->SetEnhancedLIC(m->GetEnhancedLIC());
this->SetGenerateNoiseTexture(m->GetGenerateNoiseTexture());
this->SetNoiseType(m->GetNoiseType());
this->SetNormalizeVectors(m->GetNormalizeVectors());
this->SetNoiseTextureSize(m->GetNoiseTextureSize());
this->SetNoiseGrainSize(m->GetNoiseGrainSize());
this->SetMinNoiseValue(m->GetMinNoiseValue());
this->SetMaxNoiseValue(m->GetMaxNoiseValue());
this->SetNumberOfNoiseLevels(m->GetNumberOfNoiseLevels());
this->SetImpulseNoiseProbability(m->GetImpulseNoiseProbability());
this->SetImpulseNoiseBackgroundValue(m->GetImpulseNoiseBackgroundValue());
this->SetNoiseGeneratorSeed(m->GetNoiseGeneratorSeed());
this->SetEnhanceContrast(m->GetEnhanceContrast());
this->SetLowLICContrastEnhancementFactor(
m->GetLowLICContrastEnhancementFactor());
this->SetHighLICContrastEnhancementFactor(
m->GetHighLICContrastEnhancementFactor());
this->SetLowColorContrastEnhancementFactor(
m->GetLowColorContrastEnhancementFactor());
this->SetHighColorContrastEnhancementFactor(
m->GetHighColorContrastEnhancementFactor());
this->SetAntiAlias(m->GetAntiAlias());
this->SetColorMode(m->GetColorMode());
this->SetLICIntensity(m->GetLICIntensity());
this->SetMapModeBias(m->GetMapModeBias());
this->SetMaskOnSurface(m->GetMaskOnSurface());
this->SetMaskThreshold(m->GetMaskThreshold());
this->SetMaskIntensity(m->GetMaskIntensity());
this->SetMaskColor(m->GetMaskColor());
this->SetInputArrayToProcess(0,
m->GetInputArrayInformation(0));
}
// Now do superclass
this->vtkOpenGLPolyDataMapper::ShallowCopy(mapper);
}
//----------------------------------------------------------------------------
void vtkSurfaceLICMapper::ReleaseGraphicsResources(vtkWindow* win)
{
this->Internals->ClearGraphicsResources();
this->Internals->Context = NULL;
if (this->Output)
{
this->Output->Delete();
this->Output = NULL;
}
this->Superclass::ReleaseGraphicsResources(win);
}
//----------------------------------------------------------------------------
#define vtkSetMonitoredParameterMacro(_name, _type, _code) \
void vtkSurfaceLICMapper::Set##_name (_type val) \
{ \
if (val == this->_name) \
{ \
return; \
} \
_code \
this->_name = val; \
this->Modified(); \
}
// output dataset
vtkSetMonitoredParameterMacro(
Enable,
int,
this->Internals->OutputDataNeedsUpdate = true;)
// lic
vtkSetMonitoredParameterMacro(
GenerateNoiseTexture,
int,
this->Internals->Noise = NULL;
this->Internals->NoiseImage = NULL;
this->Internals->LICNeedsUpdate = true;)
vtkSetMonitoredParameterMacro(
NoiseType,
int,
this->Internals->Noise = NULL;
this->Internals->NoiseImage = NULL;
this->Internals->LICNeedsUpdate = true;)
vtkSetMonitoredParameterMacro(
NoiseTextureSize,
int,
this->Internals->Noise = NULL;
this->Internals->NoiseImage = NULL;
this->Internals->LICNeedsUpdate = true;)
vtkSetMonitoredParameterMacro(
NoiseGrainSize,
int,
this->Internals->Noise = NULL;
this->Internals->NoiseImage = NULL;
this->Internals->LICNeedsUpdate = true;)
vtkSetMonitoredParameterMacro(
MinNoiseValue,
double,
val = val < 0.0 ? 0.0 : val;
val = val > 1.0 ? 1.0 : val;
this->Internals->Noise = NULL;
this->Internals->NoiseImage = NULL;
this->Internals->LICNeedsUpdate = true;)
vtkSetMonitoredParameterMacro(
MaxNoiseValue,
double,
val = val < 0.0 ? 0.0 : val;
val = val > 1.0 ? 1.0 : val;
this->Internals->Noise = NULL;
this->Internals->NoiseImage = NULL;
this->Internals->LICNeedsUpdate = true;)
vtkSetMonitoredParameterMacro(
NumberOfNoiseLevels,
int,
this->Internals->Noise = NULL;
this->Internals->NoiseImage = NULL;
this->Internals->LICNeedsUpdate = true;)
vtkSetMonitoredParameterMacro(
ImpulseNoiseProbability,
double,
val = val < 0.0 ? 0.0 : val;
val = val > 1.0 ? 1.0 : val;
this->Internals->Noise = NULL;
this->Internals->NoiseImage = NULL;
this->Internals->LICNeedsUpdate = true;)
vtkSetMonitoredParameterMacro(
ImpulseNoiseBackgroundValue,
double,
val = val < 0.0 ? 0.0 : val;
val = val > 1.0 ? 1.0 : val;
this->Internals->Noise = NULL;
this->Internals->NoiseImage = NULL;
this->Internals->LICNeedsUpdate = true;)
vtkSetMonitoredParameterMacro(
NoiseGeneratorSeed,
int,
this->Internals->Noise = NULL;
this->Internals->NoiseImage = NULL;
this->Internals->LICNeedsUpdate = true;)
// compositor
vtkSetMonitoredParameterMacro(
CompositeStrategy,
int,
this->Internals->GatherNeedsUpdate = true;)
// lic/compositor
vtkSetMonitoredParameterMacro(
NumberOfSteps,
int,
this->Internals->GatherNeedsUpdate = true;
this->Internals->LICNeedsUpdate = true;)
vtkSetMonitoredParameterMacro(
StepSize,
double,
this->Internals->GatherNeedsUpdate = true;
this->Internals->LICNeedsUpdate = true;)
vtkSetMonitoredParameterMacro(
NormalizeVectors,
int,
val = val < 0 ? 0 : val;
val = val > 1 ? 1 : val;
this->Internals->GatherNeedsUpdate = true;
this->Internals->LICNeedsUpdate = true;)
vtkSetMonitoredParameterMacro(
MaskThreshold,
double,
this->Internals->LICNeedsUpdate = true;)
vtkSetMonitoredParameterMacro(
EnhancedLIC,
int,
this->Internals->GatherNeedsUpdate = true;
this->Internals->LICNeedsUpdate = true;)
// lic
vtkSetMonitoredParameterMacro(
LowLICContrastEnhancementFactor,
double,
val = val < 0.0 ? 0.0 : val;
val = val > 1.0 ? 1.0 : val;
this->Internals->LICNeedsUpdate = true;)
vtkSetMonitoredParameterMacro(
HighLICContrastEnhancementFactor,
double,
val = val < 0.0 ? 0.0 : val;
val = val > 1.0 ? 1.0 : val;
this->Internals->LICNeedsUpdate = true;)
vtkSetMonitoredParameterMacro(
AntiAlias,
int,
val = val < 0 ? 0 : val;
this->Internals->GatherNeedsUpdate = true;
this->Internals->LICNeedsUpdate = true;)
// geometry
vtkSetMonitoredParameterMacro(
MaskOnSurface,
int,
val = val < 0 ? 0 : val;
val = val > 1 ? 1 : val;
this->Internals->GeometryNeedsUpdate = true;)
// colors
vtkSetMonitoredParameterMacro(
ColorMode,
int,
this->Internals->ColorNeedsUpdate = true;)
vtkSetMonitoredParameterMacro(
LICIntensity,
double,
val = val < 0.0 ? 0.0 : val;
val = val > 1.0 ? 1.0 : val;
this->Internals->ColorNeedsUpdate = true;)
vtkSetMonitoredParameterMacro(
MaskIntensity,
double,
val = val < 0.0 ? 0.0 : val;
val = val > 1.0 ? 1.0 : val;
this->Internals->ColorNeedsUpdate = true;)
vtkSetMonitoredParameterMacro(
MapModeBias,
double,
val = val <-1.0 ? -1.0 : val;
val = val > 1.0 ? 1.0 : val;
this->Internals->ColorNeedsUpdate = true;)
vtkSetMonitoredParameterMacro(
LowColorContrastEnhancementFactor,
double,
val = val < 0.0 ? 0.0 : val;
val = val > 1.0 ? 1.0 : val;
this->Internals->ColorNeedsUpdate = true;)
vtkSetMonitoredParameterMacro(
HighColorContrastEnhancementFactor,
double,
val = val < 0.0 ? 0.0 : val;
val = val > 1.0 ? 1.0 : val;
this->Internals->ColorNeedsUpdate = true;)
//----------------------------------------------------------------------------
void vtkSurfaceLICMapper::SetMaskColor(double *val)
{
double rgb[3];
for (int q=0; q<3; ++q)
{
rgb[q] = val[q];
rgb[q] = rgb[q] < 0.0 ? 0.0 : rgb[q];
rgb[q] = rgb[q] > 1.0 ? 1.0 : rgb[q];
}
if ( (rgb[0] == this->MaskColor[0])
&& (rgb[1] == this->MaskColor[1])
&& (rgb[2] == this->MaskColor[2]) )
{
return;
}
for (int q=0; q<3; ++q)
{
this->MaskColor[q] = rgb[q];
}
this->Internals->ColorNeedsUpdate = true;
this->Modified();
}
//----------------------------------------------------------------------------
void vtkSurfaceLICMapper::SetEnhanceContrast(int val)
{
val = val < ENHANCE_CONTRAST_OFF ? ENHANCE_CONTRAST_OFF : val;
val = val > ENHANCE_CONTRAST_BOTH ? ENHANCE_CONTRAST_BOTH : val;
if (val == this->EnhanceContrast)
{
return;
}
switch ( this->EnhanceContrast )
{
case ENHANCE_CONTRAST_OFF:
switch ( val )
{
case ENHANCE_CONTRAST_LIC:
case ENHANCE_CONTRAST_BOTH:
this->Internals->LICNeedsUpdate = true;
break;
case ENHANCE_CONTRAST_COLOR:
this->Internals->ColorNeedsUpdate = true;
break;
}
break;
case ENHANCE_CONTRAST_LIC:
switch ( val )
{
case ENHANCE_CONTRAST_OFF:
case ENHANCE_CONTRAST_COLOR:
this->Internals->LICNeedsUpdate = true;
break;
case ENHANCE_CONTRAST_BOTH:
this->Internals->ColorNeedsUpdate = true;
break;
}
break;
case ENHANCE_CONTRAST_COLOR:
switch ( val )
{
case ENHANCE_CONTRAST_LIC:
case ENHANCE_CONTRAST_BOTH:
this->Internals->LICNeedsUpdate = true;
break;
case ENHANCE_CONTRAST_OFF:
this->Internals->ColorNeedsUpdate = true;
break;
}
break;
case ENHANCE_CONTRAST_BOTH:
switch ( val )
{
case ENHANCE_CONTRAST_OFF:
this->Internals->LICNeedsUpdate = true;
break;
case ENHANCE_CONTRAST_COLOR:
this->Internals->LICNeedsUpdate = true;
case ENHANCE_CONTRAST_LIC:
this->Internals->ColorNeedsUpdate = true;
break;
}
break;
}
this->EnhanceContrast = val;
this->Modified();
}
//----------------------------------------------------------------------------
void vtkSurfaceLICMapper::SetNoiseDataSet(vtkImageData *data)
{
if (data == this->Internals->Noise)
{
return;
}
this->Internals->Noise = data;
this->Internals->NoiseImage = NULL;
this->Modified();
}
//----------------------------------------------------------------------------
vtkImageData *vtkSurfaceLICMapper::GetNoiseDataSet()
{
if (this->Internals->Noise == NULL)
{
vtkImageData *noise = NULL;
if ( this->GenerateNoiseTexture )
{
// report potential issues
if ( this->NoiseGrainSize >= this->NoiseTextureSize )
{
vtkErrorMacro(
"NoiseGrainSize must be smaller than NoiseTextureSize");
}
if ( this->MinNoiseValue >= this->MaxNoiseValue )
{
vtkErrorMacro(
"MinNoiseValue must be smaller than MaxNoiseValue");
}
if ( (this->ImpulseNoiseProbability == 1.0)
&& (this->NumberOfNoiseLevels < 2) )
{
vtkErrorMacro(
"NumberOfNoiseLevels must be greater than 1 "
"when not generating impulse noise");
}
// generate a custom noise texture based on the
// current settings.
int noiseTextureSize = this->NoiseTextureSize;
int noiseGrainSize = this->NoiseGrainSize;
RandomNoise2D noiseGen;
float *noiseValues = noiseGen.Generate(
this->NoiseType,
noiseTextureSize,
noiseGrainSize,
static_cast<float>(this->MinNoiseValue),
static_cast<float>(this->MaxNoiseValue),
this->NumberOfNoiseLevels,
this->ImpulseNoiseProbability,
static_cast<float>(this->ImpulseNoiseBackgroundValue),
this->NoiseGeneratorSeed);
if ( noiseValues == NULL )
{
vtkErrorMacro("Failed to generate noise.");
}
vtkFloatArray *noiseArray = vtkFloatArray::New();
noiseArray->SetNumberOfComponents(2);
noiseArray->SetName("noise");
vtkIdType arraySize = 2*noiseTextureSize*noiseTextureSize;
noiseArray->SetArray(noiseValues, arraySize, 0);
noise = vtkImageData::New();
noise->SetSpacing(1.0, 1.0, 1.0);
noise->SetOrigin(0.0, 0.0, 0.0);
noise->SetDimensions(noiseTextureSize, noiseTextureSize, 1);
noise->GetPointData()->SetScalars(noiseArray);
noiseArray->Delete();
}
else
{
// load a predefined noise texture.
noise = vtkGetNoiseResource();
}
this->Internals->Noise = noise;
this->Internals->NoiseImage = NULL;
noise->Delete();
noise = NULL;
}
return this->Internals->Noise;
}
//----------------------------------------------------------------------------
void vtkSurfaceLICMapper::UpdateNoiseImage(vtkRenderWindow *renWin)
{
vtkOpenGLRenderWindow *rw = vtkOpenGLRenderWindow::SafeDownCast(renWin);
vtkImageData *noiseDataSet = this->GetNoiseDataSet();
int ext[6];
noiseDataSet->GetExtent(ext);
unsigned int dataWidth = ext[1]-ext[0]+1;
unsigned int dataHeight = ext[3]-ext[2]+1;
vtkDataArray *noiseArray = noiseDataSet->GetPointData()->GetScalars();
int dataType = noiseArray->GetDataType();
void *data = noiseArray->GetVoidPointer(0);
int dataComps = noiseArray->GetNumberOfComponents();
unsigned int dataSize = noiseArray->GetNumberOfTuples()*dataComps;
vtkPixelBufferObject *pbo = vtkPixelBufferObject::New();
pbo->SetContext(renWin);
pbo->Upload1D(dataType, data, dataSize, 1, 0);
vtkTextureObject *tex = vtkTextureObject::New();
tex->SetContext(rw);
tex->SetBaseLevel(0);
tex->SetMaxLevel(0);
tex->SetWrapS(vtkTextureObject::Repeat);
tex->SetWrapT(vtkTextureObject::Repeat);
tex->SetMinificationFilter(vtkTextureObject::Nearest);
tex->SetMagnificationFilter(vtkTextureObject::Nearest);
tex->Create2D(dataWidth, dataHeight, dataComps, pbo, false);
tex->SetAutoParameters(0);
pbo->Delete();
this->Internals->NoiseImage = tex;
tex->Delete();
}
//----------------------------------------------------------------------------
bool vtkSurfaceLICMapper::IsSupported(vtkRenderWindow *renWin)
{
vtkOpenGLRenderWindow *context
= vtkOpenGLRenderWindow::SafeDownCast(renWin);
return vtkInternals::IsSupported(context);
}
//----------------------------------------------------------------------------
bool vtkSurfaceLICMapper::CanRenderSurfaceLIC(vtkActor *actor)
{
// check the render context for GL fetaure support
// note this also handles non-opengl render window
if ( this->Internals->ContextNeedsUpdate
&& !vtkSurfaceLICMapper::IsSupported(this->Internals->Context) )
{
vtkErrorMacro("SurfaceLIC is not supported");
return false;
}
bool canRender = false;
int rep = actor->GetProperty()->GetRepresentation();
if ( this->Enable
&& this->Internals->HasVectors
&& (rep == VTK_SURFACE))
{
canRender = true;
}
#if vtkSurfaceLICMapperDEBUG >= 1
cerr
<< this->Internals->Communicator->GetWorldRank()
<< " CanRender " << canRender << endl;
#endif
return canRender;
}
namespace {
void BuildAShader(vtkOpenGLRenderWindow *renWin,
vtkOpenGLHelper **cbor, const char * vert,
const char *frag)
{
if (*cbor == NULL)
{
*cbor = new vtkOpenGLHelper;
std::string GSSource;
(*cbor)->Program =
renWin->GetShaderCache()->ReadyShaderProgram(vert,
frag,
GSSource.c_str());
}
else
{
renWin->GetShaderCache()->ReadyShaderProgram((*cbor)->Program);
}
}
}
//----------------------------------------------------------------------------
void vtkSurfaceLICMapper::InitializeResources()
{
bool initialized = true;
// noise image
if (!this->Internals->NoiseImage)
{
initialized = false;
this->UpdateNoiseImage(this->Internals->Context);
}
// compositer for parallel operation
if (!this->Internals->Compositor)
{
this->Internals->UpdateAll();
vtkSurfaceLICComposite *compositor = vtkSurfaceLICComposite::New();
compositor->SetContext(this->Internals->Context);
this->Internals->Compositor = compositor;
compositor->Delete();
}
// image LIC
if (!this->Internals->LICer)
{
initialized = false;
vtkLineIntegralConvolution2D *LICer = vtkLineIntegralConvolution2D::New();
LICer->SetContext(this->Internals->Context);
this->Internals->LICer = LICer;
LICer->Delete();
}
// frame buffers
if (!this->Internals->FBO)
{
initialized = false;
vtkFrameBufferObject2 * fbo = vtkFrameBufferObject2::New();
fbo->SetContext(this->Internals->Context);
this->Internals->FBO = fbo;
fbo->Delete();
}
// load shader codes
vtkOpenGLRenderWindow *renWin = this->Internals->Context;
if (!this->Internals->ColorPass)
{
initialized = false;
BuildAShader(renWin, &this->Internals->ColorPass,
vtkTextureObjectVS, vtkSurfaceLICMapper_SC);
}
if (!this->Internals->ColorEnhancePass)
{
initialized = false;
BuildAShader(renWin, &this->Internals->ColorEnhancePass,
vtkTextureObjectVS, vtkSurfaceLICMapper_CE);
}
if (!this->Internals->CopyPass)
{
initialized = false;
BuildAShader(renWin, &this->Internals->CopyPass,
vtkTextureObjectVS, vtkSurfaceLICMapper_DCpy);
}
// if any of the above were not already initialized
// then execute all stages
if (!initialized)
{
this->Internals->UpdateAll();
}
}
//----------------------------------------------------------------------------
bool vtkSurfaceLICMapper::NeedToColorLIC()
{
if ( this->Internals->ColorNeedsUpdate
|| this->Internals->LICNeedsUpdate
|| this->Internals->GatherNeedsUpdate
|| this->Internals->GeometryNeedsUpdate
|| this->Internals->CommunicatorNeedsUpdate
|| this->Internals->OutputDataNeedsUpdate
|| this->Internals->ContextNeedsUpdate
|| this->AlwaysUpdate )
{
this->Internals->ColorNeedsUpdate = true;
}
#if vtkSurfaceLICMapperDEBUG >= 1
cerr
<< this->Internals->Communicator->GetWorldRank()
<< " NeedToColorLIC " << this->Internals->ColorNeedsUpdate << endl;
#endif
return this->Internals->ColorNeedsUpdate;
}
//----------------------------------------------------------------------------
bool vtkSurfaceLICMapper::NeedToComputeLIC()
{
if ( this->Internals->LICNeedsUpdate
|| this->Internals->GatherNeedsUpdate
|| this->Internals->GeometryNeedsUpdate
|| this->Internals->CommunicatorNeedsUpdate
|| this->Internals->OutputDataNeedsUpdate
|| this->Internals->ContextNeedsUpdate
|| this->AlwaysUpdate )
{
this->Internals->LICNeedsUpdate = true;
}
#if vtkSurfaceLICMapperDEBUG >= 1
cerr
<< this->Internals->Communicator->GetWorldRank()
<< " NeedToComputeLIC " << this->Internals->LICNeedsUpdate << endl;
#endif
return this->Internals->LICNeedsUpdate;
}
//----------------------------------------------------------------------------
bool vtkSurfaceLICMapper::NeedToGatherVectors()
{
if ( this->Internals->GatherNeedsUpdate
|| this->Internals->GeometryNeedsUpdate
|| this->Internals->OutputDataNeedsUpdate
|| this->Internals->CommunicatorNeedsUpdate
|| this->Internals->ContextNeedsUpdate
|| this->AlwaysUpdate )
{
this->Internals->GatherNeedsUpdate = true;
}
#if vtkSurfaceLICMapperDEBUG >= 1
cerr
<< this->Internals->Communicator->GetWorldRank()
<< " NeedToGatherVectors "
<< this->Internals->GatherNeedsUpdate << endl;
#endif
return this->Internals->GatherNeedsUpdate;
}
//----------------------------------------------------------------------------
bool vtkSurfaceLICMapper::NeedToRenderGeometry(
vtkRenderer *renderer,
vtkActor *actor)
{
// view changed or
// user modifiable parameters
if ( this->Internals->GeometryNeedsUpdate
|| this->Internals->CommunicatorNeedsUpdate
|| this->Internals->OutputDataNeedsUpdate
|| this->Internals->ContextNeedsUpdate
|| this->AlwaysUpdate )
{
this->Internals->GeometryNeedsUpdate = true;
}
// lights changed
if ( this->Internals->LightingChanged() )
{
this->Internals->GeometryNeedsUpdate = true;
}
// props changed
long long propMTime = actor->GetProperty()->GetMTime();
if ( this->Internals->LastPropertyMTime != propMTime )
{
this->Internals->LastPropertyMTime = propMTime;
this->Internals->GeometryNeedsUpdate = true;
}
// background colors changed
if (this->Internals->BackgroundChanged(renderer))
{
this->Internals->GeometryNeedsUpdate = true;
this->Internals->ColorNeedsUpdate = true;
}
#if vtkSurfaceLICMapperDEBUG >= 1
cerr
<< this->Internals->Communicator->GetWorldRank()
<< " NeedToUpdateGeometry "
<< this->Internals->GeometryNeedsUpdate << endl;
#endif
return this->Internals->GeometryNeedsUpdate;
}
//----------------------------------------------------------------------------
bool vtkSurfaceLICMapper::NeedToUpdateCommunicator()
{
// no comm or externally modfied paramters
if ( this->Internals->CommunicatorNeedsUpdate
|| this->Internals->ContextNeedsUpdate
|| this->Internals->OutputDataNeedsUpdate
|| !this->Internals->Communicator
|| this->AlwaysUpdate )
{
this->Internals->CommunicatorNeedsUpdate = true;
this->Internals->UpdateAll();
}
#if vtkSurfaceLICMapperDEBUG >= 1
cerr
<< this->Internals->Communicator->GetWorldRank()
<< " NeedToUpdateCommunicator "
<< this->Internals->CommunicatorNeedsUpdate << endl;
#endif
return this->Internals->CommunicatorNeedsUpdate;
}
//----------------------------------------------------------------------------
bool vtkSurfaceLICMapper::NeedToUpdateOutputData()
{
vtkDataObject *input = this->GetInput();
// input dataset changed
long long inputMTime = input->GetMTime();
if ( (this->Internals->LastInputDataSetMTime < inputMTime)
|| !this->Output
|| this->AlwaysUpdate)
{
this->Internals->LastInputDataSetMTime = inputMTime;
this->Internals->UpdateAll();
}
#if vtkSurfaceLICMapperDEBUG >= 1
cerr
<< this->Internals->Communicator->GetWorldRank()
<< " NeedToUpdateOutputData " << this->Internals->OutputDataNeedsUpdate << endl;
#endif
return this->Internals->OutputDataNeedsUpdate;
}
//----------------------------------------------------------------------------
void vtkSurfaceLICMapper::ValidateContext(vtkRenderer *renderer)
{
bool modified = false;
vtkOpenGLRenderWindow *context
= vtkOpenGLRenderWindow::SafeDownCast(renderer->GetRenderWindow());
// context changed
if (this->Internals->Context != context)
{
modified = true;
if (this->Internals->Context)
{
this->ReleaseGraphicsResources(this->Internals->Context);
}
this->Internals->Context = context;
}
// viewport size changed
int viewsize[2];
renderer->GetTiledSize(&viewsize[0], &viewsize[1]);
if ( this->Internals->Viewsize[0] != viewsize[0]
|| this->Internals->Viewsize[1] != viewsize[1] )
{
modified = true;
// udpate view size
this->Internals->Viewsize[0] = viewsize[0];
this->Internals->Viewsize[1] = viewsize[1];
// resize textures
this->Internals->ClearTextures();
this->Internals->AllocateTextures(context, viewsize);
}
// view changed
if (this->Internals->ViewChanged())
{
modified = true;
}
// if anything changed execute all stages
if (modified)
{
this->Internals->UpdateAll();
}
#if vtkSurfaceLICMapperDEBUG >= 1
cerr
<< this->Internals->Communicator->GetWorldRank()
<< " NeedToUpdatContext " << modified << endl;
#endif
}
//----------------------------------------------------------------------------
vtkPainterCommunicator *vtkSurfaceLICMapper::CreateCommunicator(int)
{
return new vtkPainterCommunicator;
}
//----------------------------------------------------------------------------
void vtkSurfaceLICMapper::CreateCommunicator(
vtkRenderer *ren,
vtkActor *act)
{
// compute screen space pixel extent of local blocks and
// union of local blocks. only blocks that pass view frustum
// visibility test are used in the computation.
vtkDataObject *input = this->GetInput();
this->Internals->DataSetExt.Clear();
this->Internals->BlockExts.clear();
int includeRank = this->Internals->ProjectBounds(
ren, act, input,
this->Internals->Viewsize,
this->Internals->DataSetExt,
this->Internals->BlockExts);
delete this->Internals->Communicator;
this->Internals->Communicator = this->CreateCommunicator(includeRank);
#if vtkSurfaceLICMapperDEBUG >= 1
cerr
<< this->Internals->Communicator->GetWorldRank()
<< " is rendering " << includeRank << endl;
#endif
}
//-----------------------------------------------------------------------------
void vtkSurfaceLICMapper::ProcessInformation(
vtkInformation* vtkNotUsed(info))
{
#if vtkSurfaceLICMapperDEBUG >= 1
bool LUTNeedsUpdate = false;
#endif
// detect when the LUT has been modified
vtkScalarsToColors *lut = this->GetLookupTable();
long long lutMTime;
if (lut && ((lutMTime = lut->GetMTime()) > this->Internals->LastLUTMTime))
{
this->Internals->LastLUTMTime = lutMTime;
this->Internals->UpdateAll();
#if vtkSurfaceLICMapperDEBUG >= 1
LUTNeedsUpdate = true;
#endif
}
#if vtkSurfaceLICMapperDEBUG >= 1
cerr
<< this->Internals->Communicator->GetWorldRank()
<< " NeedToUpdateLUT " << LUTNeedsUpdate << endl;
#endif
}
//----------------------------------------------------------------------------
void vtkSurfaceLICMapper::SetUpdateAll()
{
this->Internals->UpdateAll();
}
void vtkSurfaceLICMapper::ReplaceShaderValues(
std::map<vtkShader::Type, vtkShader *> shaders,
vtkRenderer *ren, vtkActor *actor)
{
std::string VSSource = shaders[vtkShader::Vertex]->GetSource();
std::string FSSource = shaders[vtkShader::Fragment]->GetSource();
// add some code to handle the LIC vectors and mask
vtkShaderProgram::Substitute(VSSource,
"//VTK::TCoord::Dec",
"attribute vec3 tcoordMC;\n"
"varying vec3 tcoordVCVSOutput;\n"
);
vtkShaderProgram::Substitute(VSSource, "//VTK::TCoord::Impl",
"tcoordVCVSOutput = tcoordMC;"
);
vtkShaderProgram::Substitute(FSSource,
"//VTK::TCoord::Dec",
// 0/1, when 1 V is projected to surface for |V| computation.
"uniform int uMaskOnSurface;\n"
"uniform mat3 normalMatrix;\n"
"varying vec3 tcoordVCVSOutput;"
);
vtkShaderProgram::Substitute(FSSource,
"//VTK::TCoord::Impl",
// projected vectors
" vec3 tcoordLIC = normalMatrix * tcoordVCVSOutput;\n"
" vec3 normN = normalize(normalVCVSOutput);\n"
" float k = dot(tcoordLIC, normN);\n"
" tcoordLIC = (tcoordLIC - k*normN);\n"
" gl_FragData[1] = vec4(tcoordLIC.x, tcoordLIC.y, 0.0 , gl_FragCoord.z);\n"
// " gl_FragData[1] = vec4(tcoordVC.xyz, gl_FragCoord.z);\n"
// vectors for fragment masking
" if (uMaskOnSurface == 0)\n"
" {\n"
" gl_FragData[2] = vec4(tcoordVCVSOutput, gl_FragCoord.z);\n"
" }\n"
" else\n"
" {\n"
" gl_FragData[2] = vec4(tcoordLIC.x, tcoordLIC.y, 0.0 , gl_FragCoord.z);\n"
" }\n"
// " gl_FragData[2] = vec4(19.0, 19.0, tcoordVC.x, gl_FragCoord.z);\n"
, false);
this->ShaderVariablesUsed.push_back("normalMatrix");
shaders[vtkShader::Vertex]->SetSource(VSSource);
shaders[vtkShader::Fragment]->SetSource(FSSource);
this->Superclass::ReplaceShaderValues(shaders,ren,actor);
}
void vtkSurfaceLICMapper::SetMapperShaderParameters(
vtkOpenGLHelper &cellBO,
vtkRenderer* ren, vtkActor *actor)
{
this->Superclass::SetMapperShaderParameters(cellBO, ren, actor);
cellBO.Program->SetUniformi("uMaskOnSurface", this->MaskOnSurface);
}
//----------------------------------------------------------------------------
void vtkSurfaceLICMapper::RenderPiece(
vtkRenderer *renderer,
vtkActor *actor)
{
#if vtkSurfaceLICMapperDEBUG >= 1
cerr
<< this->Internals->Communicator->GetWorldRank()
<< " ===== " << this->GetClassName() << "::RenderInternal" << endl;
#endif
#ifdef vtkSurfaceLICMapperTIME
this->StartTimerEvent("vtkSurfaceLICMapper::RenderInternal");
#else
vtkSmartPointer<vtkTimerLog> timer = vtkSmartPointer<vtkTimerLog>::New();
timer->StartTimer();
#endif
vtkOpenGLClearErrorMacro();
this->ValidateContext(renderer);
vtkOpenGLRenderWindow *renWin =
vtkOpenGLRenderWindow::SafeDownCast(renderer->GetVTKWindow());
if (this->NeedToUpdateOutputData())
{
// if the input data has changed we need to
// reload vector attributes and recompute
// all, but only if the output is valid.
this->PrepareOutput();
}
if (this->NeedToUpdateCommunicator())
{
#ifdef vtkSurfaceLICMapperTIME
this->StartTimerEvent("vtkSurfaceLICMapper::CreateCommunicator");
#endif
// create a communicator that contains only ranks
// that have visible data. In parallel this is a
// collective operation accross all ranks. In
// serial this is a no-op.
this->CreateCommunicator(renderer,actor);
#ifdef vtkSurfaceLICMapperTIME
this->EndTimerEvent("vtkSurfaceLICMapper::CreateCommunicator");
#endif
}
vtkPainterCommunicator *comm = this->Internals->Communicator;
if (comm->GetIsNull())
{
// other rank's may have some visible data but we
// have none and should not participate further
#ifdef vtkSurfaceLICMapperTIME
this->EndTimerEvent("vtkSurfaceLICMapper::RenderInternal");
#endif
return;
}
if (!this->CanRenderSurfaceLIC(actor))
{
// we've determined that there's no work for us, or that the
// requisite opengl extensions are not available. pass control on
// to delegate renderer and return.
this->Superclass::RenderPiece(renderer, actor);
#ifdef vtkSurfaceLICMapperTIME
this->EndTimerEvent("vtkSurfaceLICMapper::RenderInternal");
#endif
return;
}
// allocate rendering resources, initialize or update
// textures and shaders.
this->InitializeResources();
vtkPixelExtent viewExt(
this->Internals->Viewsize[0],
this->Internals->Viewsize[1]);
// save the active fbo and its draw buffer
int prevDrawBuf = 0;
glGetIntegerv(GL_DRAW_BUFFER, &prevDrawBuf);
int prevFbo = 0;
glGetIntegerv(GL_DRAW_FRAMEBUFFER_BINDING, &prevFbo);
// ------------------------------------------- render geometry, project vectors onto screen, etc
if (this->NeedToRenderGeometry(renderer, actor))
{
#ifdef vtkSurfaceLICMapperTIME
this->StartTimerEvent("vtkSurfaceLICMapper::RenderGeometry");
#endif
// setup our fbo
vtkFrameBufferObject2 *fbo = this->Internals->FBO;
fbo->SaveCurrentBindings();
fbo->Bind(GL_FRAMEBUFFER);
fbo->AddDepthAttachment(GL_DRAW_FRAMEBUFFER, this->Internals->DepthImage);
fbo->AddColorAttachment(GL_DRAW_FRAMEBUFFER, 0U, this->Internals->GeometryImage);
fbo->AddColorAttachment(GL_DRAW_FRAMEBUFFER, 1U, this->Internals->VectorImage);
fbo->AddColorAttachment(GL_DRAW_FRAMEBUFFER, 2U, this->Internals->MaskVectorImage);
fbo->ActivateDrawBuffers(3);
vtkCheckFrameBufferStatusMacro(GL_FRAMEBUFFER);
// clear internal color and depth buffers
// the LIC'er requires *all* fragments in the vector
// texture to be initialized to 0
glDisable(GL_BLEND);
glEnable(GL_DEPTH_TEST);
glDisable(GL_SCISSOR_TEST);
glClearColor(0.0, 0.0, 0.0, 0.0);
glClear(GL_DEPTH_BUFFER_BIT|GL_COLOR_BUFFER_BIT);
this->CurrentInput = vtkPolyData::SafeDownCast(this->Output);
this->RenderPieceStart(renderer, actor);
this->RenderPieceDraw(renderer, actor);
this->RenderEdges(renderer,actor);
this->RenderPieceFinish(renderer, actor);
// this->Superclass::RenderPiece(renderer, actor);
fbo->RemoveRenDepthAttachment(GL_DRAW_FRAMEBUFFER);
fbo->RemoveTexColorAttachment(GL_DRAW_FRAMEBUFFER, 0U);
fbo->RemoveTexColorAttachment(GL_DRAW_FRAMEBUFFER, 1U);
fbo->RemoveTexColorAttachment(GL_DRAW_FRAMEBUFFER, 2U);
fbo->DeactivateDrawBuffers();
fbo->UnBind(GL_FRAMEBUFFER);
#ifdef vtkSurfaceLICMapperTIME
this->EndTimerEvent("vtkSurfaceLICMapper::RenderGeometry");
#endif
#if vtkSurfaceLICMapperDEBUG >= 2
vtkTextureIO::Write(
mpifn(comm,"slicp_geometry_image.vtm"),
this->Internals->GeometryImage,
this->Internals->BlockExts);
vtkTextureIO::Write(
mpifn(comm,"slicp_vector_image.vtm"),
this->Internals->VectorImage,
this->Internals->BlockExts);
vtkTextureIO::Write(
mpifn(comm,"slicp_mask_vector_image.vtm"),
this->Internals->MaskVectorImage,
this->Internals->BlockExts);
#if defined(USE_DEPTH_TEXTURE)
vtkTextureIO::Write(
mpifn(comm,"slicp_depth_image.vtm"),
this->Internals->DepthImage,
this->Internals->BlockExts);
#endif
#endif
}
// --------------------------------------------- compoiste vectors for parallel LIC
if (this->NeedToGatherVectors())
{
#ifdef vtkSurfaceLICMapperTIME
this->StartTimerEvent("vtkSurfaceLICMapper::GatherVectors");
#endif
// get tight screen space bounds to reduce communication/computation
vtkPixelBufferObject *vecPBO = this->Internals->VectorImage->Download();
void *pVecPBO = vecPBO->MapPackedBuffer();
this->Internals->GetPixelBounds(
(float*)pVecPBO,
this->Internals->Viewsize[0],
this->Internals->BlockExts);
// initialize compositor
this->Internals->Compositor->Initialize(
viewExt,
this->Internals->BlockExts,
this->CompositeStrategy,
this->StepSize,
this->NumberOfSteps,
this->NormalizeVectors,
this->EnhancedLIC,
this->AntiAlias);
if (comm->GetMPIInitialized())
{
// parallel run
// need to use the communicator provided by the rendering engine
this->Internals->Compositor->SetCommunicator(comm);
// build compositing program and set up the screen space decomp
// with guard pixels
int iErr = 0;
iErr = this->Internals->Compositor->BuildProgram((float*)pVecPBO);
if (iErr)
{
vtkErrorMacro("Failed to construct program, reason " << iErr);
}
// composite vectors
vtkTextureObject *compositeVectors = this->Internals->CompositeVectorImage;
iErr = this->Internals->Compositor->Gather(
pVecPBO,
VTK_FLOAT,
4,
compositeVectors);
if (iErr)
{
vtkErrorMacro("Failed to composite vectors, reason " << iErr);
}
// composite mask vectors
vtkTextureObject *compositeMaskVectors = this->Internals->CompositeMaskVectorImage;
vtkPixelBufferObject *maskVecPBO = this->Internals->MaskVectorImage->Download();
void *pMaskVecPBO = maskVecPBO->MapPackedBuffer();
iErr = this->Internals->Compositor->Gather(
pMaskVecPBO,
VTK_FLOAT,
4,
compositeMaskVectors);
if (iErr)
{
vtkErrorMacro("Failed to composite mask vectors, reason " << iErr);
}
maskVecPBO->UnmapPackedBuffer();
maskVecPBO->Delete();
// restore the default communicator
this->Internals->Compositor->RestoreDefaultCommunicator();
#if vtkSurfaceLICMapperDEBUG >= 2
vtkTextureIO::Write(
mpifn(comm,"slicp_new_vector_image.vtm"),
this->Internals->CompositeVectorImage,
this->Internals->Compositor->GetDisjointGuardExtents());
vtkTextureIO::Write(
mpifn(comm,"slicp_new_mask_vector_image.vtm"),
this->Internals->CompositeMaskVectorImage,
this->Internals->Compositor->GetDisjointGuardExtents());
#endif
}
else
{
// serial run
// make the decomposition disjoint and add guard pixels
this->Internals->Compositor->InitializeCompositeExtents((float*)pVecPBO);
// use the lic decomp from here on out, in serial we have this
// flexibility because we don't need to worry about ordered compositing
// or IceT's scissor boxes
this->Internals->BlockExts
= this->Internals->Compositor->GetCompositeExtents();
// pass through without compositing
this->Internals->CompositeVectorImage = this->Internals->VectorImage;
this->Internals->CompositeMaskVectorImage = this->Internals->MaskVectorImage;
}
vecPBO->UnmapPackedBuffer();
vecPBO->Delete();
#ifdef vtkSurfaceLICMapperTIME
this->EndTimerEvent("vtkSurfaceLICMapper::GatherVectors");
#endif
}
// ------------------------------------------- LIC on screen
if ( this->NeedToComputeLIC() )
{
#if vtkSurfaceLICMapperDEBUG >= 2
ostringstream oss;
if ( this->GenerateNoiseTexture )
{
const char *noiseType[3]={"unif","gauss","perl"};
oss
<< "slicp_noise_"
<< noiseType[this->NoiseType]
<< "_size_" << this->NoiseTextureSize
<< "_grain_" << this->NoiseGrainSize
<< "_minval_" << this->MinNoiseValue
<< "_maxval_" << this->MaxNoiseValue
<< "_nlevels_" << this->NumberOfNoiseLevels
<< "_impulseprob_" << this->ImpulseNoiseProbability
<< "_impulseprob_" << this->ImpulseNoiseBackgroundValue
<< ".vtk";
}
else
{
oss << "slicp_noise_default.vtk";
}
vtkTextureIO::Write(
mpifn(comm, oss.str().c_str()),
this->Internals->NoiseImage);
#endif
#ifdef vtkSurfaceLICMapperTIME
this->StartTimerEvent("vtkSurfaceLICMapper::ComputeLIC");
#endif
// TODO -- this means that the steps size is a function
// of aspect ratio which is pretty insane...
// convert from window units to texture units
// this isn't correct since there's no way to account
// for anisotropy in the trasnform to texture space
double tcScale[2] = {
1.0/this->Internals->Viewsize[0],
1.0/this->Internals->Viewsize[1]};
double stepSize
= this->StepSize*sqrt(tcScale[0]*tcScale[0]+tcScale[1]*tcScale[1]);
stepSize = stepSize <= 0.0 ? 1.0e-10 : stepSize;
// configure image lic
vtkLineIntegralConvolution2D *LICer = this->Internals->LICer;
LICer->SetStepSize(stepSize);
LICer->SetNumberOfSteps(this->NumberOfSteps);
LICer->SetEnhancedLIC(this->EnhancedLIC);
switch (this->EnhanceContrast)
{
case ENHANCE_CONTRAST_LIC:
case ENHANCE_CONTRAST_BOTH:
LICer->SetEnhanceContrast(vtkLIC2D::ENHANCE_CONTRAST_ON);
break;
default:
LICer->SetEnhanceContrast(vtkLIC2D::ENHANCE_CONTRAST_OFF);
}
LICer->SetLowContrastEnhancementFactor(this->LowLICContrastEnhancementFactor);
LICer->SetHighContrastEnhancementFactor(this->HighLICContrastEnhancementFactor);
LICer->SetAntiAlias(this->AntiAlias);
LICer->SetComponentIds(0, 1);
LICer->SetNormalizeVectors(this->NormalizeVectors);
LICer->SetMaskThreshold(this->MaskThreshold);
LICer->SetCommunicator(comm);
// loop over composited extents
const deque<vtkPixelExtent> &compositeExts
= this->Internals->Compositor->GetCompositeExtents();
const deque<vtkPixelExtent> &disjointGuardExts
= this->Internals->Compositor->GetDisjointGuardExtents();
this->Internals->LICImage.TakeReference(
LICer->Execute(
viewExt, // screen extent
disjointGuardExts, // disjoint extent of valid vectors
compositeExts, // disjoint extent where lic is needed
this->Internals->CompositeVectorImage,
this->Internals->CompositeMaskVectorImage,
this->Internals->NoiseImage));
if (!this->Internals->LICImage)
{
vtkErrorMacro("Failed to compute image LIC");
return;
}
#ifdef vtkSurfaceLICMapperTIME
this->EndTimerEvent("vtkSurfaceLICMapper::ComputeLIC");
#endif
#if vtkSurfaceLICMapperDEBUG >= 2
vtkTextureIO::Write(
mpifn(comm,"slicp_lic.vtm"),
this->Internals->LICImage,
compositeExts);
#endif
// ------------------------------------------- move from LIC decomp back to geometry decomp
if ( comm->GetMPIInitialized()
&& (this->Internals->Compositor->GetStrategy()!=COMPOSITE_INPLACE ) )
{
#ifdef vtkSurfaceLICMapperTIME
this->StartTimerEvent("vtkSurfaceLICMapper::ScatterLIC");
#endif
// parallel run
// need to use the communicator provided by the rendering engine
this->Internals->Compositor->SetCommunicator(comm);
vtkPixelBufferObject *licPBO = this->Internals->LICImage->Download();
void *pLicPBO = licPBO->MapPackedBuffer();
vtkTextureObject *newLicImage = NULL;
int iErr = this->Internals->Compositor->Scatter(pLicPBO, VTK_FLOAT, 4, newLicImage);
if (iErr)
{
vtkErrorMacro("Failed to scatter lic");
}
licPBO->UnmapPackedBuffer();
licPBO->Delete();
this->Internals->LICImage = NULL;
this->Internals->LICImage = newLicImage;
newLicImage->Delete();
// restore the default communicator
this->Internals->Compositor->RestoreDefaultCommunicator();
#ifdef vtkSurfaceLICMapperTIME
this->EndTimerEvent("vtkSurfaceLICMapper::ScatterLIC");
#endif
#if vtkSurfaceLICMapperDEBUG >= 2
vtkTextureIO::Write(
mpifn(comm,"slicp_new_lic.vtm"),
this->Internals->LICImage,
this->Internals->BlockExts);
#endif
}
}
// ------------------------------------------- combine scalar colors + LIC
if ( this->NeedToColorLIC() )
{
#ifdef vtkSurfaceLICMapperTIME
this->StartTimerEvent("vtkSurfaceLICMapper::ColorLIC");
#endif
vtkFrameBufferObject2 *fbo = this->Internals->FBO;
fbo->SaveCurrentBindings();
fbo->Bind(GL_FRAMEBUFFER);
fbo->InitializeViewport(this->Internals->Viewsize[0], this->Internals->Viewsize[1]);
fbo->AddColorAttachment(GL_DRAW_FRAMEBUFFER, 0U, this->Internals->RGBColorImage);
fbo->AddColorAttachment(GL_DRAW_FRAMEBUFFER, 1U, this->Internals->HSLColorImage);
fbo->ActivateDrawBuffers(2U);
vtkCheckFrameBufferStatusMacro(GL_FRAMEBUFFER);
#if 0
glDisable(GL_SCISSOR_TEST);
glClearColor(0.0, 0.0, 0.0, 0.0);
glClear(GL_COLOR_BUFFER_BIT);
#else
// clear the parts of the screen which we will modify
glEnable(GL_SCISSOR_TEST);
glClearColor(0.0, 0.0, 0.0, 0.0);
size_t nBlocks = this->Internals->BlockExts.size();
for (size_t e=0; e<nBlocks; ++e)
{
vtkPixelExtent ext = this->Internals->BlockExts[e];
ext.Grow(2); // halo for linear filtering
ext &= viewExt;
unsigned int extSize[2];
ext.Size(extSize);
glScissor(ext[0], ext[2], extSize[0], extSize[1]);
glClear(GL_COLOR_BUFFER_BIT);
}
glDisable(GL_SCISSOR_TEST);
#endif
this->Internals->VectorImage->Activate();
this->Internals->GeometryImage->Activate();
this->Internals->LICImage->Activate();
vtkShaderProgram *colorPass = this->Internals->ColorPass->Program;
renWin->GetShaderCache()->ReadyShaderProgram(colorPass);
colorPass->SetUniformi("texVectors",
this->Internals->VectorImage->GetTextureUnit());
colorPass->SetUniformi("texGeomColors",
this->Internals->GeometryImage->GetTextureUnit());
colorPass->SetUniformi("texLIC",
this->Internals->LICImage->GetTextureUnit());
colorPass->SetUniformi("uScalarColorMode", this->ColorMode);
colorPass->SetUniformf("uLICIntensity", this->LICIntensity);
colorPass->SetUniformf("uMapBias", this->MapModeBias);
colorPass->SetUniformf("uMaskIntensity", this->MaskIntensity);
float fMaskColor[3];
fMaskColor[0] = this->MaskColor[0];
fMaskColor[1] = this->MaskColor[1];
fMaskColor[2] = this->MaskColor[2];
colorPass->SetUniform3f("uMaskColor", fMaskColor);
for (size_t e=0; e<nBlocks; ++e)
{
this->Internals->RenderQuad(viewExt, this->Internals->BlockExts[e],
this->Internals->ColorPass);
}
this->Internals->VectorImage->Deactivate();
this->Internals->GeometryImage->Deactivate();
this->Internals->LICImage->Deactivate();
#ifdef vtkSurfaceLICMapperTIME
this->EndTimerEvent("vtkSurfaceLICMapper::ColorLIC");
#endif
// --------------------------------------------- color contrast enhance
if ( ( this->EnhanceContrast == ENHANCE_CONTRAST_COLOR )
|| ( this->EnhanceContrast == ENHANCE_CONTRAST_BOTH ) )
{
#if vtkSurfaceLICMapperDEBUG >= 2
vtkTextureIO::Write(
mpifn(comm,"slic_color_rgb_in.vtm"),
this->Internals->RGBColorImage,
this->Internals->BlockExts);
vtkTextureIO::Write(
mpifn(comm,"slic_color_hsl_in.vtm"),
this->Internals->HSLColorImage,
this->Internals->BlockExts);
#endif
#ifdef vtkSurfaceLICMapperTIME
this->StartTimerEvent("vtkSurfaceLICMapper::ContrastEnhance");
#endif
// find min/max lighness value for color contrast enhancement.
float LMin = VTK_FLOAT_MAX;
float LMax = -VTK_FLOAT_MAX;
float LMaxMinDiff = VTK_FLOAT_MAX;
#ifdef STREAMING_MIN_MAX
StreamingFindMinMax(fbo, this->Internals->BlockExts, LMin, LMax);
#else
FindMinMax(
this->Internals->HSLColorImage,
this->Internals->BlockExts,
LMin,
LMax);
#endif
if ( this->Internals->BlockExts.size()
&& ((LMax <= LMin) || (LMin < 0.0f) || (LMax > 1.0f)) )
{
vtkErrorMacro(
<< comm->GetRank()
<< ": Invalid range " << LMin << ", " << LMax
<< " for color contrast enhancement");
LMin = 0.0;
LMax = 1.0;
LMaxMinDiff = 1.0;
}
// global collective reduction for parallel operation
this->GetGlobalMinMax(comm, LMin, LMax);
// set M and m as a fraction of the range.
LMaxMinDiff = LMax-LMin;
LMin += LMaxMinDiff*this->LowColorContrastEnhancementFactor;
LMax -= LMaxMinDiff*this->HighColorContrastEnhancementFactor;
LMaxMinDiff = LMax-LMin;
// normalize shader
fbo->AddColorAttachment(GL_DRAW_FRAMEBUFFER, 0U, this->Internals->RGBColorImage);
fbo->ActivateDrawBuffer(0U);
vtkCheckFrameBufferStatusMacro(GL_DRAW_FRAMEBUFFER);
this->Internals->GeometryImage->Activate();
this->Internals->HSLColorImage->Activate();
this->Internals->LICImage->Activate();
vtkShaderProgram *colorEnhancePass =
this->Internals->ColorEnhancePass->Program;
renWin->GetShaderCache()->ReadyShaderProgram(colorEnhancePass);
colorEnhancePass->SetUniformi("texGeomColors",
this->Internals->GeometryImage->GetTextureUnit());
colorEnhancePass->SetUniformi("texHSLColors",
this->Internals->HSLColorImage->GetTextureUnit());
colorEnhancePass->SetUniformi("texLIC",
this->Internals->LICImage->GetTextureUnit());
colorEnhancePass->SetUniformf("uLMin", LMin);
colorEnhancePass->SetUniformf("uLMaxMinDiff", LMaxMinDiff);
for (size_t e=0; e<nBlocks; ++e)
{
this->Internals->RenderQuad(viewExt, this->Internals->BlockExts[e],
this->Internals->ColorEnhancePass);
}
this->Internals->GeometryImage->Deactivate();
this->Internals->HSLColorImage->Deactivate();
this->Internals->LICImage->Deactivate();
fbo->RemoveTexColorAttachment(GL_DRAW_FRAMEBUFFER, 0U);
fbo->DeactivateDrawBuffers();
#ifdef vtkSurfaceLICMapperTIME
this->EndTimerEvent("vtkSurfaceLICMapper::ContrastEnhance");
#endif
}
else
{
fbo->RemoveTexColorAttachment(GL_DRAW_FRAMEBUFFER, 0U);
fbo->RemoveTexColorAttachment(GL_DRAW_FRAMEBUFFER, 1U);
fbo->DeactivateDrawBuffers();
}
fbo->UnBind(GL_FRAMEBUFFER);
#if vtkSurfaceLICMapperDEBUG >= 2
vtkTextureIO::Write(
mpifn(comm,"slicp_new_rgb.vtm"),
this->Internals->RGBColorImage,
this->Internals->BlockExts);
#endif
}
// ----------------------------------------------- depth test and copy to screen
#ifdef vtkSurfaceLICMapperTIME
this->StartTimerEvent("vtkSurfaceLICMapper::DepthCopy");
#endif
glBindFramebuffer(GL_FRAMEBUFFER, prevFbo);
glDrawBuffer(prevDrawBuf);
vtkFrameBufferObject2::InitializeViewport(
this->Internals->Viewsize[0],
this->Internals->Viewsize[1]);
glEnable(GL_DEPTH_TEST);
this->Internals->DepthImage->Activate();
this->Internals->RGBColorImage->Activate();
vtkShaderProgram *copyPass =
this->Internals->CopyPass->Program;
renWin->GetShaderCache()->ReadyShaderProgram(copyPass);
copyPass->SetUniformi("texDepth",
this->Internals->DepthImage->GetTextureUnit());
copyPass->SetUniformi("texRGBColors",
this->Internals->RGBColorImage->GetTextureUnit());
size_t nBlocks = this->Internals->BlockExts.size();
for (size_t e=0; e<nBlocks; ++e)
{
this->Internals->RenderQuad(viewExt, this->Internals->BlockExts[e],
this->Internals->CopyPass);
}
this->Internals->DepthImage->Deactivate();
this->Internals->RGBColorImage->Deactivate();
#ifdef vtkSurfaceLICMapperTIME
this->EndTimerEvent("vtkSurfaceLICMapper::DepthCopy");
#endif
//
this->Internals->Updated();
// clear opengl error flags and be absolutely certain that nothing failed.
vtkOpenGLCheckErrorMacro("failed during surface lic painter");
#ifdef vtkSurfaceLICMapperTIME
this->EndTimerEvent("vtkSurfaceLICMapper::RenderInternal");
#else
timer->StopTimer();
#endif
}
//-----------------------------------------------------------------------------
void vtkSurfaceLICMapper::ReportReferences(vtkGarbageCollector *collector)
{
this->Superclass::ReportReferences(collector);
vtkGarbageCollectorReport(collector, this->Output, "Output PolyData");
}
//----------------------------------------------------------------------------
vtkDataObject* vtkSurfaceLICMapper::GetOutput()
{
#if vtkSurfaceLICMapperDEBUG >= 1
cerr << "=====vtkSurfaceLICMapper::GetOutput" << endl;
#endif
if (this->Enable && this->Output)
{
return this->Output;
}
return this->GetInput();
}
//----------------------------------------------------------------------------
bool vtkSurfaceLICMapper::PrepareOutput()
{
vtkDataObject* input = this->GetInput();
if ((input == NULL) || !this->Enable)
{
if (this->Output)
{
this->Output->Delete();
this->Output = NULL;
this->Internals->HasVectors = false;
}
return false;
}
if (this->Internals->OutputDataNeedsUpdate)
{
if (this->Output)
{
this->Output->Delete();
this->Output = NULL;
}
this->Output = input->NewInstance();
this->Output->ShallowCopy(input);
this->Internals->HasVectors = false;
}
if (!this->Internals->HasVectors)
{
this->Internals->HasVectors = this->VectorsToTCoords(this->Output);
}
return this->Internals->HasVectors;
}
//----------------------------------------------------------------------------
bool vtkSurfaceLICMapper::VectorsToTCoords(vtkDataObject *dataObj)
{
bool hasVectors = false;
vtkCompositeDataSet *cd = vtkCompositeDataSet::SafeDownCast(dataObj);
if (cd)
{
vtkCompositeDataIterator* iter = cd->NewIterator();
for (iter->InitTraversal(); !iter->IsDoneWithTraversal(); iter->GoToNextItem())
{
vtkDataSet* ds = vtkDataSet::SafeDownCast(iter->GetCurrentDataObject());
if (ds && ds->GetNumberOfCells())
{
this->ClearTCoords(ds);
hasVectors |= this->VectorsToTCoords(ds);
}
}
iter->Delete();
return hasVectors;
}
vtkDataSet* ds = vtkDataSet::SafeDownCast(dataObj);
if (ds && ds->GetNumberOfCells())
{
this->ClearTCoords(ds);
hasVectors |= this->VectorsToTCoords(ds);
}
if ( hasVectors )
{
// force downstream updates (display lists, etc)
this->Output->Modified();
}
return hasVectors;
}
//----------------------------------------------------------------------------
bool vtkSurfaceLICMapper::VectorsToTCoords(vtkDataSet *data)
{
// don't use SafeDownCast here for rendering performance
vtkDataArray *vectors = NULL;
vectors = this->GetInputArrayToProcess(0, data);
if ( vectors == NULL )
{
return false;
}
vtkDataSetAttributes *atts = NULL;
atts = data->GetPointData();
int nArrays = atts->GetNumberOfArrays();
for (int i=0; i<nArrays; ++i)
{
if ( atts->GetArray(i) == vectors )
{
atts->SetActiveAttribute(i, vtkDataSetAttributes::TCOORDS);
return true;
}
}
atts = data->GetCellData();
nArrays = atts->GetNumberOfArrays();
for (int i=0; i<nArrays; ++i)
{
if ( atts->GetArray(i) == vectors )
{
atts->SetActiveAttribute(i, vtkDataSetAttributes::TCOORDS);
return true;
}
}
return false;
}
//----------------------------------------------------------------------------
void vtkSurfaceLICMapper::ClearTCoords(vtkDataSet *data)
{
data->GetCellData()->SetActiveAttribute(-1, vtkDataSetAttributes::TCOORDS);
data->GetPointData()->SetActiveAttribute(-1, vtkDataSetAttributes::TCOORDS);
}
//----------------------------------------------------------------------------
void vtkSurfaceLICMapper::PrintSelf(ostream & os, vtkIndent indent)
{
this->Superclass::PrintSelf(os, indent);
os
<< indent << "NumberOfSteps=" << this->NumberOfSteps << endl
<< indent << "StepSize=" << this->StepSize << endl
<< indent << "NormalizeVectors=" << this->NormalizeVectors << endl
<< indent << "EnhancedLIC=" << this->EnhancedLIC << endl
<< indent << "EnhanceContrast=" << this->EnhanceContrast << endl
<< indent << "LowLICContrastEnhancementFactor=" << this->LowLICContrastEnhancementFactor << endl
<< indent << "HighLICContrastEnhancementFactor=" << this->HighLICContrastEnhancementFactor << endl
<< indent << "LowColorContrastEnhancementFactor=" << this->LowColorContrastEnhancementFactor << endl
<< indent << "HighColorContrastEnhancementFactor=" << this->HighColorContrastEnhancementFactor << endl
<< indent << "AntiAlias=" << this->AntiAlias << endl
<< indent << "MaskOnSurface=" << this->MaskOnSurface << endl
<< indent << "MaskThreshold=" << this->MaskThreshold << endl
<< indent << "MaskIntensity=" << this->MaskIntensity << endl
<< indent << "MaskColor=" << this->MaskColor[0] << ", " << this->MaskColor[1] << ", " << this->MaskColor[2] << endl
<< indent << "ColorMode=" << this->ColorMode << endl
<< indent << "LICIntensity=" << this->LICIntensity << endl
<< indent << "MapModeBias=" << this->MapModeBias << endl
<< indent << "GenerateNoiseTexture=" << this->GenerateNoiseTexture << endl
<< indent << "NoiseType=" << this->NoiseType << endl
<< indent << "NoiseTextureSize=" << this->NoiseTextureSize << endl
<< indent << "NoiseGrainSize=" << this->NoiseGrainSize << endl
<< indent << "MinNoiseValue=" << this->MinNoiseValue << endl
<< indent << "MaxNoiseValue=" << this->MaxNoiseValue << endl
<< indent << "NumberOfNoiseLevels=" << this->NumberOfNoiseLevels << endl
<< indent << "ImpulseNoiseProbablity=" << this->ImpulseNoiseProbability << endl
<< indent << "ImpulseNoiseBackgroundValue=" << this->ImpulseNoiseBackgroundValue << endl
<< indent << "NoiseGeneratorSeed=" << this->NoiseGeneratorSeed << endl
<< indent << "AlwaysUpdate=" << this->AlwaysUpdate << endl
<< indent << "Enable=" << this->Enable << endl
<< indent << "CompositeStrategy=" << this->CompositeStrategy << endl;
}
|