1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107 2108 2109 2110 2111 2112 2113 2114 2115 2116 2117 2118 2119 2120 2121 2122 2123 2124 2125 2126 2127 2128 2129 2130 2131 2132 2133 2134 2135 2136 2137 2138 2139 2140 2141 2142 2143 2144 2145 2146 2147 2148 2149 2150 2151 2152 2153 2154 2155 2156 2157 2158 2159 2160 2161 2162 2163 2164 2165 2166 2167 2168 2169 2170 2171 2172 2173 2174 2175 2176 2177 2178 2179 2180 2181 2182 2183 2184 2185 2186 2187 2188 2189 2190 2191 2192 2193 2194 2195 2196 2197 2198 2199 2200 2201 2202 2203 2204 2205 2206 2207 2208 2209 2210 2211 2212 2213 2214 2215 2216 2217 2218 2219 2220 2221 2222 2223 2224 2225 2226 2227 2228 2229 2230 2231 2232 2233 2234 2235 2236 2237 2238 2239 2240 2241 2242 2243 2244 2245 2246 2247 2248 2249 2250 2251 2252 2253 2254 2255 2256 2257 2258 2259 2260 2261 2262 2263 2264 2265 2266 2267 2268 2269 2270 2271 2272 2273 2274 2275 2276 2277 2278 2279 2280 2281 2282 2283 2284 2285 2286 2287 2288 2289 2290 2291 2292 2293 2294 2295 2296 2297 2298 2299 2300 2301 2302 2303 2304 2305 2306 2307 2308 2309 2310 2311 2312 2313 2314 2315 2316 2317 2318 2319 2320 2321 2322 2323 2324 2325 2326 2327 2328 2329 2330 2331 2332 2333 2334 2335 2336 2337 2338 2339 2340 2341 2342 2343 2344 2345 2346 2347 2348 2349 2350 2351 2352 2353 2354 2355 2356 2357 2358 2359 2360 2361 2362 2363 2364 2365 2366 2367 2368 2369 2370 2371 2372 2373 2374 2375 2376 2377 2378 2379 2380 2381 2382 2383 2384 2385 2386 2387 2388 2389 2390 2391 2392 2393 2394 2395 2396 2397 2398 2399 2400 2401 2402 2403 2404 2405 2406 2407 2408 2409 2410 2411 2412 2413 2414 2415 2416 2417 2418 2419 2420 2421 2422 2423 2424 2425 2426 2427 2428 2429 2430 2431 2432 2433 2434 2435 2436 2437 2438 2439 2440 2441 2442 2443 2444 2445 2446 2447 2448 2449 2450 2451 2452 2453 2454 2455 2456 2457 2458 2459 2460 2461 2462 2463 2464 2465 2466 2467 2468 2469 2470 2471 2472 2473 2474 2475 2476 2477 2478 2479 2480 2481 2482 2483 2484 2485 2486 2487 2488 2489 2490 2491 2492 2493 2494 2495 2496 2497 2498 2499 2500 2501 2502 2503 2504 2505 2506 2507 2508 2509 2510 2511 2512 2513 2514 2515 2516 2517 2518 2519 2520 2521 2522 2523 2524 2525 2526 2527 2528 2529 2530 2531 2532 2533 2534 2535 2536 2537 2538 2539 2540 2541 2542 2543 2544 2545 2546 2547 2548 2549 2550 2551 2552 2553 2554 2555 2556 2557 2558 2559 2560 2561 2562 2563 2564 2565 2566 2567 2568 2569 2570 2571 2572 2573 2574 2575 2576 2577 2578 2579 2580 2581 2582 2583 2584 2585 2586 2587 2588 2589 2590 2591 2592 2593 2594 2595 2596 2597 2598 2599 2600 2601 2602 2603 2604 2605 2606 2607 2608 2609 2610 2611 2612 2613 2614 2615 2616 2617 2618 2619 2620 2621 2622 2623 2624 2625 2626 2627 2628 2629 2630 2631 2632 2633 2634 2635 2636 2637 2638 2639 2640 2641 2642 2643 2644 2645 2646 2647 2648 2649 2650 2651 2652 2653 2654 2655 2656 2657 2658 2659 2660 2661 2662 2663 2664 2665 2666 2667 2668 2669 2670 2671 2672 2673 2674 2675 2676 2677 2678 2679 2680 2681 2682 2683 2684 2685 2686 2687 2688 2689 2690 2691 2692 2693 2694 2695 2696 2697 2698 2699 2700 2701 2702 2703 2704 2705 2706 2707 2708 2709 2710 2711 2712 2713 2714 2715 2716 2717 2718 2719 2720 2721 2722 2723 2724 2725 2726 2727 2728 2729 2730 2731 2732 2733 2734 2735 2736 2737 2738 2739 2740 2741 2742 2743 2744 2745 2746 2747 2748 2749 2750 2751 2752 2753 2754 2755 2756 2757 2758 2759 2760 2761 2762 2763 2764 2765 2766 2767 2768 2769 2770 2771 2772 2773 2774 2775 2776 2777 2778 2779 2780 2781 2782 2783 2784 2785 2786 2787 2788 2789 2790 2791 2792 2793 2794 2795 2796 2797 2798 2799 2800 2801 2802 2803 2804 2805 2806 2807 2808 2809 2810 2811 2812 2813 2814 2815 2816 2817 2818 2819 2820 2821 2822 2823 2824 2825 2826 2827 2828 2829 2830 2831 2832 2833 2834 2835 2836 2837 2838 2839 2840 2841 2842 2843 2844 2845 2846 2847 2848 2849 2850 2851 2852 2853 2854 2855 2856 2857 2858 2859 2860 2861 2862 2863 2864 2865 2866 2867 2868 2869 2870 2871 2872 2873 2874 2875 2876 2877 2878 2879 2880 2881 2882 2883 2884 2885 2886 2887 2888 2889 2890 2891 2892 2893 2894 2895 2896 2897 2898 2899 2900 2901 2902 2903 2904 2905 2906 2907 2908 2909 2910 2911 2912 2913 2914 2915 2916 2917 2918 2919 2920 2921 2922 2923 2924 2925 2926 2927 2928 2929 2930 2931 2932 2933 2934 2935 2936 2937 2938 2939 2940 2941 2942 2943 2944 2945 2946 2947 2948 2949 2950 2951 2952 2953 2954 2955 2956 2957 2958 2959 2960 2961 2962 2963 2964 2965 2966 2967 2968 2969 2970 2971 2972 2973 2974 2975 2976 2977 2978 2979 2980 2981 2982 2983 2984 2985 2986 2987 2988 2989 2990 2991 2992 2993 2994 2995 2996 2997 2998 2999 3000 3001 3002 3003 3004 3005 3006 3007 3008 3009 3010 3011 3012 3013 3014 3015 3016 3017 3018 3019 3020 3021 3022 3023 3024 3025 3026 3027 3028 3029 3030 3031 3032 3033 3034 3035 3036 3037 3038 3039 3040 3041 3042 3043 3044 3045 3046 3047 3048 3049 3050 3051 3052 3053 3054 3055 3056 3057 3058 3059 3060 3061 3062 3063 3064 3065 3066 3067 3068 3069 3070 3071 3072 3073 3074 3075 3076 3077 3078 3079 3080 3081 3082 3083 3084 3085 3086 3087 3088 3089 3090 3091 3092 3093 3094 3095 3096 3097 3098 3099 3100 3101 3102 3103 3104 3105 3106 3107 3108 3109 3110 3111 3112 3113 3114 3115 3116 3117 3118 3119 3120 3121 3122 3123 3124 3125 3126 3127 3128 3129 3130 3131 3132 3133 3134 3135 3136 3137 3138 3139 3140 3141 3142 3143 3144 3145 3146 3147 3148 3149 3150 3151 3152 3153 3154 3155 3156 3157 3158 3159 3160 3161 3162 3163 3164 3165 3166 3167 3168 3169 3170 3171 3172 3173 3174 3175 3176 3177 3178 3179 3180 3181 3182 3183 3184 3185 3186 3187 3188 3189 3190 3191 3192 3193 3194 3195 3196 3197 3198 3199 3200 3201 3202 3203 3204 3205 3206 3207 3208 3209 3210 3211 3212 3213 3214 3215 3216 3217 3218 3219 3220 3221 3222 3223 3224 3225 3226 3227 3228 3229 3230 3231 3232 3233 3234 3235 3236 3237 3238 3239 3240 3241 3242 3243 3244 3245 3246 3247 3248 3249 3250 3251 3252 3253 3254 3255 3256 3257 3258 3259 3260 3261 3262 3263 3264 3265 3266 3267 3268 3269 3270 3271 3272 3273 3274 3275 3276 3277 3278 3279 3280 3281 3282 3283 3284 3285 3286 3287 3288 3289 3290 3291 3292 3293 3294 3295 3296 3297 3298 3299 3300 3301 3302 3303 3304 3305 3306 3307 3308 3309 3310 3311 3312 3313 3314 3315 3316 3317 3318 3319 3320 3321 3322 3323 3324 3325 3326 3327 3328 3329 3330 3331 3332 3333 3334 3335 3336 3337 3338 3339 3340 3341 3342 3343 3344 3345 3346 3347 3348 3349 3350 3351 3352 3353 3354 3355 3356 3357 3358 3359 3360 3361 3362 3363 3364 3365 3366 3367 3368 3369 3370 3371 3372 3373 3374 3375 3376 3377 3378 3379 3380 3381 3382 3383 3384 3385 3386 3387 3388 3389 3390 3391 3392 3393 3394 3395 3396 3397 3398 3399 3400 3401 3402 3403 3404 3405 3406 3407 3408 3409 3410 3411 3412 3413 3414 3415 3416 3417 3418 3419 3420 3421 3422 3423 3424 3425 3426 3427 3428 3429 3430 3431 3432 3433 3434 3435 3436 3437 3438 3439 3440 3441 3442 3443 3444 3445 3446 3447 3448 3449 3450 3451 3452 3453 3454 3455 3456 3457 3458 3459 3460 3461 3462 3463 3464 3465 3466 3467 3468 3469 3470 3471 3472 3473 3474 3475 3476 3477 3478 3479 3480 3481 3482 3483 3484 3485 3486 3487 3488 3489 3490 3491 3492 3493 3494 3495 3496 3497 3498 3499 3500 3501 3502 3503 3504 3505 3506 3507 3508 3509 3510 3511 3512 3513 3514 3515 3516 3517 3518 3519 3520 3521 3522 3523 3524 3525 3526 3527 3528 3529 3530 3531 3532 3533 3534 3535 3536 3537 3538 3539 3540 3541 3542 3543 3544 3545 3546 3547 3548 3549 3550 3551 3552 3553 3554 3555 3556 3557 3558 3559 3560 3561 3562 3563 3564 3565 3566 3567 3568 3569 3570 3571 3572 3573 3574 3575 3576 3577 3578 3579 3580 3581 3582 3583 3584 3585 3586 3587 3588 3589 3590 3591 3592 3593 3594 3595 3596 3597 3598 3599 3600 3601 3602 3603 3604 3605 3606 3607 3608 3609 3610 3611 3612 3613 3614 3615 3616 3617 3618 3619 3620 3621 3622 3623 3624 3625 3626 3627 3628 3629 3630 3631 3632 3633 3634 3635 3636 3637 3638 3639 3640 3641 3642 3643 3644 3645 3646 3647 3648 3649 3650 3651 3652 3653 3654 3655 3656 3657 3658 3659 3660 3661 3662 3663 3664 3665 3666 3667 3668 3669 3670 3671 3672 3673 3674 3675 3676 3677 3678 3679 3680 3681 3682 3683 3684 3685 3686 3687 3688 3689 3690 3691 3692 3693 3694 3695 3696 3697 3698 3699 3700 3701 3702 3703 3704 3705 3706 3707 3708 3709 3710 3711 3712 3713 3714 3715 3716
|
/*=========================================================================
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 "vtkKWOpenWizard.h"
#include "vtkDirectory.h"
#include "vtkImageData.h"
#include "vtkAlgorithm.h"
#include "vtkKWApplicationPro.h"
#include "vtkKWWindow.h"
#include "vtkObjectFactory.h"
#include "vtkStructuredPoints.h"
#include "vtkStreamingDemandDrivenPipeline.h"
#include "vtkDataSetAttributes.h"
#include "vtkInformation.h"
#include "vtkMedicalImageProperties.h"
#include "vtkImageReslice.h"
#include "vtkStringArray.h"
#include "vtkPointData.h"
#include "vtkCornerAnnotation.h"
#include "vtkUnstructuredGrid.h"
// Some widgets we use
#include "vtkKWCheckButton.h"
#include "vtkKWColorImageConversionFilter.h"
#include "vtkKWEntry.h"
#include "vtkKWFrame.h"
#include "vtkKWIcon.h"
#include "vtkKWImageWidget.h"
#include "vtkKWLabel.h"
#include "vtkKWEntryWithLabel.h"
#include "vtkKWInternationalization.h"
#include "vtkKWLabelWithLabel.h"
#include "vtkKWMenu.h"
#include "vtkKWMenuButtonWithLabel.h"
#include "vtkKWLoadSaveDialog.h"
#include "vtkKWMessageDialog.h"
#include "vtkKWMenuButton.h"
#include "vtkKWOpenFileHelper.h"
#include "vtkKWOpenFileProperties.h"
#include "vtkKWOrientationFilter.h"
#include "vtkKWProgressCommand.h"
#include "vtkKWPushButton.h"
#include "vtkKWRadioButtonSet.h"
#include "vtkKWRadioButton.h"
#include "vtkKWSpinBox.h"
#include "vtkKWSpinBoxWithLabel.h"
#include "vtkDICOMCollectorOptions.h"
// The readers we support
#include "vtkAnalyzeReader.h"
#include "vtkBMPReader.h"
#include "vtkDICOMCollector.h"
#include "vtkDICOMReader.h"
#include "vtkGESignaReader.h"
#include "vtkGESignaReader3D.h"
#include "vtkJPEGReader.h"
#include "vtkLSMReader.h"
#include "vtkPICReader.h"
#include "vtkPNGReader.h"
#include "vtkPNMReader.h"
#include "vtkSLCReader.h"
#include "vtkSTKReader.h"
#include "vtkStructuredPointsReader.h"
#include "vtkTIFFReader.h"
#include "vtkMetaImageReader.h"
#include "vtkXMLImageDataReader.h"
#include <vtksys/SystemTools.hxx>
#include <vtksys/ios/sstream>
#include <vtksys/stl/vector>
#include <sys/stat.h>
#include <time.h>
#define VTK_VV_OW_MULTIPLICITY_SERIES_BUTTON_ID 0
#define VTK_VV_OW_MULTIPLICITY_SINGLE_BUTTON_ID 1
#define VTK_VV_OW_DEFAULT_POSTTEXT_LABEL "\n"
#define VTK_VV_OW_DATA_ORIGIN_UNKNOWN -0.125
#define VTK_VV_OW_DATA_SPACING_UNKNOWN -0.125
#ifdef KWCommonPro_USE_XML_RW
#include "XML/vtkXMLKWOpenFilePropertiesReader.h"
#include "XML/vtkXMLKWOpenFilePropertiesWriter.h"
#endif
//----------------------------------------------------------------------------
vtkStandardNewMacro( vtkKWOpenWizard );
vtkCxxRevisionMacro(vtkKWOpenWizard, "$Revision: 1.96 $");
vtkCxxSetObjectMacro(vtkKWOpenWizard, PreviousReader, vtkAlgorithm);
//----------------------------------------------------------------------------
class vtkKWOpenWizardInternals
{
public:
vtksys_stl::string ScheduleSetupRawPreviewTimerId;
};
//----------------------------------------------------------------------------
vtkKWOpenWizard::vtkKWOpenWizard()
{
this->Internals = new vtkKWOpenWizardInternals;
this->OpenFileHelper = vtkKWOpenFileHelper::New();
this->OpenFileHelper->SetOpenWizard(this);
this->LoadDialog = NULL;
this->ReadyToLoad = vtkKWOpenWizard::DATA_IS_UNAVAILABLE;
this->PreviousReader = NULL;
this->PreviousOpenFileProperties = NULL;
this->Invoked = 0;
this->OrientationFilter = NULL;
this->ColorImageConversionFilter = NULL;
this->SeriesFrame = NULL;
this->PatternEntry = NULL;
this->KMinEntry = NULL;
this->KMaxEntry = NULL;
this->SpatialAttributesFrame = NULL;
this->OriginLabel = NULL;
this->SpacingLabel = NULL;
this->UnitsFrame = NULL;
this->DistanceUnitsEntry = NULL;
int i;
for (i = 0; i < VTK_MAX_VRCOMP; i++)
{
this->ScalarUnitsEntry[i] = 0;
}
for (i = 0; i < 3; i++)
{
this->OriginEntry[i] = 0;
this->SpacingEntry[i] = 0;
}
this->OrientationFrame = NULL;
this->SliceAxisMenu = NULL;
this->RowAxisMenu = NULL;
this->ColumnAxisMenu = NULL;
this->MultiplicityFrame = NULL;
this->MultiplicityChoice = NULL;
this->RawInfoFrame = NULL;
this->Preview = NULL;
this->IDimEntry = NULL;
this->JDimEntry = NULL;
this->KDimEntry = NULL;
this->ScalarTypeMenu = NULL;
this->ByteOrderMenu = NULL;
this->ScalarComponentsMenu = NULL;
this->ComponentsFrame = NULL;
this->IndependentComponentsButton = NULL;
this->ScopeFrame = NULL;
this->ScopeChoice = NULL;
this->PreviewReader = NULL;
this->OpenWithCurrentOpenFileProperties = 0;
this->IgnoreVVIOnRead = 0;
this->IgnoreVVIOnWrite = 0;
this->FileNames = vtkStringArray::New();
}
//----------------------------------------------------------------------------
vtkKWOpenWizard::~vtkKWOpenWizard()
{
delete this->Internals;
this->Internals = NULL;
int i;
if (this->LoadDialog)
{
this->LoadDialog->Delete();
this->LoadDialog = 0;
}
this->SetPreviousReader(0);
if (this->FileNames)
{
this->FileNames->Delete();
this->FileNames = NULL;
}
if (this->OrientationFilter)
{
this->OrientationFilter->Delete();
this->OrientationFilter = 0;
}
if (this->ColorImageConversionFilter)
{
this->ColorImageConversionFilter->Delete();
this->ColorImageConversionFilter = 0;
}
if (this->PreviousReader)
{
this->PreviousReader->Delete();
}
if (this->PreviousOpenFileProperties)
{
this->PreviousOpenFileProperties->Delete();
}
if (this->SeriesFrame)
{
this->SeriesFrame->Delete();
}
if (this->PatternEntry)
{
this->PatternEntry->Delete();
}
if (this->KMinEntry)
{
this->KMinEntry->Delete();
}
if (this->KMaxEntry)
{
this->KMaxEntry->Delete();
}
if (this->SpatialAttributesFrame)
{
this->SpatialAttributesFrame->Delete();
}
if (this->OriginLabel)
{
this->OriginLabel->Delete();
}
if (this->SpacingLabel)
{
this->SpacingLabel->Delete();
}
if (this->UnitsFrame)
{
this->UnitsFrame->Delete();
}
if (this->DistanceUnitsEntry)
{
this->DistanceUnitsEntry->Delete();
}
for (i = 0; i < 3; i++)
{
if (this->OriginEntry[i])
{
this->OriginEntry[i]->Delete();
}
if (this->SpacingEntry[i])
{
this->SpacingEntry[i]->Delete();
}
}
for (i = 0; i < VTK_MAX_VRCOMP; i++)
{
if (this->ScalarUnitsEntry[i])
{
this->ScalarUnitsEntry[i]->Delete();
}
}
if (this->OrientationFrame)
{
this->OrientationFrame->Delete();
}
if (this->SliceAxisMenu)
{
this->SliceAxisMenu->Delete();
}
if (this->RowAxisMenu)
{
this->RowAxisMenu->Delete();
}
if (this->ColumnAxisMenu)
{
this->ColumnAxisMenu->Delete();
}
if (this->MultiplicityFrame)
{
this->MultiplicityFrame->Delete();
}
if (this->MultiplicityChoice)
{
this->MultiplicityChoice->Delete();
}
if (this->Preview)
{
this->Preview->Close();
this->Preview->SetParent(0);
this->Preview->Delete();
}
if (this->PreviewReader)
{
this->PreviewReader->Delete();
}
if (this->RawInfoFrame)
{
this->RawInfoFrame->Delete();
}
if (this->IDimEntry)
{
this->IDimEntry->Delete();
}
if (this->JDimEntry)
{
this->JDimEntry->Delete();
}
if (this->KDimEntry)
{
this->KDimEntry->Delete();
}
if (this->ScalarTypeMenu)
{
this->ScalarTypeMenu->Delete();
}
if (this->ByteOrderMenu)
{
this->ByteOrderMenu->Delete();
}
if (this->ScalarComponentsMenu)
{
this->ScalarComponentsMenu->Delete();
}
if (this->ComponentsFrame)
{
this->ComponentsFrame->Delete();
}
if (this->IndependentComponentsButton)
{
this->IndependentComponentsButton->Delete();
}
if (this->ScopeFrame)
{
this->ScopeFrame->Delete();
}
if (this->ScopeChoice)
{
this->ScopeChoice->Delete();
}
if (this->OpenFileHelper)
{
this->OpenFileHelper->Delete();
this->OpenFileHelper = 0;
}
}
//----------------------------------------------------------------------------
void vtkKWOpenWizard::SetFileName(const char *filename)
{
this->FileNames->Reset();
if (filename && *filename)
{
this->FileNames->InsertNextValue(filename);
}
}
//----------------------------------------------------------------------------
const char* vtkKWOpenWizard::GetFileName()
{
if (this->FileNames->GetNumberOfValues())
{
const char *filename = this->FileNames->GetValue(0).c_str();
return *filename ? filename : NULL;
}
return NULL;
}
//----------------------------------------------------------------------------
void vtkKWOpenWizard::CreateWidget()
{
if (this->IsCreated())
{
vtkErrorMacro("widget already created " << this->GetClassName());
return;
}
this->Superclass::CreateWidget();
this->TitleLabel->SetText(ks_("Open Wizard|Title|Open File Wizard"));
// Create the dialog
if (!this->LoadDialog)
{
this->LoadDialog = vtkKWLoadSaveDialog::New();
this->LoadDialog->SetApplication(this->GetApplication());
this->LoadDialog->SetMasterWindow(this->MasterWindow);
}
if (!this->LoadDialog->IsCreated())
{
this->LoadDialog->Create();
}
this->PostTextLabel->SetForegroundColor(0.8, 0, 0);
}
//----------------------------------------------------------------------------
int vtkKWOpenWizard::PromptRaw()
{
// Always clear first
this->ForgetClientArea();
// let the user know what is up
this->SetPreText(
k_("This application was unable to open your data file. If you wish, it "
"will try to load your data file as a raw data file."));
this->SetPostText(VTK_VV_OW_DEFAULT_POSTTEXT_LABEL);
this->SubTitleLabel->SetText(ks_("Open Wizard|Raw File?"));
this->NextButton->EnabledOn();
this->NextButton->SetCommand(this, "ValidateRaw");
if (!this->Invoked)
{
this->Invoked = 1;
return this->vtkKWWizard::Invoke();
}
return 1;
}
//----------------------------------------------------------------------------
int vtkKWOpenWizard::ValidateRaw()
{
// Set the back button
this->AddBackButtonCommand("PromptRaw");
// Create a raw reader
vtkImageReader2 *rdr = vtkImageReader2::SafeDownCast(this->GetLastReader());
if (!rdr)
{
rdr = vtkImageReader2::New();
this->SetLastReader(rdr);
rdr->Delete();
}
// And move to the next page
return this->PromptMultiplicity();
}
//----------------------------------------------------------------------------
void vtkKWOpenWizard::CreateMultiplicityFrame()
{
if (!this->IsCreated())
{
return;
}
// Create the raw frame
this->MultiplicityFrame = vtkKWFrame::New();
this->MultiplicityFrame->SetParent(this->ClientArea);
this->MultiplicityFrame->Create();
this->MultiplicityChoice = vtkKWRadioButtonSet::New();
this->MultiplicityChoice->SetParent(this->MultiplicityFrame);
this->MultiplicityChoice->Create();
vtkKWRadioButton *rb;
rb = this->MultiplicityChoice->AddWidget(
VTK_VV_OW_MULTIPLICITY_SINGLE_BUTTON_ID);
rb->SetValueAsInt(VTK_VV_OW_MULTIPLICITY_SINGLE_BUTTON_ID);
rb->SetText(k_("My data is stored in a single 2D or 3D file."));
rb = this->MultiplicityChoice->AddWidget(
VTK_VV_OW_MULTIPLICITY_SERIES_BUTTON_ID);
rb->SetValueAsInt(VTK_VV_OW_MULTIPLICITY_SERIES_BUTTON_ID);
rb->SetText(k_("My data is stored in a series of 2D files."));
this->Script("grid %s -row 0 -column 0 -sticky nsew -padx 4 -pady 4",
this->MultiplicityChoice->GetWidgetName());
}
//----------------------------------------------------------------------------
int vtkKWOpenWizard::PromptMultiplicity()
{
// Always clear first
this->ForgetClientArea();
if (!this->MultiplicityFrame)
{
this->CreateMultiplicityFrame();
}
// let the user know what is up
this->SetPreText(
k_("This application can load your data as a single 2D or 3D file "
"or as a series of 2D files. Please select how you would like to "
"proceed."));
this->SetPostText(VTK_VV_OW_DEFAULT_POSTTEXT_LABEL);
this->SubTitleLabel->SetText(ks_("Open Wizard|Series?"));
vtkKWRadioButton *series_button = this->MultiplicityChoice->GetWidget(
VTK_VV_OW_MULTIPLICITY_SERIES_BUTTON_ID);
vtkKWRadioButton *single_button = this->MultiplicityChoice->GetWidget(
VTK_VV_OW_MULTIPLICITY_SINGLE_BUTTON_ID);
// If we have a pattern, it's likely we are dealing with a series,
// though the test below will refine this
if (this->GetOpenFileProperties()->GetFilePattern())
{
series_button->SelectedStateOn();
}
// If the output is a single 2D slice, but the whole extent as set
// in the VVI file is 3D, then we had a series
vtkImageReader2 *rdr = vtkImageReader2::SafeDownCast(this->GetLastReader());
if (rdr)
{
int *output_wext = rdr->GetOutput()->GetWholeExtent();
int *open_prop_wext = this->GetOpenFileProperties()->GetWholeExtent();
if (output_wext[4] == output_wext[5])
{
if (open_prop_wext[4] != open_prop_wext[5])
{
series_button->SelectedStateOn();
}
}
else
{
// The DICOM reader manages to get the proper 3D extent even from
// a single slice (by collecting the others)
// (that's provided that we don't deal with 3D DICOM files stored
// as a single file, which we haven't dealt with so far)
if (vtkDICOMReader::SafeDownCast(rdr) &&
open_prop_wext[4] != open_prop_wext[5])
{
series_button->SelectedStateOn();
}
else
{
single_button->SelectedStateOn();
}
}
}
// Nothing selected? Go for one.
if (!series_button->GetSelectedState() &&
!single_button->GetSelectedState())
{
series_button->SelectedStateOn();
}
this->Script("pack %s",this->MultiplicityFrame->GetWidgetName());
this->NextButton->EnabledOn();
this->NextButton->SetCommand(this, "ValidateMultiplicity");
if (!this->Invoked)
{
this->Invoked = 1;
return this->vtkKWWizard::Invoke();
}
return 1;
}
//----------------------------------------------------------------------------
int vtkKWOpenWizard::ValidateMultiplicity()
{
// Set the back button
this->AddBackButtonCommand("PromptMultiplicity");
vtkImageReader2 *rdr = vtkImageReader2::SafeDownCast(this->GetLastReader());
if (rdr)
{
vtkDICOMReader *dicom_rdr = vtkDICOMReader::SafeDownCast(rdr);
vtkDICOMCollectorOptions *options =
dicom_rdr ? dicom_rdr->GetDICOMCollector()->GetOptions() : NULL;
vtkImageData *output = rdr->GetOutput();
int output_wext[6];
output->GetWholeExtent(output_wext);
int is_raw =
(output_wext[1] <= output_wext[0]) || (output_wext[3] <= output_wext[2]);
if (this->MultiplicityChoice->GetWidget(
VTK_VV_OW_MULTIPLICITY_SINGLE_BUTTON_ID)->GetSelectedState())
{
rdr->SetFileDimensionality(is_raw ? 3 : 2);
rdr->SetFileName(this->GetFileName());
rdr->SetFilePattern(NULL);
if (dicom_rdr)
{
int old_explore = options->GetExploreDirectory();
options->ExploreDirectoryOff();
if (old_explore != options->GetExploreDirectory())
{
dicom_rdr->GetDICOMCollector()->ClearCollectedSlices();
}
}
this->GetOpenFileProperties()->SetFileDimensionality(
rdr->GetFileDimensionality());
this->GetOpenFileProperties()->SetFilePattern(
rdr->GetFilePattern());
if (is_raw)
{
return this->PromptRawInfo();
}
else
{
this->GetOpenFileProperties()->SetWholeExtent(
output_wext[0], output_wext[1],
output_wext[2], output_wext[3],
0, 0);
return this->PromptScope();
}
}
else // It's a series
{
if (dicom_rdr)
{
int old_explore = options->GetExploreDirectory();
options->ExploreDirectoryOn();
if (old_explore != options->GetExploreDirectory())
{
dicom_rdr->GetDICOMCollector()->ClearCollectedSlices();
}
}
rdr->SetFileDimensionality(2);
this->GetOpenFileProperties()->SetFileDimensionality(
rdr->GetFileDimensionality());
if (is_raw)
{
return this->PromptRawInfo();
}
else
{
// If it's a series, then the output whole extent for sure is
// either in 2D at [0,0], or in 3D for readers like the DICOM one.
// The open prop's whole extent may have the *right* 3D extent
// loaded from the VVI though (i.e. the extent that was picked
// for a RAW series for example, valuable for the next step), so
// let's overwrite it only if the output extent is 3D.
int *open_prop_wext = this->GetOpenFileProperties()->GetWholeExtent();
int output_is_3d = (output_wext[4] != output_wext[5]);
this->GetOpenFileProperties()->SetWholeExtent(
output_wext[0], output_wext[1],
output_wext[2], output_wext[3],
output_is_3d ? output_wext[4] : open_prop_wext[4],
output_is_3d ? output_wext[5] : open_prop_wext[5]);
return this->PromptSeries();
}
}
}
// And move to the next page
return this->PromptRawInfo();
}
//----------------------------------------------------------------------------
void vtkKWOpenWizard::CreateRawInfoFrame()
{
if (!this->IsCreated())
{
return;
}
// Create the pattern frame
this->RawInfoFrame = vtkKWFrame::New();
this->RawInfoFrame->SetParent(this->ClientArea);
this->RawInfoFrame->Create();
int label_width = 8;
int entry_width = 4;
int menu_label_width = 11;
int menu_width = 15;
int min_range = 1;
int max_range = 1000;
this->IDimEntry = vtkKWSpinBoxWithLabel::New();
this->IDimEntry->SetParent(this->RawInfoFrame);
this->IDimEntry->Create();
this->IDimEntry->GetLabel()->SetText(ks_("Open Wizard|Columns:"));
this->IDimEntry->SetLabelWidth(label_width);
this->IDimEntry->GetWidget()->SetWidth(entry_width);
this->IDimEntry->GetWidget()->SetCommand(
this, "RawDimensionCallback");
this->IDimEntry->GetWidget()->SetRange(min_range, max_range);
this->IDimEntry->GetWidget()->SetRestrictValueToInteger();
this->IDimEntry->GetWidget()->SetCommandTriggerToAnyChange();
this->JDimEntry = vtkKWSpinBoxWithLabel::New();
this->JDimEntry->SetParent(this->RawInfoFrame);
this->JDimEntry->Create();
this->JDimEntry->GetLabel()->SetText(ks_("Open Wizard|Rows:"));
this->JDimEntry->SetLabelWidth(label_width);
this->JDimEntry->GetWidget()->SetWidth(entry_width);
this->JDimEntry->GetWidget()->SetCommand(
this, "RawDimensionCallback");
this->JDimEntry->GetWidget()->SetRange(min_range, max_range);
this->JDimEntry->GetWidget()->SetRestrictValue(
this->IDimEntry->GetWidget()->GetRestrictValue());
this->JDimEntry->GetWidget()->SetCommandTrigger(
this->IDimEntry->GetWidget()->GetCommandTrigger());
this->KDimEntry = vtkKWSpinBoxWithLabel::New();
this->KDimEntry->SetParent(this->RawInfoFrame);
this->KDimEntry->Create();
this->KDimEntry->GetLabel()->SetText(ks_("Open Wizard|Slice(s):"));
this->KDimEntry->SetLabelWidth(label_width);
this->KDimEntry->GetWidget()->SetWidth(entry_width);
this->KDimEntry->GetWidget()->SetCommand(
this, "RawDimensionCallback");
this->KDimEntry->GetWidget()->SetRange(min_range, max_range);
this->KDimEntry->GetWidget()->SetRestrictValue(
this->IDimEntry->GetWidget()->GetRestrictValue());
this->KDimEntry->GetWidget()->SetCommandTrigger(
this->IDimEntry->GetWidget()->GetCommandTrigger());
this->ScalarTypeMenu = vtkKWMenuButtonWithLabel::New();
this->ScalarTypeMenu->SetParent(this->RawInfoFrame);
this->ScalarTypeMenu->Create();
this->ScalarTypeMenu->ExpandWidgetOn();
this->ScalarTypeMenu->SetLabelWidth(menu_label_width);
this->ScalarTypeMenu->GetLabel()->SetText(ks_("Open Wizard|Data Type:"));
vtkKWMenuButton *menubutton = this->ScalarTypeMenu->GetWidget();
menubutton->SetWidth(menu_width);
menubutton->SetAnchorToWest();
vtkKWMenu *menu = menubutton->GetMenu();
menu->SetItemSelectedValueAsInt(
menu->AddRadioButton(
ks_("Data Type|Unsigned 8 bit"), this, "ScalarTypeCallback"),
VTK_UNSIGNED_CHAR);
menu->SetItemSelectedValueAsInt(
menu->AddRadioButton(
ks_("Data Type|Signed 8 bit"), this, "ScalarTypeCallback"),
VTK_CHAR);
menu->SetItemSelectedValueAsInt(
menu->AddRadioButton(
ks_("Data Type|Unsigned 16 bit"), this, "ScalarTypeCallback"),
VTK_UNSIGNED_SHORT);
menu->SetItemSelectedValueAsInt(
menu->AddRadioButton(
ks_("Data Type|Signed 16 bit"), this, "ScalarTypeCallback"),
VTK_SHORT);
menu->SetItemSelectedValueAsInt(
menu->AddRadioButton(
ks_("Data Type|Unsigned 32 bit"), this, "ScalarTypeCallback"),
VTK_UNSIGNED_LONG);
menu->SetItemSelectedValueAsInt(
menu->AddRadioButton(
ks_("Data Type|Signed 32 bit"), this, "ScalarTypeCallback"),
VTK_LONG);
menu->SetItemSelectedValueAsInt(
menu->AddRadioButton(
ks_("Data Type|Float"), this, "ScalarTypeCallback"),
VTK_FLOAT);
menu->SetItemSelectedValueAsInt(
menu->AddRadioButton(
ks_("Data Type|Double"), this, "ScalarTypeCallback"),
VTK_DOUBLE);
this->ScalarComponentsMenu = vtkKWMenuButtonWithLabel::New();
this->ScalarComponentsMenu->SetParent(this->RawInfoFrame);
this->ScalarComponentsMenu->Create();
this->ScalarComponentsMenu->ExpandWidgetOn();
this->ScalarComponentsMenu->SetLabelWidth(menu_label_width);
this->ScalarComponentsMenu->GetLabel()->SetText(ks_("Open Wizard|Channels:"));
menubutton = this->ScalarComponentsMenu->GetWidget();
menubutton->SetWidth(menu_width);
menubutton->SetAnchorToWest();
menu = menubutton->GetMenu();
menu->SetItemSelectedValueAsInt(
menu->AddRadioButton(
ks_("Open Wizard|Color Channels|1 (greyscale)"),
this, "ScalarComponentsCallback"),
1);
menu->SetItemSelectedValueAsInt(
menu->AddRadioButton(
ks_("Open Wizard|Color Channels|2 (greyscale)"),
this, "ScalarComponentsCallback"),
2);
menu->SetItemSelectedValueAsInt(
menu->AddRadioButton(
ks_("Open Wizard|Color Channels|3 (color RGB)"),
this, "ScalarComponentsCallback"),
3);
menu->SetItemSelectedValueAsInt(
menu->AddRadioButton(
ks_("Open Wizard|Color Channels|4 (color RGBA)"),
this, "ScalarComponentsCallback"),
4);
this->ByteOrderMenu = vtkKWMenuButtonWithLabel::New();
this->ByteOrderMenu->SetParent(this->RawInfoFrame);
this->ByteOrderMenu->Create();
this->ByteOrderMenu->ExpandWidgetOn();
this->ByteOrderMenu->SetLabelWidth(menu_label_width);
this->ByteOrderMenu->GetLabel()->SetText(ks_("Open Wizard|Byte Order:"));
menubutton = this->ByteOrderMenu->GetWidget();
menubutton->SetWidth(menu_width);
menubutton->SetAnchorToWest();
menu = menubutton->GetMenu();
menu->SetItemSelectedValueAsInt(
menu->AddRadioButton(
ks_("Byte Order|Little Endian (PC)"), this, "ByteOrderCallback"),
vtkKWOpenFileProperties::DataByteOrderLittleEndian);
menu->SetItemSelectedValueAsInt(
menu->AddRadioButton(
ks_("Byte Order|Big Endian (Unix)"), this, "ByteOrderCallback"),
vtkKWOpenFileProperties::DataByteOrderBigEndian);
this->Script("grid %s -row 0 -column 0 -sticky nwe -padx 2 -pady 2",
this->IDimEntry->GetWidgetName());
this->Script("grid %s -row 1 -column 0 -sticky nwe -padx 2 -pady 2",
this->JDimEntry->GetWidgetName());
this->Script("grid %s -row 0 -column 1 -sticky nwe -padx 2 -pady 2",
this->ScalarComponentsMenu->GetWidgetName());
this->Script("grid %s -row 1 -column 1 -sticky nwe -padx 2 -pady 2",
this->ScalarTypeMenu->GetWidgetName());
this->Script("grid %s -row 2 -column 1 -sticky nwe -padx 2 -pady 2",
this->ByteOrderMenu->GetWidgetName());
this->Script("grid rowconfigure %s 0 -weight 1",
this->RawInfoFrame->GetWidgetName());
this->Script("grid rowconfigure %s 1 -weight 1",
this->RawInfoFrame->GetWidgetName());
this->Script("grid rowconfigure %s 2 -weight 1",
this->RawInfoFrame->GetWidgetName());
this->Script("grid rowconfigure %s 3 -weight 50",
this->RawInfoFrame->GetWidgetName());
// Create the image preview
this->PreviewReader = vtkImageReader2::New();
this->Script("grid columnconfigure %s 2 -weight 1",
this->RawInfoFrame->GetWidgetName());
}
//----------------------------------------------------------------------------
int vtkKWOpenWizard::PromptRawInfo()
{
// Always clear first
this->ForgetClientArea();
if (!this->RawInfoFrame)
{
this->CreateRawInfoFrame();
}
// Let the user know what is up
this->SetPreText(
k_("This application has analyzed your data and has tried to make some "
"estimates as to the nature of your data file. Please verify the "
"following parameters. An active preview of one slice loaded using the "
"current parameters is displayed to aid in this process."));
this->SetPostText(VTK_VV_OW_DEFAULT_POSTTEXT_LABEL);
this->SubTitleLabel->SetText(ks_("Open Wizard|Raw File Information"));
vtkImageReader2 *rdr =
vtkImageReader2::SafeDownCast(this->GetLastReader());
// if the valid information already has reasonable values then keep them
// Make sure the computed size is not larger than the file size
struct stat statbuf;
stat(this->GetFileName(), &statbuf);
vtkKWOpenFileProperties *open_prop = this->GetOpenFileProperties();
int *open_prop_wext = open_prop->GetWholeExtent();
int zdim = open_prop->GetFileDimensionality() == 2
? 1 : (open_prop_wext[5] - open_prop_wext[4] + 1);
unsigned long fsize =
open_prop->GetNumberOfScalarComponents() *
(open_prop_wext[1] - open_prop_wext[0] + 1) *
(open_prop_wext[3] - open_prop_wext[2] + 1) *
zdim *
open_prop->GetScalarSize();
if ((unsigned int)statbuf.st_size < fsize || fsize == 0)
{
// Analyze the data to make a best guess at the properties
this->GetOpenFileHelper()->AnalyzeRawFile(this->GetFileName());
}
this->IDimEntry->GetWidget()->SetValue(
open_prop_wext[1] - open_prop_wext[0] + 1);
this->JDimEntry->GetWidget()->SetValue(
open_prop_wext[3] - open_prop_wext[2] + 1);
this->ScalarTypeMenu->GetWidget()->GetMenu()->SelectItemWithSelectedValueAsInt(
open_prop->GetScalarType());
this->ByteOrderMenu->SetEnabled(open_prop->GetScalarSize() > 1 ? 1 : 0);
this->ByteOrderMenu->GetWidget()->GetMenu()->SelectItemWithSelectedValueAsInt(
open_prop->GetDataByteOrder());
this->ScalarComponentsMenu->GetWidget()->GetMenu()->SelectItemWithSelectedValueAsInt(
open_prop->GetNumberOfScalarComponents());
if (open_prop->GetFileDimensionality() == 3)
{
this->KDimEntry->GetWidget()->SetValue(
open_prop_wext[5] - open_prop_wext[4] + 1);
this->Script("grid %s -row 2 -column 0 -sticky nwe -padx 2 -pady 2",
this->KDimEntry->GetWidgetName());
}
else if (open_prop->GetFileDimensionality() == 2)
{
this->Script("grid forget %s", this->KDimEntry->GetWidgetName());
}
this->Script("pack %s -expand 1 -fill both",
this->RawInfoFrame->GetWidgetName());
this->NextButton->SetCommand(this, "ValidateRawInfo");
// Set up the preview
this->PreviewReader->SetDataExtent(open_prop->GetWholeExtent());
this->PreviewReader->SetDataSpacing(open_prop->GetSpacing());
this->PreviewReader->SetDataOrigin(open_prop->GetOrigin());
this->PreviewReader->SetDataScalarType(open_prop->GetScalarType());
this->PreviewReader->SetNumberOfScalarComponents(
open_prop->GetNumberOfScalarComponents());
if (open_prop->GetDataByteOrder() !=
vtkKWOpenFileProperties::DataByteOrderUnknown)
{
this->PreviewReader->SetDataByteOrder(
open_prop->GetDataByteOrder());
}
this->PreviewReader->SetFileDimensionality(
open_prop->GetFileDimensionality());
this->PreviewReader->SetFileName(this->GetFileName());
this->AreRawFileValuesReasonable();
if (!this->Invoked)
{
this->Invoked = 1;
return this->vtkKWWizard::Invoke();
}
return 1;
}
//----------------------------------------------------------------------------
void vtkKWOpenWizard::SetupRawPreview()
{
// I wish we could keep the preview around, but apparently there is
// a bug that prevents it from recovering from a bad estimate in the
// structure of a RAW file. Can't find where despite lots of
// debugging. In the meantime, re-create it from scratch each time
// the user tries a new RAW structure. Do it slightly asynchronously so
// that the user can still get interactive rates.
if (this->Preview)
{
this->Preview->Close();
this->Preview->SetParent(NULL);
this->Preview->Delete();
this->Preview = NULL;
}
int preview_was_reallocated = 0;
if (!this->Preview)
{
preview_was_reallocated = 1;
this->Preview = vtkKWImageWidget::New();
this->Preview->ResetWindowLevelForSelectedSliceOnlyOn();
this->Preview->SetSupportSideAnnotation(0);
this->Preview->HasSliceControlOff();
}
int preview_was_created = 0;
if (!this->Preview->IsCreated())
{
preview_was_created = 1;
this->Preview->SetParent(this->RawInfoFrame);
this->Preview->Create();
this->Preview->SetConfigurationOptionAsInt("-width", 120);
this->Preview->SetConfigurationOptionAsInt("-height", 120);
}
int reasonable = !this->AreRawFileValuesLargerThanFileSize();
if (reasonable)
{
this->Preview->SetInput(this->PreviewReader->GetOutput());
int kdim = (int)this->KDimEntry->GetWidget()->GetValue();
int slice = (kdim < 1) ? 0 : ((kdim - 1) / 2);
if (this->Preview->GetSlice() != slice)
{
this->Preview->SetSlice(slice);
}
if (!preview_was_reallocated)
{
this->Preview->ResetWindowLevel();
this->Preview->Reset(); // calls ResetCamera and Render()
}
}
else
{
this->Preview->SetInput(NULL);
this->Preview->Render();
}
if (preview_was_created)
{
this->Script(
"grid %s -row 0 -column 2 -rowspan 4 -sticky nsew -padx 2 -pady 0",
this->Preview->GetWidgetName());
this->Preview->AddBindings();
}
this->Internals->ScheduleSetupRawPreviewTimerId = "";
}
//----------------------------------------------------------------------------
void vtkKWOpenWizard::ScheduleSetupRawPreview()
{
// Already scheduled?
if (this->Internals->ScheduleSetupRawPreviewTimerId.size() ||
!this->IsCreated())
{
return;
}
this->Internals->ScheduleSetupRawPreviewTimerId =
this->Script(
"after 200 {catch {%s SetupRawPreviewCallback}}",
this->GetTclName());
}
//----------------------------------------------------------------------------
void vtkKWOpenWizard::SetupRawPreviewCallback()
{
if (!this->GetApplication() || this->GetApplication()->GetInExit() ||
!this->IsAlive())
{
return;
}
this->SetupRawPreview();
this->Internals->ScheduleSetupRawPreviewTimerId = "";
}
//----------------------------------------------------------------------------
int vtkKWOpenWizard::AreRawFileValuesLargerThanFileSize()
{
// Make sure the computed size is not larger than the file size
struct stat statbuf;
stat(this->PreviewReader->GetFileName(), &statbuf);
// The call to get header size makes sure the increments are computed
this->PreviewReader->GetHeaderSize();
unsigned long *di = this->PreviewReader->GetDataIncrements();
return ((unsigned int)statbuf.st_size <
di[this->PreviewReader->GetFileDimensionality()]);
}
//----------------------------------------------------------------------------
int vtkKWOpenWizard::AreRawFileValuesReasonable()
{
if (!this->PreviewReader->GetFileName())
{
return 1;
}
this->ScheduleSetupRawPreview();
int reasonable = !this->AreRawFileValuesLargerThanFileSize();
if (reasonable)
{
this->SetPostText(VTK_VV_OW_DEFAULT_POSTTEXT_LABEL);
}
else
{
this->SetPostText(
k_("Error. The current parameter values result in a file size larger "
"than the file selected. Please correct the values."));
}
this->NextButton->SetEnabled(reasonable);
return reasonable;
}
//----------------------------------------------------------------------------
void vtkKWOpenWizard::RawDimensionCallback(int)
{
int idim = (int)this->IDimEntry->GetWidget()->GetValue();
if (idim < 1)
{
idim = 1;
}
int jdim = (int)this->JDimEntry->GetWidget()->GetValue();
if (jdim < 1)
{
jdim= 1;
}
int kdim = (int)this->KDimEntry->GetWidget()->GetValue();
if (kdim < 1)
{
kdim = 1;
}
if (this->GetOpenFileProperties()->GetFileDimensionality() == 3)
{
this->PreviewReader->SetDataExtent(
0, idim - 1, 0, jdim - 1, 0, kdim - 1);
}
else if (this->GetOpenFileProperties()->GetFileDimensionality() == 2)
{
this->PreviewReader->SetDataExtent(
0, idim - 1, 0, jdim - 1, 0, 0);
}
this->AreRawFileValuesReasonable();
}
//----------------------------------------------------------------------------
void vtkKWOpenWizard::ScalarComponentsCallback()
{
vtkKWMenu *menu = this->ScalarComponentsMenu->GetWidget()->GetMenu();
int nb_comp =
menu->GetItemSelectedValueAsInt(menu->GetIndexOfSelectedItem());
this->PreviewReader->SetNumberOfScalarComponents(nb_comp);
this->AreRawFileValuesReasonable();
}
//----------------------------------------------------------------------------
void vtkKWOpenWizard::ByteOrderCallback()
{
vtkKWMenu *menu = this->ByteOrderMenu->GetWidget()->GetMenu();
int byte_order =
menu->GetItemSelectedValueAsInt(menu->GetIndexOfSelectedItem());
this->PreviewReader->SetDataByteOrder(byte_order);
this->AreRawFileValuesReasonable();
}
//----------------------------------------------------------------------------
void vtkKWOpenWizard::ScalarTypeCallback()
{
vtkKWMenu *menu = this->ScalarTypeMenu->GetWidget()->GetMenu();
int scalar_type =
menu->GetItemSelectedValueAsInt(menu->GetIndexOfSelectedItem());
this->ByteOrderMenu->SetEnabled(
vtkDataArray::GetDataTypeSize(scalar_type) > 1 ? 1 : 0);
// If no byte order is selected yet, default to LittleEndian, otherwise we
// crash at the next step.
vtkKWMenu * byteOrderMenu = this->ByteOrderMenu->GetWidget()->GetMenu();
if (this->ByteOrderMenu->GetEnabled())
{
if (byteOrderMenu->GetIndexOfSelectedItem() == -1)
{
byteOrderMenu->SelectItemWithSelectedValueAsInt(
vtkKWOpenFileProperties::DataByteOrderLittleEndian);
// Invoke the callback to update the preview reader in response to changes.
this->ByteOrderCallback();
}
}
this->PreviewReader->SetDataScalarType(scalar_type);
this->AreRawFileValuesReasonable();
}
//----------------------------------------------------------------------------
int vtkKWOpenWizard::ValidateRawInfo()
{
// Set the back button
this->AddBackButtonCommand("PromptRawInfo");
vtkKWMenu *menu = this->ScalarTypeMenu->GetWidget()->GetMenu();
this->GetOpenFileProperties()->SetScalarType(
menu->GetItemSelectedValueAsInt(menu->GetIndexOfSelectedItem()));
menu = this->ByteOrderMenu->GetWidget()->GetMenu();
this->GetOpenFileProperties()->SetDataByteOrder(
menu->GetItemSelectedValueAsInt(menu->GetIndexOfSelectedItem()));
menu = this->ScalarComponentsMenu->GetWidget()->GetMenu();
this->GetOpenFileProperties()->SetNumberOfScalarComponents(
menu->GetItemSelectedValueAsInt(menu->GetIndexOfSelectedItem()));
int idim = (int)this->IDimEntry->GetWidget()->GetValue();
if (idim < 1)
{
idim = 1;
}
int jdim = (int)this->JDimEntry->GetWidget()->GetValue();
if (jdim < 1)
{
jdim= 1;
}
int kdim = (int)this->KDimEntry->GetWidget()->GetValue();
if (kdim < 1)
{
kdim = 1;
}
if (this->GetOpenFileProperties()->GetFileDimensionality() == 3)
{
this->GetOpenFileProperties()->SetWholeExtent(
0, idim - 1, 0, jdim - 1, 0, kdim - 1);
return this->PromptScope();
}
if (this->GetOpenFileProperties()->GetFileDimensionality() == 2)
{
this->GetOpenFileProperties()->SetWholeExtent(
0, idim - 1, 0, jdim - 1, 0, 0);
}
// And move to the next page
return this->PromptSeries();
}
//----------------------------------------------------------------------------
void vtkKWOpenWizard::CreateSeriesFrame()
{
if (!this->IsCreated())
{
return;
}
// Create the pattern frame
this->SeriesFrame = vtkKWFrame::New();
this->SeriesFrame->SetParent(this->ClientArea);
this->SeriesFrame->Create();
int label_width = 16;
int max_range = 1000;
this->PatternEntry = vtkKWEntryWithLabel::New();
this->PatternEntry->SetParent(this->SeriesFrame);
this->PatternEntry->Create();
this->PatternEntry->GetLabel()->SetText(
ks_("Open Wizard|Filename Pattern:"));
this->PatternEntry->SetLabelWidth(label_width);
this->PatternEntry->GetWidget()->SetWidth(60);
this->PatternEntry->GetWidget()->SetCommand(this, "SeriesPatternCallback");
this->PatternEntry->GetWidget()->SetCommandTriggerToAnyChange();
this->KMinEntry = vtkKWSpinBoxWithLabel::New();
this->KMinEntry->SetParent(this->SeriesFrame);
this->KMinEntry->Create();
this->KMinEntry->GetLabel()->SetText(
ks_("Open Wizard|Starting Slice:"));
this->KMinEntry->SetLabelWidth(label_width);
this->KMinEntry->GetWidget()->SetWidth(6);
this->KMinEntry->GetWidget()->SetRange(0, max_range);
this->KMinEntry->GetWidget()->SetRestrictValueToInteger();
this->KMinEntry->GetWidget()->SetCommand(this, "SeriesExtentCallback");
this->KMinEntry->GetWidget()->SetCommandTriggerToAnyChange();
this->KMaxEntry = vtkKWSpinBoxWithLabel::New();
this->KMaxEntry->SetParent(this->SeriesFrame);
this->KMaxEntry->Create();
this->KMaxEntry->GetLabel()->SetText(
ks_("Open Wizard|Ending Slice:"));
this->KMaxEntry->SetLabelWidth(label_width);
this->KMaxEntry->GetWidget()->SetWidth(
this->KMinEntry->GetWidget()->GetWidth());
this->KMaxEntry->GetWidget()->SetRange(0, max_range);
this->KMaxEntry->GetWidget()->SetRestrictValue(
this->KMinEntry->GetWidget()->GetRestrictValue());
this->KMaxEntry->GetWidget()->SetCommand(this, "SeriesExtentCallback");
this->KMaxEntry->GetWidget()->SetCommandTriggerToAnyChange();
this->Script("grid %s -row 0 -column 0 -sticky nsew -padx 4 -pady 4",
this->PatternEntry->GetWidgetName());
this->Script("grid %s -row 1 -column 0 -sticky nws -padx 4 -pady 4",
this->KMinEntry->GetWidgetName());
this->Script("grid %s -row 2 -column 0 -sticky nws -padx 4 -pady 4",
this->KMaxEntry->GetWidgetName());
}
//----------------------------------------------------------------------------
int vtkKWOpenWizard::PromptSeries()
{
// if it is not a vtkImageReader2 subclass or if it is but is set
// to read a whole 3D file, then it cannot be handled as a series.
// If it is DICOM, don't waste your time here, the series should have
// been collected by the DICOM Collector already.
vtkImageReader2 *rdr =
vtkImageReader2::SafeDownCast(this->GetLastReader());
if (!rdr ||
this->GetOpenFileProperties()->GetFileDimensionality() == 3 ||
vtkDICOMReader::SafeDownCast(rdr))
{
return this->PromptScope();
}
// Otherwise it can be handled as a series
// Always clear first
this->ForgetClientArea();
if (!this->SeriesFrame)
{
this->CreateSeriesFrame();
}
// Promt the user if this is a good series range & pattern
this->SetPreText(
k_("The file pattern is used to compute a unique filename for each slice. "
"In the pattern the %i (or %03i) will be replaced with the slice "
"number. Please check that this is the correct pattern and modify it "
"if neccessary. All slices between and including the starting and "
"ending slices will be loaded."));
this->SetPostText(VTK_VV_OW_DEFAULT_POSTTEXT_LABEL);
this->SubTitleLabel->SetText(ks_("Open Wizard|Series Information"));
// If the extent is all inclusive (2D), and/or the pattern is NULL, let's
// try to guess.
int zmin = this->GetOpenFileProperties()->GetWholeExtent()[4];
int zmax = this->GetOpenFileProperties()->GetWholeExtent()[5];
const char *pattern =
this->GetOpenFileProperties()->GetAbsoluteFilePatternForFile(
this->GetFileName());
char *guess_pattern = NULL;
if (zmin == zmax || !pattern || !*pattern)
{
int guess_zmin = 0, guess_zmax = 0;
guess_pattern = new char[strlen(this->GetFileName()) * 2];
if (vtkKWOpenFileHelper::FindSeriesPattern(
this->GetFileName(), guess_pattern, &guess_zmin, &guess_zmax))
{
if (!pattern || !*pattern)
{
pattern = guess_pattern;
}
if (zmin == zmax)
{
if (guess_zmin >= 0)
{
zmin = guess_zmin;
}
if (guess_zmax >= 0)
{
zmax = guess_zmax;
}
}
}
}
this->KMinEntry->GetWidget()->SetValue(zmin);
this->KMaxEntry->GetWidget()->SetValue(zmax);
this->PatternEntry->GetWidget()->SetValue(pattern);
delete [] guess_pattern;
this->Script("pack %s",this->SeriesFrame->GetWidgetName());
this->AreSeriesValuesReasonable();
this->NextButton->SetCommand(this, "ValidateSeries");
if (!this->Invoked)
{
this->Invoked = 1;
return this->vtkKWWizard::Invoke();
}
return 1;
}
//----------------------------------------------------------------------------
int vtkKWOpenWizard::AreSeriesValuesReasonable()
{
int kmin = (int)this->KMinEntry->GetWidget()->GetValue();
int kmax = (int)this->KMaxEntry->GetWidget()->GetValue();
if (kmax < kmin)
{
int tmp = kmax;
kmax = kmin;
kmin = tmp;
}
// Verify that the range of files exists
int i, valid = 1;
vtksys_stl::string pattern(this->PatternEntry->GetWidget()->GetValue());
char *testFileName = new char [strlen(pattern.c_str()) + 50];
for (i = kmin; i <= kmax; ++i)
{
sprintf(testFileName, pattern.c_str(), i);
if(!vtksys::SystemTools::FileExists(testFileName))
{
valid = 0;
break;
}
}
delete [] testFileName;
if (valid)
{
this->SetPostText(VTK_VV_OW_DEFAULT_POSTTEXT_LABEL);
this->NextButton->EnabledOn();
return 1;
}
this->SetPostText(
k_("Error. Files cannot be found for the series range specified. "
"Please verify that the series range is specified correctly "
"and that there are no missing slices."));
this->NextButton->EnabledOff();
return 0;
}
//----------------------------------------------------------------------------
void vtkKWOpenWizard::SeriesPatternCallback(const char*)
{
this->AreSeriesValuesReasonable();
}
//----------------------------------------------------------------------------
void vtkKWOpenWizard::SeriesExtentCallback(int)
{
this->AreSeriesValuesReasonable();
}
//----------------------------------------------------------------------------
const char *vtkKWOpenWizard::GetSeriesPattern()
{
return this->PatternEntry ? this->PatternEntry->GetWidget()->GetValue() : NULL;
}
//----------------------------------------------------------------------------
int vtkKWOpenWizard::GetSeriesMinimum()
{
return this->KMinEntry ? (int)this->KMinEntry->GetWidget()->GetValue() : 0;
}
//----------------------------------------------------------------------------
int vtkKWOpenWizard::GetSeriesMaximum()
{
return this->KMaxEntry ? (int)this->KMaxEntry->GetWidget()->GetValue() : 0;
}
//----------------------------------------------------------------------------
void vtkKWOpenWizard::SetSeriesPattern(const char * pattern)
{
if( this->PatternEntry )
{
this->PatternEntry->GetWidget()->SetValue(pattern);
}
}
//----------------------------------------------------------------------------
void vtkKWOpenWizard::SetSeriesMinimum(int minimum)
{
if( this->KMinEntry )
{
this->KMinEntry->GetWidget()->SetValue(minimum);
}
}
//----------------------------------------------------------------------------
void vtkKWOpenWizard::SetSeriesMaximum(int maximum)
{
if( this->KMaxEntry )
{
this->KMaxEntry->GetWidget()->SetValue(maximum);
}
}
//----------------------------------------------------------------------------
int vtkKWOpenWizard::ValidateSeries()
{
// Set the back button
this->AddBackButtonCommand("PromptSeries");
// At this point the values are valid otherwise we would not have been
// able to press the "Next" button
int kmin = (int)this->KMinEntry->GetWidget()->GetValue();
int kmax = (int)this->KMaxEntry->GetWidget()->GetValue();
if (kmax < kmin)
{
int tmp = kmax;
kmax = kmin;
kmin = tmp;
}
vtksys_stl::string pattern(this->PatternEntry->GetWidget()->GetValue());
// Modify the file name to be the first slice of this series
// NO, this should not be done (and why was it??)
//sprintf(testFileName,pattern,kmin);
//this->SetFileName(testFileName);
//delete [] testFileName;
int *open_prop_wext = this->GetOpenFileProperties()->GetWholeExtent();
this->GetOpenFileProperties()->SetWholeExtent(
open_prop_wext[0], open_prop_wext[1],
open_prop_wext[2], open_prop_wext[3],
kmin, kmax);
this->GetOpenFileProperties()->SetFilePattern(pattern.c_str());
// And move to the next page
return this->PromptScope();
}
//----------------------------------------------------------------------------
void vtkKWOpenWizard::CreateComponentsFrame()
{
if (!this->IsCreated())
{
return;
}
// Create the component frame
this->ComponentsFrame = vtkKWFrame::New();
this->ComponentsFrame->SetParent(this->ClientArea);
this->ComponentsFrame->Create();
this->IndependentComponentsButton = vtkKWCheckButton::New();
this->IndependentComponentsButton->SetParent(this->ComponentsFrame);
this->IndependentComponentsButton->Create();
this->IndependentComponentsButton->SetText(
ks_("Open Wizard|Components are independent"));
this->Script("grid %s -row 0 -column 0 -sticky nsew -padx 4 -pady 4",
this->IndependentComponentsButton->GetWidgetName());
}
//----------------------------------------------------------------------------
void vtkKWOpenWizard::CreateScopeFrame()
{
if (!this->IsCreated())
{
return;
}
// Create the component frame
this->ScopeFrame = vtkKWFrame::New();
this->ScopeFrame->SetParent(this->ClientArea);
this->ScopeFrame->Create();
this->ScopeChoice = vtkKWRadioButtonSet::New();
this->ScopeChoice->SetParent(this->ScopeFrame);
this->ScopeChoice->Create();
vtkKWRadioButton *rb;
rb = this->ScopeChoice->AddWidget(vtkKWOpenFileProperties::ScopeMedical);
rb->SetValueAsInt(vtkKWOpenFileProperties::ScopeMedical);
rb->SetText(k_("Medical data"));
rb = this->ScopeChoice->AddWidget(vtkKWOpenFileProperties::ScopeScientific);
rb->SetValueAsInt(vtkKWOpenFileProperties::ScopeScientific);
rb->SetText(k_("Scientific/Generic data"));
this->Script("grid %s -row 0 -column 0 -sticky nsew -padx 4 -pady 4",
this->ScopeChoice->GetWidgetName());
}
//----------------------------------------------------------------------------
int vtkKWOpenWizard::PromptScope()
{
// Always clear first
this->ForgetClientArea();
if (!this->ScopeFrame)
{
this->CreateScopeFrame();
}
// let the user know what is up
this->SetPreText(
k_("This application can set up default parameters specific to the "
"scope of your data. For example, the annotations will be set to an "
"XYZ coordinate system for scientific data, as opposed to LPS "
" (Left, Posterior, Superior) for medical data."));
this->SetPostText(VTK_VV_OW_DEFAULT_POSTTEXT_LABEL);
this->SubTitleLabel->SetText(ks_("Open Wizard|Scope"));
vtkKWRadioButton *medical_button = this->ScopeChoice->GetWidget(
vtkKWOpenFileProperties::ScopeMedical);
vtkKWRadioButton *scientific_button = this->ScopeChoice->GetWidget(
vtkKWOpenFileProperties::ScopeScientific);
if (this->GetOpenFileProperties()->GetScope() ==
vtkKWOpenFileProperties::ScopeMedical)
{
medical_button->SelectedStateOn();
}
if (this->GetOpenFileProperties()->GetScope() ==
vtkKWOpenFileProperties::ScopeScientific)
{
scientific_button->SelectedStateOn();
}
// Nothing selected? Go for one.
if (!medical_button->GetSelectedState() &&
!scientific_button->GetSelectedState())
{
scientific_button->SelectedStateOn();
}
this->Script("pack %s", this->ScopeFrame->GetWidgetName());
this->NextButton->EnabledOn();
this->NextButton->SetCommand(this, "ValidateScope");
if (!this->Invoked)
{
this->Invoked = 1;
return this->vtkKWWizard::Invoke();
}
return 1;
}
//----------------------------------------------------------------------------
int vtkKWOpenWizard::ValidateScope()
{
// Set the back button
this->AddBackButtonCommand("PromptScope");
if (this->ScopeChoice->GetWidget(
vtkKWOpenFileProperties::ScopeMedical)->GetSelectedState())
{
this->GetOpenFileProperties()->SetScope(
vtkKWOpenFileProperties::ScopeMedical);
}
if (this->ScopeChoice->GetWidget(
vtkKWOpenFileProperties::ScopeScientific)->GetSelectedState())
{
this->GetOpenFileProperties()->SetScope(
vtkKWOpenFileProperties::ScopeScientific);
}
// And move to the next page
return this->PromptSpatialAttributes();
}
//----------------------------------------------------------------------------
void vtkKWOpenWizard::CreateSpatialAttributesFrame()
{
if (!this->IsCreated())
{
return;
}
int i;
// Create the attribute frame
this->SpatialAttributesFrame = vtkKWFrame::New();
this->SpatialAttributesFrame->SetParent(this->ClientArea);
this->SpatialAttributesFrame->Create();
this->OriginLabel = vtkKWLabel::New();
this->OriginLabel->SetParent(this->SpatialAttributesFrame);
this->OriginLabel->Create();
this->OriginLabel->SetText(ks_("Open Wizard|Origin:"));
this->SpacingLabel = vtkKWLabel::New();
this->SpacingLabel->SetParent(this->SpatialAttributesFrame);
this->SpacingLabel->Create();
this->SpacingLabel->SetText(ks_("Open Wizard|Spacing:"));
this->Script("grid %s -row 0 -column 0 -sticky nsew -padx 4 -pady 4",
this->OriginLabel->GetWidgetName());
this->Script("grid %s -row 1 -column 0 -sticky nsew -padx 4 -pady 4",
this->SpacingLabel->GetWidgetName());
for (i = 0; i < 3; i++)
{
this->OriginEntry[i] = vtkKWEntry::New();
this->OriginEntry[i]->SetParent(this->SpatialAttributesFrame);
this->OriginEntry[i]->Create();
this->OriginEntry[i]->SetWidth(16);
this->SpacingEntry[i] = vtkKWEntry::New();
this->SpacingEntry[i]->SetParent(this->SpatialAttributesFrame);
this->SpacingEntry[i]->Create();
this->SpacingEntry[i]->SetWidth(this->OriginEntry[i]->GetWidth());
this->Script("grid %s -row 0 -column %i -sticky nsew -padx 2 -pady 4",
this->OriginEntry[i]->GetWidgetName(), i + 1);
this->Script("grid %s -row 1 -column %i -sticky nsew -padx 2 -pady 4",
this->SpacingEntry[i]->GetWidgetName(), i + 1);
this->Script("grid columnconfigure %s %i -weight 1",
this->SpatialAttributesFrame->GetWidgetName(), i + 1);
}
this->Script("grid rowconfigure %s 0 -weight 1",
this->SpatialAttributesFrame->GetWidgetName());
this->Script("grid rowconfigure %s 1 -weight 1",
this->SpatialAttributesFrame->GetWidgetName());
}
//----------------------------------------------------------------------------
int vtkKWOpenWizard::PromptSpatialAttributes()
{
// For certain file types, skip this page
if (vtkDICOMReader::SafeDownCast(this->GetLastReader()) ||
vtkGESignaReader::SafeDownCast(this->GetLastReader()) ||
vtkGESignaReader3D::SafeDownCast(this->GetLastReader()) ||
vtkStructuredPointsReader::SafeDownCast(this->GetLastReader()) ||
vtkMetaImageReader::SafeDownCast(this->GetLastReader()) ||
vtkXMLImageDataReader::SafeDownCast(this->GetLastReader()))
{
return this->PromptComponents();
}
int i;
// Always clear first
this->ForgetClientArea();
if (!this->SpatialAttributesFrame)
{
this->CreateSpatialAttributesFrame();
}
this->SetPreText(
k_("Please verify that the data's origin, and pixel spacing are correct. "
"If this application was unable to determine the origin or spacing then "
"it will list 'Unknown' as the value. If you leave the origin as "
"'Unknown' it will be assigned a default value of 0.0. If you leave "
"the spacing as 'Unknown' it will be assigned a default value of 1.0.")
);
this->SetPostText(VTK_VV_OW_DEFAULT_POSTTEXT_LABEL);
this->SubTitleLabel->SetText(ks_("Open Wizard|Spatial Attributes"));
for (i = 0; i < 3; i++)
{
if (this->GetOpenFileProperties()->GetOrigin()[i] ==
VTK_VV_OW_DATA_ORIGIN_UNKNOWN)
{
this->OriginEntry[i]->SetValue(ks_("Open Wizard|Unknown"));
}
else
{
this->OriginEntry[i]->SetValueAsDouble(
this->GetOpenFileProperties()->GetOrigin()[i]);
}
if (this->GetOpenFileProperties()->GetSpacing()[i] ==
VTK_VV_OW_DATA_SPACING_UNKNOWN)
{
this->SpacingEntry[i]->SetValue(ks_("Open Wizard|Unknown"));
}
else
{
this->SpacingEntry[i]->SetValueAsDouble(
this->GetOpenFileProperties()->GetSpacing()[i]);
}
}
this->Script("pack %s",this->SpatialAttributesFrame->GetWidgetName());
this->NextButton->SetCommand(this, "ValidateSpatialAttributes");
if (!this->Invoked)
{
this->Invoked = 1;
return this->vtkKWWizard::Invoke();
}
return 1;
}
//----------------------------------------------------------------------------
int vtkKWOpenWizard::ValidateSpatialAttributes()
{
// Set the back button
this->AddBackButtonCommand("PromptSpatialAttributes");
// Assign values to OpenFileProperties
// really should check that they entered some useful values here
double origin[3];
double spacing[3];
const char *value;
int i;
for (i = 0; i < 3; ++i)
{
value = this->OriginEntry[i]->GetValue();
if (!strcmp(ks_("Open Wizard|Unknown"), value))
{
origin[i] = 0;
}
else
{
origin[i] = atof(value);
}
value = this->SpacingEntry[i]->GetValue();
if (!strcmp(ks_("Open Wizard|Unknown"), value))
{
spacing[i] = 1;
}
else
{
spacing[i] = atof(value);
}
}
this->GetOpenFileProperties()->SetSpacing(spacing);
this->GetOpenFileProperties()->SetOrigin(origin);
// And move to the next page
return this->PromptComponents();
}
//----------------------------------------------------------------------------
int vtkKWOpenWizard::PromptComponents()
{
// Only display this page if there is more than one componment
if (this->GetOpenFileProperties()->GetNumberOfScalarComponents() <= 1)
{
return this->PromptUnits();
}
// Always clear first
this->ForgetClientArea();
if (!this->ComponentsFrame)
{
this->CreateComponentsFrame();
}
vtksys_stl::string msg;
switch (this->GetOpenFileProperties()->GetNumberOfScalarComponents())
{
case 2:
msg = k_(
"It appears that you are loading a volume with two scalar components "
"per voxel. This application can treat these components in two different ways. "
"If you treat the components as independent then each component will have its "
"own color and opacity transfer functions. An example of such a volume would "
"be where the first component is temperature and the second component is "
"density.\n\nIf the components are not independent then they will be considered "
"to represent intensity and opacity respectively. Please verify that the "
"setting of Independent Components is correct.");
break;
case 3:
msg = k_(
"It appears that you are loading a volume with three scalar components per"
"voxel. This application can treat these components in two ways. If you treat "
"the components as independent then each component will have its own color "
"and opacity transfer functions. An example of such a volume would be where "
"the first component is temperature, the second density, and the third "
"pressure.\n\nIf the components are not independent then they will be assumed "
"to represent color as Red, Green, Blue as is typical for physical slices or "
"color photographs. Please verify that the setting of Independent Components "
"is correct.");
break;
case 4:
msg = k_(
"It appears that you are loading a volume with four scalar components per "
"voxel. This application can treat these components in two different ways. "
"If you treat the components as independent then each component will have its "
"own color and opacity transfer functions.\n\nIf the components are not "
"independent then they will be considered to represent color and opacity as "
"Red, Green, Blue, Opacity respectively. Please verify that the setting of "
"Independent Components is corrent.");
break;
}
this->SetPreText(msg.c_str());
this->SetPostText(VTK_VV_OW_DEFAULT_POSTTEXT_LABEL);
this->SubTitleLabel->SetText(ks_("Open Wizard|Components"));
this->Script("pack %s",this->ComponentsFrame->GetWidgetName());
this->IndependentComponentsButton->SetSelectedState(
this->GetOpenFileProperties()->GetIndependentComponents());
this->NextButton->SetCommand(this, "ValidateComponents");
if (!this->Invoked)
{
this->Invoked = 1;
return this->vtkKWWizard::Invoke();
}
return 1;
}
//----------------------------------------------------------------------------
int vtkKWOpenWizard::ValidateComponents()
{
// Set the back button
this->AddBackButtonCommand("PromptComponents");
this->GetOpenFileProperties()->SetIndependentComponents(
this->IndependentComponentsButton->GetSelectedState());
// And move to the next page
return this->PromptUnits();
}
//----------------------------------------------------------------------------
void vtkKWOpenWizard::CreateUnitsFrame()
{
if (!this->IsCreated())
{
return;
}
int i;
// Create the units frame
this->UnitsFrame = vtkKWFrame::New();
this->UnitsFrame->SetParent(this->ClientArea);
this->UnitsFrame->Create();
this->DistanceUnitsEntry = vtkKWEntryWithLabel::New();
this->DistanceUnitsEntry->SetParent(this->UnitsFrame);
this->DistanceUnitsEntry->Create();
this->DistanceUnitsEntry->GetLabel()->SetText(
ks_("Open Wizard|Distance Units:"));
this->Script("grid %s -row 0 -column 0 -sticky nsew -padx 4 -pady 4",
this->DistanceUnitsEntry->GetWidgetName());
char buffer[256];
for (i = 0; i < VTK_MAX_VRCOMP; i++)
{
this->ScalarUnitsEntry[i] = vtkKWEntryWithLabel::New();
this->ScalarUnitsEntry[i]->SetParent(this->UnitsFrame);
this->ScalarUnitsEntry[i]->Create();
sprintf(buffer, ks_("Open Wizard|Units of Component %d:"), i + 1);
this->ScalarUnitsEntry[i]->GetLabel()->SetText(buffer);
}
this->Script("grid %s -row 0 -column 1 -sticky nsew -padx 4 -pady 4",
this->ScalarUnitsEntry[0]->GetWidgetName());
}
//----------------------------------------------------------------------------
int vtkKWOpenWizard::PromptUnits()
{
// Fill some defaults
if (vtkLSMReader::SafeDownCast(this->GetLastReader()))
{
this->GetOpenFileProperties()->SetDistanceUnits("m");
}
vtkDICOMReader *dicom_reader =
vtkDICOMReader::SafeDownCast(this->GetLastReader());
if (dicom_reader)
{
this->GetOpenFileProperties()->SetDistanceUnits("mm");
}
// STK files may have units in them
if (vtkSTKReader::SafeDownCast(this->GetLastReader()))
{
const char *units =
vtkSTKReader::SafeDownCast(this->GetLastReader())->GetUnits();
if (units && units[0] != '\0')
{
this->GetOpenFileProperties()->SetDistanceUnits(units);
}
}
int nb_components =
this->GetOpenFileProperties()->GetNumberOfScalarComponents();
if (!this->GetOpenFileProperties()->GetIndependentComponents() &&
nb_components >= 3)
{
if (!this->GetOpenFileProperties()->GetScalarUnits(0) &&
!this->GetOpenFileProperties()->GetScalarUnits(1) &&
!this->GetOpenFileProperties()->GetScalarUnits(2))
{
this->GetOpenFileProperties()->SetScalarUnits(
0, ks_("Open Wizard|Units|red"));
this->GetOpenFileProperties()->SetScalarUnits(
1, ks_("Open Wizard|Units|green"));
this->GetOpenFileProperties()->SetScalarUnits(
2, ks_("Open Wizard|Units|blue"));
}
if (!this->GetOpenFileProperties()->GetScalarUnits(3) &&
nb_components >= 4)
{
this->GetOpenFileProperties()->SetScalarUnits(
3, ks_("Open Wizard|Units|average"));
}
}
int i;
if (dicom_reader)
{
vtkDICOMCollector *collector = dicom_reader->GetDICOMCollector();
if (collector)
{
vtkMedicalImageProperties *hinfo =
collector->GetCurrentImageMedicalProperties();
if (hinfo && hinfo->GetModality())
{
if (!strcmp(hinfo->GetModality(), "CT"))
{
for (i = 0; i < nb_components; i++)
{
this->GetOpenFileProperties()->SetScalarUnits(i, "HU");
}
}
}
}
}
// If DICOM, we already know enough
if (dicom_reader)
{
return this->ValidateUnits();
}
// Always clear first
if (!this->IsCreated())
{
return 1;
}
this->ForgetClientArea();
if (!this->UnitsFrame)
{
this->CreateUnitsFrame();
}
this->SetPreText(
k_("Please verify the unit labels for this data file. "
"If the application was unable to determine the units then it will "
"list an 'Unknown' value."));
this->SetPostText(VTK_VV_OW_DEFAULT_POSTTEXT_LABEL);
this->SubTitleLabel->SetText(ks_("Open Wizard|Units"));
this->DistanceUnitsEntry->GetWidget()->SetValue(
this->GetOpenFileProperties()->GetDistanceUnits() ?
this->GetOpenFileProperties()->GetDistanceUnits() :
ks_("Open Wizard|Unknown"));
for (i = 0; i < VTK_MAX_VRCOMP; i++)
{
if (i < nb_components)
{
this->ScalarUnitsEntry[i]->GetWidget()->SetValue(
this->GetOpenFileProperties()->GetScalarUnits(i) ?
this->GetOpenFileProperties()->GetScalarUnits(i) :
ks_("Open Wizard|Unknown"));
this->Script("grid %s -row %d -column 1 -sticky nsew -padx 4 -pady 4",
this->ScalarUnitsEntry[i]->GetWidgetName(), i);
}
else
{
this->Script("grid forget %s",
this->ScalarUnitsEntry[i]->GetWidgetName());
}
}
this->Script("pack %s", this->UnitsFrame->GetWidgetName());
this->NextButton->SetCommand(this, "ValidateUnits");
if (!this->Invoked)
{
this->Invoked = 1;
return this->vtkKWWizard::Invoke();
}
return 1;
}
//----------------------------------------------------------------------------
int vtkKWOpenWizard::ValidateUnits()
{
// Set the back button
this->AddBackButtonCommand("PromptUnits");
if (this->DistanceUnitsEntry &&
*this->DistanceUnitsEntry->GetWidget()->GetValue() &&
strcmp(this->DistanceUnitsEntry->GetWidget()->GetValue(),
ks_("Open Wizard|Unknown")))
{
this->GetOpenFileProperties()->SetDistanceUnits(
this->DistanceUnitsEntry->GetWidget()->GetValue());
}
int i;
for (i = 0;
i < this->GetOpenFileProperties()->GetNumberOfScalarComponents(); i++)
{
if (this->ScalarUnitsEntry &&
this->ScalarUnitsEntry[i] &&
*this->ScalarUnitsEntry[i]->GetWidget()->GetValue() &&
strcmp(this->ScalarUnitsEntry[i]->GetWidget()->GetValue(),
ks_("Open Wizard|Unknown")))
{
this->GetOpenFileProperties()->SetScalarUnits(
i, this->ScalarUnitsEntry[i]->GetWidget()->GetValue());
}
}
// And move to the next page
return this->PromptOrientation();
}
//----------------------------------------------------------------------------
void vtkKWOpenWizard::CreateOrientationFrame()
{
if (!this->IsCreated())
{
return;
}
// Create the orientation frame
this->OrientationFrame = vtkKWFrame::New();
this->OrientationFrame->SetParent(this->ClientArea);
this->OrientationFrame->Create();
int label_width = 150; // in pixels, now that we have an icon
int menu_width = 22;
/*
* Resource generated for file:
* KWScanIncreasingColumns.png (zlib, base64) (image file)
*/
static const unsigned int image_KWScanIncreasingColumns_width = 25;
static const unsigned int image_KWScanIncreasingColumns_height = 25;
static const unsigned int image_KWScanIncreasingColumns_pixel_size = 4;
static const unsigned long image_KWScanIncreasingColumns_length = 172;
static const unsigned long image_KWScanIncreasingColumns_decoded_length = 2500;
static const unsigned char image_KWScanIncreasingColumns[] =
"eNr7//8/w/9hhL28vP5TG2OzY8OGDXA8ZcoUiviD3Y5jx/b9v3r1xP+NG1eRZQdIHSF87N"
"jO//MYGMA0yB5c6vD5A+ZOkBkgGoaR+SA7QBgivo/ksEI2gxgMUk+qHbT2B73ig9bparjk"
"QWLig1g8Wl6Nxsdws4PW9flQxwDJ7dZM";
/*
* Resource generated for file:
* KWScanIncreasingRows.png (zlib, base64) (image file)
*/
static const unsigned int image_KWScanIncreasingRows_width = 25;
static const unsigned int image_KWScanIncreasingRows_height = 25;
static const unsigned int image_KWScanIncreasingRows_pixel_size = 4;
static const unsigned long image_KWScanIncreasingRows_length = 188;
static const unsigned long image_KWScanIncreasingRows_decoded_length = 2500;
static const unsigned char image_KWScanIncreasingRows[] =
"eNrdVTEKwCAM9H2+z7kP6KRjl46hH/A9KRewSOnWHLQZjpAguXhHVFWTBkLOWb3xxFFrvV"
"BKeZVH58A5L3xJK5Fdez8sMjhaW63/kpJF5J5+oJ/IZv0HkKPu5ceY/w7UvbSC/ph71go5"
"6t6ezxys/RieILL2g3GPKBxR/WC/V6x3l/2f/x0nE3/WTA==";
/*
* Resource generated for file:
* KWScanIncreasingSlices.png (zlib, base64) (image file)
*/
static const unsigned int image_KWScanIncreasingSlices_width = 25;
static const unsigned int image_KWScanIncreasingSlices_height = 25;
static const unsigned int image_KWScanIncreasingSlices_pixel_size = 4;
static const unsigned long image_KWScanIncreasingSlices_length = 420;
static const unsigned long image_KWScanIncreasingSlices_decoded_length = 2500;
static const unsigned char image_KWScanIncreasingSlices[] =
"eNrdljGLwkAQhfP7UgbyT+zOgwPBwvIIhGsu1SKIIRGxOAuLK8wWaVUEf0YIpBr3hUyMcr"
"fxTPYKi8dmyDLfvnlLCBFZ9ESaTN5kFAUHrLZtLx9RGwP9Py2LTqf0kKbf0vO8ZRzHtdrq"
"vzCg6fSjGI1ectd1M5bjOJmuVgzoCOlmBQ/M2e2SIkk2ue/7mTpnFoZhuf5WCyGwahnwul"
"5HUgi/YE4QvNNwOCD17iH9xMBcx+PXfL+XxcWPpO12Q4vFrH5W+0jlUa6s21rHwGxXq3kO"
"D9ecr/q5DwbmixmhH3OavC4M3EfcF+SJPZgPn5+FGv3adI8P7DHhgxm4j9iDfNGT8+gzc/"
"ah69FXHvfMvWseJnzc5mGSYdJHpfL7ZiKPButYfT9799FkVDLGaLD+hdFV9GT/PGdKGpRE";
vtkKWMenuButton *menubutton;
vtkKWMenu *menu;
vtkKWLabel *label;
this->ColumnAxisMenu = vtkKWMenuButtonWithLabel::New();
this->ColumnAxisMenu->SetParent(this->OrientationFrame);
this->ColumnAxisMenu->Create();
this->ColumnAxisMenu->ExpandWidgetOn();
label = this->ColumnAxisMenu->GetLabel();
label->SetText(ks_("Open Wizard| Increasing Columns are:"));
label->SetWidth(label_width);
label->SetCompoundModeToLeft();
label->SetImageToPixels(image_KWScanIncreasingColumns,
image_KWScanIncreasingColumns_width,
image_KWScanIncreasingColumns_height,
image_KWScanIncreasingColumns_pixel_size,
image_KWScanIncreasingColumns_length);
menubutton = this->ColumnAxisMenu->GetWidget();
menubutton->SetWidth(menu_width);
menubutton->SetAnchorToWest();
menu = menubutton->GetMenu();
menu->SetItemSelectedValueAsInt(
menu->AddRadioButton(
ks_("Orientation|Left / +X axis (default)"),
this, "OrientationCallback"),
vtkKWOpenFileProperties::AxisOrientationPlusX);
menu->SetItemSelectedValueAsInt(
menu->AddRadioButton(
ks_("Orientation|Right / -X axis"),
this, "OrientationCallback"),
vtkKWOpenFileProperties::AxisOrientationMinusX);
menu->SetItemSelectedValueAsInt(
menu->AddRadioButton(
ks_("Orientation|Posterior / +Y axis"),
this, "OrientationCallback"),
vtkKWOpenFileProperties::AxisOrientationPlusY);
menu->SetItemSelectedValueAsInt(
menu->AddRadioButton(
ks_("Orientation|Anterior / -Y axis"),
this, "OrientationCallback"),
vtkKWOpenFileProperties::AxisOrientationMinusY);
menu->SetItemSelectedValueAsInt(
menu->AddRadioButton(
ks_("Orientation|Superior / +Z axis"),
this, "OrientationCallback"),
vtkKWOpenFileProperties::AxisOrientationPlusZ);
menu->SetItemSelectedValueAsInt(
menu->AddRadioButton(
ks_("Orientation|Inferior / -Z axis"),
this, "OrientationCallback"),
vtkKWOpenFileProperties::AxisOrientationMinusZ);
this->RowAxisMenu = vtkKWMenuButtonWithLabel::New();
this->RowAxisMenu->SetParent(this->OrientationFrame);
this->RowAxisMenu->Create();
this->RowAxisMenu->ExpandWidgetOn();
label = this->RowAxisMenu->GetLabel();
label->SetText(ks_("Open Wizard| Increasing Rows are:"));
label->SetWidth(label_width);
label->SetCompoundModeToLeft();
label->SetImageToPixels(image_KWScanIncreasingRows,
image_KWScanIncreasingRows_width,
image_KWScanIncreasingRows_height,
image_KWScanIncreasingRows_pixel_size,
image_KWScanIncreasingRows_length);
menubutton = this->RowAxisMenu->GetWidget();
menubutton->SetWidth(menu_width);
menubutton->SetAnchorToWest();
menu = menubutton->GetMenu();
menu->SetItemSelectedValueAsInt(
menu->AddRadioButton(
ks_("Orientation|Left / +X axis"),
this, "OrientationCallback"),
vtkKWOpenFileProperties::AxisOrientationPlusX);
menu->SetItemSelectedValueAsInt(
menu->AddRadioButton(
ks_("Orientation|Right / -X axis"),
this, "OrientationCallback"),
vtkKWOpenFileProperties::AxisOrientationMinusX);
menu->SetItemSelectedValueAsInt(
menu->AddRadioButton(
ks_("Orientation|Posterior / +Y axis (default)"),
this, "OrientationCallback"),
vtkKWOpenFileProperties::AxisOrientationPlusY);
menu->SetItemSelectedValueAsInt(
menu->AddRadioButton(
ks_("Orientation|Anterior / -Y axis"),
this, "OrientationCallback"),
vtkKWOpenFileProperties::AxisOrientationMinusY);
menu->SetItemSelectedValueAsInt(
menu->AddRadioButton(
ks_("Orientation|Superior / +Z axis"),
this, "OrientationCallback"),
vtkKWOpenFileProperties::AxisOrientationPlusZ);
menu->SetItemSelectedValueAsInt(
menu->AddRadioButton(
ks_("Orientation|Inferior / -Z axis"),
this, "OrientationCallback"),
vtkKWOpenFileProperties::AxisOrientationMinusZ);
this->SliceAxisMenu = vtkKWMenuButtonWithLabel::New();
this->SliceAxisMenu->SetParent(this->OrientationFrame);
this->SliceAxisMenu->Create();
this->SliceAxisMenu->ExpandWidgetOn();
label = this->SliceAxisMenu->GetLabel();
label->SetText(ks_("Open Wizard| Increasing Slices are:"));
label->SetWidth(label_width);
label->SetCompoundModeToLeft();
label->SetImageToPixels(image_KWScanIncreasingSlices,
image_KWScanIncreasingSlices_width,
image_KWScanIncreasingSlices_height,
image_KWScanIncreasingSlices_pixel_size,
image_KWScanIncreasingSlices_length);
menubutton = this->SliceAxisMenu->GetWidget();
menubutton->SetWidth(menu_width);
menubutton->SetAnchorToWest();
menu = menubutton->GetMenu();
menu->SetItemSelectedValueAsInt(
menu->AddRadioButton(
ks_("Orientation|Left / +X axis"),
this, "OrientationCallback"),
vtkKWOpenFileProperties::AxisOrientationPlusX);
menu->SetItemSelectedValueAsInt(
menu->AddRadioButton(
ks_("Orientation|Right / -X axis"),
this, "OrientationCallback"),
vtkKWOpenFileProperties::AxisOrientationMinusX);
menu->SetItemSelectedValueAsInt(
menu->AddRadioButton(
ks_("Orientation|Posterior / +Y axis"),
this, "OrientationCallback"),
vtkKWOpenFileProperties::AxisOrientationPlusY);
menu->SetItemSelectedValueAsInt(
menu->AddRadioButton(
ks_("Orientation|Anterior / -Y axis"),
this, "OrientationCallback"),
vtkKWOpenFileProperties::AxisOrientationMinusY);
menu->SetItemSelectedValueAsInt(
menu->AddRadioButton(
ks_("Orientation|Superior / +Z axis (default)"),
this, "OrientationCallback"),
vtkKWOpenFileProperties::AxisOrientationPlusZ);
menu->SetItemSelectedValueAsInt(
menu->AddRadioButton(
ks_("Orientation|Inferior / -Z axis"),
this, "OrientationCallback"),
vtkKWOpenFileProperties::AxisOrientationMinusZ);
this->Script("grid %s -row 0 -column 0 -sticky nsew -padx 4 -pady 4",
this->ColumnAxisMenu->GetWidgetName());
this->Script("grid %s -row 1 -column 0 -sticky nsew -padx 4 -pady 4",
this->RowAxisMenu->GetWidgetName());
this->Script("grid %s -row 2 -column 0 -sticky nsew -padx 4 -pady 4",
this->SliceAxisMenu->GetWidgetName());
}
//----------------------------------------------------------------------------
int vtkKWOpenWizard::PromptOrientation()
{
// For certain file types, skip this page
// The DICOM reader already puts LPS medical image into
// VTK's RAS, so we don't need to ask for more, the orientation filter
// which is set to RAS by default, will be a no-op, the data will fly
// through it.
if (vtkDICOMReader::SafeDownCast(this->GetLastReader()) ||
vtkGESignaReader::SafeDownCast(this->GetLastReader()) ||
vtkGESignaReader3D::SafeDownCast(this->GetLastReader()))
{
this->OK();
return 1;
}
// Always clear first
this->ForgetClientArea();
if (!this->OrientationFrame)
{
this->CreateOrientationFrame();
}
this->SetPreText(
k_("Please verify that the data's orientation is correct. The menus "
"below allow you to define the mapping between the pixels in your "
"image and the major axes in this application."));
this->SetPostText(VTK_VV_OW_DEFAULT_POSTTEXT_LABEL);
this->SubTitleLabel->SetText(ks_("Open Wizard|Orientation"));
this->Script("pack %s",this->OrientationFrame->GetWidgetName());
this->SliceAxisMenu->GetWidget()->GetMenu()->SelectItemWithSelectedValueAsInt(
this->GetOpenFileProperties()->GetSliceAxis());
this->RowAxisMenu->GetWidget()->GetMenu()->SelectItemWithSelectedValueAsInt(
this->GetOpenFileProperties()->GetRowAxis());
this->ColumnAxisMenu->GetWidget()->GetMenu()->SelectItemWithSelectedValueAsInt(
this->GetOpenFileProperties()->GetColumnAxis());
this->AreOrientationValuesReasonable();
this->NextButton->SetCommand(this, "ValidateOrientation");
this->FinishButton->SetCommand(this,"ValidateOrientation");
if (!this->Invoked)
{
this->Invoked = 1;
return this->vtkKWWizard::Invoke();
}
return 1;
}
//----------------------------------------------------------------------------
int vtkKWOpenWizard::AreOrientationValuesReasonable()
{
vtkKWMenu *menu = this->SliceAxisMenu->GetWidget()->GetMenu();
int slice_axis = menu->GetItemSelectedValueAsInt(
menu->GetIndexOfSelectedItem());
menu = this->RowAxisMenu->GetWidget()->GetMenu();
int row_axis = menu->GetItemSelectedValueAsInt(
menu->GetIndexOfSelectedItem());
menu = this->ColumnAxisMenu->GetWidget()->GetMenu();
int column_axis = menu->GetItemSelectedValueAsInt(
menu->GetIndexOfSelectedItem());
if (vtkKWOpenFileProperties::IsOrientationValid(
column_axis, row_axis, slice_axis))
{
this->SetPostText(VTK_VV_OW_DEFAULT_POSTTEXT_LABEL);
this->NextButton->EnabledOn();
this->FinishButton->EnabledOn();
return 1;
}
this->SetPostText(
k_("Error. The orientation you have specified is not a valid orientation: "
"the same axis is being used for more than one direction. Only one "
"entry from each of the following three pairs may be used: "
"(Left, Right) (Anterior, Posterior) (Superior, Inferior)"));
this->NextButton->EnabledOff();
this->FinishButton->EnabledOff();
return 0;
}
//----------------------------------------------------------------------------
void vtkKWOpenWizard::OrientationCallback()
{
this->AreOrientationValuesReasonable();
}
//----------------------------------------------------------------------------
int vtkKWOpenWizard::ValidateOrientation()
{
// Set the back button
this->AddBackButtonCommand("PromptOrientation");
// At this point the orientation *is* valid, otherwise we could not have
// clicked on the "next" button
vtkKWMenu *menu = this->SliceAxisMenu->GetWidget()->GetMenu();
this->GetOpenFileProperties()->SetSliceAxis(
menu->GetItemSelectedValueAsInt(menu->GetIndexOfSelectedItem()));
menu = this->RowAxisMenu->GetWidget()->GetMenu();
this->GetOpenFileProperties()->SetRowAxis(
menu->GetItemSelectedValueAsInt(menu->GetIndexOfSelectedItem()));
menu = this->ColumnAxisMenu->GetWidget()->GetMenu();
this->GetOpenFileProperties()->SetColumnAxis(
menu->GetItemSelectedValueAsInt(menu->GetIndexOfSelectedItem()));
// And move to the next page
this->OK();
return 1;
}
//----------------------------------------------------------------------------
void vtkKWOpenWizard::Cancel()
{
this->Superclass::Cancel();
// Restore the Previous reader and properties
this->SetLastReader(this->PreviousReader);
this->SetPreviousReader(NULL);
if (this->PreviousOpenFileProperties)
{
this->GetOpenFileProperties()->DeepCopy(this->PreviousOpenFileProperties);
}
}
//----------------------------------------------------------------------------
int vtkKWOpenWizard::Invoke()
{
// First invokes a FileIO dialog to get the file name
if (!this->QueryForFileName())
{
return 0;
}
return this->Invoke(vtkKWOpenWizard::INVOKE_VERBOSE);
}
//----------------------------------------------------------------------------
int vtkKWOpenWizard::InvokeQuiet()
{
// First invokes a FileIO dialog to get the file name
if (!this->QueryForFileName())
{
return 0;
}
return this->Invoke(vtkKWOpenWizard::INVOKE_QUIET);
}
//----------------------------------------------------------------------------
int vtkKWOpenWizard::Invoke(const char *fname, int verbosity)
{
this->SetFileName(fname);
return this->Invoke(verbosity);
}
//----------------------------------------------------------------------------
int vtkKWOpenWizard::Invoke(vtkStringArray *fileNames, int verbosity)
{
this->FileNames->DeepCopy(fileNames);
return this->Invoke(verbosity);
}
//----------------------------------------------------------------------------
int vtkKWOpenWizard::Invoke(int verbosity)
{
const char *fname = this->GetFileName();
if (!fname || !vtksys::SystemTools::FileExists(fname))
{
return 0;
}
// As a convenience, if somebody tries to open a .vvi, open the
// corresponding file automatically.
vtksys_stl::string fname_last_ext(
vtksys::SystemTools::GetFilenameLastExtension(fname));
if (!strcmp(".vvi", fname_last_ext.c_str()))
{
vtksys_stl::string fname_path(
vtksys::SystemTools::GetFilenamePath(fname));
fname_path += '/';
fname_path +=
vtksys::SystemTools::GetFilenameWithoutLastExtension(fname);
return this->Invoke(fname_path.c_str(), verbosity);
}
// The filename should not be in the future (i.e., somebody tempered
// with the clock to bypass expiration time
long int c_time = vtksys::SystemTools::CreationTime(fname);
long int m_time = vtksys::SystemTools::ModifiedTime(fname);
time_t t;
time(&t);
time_t margin = (time_t)(25 * 60 * 60); // a little more than a day
if ((c_time > 0 && c_time > (t + margin)) ||
(m_time > 0 && m_time > (t + margin)))
{
vtkKWMessageDialog::PopupMessage(
this->GetApplication(), 0,
ks_("Open Wizard|Dialog|Open File Error!"),
k_("Please check your system clock: it seems the timestamp of the "
"file you are trying to open is not consistent with the current "
"time of your system."),
vtkKWMessageDialog::ErrorIcon);
return 0;
}
// No master window, use one
if (!this->GetMasterWindow() && this->GetApplication())
{
this->SetMasterWindow(this->GetApplication()->GetNthWindow(0));
}
// Special case: if the title has been set to NULL, set the dialog title
// to use the current application name
if (this->IsCreated() && !this->GetTitle())
{
vtksys_ios::ostringstream title;
title << this->GetApplication()->GetPrettyName()
<< " : " << ks_("Open Wizard|Title|Open File Wizard");
this->SetTitle(title.str().c_str());
}
this->Invoked = 0;
this->ReadyToLoad = vtkKWOpenWizard::DATA_IS_UNAVAILABLE;
// Save the current reader and properties in case the user selects cancel
this->SetPreviousReader(this->GetLastReader());
if (!this->PreviousOpenFileProperties)
{
this->PreviousOpenFileProperties = vtkKWOpenFileProperties::New();
}
this->PreviousOpenFileProperties->DeepCopy(this->GetOpenFileProperties());
// Clear a few values and set some defaults
vtkKWOpenFileProperties *open_prop = this->GetOpenFileProperties();
open_prop->Reset();
/* The LPS co-ordinate system is shown below. The values that correspond
to the X,Y,Z axes are also shown. Know what you are doing if you mess
with this.
HEAD/SUPERIOR +Z(S)[10/4]
POSTERIOR | / +Y(P)[2]
() | /
RIGHT -/\- LEFT |/
|| -X(R)[1] ------+------ +X(L)[0]
ANTERIOR /|
FEET/INFERIOR / |
/ |
-Y(A)[3] -Z(I)[5]
NOTE:
Switching Volview to use RAS instead of LPS is very simple. This was the
behaviour as of 20 Apr 06.
1. Replace the values 10,2,0 in the following 3 lines with 10,3,1.
2. In vtkVVDataItemVolume, locate the line
vw->GetOrientationWidget()->SetAnnotationTypeToMedical();
and add the following line below it.
vw->GetOrientationWidget()->SetCoordinateSystemMedicalToRAS();
3. In the constructor of vtkKW2DRenderWidget, replace the default
this->CoordinateSystemMedical
= vtkKW2DRenderWidget::COORDINATE_SYSTEM_MEDICAL_LPS;
with
this->CoordinateSystemMedical
= vtkKW2DRenderWidget::COORDINATE_SYSTEM_MEDICAL_RAS;
NOTE: the orientation filter below defaults to +X, +Y, +Z, meaning
it does nothing and keeps the data in VTK's "favorite" coordinate
system LPS. For DICOM data, we never show the orientation GUI, data is
loaded by the DICOM reader and re-oriented while loading it, and we are
*looking* at it in a LPS fashion
(see vtkKW2DRenderWidget, double-checked by Seb and Karthik Aug 4 2008).
*/
open_prop->SetColumnAxis(
vtkKWOpenFileProperties::AxisOrientationPlusX); // Left (+X)
open_prop->SetRowAxis(
vtkKWOpenFileProperties::AxisOrientationPlusY); // Posterior (+Y)
open_prop->SetSliceAxis(
vtkKWOpenFileProperties::AxisOrientationPlusZ); // Superior (+Z)
// Is the file valid ?
vtkKWOpenFileHelper *open_helper = this->GetOpenFileHelper();
int valid = open_helper->IsFileValid(this->FileNames);
if (valid == vtkKWOpenFileHelper::FILE_IS_INVALID ||
valid == vtkKWOpenFileHelper::FILE_IS_VALID_NOT_SUPPORTED)
{
if (verbosity == vtkKWOpenWizard::INVOKE_VERBOSE && this->IsCreated())
{
vtksys_stl::string msg;
// Try to print an informative message for DICOM readers.
vtkDICOMReader *dicom_reader =
vtkDICOMReader::SafeDownCast(this->GetLastReader());
if (dicom_reader)
{
msg = k_("Sorry. The file specified cannot be read.");
msg += "\n\n";
vtkDICOMCollector *collector = dicom_reader->GetDICOMCollector();
if (collector &&
collector->GetFailureStatus() != vtkDICOMCollector::FailureNone)
{
vtkDICOMCollector::FailureStatusTypes ft =
(vtkDICOMCollector::FailureStatusTypes)collector->GetFailureStatus();
if (ft & vtkDICOMCollector::FailureCannotGetPixelDataSize)
{
msg += k_("The pixel data size could not be retrieved.");
}
if (ft & vtkDICOMCollector::FailureTooLittlePixelData)
{
msg += k_("Too little pixel data was supplied.");
}
if (ft & vtkDICOMCollector::FailureImagesNotFacingTheSameDirection)
{
msg += k_("Images in this series are not all facing the same direction and cannot be used.");
}
if (ft & vtkDICOMCollector::FailureGantryTilt)
{
msg += k_("Some DICOM features like gantry tilt are not supported for the moment.");
}
if (ft & vtkDICOMCollector::FailureMoreThanOneSamplePerPixel)
{
msg += k_("DICOM files with more than 1 sample per pixel are not supported at the moment.");
}
if (ft & vtkDICOMCollector::FailureMoreThanOneNumberOfFrames)
{
msg += k_("DICOM files with more than 1 number of frames are not supported at the moment.");
}
}
}
else
{
msg =
k_("Sorry. The file specified is either not supported, corrupt or "
"invalid and cannot be read.");
}
vtkKWMessageDialog::PopupMessage(
this->GetApplication(), 0,
ks_("Open Wizard|Dialog|Open File Error!"),
msg.c_str(),
vtkKWMessageDialog::ErrorIcon);
}
return 0;
}
// So we know that at least the file specified can be read in by volview,
// now lets figure out what additional information we need
// If the file is not a data file then we are done
if (valid == vtkKWOpenFileHelper::FILE_IS_VALID_NOT_DATA)
{
return 1;
}
// Otherwise this is a data file
// Check to see if there is a .vvi file
// If nothing works, go to verbose move (ask the user) unless:
// - we were called in light-mode (i.e. we were not created),
// - it's a DICOM file (in that case for backward compat reason we will
// try to load the whole stack).
// - we are in testing mode (i.e. the we are testing the app and should
// not bring any UI in order not to block the tests)
vtkKWApplicationPro *proapp =
vtkKWApplicationPro::SafeDownCast(this->GetApplication());
int success = 1;
int vvi_was_read = 0;
if (!this->IgnoreVVIOnRead &&
(!open_helper->GetDICOMOptions() ||
open_helper->GetDICOMOptions()->GetExploreDirectory()))
{
vvi_was_read = this->ReadVVIForFile(fname);
}
if (!vvi_was_read &&
!this->OpenWithCurrentOpenFileProperties &&
this->IsCreated() &&
!vtkDICOMReader::SafeDownCast(this->GetLastReader()) &&
(!proapp || !proapp->GetTestingMode()))
{
verbosity = vtkKWOpenWizard::INVOKE_VERBOSE;
success = 0;
}
// If we requested to use the current open file properties, instead of
// the ones either set by calling IsFileValid or ReadVVIFile, then
// bring them back from PreviousOpenFileProperties, since it is a copy
// of the open properties before either methods were called.
if (this->OpenWithCurrentOpenFileProperties)
{
this->GetOpenFileProperties()->DeepCopy(
this->PreviousOpenFileProperties);
}
// Start prompting the GUI, if needed
if (this->IsCreated())
{
this->SetPostText(VTK_VV_OW_DEFAULT_POSTTEXT_LABEL);
}
if (valid == vtkKWOpenFileHelper::FILE_IS_VALID &&
verbosity == vtkKWOpenWizard::INVOKE_VERBOSE)
{
// Skip this if it is 3D for sure
vtkImageReader2 *rdr = vtkImageReader2::SafeDownCast(this->GetLastReader());
vtkImageData *output = rdr ? rdr->GetOutput() : NULL;
// The test here is done on the output's whole extent, not the open
// properties's whole extent, which may have been read from the VVI
// file, so that picking a single file from a series that was previously
// opened as a whole series will still allow the user to choose if
// he wants to open it as a series or a single slice.
int output_is_3d = output ?
(output->GetWholeExtent()[5] - output->GetWholeExtent()[4] > 0) : 0;
vtkDICOMReader *dicom_rdr = vtkDICOMReader::SafeDownCast(rdr);
if (!rdr || (output_is_3d && !dicom_rdr) || (!output_is_3d && dicom_rdr))
{
success = this->PromptScope();
}
else
{
success = this->PromptMultiplicity();
}
}
else if (valid == vtkKWOpenFileHelper::FILE_IS_PROBABLY_VALID &&
verbosity == vtkKWOpenWizard::INVOKE_VERBOSE)
{
success = this->PromptRaw();
}
// If the invocation was successful save the info out as a
// vvi file so that the user will have the correct defaults next time
if (success)
{
// Free the Previous Reader
this->SetPreviousReader(NULL);
// copy parameters over to the reader
vtkImageReader2 *rdr =
vtkImageReader2::SafeDownCast(this->GetLastReader());
if (rdr)
{
rdr->SetDataExtent(this->GetOpenFileProperties()->GetWholeExtent());
rdr->SetDataSpacing(this->GetOpenFileProperties()->GetSpacing());
rdr->SetDataOrigin(this->GetOpenFileProperties()->GetOrigin());
rdr->SetDataScalarType(this->GetOpenFileProperties()->GetScalarType());
rdr->SetNumberOfScalarComponents(
this->GetOpenFileProperties()->GetNumberOfScalarComponents());
if (this->GetOpenFileProperties()->GetDataByteOrder() !=
vtkKWOpenFileProperties::DataByteOrderUnknown)
{
rdr->SetDataByteOrder(
this->GetOpenFileProperties()->GetDataByteOrder());
}
rdr->SetFileDimensionality(
this->GetOpenFileProperties()->GetFileDimensionality());
rdr->SetFilePattern(
this->GetOpenFileProperties()->GetAbsoluteFilePatternForFile(fname));
}
this->ReadyToLoad = vtkKWOpenWizard::DATA_IS_READY_TO_LOAD;
if (!this->IgnoreVVIOnWrite)
{
this->WriteVVIForFile(fname);
}
}
return success;
}
//----------------------------------------------------------------------------
void vtkKWOpenWizard::Release(int output_port)
{
if (this->GetOutput(output_port) &&
this->ReadyToLoad == vtkKWOpenWizard::DATA_IS_LOADED)
{
this->GetOutput(output_port)->ReleaseData();
// fixme
this->ReadyToLoad = vtkKWOpenWizard::DATA_IS_READY_TO_LOAD;
}
}
//----------------------------------------------------------------------------
void vtkKWOpenWizard::Load(int output_port)
{
if (this->ReadyToLoad != vtkKWOpenWizard::DATA_IS_READY_TO_LOAD)
{
return;
}
// Release old data if not done already
if (this->GetOutput(0))
{
this->GetOutput(0)->ReleaseData();
}
// Check the new data
// If it is a valid unstructured grid, then we are done.
vtkUnstructuredGrid *unstructuredRes = this->GetLastReader() ? vtkUnstructuredGrid::SafeDownCast(
this->GetLastReader()->GetOutputDataObject(output_port)) : NULL;
if (unstructuredRes)
{
this->ReadyToLoad = vtkKWOpenWizard::DATA_IS_LOADED;
return;
}
vtkImageData *res = this->GetLastReader() ? vtkImageData::SafeDownCast(
this->GetLastReader()->GetOutputDataObject(output_port)) : NULL;
if (!res)
{
vtkKWMessageDialog::PopupMessage(
this->GetApplication(), 0,
ks_("Open Wizard|Dialog|Open File Error!"),
k_("The data could not be loaded!"),
vtkKWMessageDialog::ErrorIcon );
return;
}
// Connect color filter
if (!this->ColorImageConversionFilter)
{
this->ColorImageConversionFilter = vtkKWColorImageConversionFilter::New();
}
this->ColorImageConversionFilter->SetInput(res);
this->ColorImageConversionFilter->SetAlphaFloor(1.0);
this->ColorImageConversionFilter->SetIndependentComponents(
this->GetOpenFileProperties()->GetIndependentComponents());
this->ColorImageConversionFilter->GetOutput()->ReleaseDataFlagOn();
// UpdateInfo has to be called here so that we can query GetConversions()
// below (done in vtkKWColorImageConversionFilter::RequestInfo).
// Bear in mind that this propagate up to the reader, meaning the
// reader will likely resets its DataSpacing, DataOrigin, etc, if those
// infos are indeed extracted and supported by the reader.
this->ColorImageConversionFilter->UpdateInformation();
res->ReleaseDataFlagOn();
// execute the reader, with progress
vtkKWWindow *firstw = vtkKWWindow::SafeDownCast(this->MasterWindow);
if (firstw)
{
vtkKWProgressCommand *cb = vtkKWProgressCommand::New();
vtkKWProgressCommand *cb2 = vtkKWProgressCommand::New();
cb2->SetWindow(firstw);
cb2->SetStartMessage(ks_("Progress|Converting color data"));
if (this->ColorImageConversionFilter->GetConversions()
& vtkKWColorImageConversionFilter::ConvertedToFloat ||
this->ColorImageConversionFilter->GetConversions()
& vtkKWColorImageConversionFilter::ConvertedToColor)
{
cb2->SetStartMessage(ks_("Progress|Reading and Converting color data"));
}
else
{
cb->SetWindow(firstw);
cb->SetStartMessage(ks_("Progress|Reading data from disk"));
this->GetLastReader()->AddObserver(vtkCommand::StartEvent, cb);
this->GetLastReader()->AddObserver(vtkCommand::ProgressEvent, cb);
this->GetLastReader()->AddObserver(vtkCommand::EndEvent, cb);
}
this->ColorImageConversionFilter->AddObserver(
vtkCommand::StartEvent, cb2);
this->ColorImageConversionFilter->AddObserver(
vtkCommand::ProgressEvent, cb2);
this->ColorImageConversionFilter->AddObserver(vtkCommand::EndEvent, cb2);
this->ColorImageConversionFilter->UpdateWholeExtent();
// remove the progress because it creates a circular loop
if (res->GetNumberOfScalarComponents() != 3 ||
this->GetOpenFileProperties()->GetIndependentComponents())
{
this->GetLastReader()->RemoveObserver(cb);
}
this->ColorImageConversionFilter->RemoveObserver(cb2);
cb->Delete();
cb2->Delete();
}
else
{
this->ColorImageConversionFilter->UpdateWholeExtent();
}
// No data
vtkImageData *color_output = this->ColorImageConversionFilter->GetOutput();
if (!color_output->GetPointData() ||
!color_output->GetPointData()->GetScalars())
{
vtkKWMessageDialog::PopupMessage(
this->GetApplication(), 0,
ks_("Open Wizard|Dialog|Open File Error!"),
k_("This file does not contain any usable data (structured points, "
"pixels, etc.). Most likely this file format can store different "
"kind of data, but this specific instance does not hold anything "
"this application can use."),
vtkKWMessageDialog::ErrorIcon);
return;
}
// if some funky conversion had to be done then report this to the user
unsigned long conv = this->ColorImageConversionFilter->GetConversions();
if (conv & vtkKWColorImageConversionFilter::CompressedSpacing ||
conv & vtkKWColorImageConversionFilter::CompressedAspectRatio ||
conv & vtkKWColorImageConversionFilter::ShiftedOrigin)
{
vtkKWMessageDialog::PopupMessage(
this->GetApplication(), 0,
ks_("Open Wizard|Dialog|Open File Warning!"),
k_("The volume you are loading has an origin, spacing, "
"or aspect ratio that exceeds the application's limits. "
"These values have been automatically adjusted. As a result "
"physical properties such as position, surface area, "
"may not accurately reflect your original data."),
vtkKWMessageDialog::WarningIcon );
}
if (conv & vtkKWColorImageConversionFilter::CompressedScalarRange)
{
vtkKWMessageDialog::PopupMessage(
this->GetApplication(), 0,
ks_("Open Wizard|Dialog|Open File Warning!"),
k_("The volume you are loading has a scalar range that "
"exceeds the application's limits. These values have been "
"automatically adjusted. As a result voxel intensities may not "
"accurately reflect your original data."),
vtkKWMessageDialog::WarningIcon );
}
// deal with orientation
if (!this->OrientationFilter)
{
this->OrientationFilter = vtkKWOrientationFilter::New();
}
else
{
#if 0
// TODO: plugins detach from the reader (vtkVVPlugin)
// this is a no-op in the new executive, so it has to be
// taken care of somehow and see how the below code should
// be modified
// reattach the source in case a plugin removed it
if (!this->GetOutput()->GetSource())
{
this->GetOutput()->SetSource(this->OrientationFilter);
}
#endif
}
if (firstw)
{
vtkKWProgressCommand *cb = vtkKWProgressCommand::New();
cb->SetWindow(firstw);
cb->SetStartMessage(ks_("Progress|Orienting data"));
this->OrientationFilter->AddObserver(vtkCommand::StartEvent, cb);
this->OrientationFilter->AddObserver(vtkCommand::ProgressEvent, cb);
this->OrientationFilter->AddObserver(vtkCommand::EndEvent, cb);
this->AdjustOrientationFilter();
// remove the progress because it creates a circular loop
this->OrientationFilter->RemoveObserver(cb);
cb->Delete();
}
else
{
this->AdjustOrientationFilter();
}
this->ReadyToLoad = vtkKWOpenWizard::DATA_IS_LOADED;
}
//----------------------------------------------------------------------------
void vtkKWOpenWizard::AdjustOrientationFilter()
{
if (!this->GetLastReader())
{
return;
}
// Assume all readers are vtkAlgorithms and output is the first output
this->OrientationFilter->SetInput(
this->ColorImageConversionFilter->GetOutput());
// if you are wonder how the heck the numbers below were picked it
// is pretty easy. The positive and negative i,j,k axes are numbered
// 0,1,2,3,4,5 (so negative I axis is 1 for example) if the number
// is greater that 5 then the axis it refers to is num%6. This
// consistency is used by algoritms and should not be changed.
// Please don't do anything that would give the impression that
// these values could be changed. (such as making them defines or an
// enum) Think of these values as the dimensionality of a vtkImageData
// (2 or 3) Not a good place for #define because so many algorithms
// require these values to always be 2 or 3
int iaxis = this->GetOpenFileProperties()->GetColumnAxis() % 6;
int jaxis = this->GetOpenFileProperties()->GetRowAxis() % 6;
int kaxis = this->GetOpenFileProperties()->GetSliceAxis() % 6;
int outAxes[3];
outAxes[iaxis/2] = 0;
if (iaxis%2)
{
outAxes[iaxis/2] = 3;
}
outAxes[jaxis/2] = 1;
if (jaxis%2)
{
outAxes[jaxis/2] = 4;
}
outAxes[kaxis/2] = 2;
if (kaxis%2)
{
outAxes[kaxis/2] = 5;
}
// In most cases outAxes should be (0,1,2). The DICOMReader tries to read
// data and place it in the right order to make things fast. If you were to
// switch from LPS to RAS as detailed in the comments on the top of the file,
// clearly outAxes would generally read be (3,4,2)
this->OrientationFilter->SetOutputAxes(outAxes);
this->OrientationFilter->UpdateWholeExtent();
}
//----------------------------------------------------------------------------
vtkImageData *vtkKWOpenWizard::GetSeriesOutput(int inputIndex, int output_port)
{
int index = inputIndex + this->GetSeriesMinimum();
if( index < this->GetSeriesMinimum() ||
index > this->GetSeriesMaximum() )
{
return NULL;
}
if( this->GetLastReader() )
{
const char * pattern = this->GetSeriesPattern();
char *fileName = new char [strlen(pattern) + 50];
sprintf(fileName,pattern,index);
vtkImageReader2 *rdr =
vtkImageReader2::SafeDownCast(this->GetLastReader());
rdr->SetFileName(fileName);
// fixme
this->Release(output_port);
this->Load(output_port);
delete [] fileName;
return this->GetOutput(output_port);
}
return NULL;
}
//----------------------------------------------------------------------------
vtkUnstructuredGrid *vtkKWOpenWizard::GetUnstructuredGridOutput(int output_port)
{
// why is output_port ignored?
return this->GetLastReader() ?
vtkUnstructuredGrid::SafeDownCast(this->GetLastReader()->GetOutputDataObject(0))
: NULL;
}
//----------------------------------------------------------------------------
vtkImageData *vtkKWOpenWizard::GetOutput(int output_port)
{
// why is output_port ignored?
return this->OrientationFilter ?
vtkImageData::SafeDownCast(this->OrientationFilter->GetOutputDataObject(0))
: NULL;
}
//----------------------------------------------------------------------------
void vtkKWOpenWizard::WriteVVIForFile(const char *fname)
{
// if it is a vtkImageReader2, then look to see if FilePattern is set
// if it is set then use the FilePattern and WholeExtent to determine
// the right name for the vvi file
char *vvi_fname = NULL;
vtkImageReader2 *rdr = vtkImageReader2::SafeDownCast(this->GetLastReader());
if (rdr && !rdr->GetFileName())
{
// Remove the VVI file that would eventually be associated to
// the file when it was open as a single slice. Otherwise it will
// be picked over and over again from "Open Recent File" for example
// instead of picking the VVI file associated to the whole series,
// which name is created below.
if (this->GetFileName())
{
vtksys_stl::string prev_vvi_fname(this->GetFileName());
prev_vvi_fname += ".vvi";
vtksys::SystemTools::RemoveFile(prev_vvi_fname.c_str());
}
vvi_fname = new char[strlen(rdr->GetFilePattern()) + 10];
// Actually instead of using the first slice of the whole extent,
// we will always use slice 0 *even* if it doesn't exist. The rational
// here is that if the user request slices 20 to 80 our of a 0 to 100
// stack, we would have ended creating a foo-20.raw.vvi file for example.
// Now the next time we request slice 0 to 100, we end up writing
// foo-00.raw.vvi, etc etc. So we end up with potentially lots of
// vvi files in the directory, all of them good candidates to be used
// the next time we open a file part of these series (since both files
// above could be valid while loading slice 25 for example).
// To avoid that, *always* write to foo-00.raw.vvi, so that only one
// single VVI file describes a series of file (all other would describe
// loading a *single* slice). Sounds like a good compromise.
// and this could conflict with a
sprintf(vvi_fname, rdr->GetFilePattern(), 0); // rdr->GetDataExtent()[4]);
}
else
{
// If DICOM reader, use the first slice filename
vtkDICOMReader *dicom_reader =
vtkDICOMReader::SafeDownCast(this->GetLastReader());
if (dicom_reader)
{
vtkDICOMCollector *col = dicom_reader->GetDICOMCollector();
if (col && col->CollectAllSlices() > 1)
{
const char *first_slice_fname = col->GetSliceFileName(0);
if (first_slice_fname)
{
// Same as above, remove the VVI file for a single slice
if (this->GetFileName())
{
vtksys_stl::string prev_vvi_fname(this->GetFileName());
prev_vvi_fname += ".vvi";
vtksys::SystemTools::RemoveFile(prev_vvi_fname.c_str());
}
fname = first_slice_fname;
}
}
}
vvi_fname = new char[strlen(fname) + 10];
strcpy(vvi_fname, fname);
}
strcat(vvi_fname, ".vvi");
vtkKWOpenFileProperties *open_prop = this->GetOpenFileProperties();
vtkXMLKWOpenFilePropertiesWriter *xmlw =
vtkXMLKWOpenFilePropertiesWriter::SafeDownCast(
open_prop->GetNewXMLWriter());
xmlw->DiscardFilePatternDirectoryOn();
xmlw->WriteIndentedOn();
xmlw->WriteToFile(vvi_fname);
xmlw->Delete();
delete [] vvi_fname;
}
//----------------------------------------------------------------------------
int vtkKWOpenWizard::IsVVIValid(const char *vvi_fname)
{
int res = vtkKWOpenWizard::VVI_IS_VALID;
// Use a new open prop, do not overwrite ours
vtkKWOpenFileProperties *open_prop = vtkKWOpenFileProperties::New();
vtkXMLKWOpenFilePropertiesReader *xmlr =
vtkXMLKWOpenFilePropertiesReader::SafeDownCast(
open_prop->GetNewXMLReader());
xmlr->SetObject(open_prop);
if (!xmlr->ParseFile(vvi_fname))
{
vtkErrorMacro("Failed reading VVI file!");
res = vtkKWOpenWizard::VVI_IS_INVALID;
}
else if (!xmlr->IsValid())
{
res = vtkKWOpenWizard::VVI_IS_INVALID;
}
xmlr->Delete();
open_prop->Delete();
return res;
}
//----------------------------------------------------------------------------
int vtkKWOpenWizard::DoesVVIIncludeFile(const char *vvi_fname,
const char *fname)
{
int res = vtkKWOpenWizard::VVI_IS_VALID;
// Check if the information included in the VVI file describe a series
// that fname is part of
// Use a new open prop, do not overwrite ours
vtkKWOpenFileProperties *open_prop = vtkKWOpenFileProperties::New();
vtkXMLKWOpenFilePropertiesReader *xmlr =
vtkXMLKWOpenFilePropertiesReader::SafeDownCast(
open_prop->GetNewXMLReader());
if (!xmlr->ParseFile(vvi_fname))
{
vtkErrorMacro("Failed reading VVI file!");
res = vtkKWOpenWizard::VVI_IS_INVALID;
}
// First check it is valid
if (!xmlr->IsValid())
{
res = vtkKWOpenWizard::VVI_IS_INVALID;
}
else
{
// We need a VVI file that describes a pattern based series
if (xmlr->IsDescribingPatternSeries())
{
res = vtkKWOpenWizard::VVI_HAS_REQUIRED_TOKEN;
int *wext = open_prop->GetWholeExtent();
char tmp[3000];
// Try checking if the file matches for some reasonable slice numbers
const char *pattern = open_prop->GetAbsoluteFilePatternForFile(fname);
for (int i = wext[4]; i <= wext[5]; ++i)
{
sprintf(tmp, pattern, i);
if (!strcmp(fname, tmp))
{
res = vtkKWOpenWizard::VVI_IS_COMPLIANT;
break;
}
}
}
}
xmlr->Delete();
open_prop->Delete();
// If not, i.e. the file is just "valid", not "compliant", then
// maybe fname is a DICOM file and the contents of the VVI file was not
// enough to detect if it is part of the same series (there is no
// FilePattern or FileName in a DICOM VVI file). Try to see if
// this is a DICOM file, and if the VVI file that was stored for the
// first slice of this series matches a filename part of the same series.
// Note that there is a hack involved here: creating a whole new
// DICOMReader *does* cost resources, as the whole stack of slices
// will be collected again, and multiple slices may potentially be
// read to make sure the scalar type is right (especially for CT).
// To avoid that, we check if 'fname' is actually the filename we
// are processing at the very moment in LastReader. If it is the case,
// then use LastReader and its DICOM collector, as they already have cached
// most of the information we need.
if (res == vtkKWOpenWizard::VVI_IS_VALID)
{
vtkKWOpenWizard *dummy = NULL;
vtkDICOMReader *rdr = vtkDICOMReader::SafeDownCast(this->GetLastReader());
if (!rdr || strcmp(fname, rdr->GetFileName()))
{
dummy = vtkKWOpenWizard::New();
dummy->GetOpenFileHelper()->SetDICOMOptions(
this->GetOpenFileHelper()->GetDICOMOptions());
if (dummy->GetOpenFileHelper()->IsFileValid(fname) ==
vtkKWOpenFileHelper::FILE_IS_VALID)
{
rdr = vtkDICOMReader::SafeDownCast(dummy->GetLastReader());
//rdr->SetFileName(fname);
// TODO: there is still a problem here as a we are not taking into
// account a list of filenames set explicitly (this method's API
// should be modified to include all extra filenames).
// Try this:
if (rdr)
{
rdr->SetFileNames(this->FileNames);
}
}
}
if (rdr)
{
vtksys_stl::string slice_name =
vtksys::SystemTools::GetFilenamePath(vvi_fname) + "/" +
vtksys::SystemTools::GetFilenameWithoutLastExtension(vvi_fname);
if (rdr->GetDICOMCollector()->DoesIncludeFile(slice_name.c_str()))
{
res = vtkKWOpenWizard::VVI_IS_COMPLIANT;
}
}
if (dummy)
{
dummy->Delete();
}
}
return res;
}
//----------------------------------------------------------------------------
int vtkKWOpenWizard::ReadVVIForFile(const char *fname)
{
int success = 0;
vtkKWOpenFileProperties *open_prop = this->GetOpenFileProperties();
vtksys_stl::string fname_dir = vtksys::SystemTools::GetFilenamePath(fname);
vtkXMLKWOpenFilePropertiesReader *xmlr =
vtkXMLKWOpenFilePropertiesReader::SafeDownCast(
open_prop->GetNewXMLReader());
vtksys_stl::string vvi_fname(fname);
vvi_fname += ".vvi";
// Maybe it is a series ... is there a vvi file in the same directory?
// that has this slice as part of it?
int has_vvi_file = vtksys::SystemTools::FileExists(vvi_fname.c_str());
if(!has_vvi_file)
{
vtkDirectory *dir = vtkDirectory::New();
if (dir->Open(fname_dir.c_str()))
{
int num_files = dir->GetNumberOfFiles();
for (int i = 0; i < num_files; ++i)
{
vtksys_stl::string fname_try(dir->GetFile(i));
vtksys_stl::string fname_try_ext(
vtksys::SystemTools::GetFilenameLastExtension(fname_try));
if (!strcmp(".vvi", fname_try_ext.c_str()))
{
vtksys_stl::string fname_try_full(fname_dir);
fname_try_full = fname_try_full + "/" + fname_try;
if (this->DoesVVIIncludeFile(fname_try_full.c_str(), fname) ==
vtkKWOpenWizard::VVI_IS_COMPLIANT)
{
vvi_fname = fname_try_full;
has_vvi_file = 1;
break;
}
}
}
}
dir->Delete();
}
// Has a VVI file, let's try to read it
if (has_vvi_file &&
this->IsVVIValid(vvi_fname.c_str()) == vtkKWOpenWizard::VVI_IS_VALID)
{
success = xmlr->ParseFile(vvi_fname.c_str()) ? 1 : 0;
if (!success)
{
vtkErrorMacro("Failed reading VVI file! " << vvi_fname);
}
}
xmlr->Delete();
if (success)
{
// If it's a 2D slice, prevent the collector from getting any more slices
// Shouldn't that be at the end of the big ::Invoke(...)
vtkDICOMReader *dicom_reader =
vtkDICOMReader::SafeDownCast(this->GetLastReader());
if (dicom_reader)
{
vtkDICOMCollectorOptions *options =
dicom_reader->GetDICOMCollector()->GetOptions();
int old_explore = options->GetExploreDirectory();
int *wext = open_prop->GetWholeExtent();
options->SetExploreDirectory(wext[5] <= wext[4] ? 0 : 1);
if (old_explore != options->GetExploreDirectory())
{
dicom_reader->GetDICOMCollector()->ClearCollectedSlices();
}
}
}
return success;
}
//----------------------------------------------------------------------------
int vtkKWOpenWizard::QueryForFileName(const char *title)
{
this->LoadDialog->SetTitle(
title ? title : ks_("Open Wizard|Title|Open File"));
//this->LoadDialog->SetDefaultExtension(".vtk");
char fileTypes[2048];
fileTypes[0] = 0;
strcat(fileTypes, "{{DICOM} {*}} ");
if (!this->GetOpenFileHelper()->GetSupportDICOMFormatOnly())
{
strcat(
fileTypes,
"{{3D} {.vtk .vti .pic .lsm .slc .stk .hdr}} ");
strcat(
fileTypes,
"{{2D} {.bmp .jpg .jpeg .png .pgm .ppm .pnm .tif .tiff}} ");
vtksys_stl::string helperFileTypes =
this->GetOpenFileHelper()->GetFileTypesTclString();
if (helperFileTypes != "")
{
strcat(fileTypes, helperFileTypes.c_str());
}
strcat(fileTypes, "{{VTK} {.vtk .vti}} ");
strcat(fileTypes, "{{Analyze} {.hdr}} ");
strcat(fileTypes, "{{BMP} {.bmp}} ");
strcat(fileTypes, "{{GE Signa} {.MR .CT}} ");
strcat(fileTypes, "{{JPEG} {.jpg .jpeg}} ");
strcat(fileTypes, "{{Zeiss LSM} {.lsm}} ");
strcat(fileTypes, "{{Metamorph Stack} {.stk}} ");
strcat(fileTypes, "{{PIC} {.pic}} ");
strcat(fileTypes, "{{PNG} {.png}} ");
strcat(fileTypes, "{{PNM} {.pgm .ppm .pnm}} ");
strcat(fileTypes, "{{SLC} {.slc}} ");
strcat(fileTypes, "{{TIFF} {.tif .tiff}} ");
strcat(fileTypes, "{{MetaImage} {.mhd .mha}} ");
strcat(fileTypes, "{{Raw} {*}} ");
}
this->LoadDialog->SetFileTypes(fileTypes);
if (!this->LoadDialog->Invoke())
{
return 0;
}
if(this->LoadDialog->GetNumberOfFileNames())
{
this->FileNames->DeepCopy(this->LoadDialog->GetFileNames());
return 1;
}
return 0;
}
//----------------------------------------------------------------------------
vtkKWOpenFileProperties* vtkKWOpenWizard::GetOpenFileProperties()
{
return this->GetOpenFileHelper()->GetOpenFileProperties();
}
//----------------------------------------------------------------------------
vtkAlgorithm* vtkKWOpenWizard::GetLastReader()
{
return this->GetOpenFileHelper()->GetLastReader();
}
//----------------------------------------------------------------------------
void vtkKWOpenWizard::SetLastReader(vtkAlgorithm *algorithm)
{
this->GetOpenFileHelper()->SetLastReader(algorithm);
}
//----------------------------------------------------------------------------
void vtkKWOpenWizard::AddValidFileExtension(
const char *description, const char *extension)
{
this->GetOpenFileHelper()->AddValidFileExtension(description, extension);
}
//----------------------------------------------------------------------------
void vtkKWOpenWizard::PrintSelf(ostream& os, vtkIndent indent)
{
this->Superclass::PrintSelf(os,indent);
os << indent << "LoadDialog: " << this->LoadDialog << endl;
os << indent << "ReadyToLoad: " << this->ReadyToLoad << endl;
os << indent << "IgnoreVVIOnRead: " << this->IgnoreVVIOnRead << endl;
os << indent << "IgnoreVVIOnWrite: " << this->IgnoreVVIOnWrite << endl;
os << indent << "OpenWithCurrentOpenFileProperties: " << this->OpenWithCurrentOpenFileProperties << endl;
os << indent << "FileNames:";
if (this->FileNames)
{
os << endl;
this->FileNames->PrintSelf(os,indent.GetNextIndent());
}
else
{
os << " (none)" << endl;
}
os << indent << "OpenFileHelper:";
if (this->OpenFileHelper)
{
os << endl;
this->OpenFileHelper->PrintSelf(os,indent.GetNextIndent());
}
else
{
os << " (none)" << endl;
}
}
|