1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107 2108 2109 2110 2111 2112 2113 2114 2115 2116 2117 2118 2119 2120 2121 2122 2123 2124 2125 2126 2127 2128 2129 2130 2131 2132 2133 2134 2135 2136 2137 2138 2139 2140 2141 2142 2143 2144 2145 2146 2147 2148 2149 2150 2151 2152 2153 2154 2155 2156 2157 2158 2159 2160 2161 2162 2163 2164 2165 2166 2167 2168 2169 2170 2171 2172 2173 2174 2175 2176 2177 2178 2179 2180 2181 2182 2183 2184 2185 2186 2187 2188 2189 2190 2191 2192 2193 2194 2195 2196 2197 2198 2199 2200 2201 2202 2203 2204 2205 2206 2207 2208 2209 2210 2211 2212 2213 2214 2215 2216 2217 2218 2219 2220 2221 2222 2223 2224 2225 2226 2227 2228 2229 2230 2231 2232 2233 2234 2235 2236 2237 2238 2239 2240 2241 2242 2243 2244 2245 2246 2247 2248 2249 2250 2251 2252 2253 2254 2255 2256 2257 2258 2259 2260 2261 2262 2263 2264 2265 2266 2267 2268 2269 2270 2271 2272 2273 2274 2275 2276 2277 2278 2279 2280 2281 2282 2283 2284 2285 2286 2287 2288 2289 2290 2291 2292 2293 2294 2295 2296 2297 2298 2299 2300 2301 2302 2303 2304 2305 2306 2307 2308 2309 2310 2311 2312 2313 2314 2315 2316 2317 2318 2319 2320 2321 2322 2323 2324 2325 2326 2327 2328 2329 2330 2331 2332 2333 2334 2335 2336 2337 2338 2339 2340 2341 2342 2343 2344 2345 2346 2347 2348 2349 2350 2351 2352 2353 2354 2355 2356 2357 2358 2359 2360 2361 2362 2363 2364 2365 2366 2367 2368 2369 2370 2371 2372 2373 2374 2375 2376 2377 2378 2379 2380 2381 2382 2383 2384 2385 2386 2387 2388 2389 2390 2391 2392 2393 2394 2395 2396 2397 2398 2399 2400 2401 2402 2403 2404 2405 2406 2407 2408 2409 2410 2411 2412 2413 2414 2415 2416 2417 2418 2419 2420 2421 2422 2423 2424 2425 2426 2427 2428 2429 2430 2431 2432 2433 2434 2435 2436 2437 2438 2439 2440 2441 2442 2443 2444 2445 2446 2447 2448 2449 2450 2451 2452 2453 2454 2455 2456 2457 2458 2459 2460 2461 2462 2463 2464 2465 2466 2467 2468 2469 2470 2471 2472 2473 2474 2475 2476 2477 2478 2479 2480 2481 2482 2483 2484 2485 2486 2487 2488 2489 2490 2491 2492 2493 2494 2495 2496 2497 2498 2499 2500 2501 2502 2503 2504 2505 2506 2507 2508 2509 2510 2511 2512 2513 2514 2515 2516 2517 2518 2519 2520 2521 2522 2523 2524 2525 2526 2527 2528 2529 2530 2531 2532 2533 2534 2535 2536 2537 2538 2539 2540 2541 2542 2543 2544 2545 2546 2547 2548 2549 2550 2551 2552 2553 2554 2555 2556 2557 2558 2559 2560 2561 2562 2563 2564 2565 2566 2567 2568 2569 2570 2571 2572 2573 2574 2575 2576 2577 2578 2579 2580 2581 2582 2583 2584 2585 2586 2587 2588 2589 2590 2591 2592 2593 2594 2595 2596 2597 2598 2599 2600 2601 2602 2603 2604 2605 2606 2607 2608 2609 2610 2611 2612 2613 2614 2615 2616 2617 2618 2619 2620 2621 2622 2623 2624 2625 2626 2627 2628 2629 2630 2631 2632 2633 2634 2635 2636 2637 2638 2639 2640 2641 2642 2643 2644 2645 2646 2647 2648 2649 2650 2651 2652 2653 2654 2655 2656 2657 2658 2659 2660 2661 2662 2663 2664 2665 2666 2667 2668 2669 2670 2671 2672 2673 2674 2675 2676 2677 2678 2679 2680 2681 2682 2683 2684 2685 2686 2687 2688 2689 2690 2691 2692 2693 2694 2695 2696 2697 2698 2699 2700 2701 2702 2703 2704 2705 2706 2707 2708 2709 2710 2711 2712 2713 2714 2715 2716 2717 2718 2719 2720 2721 2722 2723 2724 2725 2726 2727 2728 2729 2730 2731 2732 2733 2734 2735 2736 2737 2738 2739 2740 2741 2742 2743 2744 2745 2746 2747 2748 2749 2750 2751 2752 2753 2754 2755 2756 2757 2758 2759 2760 2761 2762 2763 2764 2765 2766 2767 2768 2769 2770 2771 2772 2773 2774 2775 2776 2777 2778 2779 2780 2781 2782 2783 2784 2785 2786 2787 2788 2789 2790 2791 2792 2793 2794 2795 2796 2797 2798 2799 2800 2801 2802 2803 2804 2805 2806 2807 2808 2809 2810 2811 2812 2813 2814 2815 2816 2817 2818 2819 2820 2821 2822 2823 2824 2825 2826 2827 2828 2829 2830 2831 2832 2833 2834 2835 2836 2837 2838 2839 2840 2841 2842 2843 2844 2845 2846 2847 2848 2849 2850 2851 2852 2853 2854 2855 2856 2857 2858 2859 2860 2861 2862 2863 2864 2865 2866 2867 2868 2869 2870 2871 2872 2873 2874 2875 2876 2877 2878 2879 2880 2881 2882 2883 2884 2885 2886 2887 2888 2889 2890 2891 2892 2893 2894 2895 2896 2897 2898 2899 2900 2901 2902 2903 2904 2905 2906 2907 2908 2909 2910 2911 2912 2913 2914 2915 2916 2917 2918 2919 2920 2921 2922 2923 2924 2925 2926 2927 2928 2929 2930 2931 2932 2933 2934 2935 2936 2937 2938 2939 2940 2941 2942 2943 2944 2945 2946 2947 2948 2949 2950 2951 2952 2953 2954 2955 2956 2957 2958 2959 2960 2961 2962 2963 2964 2965 2966 2967 2968 2969 2970 2971 2972 2973 2974 2975 2976 2977 2978 2979 2980 2981 2982 2983 2984 2985 2986 2987 2988 2989 2990 2991 2992 2993 2994 2995 2996 2997 2998 2999 3000 3001 3002 3003 3004 3005 3006 3007 3008 3009 3010 3011 3012 3013 3014 3015 3016 3017 3018 3019 3020 3021 3022 3023 3024 3025 3026 3027 3028 3029 3030 3031 3032 3033 3034 3035 3036 3037 3038 3039 3040 3041 3042 3043 3044 3045 3046 3047 3048 3049 3050 3051 3052 3053 3054 3055 3056 3057 3058 3059 3060 3061 3062 3063 3064 3065 3066 3067 3068 3069 3070 3071 3072 3073 3074 3075 3076 3077 3078 3079 3080 3081 3082 3083 3084 3085 3086 3087 3088 3089 3090 3091 3092 3093 3094 3095 3096 3097 3098 3099 3100 3101 3102 3103 3104 3105 3106 3107 3108 3109 3110 3111 3112 3113 3114 3115 3116 3117 3118 3119 3120 3121 3122 3123 3124 3125 3126 3127 3128 3129 3130 3131 3132 3133 3134 3135 3136 3137 3138 3139 3140 3141 3142 3143 3144 3145 3146 3147 3148 3149 3150 3151 3152 3153 3154 3155 3156 3157 3158 3159 3160 3161 3162 3163 3164 3165 3166 3167 3168 3169 3170 3171 3172 3173 3174 3175 3176 3177 3178 3179 3180 3181 3182 3183 3184 3185 3186 3187 3188 3189 3190 3191 3192 3193 3194 3195 3196 3197 3198 3199 3200 3201 3202 3203 3204 3205 3206 3207 3208 3209 3210 3211 3212 3213 3214 3215 3216 3217 3218 3219 3220 3221 3222 3223 3224 3225 3226 3227 3228 3229 3230 3231 3232 3233 3234 3235 3236 3237 3238 3239 3240 3241 3242 3243 3244 3245 3246 3247 3248 3249 3250 3251 3252 3253 3254 3255 3256 3257 3258 3259 3260 3261 3262 3263 3264 3265 3266 3267 3268 3269 3270 3271 3272 3273 3274 3275 3276 3277 3278 3279 3280 3281 3282 3283 3284 3285 3286 3287 3288 3289 3290 3291 3292 3293 3294 3295 3296 3297 3298 3299 3300 3301 3302 3303 3304 3305 3306 3307 3308 3309 3310 3311 3312 3313 3314 3315 3316 3317 3318 3319 3320 3321 3322 3323 3324 3325 3326 3327 3328 3329 3330 3331 3332 3333 3334 3335 3336 3337 3338 3339 3340 3341 3342 3343 3344 3345 3346 3347 3348 3349 3350 3351 3352 3353 3354 3355 3356 3357 3358 3359 3360 3361 3362 3363 3364 3365 3366 3367 3368 3369 3370 3371 3372 3373 3374 3375 3376 3377 3378 3379 3380 3381 3382 3383 3384 3385 3386 3387 3388 3389 3390 3391 3392 3393 3394 3395 3396 3397 3398 3399 3400 3401 3402 3403 3404 3405 3406 3407 3408 3409 3410 3411 3412 3413 3414 3415 3416 3417 3418 3419 3420 3421 3422 3423 3424 3425 3426 3427 3428 3429 3430 3431 3432 3433 3434 3435 3436 3437 3438 3439 3440 3441 3442 3443 3444 3445 3446 3447 3448 3449 3450 3451 3452 3453 3454 3455 3456 3457 3458 3459 3460 3461 3462 3463 3464 3465 3466 3467 3468 3469 3470 3471 3472 3473 3474 3475 3476 3477 3478 3479 3480 3481 3482 3483 3484 3485 3486 3487 3488 3489 3490 3491 3492 3493 3494 3495 3496 3497 3498 3499 3500 3501 3502 3503 3504 3505 3506 3507 3508 3509 3510 3511 3512 3513 3514 3515 3516 3517 3518 3519 3520 3521 3522 3523 3524 3525 3526 3527 3528 3529 3530 3531 3532 3533 3534 3535 3536 3537 3538 3539 3540 3541 3542 3543 3544 3545 3546 3547 3548 3549 3550 3551 3552 3553 3554 3555 3556 3557 3558 3559 3560 3561 3562 3563 3564 3565 3566 3567 3568 3569 3570 3571 3572 3573 3574 3575 3576 3577 3578 3579 3580 3581 3582 3583 3584 3585 3586 3587 3588 3589 3590 3591 3592 3593 3594 3595 3596 3597 3598 3599 3600 3601 3602 3603 3604 3605 3606 3607 3608 3609 3610 3611 3612 3613 3614 3615 3616 3617 3618 3619 3620 3621 3622 3623 3624 3625 3626 3627 3628 3629 3630 3631 3632 3633 3634 3635 3636 3637 3638 3639 3640 3641 3642 3643 3644 3645 3646 3647 3648
  
     | 
    
      /*=========================================================================
  Copyright (c) Kitware, Inc.
  All rights reserved.
  See Copyright.txt or http://www.kitware.com/VolViewCopyright.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 "vtkVVPlugin.h"
#include "vtkCellArray.h"
#include "vtkDynamicLoader.h"
#include "vtkDoubleArray.h"
#include "vtkDataObject.h"
#include "vtkDataObjectCollection.h"
#include "vtkFieldData.h"
#include "vtkFloatArray.h"
#include "vtkImageData.h"
#include "vtkImageImport.h"
#include "vtkMetaImageWriter.h"
#include "vtkKWApplication.h"
#include "vtkKWCheckButton.h"
#include "vtkKWFrameWithLabel.h"
#include "vtkKWIcon.h"
#include "vtkKWLabel.h"
#include "vtkKWLabelWithLabel.h"
#include "vtkKWMenu.h"
#include "vtkKWMenuButton.h"
#include "vtkKWMessageDialog.h"
#include "vtkKWProcessStatistics.h"
#include "vtkKWProgressGauge.h"
#include "vtkKWPushButton.h"
#include "vtkKWScaleWithEntry.h"
#include "vtkKWXYPlotDialog.h"
#include "vtkUnstructuredGrid.h"
#include "vtkUnstructuredGridReader.h"
#include "vtkLargeInteger.h"
#include "vtkObjectFactory.h"
#include "vtkPointData.h"
#include "vtkPointSet.h"
#include "vtkPoints.h"
#include "vtkPolyData.h"
#include "vtkKWLoadSaveDialog.h"
//BTX
#ifdef KWVolView_PLUGINS_USE_SPLINE
#include "vtkKW3DSplineSurfacesWidget.h"
#include "vtkSubdivisionSplineSurfaceWidget.h"
#include "vtkSplineSurfaceWidget.h"
#endif
//ETX
#include "vtkXYPlotActor.h"
#include "vtkVVPluginSelector.h"
#include "vtkKWOpenWizard.h"
#include "vtkKWOpenFileHelper.h"
#include "vtkKWOpenFileProperties.h"
#include "vtkKWImageWidget.h"
//BTX
#ifdef KWVolView_PLUGINS_USE_SERIES
#include "vtkVV4DOpenWizard.h"
#include "vtkVV4DSaveDialog.h"
#include "vtkVV4DSaveVolume.h"
#endif
//ETX
#include "vtkKWVolumeWidget.h"
#include "vtkVVWindow.h"
#include "vtkVVDataItemVolume.h"
#include "vtkVVHandleWidget.h"
#include "vtkVVWidgetInterface.h"
#include "vtkVVInteractorWidgetSelector.h"
#include "vtkVVSelectionFrame.h"
#include "vtkKWEPaintbrushWidget.h"
#include "vtkKWEPaintbrushRepresentation2D.h"
#include "vtkKWEPaintbrushDrawing.h"
#include "vtkKWEPaintbrushLabelData.h"
#include "vtkVolumeProperty.h"
#include "vtkVVSelectionFrameLayoutManager.h"
#include <vtksys/SystemTools.hxx>
#include <vtkstd/string>
#include <time.h>
/* this is the data structure describing one GUI element. */
class  vtkVVGUIItem 
{
public:
  /* the label for this widget */
  char *Label; 
  /* what type of GUI item should this be, menu, slider etc */    
  int GUIType;         
  /* the initial value for the widget */
  char *Default;
  /* a help string for baloon help for this widget */
  char *Help;
  /* this string is where additional information required to setup the GUI
   * element is specified. What goes in the Hints varies depending on the
   * type of the GUI item. For a slider it is the range of the slider
   * e.g. "0 255" */
  char *Hints;
  /* this is where the current value of the GUI item will be stored */
  char *Value;
};
//----------------------------------------------------------------------------
vtkStandardNewMacro( vtkVVPlugin );
vtkCxxRevisionMacro(vtkVVPlugin, "$Revision: 1.31 $");
//----------------------------------------------------------------------------
vtkVVPlugin::vtkVVPlugin()
{
  this->DocLabel = vtkKWLabel::New();
  this->DocText = vtkKWLabelWithLabel::New();
  this->ReportText = vtkKWLabelWithLabel::New();
  this->StopWatchText = vtkKWLabelWithLabel::New();
  this->Widgets = 0;
  this->Window = 0;
  this->ProgressMinimum = 0;
  this->ProgressMaximum = 1;
  this->AbortProcessing = 0;
  
  this->Name = 0;
  this->Group = 0;
  this->TerseDocumentation = 0;
  this->FullDocumentation = 0;
  this->GUIItems = 0;
  this->SupportProcessingPieces = 0;
  this->SupportInPlaceProcessing = 0;
  this->SecondInputIsUnstructuredGrid = 0;
//BTX
#ifdef KWVolView_PLUGINS_USE_SERIES
  this->SupportProcessingSeriesByVolumes = 0;
  this->SeriesInputButton = 0;
  this->SeriesInputOpenWizard = 0;
  this->ProducesSeriesOutput  = 0;
  this->RequiresSeriesInput = 0;
#endif
#ifdef KWVolView_PLUGINS_USE_SPLINE
  this->RequiresSplineSurfaces = 0;
  this->ProducesMeshOnly = 0;
#endif
//ETX
  this->PerVoxelMemoryRequired = 0;
  this->RequiredZOverlap = 0;
  this->NumberOfGUIItems = 0;
  this->RequiresSecondInput = 0;
  this->SecondInputOptional = 0;  
  this->RequiresLabelInput = 0;
  this->SecondInputButton = 0;
  this->SecondInputOpenWizard = 0;
  this->ProducesPlottingOutput  = 0;
  this->PlottingXAxisTitle  = 0;
  this->PlottingYAxisTitle  = 0;
  int i;
  // initialize the info struct to be safe
  this->PluginInfo.magic1 = 0;
  this->PluginInfo.magic2 = 0;
  this->PluginInfo.Self = 0;
  this->PluginInfo.InputVolumeScalarType = 0; 
  this->PluginInfo.InputVolumeScalarSize = 0; 
  this->PluginInfo.InputVolumeNumberOfComponents = 0; 
  for (i = 0; i < 3; i++)
    {
    this->PluginInfo.InputVolumeDimensions[i] = 0; 
    this->PluginInfo.InputVolumeSpacing[i] = 0; 
    this->PluginInfo.InputVolumeOrigin[i] = 0; 
    }
  this->PluginInfo.InputVolumeScalarRange[0] = 0; 
  this->PluginInfo.InputVolumeScalarRange[1] = 1; 
  this->PluginInfo.InputVolumeScalarRange[2] = 0; 
  this->PluginInfo.InputVolumeScalarRange[3] = 1; 
  this->PluginInfo.InputVolumeScalarRange[4] = 0; 
  this->PluginInfo.InputVolumeScalarRange[5] = 1; 
  this->PluginInfo.InputVolumeScalarRange[6] = 0; 
  this->PluginInfo.InputVolumeScalarRange[7] = 1; 
  this->PluginInfo.InputVolumeScalarTypeRange[0] = 0; 
  this->PluginInfo.InputVolumeScalarTypeRange[1] = 1; 
  this->PluginInfo.InputVolume2ScalarType = 0; 
  this->PluginInfo.InputVolume2ScalarSize = 0; 
  this->PluginInfo.InputVolume2NumberOfComponents = 0; 
  for (i = 0; i < 3; i++)
    {
    this->PluginInfo.InputVolume2Dimensions[i] = 0; 
    this->PluginInfo.InputVolume2Spacing[i] = 0; 
    this->PluginInfo.InputVolume2Origin[i] = 0; 
    }
  this->PluginInfo.InputVolume2ScalarRange[0] = 0; 
  this->PluginInfo.InputVolume2ScalarRange[1] = 1; 
  this->PluginInfo.InputVolume2ScalarRange[2] = 0; 
  this->PluginInfo.InputVolume2ScalarRange[3] = 1; 
  this->PluginInfo.InputVolume2ScalarRange[4] = 0; 
  this->PluginInfo.InputVolume2ScalarRange[5] = 1; 
  this->PluginInfo.InputVolume2ScalarRange[6] = 0; 
  this->PluginInfo.InputVolume2ScalarRange[7] = 1; 
  this->PluginInfo.InputVolume2ScalarTypeRange[0] = 0; 
  this->PluginInfo.InputVolume2ScalarTypeRange[1] = 1; 
//BTX
#ifdef KWVolView_PLUGINS_USE_SERIES
  this->PluginInfo.InputVolumeSeriesNumberOfVolumes = 0; 
  this->PluginInfo.InputVolumeSeriesScalarType = 0; 
  this->PluginInfo.InputVolumeSeriesScalarSize = 0; 
  this->PluginInfo.InputVolumeSeriesNumberOfComponents = 0; 
  for (i = 0; i < 3; i++)
    {
    this->PluginInfo.InputVolumeSeriesDimensions[i] = 0; 
    this->PluginInfo.InputVolumeSeriesSpacing[i] = 0; 
    this->PluginInfo.InputVolumeSeriesOrigin[i] = 0; 
    }
  this->PluginInfo.InputVolumeSeriesScalarRange[0] = 0; 
  this->PluginInfo.InputVolumeSeriesScalarRange[1] = 1; 
  this->PluginInfo.InputVolumeSeriesScalarRange[2] = 0; 
  this->PluginInfo.InputVolumeSeriesScalarRange[3] = 1; 
  this->PluginInfo.InputVolumeSeriesScalarRange[4] = 0; 
  this->PluginInfo.InputVolumeSeriesScalarRange[5] = 1; 
  this->PluginInfo.InputVolumeSeriesScalarRange[6] = 0; 
  this->PluginInfo.InputVolumeSeriesScalarRange[7] = 1; 
  this->PluginInfo.InputVolumeSeriesScalarTypeRange[0] = 0; 
  this->PluginInfo.InputVolumeSeriesScalarTypeRange[1] = 1; 
  this->PluginInfo.OutputVolumeSeriesNumberOfVolumes = 0; 
  this->PluginInfo.OutputVolumeSeriesScalarType = 0; 
  this->PluginInfo.OutputVolumeSeriesScalarSize = 0; 
  this->PluginInfo.OutputVolumeSeriesNumberOfComponents = 0; 
  for (i = 0; i < 3; i++)
    {
    this->PluginInfo.OutputVolumeSeriesDimensions[i] = 0; 
    this->PluginInfo.OutputVolumeSeriesSpacing[i] = 0; 
    this->PluginInfo.OutputVolumeSeriesOrigin[i] = 0; 
    }
#endif
#ifdef KWVolView_PLUGINS_USE_MARKER
  this->PluginInfo.NumberOfMarkers = 0;
  this->PluginInfo.Markers = 0;
  this->PluginInfo.MarkersGroupId = 0;
  this->PluginInfo.NumberOfMarkersGroups = 0;
  this->PluginInfo.MarkersGroupName = 0;
#endif
//ETX
  this->PluginInfo.CroppingPlanes = 0;
  this->PluginInfo.OutputVolumeScalarType = 0; 
  this->PluginInfo.OutputVolumeNumberOfComponents = 0; 
  for (i = 0; i < 3; i++)
    {
    this->PluginInfo.OutputVolumeDimensions[i] = 0; 
    this->PluginInfo.OutputVolumeSpacing[i] = 0; 
    this->PluginInfo.OutputVolumeOrigin[i] = 0; 
    }
//BTX
#ifdef KWVolView_PLUGINS_USE_SPLINE
  this->PluginInfo.NumberOfSplineSurfaces = 0;
  this->PluginInfo.NumberOfSplineSurfacePoints = 0;
  this->PluginInfo.SplineSurfacePoints = 0;
#endif
//ETX
  this->PluginInfo.OutputPlottingNumberOfColumns = 0;
  this->PluginInfo.OutputPlottingNumberOfRows = 0;
  this->PluginInfo.UnstructuredGridScalarFields = 0;
  this->PluginInfo.UpdateProgress = 0;
  this->PluginInfo.AssignPolygonalData = 0;
  this->PluginInfo.SetProperty = 0;
  this->PluginInfo.GetProperty = 0;
  this->PluginInfo.SetGUIProperty = 0;
  this->PluginInfo.GetGUIProperty = 0;
  this->PluginInfo.ProcessData = 0;
  this->PluginInfo.UpdateGUI = 0;
  this->ResultingComponentsAreIndependent = -1;
  this->ResultingDistanceUnits   = 0;
  this->ResultingComponent1Units = 0;
  this->ResultingComponent2Units = 0;
  this->ResultingComponent3Units = 0;
  this->ResultingComponent4Units = 0;
}
//----------------------------------------------------------------------------
vtkVVPlugin::~vtkVVPlugin()
{
  int i;
  // Free all of the widgets
  this->DocLabel->Delete();
  this->DocText->Delete();
  this->ReportText->Delete();
  this->StopWatchText->Delete();
  if (this->SecondInputButton)
    {
    this->SecondInputButton->Delete();
    this->SecondInputButton = 0;
    }
  if (this->SecondInputOpenWizard)
    {
    this->SecondInputOpenWizard->Delete();
    this->SecondInputOpenWizard = 0;
    }
 
//BTX
#ifdef KWVolView_PLUGINS_USE_SERIES
  if (this->SeriesInputButton)
    {
    this->SeriesInputButton->Delete();
    this->SeriesInputButton = 0;
    }
  if (this->SeriesInputOpenWizard)
    {
    this->SeriesInputOpenWizard->Delete();
    this->SeriesInputOpenWizard = 0;
    }
#endif
//ETX
 
  if (this->Widgets)
    {
    for (i = 0; i < this->NumberOfGUIItems; ++i)
      {
      if (this->Widgets[2*i])
        {
        this->Widgets[2*i]->Delete();
        }
      if (this->Widgets[2*i+1])
        {
        this->Widgets[2*i+1]->Delete();
        }
      }
    delete [] this->Widgets;
    this->Widgets = 0;
    }
  if (this->NumberOfGUIItems)
    {
    for (i = 0; i < this->NumberOfGUIItems; ++i)
      {
      if (this->GUIItems[i].Default)
        {
        free(this->GUIItems[i].Default);
        }
      if (this->GUIItems[i].Label)
        {
        free(this->GUIItems[i].Label);
        }
      if (this->GUIItems[i].Help)
        {
        free(this->GUIItems[i].Help);
        }
      if (this->GUIItems[i].Hints)
        {
        free(this->GUIItems[i].Hints);
        }
      if (this->GUIItems[i].Value)
        {
        free(this->GUIItems[i].Value);
        }
      }
    free(this->GUIItems);
    }
  this->SetName(0);
  this->SetGroup(0);
  this->SetTerseDocumentation(0);
  this->SetFullDocumentation(0);
  
  this->SetResultingDistanceUnits(0);
  this->SetResultingComponent1Units(0);
  this->SetResultingComponent2Units(0);
  this->SetResultingComponent3Units(0);
  this->SetResultingComponent4Units(0);
  
  this->SetPlottingXAxisTitle(0);
  this->SetPlottingYAxisTitle(0);
//BTX
#ifdef KWVolView_PLUGINS_USE_MARKER
  if (this->PluginInfo.Markers)
    {
    delete [] this->PluginInfo.Markers;
    this->PluginInfo.Markers = 0;
    this->PluginInfo.NumberOfMarkers = 0;
    }
  if (this->PluginInfo.MarkersGroupId)
    {
    delete [] this->PluginInfo.MarkersGroupId;
    this->PluginInfo.MarkersGroupId = 0;
    }
  if (this->PluginInfo.MarkersGroupName)
    {
    delete [] this->PluginInfo.MarkersGroupName;
    this->PluginInfo.MarkersGroupName = 0;
    this->PluginInfo.NumberOfMarkersGroups = 0;
    }
#endif
//ETX
  if (this->PluginInfo.CroppingPlanes)
    {
    delete [] this->PluginInfo.CroppingPlanes;
    this->PluginInfo.CroppingPlanes = 0;
    }
//BTX
#ifdef KWVolView_PLUGINS_USE_SPLINE
  if(this->PluginInfo.NumberOfSplineSurfacePoints)
    {
    delete [] this->PluginInfo.NumberOfSplineSurfacePoints;
    this->PluginInfo.NumberOfSplineSurfacePoints = 0;
    this->PluginInfo.NumberOfSplineSurfaces = 0;
    }
  if(this->PluginInfo.SplineSurfacePoints)
    {
    delete [] this->PluginInfo.SplineSurfacePoints;
    this->PluginInfo.SplineSurfacePoints = 0;
    this->PluginInfo.NumberOfSplineSurfaces = 0;
    }
#endif
//ETX
  if(this->PluginInfo.UnstructuredGridScalarFields)
    {
    delete [] this->PluginInfo.UnstructuredGridScalarFields;
    this->PluginInfo.UnstructuredGridScalarFields = 0;
    }
  this->PluginInfo.Self = 0;
  this->PluginInfo.UpdateProgress = 0;
  this->PluginInfo.AssignPolygonalData = 0;
  this->PluginInfo.SetProperty = 0;
  this->PluginInfo.GetProperty = 0;
  this->PluginInfo.SetGUIProperty = 0;
  this->PluginInfo.GetGUIProperty = 0;
  this->PluginInfo.ProcessData = 0;
  this->PluginInfo.UpdateGUI = 0;
}
//----------------------------------------------------------------------------
void vtkVVPlugin::UpdateEnableState()
{
  this->Superclass::UpdateEnableState();
  this->PropagateEnableState(this->DocLabel);
  this->PropagateEnableState(this->DocText);
  this->PropagateEnableState(this->ReportText);
  this->PropagateEnableState(this->StopWatchText);
  if (this->Widgets)
    {
    int i;
    for (i = 0; i < this->NumberOfGUIItems; ++i)
      {
      this->PropagateEnableState(this->Widgets[2*i]);
      this->PropagateEnableState(this->Widgets[2*i + 1]);
      }
    }
  this->PropagateEnableState(this->SecondInputButton);
//BTX
#ifdef KWVolView_PLUGINS_USE_SERIES
  this->PropagateEnableState(this->SeriesInputButton);
#endif
//ETX
}
//----------------------------------------------------------------------------
void vtkVVPlugin::SetWindow(vtkVVWindowBase *arg)
{
  if (this->Window == arg)
    {
    return;
    }
  this->Window = arg;
  this->Modified();
  this->Update();
}
//----------------------------------------------------------------------------
extern "C" 
{
  void  vtkVVPluginSetProperty(void *inf, int param, const char *val)
  {
    vtkVVPluginInfo *info = (vtkVVPluginInfo *)inf;
    vtkVVPlugin *self = (vtkVVPlugin *)info->Self;
    self->SetProperty(param,val);
  }
  const char *vtkVVPluginGetProperty(void *inf, int param)
  {
    vtkVVPluginInfo *info = (vtkVVPluginInfo *)inf;
    vtkVVPlugin *self = (vtkVVPlugin *)info->Self;
    return self->GetProperty(param);
  }
  void  vtkVVPluginSetGUIProperty(void *inf, int gui, 
                                  int param, const char *val)
  {
    vtkVVPluginInfo *info = (vtkVVPluginInfo *)inf;
    vtkVVPlugin *self = (vtkVVPlugin *)info->Self;
    self->SetGUIProperty(gui, param,val);
  }
  const char *vtkVVPluginGetGUIProperty(void *inf, int gui, int param)
  {
    vtkVVPluginInfo *info = (vtkVVPluginInfo *)inf;
    vtkVVPlugin *self = (vtkVVPlugin *)info->Self;
    return self->GetGUIProperty(gui, param);
  }
}
extern "C" 
{
  void  vtkVVPluginUpdateProgress(void *inf, float progress, const char *msg)
  {
    vtkVVPluginInfo *info = (vtkVVPluginInfo *)inf;
    vtkVVPlugin *self = (vtkVVPlugin *)info->Self;
    if (info && 
        self && 
        self->GetWindow() && 
        self->GetWindow()->GetProgressGauge())
      {
      progress = self->ProgressMinimum + 
        (self->ProgressMaximum - self->ProgressMinimum)*progress;
      self->GetWindow()->GetProgressGauge()->SetValue(
        static_cast<int>(100.0*progress));
      if (progress >= 1.0)
        {
        self->GetWindow()->GetProgressGauge()->SetValue(static_cast<int>(0.0));
        }
      self->GetWindow()->SetStatusText(msg);
      self->GetWindow()->GetApplication()->ProcessPendingEvents();
      }
  }
}
extern "C" 
{
  void  vtkVVPluginAssignPolygonalData(void *inf, vtkVVProcessDataStruct *pds)
  {
    vtkVVPluginInfo *info = (vtkVVPluginInfo *)inf;
    vtkVVPlugin *self = (vtkVVPlugin *)info->Self;
    // now did this generate polydata?
    if (pds->NumberOfMeshPoints)
      {
      vtkPolyData *pd = vtkPolyData::New();
      vtkPoints *points = vtkPoints::New();
      vtkCellArray *ca = vtkCellArray::New();
      int i, j;
      
      // do the points
      points->SetNumberOfPoints(pds->NumberOfMeshPoints);
      for (i = 0; i < pds->NumberOfMeshPoints; ++i)
        {
        points->SetPoint(i,pds->MeshPoints + i*3);
        }
      // do the cells
      int *pos = pds->MeshCells;
      for (i = 0; i < pds->NumberOfMeshCells; ++i)
        {
        ca->InsertNextCell(*pos);
        for (j = 0; j < *pos; ++j)
          {
          ca->InsertCellPoint(pos[j+1]);
          }
        pos = pos + (*pos + 1);
        }
      // are there normals?
      if (pds->MeshNormals)
        {
        vtkFloatArray *normals = vtkFloatArray::New();
        normals->SetNumberOfComponents(3);
        normals->SetNumberOfTuples(pds->NumberOfMeshPoints);
        for (i = 0; i < pds->NumberOfMeshPoints; ++i)
          {
          normals->SetTuple(i,pds->MeshNormals + i*3);
          }
        pd->GetPointData()->SetNormals(normals);
        normals->Delete();
        }
      
      // are there scalars?
      if (pds->MeshScalars)
        {
        vtkFloatArray *scalars = vtkFloatArray::New();
        scalars->SetNumberOfComponents(1);
        scalars->SetNumberOfTuples(pds->NumberOfMeshPoints);
        for (i = 0; i < pds->NumberOfMeshPoints; ++i)
          {
          scalars->SetTuple(i,pds->MeshScalars + i);
          }
        pd->GetPointData()->SetScalars(scalars);
        scalars->Delete();
        }
      pd->SetPoints(points);
      points->Delete();
      pd->SetPolys(ca);
      ca->Delete();
      // set the pd on the Window
      //self->GetWindow()->SetPolyData(pd);
      
      pd->Delete();
      }
  }
}
//----------------------------------------------------------------------------
void vtkVVPlugin::SetProperty(int param, const char *value)
{
  switch (param)
    {
    case VVP_ERROR:
      vtkKWMessageDialog::PopupMessage( 
        this->GetApplication(), 0, "Plugin Execution", value, 
        vtkKWMessageDialog::ErrorIcon);
      break;
    case VVP_NAME:
      this->SetName(value);
      break;
    case VVP_GROUP:
      this->SetGroup(value);
      break;
    case VVP_TERSE_DOCUMENTATION:
      this->SetTerseDocumentation(value);
      break;
    case VVP_FULL_DOCUMENTATION:
      this->SetFullDocumentation(value);
      break;
    case VVP_SUPPORTS_IN_PLACE_PROCESSING:
      this->SupportInPlaceProcessing = atoi(value);
      break;
    case VVP_SUPPORTS_PROCESSING_PIECES:
      this->SupportProcessingPieces = atoi(value);
      break;
//BTX
#ifdef KWVolView_PLUGINS_USE_SERIES
    case VVP_SUPPORTS_PROCESSING_SERIES_BY_VOLUMES:
      this->SupportProcessingSeriesByVolumes = atoi(value);
      break;
#endif
//ETX
    case VVP_NUMBER_OF_GUI_ITEMS:
      this->NumberOfGUIItems = atoi(value);
      break;
//BTX
#ifdef KWVolView_PLUGINS_USE_SPLINE
    case VVP_PRODUCES_MESH_ONLY:
      this->ProducesMeshOnly = atoi(value);
      break;
#endif
//ETX
    case VVP_REQUIRED_Z_OVERLAP:
      this->RequiredZOverlap = atoi(value);
      break;
    case VVP_PER_VOXEL_MEMORY_REQUIRED:
      this->PerVoxelMemoryRequired = atof(value);
      break;
    case VVP_ABORT_PROCESSING:
      this->AbortProcessing = atoi(value);
      break;
    case VVP_REPORT_TEXT:
      this->SetReportText(value);
      break;
    case VVP_REQUIRES_SECOND_INPUT:
      this->RequiresSecondInput = atoi(value);
      break;
    case VVP_SECOND_INPUT_IS_UNSTRUCTURED_GRID:
      this->SecondInputIsUnstructuredGrid = atoi(value);
      break;
    case VVP_SECOND_INPUT_OPTIONAL:
      this->SecondInputOptional = atoi(value);
      break;
    case VVP_REQUIRES_LABEL_INPUT:
      this->RequiresLabelInput = atoi(value);
      break;      
//BTX
#ifdef KWVolView_PLUGINS_USE_SPLINE
    case VVP_REQUIRES_SPLINE_SURFACES:
      this->RequiresSplineSurfaces = atoi(value);
      break;
#endif
//ETX
//BTX
#ifdef KWVolView_PLUGINS_USE_SERIES
    case VVP_REQUIRES_SERIES_INPUT:
      this->RequiresSeriesInput = atoi(value);
      break;
    case VVP_PRODUCES_OUTPUT_SERIES:
      this->ProducesSeriesOutput = atoi(value);
      break;
#endif
//ETX
    case VVP_PRODUCES_PLOTTING_OUTPUT:
      this->ProducesPlottingOutput = atoi(value);
      break;
    case VVP_RESULTING_COMPONENTS_ARE_INDEPENDENT:
      this->ResultingComponentsAreIndependent = atoi(value);
      break;
    case VVP_RESULTING_DISTANCE_UNITS:
      this->SetResultingDistanceUnits(value);
      break;
    case VVP_RESULTING_COMPONENT_1_UNITS:
      this->SetResultingComponent1Units(value);
      break;
    case VVP_RESULTING_COMPONENT_2_UNITS:
      this->SetResultingComponent2Units(value);
      break;
    case VVP_RESULTING_COMPONENT_3_UNITS:
      this->SetResultingComponent3Units(value);
      break;
    case VVP_RESULTING_COMPONENT_4_UNITS:
      this->SetResultingComponent4Units(value);
      break;
    case VVP_PLOTTING_X_AXIS_TITLE:
      this->SetPlottingXAxisTitle(value);
      break;
    case VVP_PLOTTING_Y_AXIS_TITLE:
      this->SetPlottingYAxisTitle(value);
      break;
    }
}
//----------------------------------------------------------------------------
const char *vtkVVPlugin::GetProperty(int param)
{
  vtkVVDataItemVolume *volume_data = vtkVVDataItemVolume::SafeDownCast(
                                  this->Window->GetSelectedDataItem());
  switch (param)
    {
    case VVP_NAME:
      return this->GetName();
      break;
    case VVP_GROUP:
      return this->GetGroup();
      break;
    case VVP_TERSE_DOCUMENTATION:
      return this->GetTerseDocumentation();
      break;
    case VVP_FULL_DOCUMENTATION:
      return this->GetFullDocumentation();
      break;
    case VVP_ABORT_PROCESSING:
      if (this->AbortProcessing)
        {
        return "1";
        }
      else
        {
        return "0";
        }
      break;
    case VVP_RESULTING_DISTANCE_UNITS:
      return this->GetResultingDistanceUnits();
      break;
    case VVP_RESULTING_COMPONENT_1_UNITS:
      return this->GetResultingComponent1Units();
      break;
    case VVP_RESULTING_COMPONENT_2_UNITS:
      return this->GetResultingComponent2Units();
      break;
    case VVP_RESULTING_COMPONENT_3_UNITS:
      return this->GetResultingComponent3Units();
      break;
    case VVP_RESULTING_COMPONENT_4_UNITS:
      return this->GetResultingComponent4Units();
      break;
      
    case VVP_INPUT_COMPONENTS_ARE_INDEPENDENT:
      if (volume_data->GetVolumeProperty()->GetIndependentComponents())
        {
        return "1";
        }
      else
        {
        return "0";
        }
      break;
    case VVP_INPUT_DISTANCE_UNITS:
      return volume_data->GetDistanceUnits();
      break;
    case VVP_INPUT_COMPONENT_1_UNITS:
      return volume_data->GetScalarUnits(0);
      break;
    case VVP_INPUT_COMPONENT_2_UNITS:
      return volume_data->GetScalarUnits(1);
      break;
    case VVP_INPUT_COMPONENT_3_UNITS:
      return volume_data->GetScalarUnits(2);
      break;
    case VVP_INPUT_COMPONENT_4_UNITS:
      return volume_data->GetScalarUnits(3);
      break;
      // these values may change as the second input is changed
    case VVP_INPUT_2_COMPONENTS_ARE_INDEPENDENT:
      if (this->SecondInputOpenWizard->GetOpenFileProperties()->GetIndependentComponents())
        {
        return "1";
        }
      else
        {
        return "0";
        }
      break;
    case VVP_INPUT_2_DISTANCE_UNITS:
      return this->SecondInputOpenWizard->GetOpenFileProperties()->GetDistanceUnits();
      break;
    case VVP_INPUT_2_COMPONENT_1_UNITS:
      return this->SecondInputOpenWizard->GetOpenFileProperties()->GetScalarUnits(0);
      break;
    case VVP_INPUT_2_COMPONENT_2_UNITS:
      return this->SecondInputOpenWizard->GetOpenFileProperties()->GetScalarUnits(1);
      break;
    case VVP_INPUT_2_COMPONENT_3_UNITS:
      return this->SecondInputOpenWizard->GetOpenFileProperties()->GetScalarUnits(2);
      break;
    case VVP_INPUT_2_COMPONENT_4_UNITS:
      return this->SecondInputOpenWizard->GetOpenFileProperties()->GetScalarUnits(3);
      break;
    }
  return 0;
}
//----------------------------------------------------------------------------
void vtkVVPlugin::SetGUIProperty(int gui, int param, const char *value)
{
  if (gui < 0 || gui >= this->NumberOfGUIItems)
    {
    return;
    }
  
  vtkVVGUIItem *gi = this->GUIItems + gui;
  switch (param)
    {
    case VVP_GUI_LABEL:
      if (gi->Label)
        {
        free(gi->Label);
        gi->Label = 0;
        }
      if (value)
        {
        gi->Label = strdup(value);
        }
      break;
    case VVP_GUI_DEFAULT:
      if (gi->Default)
        {
        free(gi->Default);
        gi->Default = 0;
        }
      if (value)
        {
        gi->Default = strdup(value);
        }
      break;
    case VVP_GUI_HELP:
      if (gi->Help)
        {
        free(gi->Help);
        gi->Help = 0;
        }
      if (value)
        {
        gi->Help = strdup(value);
        }
      break;
    case VVP_GUI_HINTS:
      if (gi->Hints)
        {
        free(gi->Hints);
        gi->Hints = 0;
        }
      if (value)
        {
        gi->Hints = strdup(value);
        }
      break;
    case VVP_GUI_VALUE:
      if (gi->Value)
        {
        free(gi->Value);
        gi->Value = 0;
        }
      if (value)
        {
        gi->Value = strdup(value);
        }
      break;
    case VVP_GUI_TYPE:
      if (!strcmp(value,VVP_GUI_SCALE))
        {
        gi->GUIType = VV_GUI_SCALE;
        }
      if (!strcmp(value,VVP_GUI_CHOICE))
        {
        gi->GUIType = VV_GUI_CHOICE;
        }
      if (!strcmp(value,VVP_GUI_CHECKBOX))
        {
        gi->GUIType = VV_GUI_CHECKBOX;
        }
      break;
    }
}
//----------------------------------------------------------------------------
const char *vtkVVPlugin::GetGUIProperty(int gui, int param)
{
  if (gui < 0 || gui >= this->NumberOfGUIItems)
    {
    return 0;
    }
  
  vtkVVGUIItem *gi = this->GUIItems + gui;
  
  switch (param)
    {
    case VVP_GUI_LABEL:
      return gi->Label;
      break;
    case VVP_GUI_DEFAULT:
      return gi->Default;
      break;
    case VVP_GUI_HELP:
      return gi->Help;
      break;
    case VVP_GUI_HINTS:
      return gi->Hints;
      break;
    case VVP_GUI_VALUE:
      return gi->Value;
      break;
    case VVP_GUI_TYPE:
      switch (gi->GUIType)
        {
        case VV_GUI_SCALE:
          return VVP_GUI_SCALE;
          break;
        case VV_GUI_CHOICE:
          return VVP_GUI_CHOICE;
          break;
        case VV_GUI_CHECKBOX:
          return VVP_GUI_CHECKBOX;
          break;
        }
      break;
    }
  return 0;
}
//----------------------------------------------------------------------------
void vtkVVPlugin::SetGUIProperty(const char *label, int param, const char *value)
{
  if (label)
    {
    int i;
    for (i = 0; i < this->NumberOfGUIItems; ++i)
      {
      vtkVVGUIItem *gi = &this->GUIItems[i];
      if (gi && gi->Label && !strcmp(gi->Label, label))
        {
        this->SetGUIProperty(i, param, value);
        }
      }
    }
}
//----------------------------------------------------------------------------
const char *vtkVVPlugin::GetGUIProperty(const char *label, int param)
{
  if (label)
    {
    int i;
    for (i = 0; i < this->NumberOfGUIItems; ++i)
      {
      vtkVVGUIItem *gi = &this->GUIItems[i];
      if (gi && gi->Label && !strcmp(gi->Label, label))
        {
        return this->GetGUIProperty(i, param);
        }
      }
    }
  return NULL;
}
//----------------------------------------------------------------------------
void vtkVVPlugin::SetGUIPropertyValue(const char *label, const char *value)
{
  this->SetGUIProperty(label, VVP_GUI_VALUE, value);
}
//----------------------------------------------------------------------------
const char *vtkVVPlugin::GetGUIPropertyValue(const char *label)
{
  return this->GetGUIProperty(label, VVP_GUI_VALUE);
}
//----------------------------------------------------------------------------
int vtkVVPlugin::Load(const char *path, vtkKWApplication *app)
{
  // the file must exist
  vtkstd::string fullPath = path;
  // try loading the shared library / dll
  vtkLibHandle lib = vtkDynamicLoader::OpenLibrary(fullPath.c_str());
  if(!lib)
    {
    return 1;
    }
  // find the init function
  vtkstd::string initFuncName = path;
  // remove the extension 
  vtkstd::string::size_type slash_pos = initFuncName.rfind("/");
  if(slash_pos != vtkstd::string::npos)
    {
    initFuncName = initFuncName.substr(slash_pos + 1);
    }
  vtkstd::string::size_type dot_pos = initFuncName.find(".");
  if(dot_pos != vtkstd::string::npos)
    {
    initFuncName = initFuncName.substr(0, dot_pos);
    }
  initFuncName += "Init";
  VV_INIT_FUNCTION initFunction
    = (VV_INIT_FUNCTION)
    vtkDynamicLoader::GetSymbolAddress(lib, initFuncName.c_str());
  if ( !initFunction )
    {
    initFuncName = "_";
    initFuncName += path;
    initFuncName += "Init";
    initFunction = (VV_INIT_FUNCTION)(
      vtkDynamicLoader::GetSymbolAddress(lib, initFuncName.c_str()));
    }
  // if the symbol is found call it to set the name on the 
  // function blocker
  if(initFunction)
    {
    // create the data strucvture and initialize
    this->SetGroup(VTK_VV_PLUGIN_DEFAULT_GROUP);
    this->PluginInfo.Self = (void *)this;
    this->PluginInfo.UpdateProgress = vtkVVPluginUpdateProgress;
    this->PluginInfo.SetProperty = vtkVVPluginSetProperty;
    this->PluginInfo.GetProperty = vtkVVPluginGetProperty;
    this->PluginInfo.SetGUIProperty = vtkVVPluginSetGUIProperty;
    this->PluginInfo.GetGUIProperty = vtkVVPluginGetGUIProperty;
//BTX
#ifdef KWVolView_PLUGINS_USE_SPLINE
    this->PluginInfo.AssignPolygonalData = vtkVVPluginAssignPolygonalData;
#endif
//ETX
    this->PluginInfo.magic1 = VV_PLUGIN_API_VERSION;
    (*initFunction)(&this->PluginInfo);
    // a plugin will set magic1 to the plugin API it was compiled with
    // if it can work, otherwise zero. By default the rule is that a
    // plugin will assume that it will work with future API versions.
    if (!this->PluginInfo.magic1)
      {
      char *msg = new char [strlen(path) + 1024];
      sprintf(msg,"An attempt was made to load a plugin that is not compatible with the version of VolView being run. The plugin was located in the file %s",path);
      vtkKWMessageDialog::PopupMessage( 
        app, 0, "Load Plugin", msg, vtkKWMessageDialog::ErrorIcon);
      delete [] msg;
      this->NumberOfGUIItems = 0;
      return 3;
      }
    if (this->NumberOfGUIItems)
      {
      this->GUIItems = (vtkVVGUIItem *)
        malloc(this->NumberOfGUIItems*sizeof(vtkVVGUIItem));
      // initialize the strings to null 
      int i;
      for (i = 0; i < this->NumberOfGUIItems; ++i)
        {
        this->GUIItems[i].Default = 0;
        this->GUIItems[i].Label = 0;
        this->GUIItems[i].Help = 0;
        this->GUIItems[i].Hints = 0;
        this->GUIItems[i].Value = 0;
        }
      }
    return 0;
    }
  return 2;
}
//----------------------------------------------------------------------------
void vtkVVPlugin::CreateWidget()
{
  // Check if already created
  if (this->IsCreated())
    {
    vtkErrorMacro(<< this->GetClassName() << " already created");
    return;
    }
  // Call the superclass to create the whole widget
  this->Superclass::CreateWidget();
  // create the GUI components
  this->PluginInfo.UpdateGUI(&this->PluginInfo);
  int i, row = 0;
  this->DocLabel->SetParent(this);
  this->DocLabel->Create();
  this->DocLabel->SetText(this->TerseDocumentation);
  this->Script("grid %s -sticky nsw -row %d -column 0 -columnspan 2 -pady 4",
               this->DocLabel->GetWidgetName(), row++);
  this->Script("grid columnconfigure %s 0 -weight 0",
               this->GetWidgetName());
  this->Script("grid columnconfigure %s 1 -weight 1",
               this->GetWidgetName());
  // for each GUI component ...
  this->Widgets = new vtkKWWidget *[2*this->NumberOfGUIItems];
  for (i = 0; i < this->NumberOfGUIItems; ++i)
    {
    this->Widgets[2*i] = 0;
    this->Widgets[2*i+1] = 0;
    // create the actual widget
    switch (this->GUIItems[i].GUIType) 
      {
      case VV_GUI_SCALE:
      {
      vtkKWScaleWithEntry *s = vtkKWScaleWithEntry::New();
      s->SetParent(this);
      s->Create();
      s->SetLabelAndEntryPositionToTop();
      this->Widgets[2*i+1] = s;
      this->Script("grid %s -sticky nsew -row %i -column 0 -columnspan 2",
                   this->Widgets[2*i+1]->GetWidgetName(), row++);
      }
      break;
      case VV_GUI_CHOICE:
      {
      vtkKWLabel *l = vtkKWLabel::New();
      l->SetParent(this);
      l->Create();
      this->Widgets[2*i] = l;
      this->Script("grid %s -sticky w -row %i -column 0",
                   this->Widgets[2*i]->GetWidgetName(), row++);
      vtkKWMenuButton *s = vtkKWMenuButton::New();
      s->SetParent(this);
      s->Create();
      this->Widgets[2*i+1] = s;
      this->Script("grid %s -sticky w -row %i -column 1",
                   this->Widgets[2*i+1]->GetWidgetName(), row++);
      }
      break;
      case VV_GUI_CHECKBOX:
      {
      vtkKWCheckButton *s = vtkKWCheckButton::New();
      s->SetParent(this);
      s->Create();
      this->Widgets[2*i+1] = s;
      this->Script("grid %s -sticky nsw -row %i -column 0 -columnspan 2",
                   this->Widgets[2*i+1]->GetWidgetName(), row++);
      }
      break;
      }
    }
  // if the plugin requires a second input then add the button
  if (this->RequiresSecondInput)
    {
    this->SecondInputButton = vtkKWPushButton::New();
    this->SecondInputButton->SetParent(this);
    this->SecondInputButton->Create();
    this->SecondInputButton->SetText("Assign Second Input");
    this->SecondInputButton->SetCommand(this, "SecondInputCallback");
    this->Script(
      "grid %s -sticky nsew -padx 2 -pady 2 -row %i -column 0 -columnspan 2",
      this->SecondInputButton->GetWidgetName(), row++);
    // create the open wizard
    this->SecondInputOpenWizard = vtkKWOpenWizard::New();
    this->SecondInputOpenWizard->SetApplication(this->GetApplication());
    this->SecondInputOpenWizard->Create();
    this->SecondInputOpenWizard->SetTitle(NULL); // updated by Invoke()
    this->SecondInputOpenWizard->GetOpenFileHelper()->
      SetAllowVTKUnstructuredGrid(this->SecondInputIsUnstructuredGrid);
    }
  
//BTX
#ifdef KWVolView_PLUGINS_USE_SERIES
  // if the plugin requires a series input then add the button
  if (this->RequiresSeriesInput)
    {
    this->SeriesInputButton = vtkKWPushButton::New();
    this->SeriesInputButton->SetParent(this);
    this->SeriesInputButton->Create();
    this->SeriesInputButton->SetText("Assign Series Input");
    this->SeriesInputButton->SetCommand(this, "SeriesInputCallback");
    this->Script(
      "grid %s -sticky nsew -padx 2 -pady 2 -row %i -column 0 -columnspan 2",
      this->SeriesInputButton->GetWidgetName(), row++);
    // create the open wizard
    this->SeriesInputOpenWizard = vtkVV4DOpenWizard::New();
    this->SeriesInputOpenWizard->SetApplication(this->GetApplication());
    this->SeriesInputOpenWizard->Create();
    this->SeriesInputOpenWizard->SetTitle(NULL); // updated by Invoke()
    }
#endif
//ETX
  
  this->DocText->SetParent(this);
  this->DocText->Create();
  this->DocText->GetLabel()->SetImageToPredefinedIcon(
    vtkKWIcon::IconSilkHelp);
  this->DocText->ExpandWidgetOn();
  this->DocText->GetWidget()->AdjustWrapLengthToWidthOn();
  this->DocText->GetWidget()->SetText(this->FullDocumentation);
  this->Script("grid %s -sticky nsew -row %i -column 0 -columnspan 2 -pady 1",
               this->DocText->GetWidgetName(), row++);
  this->ReportText->SetParent(this);
  this->ReportText->Create();
  this->ReportText->GetLabel()->SetImageToPredefinedIcon(
    vtkKWIcon::IconSilkInformation);
  this->ReportText->ExpandWidgetOn();
  this->ReportText->GetWidget()->AdjustWrapLengthToWidthOn();
  this->Script("grid %s -sticky nsew -row %i -column 0 -columnspan 2 -pady 1",
               this->ReportText->GetWidgetName(), row++);
  this->SetReportText("");
  this->StopWatchText->SetParent(this);
  this->StopWatchText->Create();
  this->StopWatchText->GetLabel()->SetImageToPredefinedIcon(
    vtkKWIcon::IconTime);
  this->StopWatchText->ExpandWidgetOff();
  this->Script("grid %s -sticky nsew -row %i -column 0 -columnspan 2 -pady 1",
               this->StopWatchText->GetWidgetName(), row++);
  this->SetStopWatchText("");
  // Update
  this->Update();
  // set the initial values for each GUI component ...
  for (i = 0; i < this->NumberOfGUIItems; ++i)
    {
    // update the actual widgets
    if (!this->GUIItems[i].Default)
      {
      continue;
      }
    switch (this->GUIItems[i].GUIType) 
      {
      case VV_GUI_SCALE:
      {
      vtkKWScaleWithEntry *s = 
        vtkKWScaleWithEntry::SafeDownCast(this->Widgets[2*i+1]);
      s->SetValue(atof(this->GUIItems[i].Default));
      }
      break;
      case VV_GUI_CHOICE:
      {
      vtkKWMenuButton *s = vtkKWMenuButton::SafeDownCast(this->Widgets[2*i+1]);
      s->SetValue(this->GUIItems[i].Default);
      }
      break;
      case VV_GUI_CHECKBOX:
      {
      vtkKWCheckButton *s = 
        vtkKWCheckButton::SafeDownCast(this->Widgets[2*i+1]);
      s->SetSelectedState(atoi(this->GUIItems[i].Default));
      }
      break;
      }
    }
}
//----------------------------------------------------------------------------
void vtkVVPlugin::SecondInputCallback()
{
  if (!this->SecondInputOpenWizard)
    {
    return;
    }
  // Get another input to use as the second input
  vtkKWLoadSaveDialog *loaddialog = this->SecondInputOpenWizard->GetLoadDialog();
  if (loaddialog)
    {
    loaddialog->RetrieveLastPathFromRegistry("OpenPath");
    }
  // Bring up the wizard, if succesfull then ...
  int res;
  if (this->SecondInputIsUnstructuredGrid)
    {
    res = this->SecondInputOpenWizard->InvokeQuiet();
    }
  else
    {
    res = this->SecondInputOpenWizard->Invoke();
    }
  if (res)
    {
    if (loaddialog)
      {
      loaddialog->SaveLastPathToRegistry("OpenPath");
      }
    this->UpdateAccordingToSecondInput();
    }
}
//----------------------------------------------------------------------------
const char* vtkVVPlugin::GetSecondInputFileName()
{
  if (this->SecondInputOpenWizard)
    {
    return this->SecondInputOpenWizard->GetFileName();
    }
  return NULL;
}
//----------------------------------------------------------------------------
void vtkVVPlugin::SetSecondInputFileName(const char *fname)
{
  // Bring up the wizard, if succesfull then ...
  if (this->SecondInputOpenWizard && this->SecondInputOpenWizard->Invoke(fname, 0))
    {
    this->UpdateAccordingToSecondInput();
    }
}
//----------------------------------------------------------------------------
void vtkVVPlugin::UpdateAccordingToSecondInput()
{
  if (!this->SecondInputOpenWizard || !this->SecondInputOpenWizard->GetFileName())
    {
    return;
    }
  const char *fname = this->SecondInputOpenWizard->GetFileName();
  ostrstream title;
  vtksys_stl::string basename = vtksys::SystemTools::GetFilenameName(fname);
  title << "Second Input: " << basename.c_str() << ends;
  this->SecondInputButton->SetText(title.str());
  title.rdbuf()->freeze(0);
    
  // copy over the parameters now
  
  vtkKWOpenFileProperties *open_prop = 
    this->SecondInputOpenWizard->GetOpenFileProperties();
  this->PluginInfo.InputVolume2ScalarType = open_prop->GetScalarType();
  this->PluginInfo.InputVolume2ScalarSize = open_prop->GetScalarSize();
    
  this->PluginInfo.InputVolume2NumberOfComponents = 
    open_prop->GetNumberOfScalarComponents();
    
  int *wExt = open_prop->GetWholeExtent();
  this->PluginInfo.InputVolume2Dimensions[0] = wExt[1] - wExt[0] + 1;
  this->PluginInfo.InputVolume2Dimensions[1] = wExt[3] - wExt[2] + 1;
  this->PluginInfo.InputVolume2Dimensions[2] = wExt[5] - wExt[4] + 1;
  int i;
  for (i = 0; i < 3; i++)
    {
    this->PluginInfo.InputVolume2Spacing[i] = open_prop->GetSpacing()[i];
    }
    
  // compute the ranges
  // NOTE: I don't see how this was ever meant to work
  // this used to be the OpenWizard's 
  // ValidImageInfo->GetPointData()->GetScalars(), but as its name implies
  // this is only a structure describing the data, *not* the data itself!
  /*
  vtkDataArray *scalars = open_prop->GetPointData()->GetScalars();
  double ftmp[2];
  if (scalars)
    {
    for (i = 0; i < this->PluginInfo.InputVolume2NumberOfComponents; ++i)
      {
      scalars->GetRange(ftmp,i);
      this->PluginInfo.InputVolume2ScalarRange[2*i] = ftmp[0];
      this->PluginInfo.InputVolume2ScalarRange[2*i+1] = ftmp[1];
      }
    }
  */
  this->PluginInfo.InputVolume2ScalarTypeRange[0] = 
    open_prop->GetScalarTypeMin();
  this->PluginInfo.InputVolume2ScalarTypeRange[1] =
    open_prop->GetScalarTypeMax();
    
  // we do adjust the origin because the plugin is zero extent based
  double *origin = open_prop->GetOrigin();
  this->PluginInfo.InputVolume2Origin[0] = 
    origin[0] + open_prop->GetSpacing()[0]*open_prop->GetWholeExtent()[0];
  this->PluginInfo.InputVolume2Origin[1] = 
    origin[1] + open_prop->GetSpacing()[1]*open_prop->GetWholeExtent()[2];
  this->PluginInfo.InputVolume2Origin[2] = 
    origin[2] + open_prop->GetSpacing()[2]*open_prop->GetWholeExtent()[4];
  vtkUnstructuredGrid *res = 
    this->SecondInputOpenWizard->GetUnstructuredGridOutput(0);
  if (res)
    {
    ostrstream choices;
    int numArrays = res->GetPointData()->GetNumberOfArrays();
    choices << numArrays+1 << "\nUnspecified";
    for (int ctr=0; ctr<numArrays; ctr++)
      {
      choices << "\n" << res->GetPointData()->GetArray(ctr)->GetName();
      }
    choices << ends;
    int length = strlen(choices.str()) + 1;
    this->PluginInfo.UnstructuredGridScalarFields = new char [length+1];
    choices.rdbuf()->freeze(0);
    for (int newCtr=0; newCtr<length; newCtr++)
      {
      this->PluginInfo.UnstructuredGridScalarFields[newCtr] = 
        choices.str()[newCtr];
      }
    }
  // some of the GUI elements might depend on the second input, refresh
  // them now
  this->Update();
}
//BTX
#ifdef KWVolView_PLUGINS_USE_SERIES
//----------------------------------------------------------------------------
void vtkVVPlugin::SeriesInputCallback()
{
  if (!this->SeriesInputOpenWizard)
    {
    return;
    }
  // Get another input to use as the series input
  vtkKWLoadSaveDialog *loaddialog = this->SeriesInputOpenWizard->GetLoadDialog();
  if (loaddialog)
    {
    loaddialog->RetrieveLastPathFromRegistry("OpenPath");
    }
  // Bring up the wizard, if succesfull then ...
 
  if (this->SeriesInputOpenWizard->Invoke())
    {
    if (loaddialog)
      {
      loaddialog->SaveLastPathToRegistry("OpenPath");
      }
    this->UpdateAccordingToSeriesInput();
    }
}
//----------------------------------------------------------------------------
void vtkVVPlugin::GetSeriesInputFileNames(const char ** pattern,int & min, int & max)
{
  if (this->SeriesInputOpenWizard)
    {
      std::cout << "vtkVVPlugin::GetSeriesInputFileNames() needs to be implemented" << std::endl;
      std::cout << "The OpenWizard needs a method for returning pattern,min,max" << std::endl;
    *pattern = this->SeriesInputOpenWizard->GetFileName();
    min = 0;
    max = 0;
    }
  else
    {
    *pattern = NULL;
    min = 0;
    max = 0;
    }
}
//----------------------------------------------------------------------------
void vtkVVPlugin::SetSeriesInputFileNames(const char *pattern, int min, int max)
{
  // Bring up the wizard, if succesfull then ...
  // FIXME: It seems that another overload of Invoke() is needed in order to 
  // set the case of file series...  In the meantime... do nothing. This should only
  // matter for TeleVolView...
  std::cout << "vtkVVPlugin::SetSeriesInputFileNames() work in progress.." << std::endl;
  //  if (this->SeriesInputOpenWizard && this->SeriesInputOpenWizard->Invoke(*fname, 0))
  if (this->SeriesInputOpenWizard )
    {
    this->SeriesInputOpenWizard->SetSeriesPattern(pattern);
    this->SeriesInputOpenWizard->SetSeriesMinimum(min);
    this->SeriesInputOpenWizard->SetSeriesMaximum(max);
    this->UpdateAccordingToSeriesInput();
    }
}
//----------------------------------------------------------------------------
// Note that 'index' is in the range [0:numberOfDataSetsInTheSeries], not in
// the range [SeriesMinimum:SeriesMaximum]. This method is intended to be called
// from the VVWindow during televolview communication.
//
void vtkVVPlugin::SetSeriesInputFileName(const char *fname, int index)
{
  // Bring up the wizard, if succesfull then ...
  if (this->SeriesInputOpenWizard && this->SeriesInputOpenWizard->Invoke(fname, 0))
    {
    this->UpdateAccordingToSeriesInput();
    }
}
//----------------------------------------------------------------------------
void vtkVVPlugin::UpdateAccordingToSeriesInput()
{
  if (!this->SeriesInputOpenWizard || !this->SeriesInputOpenWizard->GetFileName())
    {
    return;
    }
  this->PluginInfo.InputVolumeSeriesNumberOfVolumes = 
                      this->SeriesInputOpenWizard->GetSeriesMaximum() -
                      this->SeriesInputOpenWizard->GetSeriesMinimum() + 1;
  const char *fname = this->SeriesInputOpenWizard->GetFileName();
  ostrstream title;
  vtksys_stl::string basename = vtksys::SystemTools::GetFilenameName(fname);
  title << "Series Input: " << basename.c_str() << ends;
  this->SeriesInputButton->SetText(title.str());
  title.rdbuf()->freeze(0);
    
  // copy over the parameters now
  vtkImageData *input = this->SeriesInputOpenWizard->GetValidImageInformation();
  this->PluginInfo.InputVolumeSeriesScalarType = input->GetScalarType();
  this->PluginInfo.InputVolumeSeriesScalarSize = input->GetScalarSize();
    
  this->PluginInfo.InputVolumeSeriesNumberOfComponents = 
    input->GetNumberOfScalarComponents();
    
  int *wExt = input->GetWholeExtent();
  this->PluginInfo.InputVolumeSeriesDimensions[0] = wExt[1] - wExt[0] + 1;
  this->PluginInfo.InputVolumeSeriesDimensions[1] = wExt[3] - wExt[2] + 1;
  this->PluginInfo.InputVolumeSeriesDimensions[2] = wExt[5] - wExt[4] + 1;
  int i;
  for (i = 0; i < 3; i++)
    {
    this->PluginInfo.InputVolumeSeriesSpacing[i] = input->GetSpacing()[i];
    }
    
  // compute the ranges
  vtkDataArray *scalars = input->GetPointData()->GetScalars();
  double ftmp[2];
  if (scalars)
    {
    for (i = 0; i < this->PluginInfo.InputVolumeSeriesNumberOfComponents; ++i)
      {
      scalars->GetRange(ftmp,i);
      this->PluginInfo.InputVolumeSeriesScalarRange[2*i] = ftmp[0];
      this->PluginInfo.InputVolumeSeriesScalarRange[2*i+1] = ftmp[1];
      }
    }
  this->PluginInfo.InputVolumeSeriesScalarTypeRange[0] =input->GetScalarTypeMin();
  this->PluginInfo.InputVolumeSeriesScalarTypeRange[1] =input->GetScalarTypeMax();
    
  // we do adjust the origin because the plugin is zero extent based
  double *origin = input->GetOrigin();
  this->PluginInfo.InputVolumeSeriesOrigin[0] = 
    origin[0] + input->GetSpacing()[0]*input->GetWholeExtent()[0];
  this->PluginInfo.InputVolumeSeriesOrigin[1] = 
    origin[1] + input->GetSpacing()[1]*input->GetWholeExtent()[2];
  this->PluginInfo.InputVolumeSeriesOrigin[2] = 
    origin[2] + input->GetSpacing()[2]*input->GetWholeExtent()[4];
  // some of the GUI elements might depend on the series input, refresh
  // them now
  this->Update();
}
#endif
//ETX
//----------------------------------------------------------------------------
void vtkVVPlugin::SetReportText(const char *text)
{
  if (!this->IsCreated())
    {
    return;
    }
  this->ReportText->GetWidget()->SetText(text);
  this->Script("grid %s %s", 
               ((text && *text) ? "" : "remove"), 
               this->ReportText->GetWidgetName());
}
//----------------------------------------------------------------------------
char* vtkVVPlugin::GetReportText()
{
  return this->ReportText->GetWidget()->GetText();
}
//----------------------------------------------------------------------------
void vtkVVPlugin::SetStopWatchText(const char *text)
{
  if (!this->IsCreated())
    {
    return;
    }
  this->StopWatchText->GetWidget()->SetText(text);
  this->Script("grid %s %s", 
               ((text && *text) ? "" : "remove"), 
               this->StopWatchText->GetWidgetName());
}
//----------------------------------------------------------------------------
char* vtkVVPlugin::GetStopWatchText()
{
  return this->StopWatchText->GetWidget()->GetText();
}
//----------------------------------------------------------------------------
void vtkVVPlugin::Update()
{
  // Update enable state
  this->UpdateEnableState();
  // Update data (which will update the GUI too)
  if (this->Window)
    {
    vtkVVDataItemVolume *volume_data = vtkVVDataItemVolume::SafeDownCast(
                                  this->Window->GetSelectedDataItem());
    if( volume_data)
      this->UpdateData(volume_data->GetImageData());
    }
  // Update the GUI
  
  this->UpdateGUI();
}
//----------------------------------------------------------------------------
void vtkVVPlugin::UpdateData(vtkImageData *input)
{
  // update the markers if available
  if (this->Window)
    {
    // free/resize old markers if needed
#ifdef KWVolView_PLUGINS_USE_MARKER
    vtkVVDataItem *dataItem = this->Window->GetSelectedDataItem();
    int nb_of_markers = vtkVVHandleWidget::GetNumberOfHandlesInDataItem(
          dataItem);
    //vtkKW3DMarkersWidget *markers = 
    //  this->Window->GetVolumeWidget()->GetMarkers3D();
    //int nb_of_markers  = markers->GetNumberOfMarkers();
    if (this->PluginInfo.NumberOfMarkers != nb_of_markers)
      {
      if (this->PluginInfo.Markers)
        {
        delete [] this->PluginInfo.Markers;
        }
      if (this->PluginInfo.MarkersGroupId)
        {
        delete [] this->PluginInfo.MarkersGroupId;
        }
      if (nb_of_markers)
        {
        this->PluginInfo.Markers = new float [nb_of_markers * 3];
        this->PluginInfo.MarkersGroupId = new MarkersGroupIdType [nb_of_markers ];
        }
      else
        {
        this->PluginInfo.Markers = 0;
        this->PluginInfo.MarkersGroupId = 0;
        }
      this->PluginInfo.NumberOfMarkers = nb_of_markers;
      }
    float *ptr = this->PluginInfo.Markers;
    for (int i = 0; i < nb_of_markers; ++i)
      {
      vtkVVHandleWidget *handle = 
        vtkVVHandleWidget::GetNthHandleInDataItem( dataItem, i );
      double pos[3];
      handle->GetWorldPosition(pos);
      *ptr++ = pos[0];
      *ptr++ = pos[1];
      *ptr++ = pos[2];
      }
    // Managing Markers Groups
    // Not implemented as of now in vtkVVHandleWidget.
    MarkersGroupIdType *mgptr = this->PluginInfo.MarkersGroupId;
    for (int i = 0; i < nb_of_markers; ++i)
      {
      MarkersGroupIdType groupId = 0; //markers->GetMarkerGroupId(i);
      *mgptr++ = groupId;
      }
    int nb_of_markers_groups  = 1; //markers->GetNumberOfMarkersGroups();
    typedef char * charptr;
    if (this->PluginInfo.NumberOfMarkersGroups != nb_of_markers_groups)
      {
      if (this->PluginInfo.MarkersGroupName)
        {
        for(int i=0; i < this->PluginInfo.NumberOfMarkersGroups; i++)
          {
          if( this->PluginInfo.MarkersGroupName[i] )
            {
            delete []  this->PluginInfo.MarkersGroupName[i];
            }
          }
        delete [] this->PluginInfo.MarkersGroupName;
        }
      if (nb_of_markers_groups)
        {
        this->PluginInfo.MarkersGroupName = new charptr [nb_of_markers_groups ];
        for(int i=0; i < nb_of_markers_groups; ++i)
          {
          this->PluginInfo.MarkersGroupName[i] = 0;
          }
        }
      else
        {
        this->PluginInfo.MarkersGroupName = 0;
        }
      this->PluginInfo.NumberOfMarkersGroups = nb_of_markers_groups;
      }
    charptr * groupNames = this->PluginInfo.MarkersGroupName;
    for (int i = 0; i < nb_of_markers_groups; ++i, ++groupNames )
      {
      if( *groupNames )
        {
        delete []  (*groupNames);
        }
      const char * name  = "Seeds"; //markers->GetMarkersGroupName(i);
      const int len = (int)strlen( name ) + 1;
      *groupNames = new char [ len ];
      memcpy(*groupNames, name, len );
      }
#endif
    // set the cropping plane values
    // FIXME: Cropping planes need hooks..
    if (!this->PluginInfo.CroppingPlanes)
      {
      this->PluginInfo.CroppingPlanes = new float [6];
      this->PluginInfo.CroppingPlanes[0] = VTK_FLOAT_MIN;
      this->PluginInfo.CroppingPlanes[2] = VTK_FLOAT_MIN;
      this->PluginInfo.CroppingPlanes[4] = VTK_FLOAT_MIN;
      this->PluginInfo.CroppingPlanes[1] = VTK_FLOAT_MAX;
      this->PluginInfo.CroppingPlanes[3] = VTK_FLOAT_MAX;
      this->PluginInfo.CroppingPlanes[5] = VTK_FLOAT_MAX;
      }
    vtkVVDataItemVolume *volume_data = vtkVVDataItemVolume::SafeDownCast(
                                    this->Window->GetSelectedDataItem());
    
    if (volume_data && volume_data->GetVolumeWidget(this->Window))
      {
      double *vw_planes = volume_data->GetVolumeWidget(this->Window)->
                                                  GetCroppingPlanes();
      for (int i = 0; i < 6; i++)
        {
        this->PluginInfo.CroppingPlanes[i] = vw_planes[i];
        }
      }
    }
  
  if (!input)
    {
    return;
    }
  // let the plugin know about the new data
  this->PluginInfo.InputVolumeScalarType = input->GetScalarType();
  this->PluginInfo.InputVolumeScalarSize = input->GetScalarSize();
  this->PluginInfo.InputVolumeNumberOfComponents = 
    input->GetNumberOfScalarComponents();
  int i;
  for (i = 0; i < 3; i++)
    {
    this->PluginInfo.InputVolumeDimensions[i] = input->GetDimensions()[i];
    this->PluginInfo.InputVolumeSpacing[i] = input->GetSpacing()[i];
    }
  // compute the ranges
  vtkDataArray *scalars = input->GetPointData()->GetScalars();
  double ftmp[2];
  for (i = 0; i < this->PluginInfo.InputVolumeNumberOfComponents; ++i)
    {
    scalars->GetRange(ftmp,i);
    this->PluginInfo.InputVolumeScalarRange[2*i] = ftmp[0];
    this->PluginInfo.InputVolumeScalarRange[2*i+1] = ftmp[1];
    }
  this->PluginInfo.InputVolumeScalarTypeRange[0] = input->GetScalarTypeMin();
  this->PluginInfo.InputVolumeScalarTypeRange[1] = input->GetScalarTypeMax();
  
  // we do adjust the origin because the plugin is zero extent based
  double *origin = input->GetOrigin();
  this->PluginInfo.InputVolumeOrigin[0] = 
    origin[0] + input->GetSpacing()[0]*input->GetWholeExtent()[0];
  this->PluginInfo.InputVolumeOrigin[1] = 
    origin[1] + input->GetSpacing()[1]*input->GetWholeExtent()[2];
  this->PluginInfo.InputVolumeOrigin[2] = 
    origin[2] + input->GetSpacing()[2]*input->GetWholeExtent()[4];
  // Update the GUI
  this->UpdateGUI();
}
//----------------------------------------------------------------------------
void vtkVVPlugin::UpdateGUI()
{
  int i;
  this->PluginInfo.UpdateGUI(&this->PluginInfo);
  if (!this->Widgets)
    {
    return;
    }
  // for each GUI component ...
  for (i = 0; i < this->NumberOfGUIItems; ++i)
    {
    // update the actual widgets
    switch (this->GUIItems[i].GUIType) 
      {
      case VV_GUI_SCALE:
      {
      vtkKWScaleWithEntry *s = 
        vtkKWScaleWithEntry::SafeDownCast(this->Widgets[2*i+1]);
      double range[3];
      sscanf(this->GUIItems[i].Hints,"%lf %lf %lf",
             range, range+1, range+2);
      s->SetResolution(range[2]);
      s->SetRange(range[0],range[1]);
      s->SetLabelText(this->GUIItems[i].Label);
      if (this->GUIItems[i].Help)
        {
        s->SetBalloonHelpString(this->GUIItems[i].Help);
        }
      }
      break;
      case VV_GUI_CHOICE:
      {
      vtkKWLabel *l = vtkKWLabel::SafeDownCast(this->Widgets[2*i]);
      l->SetText(this->GUIItems[i].Label);
      vtkKWMenuButton *s = vtkKWMenuButton::SafeDownCast(this->Widgets[2*i+1]);
      ostrstream old_value;
      old_value << s->GetValue() << ends;
      ostrstream first_value;
      s->GetMenu()->DeleteAllItems();
      // extract the GUI from the hints
      int numEntries;
      sscanf(this->GUIItems[i].Hints,"%i",&numEntries);
      const char *pos = this->GUIItems[i].Hints;
      char tmp[1024];
      int j;
      for (j = 0; j < numEntries; ++j)
        {
        pos = strchr(pos,'\n') + 1;
        int k = 0;
        while (pos[k] != '\n' && pos[k] != '\0')
          {
          tmp[k] = pos[k];
          k++;
          }
        tmp[k] = '\0';
        s->GetMenu()->AddRadioButton(tmp);
        if (!j)
          {
          first_value << tmp << ends;
          }
        }
      if (s->GetMenu()->HasItem(old_value.str()))
        {
        s->SetValue(old_value.str());
        }
      else
        {
        s->SetValue(first_value.str());
        }
      old_value.rdbuf()->freeze(0);
      first_value.rdbuf()->freeze(0);
      if (this->GUIItems[i].Help)
        {
        s->SetBalloonHelpString(this->GUIItems[i].Help);
        }
      }
      break;
      case VV_GUI_CHECKBOX:
      {
      vtkKWCheckButton *s = 
        vtkKWCheckButton::SafeDownCast(this->Widgets[2*i+1]);
      s->SetText(this->GUIItems[i].Label);
      if (this->GUIItems[i].Help)
        {
        s->SetBalloonHelpString(this->GUIItems[i].Help);
        }
      }
      break;
      }
    }
}
//----------------------------------------------------------------------------
void vtkVVPlugin::GetGUIValues()
{
  if (!this->Widgets)
    {
    return;
    }
  int i;
  char tmp[1024];
  for (i = 0; i < this->NumberOfGUIItems; ++i)
    {
    switch (this->GUIItems[i].GUIType) 
      {
      case VV_GUI_SCALE:
      {
      vtkKWScaleWithEntry *s = 
        vtkKWScaleWithEntry::SafeDownCast(this->Widgets[2*i+1]);
      float v = s->GetValue();
      sprintf(tmp,"%f",v);
      this->SetGUIProperty(i, VVP_GUI_VALUE, tmp);
      }
      break;
      case VV_GUI_CHOICE:
      {
      vtkKWMenuButton *s = vtkKWMenuButton::SafeDownCast(this->Widgets[2*i+1]);
      this->SetGUIProperty(i, VVP_GUI_VALUE, s->GetValue());
      }
      break;
      case VV_GUI_CHECKBOX:
      {
      vtkKWCheckButton *s = 
        vtkKWCheckButton::SafeDownCast(this->Widgets[2*i+1]);
      sprintf(tmp, "%i",s->GetSelectedState());
      this->SetGUIProperty(i, VVP_GUI_VALUE, tmp);
      }
      break;
      }
    }
}
//----------------------------------------------------------------------------
void vtkVVPlugin::SetGUIValues()
{
  if (!this->Widgets)
    {
    return;
    }
  int i;
  for (i = 0; i < this->NumberOfGUIItems; ++i)
    {
    if (!this->GUIItems[i].Value)
      {
      continue;
      }
    switch (this->GUIItems[i].GUIType) 
      {
      case VV_GUI_SCALE:
      {
      vtkKWScaleWithEntry *s = 
        vtkKWScaleWithEntry::SafeDownCast(this->Widgets[2*i+1]);
      s->SetValue(atof(this->GUIItems[i].Value));
      }
      break;
      case VV_GUI_CHOICE:
      {
      vtkKWMenuButton *s = vtkKWMenuButton::SafeDownCast(this->Widgets[2*i+1]);
      s->SetValue(this->GUIItems[i].Value);
      }
      break;
      case VV_GUI_CHECKBOX:
      {
      vtkKWCheckButton *s = 
        vtkKWCheckButton::SafeDownCast(this->Widgets[2*i+1]);
      s->SetSelectedState(atoi(this->GUIItems[i].Value));
      }
      break;
      }
    }
}
//----------------------------------------------------------------------------
// return 0 if there is not enough memory
// return 1 if there is enough memory but do not keep the input
// return 2 if there is enough memory and you can keep the input
int vtkVVPlugin::CheckMemory(vtkImageData *input)
{
  int *dim = input->GetDimensions();
  // how much memory do we need
  // compute in size as voxels for now 
  vtkLargeInteger inSize;
  int *ext = input->GetExtent();
  inSize = (ext[1]-ext[0]);
  inSize *= (ext[3]-ext[2]); 
  inSize *= (ext[5]-ext[4]);
  
  int outVolScalarSize = 1;
  switch (this->PluginInfo.OutputVolumeScalarType)
    {
    case VTK_FLOAT:
      outVolScalarSize = sizeof(float);
      break;
    case VTK_DOUBLE:
      outVolScalarSize = sizeof(double);
      break;
    case VTK_INT:
    case VTK_UNSIGNED_INT:
      outVolScalarSize = sizeof(int);
      break;
    case VTK_LONG:
    case VTK_UNSIGNED_LONG:
      outVolScalarSize = sizeof(long);
      break;
    case VTK_SHORT:
    case VTK_UNSIGNED_SHORT:
      outVolScalarSize = sizeof(short);
      break;
    }
  vtkLargeInteger outSize;
  outSize = this->PluginInfo.OutputVolumeDimensions[0];
  outSize *= this->PluginInfo.OutputVolumeDimensions[1]; 
  outSize *= this->PluginInfo.OutputVolumeDimensions[2];
  outSize *= this->PluginInfo.OutputVolumeNumberOfComponents;
  outSize *= outVolScalarSize;
  // how much intermediate space is required
  vtkLargeInteger plugSize;
  // special handling for float, we get one decimal of precision
  // PerVoxelMemory Required is bytes per voxel
  plugSize = inSize/ 10;
  plugSize = plugSize * (int)(10*this->PerVoxelMemoryRequired);
  // now make inSize in bytes not voxels
  inSize *= input->GetNumberOfScalarComponents();
  inSize *= input->GetScalarSize();
  vtkKWProcessStatistics *pr = vtkKWProcessStatistics::New();
  long av = pr->GetAvailableVirtualMemory();
  long ap = pr->GetAvailablePhysicalMemory();
  long tv = pr->GetTotalVirtualMemory();
  long tp = pr->GetTotalPhysicalMemory();
  
  pr->Delete();
  // if we received bogus results from pr just return
  if ( av < 0 || ap < 0 || tv < 0 || tp < 0 )
    {
    // assume everything is OK
    return 2;
    }
  
//BTX
#ifdef KWVolView_PLUGINS_USE_SERIES
  if (this->RequiresSeriesInput)
    {
    vtkLargeInteger seriesOneVolumeSize = this->PluginInfo.InputVolumeSeriesScalarSize;
    seriesOneVolumeSize = 
      seriesOneVolumeSize * this->PluginInfo.InputVolumeSeriesNumberOfComponents;
    for(int k=0; k<3; k++)
      {
      seriesOneVolumeSize = 
        seriesOneVolumeSize * this->PluginInfo.InputVolumeSeriesDimensions[k];
      }
    if(this->SupportProcessingSeriesByVolumes)
      {
      plugSize = inSize + seriesOneVolumeSize;
      }
    else
      {
      vtkLargeInteger seriesTotalSize = 
        seriesOneVolumeSize * this->PluginInfo.InputVolumeSeriesNumberOfVolumes; 
      plugSize = inSize + seriesTotalSize;
      }
    }
#endif
//ETX
  // how much memory do we need to run the plugin? There are a few different
  // options on how the plugin can be run.
  vtkLargeInteger runSize;
  vtkLargeInteger runPiecesSize;
  vtkLargeInteger runInPlaceSize;
  
  runSize = outSize + plugSize;
  runPiecesSize = outSize + plugSize;
  runPiecesSize *= 2;
  runInPlaceSize = outSize + plugSize;
  runInPlaceSize *= 2;
  
  // is the plugin is in place then we can ignore outSize
  if (this->SupportInPlaceProcessing)
    {
    runInPlaceSize = plugSize;
    }
  
  if (this->SupportProcessingPieces && 
      this->PluginInfo.OutputVolumeDimensions[0] == dim[0] &&
      this->PluginInfo.OutputVolumeDimensions[1] == dim[1] &&
      this->PluginInfo.OutputVolumeDimensions[2] == dim[2] &&
      this->PluginInfo.OutputVolumeScalarType == input->GetScalarType() &&
      this->PluginInfo.OutputVolumeNumberOfComponents == 
      input->GetNumberOfScalarComponents())
    {
    // ten pieces = 1/10 (then divide by 10 to handle floats)
    runPiecesSize = inSize / 100;
    runPiecesSize = runPiecesSize * (int)(10*this->PerVoxelMemoryRequired);
    // two output buffers each at 1/10 = 1/5
    runPiecesSize = outSize/5 + runPiecesSize;
    }
  // convert into K
  runSize = runSize / 1000;
  runInPlaceSize = runInPlaceSize / 1000;
  runPiecesSize = runPiecesSize / 1000;
  inSize = inSize / 1000;
  outSize = outSize / 1000;
  plugSize = plugSize / 1000;
  // now what is the deal, do we have enough memory?   
  if ( runSize.CastToUnsignedLong() <= .5 * tp &&
       runSize.CastToUnsignedLong() <= .8 * av)
    {
    // everything is OK and we can keep the input
    return 2;
    }
  
  // we can't fit the input and the output easily Can we do it at all? This
  // requires pieces or InPlace processing
  if ( runPiecesSize.CastToUnsignedLong() < .9*av ||
       runInPlaceSize.CastToUnsignedLong() < .9*av )
    {
    if (vtkKWMessageDialog::PopupYesNo( 
          this->GetApplication(), this->Window, "Apply Plugin",
          "Applying this plugin to your data will require most of your "
          "computer's memory. This could result in reduced performance "
          "of VolView. Due to the memory limits you will not be able to "
          "Undo this operation. Do you wish to continue?"
          , vtkKWMessageDialog::WarningIcon ) )
      {
      return 1;
      }
    else
      {
      return 0;
      }
    }
  // no way to load the data
  char buffer[1024];
  sprintf(buffer, "Applying this plugin to your data will NOT fit in your system memory. Please close some applications, increase the amount of swap space, or increase the amount of memory in the computer.\n\nNote: your available memory was estimated at %ld MB (physical or virtual), running this plugin will require %ld MB, in place %ld MB (%s supported), in pieces %ld MB (%s supported). Should this estimation be way off, you can attempt to ignore this message, but be aware that this application may crash.", 
          ((long)av / (long)1024), 
          (long)(runSize.CastToLong() / 1024), 
          (long)(runInPlaceSize.CastToLong() / 1024), 
          (this->SupportInPlaceProcessing ? "is" : "not"),
          (long)(runPiecesSize.CastToLong() / 1024),
          (this->SupportProcessingPieces ? "is" : "not")
    );
  if (vtkKWMessageDialog::PopupYesNo( 
        this->GetApplication(), this->Window, "Apply Plugin",
        buffer, vtkKWMessageDialog::WarningIcon))
    {
    return 2;
    }
  return 0;
}
//----------------------------------------------------------------------------
int vtkVVPlugin::CanBeExecuted(vtkVVPluginSelector *vtkNotUsed(plugins))
{
  vtkVVDataItemVolume *volume_data = vtkVVDataItemVolume::SafeDownCast(
                                  this->Window->GetSelectedDataItem());
  if( volume_data)
    return 
      (this->Window && volume_data->GetImageData() && 
       (!this->RequiresSecondInput || this->SecondInputOptional ||
        (this->SecondInputOpenWizard && 
         this->SecondInputOpenWizard->GetReadyToLoad() != 
         vtkKWOpenWizard::DATA_IS_UNAVAILABLE))
//BTX
#ifdef KWVolView_PLUGINS_USE_SERIES
       &&
       (!this->RequiresSeriesInput || 
        (this->SeriesInputOpenWizard && 
         this->SeriesInputOpenWizard->GetReadyToLoad() != 
         vtkKWOpenWizard::DATA_IS_UNAVAILABLE)) 
#endif
//ETX
       );
  else 
    return false;
}
//----------------------------------------------------------------------------
int vtkVVPlugin::PreparePlugin(vtkVVPluginSelector *plugins)
{
  if (!this->CanBeExecuted(plugins))
    {
    this->SetReportText(
      "Plugin can not be executed, some parameters might be missing "
      "or wrong.");
    return 1;
    }
  // Ensure that a paintbrush widget is selected, if its required by the plugin
  if (this->RequiresLabelInput && !this->GetInputLabelImage())
    {
    this->SetReportText(
      "Plugin can not be executed. This plugin requires a labelmap input. "
      "A paintbrush sketch must be selected in the Widgets panel.");
    return 1;
    }
  // Ensure that a paintbrush widget is selected, if its required by the plugin
  if (this->RequiresLabelInput && !this->GetInputLabelImage())
    {
    this->SetReportText(
      "Plugin can not be executed. This plugin requires a labelmap input. "
      "A paintbrush sketch must be selected in the Widgets panel.");
    return 1;
    }
  
  // Load the second input if it is required
  if (this->RequiresSecondInput && this->SecondInputOpenWizard)
    {
    this->SecondInputOpenWizard->Load(0);
    }
//BTX
#ifdef KWVolView_PLUGINS_USE_SPLINE
  // Resample the spline surfaces if it  is required
  if( this->RequiresSplineSurfaces )
    {
    this->PrepareSplineSurfaces();
    }
#endif
//ETX
  return 0;
}
//BTX
#ifdef KWVolView_PLUGINS_USE_SPLINE
//----------------------------------------------------------------------------
int vtkVVPlugin::PrepareSplineSurfaces()
{
  // passing the spline surfaces as an array of points
  vtkKW3DSplineSurfacesWidget * surfacesWidget =
     this->Window->GetVolumeWidget()->GetSplineSurfaces3D();
  unsigned int numberOfSplineSurfaces = surfacesWidget->GetNumberOfSplineSurfaces();
  // Increase the resolution of the splines in order to ensure a density 
  // higher than the one in the image. For Subdivision splines, the final
  // number of points is proportional to handles * ( 4 ^ resolution ).
  unsigned int * previousResolution = new unsigned int [numberOfSplineSurfaces];
  vtkKW3DSplineSurfacesWidget::Iterator itrSpline = surfacesWidget->Begin();
  vtkKW3DSplineSurfacesWidget::Iterator endSpline = surfacesWidget->End();
  unsigned int k=0; 
  while( itrSpline != endSpline )
    {
    vtkSplineSurfaceWidget * splineSurface = itrSpline->second;
    try
      {
      vtkSubdivisionSplineSurfaceWidget * subdivisionSplineSurface =
          dynamic_cast<vtkSubdivisionSplineSurfaceWidget *>( splineSurface );
      previousResolution[k] = subdivisionSplineSurface->GetResolution();
      subdivisionSplineSurface->SetResolution( previousResolution[k] + 4 ); 
      subdivisionSplineSurface->GenerateSurfacePoints();
      }
    catch(...)
      {
      // find and alternative API for increasing resolution in the surface generation
      }
    ++itrSpline;
    ++k;
    }
  int arrayOfSurfacePointsMustBeCleared = 0;
  unsigned int totalNumberOfSplineSurfacePoints = 0;
  if(this->PluginInfo.NumberOfSplineSurfaces != numberOfSplineSurfaces)
    {
    if(this->PluginInfo.NumberOfSplineSurfacePoints)
      {
      delete [] this->PluginInfo.NumberOfSplineSurfacePoints;
      }
    this->PluginInfo.NumberOfSplineSurfacePoints = new int[ numberOfSplineSurfaces ];
    itrSpline = surfacesWidget->Begin();
    endSpline = surfacesWidget->End();
    unsigned i=0; 
    while( itrSpline != endSpline )
      {
      this->PluginInfo.NumberOfSplineSurfacePoints[i] = 
        surfacesWidget->GetNumberOfPointsInASplineSurface(itrSpline->first.c_str());
      totalNumberOfSplineSurfacePoints += 
            this->PluginInfo.NumberOfSplineSurfacePoints[i]; 
      ++i;
      ++itrSpline;
      }
    arrayOfSurfacePointsMustBeCleared = 1;
    this->PluginInfo.NumberOfSplineSurfaces = numberOfSplineSurfaces;
    }
  else
    {
    unsigned int nss=0;
    itrSpline = surfacesWidget->Begin();
    endSpline = surfacesWidget->End();
    unsigned i=0; 
    while( itrSpline != endSpline )
      {
      unsigned int numberOfPoints = 
        surfacesWidget->GetNumberOfPointsInASplineSurface( itrSpline->first.c_str() );
      if( this->PluginInfo.NumberOfSplineSurfacePoints[nss] != numberOfPoints )
        {
        this->PluginInfo.NumberOfSplineSurfacePoints[nss] = numberOfPoints;
        arrayOfSurfacePointsMustBeCleared = 1;
        }
      ++itrSpline;
      ++nss;
      }
    }
  if( arrayOfSurfacePointsMustBeCleared )
    {
    if(this->PluginInfo.SplineSurfacePoints)
      {
      delete [] this->PluginInfo.SplineSurfacePoints;
      }
    this->PluginInfo.SplineSurfacePoints = new float[3*totalNumberOfSplineSurfacePoints];
    }
  // Copy the points coordinates
  unsigned int numberOfPointCoordinates = 0;
  itrSpline = surfacesWidget->Begin();
  endSpline = surfacesWidget->End();
  unsigned sp=0; 
  while( itrSpline != endSpline )
    {
    const unsigned int numberOfPointsInThisSurface = 
             this->PluginInfo.NumberOfSplineSurfacePoints[sp];
    vtkPoints * points = surfacesWidget->GetPointsInASplineSurface(itrSpline->first.c_str());
    double point[3];
    for(unsigned int p=0; p<numberOfPointsInThisSurface; p++)
      {
      points->GetPoint(p, point );
      this->PluginInfo.SplineSurfacePoints[numberOfPointCoordinates++] = point[0];
      this->PluginInfo.SplineSurfacePoints[numberOfPointCoordinates++] = point[1];
      this->PluginInfo.SplineSurfacePoints[numberOfPointCoordinates++] = point[2];
      }
    ++itrSpline;
    ++sp;
    }
  // Restore the original resolution of the spline surfaces. 
  itrSpline = surfacesWidget->Begin();
  endSpline = surfacesWidget->End();
  unsigned kk=0; 
  while( itrSpline != endSpline )
    {
    vtkSplineSurfaceWidget * splineSurface = 
      surfacesWidget->GetSplineSurfaceWidget(itrSpline->first.c_str());
    try
      {
      vtkSubdivisionSplineSurfaceWidget * subdivisionSplineSurface =
          dynamic_cast<vtkSubdivisionSplineSurfaceWidget *>( splineSurface );
      subdivisionSplineSurface->SetResolution( previousResolution[kk] );
      subdivisionSplineSurface->GenerateSurfacePoints();
      }
    catch(...)
      {
      // find and alternative API for increasing resolution in the surface generation
      }
    ++itrSpline;
    ++kk;
    }
  delete [] previousResolution;
  return 0;
}
#endif
//ETX
//----------------------------------------------------------------------------
// Get the label map image, if any for this volume. If there are more than
// one, get the first one
vtkImageData * vtkVVPlugin::GetInputLabelImage()
{
  if (!this->RequiresLabelInput)
    {
    return NULL;
    }
  if (vtkVVWindow *win = vtkVVWindow::SafeDownCast(this->Window))
    {
    if (vtkVVWidgetInterface *wi = win->GetWidgetInterface())
      {
      vtkVVInteractorWidgetSelector *iws = wi->GetInteractorWidgetSelector();
      // If we have selected a paintbrush widget, use it
      int id = iws->GetIdOfSelectedPreset();
      if (id != -1)
        {
        if (vtkKWEPaintbrushWidget *paintbrush =
              vtkKWEPaintbrushWidget::SafeDownCast(
                iws->GetPresetInteractorWidget(id)))
          {
          vtkKWEPaintbrushRepresentation * rep =
            vtkKWEPaintbrushRepresentation::SafeDownCast(paintbrush->GetRepresentation());
          vtkKWEPaintbrushDrawing *drawing = rep->GetPaintbrushDrawing();
          return vtkKWEPaintbrushLabelData::SafeDownCast(
              drawing->GetPaintbrushData())->GetLabelMap();
          }
        }
      // Use any paintbrush in the list, since one is not selected.
      if (vtkVVSelectionFrame *sel_frame = 
          this->Window->GetSelectedSelectionFrame())
        {
        const int nb_interactors = sel_frame->GetNumberOfInteractorWidgets();
        for (int i = 0; i < nb_interactors; i++)
          {
          if (vtkKWEPaintbrushWidget *paintbrush = 
                vtkKWEPaintbrushWidget::SafeDownCast(
                    sel_frame->GetNthInteractorWidget(i)))
            {
            // Select this one.
            iws->SelectPreset(iws->GetIdOfInteractorWidget(paintbrush));
            vtkKWEPaintbrushRepresentation * rep =
              vtkKWEPaintbrushRepresentation::SafeDownCast(paintbrush->GetRepresentation());
            vtkKWEPaintbrushDrawing *drawing = rep->GetPaintbrushDrawing();
            return vtkKWEPaintbrushLabelData::SafeDownCast(
                drawing->GetPaintbrushData())->GetLabelMap();
            }
          }
        }
      // Since there isn't a paintbrush widget for this dataitem, create one
      wi->InteractorWidgetAddDefaultInteractorCallback(
          vtkVVInteractorWidgetSelector::PaintbrushWidget);
      id = iws->GetIdOfSelectedPreset();
      if (id != -1)
        {
        if (vtkKWEPaintbrushWidget *paintbrush =
              vtkKWEPaintbrushWidget::SafeDownCast(
                iws->GetPresetInteractorWidget(id)))
          {
          vtkKWEPaintbrushRepresentation * rep =
            vtkKWEPaintbrushRepresentation::SafeDownCast(paintbrush->GetRepresentation());
          vtkKWEPaintbrushDrawing *drawing = rep->GetPaintbrushDrawing();
          return vtkKWEPaintbrushLabelData::SafeDownCast(
              drawing->GetPaintbrushData())->GetLabelMap();
          }
        }
      }
    }
  return NULL;
}
//----------------------------------------------------------------------------
void vtkVVPlugin::Execute(vtkVVPluginSelector *plugins)
{
  this->SetReportText(NULL);
  if (this->GetStopWatchText() && *this->GetStopWatchText())
    {
    this->SetStopWatchText("Executing...");
    }
  
  // Validate params and load second input
  if (this->PreparePlugin(plugins))
    {
    return;
    }
  clock_t start_clock = clock();
  vtkVVDataItemVolume *volume_data = vtkVVDataItemVolume::SafeDownCast(
                                  this->Window->GetSelectedDataItem());
  if (!volume_data) return;
  // Execute the plugin
  this->ExecuteData(volume_data->GetImageData(), plugins);
  clock_t delta = clock() - start_clock;
  // Free the second input if it is required
  if (this->RequiresSecondInput && this->SecondInputOpenWizard)
    {
    this->SecondInputOpenWizard->Release(0);
    }
//BTX
#ifdef KWVolView_PLUGINS_USE_SERIES
  // Free the series input if it is required
  if (this->RequiresSeriesInput && this->SeriesInputOpenWizard)
    {
    this->SeriesInputOpenWizard->Release();
    }
#endif
//ETX
  this->GetWindow()->SetStatusText("");
  this->GetWindow()->GetProgressGauge()->SetValue(0);
  if (this->AbortProcessing)
    {
    this->SetReportText("Plugin execution was canceled!");
    }
  // Display how long it took
  char buf[100];
  sprintf(buf, "Done in %0.2f s.", (double)(delta) / (double)CLOCKS_PER_SEC);
  this->SetStopWatchText(buf);
  vtkImageData *inLabelImage = this->GetInputLabelImage();
  if (inLabelImage && this->RequiresLabelInput)
    {
    inLabelImage->Modified();
    // Collapse the history. Since the plugins modify the paintbrush data under
    // the hood, we can't manage undo/redo here.
    if (vtkKWEPaintbrushDrawing *drawing = this->GetPaintbrushDrawing())
      {
      drawing->CollapseHistory();
      }
    }
}
//----------------------------------------------------------------------------
void vtkVVPlugin::Cancel(vtkVVPluginSelector *vtkNotUsed(plugins))
{
  this->SetProperty(VVP_ABORT_PROCESSING,"1");
}
//----------------------------------------------------------------------------
void vtkVVPlugin::ExecuteData(vtkImageData *input, vtkVVPluginSelector *plugins)
{
  if (!input)
    {
    return;
    }
  // based on the parameters of the plugin, process the input data to produce
  // a new result. Make sure the properties are up to date as well
  this->UpdateData(input);
  
  // when plugin execute we break the connection with the reader
  //input->SetSource(0);
  // the structure that gets passed to the plugin
  vtkVVProcessDataStruct pds;
  this->AbortProcessing = 0;
  this->ProgressMinimum = 0;
  this->ProgressMaximum = 1;
//BTX
#ifdef KWVolView_PLUGINS_USE_SPLINE
  pds.NumberOfMeshPoints = 0;
  pds.MeshScalars = 0;
  pds.MeshNormals = 0;
#endif
#ifdef KWVolView_PLUGINS_USE_SERIES
  pds.inDataSeries = 0;
  pds.outDataSeries = 0;
#endif
//ETX
  pds.outDataPlotting = 0;
  
  // make sure the GUI values are up to date
  this->GetGUIValues();
  this->Update();
  // clear any undo data
  plugins->SetUndoData(0);
  this->SetResultingDistanceUnits(0);
  this->SetResultingComponent1Units(0);
  this->SetResultingComponent2Units(0);
  this->SetResultingComponent3Units(0);
  this->SetResultingComponent4Units(0);
  this->ResultingComponentsAreIndependent = -1;
   
  // Get the paintbrush label image.
  vtkImageData *inLabelImage = this->GetInputLabelImage();
  pds.inLabelData = inLabelImage ? inLabelImage->GetScalarPointer() : NULL;
  // set the second input for those that use it
  if (this->RequiresSecondInput && 
      !this->SecondInputIsUnstructuredGrid && 
      this->SecondInputOpenWizard && 
      this->SecondInputOpenWizard->GetOutput(0))
    {
    pds.inData2 = this->SecondInputOpenWizard->GetOutput(0)->GetScalarPointer();
    } 
  if (this->RequiresSecondInput && 
      this->SecondInputOpenWizard && 
      this->SecondInputIsUnstructuredGrid && 
      this->SecondInputOpenWizard->GetUnstructuredGridOutput(0))
    {
    pds.inData2 = (void *)(this->SecondInputOpenWizard->GetUnstructuredGridOutput(0));
    }
  
//BTX
#ifdef KWVolView_PLUGINS_USE_SERIES
  // set the series input for those that use it
  if (this->RequiresSeriesInput && 
      this->SeriesInputOpenWizard && 
      this->SeriesInputOpenWizard->GetLastReader() &&
     !this->SupportProcessingSeriesByVolumes )
    {
    // Replace this with an allocation for N x DataSet size buffer,
    // memcpying the buffer of all the input datasets in the serie.
    int numberOfSeries = this->PluginInfo.InputVolumeSeriesNumberOfVolumes;
    int volumeSizeInBytes = this->PluginInfo.InputVolumeSeriesScalarSize;
    for(int k=0; k<3; k++)
      {
      volumeSizeInBytes *= this->PluginInfo.InputVolumeSeriesDimensions[k];
      }
    pds.inDataSeries = new char [ numberOfSeries * volumeSizeInBytes ];
    for(int s=0; s<numberOfSeries; s++)
      {
      char * destination = (char *)(pds.inDataSeries)+(s*volumeSizeInBytes);
      vtkImageData * volume = this->SeriesInputOpenWizard->GetSeriesOutput(s);
      if( volume && volume->GetScalarPointer() )
        {
        memcpy(destination, volume->GetScalarPointer(), volumeSizeInBytes);
        }
      else
        {
        // if any of the datasets is not available, series data cannot be
        // passed to the pluging.
        if( pds.inDataSeries )
          {
          delete [] (char *)(pds.inDataSeries);
          }
        pds.inDataSeries = 0;
        break;
        }
      }
    }
#endif
 
#ifdef KWVolView_PLUGINS_USE_SPLINE
  // if it only does a mesh handle that
  if (this->ProducesMeshOnly)
    {
    pds.inData = input->GetScalarPointer();
    pds.outData = input->GetScalarPointer();
    pds.StartSlice = 0;
#ifdef KWVolView_PLUGINS_USE_SERIES
    pds.CurrentVolumeFromSeries = 0;
#endif
    pds.NumberOfSlicesToProcess = input->GetDimensions()[2];
    this->PluginInfo.ProcessData(&this->PluginInfo, &pds);
    // update the GUI
    plugins->Update();
    return;
    }
#endif
#ifdef KWVolView_PLUGINS_USE_SERIES
  // if it produces a volume series as output
  if (this->ProducesSeriesOutput)
    {
    pds.inData = input->GetScalarPointer();
    pds.outData = input->GetScalarPointer();
    pds.StartSlice = 0;
    pds.CurrentVolumeFromSeries = 0;
    pds.NumberOfSlicesToProcess = 0;
    int outVolScalarSize = 1;
    switch (this->PluginInfo.OutputVolumeSeriesScalarType)
      {
      case VTK_FLOAT:
        outVolScalarSize = sizeof(float);
        break;
      case VTK_DOUBLE:
        outVolScalarSize = sizeof(double);
        break;
      case VTK_INT:
      case VTK_UNSIGNED_INT:
        outVolScalarSize = sizeof(int);
        break;
      case VTK_LONG:
      case VTK_UNSIGNED_LONG:
        outVolScalarSize = sizeof(long);
        break;
      case VTK_SHORT:
      case VTK_UNSIGNED_SHORT:
        outVolScalarSize = sizeof(short);
        break;
      }
    this->PluginInfo.OutputVolumeSeriesScalarSize = outVolScalarSize;
    // Allocate memory for receiving the output series in a single block.
    const int outputSeriesSize = 
      this->PluginInfo.OutputVolumeSeriesNumberOfVolumes *
      this->PluginInfo.OutputVolumeSeriesScalarSize *
      this->PluginInfo.OutputVolumeSeriesNumberOfComponents *
      this->PluginInfo.OutputVolumeSeriesDimensions[0] *
      this->PluginInfo.OutputVolumeSeriesDimensions[1] *
      this->PluginInfo.OutputVolumeSeriesDimensions[2];
    
    if( outputSeriesSize )
      {
      pds.outDataSeries = new char[ outputSeriesSize ];
      }
    }
#endif
//ETX
  // otherwise check first for memory issues
  int memCheck = this->CheckMemory(input);
  if (!memCheck)
    {
    return;
    }
  // For plugins that produce as output array data to be plotted in 2D.
  // Here we allocate the memory needed for returning the data array.
  // We assume that the memory size of this array is negligeable compared
  // to the volume data itself, therefore we don't count this array on the
  // CheckMemory() function above.
  if( this->ProducesPlottingOutput )
    {
    const int arraySize = 
      this->PluginInfo.OutputPlottingNumberOfRows *
      this->PluginInfo.OutputPlottingNumberOfColumns;
    if( arraySize )
      {
      pds.outDataPlotting = new double[arraySize];
      }
    }
//BTX
#ifdef KWVolView_PLUGINS_USE_SERIES
  if( !this->RequiresSeriesInput && !this->ProducesSeriesOutput )
#endif
//ETX
    {
    // if we have the memory, and the plugin is not expecting a series
    // on a volume-by-volume basis, then just pass it in in one piece
    if (memCheck == 2)
      {
      this->ProcessInOnePiece(input, memCheck, &pds, plugins);
      this->DisplayPlot(&pds);
      return;
      }
    
    // if it supports in place processing then that is the easiest
    // but if we have the memory we might as well keep the input
    // around 
    if (this->SupportInPlaceProcessing)
      {
      // make sure the other values are consistent with in place 
      // processing as well
      if (this->PluginInfo.OutputVolumeDimensions[0] !=
          input->GetDimensions()[0] ||
          this->PluginInfo.OutputVolumeDimensions[1] !=
          input->GetDimensions()[1] ||
          this->PluginInfo.OutputVolumeDimensions[2] !=
          input->GetDimensions()[2] ||
          this->PluginInfo.OutputVolumeScalarType !=
          input->GetScalarType())
        {
        vtkErrorMacro("A plugin specified incorrectly that it could perform in place processing!");
        return;
        }
      pds.inData = input->GetScalarPointer();
      pds.outData = input->GetScalarPointer();
      pds.StartSlice = 0;
      pds.CurrentVolumeFromSeries = 0;
      pds.NumberOfSlicesToProcess = input->GetDimensions()[2];
      this->PluginInfo.ProcessData(&this->PluginInfo, &pds);
      input->Modified();
      this->PushNewProperties();
      this->DisplayPlot(&pds);
      return;
      }
    // handle the next case which is that the output type and extent are the
    // same as the input, but it cannot process in place
    int *dim = input->GetDimensions();
    if (this->SupportProcessingPieces && 
        this->PluginInfo.OutputVolumeDimensions[0] == dim[0] &&
        this->PluginInfo.OutputVolumeDimensions[1] == dim[1] &&
        this->PluginInfo.OutputVolumeDimensions[2] == dim[2] &&
        this->PluginInfo.OutputVolumeScalarType == input->GetScalarType() &&
        this->PluginInfo.OutputVolumeNumberOfComponents == 
        input->GetNumberOfScalarComponents() 
//BTX
#ifdef KWVolView_PLUGINS_USE_SERIES
        && !this->RequiresSeriesInput 
#endif
//ETX
      )
      {
      this->ProcessInPieces(input,memCheck, &pds);
      }
    }
//BTX
#ifdef KWVolView_PLUGINS_USE_SERIES
  else
    {
    // if we have the memory, and the plugin is not expecting a series
    // on a volume-by-volume basis, then just pass it in in one piece
    if (memCheck == 2 && !this->SupportProcessingSeriesByVolumes)
      {
      this->ProcessInOnePiece(input, memCheck, &pds, plugins);
      }
    else
      {
      if( this->RequiresSeriesInput && this->SupportProcessingSeriesByVolumes )
        {
        // this plugin can process an input series, volume by volume.
        this->ProcessSeriesByVolumes(input,memCheck, &pds, plugins);
        }
      else
        {
        // if all else failed, process in one piece and discard the input
        this->ProcessInOnePiece(input, memCheck, &pds, plugins);
        }
      }
    // Release intermediate memory that may have been used for passing the series
    // input data.
    if( pds.inDataSeries )
      {
      delete [] (char *)(pds.inDataSeries);
      pds.inDataSeries = 0;
      }
    // If the plugin produced a volume series as output we deal here with
    // saving those volumes.
    if( this->ProducesSeriesOutput )
      {
      this->SaveVolumeSeries(&pds);
      
      // Release intermediate memory that may have been used for passing the series
      // output data.
      if( pds.outDataSeries )
        {
        delete [] (char *)(pds.outDataSeries);
        pds.outDataSeries = 0;
        }
      }
    }
#endif
//ETX
  this->DisplayPlot(&pds);
  
  // The paintbrush may have been modified. Update timestamp
  if (inLabelImage && this->RequiresLabelInput)
    {
    inLabelImage->Modified();
    // Collapse the history. Since the plugins modify the paintbrush data under
    // the hood, we can't manage undo/redo here.
    if (vtkKWEPaintbrushDrawing *drawing = this->GetPaintbrushDrawing())
      {
      drawing->CollapseHistory();
      }
    }
}
//----------------------------------------------------------------------------
vtkKWEPaintbrushDrawing * vtkVVPlugin::GetPaintbrushDrawing()
{
  if (vtkVVWindow *win = vtkVVWindow::SafeDownCast(this->Window))
    {
    if (vtkVVWidgetInterface *wi = win->GetWidgetInterface())
      {
      vtkVVInteractorWidgetSelector *iws = wi->GetInteractorWidgetSelector();
      // If we have selected a paintbrush widget, use it
      int id = iws->GetIdOfSelectedPreset();
      if (id != -1)
        {
        if (vtkKWEPaintbrushWidget *paintbrush =
              vtkKWEPaintbrushWidget::SafeDownCast(
                iws->GetPresetInteractorWidget(id)))
          {
          vtkKWEPaintbrushRepresentation * rep =
            vtkKWEPaintbrushRepresentation::SafeDownCast(paintbrush->GetRepresentation());
          vtkKWEPaintbrushDrawing *drawing = rep->GetPaintbrushDrawing();        return drawing;
          }
        }
      }
    }
  return NULL;
}
  
//----------------------------------------------------------------------------
void vtkVVPlugin::ProcessInPieces(vtkImageData *input, 
                                  int vtkNotUsed(memCheck),
                                  vtkVVProcessDataStruct *pds)
{
  // break the input volume into pieces and pass them into the plugin
  // allocate a temp buffers to store the output
  int *dim = input->GetDimensions();
  int bufferSlices = dim[2]/10;
  if (bufferSlices < this->RequiredZOverlap)
    {
    bufferSlices =this->RequiredZOverlap;
    }
  unsigned char *buffer1 = new unsigned char [
    input->GetScalarSize()*bufferSlices*
    input->GetNumberOfScalarComponents()*dim[0]*dim[1]];
  unsigned char *buffer2 = new unsigned char [
    input->GetScalarSize()*bufferSlices*
    input->GetNumberOfScalarComponents()*dim[0]*dim[1]];
  unsigned char *bufferPtr;
  int buffer1Size;
  int buffer2Size = 0;
  int buffer1Slice = 0;
  int buffer2Slice = 0;
  int numSlicesToProcess;
  int abort = 0;
  while (!this->AbortProcessing && !abort && buffer1Slice < dim[2])
    {
    // run the plugin
    numSlicesToProcess = bufferSlices;
    if (buffer1Slice + numSlicesToProcess > dim[2])
      {
      numSlicesToProcess = dim[2] - buffer1Slice;
      }
    this->ProgressMinimum = (float)buffer1Slice/dim[2];
    this->ProgressMaximum = 
      (float)(buffer1Slice + numSlicesToProcess)/dim[2];
    buffer1Size = dim[0]*dim[1]*numSlicesToProcess*input->GetScalarSize()
      *input->GetNumberOfScalarComponents();
    pds->inData = input->GetScalarPointer();
    pds->outData = buffer1;
    pds->StartSlice = buffer1Slice;
    pds->NumberOfSlicesToProcess = numSlicesToProcess;
    if (this->PluginInfo.ProcessData(&this->PluginInfo, pds))
      {
      abort = 1;
      }
    
    // if we are past the first run copy results
    if (buffer1Slice > 0)
      {
      // copy results back into the buffer
      memcpy(input->GetScalarPointer(0,0,buffer2Slice),
             buffer2, buffer2Size);
      }
    
    // swap the buffers
    buffer2Slice = buffer1Slice;      
    buffer2Size = buffer1Size;
    bufferPtr = buffer1;
    buffer1 = buffer2;
    buffer2 = bufferPtr;
    
    // move lastSlice
    buffer1Slice += numSlicesToProcess;
    }
  // copy the last group
  memcpy(input->GetScalarPointer(0,0,buffer2Slice),
         buffer2, buffer2Size);
  delete [] buffer1;
  delete [] buffer2;
  input->Modified();  
  if (!this->AbortProcessing && !abort)
    {
    this->PushNewProperties();
    }
  return;
}
  
//----------------------------------------------------------------------------
void vtkVVPlugin::ProcessInOnePiece(vtkImageData *input, int memCheck,
                                    vtkVVProcessDataStruct *pds, 
                                    vtkVVPluginSelector *plugins)
{
  vtkImageData *output;
  // if we have the memory then keep the input and use a new output
  if (memCheck == 2)
    {
    output = vtkImageData::New();
    output->ShallowCopy(input);
    // since the current data is always the input ptr
    // we must swap here
    vtkImageData *tempID = input;
    input = output;
    output = tempID;
    // now the input is really a copy of the input ImageData
    }
  else
    {
    // otherwise we have to allocate the output
    output = input;
    }
  
  int outVolScalarSize = 1;
  switch (this->PluginInfo.OutputVolumeScalarType)
    {
    case VTK_FLOAT:
      outVolScalarSize = sizeof(float);
      break;
    case VTK_DOUBLE:
      outVolScalarSize = sizeof(double);
      break;
    case VTK_INT:
    case VTK_UNSIGNED_INT:
      outVolScalarSize = sizeof(int);
      break;
    case VTK_LONG:
    case VTK_UNSIGNED_LONG:
      outVolScalarSize = sizeof(long);
      break;
    case VTK_SHORT:
    case VTK_UNSIGNED_SHORT:
      outVolScalarSize = sizeof(short);
      break;
    }
  int *outDim = this->PluginInfo.OutputVolumeDimensions;
  int size = outVolScalarSize *
    this->PluginInfo.OutputVolumeNumberOfComponents *
    outDim[0]*outDim[1]*outDim[2];
  unsigned char *buffer1 = new unsigned char [size];
  pds->inData = input->GetScalarPointer();
  pds->outData = buffer1;
  // for in place plugins copy the input to the output
  if (this->SupportInPlaceProcessing)
    {
    memcpy(pds->outData, pds->inData, size);
    }
  pds->StartSlice = 0;
  pds->CurrentVolumeFromSeries = 0;
  pds->NumberOfSlicesToProcess = outDim[2];
  int failed = this->PluginInfo.ProcessData(&this->PluginInfo, pds);
  
  if (!failed && !this->AbortProcessing)
    {
    // now copy the output data to the ImageData instance
    // also adjust all the properties to match the results of the plugin
    output->SetScalarType(this->PluginInfo.OutputVolumeScalarType);
    output->SetSpacing(this->PluginInfo.OutputVolumeSpacing[0],
                       this->PluginInfo.OutputVolumeSpacing[1],
                       this->PluginInfo.OutputVolumeSpacing[2]);
    output->SetNumberOfScalarComponents(
      this->PluginInfo.OutputVolumeNumberOfComponents);
    output->SetExtent(0, 0, 0, 0, 0, 0);
    output->AllocateScalars();
    output->SetExtent(0, outDim[0] - 1, 0, outDim[1] - 1, 0, outDim[2] - 1);
    output->SetWholeExtent(output->GetExtent());
    output->GetPointData()->GetScalars()->SetVoidArray(
      buffer1, size/outVolScalarSize,0);
    // if we have kept the input, then let the user undo
    if (memCheck == 2)
      {
      // recall that the input here is not the original input anymore. Also, 
      // if a label map is processed, we don't bother to maintain the old 
      // label map. We don't want that kind of memory bloat. So just disable
      // undo in that case.
      output->Modified();
      plugins->SetUndoData(this->RequiresLabelInput == 0 ? input : 0);
      input->Delete();
      }
    // this must come after the SetUndoData
    this->PushNewProperties();
    }
  else
    {
    // if we have kept the input, then restore it
    if (memCheck == 2)
      {
      int *inDim = this->PluginInfo.InputVolumeDimensions;
      int inSize = this->PluginInfo.InputVolumeScalarSize*
        this->PluginInfo.InputVolumeNumberOfComponents *
        inDim[0]*inDim[1]*inDim[2];
      // take the smaller of the inSize and size.
      if (size > inSize)
        {
        size = inSize;
        }
      memcpy(pds->outData, pds->inData, size);
      input->Delete();
      }
    }
}
 
//BTX
#ifdef KWVolView_PLUGINS_USE_SERIES
//----------------------------------------------------------------------------
void vtkVVPlugin::ProcessSeriesByVolumes(vtkImageData *input, 
                                          int memCheck,
                                          vtkVVProcessDataStruct *pds,
                                          vtkVVPluginSelector *plugins)
{
  // Release memory, if it that was allocated in ExecuteData().
  if( pds->inDataSeries )
    {
    delete [] (char *)(pds->inDataSeries);
    pds->inDataSeries = 0;
    }
  vtkImageData *output;
  // if we have the memory then keep the input and use a new output
  if (memCheck == 2)
    {
    output = vtkImageData::New();
    output->ShallowCopy(input);
    // since the current data is always the input ptr
    // we must swap here
    vtkImageData *tempID = input;
    input = output;
    output = tempID;
    // now the input is really a copy of the input ImageData
    }
  else
    {
    // otherwise we have to allocate the output
    output = input;
    }
   
  int outVolScalarSize = 1;
  switch (this->PluginInfo.OutputVolumeScalarType)
    {
    case VTK_FLOAT:
      outVolScalarSize = sizeof(float);
      break;
    case VTK_DOUBLE:
      outVolScalarSize = sizeof(double);
      break;
    case VTK_INT:
    case VTK_UNSIGNED_INT:
      outVolScalarSize = sizeof(int);
      break;
    case VTK_LONG:
    case VTK_UNSIGNED_LONG:
      outVolScalarSize = sizeof(long);
      break;
    case VTK_SHORT:
    case VTK_UNSIGNED_SHORT:
      outVolScalarSize = sizeof(short);
      break;
    }
  int *outDim = this->PluginInfo.OutputVolumeDimensions;
  int size = outVolScalarSize *
    this->PluginInfo.OutputVolumeNumberOfComponents *
    outDim[0]*outDim[1]*outDim[2];
  unsigned char *buffer1 = new unsigned char [size];
  pds->inData = input->GetScalarPointer();
  pds->outData = buffer1;
  int abort = 0;
  int volumeToProcess = 0;
  while (!this->AbortProcessing && !abort && 
         volumeToProcess < this->PluginInfo.InputVolumeSeriesNumberOfVolumes )
    {
    vtkImageData * volume = this->SeriesInputOpenWizard->GetSeriesOutput(volumeToProcess);
    if( volume && volume->GetScalarPointer() )
      {
      pds->inDataSeries = volume->GetScalarPointer();
      pds->CurrentVolumeFromSeries = volumeToProcess;
      // run the plugin
      if (this->PluginInfo.ProcessData(&this->PluginInfo, pds))
        {
        abort = 1;
        }
      // set it to NULL to prevent others from attempting to release this
      // memory. The memory actually belongs to the reader.
      pds->inDataSeries = 0; 
      }
    else
      {
      vtkErrorMacro("Problem getting access to Volume " << volumeToProcess << " from the series" );
      pds->inDataSeries = 0;
      return;
      }
    volumeToProcess++;
    }
  if (!abort && !this->AbortProcessing)
    {
    // now copy the output data to the ImageData instance
    // also adjust all the properties to match the results of the plugin
    output->SetScalarType(this->PluginInfo.OutputVolumeScalarType);
    output->SetSpacing(this->PluginInfo.OutputVolumeSpacing[0],
                       this->PluginInfo.OutputVolumeSpacing[1],
                       this->PluginInfo.OutputVolumeSpacing[2]);
    output->SetNumberOfScalarComponents(
      this->PluginInfo.OutputVolumeNumberOfComponents);
    output->SetExtent(0, 0, 0, 0, 0, 0);
    output->AllocateScalars();
    output->SetExtent(0, outDim[0] - 1, 0, outDim[1] - 1, 0, outDim[2] - 1);
    output->SetWholeExtent(output->GetExtent());
    output->GetPointData()->GetScalars()->SetVoidArray(
      buffer1, size/outVolScalarSize,0);
    
    // if we have kept the input, then let the user undo
    if (memCheck == 2)
      {
      // recall that the input here is not the original input anymore. Also, 
      // if a label map is processed, we don't bother to maintain the old 
      // label map. We don't want that kind of memory bloat. So just disable
      // undo in that case.
      output->Modified();
      plugins->SetUndoData(this->RequiresLabelInput == 0 ? input : 0);
      input->Delete();
      }
    // this must come after the SetUndoData
    this->PushNewProperties();
    }
  else
    {
    // if we have kept the input, then restore it
    if (memCheck == 2)
      {
      int *inDim = this->PluginInfo.InputVolumeDimensions;
      int inSize = this->PluginInfo.InputVolumeScalarSize*
        this->PluginInfo.InputVolumeNumberOfComponents *
        inDim[0]*inDim[1]*inDim[2];
      // take the smaller of the inSize and size.
      if (size > inSize)
        {
        size = inSize;
        }
      memcpy(pds->outData, pds->inData, size);
      input->Delete();
      }
    }
}
#endif
//ETX
//----------------------------------------------------------------------------
void vtkVVPlugin::PushNewProperties()
{
  // if any properties were set then push them out
  int nb_rw = this->Window->GetNumberOfRenderWidgetsUsingSelectedDataItem();
  for (int i = 0; i < nb_rw; i++)
    {
    vtkKWRenderWidgetPro *rwp = vtkKWRenderWidgetPro::SafeDownCast(
      this->Window->GetNthRenderWidgetUsingSelectedDataItem(i));
    if (!rwp)
      {
      continue;
      }
    if (this->ResultingComponentsAreIndependent >= 0)
      {
      rwp->SetIndependentComponents(
        this->ResultingComponentsAreIndependent);      
      }
    if (this->ResultingDistanceUnits)
      {
      rwp->SetDistanceUnits(this->ResultingDistanceUnits);
      }
    if (this->ResultingComponent1Units)
      {
      rwp->SetScalarUnits(0,this->ResultingComponent1Units);
      }
    if (this->ResultingComponent2Units)
      {
      rwp->SetScalarUnits(1,this->ResultingComponent2Units);
      }
    if (this->ResultingComponent3Units)
      {
      rwp->SetScalarUnits(2,this->ResultingComponent3Units);
      }
    if (this->ResultingComponent4Units)
      {
      rwp->SetScalarUnits(3,this->ResultingComponent4Units);
      }
    }  
}
//BTX
#ifdef KWVolView_PLUGINS_USE_SERIES
//----------------------------------------------------------------------------
int vtkVVPlugin::SaveVolumeSeries(vtkVVProcessDataStruct *pds)
{
  // We must have a volume series from a plugin 
  if (!this->ProducesSeriesOutput || !pds)
    {
    return 0;
    }
  if (!pds->outDataSeries)
    {
    vtkKWMessageDialog::PopupMessage( 
      this->GetApplication(), this->Window, "Save Error", 
      "The plugin did not returned any series data.", vtkKWMessageDialog::ErrorIcon);
    return 0;
    }
  this->Window->DisableRenderStates();
  vtkVV4DSaveDialog *dlg = vtkVV4DSaveDialog::New();
  dlg->SetParent(this);
  dlg->Create();
  dlg->RetrieveLastPathFromRegistry("SavePath");
  int success = 0;
  if (dlg->Invoke() && this->SaveVolumeSeries(pds,dlg->GetFileName()))
    {
    dlg->SaveLastPathToRegistry("SavePath");
    success = 1;
    }
  dlg->Delete();
  this->Window->UpdateAccordingToImageData();
  this->Window->RestoreRenderStates();
  
  return success;
}
//----------------------------------------------------------------------------
int vtkVVPlugin::SaveVolumeSeries(vtkVVProcessDataStruct *pds,const char *fname) 
{
  // We must have a filename and a volume series from a plugin 
  if (!fname || !this->ProducesSeriesOutput || !pds || !pds->outDataSeries)
    {
    return 0;
    }
  vtkImageImport * imageImporter = vtkImageImport::New();
  imageImporter->SetDataScalarType( this->PluginInfo.InputVolumeSeriesScalarType );
  imageImporter->SetNumberOfScalarComponents( 
      this->PluginInfo.InputVolumeSeriesNumberOfComponents );
    
  int wExt[6];
  wExt[0] = 0;
  wExt[1] = this->PluginInfo.InputVolumeSeriesDimensions[0]-1;
  wExt[2] = 0;
  wExt[3] = this->PluginInfo.InputVolumeSeriesDimensions[1]-1;
  wExt[4] = 0;
  wExt[5] = this->PluginInfo.InputVolumeSeriesDimensions[2]-1;
  imageImporter->SetWholeExtent( wExt );
  imageImporter->SetDataExtentToWholeExtent();
  int i;
  double spacing[3];
  for (i = 0; i < 3; i++)
    {
    spacing[i] = this->PluginInfo.InputVolumeSeriesSpacing[i]; 
    }
  imageImporter->SetDataSpacing( spacing );
 
  vtkVV4DSaveVolume *sv = vtkVV4DSaveVolume::New();
  sv->Create();
  sv->SetWindow(this->Window);
  sv->SetInput(imageImporter->GetOutput());  
  vtkLargeInteger seriesOneVolumeSize = this->PluginInfo.OutputVolumeSeriesScalarSize;
  seriesOneVolumeSize = 
    seriesOneVolumeSize * this->PluginInfo.OutputVolumeSeriesNumberOfComponents;
  for(int k=0; k<3; k++)
    {
    seriesOneVolumeSize = 
      seriesOneVolumeSize * this->PluginInfo.OutputVolumeSeriesDimensions[k];
    }
  vtkstd::string fullfilename = fname;
  vtkstd::string filenamePath =
    vtksys::SystemTools::GetFilenamePath(fullfilename);
  vtkstd::string filenameExtension =
    vtksys::SystemTools::GetFilenameLastExtension(fullfilename);
  vtkstd::string filenameWithOutExtension = 
    vtksys::SystemTools::GetFilenameWithoutLastExtension(fullfilename);
  char * filename = new char[filenamePath.size() +
                             filenameWithOutExtension.size() +
                             filenameExtension.size() + 10 ];
  int si=0;
  int writinWasOK = 1;
  while(si < this->PluginInfo.OutputVolumeSeriesNumberOfVolumes && writinWasOK)
    {
    unsigned long offset = seriesOneVolumeSize.CastToUnsignedLong() * si;
    char * initialPointer = (char *)(pds->outDataSeries)+offset;
    imageImporter->SetImportVoidPointer(initialPointer,1);
    imageImporter->Update();
    sprintf( filename, "%s/%s%03i%s", filenamePath.c_str(), 
                                      filenameWithOutExtension.c_str(),
                                      si,filenameExtension.c_str());
    sv->SetFileName(filename);
    writinWasOK = sv->Write();
    if ( !writinWasOK )
      {
      vtkKWMessageDialog::PopupMessage(
        this->GetApplication(), this->Window, "VolView Write Error",
        "There was a problem writing the volume series.\n"
        "Please check the location and make sure you have write\n"
        "permissions and enough disk space.",
        vtkKWMessageDialog::ErrorIcon);
      }
    
    ++si;
    }
  sv->SetInput(0);
  sv->Delete();
  imageImporter->Delete();
  delete [] filename;
  
  return writinWasOK;
}
#endif
//ETX
//----------------------------------------------------------------------------
void vtkVVPlugin::DisplayPlot(vtkVVProcessDataStruct *pds)
{
  if( !pds->outDataPlotting )
    {
    return;
    }
  vtkKWXYPlotDialog * plottingDialog = vtkKWXYPlotDialog::New();
  // Pass the plugin data into the Plotter
  vtkXYPlotActor * plotActor = plottingDialog->GetXYPlotActor();
  vtkPoints   * points = vtkPoints::New();
  
  const vtkIdType numberOfPoints = this->PluginInfo.OutputPlottingNumberOfRows;
  points->SetNumberOfPoints(numberOfPoints);
  vtkIdType pointId=0;
  double pcoord[3];
  pcoord[0] = pcoord[1] = pcoord[2] = 0.0;
  double *px = static_cast<double *>(pds->outDataPlotting);
  while(pointId < numberOfPoints)
    {
    pcoord[0] = *px; // set the independent values as X coordinate of the points.
    points->SetPoint(pointId,pcoord);
    ++pointId;
    ++px;
    }
  const int numberOfSeries= this->PluginInfo.OutputPlottingNumberOfColumns-1;
  int nc=0;
  double *py = static_cast<double *>(pds->outDataPlotting) + numberOfPoints;
  while(nc < numberOfSeries )
    {
    vtkPolyData * dataObject = vtkPolyData::New();
    vtkFieldData * fieldData = vtkFieldData::New();
    vtkDoubleArray * dataSeries = vtkDoubleArray::New();
    dataSeries->SetNumberOfComponents(1);
    dataSeries->SetNumberOfTuples(numberOfPoints);
    vtkIdType dataId=0;
    while(dataId < numberOfPoints)
      {
      dataSeries->InsertValue(dataId,*py);
      ++dataId;
      ++py;
      }
    fieldData->AddArray(dataSeries);
    dataSeries->Delete();
    dataObject->SetFieldData(fieldData);
    fieldData->Delete();
    dataObject->SetPoints(points);
    plotActor->AddDataObjectInput(dataObject);
    dataObject->Delete();
    ++nc;
    }
 
  points->Delete();
  
  if( this->GetPlottingXAxisTitle() )
    {
    plotActor->SetXTitle( this->GetPlottingXAxisTitle() );
    }
  if( this->GetPlottingYAxisTitle() )
    {
    plotActor->SetYTitle( this->GetPlottingYAxisTitle() );
    }
  plottingDialog->Create();
  plottingDialog->SetParent(this->Window);
  
  plottingDialog->Invoke(); // Display as a modal window
  plottingDialog->Delete();
  
  // Release the memory buffer used for data transfer.
  delete [] (double *)(pds->outDataPlotting);
  pds->outDataPlotting = 0;
}
 
//----------------------------------------------------------------------------
void vtkVVPlugin::PrintSelf(ostream& os, vtkIndent indent)
{
  this->Superclass::PrintSelf(os,indent);
  os << indent << "Window: " << this->Window << endl;
  os << indent << "Name: ";
  if (this->Name)
    {
    os << this->Name << endl;
    }
  else
    {
    os << "(none)" << endl;
    }
  os << indent << "Group: ";
  if (this->Group)
    {
    os << this->Group << endl;
    }
  else
    {
    os << "(none)" << endl;
    }
  os << indent << "TerseDocumentation: ";
  if (this->TerseDocumentation)
    {
    os << this->TerseDocumentation << endl;
    }
  else
    {
    os << "(none)" << endl;
    }
  os << indent << "Full Documentation: ";
  if (this->FullDocumentation)
    {
    os << indent << this->FullDocumentation << endl;
    }
  else
    {
    os << indent << "(none)" << endl;
    }
  if (this->ResultingComponent1Units)
    {
    os << indent << this->ResultingComponent1Units << endl;
    }
  else
    {
    os << indent << "(none)" << endl;
    }
  if (this->ResultingComponent2Units)
    {
    os << indent << this->ResultingComponent2Units << endl;
    }
  else
    {
    os << indent << "(none)" << endl;
    }
  if (this->ResultingComponent3Units)
    {
    os << indent << this->ResultingComponent3Units << endl;
    }
  else
    {
    os << indent << "(none)" << endl;
    }
  if (this->ResultingComponent4Units)
    {
    os << indent << this->ResultingComponent4Units << endl;
    }
  else
    {
    os << indent << "(none)" << endl;
    }
  if (this->ResultingDistanceUnits)
    {
    os << indent << this->ResultingDistanceUnits << endl;
    }
  else
    {
    os << indent << "(none)" << endl;
    }
  os << indent << "NumberOfGUIItems: " << this->NumberOfGUIItems << endl;
  os << indent << "RequiresSecondInput: " << this->RequiresSecondInput << endl;
  os << indent << "SecondInputOptional: " << this->SecondInputOptional << endl;  
  os << indent << "RequiresLabelInput: " << this->RequiresLabelInput << endl;
  os << indent << "SecondInputOpenWizard: " << this->SecondInputOpenWizard << endl;
}
 
     |