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
|
/*
* vp_compA.m4
*
* Compositing routine for affine viewing transformations.
*
* Copyright (c) 1994 The Board of Trustees of The Leland Stanford
* Junior University. All rights reserved.
*
* Permission to use, copy, modify and distribute this software and its
* documentation for any purpose is hereby granted without fee, provided
* that the above copyright notice and this permission notice appear in
* all copies of this software and that you do not sell the software.
* Commercial licensing is available by contacting the author.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND WITHOUT WARRANTY OF ANY KIND,
* EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY
* WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.
*
* Author:
* Phil Lacroute
* Computer Systems Laboratory
* Electrical Engineering Dept.
* Stanford University
*/
/*
* $Date: 1994/12/30 23:52:38 $
* $Revision: 1.7 $
*/
#include "vp_global.h"
dnl Description:
dnl This is an m4 source file which defines a C procedure to resample
dnl and composite one slice of a volume. The macro definitions allow
dnl the procedure to be specialized for a particular volume data
dnl structure (run-length encoded classified volume, or unclassified
dnl volume with or without a min-max octree), a particular number of
dnl color channels (1 or 3), and a particular number of material types.
dnl The definitions are a bit messy, but they keep the body of the
dnl procedure pretty clean. Inlined procedures would be better but
dnl many compilers do not support them.
dnl
dnl To produce a C source file, run this file through m4 with the
dnl following m4 macros defined:
dnl
dnl FuncName name of the C function to produce
dnl VolumeType "rlevolume" or "rawvolume"
dnl ColorChannels number of color channels (1 or 3)
dnl NumMaterials number of materials (a small integer or "n"
dnl for a routine which handles any number)
dnl
dnl OR, define "SourceFile" to be a file name of the form
dnl vp_compA????.c
dnl where the four wildcard characters (call them W, X, Y and Z)
dnl can have the following values:
dnl W: volume type ("C" for classified volumes, "R" for raw volumes)
dnl X: number of color channels ("1" for grayscale, "3" for RGB)
dnl Y: number of materials ("1", "2", "N" for any number, "P" for
dnl callback procedure to replace the material shading model)
dnl Z: special options ("S" for rendering shadows, "G" for
dnl generating shadow buffer, "N" for nearest-neighbor filter,
dnl "I" to use index volume, "B" for normal case (bilinear
dnl filter, no shadows, no index volume)
dnl
ifdef(`SourceFile', `
define(FuncNameStr, `substr(SourceFile, 7, 5)')
define(VolumeTypeChar, `substr(SourceFile, 8, 1)')
define(ColorChannels, `substr(SourceFile, 9, 1)')
define(NumMaterials, `substr(SourceFile, 10, 1)')
define(SpecialChar, `substr(SourceFile, 11, 1)')
define(FuncName, `VPComp'FuncNameStr())
ifelse(VolumeTypeChar, `C',
`define(VolumeType, `rlevolume')',
VolumeTypeChar, `R',
`define(VolumeType, `rawvolume')')
ifelse(SpecialChar, `S', `
#define USE_SHADOW_BUFFER
define(ShadowBuffer)')
ifelse(SpecialChar, `G', `
#define COMPUTE_SHADOW_BUFFER')
ifelse(SpecialChar, `I', `
define(`IndexVolume')')
')
dnl Turn off unrolling of the run loop for the non-specialized routines.
ifelse(NumMaterials, `N', `#undef UNROLL_RUN_LOOP',
NumMaterials, `P', `#undef UNROLL_RUN_LOOP')
dnl
dnl LoadTopLeft()
dnl
dnl Load, classify and shade the voxel above and left of the current pixel.
dnl
define(LoadTopLeft, `
ClassifyVox(top_opc, topRLEdata - voxel_istride);
ShadeVox(top, topRLEdata - voxel_istride)')
dnl
dnl LoadTopRight()
dnl
dnl Load, classify and shade the voxel above and right of the current pixel.
dnl
define(LoadTopRight, `
ClassifyVox(top_opc, topRLEdata);
ShadeVox(top, topRLEdata)')
dnl
dnl LoadBotLeft()
dnl
dnl Load, classify and shade the voxel below and left of the current pixel.
dnl
define(LoadBotLeft, `
ClassifyVox(bot_opc, botRLEdata - voxel_istride);
ShadeVox(bot, botRLEdata - voxel_istride)')
dnl
dnl LoadBotRight()
dnl
dnl Load, classify and shade the voxel below and right of the current pixel.
dnl
define(LoadBotRight, `
ClassifyVox(bot_opc, botRLEdata);
ShadeVox(bot, botRLEdata)')
dnl
dnl ShadeVox(scan, voxel)
dnl
dnl Shade the voxel pointed to by "voxel" and store the result in the
dnl color variables for scanline scan (either "top" or "bot").
dnl
define(ShadeVox, `
ifelse(ColorChannels, 0, `', `
ComputeShadeIndex($2);
ComputeWeightIndex($2);
CallShader($1, $2);
shade_factor = $1_opc * slice_depth_cueing;
AttenuateColor($1);
AttenuateShadowColor($1)')')
dnl
dnl ComputeShadeIndex(voxel)
dnl
dnl Compute the offset into the shade and shadow tables for the specified
dnl voxel.
dnl
define(ComputeShadeIndex,
ifelse(NumMaterials, `P', `',
`shade_index=MaterialCount()*ColorChannels()*ShortField($1,norm_offset)'))
dnl
dnl ComputeWeightIndex(voxel)
dnl
dnl Compute the offset into the material weight table for the specified
dnl voxel.
dnl
define(ComputeWeightIndex,
ifelse(NumMaterials, `P', `', NumMaterials, `1', `',
`weight_index = MaterialCount() * ByteField($1, wgt_offset)'))
dnl
dnl MaterialCount()
dnl
dnl Return the number of materials, as a constant if possible.
dnl
define(MaterialCount,
`ifelse(NumMaterials, `N', `num_materials', NumMaterials)')
dnl
dnl CallShader(scan, voxel)
dnl
dnl Invoke the appropriate shader code to compute the color of the
dnl voxel pointed to by "voxel". Store the result in the
dnl color variables for scanline scan (either "top" or "bot").
dnl
ifelse(NumMaterials, `P',
`ifelse(ColorChannels, 1,
`define(CallShader, `shade_func($2, &($1_clr), client_data)')',
`define(CallShader, `shade_func($2, &($1_rclr), &($1_gclr), &($1_bclr),
client_data)')')',
NumMaterials, `1',
`define(CallShader, `ShadeMaterial($1, 0, =)')',
NumMaterials, `2',
`define(CallShader, `
ShadeMaterial($1, 0, =);
ShadeMaterial($1, 1, +=)')',
`define(CallShader, `
ShadeMaterial($1, 0, =);
for (m = 1; m < num_materials; m++) {
ShadeMaterial($1, m, +=);
}')')
dnl Preprocessor definitions that cause local variables specific to the
dnl shader to be allocated.
ifelse(NumMaterials, 1, ,
NumMaterials, `P', `
#define CALLBACK', `
#define MULTIPLE_MATERIALS')
dnl
dnl ShadeMaterial(scan, material, op)
dnl
dnl Compute the contribution of material number "material" to the
dnl color of the current voxel. The result is stored in the color
dnl variables for scanline scan (either "top" or "bot") using
dnl operation op ("=" or "+=").
dnl
ifelse(ColorChannels, 1,
`define(ShadeMaterial, `
ShadeComponent($1_clr, $2, $3, 0);
ShadeShadowComponent($1_sclr, $2, $3, 0)')',
`define(ShadeMaterial, `
ShadeComponent($1_rclr, $2, $3, 0);
ShadeComponent($1_gclr, $2, $3, 1);
ShadeComponent($1_bclr, $2, $3, 2);
ShadeShadowComponent($1_rsclr, $2, $3, 0);
ShadeShadowComponent($1_gsclr, $2, $3, 1);
ShadeShadowComponent($1_bsclr, $2, $3, 2)')')
dnl
dnl ShadeComponent(dst, material, op, component)
dnl
dnl Compute the contribution of material number "material" to channel
dnl number "component" (0 = red, 1 = green, 2 = blue) of the
dnl color of the current voxel. The result is stored in dst using
dnl operator "op" ("=" or "+="). This macro uses non-shadow lighting only.
dnl
define(ShadeComponent, `
$1 $3 ShadeLookup($2, $4) * MaterialWeight($2)')
dnl
dnl ShadeLookup(material, component)
dnl
dnl Compute the contribution of material number "material" to channel
dnl number "component" (0 = red, 1 = green, 2 = blue) of the current
dnl voxel (which determines the contents of shade_index). Use the
dnl value in the shading lookup table (which does not contain the
dnl contribution of lights that may produce shadows). The result is
dnl returned.
dnl
define(ShadeLookup, `
shade_table[shade_index + ColorChannels*$1 + $2]')
dnl
dnl ShadeShadowComponent(dst, material, op, component)
dnl
dnl Compute the contribution of material number "material" to channel
dnl number "component" (0 = red, 1 = green, 2 = blue) of the
dnl color of the current voxel. The result is stored in dst using
dnl operator "op" ("=" or "+="). This macro uses shadow lighting only.
dnl
ifdef(`ShadowBuffer',
`define(ShadeShadowComponent, `
$1 $3 ShadowLookup($2, $4) * MaterialWeight($2)')',
`define(ShadeShadowComponent, `')')
dnl
dnl ShadowLookup(material, component)
dnl
dnl Compute the contribution of material number "material" to channel
dnl number "component" (0 = red, 1 = green, 2 = blue) of the current
dnl voxel (which determines the contents of shade_index). Use the
dnl value in the shadow lookup table (which contains only the
dnl contribution of lights that may produce shadows). The result is
dnl returned.
dnl
define(ShadowLookup, `
shadow_table[shade_index + ColorChannels*$1 + $2]')
dnl
dnl MaterialWeight(material)
dnl
dnl Return the weight associated with the specified material number
dnl for the current voxel.
dnl
ifelse(
NumMaterials, 1,
`define(MaterialWeight, `(float)1.0')',
NumMaterials, `N',
`define(MaterialWeight, `
ifelse($1, 0,
`((num_materials > 1) ? weight_table[weight_index] : (float)1.0)',
`weight_table[weight_index + $1]')')',
`define(MaterialWeight, `weight_table[weight_index + $1]')')
dnl
dnl AttenuateColor(scan)
dnl
dnl Scale the color for the current voxel in scanline scan ("top" or "bot")
dnl by the current shading factor (the voxel's opacity multiplied by
dnl the depth cueing factor). This macro uses non-shadow lighting only.
dnl
ifelse(ColorChannels, 1,
`define(AttenuateColor, `
$1_clr *= shade_factor')',
`define(AttenuateColor, `
$1_rclr *= shade_factor;
$1_gclr *= shade_factor;
$1_bclr *= shade_factor')')
dnl
dnl AttenuateShadowColor(scan)
dnl
dnl Scale the color for the current voxel in scanline scan ("top" or "bot")
dnl by the current shading factor (the voxel's opacity multiplied by
dnl the depth cueing factor). This macro uses shadow lighting only.
dnl
ifdef(`ShadowBuffer',
`ifelse(ColorChannels, 1,
`define(AttenuateShadowColor, `
$1_sclr *= shade_factor')',
`define(AttenuateShadowColor, `
$1_rsclr *= shade_factor;
$1_gsclr *= shade_factor;
$1_bsclr *= shade_factor')')',
`define(AttenuateShadowColor, `')')
dnl
dnl ClearAccum()
dnl
dnl Clear the voxel opacity/color accumulator.
dnl
define(ClearAccum, `
acc_opc = 0;
ClearColorAccum()')
dnl
dnl Accum(scan, wgt, op)
dnl
dnl Accumulate opacity and color for scan (either "top" or "bot")
dnl weighted by one of the four weights ("TL", "BL", "TR" or "BR") using
dnl operation op ("+=" or "=").
dnl
define(Accum, `
acc_opc $3 $1_opc * wgt$2;
AccumColor($1, $2, $3);
Trace($1, $2)')
dnl
dnl Composite()
dnl
dnl Composite the current resampled voxel.
dnl
define(Composite, `
COUNT_RESAMPLE;
if (acc_opc > min_opacity) {
COUNT_COMPOSITE;
iopc = ipixel->opcflt;
# ifndef SKIP_ERT
ASSERT(iopc < max_opacity);
# endif
iopc_inv = (float)1. - iopc;
CompositeColor();
iopc += acc_opc * iopc_inv;
ipixel->opcflt = iopc;
PrintTrace();
# ifndef SKIP_ERT
if (iopc >= max_opacity) {
ASSERT(ipixel->lnk == 0);
ipixel->lnk = 1;
}
# endif
}')
dnl
dnl NextIntPixel(c)
dnl
dnl Increment intermediate image pointer by c pixels.
dnl
ifdef(`ShadowBuffer',
`define(NextIntPixel, `ipixel += $1; shadow_pixel += $1')',
`define(NextIntPixel, `ipixel += $1')')
dnl
dnl Macros that depend on the number of color channels:
dnl IntPixelType type of an intermediate image pixel
dnl (GrayIntPixel or RGBIntPixel)
dnl ClearColorAccum clear the pixel color accumulator
dnl AccumColor(scan, wgt, op)
dnl accumulate color for scan (either "top"
dnl or "bot") weighted by one of the four
dnl weights ("TL", "BL", "TR" or "BR") using
dnl operation op ("+=" or "=")
dnl CompositeColor composite color for current resampled voxel
dnl shadow buffer (0 color channels)
ifelse(ColorChannels, 0, `
define(IntPixelType, `GrayIntPixel')
define(ClearColorAccum, `')
define(AccumColor, `')
define(CompositeColor, `')')
dnl grayscale image (1 color channel)
ifelse(ColorChannels, 1, `
#define GRAYSCALE
define(IntPixelType, `GrayIntPixel')
define(ClearColorAccum, `acc_clr = 0')
ifdef(`ShadowBuffer',
`define(AccumColor, `acc_clr $3 ($1_clr + $1_sclr *
((float)1.0 - shadow_pixel->opcflt)) * wgt$2')',
`define(AccumColor, `acc_clr $3 $1_clr * wgt$2')')
define(CompositeColor, `ipixel->clrflt += acc_clr * iopc_inv')')
dnl RGB image (3 color channels)
ifelse(ColorChannels, 3, `
#define RGB
define(IntPixelType, `RGBIntPixel')
define(ClearColorAccum, `acc_rclr = acc_gclr = acc_bclr = 0')
ifdef(`ShadowBuffer',
`define(AccumColor, `
acc_rclr $3 ($1_rclr + $1_rsclr *
((float)1.0 - shadow_pixel->opcflt)) * wgt$2;
acc_gclr $3 ($1_gclr + $1_gsclr *
((float)1.0 - shadow_pixel->opcflt)) * wgt$2;
acc_bclr $3 ($1_bclr + $1_bsclr *
((float)1.0 - shadow_pixel->opcflt)) * wgt$2')',
`define(AccumColor, `
acc_rclr $3 $1_rclr * wgt$2;
acc_gclr $3 $1_gclr * wgt$2;
acc_bclr $3 $1_bclr * wgt$2')')
define(CompositeColor, `
ipixel->rclrflt += acc_rclr * iopc_inv;
ipixel->gclrflt += acc_gclr * iopc_inv;
ipixel->bclrflt += acc_bclr * iopc_inv')')
dnl
dnl Macros that depend on the type of volume data structure:
dnl VolumeArgs list of function arguments for volume data
dnl VolumeArgsDecl declaration of VolumeArgs
dnl NextNonZeroTopVoxel(c) increment top voxel ptr. by c nonzero voxels
dnl NextZeroTopVoxel(c) increment top voxel ptr. by c zero voxels
dnl NextNonZeroBotVoxel(c) increment bot voxel ptr. by c nonzero voxels
dnl NextZeroBotVoxel(c) increment bot voxel ptr. by c zero voxels
dnl ClassifyVox(opc, vox) classify a voxel and store the result in opc
dnl
dnl rlevolume (run-length encoded volume)
ifelse(VolumeType, `rlevolume', `
#define RLEVOLUME
define(VolumeArgs, `run_lengths, voxel_data')
define(VolumeArgsDecl, `
unsigned char *run_lengths; /* run lengths for slice */
void *voxel_data; /* voxel data for slice */')
define(NextNonZeroTopVoxel, `topRLEdata += $1 * voxel_istride')
define(NextZeroTopVoxel, `')
define(NextNonZeroBotVoxel, `botRLEdata += $1 * voxel_istride')
define(NextZeroBotVoxel, `')
define(ClassifyVox,
`$1 = opac_correct[ByteField($2, voxel_istride-1)]')')
dnl rawvolume (3D volume array, optionally with a min-max octree)
ifelse(VolumeType, `rawvolume', `
#define RAWVOLUME
define(VolumeArgs, `voxel_data, voxel_istride, voxel_jstride')
define(VolumeArgsDecl, `
void *voxel_data; /* voxel data for slice */
int voxel_istride; /* strides for voxel data */
int voxel_jstride;')
define(NextNonZeroTopVoxel, `topRLEdata += $1 * voxel_istride')
define(NextZeroTopVoxel, `topRLEdata += $1 * voxel_istride')
define(NextNonZeroBotVoxel, `botRLEdata += $1 * voxel_istride')
define(NextZeroBotVoxel, `botRLEdata += $1 * voxel_istride')
define(ClassifyVox, `
opac_param = VoxelField($2, param0_offset, param0_size);
opacity = param0_table[opac_param];
if (param1_size != 0) {
opac_param = VoxelField($2, param1_offset, param1_size);
opacity *= param1_table[opac_param];
if (param2_size != 0) {
opac_param = VoxelField($2, param2_offset, param2_size);
opacity *= param2_table[opac_param];
}
}
if (opacity > min_opacity) {
opacity_int = opacity*255.;
$1 = opac_correct[opacity_int];
} else {
$1 = (float)0.;
}')')
dnl rlevolume + IndexVolume (experimental data structure that contains
dnl a mapping from voxel coordinates to location of voxel in rlevolume)
ifdef(`IndexVolume', `
#define INDEX_VOLUME
define(`VolumeArgs', `run_lengths, voxel_data, voxel_index')
define(`VolumeArgsDecl', `
unsigned char *run_lengths; /* run lengths for slice */
void *voxel_data; /* voxel data for slice */
VoxelLocation *voxel_index; /* index for ERT */')',
`
#undef INDEX_VOLUME')
dnl
dnl Macros for rendering shadows:
dnl ShadowArgs list of function arguments for shadow buffer
dnl ShadowArgsDecl declaration of ShadowArgs
dnl
ifdef(`ShadowBuffer', `
define(ShadowArgs, `, shadow_buffer')
define(ShadowArgsDecl, `GrayIntPixel *shadow_buffer;')',`
define(ShadowArgs, `')
define(ShadowArgsDecl, `')')
dnl
dnl Macros for pixel tracing (a printout of all of the voxels and
dnl filter weights that contribute to one intermediate image pixel).
dnl
dnl
dnl NewPixel()
dnl
dnl Prepare to process a new pixel by clearing tracing buffers.
dnl
define(NewPixel, `
#ifdef DEBUG
if (ipixel == trace_pixel_ptr) {
trace_opcTL = 0.; trace_opcBL = 0.; trace_opcTR = 0.; trace_opcBR = 0.;
trace_rsclrTL=0.; trace_rsclrBL=0.; trace_rsclrTR=0.; trace_rsclrBR=0.;
trace_rclrTL= 0.; trace_rclrBL= 0.; trace_rclrTR= 0.; trace_rclrBR= 0.;
trace_gclrTL= 0.; trace_gclrBL= 0.; trace_gclrTR= 0.; trace_gclrBR= 0.;
trace_bclrTL= 0.; trace_bclrBL= 0.; trace_bclrTR= 0.; trace_bclrBR= 0.;
}
#endif
')
dnl
dnl Trace(scan, wgt)
dnl
dnl Store voxel opacity and color from the specified scanline ("top" or "bot")
dnl in the tracing buffer associated with the specified weight ("TR", "BR",
dnl "TL", "BL").
dnl
define(Trace, `
#ifdef DEBUG
if (ipixel == trace_pixel_ptr) {
trace_opc$2 = $1_opc;
ifelse(ColorChannels, 1,
`trace_rclr$2 = $1_clr;',
ColorChannels, 3,
`trace_rclr$2 = $1_rclr;
trace_gclr$2 = $1_gclr;
trace_bclr$2 = $1_bclr;')
ifdef(`ShadowBuffer',
`ifelse(ColorChannels, 1, `trace_rsclr$2 = $1_sclr;')')
}
#endif
')
dnl
dnl PrintTrace()
dnl
dnl Print one line of the trace.
dnl
define(PrintTrace, `
#ifdef DEBUG
if (ipixel == trace_pixel_ptr) {
#ifdef COMPUTE_SHADOW_BUFFER
printf("{%3d} %3d %3d", k, icount-i-count, j);
#else
printf("[%3d] %3d %3d", k, icount-i-count, j);
#endif
printf(" %3.0f %3.0f %3.0f",trace_opcTL*255.,trace_rclrTL,wgtTL*100.);
printf(" %3.0f %3.0f %3.0f",trace_opcBL*255.,trace_rclrBL,wgtBL*100.);
printf(" %3.0f %3.0f %3.0f",trace_opcTR*255.,trace_rclrTR,wgtTR*100.);
printf(" %3.0f %3.0f %3.0f",trace_opcBR*255.,trace_rclrBR,wgtBR*100.);
printf(" %3.0f %3.0f\n", iopc*255.,
ifelse(ColorChannels, 3, `ipixel->rclrflt',
ColorChannels, 1, `ipixel->clrflt',
`0'));
ifdef(`ShadowBuffer', `
printf(" ");
printf(" %3.0f ",trace_rsclrTL);
printf(" %3.0f ",trace_rsclrBL);
printf(" %3.0f ",trace_rsclrTR);
printf(" %3.0f ",trace_rsclrBR);
printf(" %3.0f\n", shadow_pixel->opcflt * 255.);')
ifelse(ColorChannels, 3, `
printf(" ");
printf(" %3.0f ",trace_gclrTL);
printf(" %3.0f ",trace_gclrBL);
printf(" %3.0f ",trace_gclrTR);
printf(" %3.0f ",trace_gclrBR);
printf(" %3.0f\n", ipixel->gclrflt);
printf(" ");
printf(" %3.0f ",trace_bclrTL);
printf(" %3.0f ",trace_bclrBL);
printf(" %3.0f ",trace_bclrTR);
printf(" %3.0f ",trace_bclrBR);
printf(" %3.0f\n", ipixel->bclrflt);')
}
#endif /* DEBUG */
')
/* codes indicating the types of a pair of runs in adjacent scanlines */
#define ALL_ZERO 0 /* both runs are runs of zeros */
#define TOP_NONZERO 1 /* run for top scanline has nonzero data */
#define BOT_NONZERO 2 /* run for bottom scanline has nonzero data */
#define ALL_NONZERO 3 /* both runs have nonzero data */
/* codes indicating the types for the current left and right voxel pairs */
#define ALL_ZERO__ALL_ZERO ((ALL_ZERO << 2) | ALL_ZERO)
#define ALL_ZERO__TOP_NONZERO ((ALL_ZERO << 2) | TOP_NONZERO)
#define ALL_ZERO__BOT_NONZERO ((ALL_ZERO << 2) | BOT_NONZERO)
#define ALL_ZERO__ALL_NONZERO ((ALL_ZERO << 2) | ALL_NONZERO)
#define TOP_NONZERO__ALL_ZERO ((TOP_NONZERO << 2) | ALL_ZERO)
#define TOP_NONZERO__TOP_NONZERO ((TOP_NONZERO << 2) | TOP_NONZERO)
#define TOP_NONZERO__BOT_NONZERO ((TOP_NONZERO << 2) | BOT_NONZERO)
#define TOP_NONZERO__ALL_NONZERO ((TOP_NONZERO << 2) | ALL_NONZERO)
#define BOT_NONZERO__ALL_ZERO ((BOT_NONZERO << 2) | ALL_ZERO)
#define BOT_NONZERO__TOP_NONZERO ((BOT_NONZERO << 2) | TOP_NONZERO)
#define BOT_NONZERO__BOT_NONZERO ((BOT_NONZERO << 2) | BOT_NONZERO)
#define BOT_NONZERO__ALL_NONZERO ((BOT_NONZERO << 2) | ALL_NONZERO)
#define ALL_NONZERO__ALL_ZERO ((ALL_NONZERO << 2) | ALL_ZERO)
#define ALL_NONZERO__TOP_NONZERO ((ALL_NONZERO << 2) | TOP_NONZERO)
#define ALL_NONZERO__BOT_NONZERO ((ALL_NONZERO << 2) | BOT_NONZERO)
#define ALL_NONZERO__ALL_NONZERO ((ALL_NONZERO << 2) | ALL_NONZERO)
#ifdef SKIP_ERT
#define PIXEL_IS_OPAQUE(ipixel) 0
#else
#define PIXEL_IS_OPAQUE(ipixel) ((ipixel)->lnk != 0)
#endif
#ifdef STATISTICS
extern int vpResampleCount;
extern int vpCompositeCount;
extern int vpERTSkipCount;
extern int vpERTSkipAgainCount;
extern int vpERTUpdateCount;
extern int vpSpecialZeroSkipCount;
extern int vpRunFragmentCount;
#define COUNT_RESAMPLE vpResampleCount++
#define COUNT_COMPOSITE vpCompositeCount++
#define COUNT_ERT_SKIP vpERTSkipCount++
#define COUNT_ERT_SKIP_AGAIN vpERTSkipAgainCount++
#define COUNT_ERT_UPDATE vpERTUpdateCount++
#define COUNT_SPECIAL_ZERO_SKIP vpSpecialZeroSkipCount++
#define COUNT_RUN_FRAGMENT vpRunFragmentCount++
#else
#define COUNT_RESAMPLE
#define COUNT_COMPOSITE
#define COUNT_ERT_SKIP
#define COUNT_ERT_SKIP_AGAIN
#define COUNT_ERT_UPDATE
#define COUNT_SPECIAL_ZERO_SKIP
#define COUNT_RUN_FRAGMENT
#endif /* STATISTICS */
/*
* FuncName
*
* Compositing routine for run-length encoded volume data slices.
* Decode and resample one slice of volume data, and composite
* it into the intermediate image. The resampling filter is a bilirp.
*/
void
FuncName (vpc, icount, jcount, k, slice_depth_cueing_dbl, intimage,
weightTLdbl, weightBLdbl, weightTRdbl, weightBRdbl,
VolumeArgs ShadowArgs)
vpContext *vpc; /* context */
int icount; /* slice size */
int jcount;
int k; /* slice number */
double slice_depth_cueing_dbl; /* depth cueing factor for slice */
IntPixelType *intimage; /* intermediate image pixels */
double weightTLdbl; /* resampling weights */
double weightBLdbl;
double weightTRdbl;
double weightBRdbl;
VolumeArgsDecl
ShadowArgsDecl
{
int i, j; /* voxel index in rotated object space */
IntPixelType *ipixel; /* current intermediate image pixel */
IntPixelType *ipixel2; /* another intermediate image pixel */
int update_interval; /* # of pixels to skip when updating links */
float iopc; /* intermediate pixel opacity (0-1) */
float iopc_inv; /* 1-iopc */
float acc_opc; /* accumulator for resampled voxel opacity */
float top_opc, bot_opc; /* voxel opacity (top and bottom scanlines) */
#ifdef NO_REUSE_VOXEL
#define voxels_loaded 0
#define CLEAR_VOXELS_LOADED
#define SET_VOXELS_LOADED
#else
int voxels_loaded; /* if true, top/bot_opc contain valid
data loaded during the last resample */
#define CLEAR_VOXELS_LOADED voxels_loaded = 0
#define SET_VOXELS_LOADED voxels_loaded = 1
#endif
float wgtTL, wgtBL, /* weights in the range 0..1 which give the */
wgtTR, wgtBR; /* fractional contribution of the */
/* neighboring voxels to the current */
/* intermediate image pixel */
unsigned char *topRLElen; /* length of current run in top scanline */
unsigned char *botRLElen; /* length of current run in bottom scanline */
char *topRLEdata; /* data for current run in top scanline */
char *botRLEdata; /* data for current run in bottom scanline */
int toprun_count; /* number of voxels left in top run */
int botrun_count; /* number of voxels left in bottom run */
int last_run_state; /* run state code for last resample */
int run_state; /* run state code for this resample */
int final_run_state; /* run state code for end of scanline */
float min_opacity; /* low opacity threshold */
float max_opacity; /* high opacity threshold */
float slice_depth_cueing; /* depth cueing factor for slice */
float *opac_correct; /* opacity correction table */
int ert_skip_count; /* number of pixels to skip for ERT */
int intermediate_width; /* width of intermediate image in pixels */
int count; /* voxels left in current run */
float *shade_table; /* shade lookup table */
int norm_offset; /* byte offset to shade table index in voxel */
int shade_index; /* shade index */
float shade_factor; /* attenuation factor for color
(voxel opacity * depth cueing) */
#ifdef MULTIPLE_MATERIALS
float *weight_table; /* weight lookup table */
int wgt_offset; /* byte offset to weight table index */
int weight_index; /* weight index */
int m, num_materials;
float weight1, weight2;
#endif /* MULTIPLE_MATERIALS */
#ifdef GRAYSCALE
float acc_clr; /* accumulator for resampled color */
float top_clr, bot_clr; /* voxel color (top and bottom scanlines) */
#endif /* GRAYSCALE */
#ifdef RGB
float acc_rclr; /* accumulator for resampled color */
float acc_gclr;
float acc_bclr;
float top_rclr; /* voxel color (top and bottom scanlines) */
float bot_rclr;
float top_gclr;
float bot_gclr;
float top_bclr;
float bot_bclr;
#endif
#ifdef RLEVOLUME
int voxel_istride; /* size of a voxel in bytes */
#endif
#ifdef RAWVOLUME
int use_octree; /* if true then use the min-max octree */
MMOctreeLevel level_stack[VP_MAX_OCTREE_LEVELS];
/* stack for traversal of min-max octree */
int scans_left; /* scanlines until next octree traversal */
int best_view_axis; /* viewing axis */
unsigned char runlen_buf1[VP_MAX_VOLUME_DIM]; /* buffers for run lengths */
unsigned char runlen_buf2[VP_MAX_VOLUME_DIM];
unsigned char *top_len_base;/* first run length for top scanline */
unsigned char *bot_len_base;/* first run length for bottom scanline */
int opac_param; /* parameter to opacity transfer function */
float opacity; /* voxel opacity */
int opacity_int; /* voxel opacity truncated to an integer */
int param0_offset; /* offset to first parameter in voxel */
int param0_size; /* size of first parameter in bytes */
float *param0_table; /* lookup table for first parameter */
int param1_offset; /* offset to second parameter in voxel */
int param1_size; /* size of second parameter in bytes */
float *param1_table; /* lookup table for second parameter */
int param2_offset; /* offset to third parameter in voxel */
int param2_size; /* size of third parameter in bytes */
float *param2_table; /* lookup table for third parameter */
#endif /* RAWVOLUME */
#ifdef INDEX_VOLUME
unsigned char *scanline_topRLElen; /* first topRLElen in scanline */
unsigned char *scanline_botRLElen; /* first botRLElen in scanline */
char *scanline_topRLEdata; /* first topRLEdata in scanline */
char *scanline_botRLEdata; /* first botRLEdata in scanline */
VoxelLocation *top_voxel_index; /* voxel indexes for top scanline */
VoxelLocation *bot_voxel_index; /* voxel indexes for bot scanline */
VoxelLocation *vindex;
int next_i; /* i coordinate of voxel to skip to */
int next_scan; /* true if skipped to next scanline */
#endif /* INDEX_VOLUME */
#ifdef CALLBACK
/* shading callback function */
#ifdef GRAYSCALE
void (*shade_func) ANSI_ARGS((void *, float *, void *));
#endif
#ifdef RGB
void (*shade_func) ANSI_ARGS((void *, float *, float *, float *, void *));
#endif
void *client_data; /* client data handle */
#endif /* CALLBACK */
#ifdef USE_SHADOW_BUFFER
float *shadow_table; /* color lookup table for shadows */
int shadow_width; /* width of shadow buffer */
GrayIntPixel *shadow_pixel; /* current shadow buffer pixel */
#ifdef GRAYSCALE
float top_sclr, bot_sclr; /* shadow color (top and bottom scanlines) */
#endif /* GRAYSCALE */
#ifdef RGB
float top_rsclr; /* shadow color (top and bottom scanlines) */
float bot_rsclr;
float top_gsclr;
float bot_gsclr;
float top_bsclr;
float bot_bsclr;
#endif
#endif /* SHADOW_BUFFER */
#ifdef DEBUG
float trace_opcTL, trace_opcBL, trace_opcTR, trace_opcBR;
float trace_rsclrTL, trace_rsclrBL, trace_rsclrTR, trace_rsclrBR;
float trace_rclrTL, trace_rclrBL, trace_rclrTR, trace_rclrBR;
float trace_gclrTL, trace_gclrBL, trace_gclrTR, trace_gclrBR;
float trace_bclrTL, trace_bclrBL, trace_bclrTR, trace_bclrBR;
IntPixelType *trace_pixel_ptr;
#ifdef COMPUTE_SHADOW_BUFFER
int slice_u_int, shadow_slice_u_int;
int slice_v_int, shadow_slice_v_int;
#endif
#endif /* DEBUG */
DECLARE_HIRES_TIME(t0);
DECLARE_HIRES_TIME(t1);
/*******************************************************************
* Copy parameters from the rendering context into local variables.
*******************************************************************/
GET_HIRES_TIME(vpc, t0);
wgtTL = weightTLdbl;
wgtBL = weightBLdbl;
wgtTR = weightTRdbl;
wgtBR = weightBRdbl;
slice_depth_cueing = slice_depth_cueing_dbl;
min_opacity = vpc->min_opacity;
max_opacity = vpc->max_opacity;
#ifdef USE_SHADOW_BUFFER
opac_correct = vpc->shadow_opac_correct;
#else
opac_correct = vpc->affine_opac_correct;
#endif
#ifdef COMPUTE_SHADOW_BUFFER
intermediate_width = vpc->shadow_width;
#else
intermediate_width = vpc->intermediate_width;
#endif
#ifdef USE_SHADOW_BUFFER
shadow_table = vpc->shadow_color_table;
shadow_width = vpc->shadow_width;
shadow_pixel = shadow_buffer;
#endif
ipixel = intimage;
shade_table = vpc->shade_color_table;
norm_offset = vpc->field_offset[vpc->color_field];
#ifdef MULTIPLE_MATERIALS
weight_table = vpc->shade_weight_table;
wgt_offset = vpc->field_offset[vpc->weight_field];
num_materials = vpc->num_materials;
#endif /* MULTIPLE_MATERIALS */
#ifdef RLEVOLUME
topRLEdata = voxel_data;
botRLEdata = voxel_data;
topRLElen = run_lengths;
botRLElen = run_lengths;
voxel_istride = vpc->rle_bytes_per_voxel;
#endif /* RLEVOLUME */
#ifdef RAWVOLUME
ASSERT(vpc->num_clsfy_params > 0);
ASSERT(vpc->num_clsfy_params < 3);
param0_offset = vpc->field_offset[vpc->param_field[0]];
param0_size = vpc->field_size[vpc->param_field[0]];
param0_table = vpc->clsfy_table[0];
if (vpc->num_clsfy_params > 1) {
param1_offset = vpc->field_offset[vpc->param_field[1]];
param1_size = vpc->field_size[vpc->param_field[1]];
param1_table = vpc->clsfy_table[1];
} else {
param1_offset = 0;
param1_size = 0;
param1_table = NULL;
}
if (vpc->num_clsfy_params > 2) {
param2_offset = vpc->field_offset[vpc->param_field[2]];
param2_size = vpc->field_size[vpc->param_field[2]];
param2_table = vpc->clsfy_table[2];
} else {
param2_offset = 0;
param2_size = 0;
param2_table = NULL;
}
if (vpc->mm_octree == NULL) {
use_octree = 0;
} else {
use_octree = 1;
best_view_axis = vpc->best_view_axis;
VPInitOctreeLevelStack(vpc, level_stack, best_view_axis, k);
scans_left = 0;
bot_len_base = runlen_buf1;
}
#endif /* RAWVOLUME */
#ifdef CALLBACK
shade_func = vpc->shade_func;
client_data = vpc->client_data;
ASSERT(shade_func != NULL);
#endif
#ifdef DEBUG
trace_pixel_ptr = 0;
if (vpc->trace_u >= 0 && vpc->trace_v >= 0) {
#ifdef GRAYSCALE
trace_pixel_ptr = &vpc->int_image.gray_intim[vpc->trace_u +
vpc->trace_v*vpc->intermediate_width];
#endif
#ifdef RGB
trace_pixel_ptr = &vpc->int_image.rgb_intim[vpc->trace_u +
vpc->trace_v*vpc->intermediate_width];
#endif
#ifdef COMPUTE_SHADOW_BUFFER
slice_u_int = (int)ceil(vpc->shear_i * vpc->trace_shadow_k +
vpc->trans_i) - 1;
shadow_slice_u_int = (int)ceil(vpc->shadow_shear_i *
vpc->trace_shadow_k + vpc->shadow_trans_i) - 1;
slice_v_int = (int)ceil(vpc->shear_j * vpc->trace_shadow_k
+ vpc->trans_j) - 1;
shadow_slice_v_int = (int)ceil(vpc->shadow_shear_j *
vpc->trace_shadow_k + vpc->shadow_trans_j) - 1;
trace_pixel_ptr = &vpc->shadow_buffer[vpc->trace_u +
shadow_slice_u_int - slice_u_int +
(vpc->trace_v + shadow_slice_v_int -
slice_v_int)*vpc->shadow_width];
#endif
}
#endif /* DEBUG */
/*******************************************************************
* Loop over voxel scanlines.
*******************************************************************/
for (j = 0; j <= jcount; j++) {
/***************************************************************
* Initialize counters and flags.
***************************************************************/
i = icount;
CLEAR_VOXELS_LOADED;
last_run_state = ALL_ZERO;
#ifdef RAWVOLUME
botRLEdata = (char *)voxel_data + j*voxel_jstride;
topRLEdata = botRLEdata - voxel_jstride;
if (!use_octree) {
if (j == 0) {
run_state = BOT_NONZERO;
toprun_count = icount+2;
botrun_count = icount;
} else if (j == jcount) {
run_state = TOP_NONZERO;
toprun_count = icount;
botrun_count = icount+2;
} else {
run_state = ALL_NONZERO;
toprun_count = icount;
botrun_count = icount;
}
} else
#endif /* RAWVOLUME */
if (j == 0) {
run_state = BOT_NONZERO;
toprun_count = icount+2;
botrun_count = 0;
} else if (j == jcount) {
run_state = TOP_NONZERO;
toprun_count = 0;
botrun_count = icount+2;
} else {
run_state = ALL_NONZERO;
toprun_count = 0;
botrun_count = 0;
}
#ifdef INDEX_VOLUME
scanline_topRLElen = topRLElen;
scanline_botRLElen = botRLElen;
scanline_topRLEdata = topRLEdata;
scanline_botRLEdata = botRLEdata;
if (j == 0) {
top_voxel_index = voxel_index;
bot_voxel_index = voxel_index;
} else {
top_voxel_index = bot_voxel_index;
bot_voxel_index += icount;
}
#endif /* INDEX_VOLUME */
/***************************************************************
* If the volume is not run-length encoded, use the min-max
* to find run lengths for the current voxel scanline.
***************************************************************/
#ifdef RAWVOLUME
if (use_octree) {
top_len_base = bot_len_base;
if (scans_left == 0) {
if (bot_len_base == runlen_buf1)
bot_len_base = runlen_buf2;
else
bot_len_base = runlen_buf1;
GET_HIRES_TIME(vpc, t1);
STORE_HIRES_TIME(vpc, VPTIMER_TRAVERSE_RUNS, t0, t1);
COPY_HIRES_TIME(t0, t1);
scans_left = VPComputeScanRuns(vpc, level_stack, bot_len_base,
best_view_axis, j, icount);
GET_HIRES_TIME(vpc, t1);
STORE_HIRES_TIME(vpc, VPTIMER_TRAVERSE_OCTREE, t0, t1);
COPY_HIRES_TIME(t0, t1);
}
#ifdef DEBUG
if (j > 0)
VPCheckRuns(vpc, top_len_base, best_view_axis, k, j-1);
if (j < jcount)
VPCheckRuns(vpc, bot_len_base, best_view_axis, k, j);
#endif
scans_left--;
topRLElen = top_len_base;
botRLElen = bot_len_base;
}
#endif /* RAWVOLUME */
/***************************************************************
* Loop over runs in the voxel scanline.
***************************************************************/
Debug((vpc, VPDEBUG_COMPOSITE, "StartIScan(u=%d,v=%d)\n",
(((int)ipixel - (int)vpc->int_image.gray_intim) /
sizeof(IntPixelType)) % vpc->intermediate_width,
(((int)ipixel - (int)vpc->int_image.gray_intim) /
sizeof(IntPixelType)) / vpc->intermediate_width));
#ifdef UNROLL_RUN_LOOP
while (i > 0) {
#else
while (i >= 0) {
#endif
/***********************************************************
* Skip over any empty runs at beginning of scanline.
***********************************************************/
if (last_run_state == ALL_ZERO) {
#ifndef UNROLL_RUN_LOOP
if (i == 0) {
Debug((vpc, VPDEBUG_COMPOSITE, "ZeroSkip(1)End\n"));
NextIntPixel(1);
final_run_state = ALL_ZERO;
i = -1;
break; /* scanline is done */
}
#endif
/* check if this is the start of a new run */
while (toprun_count == 0) {
toprun_count = *topRLElen++;
run_state ^= 1;
}
while (botrun_count == 0) {
botrun_count = *botRLElen++;
run_state ^= 2;
}
if (run_state == ALL_ZERO) {
COUNT_SPECIAL_ZERO_SKIP;
/* find the union of the two runs of voxels */
count = MIN(toprun_count, botrun_count);
toprun_count -= count;
botrun_count -= count;
NextIntPixel(count);
NextZeroTopVoxel(count);
NextZeroBotVoxel(count);
i -= count;
ASSERT(i >= 0);
Debug((vpc, VPDEBUG_COMPOSITE, "ZeroSkip(%d)\n", count));
continue;
}
}
#ifndef SKIP_ERT
/***********************************************************
* Skip over opaque pixels (early-ray termination).
***********************************************************/
if ((ert_skip_count = ipixel->lnk) != 0) {
GET_HIRES_TIME(vpc, t1);
STORE_HIRES_TIME(vpc, VPTIMER_TRAVERSE_RUNS, t0, t1);
COPY_HIRES_TIME(t0, t1);
COUNT_ERT_SKIP;
#ifndef UNROLL_RUN_LOOP
if (i == 0) {
NextIntPixel(1);
final_run_state = last_run_state;
i = -1;
Debug((vpc, VPDEBUG_COMPOSITE, "ERTSkip(1)End\n"));
break; /* scanline is done */
}
#endif
/* find out how many pixels to skip */
if (ert_skip_count < i &&
(count = ipixel[ert_skip_count].lnk) != 0) {
/* follow pointer chain */
do {
COUNT_ERT_SKIP_AGAIN;
ert_skip_count += count;
} while (ert_skip_count < i &&
(count = ipixel[ert_skip_count].lnk) != 0);
/* update some of the lnk pointers in the run of opaque
pixels; the more links we update the longer it will
take to perform the update, but we will potentially
save time in future slices by not having to follow
long pointer chains */
ipixel2 = ipixel;
update_interval = 1;
count = ert_skip_count - 1;
while (count > 0) {
COUNT_ERT_UPDATE;
ipixel2 += update_interval;
if (count > 255)
ipixel2->lnk = 255;
else
ipixel2->lnk = count;
update_interval *= 2;
count -= update_interval;
}
/* update the current link */
COUNT_ERT_UPDATE;
if (ert_skip_count > 255)
ert_skip_count = 255;
ipixel->lnk = ert_skip_count;
}
/* skip over the opaque pixels */
if (ert_skip_count > i)
ert_skip_count = i;
Debug((vpc, VPDEBUG_COMPOSITE,"ERTSkip(%d)\n",ert_skip_count));
NextIntPixel(ert_skip_count);
CLEAR_VOXELS_LOADED;
#ifdef INDEX_VOLUME
/* compute i coordinate of voxel to skip to */
next_i = icount - i + ert_skip_count;
if (next_i == icount) {
next_i--;
next_scan = 1;
} else {
next_scan = 0;
}
/* skip over voxels in top scanline */
vindex = &top_voxel_index[next_i];
toprun_count = vindex->run_count;
topRLElen = scanline_topRLElen + vindex->len_offset;
if (vindex->data_offset & INDEX_RUN_IS_ZERO) {
run_state &= ~1;
topRLEdata = scanline_topRLEdata +
(vindex->data_offset & ~INDEX_RUN_IS_ZERO);
} else {
run_state |= 1;
topRLEdata = scanline_topRLEdata + vindex->data_offset;
}
/* skip over voxels in bottom scanline */
vindex = &bot_voxel_index[next_i];
botrun_count = vindex->run_count;
botRLElen = scanline_botRLElen + vindex->len_offset;
if (vindex->data_offset & INDEX_RUN_IS_ZERO) {
run_state &= ~2;
botRLEdata = scanline_botRLEdata +
(vindex->data_offset & ~INDEX_RUN_IS_ZERO);
} else {
run_state |= 2;
botRLEdata = scanline_botRLEdata + vindex->data_offset;
}
/* special case to skip over last voxel in scanline */
if (next_scan) {
/* advance to beginning of next top scanline */
while (toprun_count == 0) {
toprun_count = *topRLElen++;
run_state ^= 1;
}
toprun_count--;
if (run_state & 1) {
NextNonZeroTopVoxel(1);
} else {
NextZeroTopVoxel(1);
}
/* advance to beginning of next bottom scanline */
while (botrun_count == 0) {
botrun_count = *botRLElen++;
run_state ^= 2;
}
botrun_count--;
if (run_state & 2) {
NextNonZeroBotVoxel(1);
} else {
NextZeroBotVoxel(1);
}
}
#else /* !INDEX_VOLUME */
/* skip over voxels in top scanline */
count = ert_skip_count;
for (;;) {
if (toprun_count >= count) {
toprun_count -= count;
if (run_state & 1) {
NextNonZeroTopVoxel(count);
} else {
NextZeroTopVoxel(count);
}
break;
} else {
count -= toprun_count;
if (run_state & 1) {
NextNonZeroTopVoxel(toprun_count);
} else {
NextZeroTopVoxel(toprun_count);
}
toprun_count = *topRLElen++;
if (toprun_count == 0)
toprun_count = *topRLElen++;
else
run_state ^= 1;
}
}
/* skip over voxels in bottom scanline */
count = ert_skip_count;
for (;;) {
if (botrun_count >= count) {
botrun_count -= count;
if (run_state & 2) {
NextNonZeroBotVoxel(count);
} else {
NextZeroBotVoxel(count);
}
break;
} else {
count -= botrun_count;
if (run_state & 2) {
NextNonZeroBotVoxel(botrun_count);
} else {
NextZeroBotVoxel(botrun_count);
}
botrun_count = *botRLElen++;
if (botrun_count == 0)
botrun_count = *botRLElen++;
else
run_state ^= 2;
}
}
#endif /* INDEX_VOLUME */
i -= ert_skip_count;
last_run_state = run_state;
if (i == 0) {
#ifdef UNROLL_RUN_LOOP
break;
#else
if (last_run_state == ALL_ZERO) {
NextIntPixel(1);
final_run_state = ALL_ZERO;
i = -1;
Debug((vpc, VPDEBUG_COMPOSITE, "ZeroSkip(1)End\n"));
break; /* scanline is done */
}
if (ipixel->lnk != 0) {
NextIntPixel(1);
final_run_state = last_run_state;
i = -1;
Debug((vpc, VPDEBUG_COMPOSITE, "ERTSkip(1)End\n"));
break; /* scanline is done */
}
#endif /* UNROLL_RUN_LOOP */
}
GET_HIRES_TIME(vpc, t1);
STORE_HIRES_TIME(vpc, VPTIMER_ERT, t0, t1);
COPY_HIRES_TIME(t0, t1);
}
ASSERT(ipixel->opcflt < max_opacity);
#endif /* SKIP_ERT */
/***********************************************************
* Compute the length of the current run.
***********************************************************/
#ifndef UNROLL_RUN_LOOP
if (i == 0) {
final_run_state = last_run_state;
run_state = ALL_ZERO;
i = -1;
count = 1;
Debug((vpc, VPDEBUG_COMPOSITE, "Run(1)End\n"));
} else {
#endif
/* check if this is the start of a new run */
while (toprun_count == 0) {
toprun_count = *topRLElen++;
run_state ^= 1;
}
while (botrun_count == 0) {
botrun_count = *botRLElen++;
run_state ^= 2;
}
/* find the union of the two runs of voxels */
count = MIN(toprun_count, botrun_count);
toprun_count -= count;
botrun_count -= count;
i -= count;
Debug((vpc, VPDEBUG_COMPOSITE, "Run(%d)\n", count));
ASSERT(i >= 0);
#ifndef UNROLL_RUN_LOOP
}
#endif
COUNT_RUN_FRAGMENT;
/***********************************************************
* composite the voxels in the current run.
***********************************************************/
GET_HIRES_TIME(vpc, t1);
STORE_HIRES_TIME(vpc, VPTIMER_TRAVERSE_RUNS, t0, t1);
COPY_HIRES_TIME(t0, t1);
#ifdef SKIP_COMPOSITE
switch (run_state) {
case ALL_ZERO:
NextIntPixel(count);
NextZeroTopVoxel(count);
NextZeroBotVoxel(count);
count = 0;
break;
case TOP_NONZERO:
NextIntPixel(count);
NextNonZeroTopVoxel(count);
NextZeroBotVoxel(count);
count = 0;
break;
case BOT_NONZERO:
NextIntPixel(count);
NextZeroTopVoxel(count);
NextNonZeroBotVoxel(count);
count = 0;
break;
case ALL_NONZERO:
NextIntPixel(count);
NextNonZeroTopVoxel(count);
NextNonZeroBotVoxel(count);
count = 0;
break;
}
#else /* !SKIP_COMPOSITE */
#ifdef UNROLL_RUN_LOOP
/* this run contains pixels, so process them */
switch ((last_run_state << 2) | run_state) {
case ALL_ZERO__ALL_ZERO:
/* no voxels contribute to the pixels in this run */
NextIntPixel(count);
NextZeroTopVoxel(count);
NextZeroBotVoxel(count);
count = 0;
break;
case TOP_NONZERO__ALL_ZERO:
/* only the top-left voxel contributes to the first
pixel of the run, and the rest are zero */
if (!voxels_loaded) {
LoadTopLeft();
}
NewPixel();
Accum(top, TL, =);
Composite();
NextIntPixel(count);
NextZeroTopVoxel(count);
NextZeroBotVoxel(count);
count = 0;
break;
case BOT_NONZERO__ALL_ZERO:
/* only the bottom left voxel contributes to the first
pixel of the run, and the rest are zero */
if (!voxels_loaded) {
LoadBotLeft();
}
NewPixel();
Accum(bot, BL, =);
Composite();
NextIntPixel(count);
NextZeroTopVoxel(count);
NextZeroBotVoxel(count);
count = 0;
break;
case ALL_NONZERO__ALL_ZERO:
/* the top and bottom left voxels contribute to the
first pixel of the run, and the rest are zero */
if (!voxels_loaded) {
LoadTopLeft();
LoadBotLeft();
}
NewPixel();
Accum(top, TL, =);
Accum(bot, BL, +=);
Composite();
NextIntPixel(count);
NextZeroTopVoxel(count);
NextZeroBotVoxel(count);
count = 0;
break;
case ALL_ZERO__TOP_NONZERO:
/* first pixel: only the top-right voxel contributes */
LoadTopRight();
NewPixel();
Accum(top, TR, =);
Composite();
NextIntPixel(1);
NextNonZeroTopVoxel(1);
NextZeroBotVoxel(1);
count--;
SET_VOXELS_LOADED;
/* do the rest of the pixels in this run;
the top-left and top-right voxels contribute */
while (count > 0) {
if (PIXEL_IS_OPAQUE(ipixel))
break;
if (!voxels_loaded) {
LoadTopLeft();
}
NewPixel();
Accum(top, TL, =);
LoadTopRight();
Accum(top, TR, +=);
Composite();
NextIntPixel(1);
NextNonZeroTopVoxel(1);
NextZeroBotVoxel(1);
count--;
SET_VOXELS_LOADED;
}
break;
case TOP_NONZERO__TOP_NONZERO:
/* do the pixels in this run; the top-left and
top-right voxels contribute */
while (count > 0) {
if (PIXEL_IS_OPAQUE(ipixel))
break;
if (!voxels_loaded) {
LoadTopLeft();
}
NewPixel();
Accum(top, TL, =);
LoadTopRight();
Accum(top, TR, +=);
Composite();
NextIntPixel(1);
NextNonZeroTopVoxel(1);
NextZeroBotVoxel(1);
count--;
SET_VOXELS_LOADED;
}
break;
case BOT_NONZERO__TOP_NONZERO:
/* first pixel: bottom-left and top-right voxels
contribute */
if (!voxels_loaded) {
LoadBotLeft();
}
NewPixel();
Accum(bot, BL, =);
LoadTopRight();
Accum(top, TR, +=);
Composite();
NextIntPixel(1);
NextNonZeroTopVoxel(1);
NextZeroBotVoxel(1);
count--;
SET_VOXELS_LOADED;
/* do the rest of the pixels in this run;
the top-left and top-right voxels contribute */
while (count > 0) {
if (PIXEL_IS_OPAQUE(ipixel))
break;
if (!voxels_loaded) {
LoadTopLeft();
}
NewPixel();
Accum(top, TL, =);
LoadTopRight();
Accum(top, TR, +=);
Composite();
NextIntPixel(1);
NextNonZeroTopVoxel(1);
NextZeroBotVoxel(1);
count--;
SET_VOXELS_LOADED;
}
break;
case ALL_NONZERO__TOP_NONZERO:
/* first pixel: top-left, bottom-left and top-right voxels
contribute */
if (!voxels_loaded) {
LoadTopLeft();
LoadBotLeft();
}
NewPixel();
Accum(top, TL, =);
Accum(bot, BL, +=);
LoadTopRight();
Accum(top, TR, +=);
Composite();
NextIntPixel(1);
NextNonZeroTopVoxel(1);
NextZeroBotVoxel(1);
count--;
SET_VOXELS_LOADED;
/* do the rest of the pixels in this run;
the top-left and top-right voxels contribute */
while (count > 0) {
if (PIXEL_IS_OPAQUE(ipixel))
break;
if (!voxels_loaded) {
LoadTopLeft();
}
NewPixel();
Accum(top, TL, =);
LoadTopRight();
Accum(top, TR, +=);
Composite();
NextIntPixel(1);
NextNonZeroTopVoxel(1);
NextZeroBotVoxel(1);
count--;
SET_VOXELS_LOADED;
}
break;
case ALL_ZERO__BOT_NONZERO:
/* first pixel: only the bottom-right voxel contributes */
LoadBotRight();
NewPixel();
Accum(bot, BR, =);
Composite();
NextIntPixel(1);
NextZeroTopVoxel(1);
NextNonZeroBotVoxel(1);
count--;
SET_VOXELS_LOADED;
/* do the rest of the pixels in this run;
bottom-left and bottom-right voxels contribute */
while (count > 0) {
if (PIXEL_IS_OPAQUE(ipixel))
break;
if (!voxels_loaded) {
LoadBotLeft();
}
NewPixel();
Accum(bot, BL, =);
LoadBotRight();
Accum(bot, BR, +=);
Composite();
NextIntPixel(1);
NextZeroTopVoxel(1);
NextNonZeroBotVoxel(1);
count--;
SET_VOXELS_LOADED;
}
break;
case TOP_NONZERO__BOT_NONZERO:
/* first pixel: top-left and bottom-right voxels contribute */
if (!voxels_loaded) {
LoadTopLeft();
}
NewPixel();
Accum(top, TL, =);
LoadBotRight();
Accum(bot, BR, +=);
Composite();
NextIntPixel(1);
NextZeroTopVoxel(1);
NextNonZeroBotVoxel(1);
count--;
SET_VOXELS_LOADED;
/* do the rest of the pixels in this run;
bottom-left and bottom-right voxels contribute */
while (count > 0) {
if (PIXEL_IS_OPAQUE(ipixel))
break;
if (!voxels_loaded) {
LoadBotLeft();
}
NewPixel();
Accum(bot, BL, =);
LoadBotRight();
Accum(bot, BR, +=);
Composite();
NextIntPixel(1);
NextZeroTopVoxel(1);
NextNonZeroBotVoxel(1);
count--;
SET_VOXELS_LOADED;
}
break;
case BOT_NONZERO__BOT_NONZERO:
/* do the pixels in this run; bottom-left and
bottom-right voxels contribute */
while (count > 0) {
if (PIXEL_IS_OPAQUE(ipixel))
break;
if (!voxels_loaded) {
LoadBotLeft();
}
NewPixel();
Accum(bot, BL, =);
LoadBotRight();
Accum(bot, BR, +=);
Composite();
NextIntPixel(1);
NextZeroTopVoxel(1);
NextNonZeroBotVoxel(1);
count--;
SET_VOXELS_LOADED;
}
break;
case ALL_NONZERO__BOT_NONZERO:
/* first pixel: top-left, bottom-left and bottom-right
voxels contribute */
if (!voxels_loaded) {
LoadTopLeft();
LoadBotLeft();
}
NewPixel();
Accum(top, TL, =);
Accum(bot, BL, +=);
LoadBotRight();
Accum(bot, BR, +=);
Composite();
NextIntPixel(1);
NextZeroTopVoxel(1);
NextNonZeroBotVoxel(1);
count--;
SET_VOXELS_LOADED;
/* do the rest of the pixels in this run;
bottom-left and bottom-right voxels contribute */
while (count > 0) {
if (PIXEL_IS_OPAQUE(ipixel))
break;
if (!voxels_loaded) {
LoadBotLeft();
}
NewPixel();
Accum(bot, BL, =);
LoadBotRight();
Accum(bot, BR, +=);
Composite();
NextIntPixel(1);
NextZeroTopVoxel(1);
NextNonZeroBotVoxel(1);
count--;
SET_VOXELS_LOADED;
}
break;
case ALL_ZERO__ALL_NONZERO:
/* first pixel: top-right and bottom-right voxels contribute */
LoadTopRight();
LoadBotRight();
NewPixel();
Accum(top, TR, =);
Accum(bot, BR, +=);
Composite();
NextIntPixel(1);
NextNonZeroTopVoxel(1);
NextNonZeroBotVoxel(1);
count--;
SET_VOXELS_LOADED;
/* do the rest of the pixels in this run;
all four voxels contribute */
while (count > 0) {
if (PIXEL_IS_OPAQUE(ipixel))
break;
if (!voxels_loaded) {
LoadTopLeft();
LoadBotLeft();
}
NewPixel();
Accum(top, TL, =);
Accum(bot, BL, +=);
LoadTopRight();
LoadBotRight();
Accum(top, TR, +=);
Accum(bot, BR, +=);
Composite();
NextIntPixel(1);
NextNonZeroTopVoxel(1);
NextNonZeroBotVoxel(1);
count--;
SET_VOXELS_LOADED;
}
break;
case TOP_NONZERO__ALL_NONZERO:
/* first pixel: top-left, top-right and bottom-right
voxels contribute */
if (!voxels_loaded) {
LoadTopLeft();
}
NewPixel();
Accum(top, TL, =);
LoadTopRight();
LoadBotRight();
Accum(top, TR, +=);
Accum(bot, BR, +=);
Composite();
NextIntPixel(1);
NextNonZeroTopVoxel(1);
NextNonZeroBotVoxel(1);
count--;
SET_VOXELS_LOADED;
/* do the rest of the pixels in this run;
all four voxels contribute */
while (count > 0) {
if (PIXEL_IS_OPAQUE(ipixel))
break;
if (!voxels_loaded) {
LoadTopLeft();
LoadBotLeft();
}
NewPixel();
Accum(top, TL, =);
Accum(bot, BL, +=);
LoadTopRight();
LoadBotRight();
Accum(top, TR, +=);
Accum(bot, BR, +=);
Composite();
NextIntPixel(1);
NextNonZeroTopVoxel(1);
NextNonZeroBotVoxel(1);
count--;
SET_VOXELS_LOADED;
}
break;
case BOT_NONZERO__ALL_NONZERO:
/* first pixel: bottom-left, top-right and bottom-right
voxels contribute */
if (!voxels_loaded) {
LoadBotLeft();
}
NewPixel();
Accum(bot, BL, =);
LoadTopRight();
LoadBotRight();
Accum(top, TR, +=);
Accum(bot, BR, +=);
Composite();
NextIntPixel(1);
NextNonZeroTopVoxel(1);
NextNonZeroBotVoxel(1);
count--;
SET_VOXELS_LOADED;
/* do the rest of the pixels in this run;
all four voxels contribute */
while (count > 0) {
if (PIXEL_IS_OPAQUE(ipixel))
break;
if (!voxels_loaded) {
LoadTopLeft();
LoadBotLeft();
}
NewPixel();
Accum(top, TL, =);
Accum(bot, BL, +=);
LoadTopRight();
LoadBotRight();
Accum(top, TR, +=);
Accum(bot, BR, +=);
Composite();
NextIntPixel(1);
NextNonZeroTopVoxel(1);
NextNonZeroBotVoxel(1);
count--;
SET_VOXELS_LOADED;
}
break;
case ALL_NONZERO__ALL_NONZERO:
/* do the pixels in this run; all four voxels contribute */
while (count > 0) {
if (PIXEL_IS_OPAQUE(ipixel))
break;
if (!voxels_loaded) {
LoadTopLeft();
LoadBotLeft();
}
NewPixel();
Accum(top, TL, =);
Accum(bot, BL, +=);
LoadTopRight();
LoadBotRight();
Accum(top, TR, +=);
Accum(bot, BR, +=);
Composite();
NextIntPixel(1);
NextNonZeroTopVoxel(1);
NextNonZeroBotVoxel(1);
count--;
SET_VOXELS_LOADED;
}
break;
default:
VPBug("illegal value for run states in compositing loop");
}
#else /* UNROLL_RUN_LOOP */
/* this run contains pixels, so process them */
while (count > 0) {
if (last_run_state == ALL_ZERO && run_state == ALL_ZERO) {
NextIntPixel(count);
if (i != -1) {
NextZeroTopVoxel(count);
NextZeroBotVoxel(count);
}
count = 0;
break;
}
if (ipixel->lnk != 0)
break;
NewPixel();
ClearAccum();
if (last_run_state & TOP_NONZERO) {
if (!voxels_loaded) {
LoadTopLeft();
}
Accum(top, TL, +=);
}
if (last_run_state & BOT_NONZERO) {
if (!voxels_loaded) {
LoadBotLeft();
}
Accum(bot, BL, +=);
}
if (run_state & TOP_NONZERO) {
LoadTopRight();
Accum(top, TR, +=);
NextNonZeroTopVoxel(1);
} else {
if (i != -1) {
NextZeroTopVoxel(1);
}
}
if (run_state & BOT_NONZERO) {
LoadBotRight();
Accum(bot, BR, +=);
NextNonZeroBotVoxel(1);
} else {
if (i != -1) {
NextZeroBotVoxel(1);
}
}
Composite();
NextIntPixel(1);
count--;
SET_VOXELS_LOADED;
last_run_state = run_state;
}
#endif /* UNROLL_RUN_LOOP */
GET_HIRES_TIME(vpc, t1);
STORE_HIRES_TIME(vpc, VPTIMER_PROCESS_VOXELS, t0, t1);
COPY_HIRES_TIME(t0, t1);
if (count > 0) {
Debug((vpc, VPDEBUG_COMPOSITE, "Backup(%d)\n", count));
toprun_count += count;
botrun_count += count;
i += count;
}
#endif /* SKIP_COMPOSITE */
/***********************************************************
* Go on to next voxel run.
***********************************************************/
last_run_state = run_state;
} /* while (i > 0) */
/***************************************************************
* Finish processing voxel scanline and go on to next one.
***************************************************************/
#ifdef UNROLL_RUN_LOOP
ASSERT(i == 0);
#else
ASSERT(i == -1);
#endif
#ifndef SKIP_COMPOSITE
#ifdef UNROLL_RUN_LOOP
/* do the last pixel (to the right of the last voxel) */
if (last_run_state != ALL_ZERO && !PIXEL_IS_OPAQUE(ipixel)) {
/* last voxels are nonzero and the pixel is not opaque yet
so there is work to be done */
Debug((vpc, VPDEBUG_COMPOSITE, "Run(1)End\n"));
switch (last_run_state) {
case TOP_NONZERO:
/* only the top-left voxel contributes */
if (!voxels_loaded) {
LoadTopLeft();
}
NewPixel();
Accum(top, TL, =);
Composite();
break;
case BOT_NONZERO:
/* only the bottom left voxel contributes */
if (!voxels_loaded) {
LoadBotLeft();
}
NewPixel();
Accum(bot, BL, =);
Composite();
break;
case ALL_NONZERO:
/* the top and bottom left voxels contribute */
if (!voxels_loaded) {
LoadTopLeft();
LoadBotLeft();
}
NewPixel();
Accum(top, TL, =);
Accum(bot, BL, +=);
Composite();
break;
default:
VPBug("illegal value for run state at end of scanline");
}
} else if (last_run_state == ALL_ZERO) {
Debug((vpc, VPDEBUG_COMPOSITE, "ZeroSkip(1)End\n"));
} else {
Debug((vpc, VPDEBUG_COMPOSITE, "ERTSkip(1)End\n"));
}
#endif /* UNROLL_RUN_LOOP */
#endif /* SKIP_COMPOSITE */
#ifndef UNROLL_RUN_LOOP
run_state = final_run_state;
#endif
/* skip over any zero-length runs remaining in this scanline */
if (j != 0 && ((run_state & 1) == 0)) {
toprun_count = *topRLElen++;
ASSERT(toprun_count == 0);
}
if (j != jcount && ((run_state & 2) == 0)) {
botrun_count = *botRLElen++;
ASSERT(botrun_count == 0);
}
/* go to next intermediate image scanline */
#ifdef UNROLL_RUN_LOOP
ipixel += intermediate_width - icount;
#ifdef USE_SHADOW_BUFFER
shadow_pixel += shadow_width - icount;
#endif
#else /* UNROLL_RUN_LOOP */
ipixel += intermediate_width - (icount+1);
#ifdef USE_SHADOW_BUFFER
shadow_pixel += shadow_width - (icount+1);
#endif
#endif /* UNROLL_RUN_LOOP */
Debug((vpc, VPDEBUG_COMPOSITE, "ScanDone\n"));
} /* for j */
/***************************************************************
* Finish processing the voxel slice.
***************************************************************/
GET_HIRES_TIME(vpc, t1);
STORE_HIRES_TIME(vpc, VPTIMER_TRAVERSE_RUNS, t0, t1);
Debug((vpc, VPDEBUG_COMPOSITE, "SliceDone\n"));
}
|