Skip to content

AFNI/NIfTI Server

Sections
Personal tools
You are here: Home » AFNI » Documentation

Doxygen Source Code Documentation


Main Page   Alphabetical List   Data Structures   File List   Data Fields   Globals   Search  

vp_compAR3NS.c

Go to the documentation of this file.
00001 /*
00002  * DO NOT EDIT THIS FILE! It was created automatically by m4.
00003  */
00004 
00005 /*
00006  * Copyright (c) 1994 The Board of Trustees of The Leland Stanford
00007  * Junior University.  All rights reserved.
00008  * 
00009  * Permission to use, copy, modify and distribute this software and its
00010  * documentation for any purpose is hereby granted without fee, provided
00011  * that the above copyright notice and this permission notice appear in
00012  * all copies of this software and that you do not sell the software.
00013  * Commercial licensing is available by contacting the author.
00014  * 
00015  * THE SOFTWARE IS PROVIDED "AS IS" AND WITHOUT WARRANTY OF ANY KIND,
00016  * EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY
00017  * WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.
00018  * 
00019  * Author:
00020  *    Phil Lacroute
00021  *    Computer Systems Laboratory
00022  *    Electrical Engineering Dept.
00023  *    Stanford University
00024  */
00025 /*
00026  * vp_compA.m4
00027  *
00028  * Compositing routine for affine viewing transformations.
00029  *
00030  * Copyright (c) 1994 The Board of Trustees of The Leland Stanford
00031  * Junior University.  All rights reserved.
00032  *
00033  * Permission to use, copy, modify and distribute this software and its
00034  * documentation for any purpose is hereby granted without fee, provided
00035  * that the above copyright notice and this permission notice appear in
00036  * all copies of this software and that you do not sell the software.
00037  * Commercial licensing is available by contacting the author.
00038  * 
00039  * THE SOFTWARE IS PROVIDED "AS IS" AND WITHOUT WARRANTY OF ANY KIND,
00040  * EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY
00041  * WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.
00042  *
00043  * Author:
00044  *    Phil Lacroute
00045  *    Computer Systems Laboratory
00046  *    Electrical Engineering Dept.
00047  *    Stanford University
00048  */
00049 
00050 /*
00051  * $Date: 2001/12/17 16:16:22 $
00052  * $Revision: 1.1 $
00053  */
00054 
00055 #include "vp_global.h"
00056 
00057 
00058 
00059     
00060     
00061     
00062     
00063     
00064 
00065     
00066     
00067     
00068 #define USE_SHADOW_BUFFER
00069             
00070     
00071     
00072 
00073 
00074 #undef UNROLL_RUN_LOOP
00075 
00076 
00077 
00078 
00079 
00080 
00081 
00082 
00083 
00084 
00085 
00086 
00087 
00088 
00089 
00090 
00091 
00092 
00093 
00094 
00095 #define MULTIPLE_MATERIALS
00096 
00097 
00098 
00099 
00100 
00101 
00102 
00103 
00104 
00105 
00106 
00107 
00108 
00109 
00110 
00111 
00112 
00113 
00114 
00115 
00116 
00117 
00118 
00119 
00120 
00121 
00122 
00123 
00124 
00125 
00126 
00127 #define RGB
00128     
00129     
00130     
00131     
00132 
00133 
00134 
00135 
00136 
00137 #define RAWVOLUME
00138         
00139         
00140         
00141         
00142         
00143         
00144         
00145 
00146 
00147 #undef INDEX_VOLUME
00148 
00149 
00150     
00151     
00152 
00153 
00154 
00155 
00156 
00157 
00158 
00159 
00160 /* codes indicating the types of a pair of runs in adjacent scanlines */
00161 #define ALL_ZERO        0       /* both runs are runs of zeros */
00162 #define TOP_NONZERO     1       /* run for top scanline has nonzero data */
00163 #define BOT_NONZERO     2       /* run for bottom scanline has nonzero data */
00164 #define ALL_NONZERO     3       /* both runs have nonzero data */
00165 
00166 /* codes indicating the types for the current left and right voxel pairs */
00167 #define ALL_ZERO__ALL_ZERO              ((ALL_ZERO << 2) | ALL_ZERO)
00168 #define ALL_ZERO__TOP_NONZERO           ((ALL_ZERO << 2) | TOP_NONZERO)
00169 #define ALL_ZERO__BOT_NONZERO           ((ALL_ZERO << 2) | BOT_NONZERO)
00170 #define ALL_ZERO__ALL_NONZERO           ((ALL_ZERO << 2) | ALL_NONZERO)
00171 #define TOP_NONZERO__ALL_ZERO           ((TOP_NONZERO << 2) | ALL_ZERO)
00172 #define TOP_NONZERO__TOP_NONZERO        ((TOP_NONZERO << 2) | TOP_NONZERO)
00173 #define TOP_NONZERO__BOT_NONZERO        ((TOP_NONZERO << 2) | BOT_NONZERO)
00174 #define TOP_NONZERO__ALL_NONZERO        ((TOP_NONZERO << 2) | ALL_NONZERO)
00175 #define BOT_NONZERO__ALL_ZERO           ((BOT_NONZERO << 2) | ALL_ZERO)
00176 #define BOT_NONZERO__TOP_NONZERO        ((BOT_NONZERO << 2) | TOP_NONZERO)
00177 #define BOT_NONZERO__BOT_NONZERO        ((BOT_NONZERO << 2) | BOT_NONZERO)
00178 #define BOT_NONZERO__ALL_NONZERO        ((BOT_NONZERO << 2) | ALL_NONZERO)
00179 #define ALL_NONZERO__ALL_ZERO           ((ALL_NONZERO << 2) | ALL_ZERO)
00180 #define ALL_NONZERO__TOP_NONZERO        ((ALL_NONZERO << 2) | TOP_NONZERO)
00181 #define ALL_NONZERO__BOT_NONZERO        ((ALL_NONZERO << 2) | BOT_NONZERO)
00182 #define ALL_NONZERO__ALL_NONZERO        ((ALL_NONZERO << 2) | ALL_NONZERO)
00183 
00184 #ifdef SKIP_ERT
00185 #define PIXEL_IS_OPAQUE(ipixel) 0
00186 #else
00187 #define PIXEL_IS_OPAQUE(ipixel) ((ipixel)->lnk != 0)
00188 #endif
00189 
00190 #ifdef STATISTICS
00191 extern int vpResampleCount;
00192 extern int vpCompositeCount;
00193 extern int vpERTSkipCount;
00194 extern int vpERTSkipAgainCount;
00195 extern int vpERTUpdateCount;
00196 extern int vpSpecialZeroSkipCount;
00197 extern int vpRunFragmentCount;
00198 #define COUNT_RESAMPLE          vpResampleCount++
00199 #define COUNT_COMPOSITE         vpCompositeCount++
00200 #define COUNT_ERT_SKIP          vpERTSkipCount++
00201 #define COUNT_ERT_SKIP_AGAIN    vpERTSkipAgainCount++
00202 #define COUNT_ERT_UPDATE        vpERTUpdateCount++
00203 #define COUNT_SPECIAL_ZERO_SKIP vpSpecialZeroSkipCount++
00204 #define COUNT_RUN_FRAGMENT      vpRunFragmentCount++
00205 #else
00206 #define COUNT_RESAMPLE
00207 #define COUNT_COMPOSITE
00208 #define COUNT_ERT_SKIP
00209 #define COUNT_ERT_SKIP_AGAIN
00210 #define COUNT_ERT_UPDATE
00211 #define COUNT_SPECIAL_ZERO_SKIP
00212 #define COUNT_RUN_FRAGMENT
00213 #endif /* STATISTICS */
00214 
00215 /*
00216  * VPCompAR3NS
00217  *
00218  * Compositing routine for run-length encoded volume data slices.
00219  * Decode and resample one slice of volume data, and composite
00220  * it into the intermediate image.  The resampling filter is a bilirp.
00221  */
00222 
00223 void
00224 VPCompAR3NS (vpc, icount, jcount, k, slice_depth_cueing_dbl, intimage,
00225           weightTLdbl, weightBLdbl, weightTRdbl, weightBRdbl,
00226           voxel_data, voxel_istride, voxel_jstride , shadow_buffer)
00227 vpContext *vpc;                 /* context */
00228 int icount;                     /* slice size */
00229 int jcount;
00230 int k;                          /* slice number */
00231 double slice_depth_cueing_dbl;  /* depth cueing factor for slice */
00232 RGBIntPixel *intimage;          /* intermediate image pixels */
00233 double weightTLdbl;             /* resampling weights */
00234 double weightBLdbl;
00235 double weightTRdbl;
00236 double weightBRdbl;
00237 
00238                 void *voxel_data;               /* voxel data for slice */
00239                 int voxel_istride;              /* strides for voxel data */
00240                 int voxel_jstride;
00241 GrayIntPixel *shadow_buffer;
00242 {
00243     int i, j;                   /* voxel index in rotated object space */
00244     RGBIntPixel *ipixel;        /* current intermediate image pixel */
00245     RGBIntPixel *ipixel2;       /* another intermediate image pixel */
00246     int update_interval;        /* # of pixels to skip when updating links */
00247     float iopc;                 /* intermediate pixel opacity (0-1) */
00248     float iopc_inv;             /* 1-iopc */
00249     float acc_opc;              /* accumulator for resampled voxel opacity */
00250     float top_opc, bot_opc;     /* voxel opacity (top and bottom scanlines) */
00251 #ifdef NO_REUSE_VOXEL
00252 #define voxels_loaded   0
00253 #define CLEAR_VOXELS_LOADED
00254 #define SET_VOXELS_LOADED
00255 #else
00256     int voxels_loaded;          /* if true, top/bot_opc contain valid
00257                                    data loaded during the last resample */
00258 #define CLEAR_VOXELS_LOADED     voxels_loaded = 0
00259 #define SET_VOXELS_LOADED       voxels_loaded = 1
00260 #endif
00261     float wgtTL, wgtBL,         /* weights in the range 0..1 which give the */
00262           wgtTR, wgtBR;         /*   fractional contribution of the */
00263                                 /*   neighboring voxels to the current */
00264                                 /*   intermediate image pixel */
00265     unsigned char *topRLElen;   /* length of current run in top scanline */
00266     unsigned char *botRLElen;   /* length of current run in bottom scanline */
00267     char *topRLEdata;           /* data for current run in top scanline */
00268     char *botRLEdata;           /* data for current run in bottom scanline */
00269     int toprun_count;           /* number of voxels left in top run */
00270     int botrun_count;           /* number of voxels left in bottom run */
00271     int last_run_state;         /* run state code for last resample */
00272     int run_state;              /* run state code for this resample */
00273     int final_run_state;        /* run state code for end of scanline */
00274     float min_opacity;          /* low opacity threshold */
00275     float max_opacity;          /* high opacity threshold */
00276     float slice_depth_cueing;   /* depth cueing factor for slice */
00277     float *opac_correct;        /* opacity correction table */
00278     int ert_skip_count;         /* number of pixels to skip for ERT */
00279     int intermediate_width;     /* width of intermediate image in pixels */
00280     int count;                  /* voxels left in current run */
00281     float *shade_table;         /* shade lookup table */
00282     int norm_offset;            /* byte offset to shade table index in voxel */
00283     int shade_index;            /* shade index */
00284     float shade_factor;         /* attenuation factor for color
00285                                    (voxel opacity * depth cueing) */
00286 
00287 #ifdef MULTIPLE_MATERIALS
00288     float *weight_table;        /* weight lookup table */
00289     int wgt_offset;             /* byte offset to weight table index */
00290     int weight_index;           /* weight index */
00291     int m, num_materials;
00292     float weight1, weight2;
00293 #endif /* MULTIPLE_MATERIALS */
00294 
00295 #ifdef GRAYSCALE
00296     float acc_clr;              /* accumulator for resampled color */
00297     float top_clr, bot_clr;     /* voxel color (top and bottom scanlines) */
00298 #endif /* GRAYSCALE */
00299 
00300 #ifdef RGB
00301     float acc_rclr;             /* accumulator for resampled color */
00302     float acc_gclr;
00303     float acc_bclr;
00304     float top_rclr;             /* voxel color (top and bottom scanlines) */
00305     float bot_rclr;
00306     float top_gclr;
00307     float bot_gclr;
00308     float top_bclr;
00309     float bot_bclr;
00310 #endif
00311 
00312 #ifdef RLEVOLUME
00313     int voxel_istride;          /* size of a voxel in bytes */
00314 #endif
00315 
00316 #ifdef RAWVOLUME
00317     int use_octree;             /* if true then use the min-max octree */
00318     MMOctreeLevel level_stack[VP_MAX_OCTREE_LEVELS];
00319                                 /* stack for traversal of min-max octree */
00320     int scans_left;             /* scanlines until next octree traversal */
00321     int best_view_axis;         /* viewing axis */
00322     unsigned char runlen_buf1[VP_MAX_VOLUME_DIM]; /* buffers for run lengths */
00323     unsigned char runlen_buf2[VP_MAX_VOLUME_DIM];
00324     unsigned char *top_len_base;/* first run length for top scanline */
00325     unsigned char *bot_len_base;/* first run length for bottom scanline */
00326     int opac_param;             /* parameter to opacity transfer function */
00327     float opacity;              /* voxel opacity */
00328     int opacity_int;            /* voxel opacity truncated to an integer */
00329     int param0_offset;          /* offset to first parameter in voxel */
00330     int param0_size;            /* size of first parameter in bytes */
00331     float *param0_table;        /* lookup table for first parameter */
00332     int param1_offset;          /* offset to second parameter in voxel */
00333     int param1_size;            /* size of second parameter in bytes */
00334     float *param1_table;        /* lookup table for second parameter */
00335     int param2_offset;          /* offset to third parameter in voxel */
00336     int param2_size;            /* size of third parameter in bytes */
00337     float *param2_table;        /* lookup table for third parameter */
00338 #endif /* RAWVOLUME */
00339 
00340 #ifdef INDEX_VOLUME
00341     unsigned char *scanline_topRLElen; /* first topRLElen in scanline */
00342     unsigned char *scanline_botRLElen; /* first botRLElen in scanline */
00343     char *scanline_topRLEdata;  /* first topRLEdata in scanline */
00344     char *scanline_botRLEdata;  /* first botRLEdata in scanline */
00345     VoxelLocation *top_voxel_index; /* voxel indexes for top scanline */
00346     VoxelLocation *bot_voxel_index; /* voxel indexes for bot scanline */
00347     VoxelLocation *vindex;
00348     int next_i;                 /* i coordinate of voxel to skip to */
00349     int next_scan;              /* true if skipped to next scanline */
00350 #endif /* INDEX_VOLUME */
00351 
00352 #ifdef CALLBACK
00353                                 /* shading callback function */
00354 #ifdef GRAYSCALE
00355     void (*shade_func) ANSI_ARGS((void *, float *, void *));
00356 #endif
00357 #ifdef RGB
00358     void (*shade_func) ANSI_ARGS((void *, float *, float *, float *, void *));
00359 #endif
00360     void *client_data;          /* client data handle */
00361 #endif /* CALLBACK */
00362 
00363 #ifdef USE_SHADOW_BUFFER
00364     float *shadow_table;        /* color lookup table for shadows */
00365     int shadow_width;           /* width of shadow buffer */
00366     GrayIntPixel *shadow_pixel; /* current shadow buffer pixel */
00367 #ifdef GRAYSCALE
00368     float top_sclr, bot_sclr;   /* shadow color (top and bottom scanlines) */
00369 #endif /* GRAYSCALE */
00370 #ifdef RGB
00371     float top_rsclr;            /* shadow color (top and bottom scanlines) */
00372     float bot_rsclr;
00373     float top_gsclr;
00374     float bot_gsclr;
00375     float top_bsclr;
00376     float bot_bsclr;
00377 #endif
00378 #endif /* SHADOW_BUFFER */
00379 
00380 #ifdef DEBUG
00381     float trace_opcTL, trace_opcBL, trace_opcTR, trace_opcBR;
00382     float trace_rsclrTL, trace_rsclrBL, trace_rsclrTR, trace_rsclrBR;
00383     float trace_rclrTL, trace_rclrBL, trace_rclrTR, trace_rclrBR;
00384     float trace_gclrTL, trace_gclrBL, trace_gclrTR, trace_gclrBR;
00385     float trace_bclrTL, trace_bclrBL, trace_bclrTR, trace_bclrBR;
00386     RGBIntPixel *trace_pixel_ptr;
00387 
00388 #ifdef COMPUTE_SHADOW_BUFFER
00389     int slice_u_int, shadow_slice_u_int;
00390     int slice_v_int, shadow_slice_v_int;
00391 #endif
00392 #endif /* DEBUG */
00393 
00394     DECLARE_HIRES_TIME(t0);
00395     DECLARE_HIRES_TIME(t1);
00396 
00397     /*******************************************************************
00398      * Copy parameters from the rendering context into local variables.
00399      *******************************************************************/
00400 
00401     GET_HIRES_TIME(vpc, t0);
00402 
00403     wgtTL = weightTLdbl;
00404     wgtBL = weightBLdbl;
00405     wgtTR = weightTRdbl;
00406     wgtBR = weightBRdbl;
00407     slice_depth_cueing = slice_depth_cueing_dbl;
00408     min_opacity = vpc->min_opacity;
00409     max_opacity = vpc->max_opacity;
00410 #ifdef USE_SHADOW_BUFFER
00411     opac_correct = vpc->shadow_opac_correct;
00412 #else
00413     opac_correct = vpc->affine_opac_correct;
00414 #endif
00415 #ifdef COMPUTE_SHADOW_BUFFER
00416     intermediate_width = vpc->shadow_width;
00417 #else
00418     intermediate_width = vpc->intermediate_width;
00419 #endif
00420 #ifdef USE_SHADOW_BUFFER
00421     shadow_table = vpc->shadow_color_table;
00422     shadow_width = vpc->shadow_width;
00423     shadow_pixel = shadow_buffer;
00424 #endif
00425     ipixel = intimage;
00426     shade_table = vpc->shade_color_table;
00427     norm_offset = vpc->field_offset[vpc->color_field];
00428 
00429 #ifdef MULTIPLE_MATERIALS
00430     weight_table = vpc->shade_weight_table;
00431     wgt_offset = vpc->field_offset[vpc->weight_field];
00432     num_materials = vpc->num_materials;
00433 #endif /* MULTIPLE_MATERIALS */
00434 
00435 #ifdef RLEVOLUME
00436     topRLEdata = voxel_data;
00437     botRLEdata = voxel_data;
00438     topRLElen = run_lengths;
00439     botRLElen = run_lengths;
00440     voxel_istride = vpc->rle_bytes_per_voxel;
00441 #endif /* RLEVOLUME */
00442 
00443 #ifdef RAWVOLUME
00444     ASSERT(vpc->num_clsfy_params > 0);
00445     ASSERT(vpc->num_clsfy_params < 3);
00446     param0_offset = vpc->field_offset[vpc->param_field[0]];
00447     param0_size = vpc->field_size[vpc->param_field[0]];
00448     param0_table = vpc->clsfy_table[0];
00449     if (vpc->num_clsfy_params > 1) {
00450         param1_offset = vpc->field_offset[vpc->param_field[1]];
00451         param1_size = vpc->field_size[vpc->param_field[1]];
00452         param1_table = vpc->clsfy_table[1];
00453     } else {
00454         param1_offset = 0;
00455         param1_size = 0;
00456         param1_table = NULL;
00457     }
00458     if (vpc->num_clsfy_params > 2) {
00459         param2_offset = vpc->field_offset[vpc->param_field[2]];
00460         param2_size = vpc->field_size[vpc->param_field[2]];
00461         param2_table = vpc->clsfy_table[2];
00462     } else {
00463         param2_offset = 0;
00464         param2_size = 0;
00465         param2_table = NULL;
00466     }
00467     if (vpc->mm_octree == NULL) {
00468         use_octree = 0;
00469     } else {
00470         use_octree = 1;
00471         best_view_axis = vpc->best_view_axis;
00472         VPInitOctreeLevelStack(vpc, level_stack, best_view_axis, k);
00473         scans_left = 0;
00474         bot_len_base = runlen_buf1;
00475     }
00476 #endif /* RAWVOLUME */
00477 
00478 #ifdef CALLBACK
00479     shade_func = vpc->shade_func;
00480     client_data = vpc->client_data;
00481     ASSERT(shade_func != NULL);
00482 #endif
00483 
00484 #ifdef DEBUG
00485     trace_pixel_ptr = 0;
00486     if (vpc->trace_u >= 0 && vpc->trace_v >= 0) {
00487 #ifdef GRAYSCALE
00488         trace_pixel_ptr = &vpc->int_image.gray_intim[vpc->trace_u + 
00489                       vpc->trace_v*vpc->intermediate_width];
00490 #endif
00491 #ifdef RGB
00492         trace_pixel_ptr = &vpc->int_image.rgb_intim[vpc->trace_u + 
00493                       vpc->trace_v*vpc->intermediate_width];
00494 #endif
00495 #ifdef COMPUTE_SHADOW_BUFFER
00496         slice_u_int = (int)ceil(vpc->shear_i * vpc->trace_shadow_k +
00497                                 vpc->trans_i) - 1;
00498         shadow_slice_u_int = (int)ceil(vpc->shadow_shear_i * 
00499                              vpc->trace_shadow_k + vpc->shadow_trans_i) - 1;
00500         slice_v_int = (int)ceil(vpc->shear_j * vpc->trace_shadow_k
00501                                 + vpc->trans_j) - 1;
00502         shadow_slice_v_int = (int)ceil(vpc->shadow_shear_j *
00503                              vpc->trace_shadow_k + vpc->shadow_trans_j) - 1;
00504         trace_pixel_ptr = &vpc->shadow_buffer[vpc->trace_u +
00505                 shadow_slice_u_int - slice_u_int + 
00506                 (vpc->trace_v + shadow_slice_v_int -
00507                 slice_v_int)*vpc->shadow_width];
00508 #endif
00509     }
00510 #endif /* DEBUG */
00511 
00512     /*******************************************************************
00513      * Loop over voxel scanlines.
00514      *******************************************************************/
00515 
00516     for (j = 0; j <= jcount; j++) {
00517 
00518         /***************************************************************
00519          * Initialize counters and flags.
00520          ***************************************************************/
00521 
00522         i = icount;
00523         CLEAR_VOXELS_LOADED;
00524         last_run_state = ALL_ZERO;
00525 
00526 #ifdef RAWVOLUME
00527         botRLEdata = (char *)voxel_data + j*voxel_jstride;
00528         topRLEdata = botRLEdata - voxel_jstride;
00529         if (!use_octree) {
00530             if (j == 0) {
00531                 run_state = BOT_NONZERO;
00532                 toprun_count = icount+2;
00533                 botrun_count = icount;
00534             } else if (j == jcount) {
00535                 run_state = TOP_NONZERO;
00536                 toprun_count = icount;
00537                 botrun_count = icount+2;
00538             } else {
00539                 run_state = ALL_NONZERO;
00540                 toprun_count = icount;
00541                 botrun_count = icount;
00542             }
00543         } else
00544 #endif /* RAWVOLUME */
00545         if (j == 0) {
00546             run_state = BOT_NONZERO;
00547             toprun_count = icount+2;
00548             botrun_count = 0;
00549         } else if (j == jcount) {
00550             run_state = TOP_NONZERO;
00551             toprun_count = 0;
00552             botrun_count = icount+2;
00553         } else {
00554             run_state = ALL_NONZERO;
00555             toprun_count = 0;
00556             botrun_count = 0;
00557         }
00558 
00559 #ifdef INDEX_VOLUME
00560         scanline_topRLElen = topRLElen;
00561         scanline_botRLElen = botRLElen;
00562         scanline_topRLEdata = topRLEdata;
00563         scanline_botRLEdata = botRLEdata;
00564         if (j == 0) {
00565             top_voxel_index = voxel_index;
00566             bot_voxel_index = voxel_index;
00567         } else {
00568             top_voxel_index = bot_voxel_index;
00569             bot_voxel_index += icount;
00570         }
00571 #endif /* INDEX_VOLUME */
00572 
00573         /***************************************************************
00574          * If the volume is not run-length encoded, use the min-max
00575          * to find run lengths for the current voxel scanline.
00576          ***************************************************************/
00577 
00578 #ifdef RAWVOLUME
00579         if (use_octree) {
00580             top_len_base = bot_len_base;
00581             if (scans_left == 0) {
00582                 if (bot_len_base == runlen_buf1)
00583                     bot_len_base = runlen_buf2;
00584                 else
00585                     bot_len_base = runlen_buf1;
00586 
00587                 GET_HIRES_TIME(vpc, t1);
00588                 STORE_HIRES_TIME(vpc, VPTIMER_TRAVERSE_RUNS, t0, t1);
00589                 COPY_HIRES_TIME(t0, t1);
00590 
00591                 scans_left = VPComputeScanRuns(vpc, level_stack, bot_len_base,
00592                                                best_view_axis, j, icount);
00593 
00594                 GET_HIRES_TIME(vpc, t1);
00595                 STORE_HIRES_TIME(vpc, VPTIMER_TRAVERSE_OCTREE, t0, t1);
00596                 COPY_HIRES_TIME(t0, t1);
00597             }
00598 #ifdef DEBUG
00599             if (j > 0)
00600                 VPCheckRuns(vpc, top_len_base, best_view_axis, k, j-1);
00601             if (j < jcount)
00602                 VPCheckRuns(vpc, bot_len_base, best_view_axis, k, j);
00603 #endif
00604             scans_left--;
00605             topRLElen = top_len_base;
00606             botRLElen = bot_len_base;
00607         }
00608 #endif /* RAWVOLUME */
00609 
00610         /***************************************************************
00611          * Loop over runs in the voxel scanline.
00612          ***************************************************************/
00613 
00614         Debug((vpc, VPDEBUG_COMPOSITE, "StartIScan(u=%d,v=%d)\n",
00615                (((int)ipixel - (int)vpc->int_image.gray_intim) /
00616                 sizeof(RGBIntPixel)) % vpc->intermediate_width,
00617                (((int)ipixel - (int)vpc->int_image.gray_intim) /
00618                 sizeof(RGBIntPixel)) / vpc->intermediate_width));
00619 
00620 #ifdef UNROLL_RUN_LOOP
00621         while (i > 0) {
00622 #else
00623         while (i >= 0) {
00624 #endif
00625             /***********************************************************
00626              * Skip over any empty runs at beginning of scanline.
00627              ***********************************************************/
00628 
00629             if (last_run_state == ALL_ZERO) {
00630 #ifndef UNROLL_RUN_LOOP
00631                 if (i == 0) {
00632                     Debug((vpc, VPDEBUG_COMPOSITE, "ZeroSkip(1)End\n"));
00633                     ipixel += 1; shadow_pixel += 1;
00634                     final_run_state = ALL_ZERO;
00635                     i = -1;
00636                     break;      /* scanline is done */
00637                 }
00638 #endif
00639 
00640                 /* check if this is the start of a new run */
00641                 while (toprun_count == 0) {
00642                     toprun_count = *topRLElen++;
00643                     run_state ^= 1;
00644                 }
00645                 while (botrun_count == 0) {
00646                     botrun_count = *botRLElen++;
00647                     run_state ^= 2;
00648                 }
00649                 if (run_state == ALL_ZERO) {
00650                     COUNT_SPECIAL_ZERO_SKIP;
00651 
00652                     /* find the union of the two runs of voxels */
00653                     count = MIN(toprun_count, botrun_count);
00654                     toprun_count -= count;
00655                     botrun_count -= count;
00656                     ipixel += count; shadow_pixel += count;
00657                     topRLEdata += count * voxel_istride;
00658                     botRLEdata += count * voxel_istride;
00659                     i -= count;
00660                     ASSERT(i >= 0);
00661                     Debug((vpc, VPDEBUG_COMPOSITE, "ZeroSkip(%d)\n", count));
00662                     continue;
00663                 }
00664             }
00665 
00666 #ifndef SKIP_ERT
00667             /***********************************************************
00668              * Skip over opaque pixels (early-ray termination).
00669              ***********************************************************/
00670 
00671             if ((ert_skip_count = ipixel->lnk) != 0) {
00672 
00673                 GET_HIRES_TIME(vpc, t1);
00674                 STORE_HIRES_TIME(vpc, VPTIMER_TRAVERSE_RUNS, t0, t1);
00675                 COPY_HIRES_TIME(t0, t1);
00676 
00677                 COUNT_ERT_SKIP;
00678 
00679 #ifndef UNROLL_RUN_LOOP
00680                 if (i == 0) {
00681                     ipixel += 1; shadow_pixel += 1;
00682                     final_run_state = last_run_state;
00683                     i = -1;
00684                     Debug((vpc, VPDEBUG_COMPOSITE, "ERTSkip(1)End\n"));
00685                     break;      /* scanline is done */
00686                 }
00687 #endif
00688 
00689                 /* find out how many pixels to skip */
00690                 if (ert_skip_count < i &&
00691                                 (count = ipixel[ert_skip_count].lnk) != 0) {
00692                     /* follow pointer chain */
00693                     do {
00694                         COUNT_ERT_SKIP_AGAIN;
00695                         ert_skip_count += count;
00696                     } while (ert_skip_count < i &&
00697                                  (count = ipixel[ert_skip_count].lnk) != 0);
00698 
00699                     /* update some of the lnk pointers in the run of opaque
00700                        pixels; the more links we update the longer it will
00701                        take to perform the update, but we will potentially
00702                        save time in future slices by not having to follow
00703                        long pointer chains */
00704                     ipixel2 = ipixel;
00705                     update_interval = 1;
00706                     count = ert_skip_count - 1;
00707                     while (count > 0) {
00708                         COUNT_ERT_UPDATE;
00709                         ipixel2 += update_interval;
00710                         if (count > 255)
00711                             ipixel2->lnk = 255;
00712                         else
00713                             ipixel2->lnk = count;
00714                         update_interval *= 2;
00715                         count -= update_interval;
00716                     }
00717 
00718                     /* update the current link */
00719                     COUNT_ERT_UPDATE;
00720                     if (ert_skip_count > 255)
00721                         ert_skip_count = 255;
00722                     ipixel->lnk = ert_skip_count;
00723                 }
00724 
00725                 /* skip over the opaque pixels */
00726                 if (ert_skip_count > i)
00727                     ert_skip_count = i;
00728                 Debug((vpc, VPDEBUG_COMPOSITE,"ERTSkip(%d)\n",ert_skip_count));
00729                 ipixel += ert_skip_count; shadow_pixel += ert_skip_count;
00730                 CLEAR_VOXELS_LOADED;
00731 
00732 #ifdef INDEX_VOLUME
00733                 /* compute i coordinate of voxel to skip to */
00734                 next_i = icount - i + ert_skip_count;
00735                 if (next_i == icount) {
00736                     next_i--;
00737                     next_scan = 1;
00738                 } else {
00739                     next_scan = 0;
00740                 }
00741 
00742                 /* skip over voxels in top scanline */
00743                 vindex = &top_voxel_index[next_i];
00744                 toprun_count = vindex->run_count;
00745                 topRLElen = scanline_topRLElen + vindex->len_offset;
00746                 if (vindex->data_offset & INDEX_RUN_IS_ZERO) {
00747                     run_state &= ~1;
00748                     topRLEdata = scanline_topRLEdata +
00749                         (vindex->data_offset & ~INDEX_RUN_IS_ZERO);
00750                 } else {
00751                     run_state |= 1;
00752                     topRLEdata = scanline_topRLEdata + vindex->data_offset;
00753                 }
00754 
00755                 /* skip over voxels in bottom scanline */
00756                 vindex = &bot_voxel_index[next_i];
00757                 botrun_count = vindex->run_count;
00758                 botRLElen = scanline_botRLElen + vindex->len_offset;
00759                 if (vindex->data_offset & INDEX_RUN_IS_ZERO) {
00760                     run_state &= ~2;
00761                     botRLEdata = scanline_botRLEdata +
00762                         (vindex->data_offset & ~INDEX_RUN_IS_ZERO);
00763                 } else {
00764                     run_state |= 2;
00765                     botRLEdata = scanline_botRLEdata + vindex->data_offset;
00766                 }
00767 
00768                 /* special case to skip over last voxel in scanline */
00769                 if (next_scan) {
00770                     /* advance to beginning of next top scanline */
00771                     while (toprun_count == 0) {
00772                         toprun_count = *topRLElen++;
00773                         run_state ^= 1;
00774                     }
00775                     toprun_count--;
00776                     if (run_state & 1) {
00777                         topRLEdata += 1 * voxel_istride;
00778                     } else {
00779                         topRLEdata += 1 * voxel_istride;
00780                     }
00781 
00782                     /* advance to beginning of next bottom scanline */
00783                     while (botrun_count == 0) {
00784                         botrun_count = *botRLElen++;
00785                         run_state ^= 2;
00786                     }
00787                     botrun_count--;
00788                     if (run_state & 2) {
00789                         botRLEdata += 1 * voxel_istride;
00790                     } else {
00791                         botRLEdata += 1 * voxel_istride;
00792                     }
00793                 }
00794 
00795 #else /* !INDEX_VOLUME */
00796                 /* skip over voxels in top scanline */
00797                 count = ert_skip_count;
00798                 for (;;) {
00799                     if (toprun_count >= count) {
00800                         toprun_count -= count;
00801                         if (run_state & 1) {
00802                             topRLEdata += count * voxel_istride;
00803                         } else {
00804                             topRLEdata += count * voxel_istride;
00805                         }
00806                         break;
00807                     } else {
00808                         count -= toprun_count;
00809                         if (run_state & 1) {
00810                             topRLEdata += toprun_count * voxel_istride;
00811                         } else {
00812                             topRLEdata += toprun_count * voxel_istride;
00813                         }
00814                         toprun_count = *topRLElen++;
00815                         if (toprun_count == 0)
00816                             toprun_count = *topRLElen++;
00817                         else
00818                             run_state ^= 1;
00819                     }
00820                 }
00821 
00822                 /* skip over voxels in bottom scanline */
00823                 count = ert_skip_count;
00824                 for (;;) {
00825                     if (botrun_count >= count) {
00826                         botrun_count -= count;
00827                         if (run_state & 2) {
00828                             botRLEdata += count * voxel_istride;
00829                         } else {
00830                             botRLEdata += count * voxel_istride;
00831                         }
00832                         break;
00833                     } else {
00834                         count -= botrun_count;
00835                         if (run_state & 2) {
00836                             botRLEdata += botrun_count * voxel_istride;
00837                         } else {
00838                             botRLEdata += botrun_count * voxel_istride;
00839                         }
00840                         botrun_count = *botRLElen++;
00841                         if (botrun_count == 0)
00842                             botrun_count = *botRLElen++;
00843                         else
00844                             run_state ^= 2;
00845                     }
00846                 }
00847 #endif /* INDEX_VOLUME */
00848                 i -= ert_skip_count;
00849                 last_run_state = run_state;
00850                 if (i == 0) {
00851 #ifdef UNROLL_RUN_LOOP
00852                     break;
00853 #else
00854                     if (last_run_state == ALL_ZERO) {
00855                         ipixel += 1; shadow_pixel += 1;
00856                         final_run_state = ALL_ZERO;
00857                         i = -1;
00858                         Debug((vpc, VPDEBUG_COMPOSITE, "ZeroSkip(1)End\n"));
00859                         break;  /* scanline is done */
00860                     }
00861                     if (ipixel->lnk != 0) {
00862                         ipixel += 1; shadow_pixel += 1;
00863                         final_run_state = last_run_state;
00864                         i = -1;
00865                         Debug((vpc, VPDEBUG_COMPOSITE, "ERTSkip(1)End\n"));
00866                         break;  /* scanline is done */
00867                     }
00868 #endif /* UNROLL_RUN_LOOP */
00869                 }
00870 
00871                 GET_HIRES_TIME(vpc, t1);
00872                 STORE_HIRES_TIME(vpc, VPTIMER_ERT, t0, t1);
00873                 COPY_HIRES_TIME(t0, t1);
00874             }
00875             ASSERT(ipixel->opcflt < max_opacity);
00876 #endif /* SKIP_ERT */
00877 
00878             /***********************************************************
00879              * Compute the length of the current run.
00880              ***********************************************************/
00881 
00882 #ifndef UNROLL_RUN_LOOP
00883             if (i == 0) {
00884                 final_run_state = last_run_state;
00885                 run_state = ALL_ZERO;
00886                 i = -1;
00887                 count = 1;
00888                 Debug((vpc, VPDEBUG_COMPOSITE, "Run(1)End\n"));
00889             } else {
00890 #endif
00891                 /* check if this is the start of a new run */
00892                 while (toprun_count == 0) {
00893                     toprun_count = *topRLElen++;
00894                     run_state ^= 1;
00895                 }
00896                 while (botrun_count == 0) {
00897                     botrun_count = *botRLElen++;
00898                     run_state ^= 2;
00899                 }
00900 
00901                 /* find the union of the two runs of voxels */
00902                 count = MIN(toprun_count, botrun_count);
00903                 toprun_count -= count;
00904                 botrun_count -= count;
00905                 i -= count;
00906                 Debug((vpc, VPDEBUG_COMPOSITE, "Run(%d)\n", count));
00907                 ASSERT(i >= 0);
00908 #ifndef UNROLL_RUN_LOOP
00909             }
00910 #endif
00911             COUNT_RUN_FRAGMENT;
00912 
00913             /***********************************************************
00914              * composite the voxels in the current run.
00915              ***********************************************************/
00916 
00917             GET_HIRES_TIME(vpc, t1);
00918             STORE_HIRES_TIME(vpc, VPTIMER_TRAVERSE_RUNS, t0, t1);
00919             COPY_HIRES_TIME(t0, t1);
00920 
00921 #ifdef SKIP_COMPOSITE
00922             switch (run_state) {
00923             case ALL_ZERO:
00924                 ipixel += count; shadow_pixel += count;
00925                 topRLEdata += count * voxel_istride;
00926                 botRLEdata += count * voxel_istride;
00927                 count = 0;
00928                 break;
00929             case TOP_NONZERO:
00930                 ipixel += count; shadow_pixel += count;
00931                 topRLEdata += count * voxel_istride;
00932                 botRLEdata += count * voxel_istride;
00933                 count = 0;
00934                 break;
00935             case BOT_NONZERO:
00936                 ipixel += count; shadow_pixel += count;
00937                 topRLEdata += count * voxel_istride;
00938                 botRLEdata += count * voxel_istride;
00939                 count = 0;
00940                 break;
00941             case ALL_NONZERO:
00942                 ipixel += count; shadow_pixel += count;
00943                 topRLEdata += count * voxel_istride;
00944                 botRLEdata += count * voxel_istride;
00945                 count = 0;
00946                 break;
00947             }
00948 #else /* !SKIP_COMPOSITE */
00949 #ifdef UNROLL_RUN_LOOP
00950             /* this run contains pixels, so process them */
00951             switch ((last_run_state << 2) | run_state) {
00952             case ALL_ZERO__ALL_ZERO:
00953                 /* no voxels contribute to the pixels in this run */
00954                 ipixel += count; shadow_pixel += count;
00955                 topRLEdata += count * voxel_istride;
00956                 botRLEdata += count * voxel_istride;
00957                 count = 0;
00958                 break;
00959             case TOP_NONZERO__ALL_ZERO:
00960                 /* only the top-left voxel contributes to the first
00961                    pixel of the run, and the rest are zero */
00962                 if (!voxels_loaded) {
00963                     
00964     
00965             opac_param = VoxelField(topRLEdata - voxel_istride, param0_offset, param0_size);
00966             opacity = param0_table[opac_param];
00967             if (param1_size != 0) {
00968                 opac_param = VoxelField(topRLEdata - voxel_istride, param1_offset, param1_size);
00969                 opacity *= param1_table[opac_param];
00970                 if (param2_size != 0) {
00971                     opac_param = VoxelField(topRLEdata - voxel_istride, param2_offset, param2_size);
00972                     opacity *= param2_table[opac_param];
00973                 }
00974             }
00975             if (opacity > min_opacity) {
00976                 opacity_int = opacity*255.;
00977                 top_opc = opac_correct[opacity_int];
00978             } else {
00979                 top_opc = (float)0.;
00980             };
00981     
00982     
00983     shade_index=num_materials*3*ShortField(topRLEdata - voxel_istride,norm_offset);
00984     weight_index = num_materials * ByteField(topRLEdata - voxel_istride, wgt_offset);
00985     
00986         
00987         
00988     top_rclr = 
00989     shade_table[shade_index + 3*0 + 0] * 
00990         ((num_materials > 1) ? weight_table[weight_index] : (float)1.0);
00991         
00992     top_gclr = 
00993     shade_table[shade_index + 3*0 + 1] * 
00994         ((num_materials > 1) ? weight_table[weight_index] : (float)1.0);
00995         
00996     top_bclr = 
00997     shade_table[shade_index + 3*0 + 2] * 
00998         ((num_materials > 1) ? weight_table[weight_index] : (float)1.0);
00999         
01000         top_rsclr = 
01001     shadow_table[shade_index + 3*0 + 0] * 
01002         ((num_materials > 1) ? weight_table[weight_index] : (float)1.0);
01003         
01004         top_gsclr = 
01005     shadow_table[shade_index + 3*0 + 1] * 
01006         ((num_materials > 1) ? weight_table[weight_index] : (float)1.0);
01007         
01008         top_bsclr = 
01009     shadow_table[shade_index + 3*0 + 2] * 
01010         ((num_materials > 1) ? weight_table[weight_index] : (float)1.0);
01011         for (m = 1; m < num_materials; m++) {
01012              
01013         
01014     top_rclr += 
01015     shade_table[shade_index + 3*m + 0] * 
01016         weight_table[weight_index + m];
01017         
01018     top_gclr += 
01019     shade_table[shade_index + 3*m + 1] * 
01020         weight_table[weight_index + m];
01021         
01022     top_bclr += 
01023     shade_table[shade_index + 3*m + 2] * 
01024         weight_table[weight_index + m];
01025         
01026         top_rsclr += 
01027     shadow_table[shade_index + 3*m + 0] * 
01028         weight_table[weight_index + m];
01029         
01030         top_gsclr += 
01031     shadow_table[shade_index + 3*m + 1] * 
01032         weight_table[weight_index + m];
01033         
01034         top_bsclr += 
01035     shadow_table[shade_index + 3*m + 2] * 
01036         weight_table[weight_index + m];
01037         };
01038     shade_factor = top_opc * slice_depth_cueing;
01039     
01040         top_rclr *= shade_factor;
01041         top_gclr *= shade_factor;
01042         top_bclr *= shade_factor;
01043     
01044             top_rsclr *= shade_factor;
01045             top_gsclr *= shade_factor;
01046             top_bsclr *= shade_factor;
01047                 }
01048                 
01049 #ifdef DEBUG
01050     if (ipixel == trace_pixel_ptr) {
01051         trace_opcTL = 0.; trace_opcBL = 0.; trace_opcTR = 0.; trace_opcBR = 0.;
01052         trace_rsclrTL=0.; trace_rsclrBL=0.; trace_rsclrTR=0.; trace_rsclrBR=0.;
01053         trace_rclrTL= 0.; trace_rclrBL= 0.; trace_rclrTR= 0.; trace_rclrBR= 0.;
01054         trace_gclrTL= 0.; trace_gclrBL= 0.; trace_gclrTR= 0.; trace_gclrBR= 0.;
01055         trace_bclrTL= 0.; trace_bclrBL= 0.; trace_bclrTR= 0.; trace_bclrBR= 0.;
01056     }
01057 #endif
01058 ;
01059                 
01060        acc_opc = top_opc * wgtTL;
01061        
01062             acc_rclr = (top_rclr + top_rsclr *
01063                          ((float)1.0 - shadow_pixel->opcflt)) * wgtTL;
01064             acc_gclr = (top_gclr + top_gsclr *
01065                          ((float)1.0 - shadow_pixel->opcflt)) * wgtTL;
01066             acc_bclr = (top_bclr + top_bsclr *
01067                          ((float)1.0 - shadow_pixel->opcflt)) * wgtTL;
01068        
01069 #ifdef DEBUG
01070     if (ipixel == trace_pixel_ptr) {
01071         trace_opcTL = top_opc;
01072         trace_rclrTL = top_rclr;
01073                      trace_gclrTL = top_gclr;
01074                      trace_bclrTL = top_bclr;
01075         
01076     }
01077 #endif
01078 ;
01079                 
01080         COUNT_RESAMPLE;
01081         if (acc_opc > min_opacity) {
01082             COUNT_COMPOSITE;
01083             iopc = ipixel->opcflt;
01084 #           ifndef SKIP_ERT
01085                 ASSERT(iopc < max_opacity);
01086 #           endif
01087             iopc_inv = (float)1. - iopc;
01088             
01089         ipixel->rclrflt += acc_rclr * iopc_inv;
01090         ipixel->gclrflt += acc_gclr * iopc_inv;
01091         ipixel->bclrflt += acc_bclr * iopc_inv;
01092             iopc += acc_opc * iopc_inv;
01093             ipixel->opcflt = iopc;
01094             
01095 #ifdef DEBUG
01096     if (ipixel == trace_pixel_ptr) {
01097 #ifdef COMPUTE_SHADOW_BUFFER
01098         printf("{%3d}  %3d %3d", k, icount-i-count, j);
01099 #else
01100         printf("[%3d]  %3d %3d", k, icount-i-count, j);
01101 #endif
01102         printf("  %3.0f %3.0f %3.0f",trace_opcTL*255.,trace_rclrTL,wgtTL*100.);
01103         printf("  %3.0f %3.0f %3.0f",trace_opcBL*255.,trace_rclrBL,wgtBL*100.);
01104         printf("  %3.0f %3.0f %3.0f",trace_opcTR*255.,trace_rclrTR,wgtTR*100.);
01105         printf("  %3.0f %3.0f %3.0f",trace_opcBR*255.,trace_rclrBR,wgtBR*100.);
01106         printf("  %3.0f %3.0f\n", iopc*255., 
01107                ipixel->rclrflt);
01108         
01109         printf("              ");
01110         printf("      %3.0f    ",trace_rsclrTL);
01111         printf("      %3.0f    ",trace_rsclrBL);
01112         printf("      %3.0f    ",trace_rsclrTR);
01113         printf("      %3.0f    ",trace_rsclrBR);
01114         printf("  %3.0f\n", shadow_pixel->opcflt * 255.);
01115         
01116         printf("              ");
01117         printf("      %3.0f    ",trace_gclrTL);
01118         printf("      %3.0f    ",trace_gclrBL);
01119         printf("      %3.0f    ",trace_gclrTR);
01120         printf("      %3.0f    ",trace_gclrBR);
01121         printf("      %3.0f\n", ipixel->gclrflt);
01122         printf("              ");
01123         printf("      %3.0f    ",trace_bclrTL);
01124         printf("      %3.0f    ",trace_bclrBL);
01125         printf("      %3.0f    ",trace_bclrTR);
01126         printf("      %3.0f    ",trace_bclrBR);
01127         printf("      %3.0f\n", ipixel->bclrflt);
01128     }
01129 #endif /* DEBUG */
01130 ;
01131 #           ifndef SKIP_ERT
01132                 if (iopc >= max_opacity) {
01133                     ASSERT(ipixel->lnk == 0);
01134                     ipixel->lnk = 1;
01135                 }
01136 #           endif
01137         };
01138                 ipixel += count; shadow_pixel += count;
01139                 topRLEdata += count * voxel_istride;
01140                 botRLEdata += count * voxel_istride;
01141                 count = 0;
01142                 break;
01143             case BOT_NONZERO__ALL_ZERO:
01144                 /* only the bottom left voxel contributes to the first
01145                    pixel of the run, and the rest are zero */
01146                 if (!voxels_loaded) {
01147                     
01148     
01149             opac_param = VoxelField(botRLEdata - voxel_istride, param0_offset, param0_size);
01150             opacity = param0_table[opac_param];
01151             if (param1_size != 0) {
01152                 opac_param = VoxelField(botRLEdata - voxel_istride, param1_offset, param1_size);
01153                 opacity *= param1_table[opac_param];
01154                 if (param2_size != 0) {
01155                     opac_param = VoxelField(botRLEdata - voxel_istride, param2_offset, param2_size);
01156                     opacity *= param2_table[opac_param];
01157                 }
01158             }
01159             if (opacity > min_opacity) {
01160                 opacity_int = opacity*255.;
01161                 bot_opc = opac_correct[opacity_int];
01162             } else {
01163                 bot_opc = (float)0.;
01164             };
01165     
01166     
01167     shade_index=num_materials*3*ShortField(botRLEdata - voxel_istride,norm_offset);
01168     weight_index = num_materials * ByteField(botRLEdata - voxel_istride, wgt_offset);
01169     
01170         
01171         
01172     bot_rclr = 
01173     shade_table[shade_index + 3*0 + 0] * 
01174         ((num_materials > 1) ? weight_table[weight_index] : (float)1.0);
01175         
01176     bot_gclr = 
01177     shade_table[shade_index + 3*0 + 1] * 
01178         ((num_materials > 1) ? weight_table[weight_index] : (float)1.0);
01179         
01180     bot_bclr = 
01181     shade_table[shade_index + 3*0 + 2] * 
01182         ((num_materials > 1) ? weight_table[weight_index] : (float)1.0);
01183         
01184         bot_rsclr = 
01185     shadow_table[shade_index + 3*0 + 0] * 
01186         ((num_materials > 1) ? weight_table[weight_index] : (float)1.0);
01187         
01188         bot_gsclr = 
01189     shadow_table[shade_index + 3*0 + 1] * 
01190         ((num_materials > 1) ? weight_table[weight_index] : (float)1.0);
01191         
01192         bot_bsclr = 
01193     shadow_table[shade_index + 3*0 + 2] * 
01194         ((num_materials > 1) ? weight_table[weight_index] : (float)1.0);
01195         for (m = 1; m < num_materials; m++) {
01196              
01197         
01198     bot_rclr += 
01199     shade_table[shade_index + 3*m + 0] * 
01200         weight_table[weight_index + m];
01201         
01202     bot_gclr += 
01203     shade_table[shade_index + 3*m + 1] * 
01204         weight_table[weight_index + m];
01205         
01206     bot_bclr += 
01207     shade_table[shade_index + 3*m + 2] * 
01208         weight_table[weight_index + m];
01209         
01210         bot_rsclr += 
01211     shadow_table[shade_index + 3*m + 0] * 
01212         weight_table[weight_index + m];
01213         
01214         bot_gsclr += 
01215     shadow_table[shade_index + 3*m + 1] * 
01216         weight_table[weight_index + m];
01217         
01218         bot_bsclr += 
01219     shadow_table[shade_index + 3*m + 2] * 
01220         weight_table[weight_index + m];
01221         };
01222     shade_factor = bot_opc * slice_depth_cueing;
01223     
01224         bot_rclr *= shade_factor;
01225         bot_gclr *= shade_factor;
01226         bot_bclr *= shade_factor;
01227     
01228             bot_rsclr *= shade_factor;
01229             bot_gsclr *= shade_factor;
01230             bot_bsclr *= shade_factor;
01231                 }
01232                 
01233 #ifdef DEBUG
01234     if (ipixel == trace_pixel_ptr) {
01235         trace_opcTL = 0.; trace_opcBL = 0.; trace_opcTR = 0.; trace_opcBR = 0.;
01236         trace_rsclrTL=0.; trace_rsclrBL=0.; trace_rsclrTR=0.; trace_rsclrBR=0.;
01237         trace_rclrTL= 0.; trace_rclrBL= 0.; trace_rclrTR= 0.; trace_rclrBR= 0.;
01238         trace_gclrTL= 0.; trace_gclrBL= 0.; trace_gclrTR= 0.; trace_gclrBR= 0.;
01239         trace_bclrTL= 0.; trace_bclrBL= 0.; trace_bclrTR= 0.; trace_bclrBR= 0.;
01240     }
01241 #endif
01242 ;
01243                 
01244        acc_opc = bot_opc * wgtBL;
01245        
01246             acc_rclr = (bot_rclr + bot_rsclr *
01247                          ((float)1.0 - shadow_pixel->opcflt)) * wgtBL;
01248             acc_gclr = (bot_gclr + bot_gsclr *
01249                          ((float)1.0 - shadow_pixel->opcflt)) * wgtBL;
01250             acc_bclr = (bot_bclr + bot_bsclr *
01251                          ((float)1.0 - shadow_pixel->opcflt)) * wgtBL;
01252        
01253 #ifdef DEBUG
01254     if (ipixel == trace_pixel_ptr) {
01255         trace_opcBL = bot_opc;
01256         trace_rclrBL = bot_rclr;
01257                      trace_gclrBL = bot_gclr;
01258                      trace_bclrBL = bot_bclr;
01259         
01260     }
01261 #endif
01262 ;
01263                 
01264         COUNT_RESAMPLE;
01265         if (acc_opc > min_opacity) {
01266             COUNT_COMPOSITE;
01267             iopc = ipixel->opcflt;
01268 #           ifndef SKIP_ERT
01269                 ASSERT(iopc < max_opacity);
01270 #           endif
01271             iopc_inv = (float)1. - iopc;
01272             
01273         ipixel->rclrflt += acc_rclr * iopc_inv;
01274         ipixel->gclrflt += acc_gclr * iopc_inv;
01275         ipixel->bclrflt += acc_bclr * iopc_inv;
01276             iopc += acc_opc * iopc_inv;
01277             ipixel->opcflt = iopc;
01278             
01279 #ifdef DEBUG
01280     if (ipixel == trace_pixel_ptr) {
01281 #ifdef COMPUTE_SHADOW_BUFFER
01282         printf("{%3d}  %3d %3d", k, icount-i-count, j);
01283 #else
01284         printf("[%3d]  %3d %3d", k, icount-i-count, j);
01285 #endif
01286         printf("  %3.0f %3.0f %3.0f",trace_opcTL*255.,trace_rclrTL,wgtTL*100.);
01287         printf("  %3.0f %3.0f %3.0f",trace_opcBL*255.,trace_rclrBL,wgtBL*100.);
01288         printf("  %3.0f %3.0f %3.0f",trace_opcTR*255.,trace_rclrTR,wgtTR*100.);
01289         printf("  %3.0f %3.0f %3.0f",trace_opcBR*255.,trace_rclrBR,wgtBR*100.);
01290         printf("  %3.0f %3.0f\n", iopc*255., 
01291                ipixel->rclrflt);
01292         
01293         printf("              ");
01294         printf("      %3.0f    ",trace_rsclrTL);
01295         printf("      %3.0f    ",trace_rsclrBL);
01296         printf("      %3.0f    ",trace_rsclrTR);
01297         printf("      %3.0f    ",trace_rsclrBR);
01298         printf("  %3.0f\n", shadow_pixel->opcflt * 255.);
01299         
01300         printf("              ");
01301         printf("      %3.0f    ",trace_gclrTL);
01302         printf("      %3.0f    ",trace_gclrBL);
01303         printf("      %3.0f    ",trace_gclrTR);
01304         printf("      %3.0f    ",trace_gclrBR);
01305         printf("      %3.0f\n", ipixel->gclrflt);
01306         printf("              ");
01307         printf("      %3.0f    ",trace_bclrTL);
01308         printf("      %3.0f    ",trace_bclrBL);
01309         printf("      %3.0f    ",trace_bclrTR);
01310         printf("      %3.0f    ",trace_bclrBR);
01311         printf("      %3.0f\n", ipixel->bclrflt);
01312     }
01313 #endif /* DEBUG */
01314 ;
01315 #           ifndef SKIP_ERT
01316                 if (iopc >= max_opacity) {
01317                     ASSERT(ipixel->lnk == 0);
01318                     ipixel->lnk = 1;
01319                 }
01320 #           endif
01321         };
01322                 ipixel += count; shadow_pixel += count;
01323                 topRLEdata += count * voxel_istride;
01324                 botRLEdata += count * voxel_istride;
01325                 count = 0;
01326                 break;
01327             case ALL_NONZERO__ALL_ZERO:
01328                 /* the top and bottom left voxels contribute to the
01329                    first pixel of the run, and the rest are zero */
01330                 if (!voxels_loaded) {
01331                     
01332     
01333             opac_param = VoxelField(topRLEdata - voxel_istride, param0_offset, param0_size);
01334             opacity = param0_table[opac_param];
01335             if (param1_size != 0) {
01336                 opac_param = VoxelField(topRLEdata - voxel_istride, param1_offset, param1_size);
01337                 opacity *= param1_table[opac_param];
01338                 if (param2_size != 0) {
01339                     opac_param = VoxelField(topRLEdata - voxel_istride, param2_offset, param2_size);
01340                     opacity *= param2_table[opac_param];
01341                 }
01342             }
01343             if (opacity > min_opacity) {
01344                 opacity_int = opacity*255.;
01345                 top_opc = opac_correct[opacity_int];
01346             } else {
01347                 top_opc = (float)0.;
01348             };
01349     
01350     
01351     shade_index=num_materials*3*ShortField(topRLEdata - voxel_istride,norm_offset);
01352     weight_index = num_materials * ByteField(topRLEdata - voxel_istride, wgt_offset);
01353     
01354         
01355         
01356     top_rclr = 
01357     shade_table[shade_index + 3*0 + 0] * 
01358         ((num_materials > 1) ? weight_table[weight_index] : (float)1.0);
01359         
01360     top_gclr = 
01361     shade_table[shade_index + 3*0 + 1] * 
01362         ((num_materials > 1) ? weight_table[weight_index] : (float)1.0);
01363         
01364     top_bclr = 
01365     shade_table[shade_index + 3*0 + 2] * 
01366         ((num_materials > 1) ? weight_table[weight_index] : (float)1.0);
01367         
01368         top_rsclr = 
01369     shadow_table[shade_index + 3*0 + 0] * 
01370         ((num_materials > 1) ? weight_table[weight_index] : (float)1.0);
01371         
01372         top_gsclr = 
01373     shadow_table[shade_index + 3*0 + 1] * 
01374         ((num_materials > 1) ? weight_table[weight_index] : (float)1.0);
01375         
01376         top_bsclr = 
01377     shadow_table[shade_index + 3*0 + 2] * 
01378         ((num_materials > 1) ? weight_table[weight_index] : (float)1.0);
01379         for (m = 1; m < num_materials; m++) {
01380              
01381         
01382     top_rclr += 
01383     shade_table[shade_index + 3*m + 0] * 
01384         weight_table[weight_index + m];
01385         
01386     top_gclr += 
01387     shade_table[shade_index + 3*m + 1] * 
01388         weight_table[weight_index + m];
01389         
01390     top_bclr += 
01391     shade_table[shade_index + 3*m + 2] * 
01392         weight_table[weight_index + m];
01393         
01394         top_rsclr += 
01395     shadow_table[shade_index + 3*m + 0] * 
01396         weight_table[weight_index + m];
01397         
01398         top_gsclr += 
01399     shadow_table[shade_index + 3*m + 1] * 
01400         weight_table[weight_index + m];
01401         
01402         top_bsclr += 
01403     shadow_table[shade_index + 3*m + 2] * 
01404         weight_table[weight_index + m];
01405         };
01406     shade_factor = top_opc * slice_depth_cueing;
01407     
01408         top_rclr *= shade_factor;
01409         top_gclr *= shade_factor;
01410         top_bclr *= shade_factor;
01411     
01412             top_rsclr *= shade_factor;
01413             top_gsclr *= shade_factor;
01414             top_bsclr *= shade_factor;
01415                     
01416     
01417             opac_param = VoxelField(botRLEdata - voxel_istride, param0_offset, param0_size);
01418             opacity = param0_table[opac_param];
01419             if (param1_size != 0) {
01420                 opac_param = VoxelField(botRLEdata - voxel_istride, param1_offset, param1_size);
01421                 opacity *= param1_table[opac_param];
01422                 if (param2_size != 0) {
01423                     opac_param = VoxelField(botRLEdata - voxel_istride, param2_offset, param2_size);
01424                     opacity *= param2_table[opac_param];
01425                 }
01426             }
01427             if (opacity > min_opacity) {
01428                 opacity_int = opacity*255.;
01429                 bot_opc = opac_correct[opacity_int];
01430             } else {
01431                 bot_opc = (float)0.;
01432             };
01433     
01434     
01435     shade_index=num_materials*3*ShortField(botRLEdata - voxel_istride,norm_offset);
01436     weight_index = num_materials * ByteField(botRLEdata - voxel_istride, wgt_offset);
01437     
01438         
01439         
01440     bot_rclr = 
01441     shade_table[shade_index + 3*0 + 0] * 
01442         ((num_materials > 1) ? weight_table[weight_index] : (float)1.0);
01443         
01444     bot_gclr = 
01445     shade_table[shade_index + 3*0 + 1] * 
01446         ((num_materials > 1) ? weight_table[weight_index] : (float)1.0);
01447         
01448     bot_bclr = 
01449     shade_table[shade_index + 3*0 + 2] * 
01450         ((num_materials > 1) ? weight_table[weight_index] : (float)1.0);
01451         
01452         bot_rsclr = 
01453     shadow_table[shade_index + 3*0 + 0] * 
01454         ((num_materials > 1) ? weight_table[weight_index] : (float)1.0);
01455         
01456         bot_gsclr = 
01457     shadow_table[shade_index + 3*0 + 1] * 
01458         ((num_materials > 1) ? weight_table[weight_index] : (float)1.0);
01459         
01460         bot_bsclr = 
01461     shadow_table[shade_index + 3*0 + 2] * 
01462         ((num_materials > 1) ? weight_table[weight_index] : (float)1.0);
01463         for (m = 1; m < num_materials; m++) {
01464              
01465         
01466     bot_rclr += 
01467     shade_table[shade_index + 3*m + 0] * 
01468         weight_table[weight_index + m];
01469         
01470     bot_gclr += 
01471     shade_table[shade_index + 3*m + 1] * 
01472         weight_table[weight_index + m];
01473         
01474     bot_bclr += 
01475     shade_table[shade_index + 3*m + 2] * 
01476         weight_table[weight_index + m];
01477         
01478         bot_rsclr += 
01479     shadow_table[shade_index + 3*m + 0] * 
01480         weight_table[weight_index + m];
01481         
01482         bot_gsclr += 
01483     shadow_table[shade_index + 3*m + 1] * 
01484         weight_table[weight_index + m];
01485         
01486         bot_bsclr += 
01487     shadow_table[shade_index + 3*m + 2] * 
01488         weight_table[weight_index + m];
01489         };
01490     shade_factor = bot_opc * slice_depth_cueing;
01491     
01492         bot_rclr *= shade_factor;
01493         bot_gclr *= shade_factor;
01494         bot_bclr *= shade_factor;
01495     
01496             bot_rsclr *= shade_factor;
01497             bot_gsclr *= shade_factor;
01498             bot_bsclr *= shade_factor;
01499                 }
01500                 
01501 #ifdef DEBUG
01502     if (ipixel == trace_pixel_ptr) {
01503         trace_opcTL = 0.; trace_opcBL = 0.; trace_opcTR = 0.; trace_opcBR = 0.;
01504         trace_rsclrTL=0.; trace_rsclrBL=0.; trace_rsclrTR=0.; trace_rsclrBR=0.;
01505         trace_rclrTL= 0.; trace_rclrBL= 0.; trace_rclrTR= 0.; trace_rclrBR= 0.;
01506         trace_gclrTL= 0.; trace_gclrBL= 0.; trace_gclrTR= 0.; trace_gclrBR= 0.;
01507         trace_bclrTL= 0.; trace_bclrBL= 0.; trace_bclrTR= 0.; trace_bclrBR= 0.;
01508     }
01509 #endif
01510 ;
01511                 
01512        acc_opc = top_opc * wgtTL;
01513        
01514             acc_rclr = (top_rclr + top_rsclr *
01515                          ((float)1.0 - shadow_pixel->opcflt)) * wgtTL;
01516             acc_gclr = (top_gclr + top_gsclr *
01517                          ((float)1.0 - shadow_pixel->opcflt)) * wgtTL;
01518             acc_bclr = (top_bclr + top_bsclr *
01519                          ((float)1.0 - shadow_pixel->opcflt)) * wgtTL;
01520        
01521 #ifdef DEBUG
01522     if (ipixel == trace_pixel_ptr) {
01523         trace_opcTL = top_opc;
01524         trace_rclrTL = top_rclr;
01525                      trace_gclrTL = top_gclr;
01526                      trace_bclrTL = top_bclr;
01527         
01528     }
01529 #endif
01530 ;
01531                 
01532        acc_opc += bot_opc * wgtBL;
01533        
01534             acc_rclr += (bot_rclr + bot_rsclr *
01535                          ((float)1.0 - shadow_pixel->opcflt)) * wgtBL;
01536             acc_gclr += (bot_gclr + bot_gsclr *
01537                          ((float)1.0 - shadow_pixel->opcflt)) * wgtBL;
01538             acc_bclr += (bot_bclr + bot_bsclr *
01539                          ((float)1.0 - shadow_pixel->opcflt)) * wgtBL;
01540        
01541 #ifdef DEBUG
01542     if (ipixel == trace_pixel_ptr) {
01543         trace_opcBL = bot_opc;
01544         trace_rclrBL = bot_rclr;
01545                      trace_gclrBL = bot_gclr;
01546                      trace_bclrBL = bot_bclr;
01547         
01548     }
01549 #endif
01550 ;
01551                 
01552         COUNT_RESAMPLE;
01553         if (acc_opc > min_opacity) {
01554             COUNT_COMPOSITE;
01555             iopc = ipixel->opcflt;
01556 #           ifndef SKIP_ERT
01557                 ASSERT(iopc < max_opacity);
01558 #           endif
01559             iopc_inv = (float)1. - iopc;
01560             
01561         ipixel->rclrflt += acc_rclr * iopc_inv;
01562         ipixel->gclrflt += acc_gclr * iopc_inv;
01563         ipixel->bclrflt += acc_bclr * iopc_inv;
01564             iopc += acc_opc * iopc_inv;
01565             ipixel->opcflt = iopc;
01566             
01567 #ifdef DEBUG
01568     if (ipixel == trace_pixel_ptr) {
01569 #ifdef COMPUTE_SHADOW_BUFFER
01570         printf("{%3d}  %3d %3d", k, icount-i-count, j);
01571 #else
01572         printf("[%3d]  %3d %3d", k, icount-i-count, j);
01573 #endif
01574         printf("  %3.0f %3.0f %3.0f",trace_opcTL*255.,trace_rclrTL,wgtTL*100.);
01575         printf("  %3.0f %3.0f %3.0f",trace_opcBL*255.,trace_rclrBL,wgtBL*100.);
01576         printf("  %3.0f %3.0f %3.0f",trace_opcTR*255.,trace_rclrTR,wgtTR*100.);
01577         printf("  %3.0f %3.0f %3.0f",trace_opcBR*255.,trace_rclrBR,wgtBR*100.);
01578         printf("  %3.0f %3.0f\n", iopc*255., 
01579                ipixel->rclrflt);
01580         
01581         printf("              ");
01582         printf("      %3.0f    ",trace_rsclrTL);
01583         printf("      %3.0f    ",trace_rsclrBL);
01584         printf("      %3.0f    ",trace_rsclrTR);
01585         printf("      %3.0f    ",trace_rsclrBR);
01586         printf("  %3.0f\n", shadow_pixel->opcflt * 255.);
01587         
01588         printf("              ");
01589         printf("      %3.0f    ",trace_gclrTL);
01590         printf("      %3.0f    ",trace_gclrBL);
01591         printf("      %3.0f    ",trace_gclrTR);
01592         printf("      %3.0f    ",trace_gclrBR);
01593         printf("      %3.0f\n", ipixel->gclrflt);
01594         printf("              ");
01595         printf("      %3.0f    ",trace_bclrTL);
01596         printf("      %3.0f    ",trace_bclrBL);
01597         printf("      %3.0f    ",trace_bclrTR);
01598         printf("      %3.0f    ",trace_bclrBR);
01599         printf("      %3.0f\n", ipixel->bclrflt);
01600     }
01601 #endif /* DEBUG */
01602 ;
01603 #           ifndef SKIP_ERT
01604                 if (iopc >= max_opacity) {
01605                     ASSERT(ipixel->lnk == 0);
01606                     ipixel->lnk = 1;
01607                 }
01608 #           endif
01609         };
01610                 ipixel += count; shadow_pixel += count;
01611                 topRLEdata += count * voxel_istride;
01612                 botRLEdata += count * voxel_istride;
01613                 count = 0;
01614                 break;
01615             case ALL_ZERO__TOP_NONZERO:
01616                 /* first pixel: only the top-right voxel contributes */
01617                 
01618     
01619             opac_param = VoxelField(topRLEdata, param0_offset, param0_size);
01620             opacity = param0_table[opac_param];
01621             if (param1_size != 0) {
01622                 opac_param = VoxelField(topRLEdata, param1_offset, param1_size);
01623                 opacity *= param1_table[opac_param];
01624                 if (param2_size != 0) {
01625                     opac_param = VoxelField(topRLEdata, param2_offset, param2_size);
01626                     opacity *= param2_table[opac_param];
01627                 }
01628             }
01629             if (opacity > min_opacity) {
01630                 opacity_int = opacity*255.;
01631                 top_opc = opac_correct[opacity_int];
01632             } else {
01633                 top_opc = (float)0.;
01634             };
01635     
01636     
01637     shade_index=num_materials*3*ShortField(topRLEdata,norm_offset);
01638     weight_index = num_materials * ByteField(topRLEdata, wgt_offset);
01639     
01640         
01641         
01642     top_rclr = 
01643     shade_table[shade_index + 3*0 + 0] * 
01644         ((num_materials > 1) ? weight_table[weight_index] : (float)1.0);
01645         
01646     top_gclr = 
01647     shade_table[shade_index + 3*0 + 1] * 
01648         ((num_materials > 1) ? weight_table[weight_index] : (float)1.0);
01649         
01650     top_bclr = 
01651     shade_table[shade_index + 3*0 + 2] * 
01652         ((num_materials > 1) ? weight_table[weight_index] : (float)1.0);
01653         
01654         top_rsclr = 
01655     shadow_table[shade_index + 3*0 + 0] * 
01656         ((num_materials > 1) ? weight_table[weight_index] : (float)1.0);
01657         
01658         top_gsclr = 
01659     shadow_table[shade_index + 3*0 + 1] * 
01660         ((num_materials > 1) ? weight_table[weight_index] : (float)1.0);
01661         
01662         top_bsclr = 
01663     shadow_table[shade_index + 3*0 + 2] * 
01664         ((num_materials > 1) ? weight_table[weight_index] : (float)1.0);
01665         for (m = 1; m < num_materials; m++) {
01666              
01667         
01668     top_rclr += 
01669     shade_table[shade_index + 3*m + 0] * 
01670         weight_table[weight_index + m];
01671         
01672     top_gclr += 
01673     shade_table[shade_index + 3*m + 1] * 
01674         weight_table[weight_index + m];
01675         
01676     top_bclr += 
01677     shade_table[shade_index + 3*m + 2] * 
01678         weight_table[weight_index + m];
01679         
01680         top_rsclr += 
01681     shadow_table[shade_index + 3*m + 0] * 
01682         weight_table[weight_index + m];
01683         
01684         top_gsclr += 
01685     shadow_table[shade_index + 3*m + 1] * 
01686         weight_table[weight_index + m];
01687         
01688         top_bsclr += 
01689     shadow_table[shade_index + 3*m + 2] * 
01690         weight_table[weight_index + m];
01691         };
01692     shade_factor = top_opc * slice_depth_cueing;
01693     
01694         top_rclr *= shade_factor;
01695         top_gclr *= shade_factor;
01696         top_bclr *= shade_factor;
01697     
01698             top_rsclr *= shade_factor;
01699             top_gsclr *= shade_factor;
01700             top_bsclr *= shade_factor;
01701                 
01702 #ifdef DEBUG
01703     if (ipixel == trace_pixel_ptr) {
01704         trace_opcTL = 0.; trace_opcBL = 0.; trace_opcTR = 0.; trace_opcBR = 0.;
01705         trace_rsclrTL=0.; trace_rsclrBL=0.; trace_rsclrTR=0.; trace_rsclrBR=0.;
01706         trace_rclrTL= 0.; trace_rclrBL= 0.; trace_rclrTR= 0.; trace_rclrBR= 0.;
01707         trace_gclrTL= 0.; trace_gclrBL= 0.; trace_gclrTR= 0.; trace_gclrBR= 0.;
01708         trace_bclrTL= 0.; trace_bclrBL= 0.; trace_bclrTR= 0.; trace_bclrBR= 0.;
01709     }
01710 #endif
01711 ;
01712                 
01713        acc_opc = top_opc * wgtTR;
01714        
01715             acc_rclr = (top_rclr + top_rsclr *
01716                          ((float)1.0 - shadow_pixel->opcflt)) * wgtTR;
01717             acc_gclr = (top_gclr + top_gsclr *
01718                          ((float)1.0 - shadow_pixel->opcflt)) * wgtTR;
01719             acc_bclr = (top_bclr + top_bsclr *
01720                          ((float)1.0 - shadow_pixel->opcflt)) * wgtTR;
01721        
01722 #ifdef DEBUG
01723     if (ipixel == trace_pixel_ptr) {
01724         trace_opcTR = top_opc;
01725         trace_rclrTR = top_rclr;
01726                      trace_gclrTR = top_gclr;
01727                      trace_bclrTR = top_bclr;
01728         
01729     }
01730 #endif
01731 ;
01732                 
01733         COUNT_RESAMPLE;
01734         if (acc_opc > min_opacity) {
01735             COUNT_COMPOSITE;
01736             iopc = ipixel->opcflt;
01737 #           ifndef SKIP_ERT
01738                 ASSERT(iopc < max_opacity);
01739 #           endif
01740             iopc_inv = (float)1. - iopc;
01741             
01742         ipixel->rclrflt += acc_rclr * iopc_inv;
01743         ipixel->gclrflt += acc_gclr * iopc_inv;
01744         ipixel->bclrflt += acc_bclr * iopc_inv;
01745             iopc += acc_opc * iopc_inv;
01746             ipixel->opcflt = iopc;
01747             
01748 #ifdef DEBUG
01749     if (ipixel == trace_pixel_ptr) {
01750 #ifdef COMPUTE_SHADOW_BUFFER
01751         printf("{%3d}  %3d %3d", k, icount-i-count, j);
01752 #else
01753         printf("[%3d]  %3d %3d", k, icount-i-count, j);
01754 #endif
01755         printf("  %3.0f %3.0f %3.0f",trace_opcTL*255.,trace_rclrTL,wgtTL*100.);
01756         printf("  %3.0f %3.0f %3.0f",trace_opcBL*255.,trace_rclrBL,wgtBL*100.);
01757         printf("  %3.0f %3.0f %3.0f",trace_opcTR*255.,trace_rclrTR,wgtTR*100.);
01758         printf("  %3.0f %3.0f %3.0f",trace_opcBR*255.,trace_rclrBR,wgtBR*100.);
01759         printf("  %3.0f %3.0f\n", iopc*255., 
01760                ipixel->rclrflt);
01761         
01762         printf("              ");
01763         printf("      %3.0f    ",trace_rsclrTL);
01764         printf("      %3.0f    ",trace_rsclrBL);
01765         printf("      %3.0f    ",trace_rsclrTR);
01766         printf("      %3.0f    ",trace_rsclrBR);
01767         printf("  %3.0f\n", shadow_pixel->opcflt * 255.);
01768         
01769         printf("              ");
01770         printf("      %3.0f    ",trace_gclrTL);
01771         printf("      %3.0f    ",trace_gclrBL);
01772         printf("      %3.0f    ",trace_gclrTR);
01773         printf("      %3.0f    ",trace_gclrBR);
01774         printf("      %3.0f\n", ipixel->gclrflt);
01775         printf("              ");
01776         printf("      %3.0f    ",trace_bclrTL);
01777         printf("      %3.0f    ",trace_bclrBL);
01778         printf("      %3.0f    ",trace_bclrTR);
01779         printf("      %3.0f    ",trace_bclrBR);
01780         printf("      %3.0f\n", ipixel->bclrflt);
01781     }
01782 #endif /* DEBUG */
01783 ;
01784 #           ifndef SKIP_ERT
01785                 if (iopc >= max_opacity) {
01786                     ASSERT(ipixel->lnk == 0);
01787                     ipixel->lnk = 1;
01788                 }
01789 #           endif
01790         };
01791                 ipixel += 1; shadow_pixel += 1;
01792                 topRLEdata += 1 * voxel_istride;
01793                 botRLEdata += 1 * voxel_istride;
01794                 count--;
01795                 SET_VOXELS_LOADED;
01796 
01797                 /* do the rest of the pixels in this run;
01798                    the top-left and top-right voxels contribute */
01799                 while (count > 0) {
01800                     if (PIXEL_IS_OPAQUE(ipixel))
01801                         break;
01802                     if (!voxels_loaded) {
01803                         
01804     
01805             opac_param = VoxelField(topRLEdata - voxel_istride, param0_offset, param0_size);
01806             opacity = param0_table[opac_param];
01807             if (param1_size != 0) {
01808                 opac_param = VoxelField(topRLEdata - voxel_istride, param1_offset, param1_size);
01809                 opacity *= param1_table[opac_param];
01810                 if (param2_size != 0) {
01811                     opac_param = VoxelField(topRLEdata - voxel_istride, param2_offset, param2_size);
01812                     opacity *= param2_table[opac_param];
01813                 }
01814             }
01815             if (opacity > min_opacity) {
01816                 opacity_int = opacity*255.;
01817                 top_opc = opac_correct[opacity_int];
01818             } else {
01819                 top_opc = (float)0.;
01820             };
01821     
01822     
01823     shade_index=num_materials*3*ShortField(topRLEdata - voxel_istride,norm_offset);
01824     weight_index = num_materials * ByteField(topRLEdata - voxel_istride, wgt_offset);
01825     
01826         
01827         
01828     top_rclr = 
01829     shade_table[shade_index + 3*0 + 0] * 
01830         ((num_materials > 1) ? weight_table[weight_index] : (float)1.0);
01831         
01832     top_gclr = 
01833     shade_table[shade_index + 3*0 + 1] * 
01834         ((num_materials > 1) ? weight_table[weight_index] : (float)1.0);
01835         
01836     top_bclr = 
01837     shade_table[shade_index + 3*0 + 2] * 
01838         ((num_materials > 1) ? weight_table[weight_index] : (float)1.0);
01839         
01840         top_rsclr = 
01841     shadow_table[shade_index + 3*0 + 0] * 
01842         ((num_materials > 1) ? weight_table[weight_index] : (float)1.0);
01843         
01844         top_gsclr = 
01845     shadow_table[shade_index + 3*0 + 1] * 
01846         ((num_materials > 1) ? weight_table[weight_index] : (float)1.0);
01847         
01848         top_bsclr = 
01849     shadow_table[shade_index + 3*0 + 2] * 
01850         ((num_materials > 1) ? weight_table[weight_index] : (float)1.0);
01851         for (m = 1; m < num_materials; m++) {
01852              
01853         
01854     top_rclr += 
01855     shade_table[shade_index + 3*m + 0] * 
01856         weight_table[weight_index + m];
01857         
01858     top_gclr += 
01859     shade_table[shade_index + 3*m + 1] * 
01860         weight_table[weight_index + m];
01861         
01862     top_bclr += 
01863     shade_table[shade_index + 3*m + 2] * 
01864         weight_table[weight_index + m];
01865         
01866         top_rsclr += 
01867     shadow_table[shade_index + 3*m + 0] * 
01868         weight_table[weight_index + m];
01869         
01870         top_gsclr += 
01871     shadow_table[shade_index + 3*m + 1] * 
01872         weight_table[weight_index + m];
01873         
01874         top_bsclr += 
01875     shadow_table[shade_index + 3*m + 2] * 
01876         weight_table[weight_index + m];
01877         };
01878     shade_factor = top_opc * slice_depth_cueing;
01879     
01880         top_rclr *= shade_factor;
01881         top_gclr *= shade_factor;
01882         top_bclr *= shade_factor;
01883     
01884             top_rsclr *= shade_factor;
01885             top_gsclr *= shade_factor;
01886             top_bsclr *= shade_factor;
01887                     }
01888                     
01889 #ifdef DEBUG
01890     if (ipixel == trace_pixel_ptr) {
01891         trace_opcTL = 0.; trace_opcBL = 0.; trace_opcTR = 0.; trace_opcBR = 0.;
01892         trace_rsclrTL=0.; trace_rsclrBL=0.; trace_rsclrTR=0.; trace_rsclrBR=0.;
01893         trace_rclrTL= 0.; trace_rclrBL= 0.; trace_rclrTR= 0.; trace_rclrBR= 0.;
01894         trace_gclrTL= 0.; trace_gclrBL= 0.; trace_gclrTR= 0.; trace_gclrBR= 0.;
01895         trace_bclrTL= 0.; trace_bclrBL= 0.; trace_bclrTR= 0.; trace_bclrBR= 0.;
01896     }
01897 #endif
01898 ;
01899                     
01900        acc_opc = top_opc * wgtTL;
01901        
01902             acc_rclr = (top_rclr + top_rsclr *
01903                          ((float)1.0 - shadow_pixel->opcflt)) * wgtTL;
01904             acc_gclr = (top_gclr + top_gsclr *
01905                          ((float)1.0 - shadow_pixel->opcflt)) * wgtTL;
01906             acc_bclr = (top_bclr + top_bsclr *
01907                          ((float)1.0 - shadow_pixel->opcflt)) * wgtTL;
01908        
01909 #ifdef DEBUG
01910     if (ipixel == trace_pixel_ptr) {
01911         trace_opcTL = top_opc;
01912         trace_rclrTL = top_rclr;
01913                      trace_gclrTL = top_gclr;
01914                      trace_bclrTL = top_bclr;
01915         
01916     }
01917 #endif
01918 ;
01919                     
01920     
01921             opac_param = VoxelField(topRLEdata, param0_offset, param0_size);
01922             opacity = param0_table[opac_param];
01923             if (param1_size != 0) {
01924                 opac_param = VoxelField(topRLEdata, param1_offset, param1_size);
01925                 opacity *= param1_table[opac_param];
01926                 if (param2_size != 0) {
01927                     opac_param = VoxelField(topRLEdata, param2_offset, param2_size);
01928                     opacity *= param2_table[opac_param];
01929                 }
01930             }
01931             if (opacity > min_opacity) {
01932                 opacity_int = opacity*255.;
01933                 top_opc = opac_correct[opacity_int];
01934             } else {
01935                 top_opc = (float)0.;
01936             };
01937     
01938     
01939     shade_index=num_materials*3*ShortField(topRLEdata,norm_offset);
01940     weight_index = num_materials * ByteField(topRLEdata, wgt_offset);
01941     
01942         
01943         
01944     top_rclr = 
01945     shade_table[shade_index + 3*0 + 0] * 
01946         ((num_materials > 1) ? weight_table[weight_index] : (float)1.0);
01947         
01948     top_gclr = 
01949     shade_table[shade_index + 3*0 + 1] * 
01950         ((num_materials > 1) ? weight_table[weight_index] : (float)1.0);
01951         
01952     top_bclr = 
01953     shade_table[shade_index + 3*0 + 2] * 
01954         ((num_materials > 1) ? weight_table[weight_index] : (float)1.0);
01955         
01956         top_rsclr = 
01957     shadow_table[shade_index + 3*0 + 0] * 
01958         ((num_materials > 1) ? weight_table[weight_index] : (float)1.0);
01959         
01960         top_gsclr = 
01961     shadow_table[shade_index + 3*0 + 1] * 
01962         ((num_materials > 1) ? weight_table[weight_index] : (float)1.0);
01963         
01964         top_bsclr = 
01965     shadow_table[shade_index + 3*0 + 2] * 
01966         ((num_materials > 1) ? weight_table[weight_index] : (float)1.0);
01967         for (m = 1; m < num_materials; m++) {
01968              
01969         
01970     top_rclr += 
01971     shade_table[shade_index + 3*m + 0] * 
01972         weight_table[weight_index + m];
01973         
01974     top_gclr += 
01975     shade_table[shade_index + 3*m + 1] * 
01976         weight_table[weight_index + m];
01977         
01978     top_bclr += 
01979     shade_table[shade_index + 3*m + 2] * 
01980         weight_table[weight_index + m];
01981         
01982         top_rsclr += 
01983     shadow_table[shade_index + 3*m + 0] * 
01984         weight_table[weight_index + m];
01985         
01986         top_gsclr += 
01987     shadow_table[shade_index + 3*m + 1] * 
01988         weight_table[weight_index + m];
01989         
01990         top_bsclr += 
01991     shadow_table[shade_index + 3*m + 2] * 
01992         weight_table[weight_index + m];
01993         };
01994     shade_factor = top_opc * slice_depth_cueing;
01995     
01996         top_rclr *= shade_factor;
01997         top_gclr *= shade_factor;
01998         top_bclr *= shade_factor;
01999     
02000             top_rsclr *= shade_factor;
02001             top_gsclr *= shade_factor;
02002             top_bsclr *= shade_factor;
02003                     
02004        acc_opc += top_opc * wgtTR;
02005        
02006             acc_rclr += (top_rclr + top_rsclr *
02007                          ((float)1.0 - shadow_pixel->opcflt)) * wgtTR;
02008             acc_gclr += (top_gclr + top_gsclr *
02009                          ((float)1.0 - shadow_pixel->opcflt)) * wgtTR;
02010             acc_bclr += (top_bclr + top_bsclr *
02011                          ((float)1.0 - shadow_pixel->opcflt)) * wgtTR;
02012        
02013 #ifdef DEBUG
02014     if (ipixel == trace_pixel_ptr) {
02015         trace_opcTR = top_opc;
02016         trace_rclrTR = top_rclr;
02017                      trace_gclrTR = top_gclr;
02018                      trace_bclrTR = top_bclr;
02019         
02020     }
02021 #endif
02022 ;
02023                     
02024         COUNT_RESAMPLE;
02025         if (acc_opc > min_opacity) {
02026             COUNT_COMPOSITE;
02027             iopc = ipixel->opcflt;
02028 #           ifndef SKIP_ERT
02029                 ASSERT(iopc < max_opacity);
02030 #           endif
02031             iopc_inv = (float)1. - iopc;
02032             
02033         ipixel->rclrflt += acc_rclr * iopc_inv;
02034         ipixel->gclrflt += acc_gclr * iopc_inv;
02035         ipixel->bclrflt += acc_bclr * iopc_inv;
02036             iopc += acc_opc * iopc_inv;
02037             ipixel->opcflt = iopc;
02038             
02039 #ifdef DEBUG
02040     if (ipixel == trace_pixel_ptr) {
02041 #ifdef COMPUTE_SHADOW_BUFFER
02042         printf("{%3d}  %3d %3d", k, icount-i-count, j);
02043 #else
02044         printf("[%3d]  %3d %3d", k, icount-i-count, j);
02045 #endif
02046         printf("  %3.0f %3.0f %3.0f",trace_opcTL*255.,trace_rclrTL,wgtTL*100.);
02047         printf("  %3.0f %3.0f %3.0f",trace_opcBL*255.,trace_rclrBL,wgtBL*100.);
02048         printf("  %3.0f %3.0f %3.0f",trace_opcTR*255.,trace_rclrTR,wgtTR*100.);
02049         printf("  %3.0f %3.0f %3.0f",trace_opcBR*255.,trace_rclrBR,wgtBR*100.);
02050         printf("  %3.0f %3.0f\n", iopc*255., 
02051                ipixel->rclrflt);
02052         
02053         printf("              ");
02054         printf("      %3.0f    ",trace_rsclrTL);
02055         printf("      %3.0f    ",trace_rsclrBL);
02056         printf("      %3.0f    ",trace_rsclrTR);
02057         printf("      %3.0f    ",trace_rsclrBR);
02058         printf("  %3.0f\n", shadow_pixel->opcflt * 255.);
02059         
02060         printf("              ");
02061         printf("      %3.0f    ",trace_gclrTL);
02062         printf("      %3.0f    ",trace_gclrBL);
02063         printf("      %3.0f    ",trace_gclrTR);
02064         printf("      %3.0f    ",trace_gclrBR);
02065         printf("      %3.0f\n", ipixel->gclrflt);
02066         printf("              ");
02067         printf("      %3.0f    ",trace_bclrTL);
02068         printf("      %3.0f    ",trace_bclrBL);
02069         printf("      %3.0f    ",trace_bclrTR);
02070         printf("      %3.0f    ",trace_bclrBR);
02071         printf("      %3.0f\n", ipixel->bclrflt);
02072     }
02073 #endif /* DEBUG */
02074 ;
02075 #           ifndef SKIP_ERT
02076                 if (iopc >= max_opacity) {
02077                     ASSERT(ipixel->lnk == 0);
02078                     ipixel->lnk = 1;
02079                 }
02080 #           endif
02081         };
02082                     ipixel += 1; shadow_pixel += 1;
02083                     topRLEdata += 1 * voxel_istride;
02084                     botRLEdata += 1 * voxel_istride;
02085                     count--;
02086                     SET_VOXELS_LOADED;
02087                 }
02088                 break;
02089             case TOP_NONZERO__TOP_NONZERO:
02090                 /* do the pixels in this run; the top-left and
02091                    top-right voxels contribute */
02092                 while (count > 0) {
02093                     if (PIXEL_IS_OPAQUE(ipixel))
02094                         break;
02095                     if (!voxels_loaded) {
02096                         
02097     
02098             opac_param = VoxelField(topRLEdata - voxel_istride, param0_offset, param0_size);
02099             opacity = param0_table[opac_param];
02100             if (param1_size != 0) {
02101                 opac_param = VoxelField(topRLEdata - voxel_istride, param1_offset, param1_size);
02102                 opacity *= param1_table[opac_param];
02103                 if (param2_size != 0) {
02104                     opac_param = VoxelField(topRLEdata - voxel_istride, param2_offset, param2_size);
02105                     opacity *= param2_table[opac_param];
02106                 }
02107             }
02108             if (opacity > min_opacity) {
02109                 opacity_int = opacity*255.;
02110                 top_opc = opac_correct[opacity_int];
02111             } else {
02112                 top_opc = (float)0.;
02113             };
02114     
02115     
02116     shade_index=num_materials*3*ShortField(topRLEdata - voxel_istride,norm_offset);
02117     weight_index = num_materials * ByteField(topRLEdata - voxel_istride, wgt_offset);
02118     
02119         
02120         
02121     top_rclr = 
02122     shade_table[shade_index + 3*0 + 0] * 
02123         ((num_materials > 1) ? weight_table[weight_index] : (float)1.0);
02124         
02125     top_gclr = 
02126     shade_table[shade_index + 3*0 + 1] * 
02127         ((num_materials > 1) ? weight_table[weight_index] : (float)1.0);
02128         
02129     top_bclr = 
02130     shade_table[shade_index + 3*0 + 2] * 
02131         ((num_materials > 1) ? weight_table[weight_index] : (float)1.0);
02132         
02133         top_rsclr = 
02134     shadow_table[shade_index + 3*0 + 0] * 
02135         ((num_materials > 1) ? weight_table[weight_index] : (float)1.0);
02136         
02137         top_gsclr = 
02138     shadow_table[shade_index + 3*0 + 1] * 
02139         ((num_materials > 1) ? weight_table[weight_index] : (float)1.0);
02140         
02141         top_bsclr = 
02142     shadow_table[shade_index + 3*0 + 2] * 
02143         ((num_materials > 1) ? weight_table[weight_index] : (float)1.0);
02144         for (m = 1; m < num_materials; m++) {
02145              
02146         
02147     top_rclr += 
02148     shade_table[shade_index + 3*m + 0] * 
02149         weight_table[weight_index + m];
02150         
02151     top_gclr += 
02152     shade_table[shade_index + 3*m + 1] * 
02153         weight_table[weight_index + m];
02154         
02155     top_bclr += 
02156     shade_table[shade_index + 3*m + 2] * 
02157         weight_table[weight_index + m];
02158         
02159         top_rsclr += 
02160     shadow_table[shade_index + 3*m + 0] * 
02161         weight_table[weight_index + m];
02162         
02163         top_gsclr += 
02164     shadow_table[shade_index + 3*m + 1] * 
02165         weight_table[weight_index + m];
02166         
02167         top_bsclr += 
02168     shadow_table[shade_index + 3*m + 2] * 
02169         weight_table[weight_index + m];
02170         };
02171     shade_factor = top_opc * slice_depth_cueing;
02172     
02173         top_rclr *= shade_factor;
02174         top_gclr *= shade_factor;
02175         top_bclr *= shade_factor;
02176     
02177             top_rsclr *= shade_factor;
02178             top_gsclr *= shade_factor;
02179             top_bsclr *= shade_factor;
02180                     }
02181                     
02182 #ifdef DEBUG
02183     if (ipixel == trace_pixel_ptr) {
02184         trace_opcTL = 0.; trace_opcBL = 0.; trace_opcTR = 0.; trace_opcBR = 0.;
02185         trace_rsclrTL=0.; trace_rsclrBL=0.; trace_rsclrTR=0.; trace_rsclrBR=0.;
02186         trace_rclrTL= 0.; trace_rclrBL= 0.; trace_rclrTR= 0.; trace_rclrBR= 0.;
02187         trace_gclrTL= 0.; trace_gclrBL= 0.; trace_gclrTR= 0.; trace_gclrBR= 0.;
02188         trace_bclrTL= 0.; trace_bclrBL= 0.; trace_bclrTR= 0.; trace_bclrBR= 0.;
02189     }
02190 #endif
02191 ;
02192                     
02193        acc_opc = top_opc * wgtTL;
02194        
02195             acc_rclr = (top_rclr + top_rsclr *
02196                          ((float)1.0 - shadow_pixel->opcflt)) * wgtTL;
02197             acc_gclr = (top_gclr + top_gsclr *
02198                          ((float)1.0 - shadow_pixel->opcflt)) * wgtTL;
02199             acc_bclr = (top_bclr + top_bsclr *
02200                          ((float)1.0 - shadow_pixel->opcflt)) * wgtTL;
02201        
02202 #ifdef DEBUG
02203     if (ipixel == trace_pixel_ptr) {
02204         trace_opcTL = top_opc;
02205         trace_rclrTL = top_rclr;
02206                      trace_gclrTL = top_gclr;
02207                      trace_bclrTL = top_bclr;
02208         
02209     }
02210 #endif
02211 ;
02212                     
02213     
02214             opac_param = VoxelField(topRLEdata, param0_offset, param0_size);
02215             opacity = param0_table[opac_param];
02216             if (param1_size != 0) {
02217                 opac_param = VoxelField(topRLEdata, param1_offset, param1_size);
02218                 opacity *= param1_table[opac_param];
02219                 if (param2_size != 0) {
02220                     opac_param = VoxelField(topRLEdata, param2_offset, param2_size);
02221                     opacity *= param2_table[opac_param];
02222                 }
02223             }
02224             if (opacity > min_opacity) {
02225                 opacity_int = opacity*255.;
02226                 top_opc = opac_correct[opacity_int];
02227             } else {
02228                 top_opc = (float)0.;
02229             };
02230     
02231     
02232     shade_index=num_materials*3*ShortField(topRLEdata,norm_offset);
02233     weight_index = num_materials * ByteField(topRLEdata, wgt_offset);
02234     
02235         
02236         
02237     top_rclr = 
02238     shade_table[shade_index + 3*0 + 0] * 
02239         ((num_materials > 1) ? weight_table[weight_index] : (float)1.0);
02240         
02241     top_gclr = 
02242     shade_table[shade_index + 3*0 + 1] * 
02243         ((num_materials > 1) ? weight_table[weight_index] : (float)1.0);
02244         
02245     top_bclr = 
02246     shade_table[shade_index + 3*0 + 2] * 
02247         ((num_materials > 1) ? weight_table[weight_index] : (float)1.0);
02248         
02249         top_rsclr = 
02250     shadow_table[shade_index + 3*0 + 0] * 
02251         ((num_materials > 1) ? weight_table[weight_index] : (float)1.0);
02252         
02253         top_gsclr = 
02254     shadow_table[shade_index + 3*0 + 1] * 
02255         ((num_materials > 1) ? weight_table[weight_index] : (float)1.0);
02256         
02257         top_bsclr = 
02258     shadow_table[shade_index + 3*0 + 2] * 
02259         ((num_materials > 1) ? weight_table[weight_index] : (float)1.0);
02260         for (m = 1; m < num_materials; m++) {
02261              
02262         
02263     top_rclr += 
02264     shade_table[shade_index + 3*m + 0] * 
02265         weight_table[weight_index + m];
02266         
02267     top_gclr += 
02268     shade_table[shade_index + 3*m + 1] * 
02269         weight_table[weight_index + m];
02270         
02271     top_bclr += 
02272     shade_table[shade_index + 3*m + 2] * 
02273         weight_table[weight_index + m];
02274         
02275         top_rsclr += 
02276     shadow_table[shade_index + 3*m + 0] * 
02277         weight_table[weight_index + m];
02278         
02279         top_gsclr += 
02280     shadow_table[shade_index + 3*m + 1] * 
02281         weight_table[weight_index + m];
02282         
02283         top_bsclr += 
02284     shadow_table[shade_index + 3*m + 2] * 
02285         weight_table[weight_index + m];
02286         };
02287     shade_factor = top_opc * slice_depth_cueing;
02288     
02289         top_rclr *= shade_factor;
02290         top_gclr *= shade_factor;
02291         top_bclr *= shade_factor;
02292     
02293             top_rsclr *= shade_factor;
02294             top_gsclr *= shade_factor;
02295             top_bsclr *= shade_factor;
02296                     
02297        acc_opc += top_opc * wgtTR;
02298        
02299             acc_rclr += (top_rclr + top_rsclr *
02300                          ((float)1.0 - shadow_pixel->opcflt)) * wgtTR;
02301             acc_gclr += (top_gclr + top_gsclr *
02302                          ((float)1.0 - shadow_pixel->opcflt)) * wgtTR;
02303             acc_bclr += (top_bclr + top_bsclr *
02304                          ((float)1.0 - shadow_pixel->opcflt)) * wgtTR;
02305        
02306 #ifdef DEBUG
02307     if (ipixel == trace_pixel_ptr) {
02308         trace_opcTR = top_opc;
02309         trace_rclrTR = top_rclr;
02310                      trace_gclrTR = top_gclr;
02311                      trace_bclrTR = top_bclr;
02312         
02313     }
02314 #endif
02315 ;
02316                     
02317         COUNT_RESAMPLE;
02318         if (acc_opc > min_opacity) {
02319             COUNT_COMPOSITE;
02320             iopc = ipixel->opcflt;
02321 #           ifndef SKIP_ERT
02322                 ASSERT(iopc < max_opacity);
02323 #           endif
02324             iopc_inv = (float)1. - iopc;
02325             
02326         ipixel->rclrflt += acc_rclr * iopc_inv;
02327         ipixel->gclrflt += acc_gclr * iopc_inv;
02328         ipixel->bclrflt += acc_bclr * iopc_inv;
02329             iopc += acc_opc * iopc_inv;
02330             ipixel->opcflt = iopc;
02331             
02332 #ifdef DEBUG
02333     if (ipixel == trace_pixel_ptr) {
02334 #ifdef COMPUTE_SHADOW_BUFFER
02335         printf("{%3d}  %3d %3d", k, icount-i-count, j);
02336 #else
02337         printf("[%3d]  %3d %3d", k, icount-i-count, j);
02338 #endif
02339         printf("  %3.0f %3.0f %3.0f",trace_opcTL*255.,trace_rclrTL,wgtTL*100.);
02340         printf("  %3.0f %3.0f %3.0f",trace_opcBL*255.,trace_rclrBL,wgtBL*100.);
02341         printf("  %3.0f %3.0f %3.0f",trace_opcTR*255.,trace_rclrTR,wgtTR*100.);
02342         printf("  %3.0f %3.0f %3.0f",trace_opcBR*255.,trace_rclrBR,wgtBR*100.);
02343         printf("  %3.0f %3.0f\n", iopc*255., 
02344                ipixel->rclrflt);
02345         
02346         printf("              ");
02347         printf("      %3.0f    ",trace_rsclrTL);
02348         printf("      %3.0f    ",trace_rsclrBL);
02349         printf("      %3.0f    ",trace_rsclrTR);
02350         printf("      %3.0f    ",trace_rsclrBR);
02351         printf("  %3.0f\n", shadow_pixel->opcflt * 255.);
02352         
02353         printf("              ");
02354         printf("      %3.0f    ",trace_gclrTL);
02355         printf("      %3.0f    ",trace_gclrBL);
02356         printf("      %3.0f    ",trace_gclrTR);
02357         printf("      %3.0f    ",trace_gclrBR);
02358         printf("      %3.0f\n", ipixel->gclrflt);
02359         printf("              ");
02360         printf("      %3.0f    ",trace_bclrTL);
02361         printf("      %3.0f    ",trace_bclrBL);
02362         printf("      %3.0f    ",trace_bclrTR);
02363         printf("      %3.0f    ",trace_bclrBR);
02364         printf("      %3.0f\n", ipixel->bclrflt);
02365     }
02366 #endif /* DEBUG */
02367 ;
02368 #           ifndef SKIP_ERT
02369                 if (iopc >= max_opacity) {
02370                     ASSERT(ipixel->lnk == 0);
02371                     ipixel->lnk = 1;
02372                 }
02373 #           endif
02374         };
02375                     ipixel += 1; shadow_pixel += 1;
02376                     topRLEdata += 1 * voxel_istride;
02377                     botRLEdata += 1 * voxel_istride;
02378                     count--;
02379                     SET_VOXELS_LOADED;
02380                 }
02381                 break;
02382             case BOT_NONZERO__TOP_NONZERO:
02383                 /* first pixel: bottom-left and top-right voxels
02384                    contribute */
02385                 if (!voxels_loaded) {
02386                     
02387     
02388             opac_param = VoxelField(botRLEdata - voxel_istride, param0_offset, param0_size);
02389             opacity = param0_table[opac_param];
02390             if (param1_size != 0) {
02391                 opac_param = VoxelField(botRLEdata - voxel_istride, param1_offset, param1_size);
02392                 opacity *= param1_table[opac_param];
02393                 if (param2_size != 0) {
02394                     opac_param = VoxelField(botRLEdata - voxel_istride, param2_offset, param2_size);
02395                     opacity *= param2_table[opac_param];
02396                 }
02397             }
02398             if (opacity > min_opacity) {
02399                 opacity_int = opacity*255.;
02400                 bot_opc = opac_correct[opacity_int];
02401             } else {
02402                 bot_opc = (float)0.;
02403             };
02404     
02405     
02406     shade_index=num_materials*3*ShortField(botRLEdata - voxel_istride,norm_offset);
02407     weight_index = num_materials * ByteField(botRLEdata - voxel_istride, wgt_offset);
02408     
02409         
02410         
02411     bot_rclr = 
02412     shade_table[shade_index + 3*0 + 0] * 
02413         ((num_materials > 1) ? weight_table[weight_index] : (float)1.0);
02414         
02415     bot_gclr = 
02416     shade_table[shade_index + 3*0 + 1] * 
02417         ((num_materials > 1) ? weight_table[weight_index] : (float)1.0);
02418         
02419     bot_bclr = 
02420     shade_table[shade_index + 3*0 + 2] * 
02421         ((num_materials > 1) ? weight_table[weight_index] : (float)1.0);
02422         
02423         bot_rsclr = 
02424     shadow_table[shade_index + 3*0 + 0] * 
02425         ((num_materials > 1) ? weight_table[weight_index] : (float)1.0);
02426         
02427         bot_gsclr = 
02428     shadow_table[shade_index + 3*0 + 1] * 
02429         ((num_materials > 1) ? weight_table[weight_index] : (float)1.0);
02430         
02431         bot_bsclr = 
02432     shadow_table[shade_index + 3*0 + 2] * 
02433         ((num_materials > 1) ? weight_table[weight_index] : (float)1.0);
02434         for (m = 1; m < num_materials; m++) {
02435              
02436         
02437     bot_rclr += 
02438     shade_table[shade_index + 3*m + 0] * 
02439         weight_table[weight_index + m];
02440         
02441     bot_gclr += 
02442     shade_table[shade_index + 3*m + 1] * 
02443         weight_table[weight_index + m];
02444         
02445     bot_bclr += 
02446     shade_table[shade_index + 3*m + 2] * 
02447         weight_table[weight_index + m];
02448         
02449         bot_rsclr += 
02450     shadow_table[shade_index + 3*m + 0] * 
02451         weight_table[weight_index + m];
02452         
02453         bot_gsclr += 
02454     shadow_table[shade_index + 3*m + 1] * 
02455         weight_table[weight_index + m];
02456         
02457         bot_bsclr += 
02458     shadow_table[shade_index + 3*m + 2] * 
02459         weight_table[weight_index + m];
02460         };
02461     shade_factor = bot_opc * slice_depth_cueing;
02462     
02463         bot_rclr *= shade_factor;
02464         bot_gclr *= shade_factor;
02465         bot_bclr *= shade_factor;
02466     
02467             bot_rsclr *= shade_factor;
02468             bot_gsclr *= shade_factor;
02469             bot_bsclr *= shade_factor;
02470                 }
02471                 
02472 #ifdef DEBUG
02473     if (ipixel == trace_pixel_ptr) {
02474         trace_opcTL = 0.; trace_opcBL = 0.; trace_opcTR = 0.; trace_opcBR = 0.;
02475         trace_rsclrTL=0.; trace_rsclrBL=0.; trace_rsclrTR=0.; trace_rsclrBR=0.;
02476         trace_rclrTL= 0.; trace_rclrBL= 0.; trace_rclrTR= 0.; trace_rclrBR= 0.;
02477         trace_gclrTL= 0.; trace_gclrBL= 0.; trace_gclrTR= 0.; trace_gclrBR= 0.;
02478         trace_bclrTL= 0.; trace_bclrBL= 0.; trace_bclrTR= 0.; trace_bclrBR= 0.;
02479     }
02480 #endif
02481 ;
02482                 
02483        acc_opc = bot_opc * wgtBL;
02484        
02485             acc_rclr = (bot_rclr + bot_rsclr *
02486                          ((float)1.0 - shadow_pixel->opcflt)) * wgtBL;
02487             acc_gclr = (bot_gclr + bot_gsclr *
02488                          ((float)1.0 - shadow_pixel->opcflt)) * wgtBL;
02489             acc_bclr = (bot_bclr + bot_bsclr *
02490                          ((float)1.0 - shadow_pixel->opcflt)) * wgtBL;
02491        
02492 #ifdef DEBUG
02493     if (ipixel == trace_pixel_ptr) {
02494         trace_opcBL = bot_opc;
02495         trace_rclrBL = bot_rclr;
02496                      trace_gclrBL = bot_gclr;
02497                      trace_bclrBL = bot_bclr;
02498         
02499     }
02500 #endif
02501 ;
02502                 
02503     
02504             opac_param = VoxelField(topRLEdata, param0_offset, param0_size);
02505             opacity = param0_table[opac_param];
02506             if (param1_size != 0) {
02507                 opac_param = VoxelField(topRLEdata, param1_offset, param1_size);
02508                 opacity *= param1_table[opac_param];
02509                 if (param2_size != 0) {
02510                     opac_param = VoxelField(topRLEdata, param2_offset, param2_size);
02511                     opacity *= param2_table[opac_param];
02512                 }
02513             }
02514             if (opacity > min_opacity) {
02515                 opacity_int = opacity*255.;
02516                 top_opc = opac_correct[opacity_int];
02517             } else {
02518                 top_opc = (float)0.;
02519             };
02520     
02521     
02522     shade_index=num_materials*3*ShortField(topRLEdata,norm_offset);
02523     weight_index = num_materials * ByteField(topRLEdata, wgt_offset);
02524     
02525         
02526         
02527     top_rclr = 
02528     shade_table[shade_index + 3*0 + 0] * 
02529         ((num_materials > 1) ? weight_table[weight_index] : (float)1.0);
02530         
02531     top_gclr = 
02532     shade_table[shade_index + 3*0 + 1] * 
02533         ((num_materials > 1) ? weight_table[weight_index] : (float)1.0);
02534         
02535     top_bclr = 
02536     shade_table[shade_index + 3*0 + 2] * 
02537         ((num_materials > 1) ? weight_table[weight_index] : (float)1.0);
02538         
02539         top_rsclr = 
02540     shadow_table[shade_index + 3*0 + 0] * 
02541         ((num_materials > 1) ? weight_table[weight_index] : (float)1.0);
02542         
02543         top_gsclr = 
02544     shadow_table[shade_index + 3*0 + 1] * 
02545         ((num_materials > 1) ? weight_table[weight_index] : (float)1.0);
02546         
02547         top_bsclr = 
02548     shadow_table[shade_index + 3*0 + 2] * 
02549         ((num_materials > 1) ? weight_table[weight_index] : (float)1.0);
02550         for (m = 1; m < num_materials; m++) {
02551              
02552         
02553     top_rclr += 
02554     shade_table[shade_index + 3*m + 0] * 
02555         weight_table[weight_index + m];
02556         
02557     top_gclr += 
02558     shade_table[shade_index + 3*m + 1] * 
02559         weight_table[weight_index + m];
02560         
02561     top_bclr += 
02562     shade_table[shade_index + 3*m + 2] * 
02563         weight_table[weight_index + m];
02564         
02565         top_rsclr += 
02566     shadow_table[shade_index + 3*m + 0] * 
02567         weight_table[weight_index + m];
02568         
02569         top_gsclr += 
02570     shadow_table[shade_index + 3*m + 1] * 
02571         weight_table[weight_index + m];
02572         
02573         top_bsclr += 
02574     shadow_table[shade_index + 3*m + 2] * 
02575         weight_table[weight_index + m];
02576         };
02577     shade_factor = top_opc * slice_depth_cueing;
02578     
02579         top_rclr *= shade_factor;
02580         top_gclr *= shade_factor;
02581         top_bclr *= shade_factor;
02582     
02583             top_rsclr *= shade_factor;
02584             top_gsclr *= shade_factor;
02585             top_bsclr *= shade_factor;
02586                 
02587        acc_opc += top_opc * wgtTR;
02588        
02589             acc_rclr += (top_rclr + top_rsclr *
02590                          ((float)1.0 - shadow_pixel->opcflt)) * wgtTR;
02591             acc_gclr += (top_gclr + top_gsclr *
02592                          ((float)1.0 - shadow_pixel->opcflt)) * wgtTR;
02593             acc_bclr += (top_bclr + top_bsclr *
02594                          ((float)1.0 - shadow_pixel->opcflt)) * wgtTR;
02595        
02596 #ifdef DEBUG
02597     if (ipixel == trace_pixel_ptr) {
02598         trace_opcTR = top_opc;
02599         trace_rclrTR = top_rclr;
02600                      trace_gclrTR = top_gclr;
02601                      trace_bclrTR = top_bclr;
02602         
02603     }
02604 #endif
02605 ;
02606                 
02607         COUNT_RESAMPLE;
02608         if (acc_opc > min_opacity) {
02609             COUNT_COMPOSITE;
02610             iopc = ipixel->opcflt;
02611 #           ifndef SKIP_ERT
02612                 ASSERT(iopc < max_opacity);
02613 #           endif
02614             iopc_inv = (float)1. - iopc;
02615             
02616         ipixel->rclrflt += acc_rclr * iopc_inv;
02617         ipixel->gclrflt += acc_gclr * iopc_inv;
02618         ipixel->bclrflt += acc_bclr * iopc_inv;
02619             iopc += acc_opc * iopc_inv;
02620             ipixel->opcflt = iopc;
02621             
02622 #ifdef DEBUG
02623     if (ipixel == trace_pixel_ptr) {
02624 #ifdef COMPUTE_SHADOW_BUFFER
02625         printf("{%3d}  %3d %3d", k, icount-i-count, j);
02626 #else
02627         printf("[%3d]  %3d %3d", k, icount-i-count, j);
02628 #endif
02629         printf("  %3.0f %3.0f %3.0f",trace_opcTL*255.,trace_rclrTL,wgtTL*100.);
02630         printf("  %3.0f %3.0f %3.0f",trace_opcBL*255.,trace_rclrBL,wgtBL*100.);
02631         printf("  %3.0f %3.0f %3.0f",trace_opcTR*255.,trace_rclrTR,wgtTR*100.);
02632         printf("  %3.0f %3.0f %3.0f",trace_opcBR*255.,trace_rclrBR,wgtBR*100.);
02633         printf("  %3.0f %3.0f\n", iopc*255., 
02634                ipixel->rclrflt);
02635         
02636         printf("              ");
02637         printf("      %3.0f    ",trace_rsclrTL);
02638         printf("      %3.0f    ",trace_rsclrBL);
02639         printf("      %3.0f    ",trace_rsclrTR);
02640         printf("      %3.0f    ",trace_rsclrBR);
02641         printf("  %3.0f\n", shadow_pixel->opcflt * 255.);
02642         
02643         printf("              ");
02644         printf("      %3.0f    ",trace_gclrTL);
02645         printf("      %3.0f    ",trace_gclrBL);
02646         printf("      %3.0f    ",trace_gclrTR);
02647         printf("      %3.0f    ",trace_gclrBR);
02648         printf("      %3.0f\n", ipixel->gclrflt);
02649         printf("              ");
02650         printf("      %3.0f    ",trace_bclrTL);
02651         printf("      %3.0f    ",trace_bclrBL);
02652         printf("      %3.0f    ",trace_bclrTR);
02653         printf("      %3.0f    ",trace_bclrBR);
02654         printf("      %3.0f\n", ipixel->bclrflt);
02655     }
02656 #endif /* DEBUG */
02657 ;
02658 #           ifndef SKIP_ERT
02659                 if (iopc >= max_opacity) {
02660                     ASSERT(ipixel->lnk == 0);
02661                     ipixel->lnk = 1;
02662                 }
02663 #           endif
02664         };
02665                 ipixel += 1; shadow_pixel += 1;
02666                 topRLEdata += 1 * voxel_istride;
02667                 botRLEdata += 1 * voxel_istride;
02668                 count--;
02669                 SET_VOXELS_LOADED;
02670 
02671                 /* do the rest of the pixels in this run;
02672                    the top-left and top-right voxels contribute */
02673                 while (count > 0) {
02674                     if (PIXEL_IS_OPAQUE(ipixel))
02675                         break;
02676                     if (!voxels_loaded) {
02677                         
02678     
02679             opac_param = VoxelField(topRLEdata - voxel_istride, param0_offset, param0_size);
02680             opacity = param0_table[opac_param];
02681             if (param1_size != 0) {
02682                 opac_param = VoxelField(topRLEdata - voxel_istride, param1_offset, param1_size);
02683                 opacity *= param1_table[opac_param];
02684                 if (param2_size != 0) {
02685                     opac_param = VoxelField(topRLEdata - voxel_istride, param2_offset, param2_size);
02686                     opacity *= param2_table[opac_param];
02687                 }
02688             }
02689             if (opacity > min_opacity) {
02690                 opacity_int = opacity*255.;
02691                 top_opc = opac_correct[opacity_int];
02692             } else {
02693                 top_opc = (float)0.;
02694             };
02695     
02696     
02697     shade_index=num_materials*3*ShortField(topRLEdata - voxel_istride,norm_offset);
02698     weight_index = num_materials * ByteField(topRLEdata - voxel_istride, wgt_offset);
02699     
02700         
02701         
02702     top_rclr = 
02703     shade_table[shade_index + 3*0 + 0] * 
02704         ((num_materials > 1) ? weight_table[weight_index] : (float)1.0);
02705         
02706     top_gclr = 
02707     shade_table[shade_index + 3*0 + 1] * 
02708         ((num_materials > 1) ? weight_table[weight_index] : (float)1.0);
02709         
02710     top_bclr = 
02711     shade_table[shade_index + 3*0 + 2] * 
02712         ((num_materials > 1) ? weight_table[weight_index] : (float)1.0);
02713         
02714         top_rsclr = 
02715     shadow_table[shade_index + 3*0 + 0] * 
02716         ((num_materials > 1) ? weight_table[weight_index] : (float)1.0);
02717         
02718         top_gsclr = 
02719     shadow_table[shade_index + 3*0 + 1] * 
02720         ((num_materials > 1) ? weight_table[weight_index] : (float)1.0);
02721         
02722         top_bsclr = 
02723     shadow_table[shade_index + 3*0 + 2] * 
02724         ((num_materials > 1) ? weight_table[weight_index] : (float)1.0);
02725         for (m = 1; m < num_materials; m++) {
02726              
02727         
02728     top_rclr += 
02729     shade_table[shade_index + 3*m + 0] * 
02730         weight_table[weight_index + m];
02731         
02732     top_gclr += 
02733     shade_table[shade_index + 3*m + 1] * 
02734         weight_table[weight_index + m];
02735         
02736     top_bclr += 
02737     shade_table[shade_index + 3*m + 2] * 
02738         weight_table[weight_index + m];
02739         
02740         top_rsclr += 
02741     shadow_table[shade_index + 3*m + 0] * 
02742         weight_table[weight_index + m];
02743         
02744         top_gsclr += 
02745     shadow_table[shade_index + 3*m + 1] * 
02746         weight_table[weight_index + m];
02747         
02748         top_bsclr += 
02749     shadow_table[shade_index + 3*m + 2] * 
02750         weight_table[weight_index + m];
02751         };
02752     shade_factor = top_opc * slice_depth_cueing;
02753     
02754         top_rclr *= shade_factor;
02755         top_gclr *= shade_factor;
02756         top_bclr *= shade_factor;
02757     
02758             top_rsclr *= shade_factor;
02759             top_gsclr *= shade_factor;
02760             top_bsclr *= shade_factor;
02761                     }
02762                     
02763 #ifdef DEBUG
02764     if (ipixel == trace_pixel_ptr) {
02765         trace_opcTL = 0.; trace_opcBL = 0.; trace_opcTR = 0.; trace_opcBR = 0.;
02766         trace_rsclrTL=0.; trace_rsclrBL=0.; trace_rsclrTR=0.; trace_rsclrBR=0.;
02767         trace_rclrTL= 0.; trace_rclrBL= 0.; trace_rclrTR= 0.; trace_rclrBR= 0.;
02768         trace_gclrTL= 0.; trace_gclrBL= 0.; trace_gclrTR= 0.; trace_gclrBR= 0.;
02769         trace_bclrTL= 0.; trace_bclrBL= 0.; trace_bclrTR= 0.; trace_bclrBR= 0.;
02770     }
02771 #endif
02772 ;
02773                     
02774        acc_opc = top_opc * wgtTL;
02775        
02776             acc_rclr = (top_rclr + top_rsclr *
02777                          ((float)1.0 - shadow_pixel->opcflt)) * wgtTL;
02778             acc_gclr = (top_gclr + top_gsclr *
02779                          ((float)1.0 - shadow_pixel->opcflt)) * wgtTL;
02780             acc_bclr = (top_bclr + top_bsclr *
02781                          ((float)1.0 - shadow_pixel->opcflt)) * wgtTL;
02782        
02783 #ifdef DEBUG
02784     if (ipixel == trace_pixel_ptr) {
02785         trace_opcTL = top_opc;
02786         trace_rclrTL = top_rclr;
02787                      trace_gclrTL = top_gclr;
02788                      trace_bclrTL = top_bclr;
02789         
02790     }
02791 #endif
02792 ;
02793                     
02794     
02795             opac_param = VoxelField(topRLEdata, param0_offset, param0_size);
02796             opacity = param0_table[opac_param];
02797             if (param1_size != 0) {
02798                 opac_param = VoxelField(topRLEdata, param1_offset, param1_size);
02799                 opacity *= param1_table[opac_param];
02800                 if (param2_size != 0) {
02801                     opac_param = VoxelField(topRLEdata, param2_offset, param2_size);
02802                     opacity *= param2_table[opac_param];
02803                 }
02804             }
02805             if (opacity > min_opacity) {
02806                 opacity_int = opacity*255.;
02807                 top_opc = opac_correct[opacity_int];
02808             } else {
02809                 top_opc = (float)0.;
02810             };
02811     
02812     
02813     shade_index=num_materials*3*ShortField(topRLEdata,norm_offset);
02814     weight_index = num_materials * ByteField(topRLEdata, wgt_offset);
02815     
02816         
02817         
02818     top_rclr = 
02819     shade_table[shade_index + 3*0 + 0] * 
02820         ((num_materials > 1) ? weight_table[weight_index] : (float)1.0);
02821         
02822     top_gclr = 
02823     shade_table[shade_index + 3*0 + 1] * 
02824         ((num_materials > 1) ? weight_table[weight_index] : (float)1.0);
02825         
02826     top_bclr = 
02827     shade_table[shade_index + 3*0 + 2] * 
02828         ((num_materials > 1) ? weight_table[weight_index] : (float)1.0);
02829         
02830         top_rsclr = 
02831     shadow_table[shade_index + 3*0 + 0] * 
02832         ((num_materials > 1) ? weight_table[weight_index] : (float)1.0);
02833         
02834         top_gsclr = 
02835     shadow_table[shade_index + 3*0 + 1] * 
02836         ((num_materials > 1) ? weight_table[weight_index] : (float)1.0);
02837         
02838         top_bsclr = 
02839     shadow_table[shade_index + 3*0 + 2] * 
02840         ((num_materials > 1) ? weight_table[weight_index] : (float)1.0);
02841         for (m = 1; m < num_materials; m++) {
02842              
02843         
02844     top_rclr += 
02845     shade_table[shade_index + 3*m + 0] * 
02846         weight_table[weight_index + m];
02847         
02848     top_gclr += 
02849     shade_table[shade_index + 3*m + 1] * 
02850         weight_table[weight_index + m];
02851         
02852     top_bclr += 
02853     shade_table[shade_index + 3*m + 2] * 
02854         weight_table[weight_index + m];
02855         
02856         top_rsclr += 
02857     shadow_table[shade_index + 3*m + 0] * 
02858         weight_table[weight_index + m];
02859         
02860         top_gsclr += 
02861     shadow_table[shade_index + 3*m + 1] * 
02862         weight_table[weight_index + m];
02863         
02864         top_bsclr += 
02865     shadow_table[shade_index + 3*m + 2] * 
02866         weight_table[weight_index + m];
02867         };
02868     shade_factor = top_opc * slice_depth_cueing;
02869     
02870         top_rclr *= shade_factor;
02871         top_gclr *= shade_factor;
02872         top_bclr *= shade_factor;
02873     
02874             top_rsclr *= shade_factor;
02875             top_gsclr *= shade_factor;
02876             top_bsclr *= shade_factor;
02877                     
02878        acc_opc += top_opc * wgtTR;
02879        
02880             acc_rclr += (top_rclr + top_rsclr *
02881                          ((float)1.0 - shadow_pixel->opcflt)) * wgtTR;
02882             acc_gclr += (top_gclr + top_gsclr *
02883                          ((float)1.0 - shadow_pixel->opcflt)) * wgtTR;
02884             acc_bclr += (top_bclr + top_bsclr *
02885                          ((float)1.0 - shadow_pixel->opcflt)) * wgtTR;
02886        
02887 #ifdef DEBUG
02888     if (ipixel == trace_pixel_ptr) {
02889         trace_opcTR = top_opc;
02890         trace_rclrTR = top_rclr;
02891                      trace_gclrTR = top_gclr;
02892                      trace_bclrTR = top_bclr;
02893         
02894     }
02895 #endif
02896 ;
02897                     
02898         COUNT_RESAMPLE;
02899         if (acc_opc > min_opacity) {
02900             COUNT_COMPOSITE;
02901             iopc = ipixel->opcflt;
02902 #           ifndef SKIP_ERT
02903                 ASSERT(iopc < max_opacity);
02904 #           endif
02905             iopc_inv = (float)1. - iopc;
02906             
02907         ipixel->rclrflt += acc_rclr * iopc_inv;
02908         ipixel->gclrflt += acc_gclr * iopc_inv;
02909         ipixel->bclrflt += acc_bclr * iopc_inv;
02910             iopc += acc_opc * iopc_inv;
02911             ipixel->opcflt = iopc;
02912             
02913 #ifdef DEBUG
02914     if (ipixel == trace_pixel_ptr) {
02915 #ifdef COMPUTE_SHADOW_BUFFER
02916         printf("{%3d}  %3d %3d", k, icount-i-count, j);
02917 #else
02918         printf("[%3d]  %3d %3d", k, icount-i-count, j);
02919 #endif
02920         printf("  %3.0f %3.0f %3.0f",trace_opcTL*255.,trace_rclrTL,wgtTL*100.);
02921         printf("  %3.0f %3.0f %3.0f",trace_opcBL*255.,trace_rclrBL,wgtBL*100.);
02922         printf("  %3.0f %3.0f %3.0f",trace_opcTR*255.,trace_rclrTR,wgtTR*100.);
02923         printf("  %3.0f %3.0f %3.0f",trace_opcBR*255.,trace_rclrBR,wgtBR*100.);
02924         printf("  %3.0f %3.0f\n", iopc*255., 
02925                ipixel->rclrflt);
02926         
02927         printf("              ");
02928         printf("      %3.0f    ",trace_rsclrTL);
02929         printf("      %3.0f    ",trace_rsclrBL);
02930         printf("      %3.0f    ",trace_rsclrTR);
02931         printf("      %3.0f    ",trace_rsclrBR);
02932         printf("  %3.0f\n", shadow_pixel->opcflt * 255.);
02933         
02934         printf("              ");
02935         printf("      %3.0f    ",trace_gclrTL);
02936         printf("      %3.0f    ",trace_gclrBL);
02937         printf("      %3.0f    ",trace_gclrTR);
02938         printf("      %3.0f    ",trace_gclrBR);
02939         printf("      %3.0f\n", ipixel->gclrflt);
02940         printf("              ");
02941         printf("      %3.0f    ",trace_bclrTL);
02942         printf("      %3.0f    ",trace_bclrBL);
02943         printf("      %3.0f    ",trace_bclrTR);
02944         printf("      %3.0f    ",trace_bclrBR);
02945         printf("      %3.0f\n", ipixel->bclrflt);
02946     }
02947 #endif /* DEBUG */
02948 ;
02949 #           ifndef SKIP_ERT
02950                 if (iopc >= max_opacity) {
02951                     ASSERT(ipixel->lnk == 0);
02952                     ipixel->lnk = 1;
02953                 }
02954 #           endif
02955         };
02956                     ipixel += 1; shadow_pixel += 1;
02957                     topRLEdata += 1 * voxel_istride;
02958                     botRLEdata += 1 * voxel_istride;
02959                     count--;
02960                     SET_VOXELS_LOADED;
02961                 }
02962                 break;
02963             case ALL_NONZERO__TOP_NONZERO:
02964                 /* first pixel: top-left, bottom-left and top-right voxels
02965                    contribute */
02966                 if (!voxels_loaded) {
02967                     
02968     
02969             opac_param = VoxelField(topRLEdata - voxel_istride, param0_offset, param0_size);
02970             opacity = param0_table[opac_param];
02971             if (param1_size != 0) {
02972                 opac_param = VoxelField(topRLEdata - voxel_istride, param1_offset, param1_size);
02973                 opacity *= param1_table[opac_param];
02974                 if (param2_size != 0) {
02975                     opac_param = VoxelField(topRLEdata - voxel_istride, param2_offset, param2_size);
02976                     opacity *= param2_table[opac_param];
02977                 }
02978             }
02979             if (opacity > min_opacity) {
02980                 opacity_int = opacity*255.;
02981                 top_opc = opac_correct[opacity_int];
02982             } else {
02983                 top_opc = (float)0.;
02984             };
02985     
02986     
02987     shade_index=num_materials*3*ShortField(topRLEdata - voxel_istride,norm_offset);
02988     weight_index = num_materials * ByteField(topRLEdata - voxel_istride, wgt_offset);
02989     
02990         
02991         
02992     top_rclr = 
02993     shade_table[shade_index + 3*0 + 0] * 
02994         ((num_materials > 1) ? weight_table[weight_index] : (float)1.0);
02995         
02996     top_gclr = 
02997     shade_table[shade_index + 3*0 + 1] * 
02998         ((num_materials > 1) ? weight_table[weight_index] : (float)1.0);
02999         
03000     top_bclr = 
03001     shade_table[shade_index + 3*0 + 2] * 
03002         ((num_materials > 1) ? weight_table[weight_index] : (float)1.0);
03003         
03004         top_rsclr = 
03005     shadow_table[shade_index + 3*0 + 0] * 
03006         ((num_materials > 1) ? weight_table[weight_index] : (float)1.0);
03007         
03008         top_gsclr = 
03009     shadow_table[shade_index + 3*0 + 1] * 
03010         ((num_materials > 1) ? weight_table[weight_index] : (float)1.0);
03011         
03012         top_bsclr = 
03013     shadow_table[shade_index + 3*0 + 2] * 
03014         ((num_materials > 1) ? weight_table[weight_index] : (float)1.0);
03015         for (m = 1; m < num_materials; m++) {
03016              
03017         
03018     top_rclr += 
03019     shade_table[shade_index + 3*m + 0] * 
03020         weight_table[weight_index + m];
03021         
03022     top_gclr += 
03023     shade_table[shade_index + 3*m + 1] * 
03024         weight_table[weight_index + m];
03025         
03026     top_bclr += 
03027     shade_table[shade_index + 3*m + 2] * 
03028         weight_table[weight_index + m];
03029         
03030         top_rsclr += 
03031     shadow_table[shade_index + 3*m + 0] * 
03032         weight_table[weight_index + m];
03033         
03034         top_gsclr += 
03035     shadow_table[shade_index + 3*m + 1] * 
03036         weight_table[weight_index + m];
03037         
03038         top_bsclr += 
03039     shadow_table[shade_index + 3*m + 2] * 
03040         weight_table[weight_index + m];
03041         };
03042     shade_factor = top_opc * slice_depth_cueing;
03043     
03044         top_rclr *= shade_factor;
03045         top_gclr *= shade_factor;
03046         top_bclr *= shade_factor;
03047     
03048             top_rsclr *= shade_factor;
03049             top_gsclr *= shade_factor;
03050             top_bsclr *= shade_factor;
03051                     
03052     
03053             opac_param = VoxelField(botRLEdata - voxel_istride, param0_offset, param0_size);
03054             opacity = param0_table[opac_param];
03055             if (param1_size != 0) {
03056                 opac_param = VoxelField(botRLEdata - voxel_istride, param1_offset, param1_size);
03057                 opacity *= param1_table[opac_param];
03058                 if (param2_size != 0) {
03059                     opac_param = VoxelField(botRLEdata - voxel_istride, param2_offset, param2_size);
03060                     opacity *= param2_table[opac_param];
03061                 }
03062             }
03063             if (opacity > min_opacity) {
03064                 opacity_int = opacity*255.;
03065                 bot_opc = opac_correct[opacity_int];
03066             } else {
03067                 bot_opc = (float)0.;
03068             };
03069     
03070     
03071     shade_index=num_materials*3*ShortField(botRLEdata - voxel_istride,norm_offset);
03072     weight_index = num_materials * ByteField(botRLEdata - voxel_istride, wgt_offset);
03073     
03074         
03075         
03076     bot_rclr = 
03077     shade_table[shade_index + 3*0 + 0] * 
03078         ((num_materials > 1) ? weight_table[weight_index] : (float)1.0);
03079         
03080     bot_gclr = 
03081     shade_table[shade_index + 3*0 + 1] * 
03082         ((num_materials > 1) ? weight_table[weight_index] : (float)1.0);
03083         
03084     bot_bclr = 
03085     shade_table[shade_index + 3*0 + 2] * 
03086         ((num_materials > 1) ? weight_table[weight_index] : (float)1.0);
03087         
03088         bot_rsclr = 
03089     shadow_table[shade_index + 3*0 + 0] * 
03090         ((num_materials > 1) ? weight_table[weight_index] : (float)1.0);
03091         
03092         bot_gsclr = 
03093     shadow_table[shade_index + 3*0 + 1] * 
03094         ((num_materials > 1) ? weight_table[weight_index] : (float)1.0);
03095         
03096         bot_bsclr = 
03097     shadow_table[shade_index + 3*0 + 2] * 
03098         ((num_materials > 1) ? weight_table[weight_index] : (float)1.0);
03099         for (m = 1; m < num_materials; m++) {
03100              
03101         
03102     bot_rclr += 
03103     shade_table[shade_index + 3*m + 0] * 
03104         weight_table[weight_index + m];
03105         
03106     bot_gclr += 
03107     shade_table[shade_index + 3*m + 1] * 
03108         weight_table[weight_index + m];
03109         
03110     bot_bclr += 
03111     shade_table[shade_index + 3*m + 2] * 
03112         weight_table[weight_index + m];
03113         
03114         bot_rsclr += 
03115     shadow_table[shade_index + 3*m + 0] * 
03116         weight_table[weight_index + m];
03117         
03118         bot_gsclr += 
03119     shadow_table[shade_index + 3*m + 1] * 
03120         weight_table[weight_index + m];
03121         
03122         bot_bsclr += 
03123     shadow_table[shade_index + 3*m + 2] * 
03124         weight_table[weight_index + m];
03125         };
03126     shade_factor = bot_opc * slice_depth_cueing;
03127     
03128         bot_rclr *= shade_factor;
03129         bot_gclr *= shade_factor;
03130         bot_bclr *= shade_factor;
03131     
03132             bot_rsclr *= shade_factor;
03133             bot_gsclr *= shade_factor;
03134             bot_bsclr *= shade_factor;
03135                 }
03136                 
03137 #ifdef DEBUG
03138     if (ipixel == trace_pixel_ptr) {
03139         trace_opcTL = 0.; trace_opcBL = 0.; trace_opcTR = 0.; trace_opcBR = 0.;
03140         trace_rsclrTL=0.; trace_rsclrBL=0.; trace_rsclrTR=0.; trace_rsclrBR=0.;
03141         trace_rclrTL= 0.; trace_rclrBL= 0.; trace_rclrTR= 0.; trace_rclrBR= 0.;
03142         trace_gclrTL= 0.; trace_gclrBL= 0.; trace_gclrTR= 0.; trace_gclrBR= 0.;
03143         trace_bclrTL= 0.; trace_bclrBL= 0.; trace_bclrTR= 0.; trace_bclrBR= 0.;
03144     }
03145 #endif
03146 ;
03147                 
03148        acc_opc = top_opc * wgtTL;
03149        
03150             acc_rclr = (top_rclr + top_rsclr *
03151                          ((float)1.0 - shadow_pixel->opcflt)) * wgtTL;
03152             acc_gclr = (top_gclr + top_gsclr *
03153                          ((float)1.0 - shadow_pixel->opcflt)) * wgtTL;
03154             acc_bclr = (top_bclr + top_bsclr *
03155                          ((float)1.0 - shadow_pixel->opcflt)) * wgtTL;
03156        
03157 #ifdef DEBUG
03158     if (ipixel == trace_pixel_ptr) {
03159         trace_opcTL = top_opc;
03160         trace_rclrTL = top_rclr;
03161                      trace_gclrTL = top_gclr;
03162                      trace_bclrTL = top_bclr;
03163         
03164     }
03165 #endif
03166 ;
03167                 
03168        acc_opc += bot_opc * wgtBL;
03169        
03170             acc_rclr += (bot_rclr + bot_rsclr *
03171                          ((float)1.0 - shadow_pixel->opcflt)) * wgtBL;
03172             acc_gclr += (bot_gclr + bot_gsclr *
03173                          ((float)1.0 - shadow_pixel->opcflt)) * wgtBL;
03174             acc_bclr += (bot_bclr + bot_bsclr *
03175                          ((float)1.0 - shadow_pixel->opcflt)) * wgtBL;
03176        
03177 #ifdef DEBUG
03178     if (ipixel == trace_pixel_ptr) {
03179         trace_opcBL = bot_opc;
03180         trace_rclrBL = bot_rclr;
03181                      trace_gclrBL = bot_gclr;
03182                      trace_bclrBL = bot_bclr;
03183         
03184     }
03185 #endif
03186 ;
03187                 
03188     
03189             opac_param = VoxelField(topRLEdata, param0_offset, param0_size);
03190             opacity = param0_table[opac_param];
03191             if (param1_size != 0) {
03192                 opac_param = VoxelField(topRLEdata, param1_offset, param1_size);
03193                 opacity *= param1_table[opac_param];
03194                 if (param2_size != 0) {
03195                     opac_param = VoxelField(topRLEdata, param2_offset, param2_size);
03196                     opacity *= param2_table[opac_param];
03197                 }
03198             }
03199             if (opacity > min_opacity) {
03200                 opacity_int = opacity*255.;
03201                 top_opc = opac_correct[opacity_int];
03202             } else {
03203                 top_opc = (float)0.;
03204             };
03205     
03206     
03207     shade_index=num_materials*3*ShortField(topRLEdata,norm_offset);
03208     weight_index = num_materials * ByteField(topRLEdata, wgt_offset);
03209     
03210         
03211         
03212     top_rclr = 
03213     shade_table[shade_index + 3*0 + 0] * 
03214         ((num_materials > 1) ? weight_table[weight_index] : (float)1.0);
03215         
03216     top_gclr = 
03217     shade_table[shade_index + 3*0 + 1] * 
03218         ((num_materials > 1) ? weight_table[weight_index] : (float)1.0);
03219         
03220     top_bclr = 
03221     shade_table[shade_index + 3*0 + 2] * 
03222         ((num_materials > 1) ? weight_table[weight_index] : (float)1.0);
03223         
03224         top_rsclr = 
03225     shadow_table[shade_index + 3*0 + 0] * 
03226         ((num_materials > 1) ? weight_table[weight_index] : (float)1.0);
03227         
03228         top_gsclr = 
03229     shadow_table[shade_index + 3*0 + 1] * 
03230         ((num_materials > 1) ? weight_table[weight_index] : (float)1.0);
03231         
03232         top_bsclr = 
03233     shadow_table[shade_index + 3*0 + 2] * 
03234         ((num_materials > 1) ? weight_table[weight_index] : (float)1.0);
03235         for (m = 1; m < num_materials; m++) {
03236              
03237         
03238     top_rclr += 
03239     shade_table[shade_index + 3*m + 0] * 
03240         weight_table[weight_index + m];
03241         
03242     top_gclr += 
03243     shade_table[shade_index + 3*m + 1] * 
03244         weight_table[weight_index + m];
03245         
03246     top_bclr += 
03247     shade_table[shade_index + 3*m + 2] * 
03248         weight_table[weight_index + m];
03249         
03250         top_rsclr += 
03251     shadow_table[shade_index + 3*m + 0] * 
03252         weight_table[weight_index + m];
03253         
03254         top_gsclr += 
03255     shadow_table[shade_index + 3*m + 1] * 
03256         weight_table[weight_index + m];
03257         
03258         top_bsclr += 
03259     shadow_table[shade_index + 3*m + 2] * 
03260         weight_table[weight_index + m];
03261         };
03262     shade_factor = top_opc * slice_depth_cueing;
03263     
03264         top_rclr *= shade_factor;
03265         top_gclr *= shade_factor;
03266         top_bclr *= shade_factor;
03267     
03268             top_rsclr *= shade_factor;
03269             top_gsclr *= shade_factor;
03270             top_bsclr *= shade_factor;
03271                 
03272        acc_opc += top_opc * wgtTR;
03273        
03274             acc_rclr += (top_rclr + top_rsclr *
03275                          ((float)1.0 - shadow_pixel->opcflt)) * wgtTR;
03276             acc_gclr += (top_gclr + top_gsclr *
03277                          ((float)1.0 - shadow_pixel->opcflt)) * wgtTR;
03278             acc_bclr += (top_bclr + top_bsclr *
03279                          ((float)1.0 - shadow_pixel->opcflt)) * wgtTR;
03280        
03281 #ifdef DEBUG
03282     if (ipixel == trace_pixel_ptr) {
03283         trace_opcTR = top_opc;
03284         trace_rclrTR = top_rclr;
03285                      trace_gclrTR = top_gclr;
03286                      trace_bclrTR = top_bclr;
03287         
03288     }
03289 #endif
03290 ;
03291                 
03292         COUNT_RESAMPLE;
03293         if (acc_opc > min_opacity) {
03294             COUNT_COMPOSITE;
03295             iopc = ipixel->opcflt;
03296 #           ifndef SKIP_ERT
03297                 ASSERT(iopc < max_opacity);
03298 #           endif
03299             iopc_inv = (float)1. - iopc;
03300             
03301         ipixel->rclrflt += acc_rclr * iopc_inv;
03302         ipixel->gclrflt += acc_gclr * iopc_inv;
03303         ipixel->bclrflt += acc_bclr * iopc_inv;
03304             iopc += acc_opc * iopc_inv;
03305             ipixel->opcflt = iopc;
03306             
03307 #ifdef DEBUG
03308     if (ipixel == trace_pixel_ptr) {
03309 #ifdef COMPUTE_SHADOW_BUFFER
03310         printf("{%3d}  %3d %3d", k, icount-i-count, j);
03311 #else
03312         printf("[%3d]  %3d %3d", k, icount-i-count, j);
03313 #endif
03314         printf("  %3.0f %3.0f %3.0f",trace_opcTL*255.,trace_rclrTL,wgtTL*100.);
03315         printf("  %3.0f %3.0f %3.0f",trace_opcBL*255.,trace_rclrBL,wgtBL*100.);
03316         printf("  %3.0f %3.0f %3.0f",trace_opcTR*255.,trace_rclrTR,wgtTR*100.);
03317         printf("  %3.0f %3.0f %3.0f",trace_opcBR*255.,trace_rclrBR,wgtBR*100.);
03318         printf("  %3.0f %3.0f\n", iopc*255., 
03319                ipixel->rclrflt);
03320         
03321         printf("              ");
03322         printf("      %3.0f    ",trace_rsclrTL);
03323         printf("      %3.0f    ",trace_rsclrBL);
03324         printf("      %3.0f    ",trace_rsclrTR);
03325         printf("      %3.0f    ",trace_rsclrBR);
03326         printf("  %3.0f\n", shadow_pixel->opcflt * 255.);
03327         
03328         printf("              ");
03329         printf("      %3.0f    ",trace_gclrTL);
03330         printf("      %3.0f    ",trace_gclrBL);
03331         printf("      %3.0f    ",trace_gclrTR);
03332         printf("      %3.0f    ",trace_gclrBR);
03333         printf("      %3.0f\n", ipixel->gclrflt);
03334         printf("              ");
03335         printf("      %3.0f    ",trace_bclrTL);
03336         printf("      %3.0f    ",trace_bclrBL);
03337         printf("      %3.0f    ",trace_bclrTR);
03338         printf("      %3.0f    ",trace_bclrBR);
03339         printf("      %3.0f\n", ipixel->bclrflt);
03340     }
03341 #endif /* DEBUG */
03342 ;
03343 #           ifndef SKIP_ERT
03344                 if (iopc >= max_opacity) {
03345                     ASSERT(ipixel->lnk == 0);
03346                     ipixel->lnk = 1;
03347                 }
03348 #           endif
03349         };
03350                 ipixel += 1; shadow_pixel += 1;
03351                 topRLEdata += 1 * voxel_istride;
03352                 botRLEdata += 1 * voxel_istride;
03353                 count--;
03354                 SET_VOXELS_LOADED;
03355 
03356                 /* do the rest of the pixels in this run;
03357                    the top-left and top-right voxels contribute */
03358                 while (count > 0) {
03359                     if (PIXEL_IS_OPAQUE(ipixel))
03360                         break;
03361                     if (!voxels_loaded) {
03362                         
03363     
03364             opac_param = VoxelField(topRLEdata - voxel_istride, param0_offset, param0_size);
03365             opacity = param0_table[opac_param];
03366             if (param1_size != 0) {
03367                 opac_param = VoxelField(topRLEdata - voxel_istride, param1_offset, param1_size);
03368                 opacity *= param1_table[opac_param];
03369                 if (param2_size != 0) {
03370                     opac_param = VoxelField(topRLEdata - voxel_istride, param2_offset, param2_size);
03371                     opacity *= param2_table[opac_param];
03372                 }
03373             }
03374             if (opacity > min_opacity) {
03375                 opacity_int = opacity*255.;
03376                 top_opc = opac_correct[opacity_int];
03377             } else {
03378                 top_opc = (float)0.;
03379             };
03380     
03381     
03382     shade_index=num_materials*3*ShortField(topRLEdata - voxel_istride,norm_offset);
03383     weight_index = num_materials * ByteField(topRLEdata - voxel_istride, wgt_offset);
03384     
03385         
03386         
03387     top_rclr = 
03388     shade_table[shade_index + 3*0 + 0] * 
03389         ((num_materials > 1) ? weight_table[weight_index] : (float)1.0);
03390         
03391     top_gclr = 
03392     shade_table[shade_index + 3*0 + 1] * 
03393         ((num_materials > 1) ? weight_table[weight_index] : (float)1.0);
03394         
03395     top_bclr = 
03396     shade_table[shade_index + 3*0 + 2] * 
03397         ((num_materials > 1) ? weight_table[weight_index] : (float)1.0);
03398         
03399         top_rsclr = 
03400     shadow_table[shade_index + 3*0 + 0] * 
03401         ((num_materials > 1) ? weight_table[weight_index] : (float)1.0);
03402         
03403         top_gsclr = 
03404     shadow_table[shade_index + 3*0 + 1] * 
03405         ((num_materials > 1) ? weight_table[weight_index] : (float)1.0);
03406         
03407         top_bsclr = 
03408     shadow_table[shade_index + 3*0 + 2] * 
03409         ((num_materials > 1) ? weight_table[weight_index] : (float)1.0);
03410         for (m = 1; m < num_materials; m++) {
03411              
03412         
03413     top_rclr += 
03414     shade_table[shade_index + 3*m + 0] * 
03415         weight_table[weight_index + m];
03416         
03417     top_gclr += 
03418     shade_table[shade_index + 3*m + 1] * 
03419         weight_table[weight_index + m];
03420         
03421     top_bclr += 
03422     shade_table[shade_index + 3*m + 2] * 
03423         weight_table[weight_index + m];
03424         
03425         top_rsclr += 
03426     shadow_table[shade_index + 3*m + 0] * 
03427         weight_table[weight_index + m];
03428         
03429         top_gsclr += 
03430     shadow_table[shade_index + 3*m + 1] * 
03431         weight_table[weight_index + m];
03432         
03433         top_bsclr += 
03434     shadow_table[shade_index + 3*m + 2] * 
03435         weight_table[weight_index + m];
03436         };
03437     shade_factor = top_opc * slice_depth_cueing;
03438     
03439         top_rclr *= shade_factor;
03440         top_gclr *= shade_factor;
03441         top_bclr *= shade_factor;
03442     
03443             top_rsclr *= shade_factor;
03444             top_gsclr *= shade_factor;
03445             top_bsclr *= shade_factor;
03446                     }
03447                     
03448 #ifdef DEBUG
03449     if (ipixel == trace_pixel_ptr) {
03450         trace_opcTL = 0.; trace_opcBL = 0.; trace_opcTR = 0.; trace_opcBR = 0.;
03451         trace_rsclrTL=0.; trace_rsclrBL=0.; trace_rsclrTR=0.; trace_rsclrBR=0.;
03452         trace_rclrTL= 0.; trace_rclrBL= 0.; trace_rclrTR= 0.; trace_rclrBR= 0.;
03453         trace_gclrTL= 0.; trace_gclrBL= 0.; trace_gclrTR= 0.; trace_gclrBR= 0.;
03454         trace_bclrTL= 0.; trace_bclrBL= 0.; trace_bclrTR= 0.; trace_bclrBR= 0.;
03455     }
03456 #endif
03457 ;
03458                     
03459        acc_opc = top_opc * wgtTL;
03460        
03461             acc_rclr = (top_rclr + top_rsclr *
03462                          ((float)1.0 - shadow_pixel->opcflt)) * wgtTL;
03463             acc_gclr = (top_gclr + top_gsclr *
03464                          ((float)1.0 - shadow_pixel->opcflt)) * wgtTL;
03465             acc_bclr = (top_bclr + top_bsclr *
03466                          ((float)1.0 - shadow_pixel->opcflt)) * wgtTL;
03467        
03468 #ifdef DEBUG
03469     if (ipixel == trace_pixel_ptr) {
03470         trace_opcTL = top_opc;
03471         trace_rclrTL = top_rclr;
03472                      trace_gclrTL = top_gclr;
03473                      trace_bclrTL = top_bclr;
03474         
03475     }
03476 #endif
03477 ;
03478                     
03479     
03480             opac_param = VoxelField(topRLEdata, param0_offset, param0_size);
03481             opacity = param0_table[opac_param];
03482             if (param1_size != 0) {
03483                 opac_param = VoxelField(topRLEdata, param1_offset, param1_size);
03484                 opacity *= param1_table[opac_param];
03485                 if (param2_size != 0) {
03486                     opac_param = VoxelField(topRLEdata, param2_offset, param2_size);
03487                     opacity *= param2_table[opac_param];
03488                 }
03489             }
03490             if (opacity > min_opacity) {
03491                 opacity_int = opacity*255.;
03492                 top_opc = opac_correct[opacity_int];
03493             } else {
03494                 top_opc = (float)0.;
03495             };
03496     
03497     
03498     shade_index=num_materials*3*ShortField(topRLEdata,norm_offset);
03499     weight_index = num_materials * ByteField(topRLEdata, wgt_offset);
03500     
03501         
03502         
03503     top_rclr = 
03504     shade_table[shade_index + 3*0 + 0] * 
03505         ((num_materials > 1) ? weight_table[weight_index] : (float)1.0);
03506         
03507     top_gclr = 
03508     shade_table[shade_index + 3*0 + 1] * 
03509         ((num_materials > 1) ? weight_table[weight_index] : (float)1.0);
03510         
03511     top_bclr = 
03512     shade_table[shade_index + 3*0 + 2] * 
03513         ((num_materials > 1) ? weight_table[weight_index] : (float)1.0);
03514         
03515         top_rsclr = 
03516     shadow_table[shade_index + 3*0 + 0] * 
03517         ((num_materials > 1) ? weight_table[weight_index] : (float)1.0);
03518         
03519         top_gsclr = 
03520     shadow_table[shade_index + 3*0 + 1] * 
03521         ((num_materials > 1) ? weight_table[weight_index] : (float)1.0);
03522         
03523         top_bsclr = 
03524     shadow_table[shade_index + 3*0 + 2] * 
03525         ((num_materials > 1) ? weight_table[weight_index] : (float)1.0);
03526         for (m = 1; m < num_materials; m++) {
03527              
03528         
03529     top_rclr += 
03530     shade_table[shade_index + 3*m + 0] * 
03531         weight_table[weight_index + m];
03532         
03533     top_gclr += 
03534     shade_table[shade_index + 3*m + 1] * 
03535         weight_table[weight_index + m];
03536         
03537     top_bclr += 
03538     shade_table[shade_index + 3*m + 2] * 
03539         weight_table[weight_index + m];
03540         
03541         top_rsclr += 
03542     shadow_table[shade_index + 3*m + 0] * 
03543         weight_table[weight_index + m];
03544         
03545         top_gsclr += 
03546     shadow_table[shade_index + 3*m + 1] * 
03547         weight_table[weight_index + m];
03548         
03549         top_bsclr += 
03550     shadow_table[shade_index + 3*m + 2] * 
03551         weight_table[weight_index + m];
03552         };
03553     shade_factor = top_opc * slice_depth_cueing;
03554     
03555         top_rclr *= shade_factor;
03556         top_gclr *= shade_factor;
03557         top_bclr *= shade_factor;
03558     
03559             top_rsclr *= shade_factor;
03560             top_gsclr *= shade_factor;
03561             top_bsclr *= shade_factor;
03562                     
03563        acc_opc += top_opc * wgtTR;
03564        
03565             acc_rclr += (top_rclr + top_rsclr *
03566                          ((float)1.0 - shadow_pixel->opcflt)) * wgtTR;
03567             acc_gclr += (top_gclr + top_gsclr *
03568                          ((float)1.0 - shadow_pixel->opcflt)) * wgtTR;
03569             acc_bclr += (top_bclr + top_bsclr *
03570                          ((float)1.0 - shadow_pixel->opcflt)) * wgtTR;
03571        
03572 #ifdef DEBUG
03573     if (ipixel == trace_pixel_ptr) {
03574         trace_opcTR = top_opc;
03575         trace_rclrTR = top_rclr;
03576                      trace_gclrTR = top_gclr;
03577                      trace_bclrTR = top_bclr;
03578         
03579     }
03580 #endif
03581 ;
03582                     
03583         COUNT_RESAMPLE;
03584         if (acc_opc > min_opacity) {
03585             COUNT_COMPOSITE;
03586             iopc = ipixel->opcflt;
03587 #           ifndef SKIP_ERT
03588                 ASSERT(iopc < max_opacity);
03589 #           endif
03590             iopc_inv = (float)1. - iopc;
03591             
03592         ipixel->rclrflt += acc_rclr * iopc_inv;
03593         ipixel->gclrflt += acc_gclr * iopc_inv;
03594         ipixel->bclrflt += acc_bclr * iopc_inv;
03595             iopc += acc_opc * iopc_inv;
03596             ipixel->opcflt = iopc;
03597             
03598 #ifdef DEBUG
03599     if (ipixel == trace_pixel_ptr) {
03600 #ifdef COMPUTE_SHADOW_BUFFER
03601         printf("{%3d}  %3d %3d", k, icount-i-count, j);
03602 #else
03603         printf("[%3d]  %3d %3d", k, icount-i-count, j);
03604 #endif
03605         printf("  %3.0f %3.0f %3.0f",trace_opcTL*255.,trace_rclrTL,wgtTL*100.);
03606         printf("  %3.0f %3.0f %3.0f",trace_opcBL*255.,trace_rclrBL,wgtBL*100.);
03607         printf("  %3.0f %3.0f %3.0f",trace_opcTR*255.,trace_rclrTR,wgtTR*100.);
03608         printf("  %3.0f %3.0f %3.0f",trace_opcBR*255.,trace_rclrBR,wgtBR*100.);
03609         printf("  %3.0f %3.0f\n", iopc*255., 
03610                ipixel->rclrflt);
03611         
03612         printf("              ");
03613         printf("      %3.0f    ",trace_rsclrTL);
03614         printf("      %3.0f    ",trace_rsclrBL);
03615         printf("      %3.0f    ",trace_rsclrTR);
03616         printf("      %3.0f    ",trace_rsclrBR);
03617         printf("  %3.0f\n", shadow_pixel->opcflt * 255.);
03618         
03619         printf("              ");
03620         printf("      %3.0f    ",trace_gclrTL);
03621         printf("      %3.0f    ",trace_gclrBL);
03622         printf("      %3.0f    ",trace_gclrTR);
03623         printf("      %3.0f    ",trace_gclrBR);
03624         printf("      %3.0f\n", ipixel->gclrflt);
03625         printf("              ");
03626         printf("      %3.0f    ",trace_bclrTL);
03627         printf("      %3.0f    ",trace_bclrBL);
03628         printf("      %3.0f    ",trace_bclrTR);
03629         printf("      %3.0f    ",trace_bclrBR);
03630         printf("      %3.0f\n", ipixel->bclrflt);
03631     }
03632 #endif /* DEBUG */
03633 ;
03634 #           ifndef SKIP_ERT
03635                 if (iopc >= max_opacity) {
03636                     ASSERT(ipixel->lnk == 0);
03637                     ipixel->lnk = 1;
03638                 }
03639 #           endif
03640         };
03641                     ipixel += 1; shadow_pixel += 1;
03642                     topRLEdata += 1 * voxel_istride;
03643                     botRLEdata += 1 * voxel_istride;
03644                     count--;
03645                     SET_VOXELS_LOADED;
03646                 }
03647                 break;
03648             case ALL_ZERO__BOT_NONZERO:
03649                 /* first pixel: only the bottom-right voxel contributes */
03650                 
03651     
03652             opac_param = VoxelField(botRLEdata, param0_offset, param0_size);
03653             opacity = param0_table[opac_param];
03654             if (param1_size != 0) {
03655                 opac_param = VoxelField(botRLEdata, param1_offset, param1_size);
03656                 opacity *= param1_table[opac_param];
03657                 if (param2_size != 0) {
03658                     opac_param = VoxelField(botRLEdata, param2_offset, param2_size);
03659                     opacity *= param2_table[opac_param];
03660                 }
03661             }
03662             if (opacity > min_opacity) {
03663                 opacity_int = opacity*255.;
03664                 bot_opc = opac_correct[opacity_int];
03665             } else {
03666                 bot_opc = (float)0.;
03667             };
03668     
03669     
03670     shade_index=num_materials*3*ShortField(botRLEdata,norm_offset);
03671     weight_index = num_materials * ByteField(botRLEdata, wgt_offset);
03672     
03673         
03674         
03675     bot_rclr = 
03676     shade_table[shade_index + 3*0 + 0] * 
03677         ((num_materials > 1) ? weight_table[weight_index] : (float)1.0);
03678         
03679     bot_gclr = 
03680     shade_table[shade_index + 3*0 + 1] * 
03681         ((num_materials > 1) ? weight_table[weight_index] : (float)1.0);
03682         
03683     bot_bclr = 
03684     shade_table[shade_index + 3*0 + 2] * 
03685         ((num_materials > 1) ? weight_table[weight_index] : (float)1.0);
03686         
03687         bot_rsclr = 
03688     shadow_table[shade_index + 3*0 + 0] * 
03689         ((num_materials > 1) ? weight_table[weight_index] : (float)1.0);
03690         
03691         bot_gsclr = 
03692     shadow_table[shade_index + 3*0 + 1] * 
03693         ((num_materials > 1) ? weight_table[weight_index] : (float)1.0);
03694         
03695         bot_bsclr = 
03696     shadow_table[shade_index + 3*0 + 2] * 
03697         ((num_materials > 1) ? weight_table[weight_index] : (float)1.0);
03698         for (m = 1; m < num_materials; m++) {
03699              
03700         
03701     bot_rclr += 
03702     shade_table[shade_index + 3*m + 0] * 
03703         weight_table[weight_index + m];
03704         
03705     bot_gclr += 
03706     shade_table[shade_index + 3*m + 1] * 
03707         weight_table[weight_index + m];
03708         
03709     bot_bclr += 
03710     shade_table[shade_index + 3*m + 2] * 
03711         weight_table[weight_index + m];
03712         
03713         bot_rsclr += 
03714     shadow_table[shade_index + 3*m + 0] * 
03715         weight_table[weight_index + m];
03716         
03717         bot_gsclr += 
03718     shadow_table[shade_index + 3*m + 1] * 
03719         weight_table[weight_index + m];
03720         
03721         bot_bsclr += 
03722     shadow_table[shade_index + 3*m + 2] * 
03723         weight_table[weight_index + m];
03724         };
03725     shade_factor = bot_opc * slice_depth_cueing;
03726     
03727         bot_rclr *= shade_factor;
03728         bot_gclr *= shade_factor;
03729         bot_bclr *= shade_factor;
03730     
03731             bot_rsclr *= shade_factor;
03732             bot_gsclr *= shade_factor;
03733             bot_bsclr *= shade_factor;
03734                 
03735 #ifdef DEBUG
03736     if (ipixel == trace_pixel_ptr) {
03737         trace_opcTL = 0.; trace_opcBL = 0.; trace_opcTR = 0.; trace_opcBR = 0.;
03738         trace_rsclrTL=0.; trace_rsclrBL=0.; trace_rsclrTR=0.; trace_rsclrBR=0.;
03739         trace_rclrTL= 0.; trace_rclrBL= 0.; trace_rclrTR= 0.; trace_rclrBR= 0.;
03740         trace_gclrTL= 0.; trace_gclrBL= 0.; trace_gclrTR= 0.; trace_gclrBR= 0.;
03741         trace_bclrTL= 0.; trace_bclrBL= 0.; trace_bclrTR= 0.; trace_bclrBR= 0.;
03742     }
03743 #endif
03744 ;
03745                 
03746        acc_opc = bot_opc * wgtBR;
03747        
03748             acc_rclr = (bot_rclr + bot_rsclr *
03749                          ((float)1.0 - shadow_pixel->opcflt)) * wgtBR;
03750             acc_gclr = (bot_gclr + bot_gsclr *
03751                          ((float)1.0 - shadow_pixel->opcflt)) * wgtBR;
03752             acc_bclr = (bot_bclr + bot_bsclr *
03753                          ((float)1.0 - shadow_pixel->opcflt)) * wgtBR;
03754        
03755 #ifdef DEBUG
03756     if (ipixel == trace_pixel_ptr) {
03757         trace_opcBR = bot_opc;
03758         trace_rclrBR = bot_rclr;
03759                      trace_gclrBR = bot_gclr;
03760                      trace_bclrBR = bot_bclr;
03761         
03762     }
03763 #endif
03764 ;
03765                 
03766         COUNT_RESAMPLE;
03767         if (acc_opc > min_opacity) {
03768             COUNT_COMPOSITE;
03769             iopc = ipixel->opcflt;
03770 #           ifndef SKIP_ERT
03771                 ASSERT(iopc < max_opacity);
03772 #           endif
03773             iopc_inv = (float)1. - iopc;
03774             
03775         ipixel->rclrflt += acc_rclr * iopc_inv;
03776         ipixel->gclrflt += acc_gclr * iopc_inv;
03777         ipixel->bclrflt += acc_bclr * iopc_inv;
03778             iopc += acc_opc * iopc_inv;
03779             ipixel->opcflt = iopc;
03780             
03781 #ifdef DEBUG
03782     if (ipixel == trace_pixel_ptr) {
03783 #ifdef COMPUTE_SHADOW_BUFFER
03784         printf("{%3d}  %3d %3d", k, icount-i-count, j);
03785 #else
03786         printf("[%3d]  %3d %3d", k, icount-i-count, j);
03787 #endif
03788         printf("  %3.0f %3.0f %3.0f",trace_opcTL*255.,trace_rclrTL,wgtTL*100.);
03789         printf("  %3.0f %3.0f %3.0f",trace_opcBL*255.,trace_rclrBL,wgtBL*100.);
03790         printf("  %3.0f %3.0f %3.0f",trace_opcTR*255.,trace_rclrTR,wgtTR*100.);
03791         printf("  %3.0f %3.0f %3.0f",trace_opcBR*255.,trace_rclrBR,wgtBR*100.);
03792         printf("  %3.0f %3.0f\n", iopc*255., 
03793                ipixel->rclrflt);
03794         
03795         printf("              ");
03796         printf("      %3.0f    ",trace_rsclrTL);
03797         printf("      %3.0f    ",trace_rsclrBL);
03798         printf("      %3.0f    ",trace_rsclrTR);
03799         printf("      %3.0f    ",trace_rsclrBR);
03800         printf("  %3.0f\n", shadow_pixel->opcflt * 255.);
03801         
03802         printf("              ");
03803         printf("      %3.0f    ",trace_gclrTL);
03804         printf("      %3.0f    ",trace_gclrBL);
03805         printf("      %3.0f    ",trace_gclrTR);
03806         printf("      %3.0f    ",trace_gclrBR);
03807         printf("      %3.0f\n", ipixel->gclrflt);
03808         printf("              ");
03809         printf("      %3.0f    ",trace_bclrTL);
03810         printf("      %3.0f    ",trace_bclrBL);
03811         printf("      %3.0f    ",trace_bclrTR);
03812         printf("      %3.0f    ",trace_bclrBR);
03813         printf("      %3.0f\n", ipixel->bclrflt);
03814     }
03815 #endif /* DEBUG */
03816 ;
03817 #           ifndef SKIP_ERT
03818                 if (iopc >= max_opacity) {
03819                     ASSERT(ipixel->lnk == 0);
03820                     ipixel->lnk = 1;
03821                 }
03822 #           endif
03823         };      
03824                 ipixel += 1; shadow_pixel += 1;
03825                 topRLEdata += 1 * voxel_istride;
03826                 botRLEdata += 1 * voxel_istride;
03827                 count--;
03828                 SET_VOXELS_LOADED;
03829 
03830                 /* do the rest of the pixels in this run;
03831                    bottom-left and bottom-right voxels contribute */
03832                 while (count > 0) {
03833                     if (PIXEL_IS_OPAQUE(ipixel))
03834                         break;
03835                     if (!voxels_loaded) {
03836                         
03837     
03838             opac_param = VoxelField(botRLEdata - voxel_istride, param0_offset, param0_size);
03839             opacity = param0_table[opac_param];
03840             if (param1_size != 0) {
03841                 opac_param = VoxelField(botRLEdata - voxel_istride, param1_offset, param1_size);
03842                 opacity *= param1_table[opac_param];
03843                 if (param2_size != 0) {
03844                     opac_param = VoxelField(botRLEdata - voxel_istride, param2_offset, param2_size);
03845                     opacity *= param2_table[opac_param];
03846                 }
03847             }
03848             if (opacity > min_opacity) {
03849                 opacity_int = opacity*255.;
03850                 bot_opc = opac_correct[opacity_int];
03851             } else {
03852                 bot_opc = (float)0.;
03853             };
03854     
03855     
03856     shade_index=num_materials*3*ShortField(botRLEdata - voxel_istride,norm_offset);
03857     weight_index = num_materials * ByteField(botRLEdata - voxel_istride, wgt_offset);
03858     
03859         
03860         
03861     bot_rclr = 
03862     shade_table[shade_index + 3*0 + 0] * 
03863         ((num_materials > 1) ? weight_table[weight_index] : (float)1.0);
03864         
03865     bot_gclr = 
03866     shade_table[shade_index + 3*0 + 1] * 
03867         ((num_materials > 1) ? weight_table[weight_index] : (float)1.0);
03868         
03869     bot_bclr = 
03870     shade_table[shade_index + 3*0 + 2] * 
03871         ((num_materials > 1) ? weight_table[weight_index] : (float)1.0);
03872         
03873         bot_rsclr = 
03874     shadow_table[shade_index + 3*0 + 0] * 
03875         ((num_materials > 1) ? weight_table[weight_index] : (float)1.0);
03876         
03877         bot_gsclr = 
03878     shadow_table[shade_index + 3*0 + 1] * 
03879         ((num_materials > 1) ? weight_table[weight_index] : (float)1.0);
03880         
03881         bot_bsclr = 
03882     shadow_table[shade_index + 3*0 + 2] * 
03883         ((num_materials > 1) ? weight_table[weight_index] : (float)1.0);
03884         for (m = 1; m < num_materials; m++) {
03885              
03886         
03887     bot_rclr += 
03888     shade_table[shade_index + 3*m + 0] * 
03889         weight_table[weight_index + m];
03890         
03891     bot_gclr += 
03892     shade_table[shade_index + 3*m + 1] * 
03893         weight_table[weight_index + m];
03894         
03895     bot_bclr += 
03896     shade_table[shade_index + 3*m + 2] * 
03897         weight_table[weight_index + m];
03898         
03899         bot_rsclr += 
03900     shadow_table[shade_index + 3*m + 0] * 
03901         weight_table[weight_index + m];
03902         
03903         bot_gsclr += 
03904     shadow_table[shade_index + 3*m + 1] * 
03905         weight_table[weight_index + m];
03906         
03907         bot_bsclr += 
03908     shadow_table[shade_index + 3*m + 2] * 
03909         weight_table[weight_index + m];
03910         };
03911     shade_factor = bot_opc * slice_depth_cueing;
03912     
03913         bot_rclr *= shade_factor;
03914         bot_gclr *= shade_factor;
03915         bot_bclr *= shade_factor;
03916     
03917             bot_rsclr *= shade_factor;
03918             bot_gsclr *= shade_factor;
03919             bot_bsclr *= shade_factor;
03920                     }
03921                     
03922 #ifdef DEBUG
03923     if (ipixel == trace_pixel_ptr) {
03924         trace_opcTL = 0.; trace_opcBL = 0.; trace_opcTR = 0.; trace_opcBR = 0.;
03925         trace_rsclrTL=0.; trace_rsclrBL=0.; trace_rsclrTR=0.; trace_rsclrBR=0.;
03926         trace_rclrTL= 0.; trace_rclrBL= 0.; trace_rclrTR= 0.; trace_rclrBR= 0.;
03927         trace_gclrTL= 0.; trace_gclrBL= 0.; trace_gclrTR= 0.; trace_gclrBR= 0.;
03928         trace_bclrTL= 0.; trace_bclrBL= 0.; trace_bclrTR= 0.; trace_bclrBR= 0.;
03929     }
03930 #endif
03931 ;
03932                     
03933        acc_opc = bot_opc * wgtBL;
03934        
03935             acc_rclr = (bot_rclr + bot_rsclr *
03936                          ((float)1.0 - shadow_pixel->opcflt)) * wgtBL;
03937             acc_gclr = (bot_gclr + bot_gsclr *
03938                          ((float)1.0 - shadow_pixel->opcflt)) * wgtBL;
03939             acc_bclr = (bot_bclr + bot_bsclr *
03940                          ((float)1.0 - shadow_pixel->opcflt)) * wgtBL;
03941        
03942 #ifdef DEBUG
03943     if (ipixel == trace_pixel_ptr) {
03944         trace_opcBL = bot_opc;
03945         trace_rclrBL = bot_rclr;
03946                      trace_gclrBL = bot_gclr;
03947                      trace_bclrBL = bot_bclr;
03948         
03949     }
03950 #endif
03951 ;
03952                     
03953     
03954             opac_param = VoxelField(botRLEdata, param0_offset, param0_size);
03955             opacity = param0_table[opac_param];
03956             if (param1_size != 0) {
03957                 opac_param = VoxelField(botRLEdata, param1_offset, param1_size);
03958                 opacity *= param1_table[opac_param];
03959                 if (param2_size != 0) {
03960                     opac_param = VoxelField(botRLEdata, param2_offset, param2_size);
03961                     opacity *= param2_table[opac_param];
03962                 }
03963             }
03964             if (opacity > min_opacity) {
03965                 opacity_int = opacity*255.;
03966                 bot_opc = opac_correct[opacity_int];
03967             } else {
03968                 bot_opc = (float)0.;
03969             };
03970     
03971     
03972     shade_index=num_materials*3*ShortField(botRLEdata,norm_offset);
03973     weight_index = num_materials * ByteField(botRLEdata, wgt_offset);
03974     
03975         
03976         
03977     bot_rclr = 
03978     shade_table[shade_index + 3*0 + 0] * 
03979         ((num_materials > 1) ? weight_table[weight_index] : (float)1.0);
03980         
03981     bot_gclr = 
03982     shade_table[shade_index + 3*0 + 1] * 
03983         ((num_materials > 1) ? weight_table[weight_index] : (float)1.0);
03984         
03985     bot_bclr = 
03986     shade_table[shade_index + 3*0 + 2] * 
03987         ((num_materials > 1) ? weight_table[weight_index] : (float)1.0);
03988         
03989         bot_rsclr = 
03990     shadow_table[shade_index + 3*0 + 0] * 
03991         ((num_materials > 1) ? weight_table[weight_index] : (float)1.0);
03992         
03993         bot_gsclr = 
03994     shadow_table[shade_index + 3*0 + 1] * 
03995         ((num_materials > 1) ? weight_table[weight_index] : (float)1.0);
03996         
03997         bot_bsclr = 
03998     shadow_table[shade_index + 3*0 + 2] * 
03999         ((num_materials > 1) ? weight_table[weight_index] : (float)1.0);
04000         for (m = 1; m < num_materials; m++) {
04001              
04002         
04003     bot_rclr += 
04004     shade_table[shade_index + 3*m + 0] * 
04005         weight_table[weight_index + m];
04006         
04007     bot_gclr += 
04008     shade_table[shade_index + 3*m + 1] * 
04009         weight_table[weight_index + m];
04010         
04011     bot_bclr += 
04012     shade_table[shade_index + 3*m + 2] * 
04013         weight_table[weight_index + m];
04014         
04015         bot_rsclr += 
04016     shadow_table[shade_index + 3*m + 0] * 
04017         weight_table[weight_index + m];
04018         
04019         bot_gsclr += 
04020     shadow_table[shade_index + 3*m + 1] * 
04021         weight_table[weight_index + m];
04022         
04023         bot_bsclr += 
04024     shadow_table[shade_index + 3*m + 2] * 
04025         weight_table[weight_index + m];
04026         };
04027     shade_factor = bot_opc * slice_depth_cueing;
04028     
04029         bot_rclr *= shade_factor;
04030         bot_gclr *= shade_factor;
04031         bot_bclr *= shade_factor;
04032     
04033             bot_rsclr *= shade_factor;
04034             bot_gsclr *= shade_factor;
04035             bot_bsclr *= shade_factor;
04036                     
04037        acc_opc += bot_opc * wgtBR;
04038        
04039             acc_rclr += (bot_rclr + bot_rsclr *
04040                          ((float)1.0 - shadow_pixel->opcflt)) * wgtBR;
04041             acc_gclr += (bot_gclr + bot_gsclr *
04042                          ((float)1.0 - shadow_pixel->opcflt)) * wgtBR;
04043             acc_bclr += (bot_bclr + bot_bsclr *
04044                          ((float)1.0 - shadow_pixel->opcflt)) * wgtBR;
04045        
04046 #ifdef DEBUG
04047     if (ipixel == trace_pixel_ptr) {
04048         trace_opcBR = bot_opc;
04049         trace_rclrBR = bot_rclr;
04050                      trace_gclrBR = bot_gclr;
04051                      trace_bclrBR = bot_bclr;
04052         
04053     }
04054 #endif
04055 ;
04056                     
04057         COUNT_RESAMPLE;
04058         if (acc_opc > min_opacity) {
04059             COUNT_COMPOSITE;
04060             iopc = ipixel->opcflt;
04061 #           ifndef SKIP_ERT
04062                 ASSERT(iopc < max_opacity);
04063 #           endif
04064             iopc_inv = (float)1. - iopc;
04065             
04066         ipixel->rclrflt += acc_rclr * iopc_inv;
04067         ipixel->gclrflt += acc_gclr * iopc_inv;
04068         ipixel->bclrflt += acc_bclr * iopc_inv;
04069             iopc += acc_opc * iopc_inv;
04070             ipixel->opcflt = iopc;
04071             
04072 #ifdef DEBUG
04073     if (ipixel == trace_pixel_ptr) {
04074 #ifdef COMPUTE_SHADOW_BUFFER
04075         printf("{%3d}  %3d %3d", k, icount-i-count, j);
04076 #else
04077         printf("[%3d]  %3d %3d", k, icount-i-count, j);
04078 #endif
04079         printf("  %3.0f %3.0f %3.0f",trace_opcTL*255.,trace_rclrTL,wgtTL*100.);
04080         printf("  %3.0f %3.0f %3.0f",trace_opcBL*255.,trace_rclrBL,wgtBL*100.);
04081         printf("  %3.0f %3.0f %3.0f",trace_opcTR*255.,trace_rclrTR,wgtTR*100.);
04082         printf("  %3.0f %3.0f %3.0f",trace_opcBR*255.,trace_rclrBR,wgtBR*100.);
04083         printf("  %3.0f %3.0f\n", iopc*255., 
04084                ipixel->rclrflt);
04085         
04086         printf("              ");
04087         printf("      %3.0f    ",trace_rsclrTL);
04088         printf("      %3.0f    ",trace_rsclrBL);
04089         printf("      %3.0f    ",trace_rsclrTR);
04090         printf("      %3.0f    ",trace_rsclrBR);
04091         printf("  %3.0f\n", shadow_pixel->opcflt * 255.);
04092         
04093         printf("              ");
04094         printf("      %3.0f    ",trace_gclrTL);
04095         printf("      %3.0f    ",trace_gclrBL);
04096         printf("      %3.0f    ",trace_gclrTR);
04097         printf("      %3.0f    ",trace_gclrBR);
04098         printf("      %3.0f\n", ipixel->gclrflt);
04099         printf("              ");
04100         printf("      %3.0f    ",trace_bclrTL);
04101         printf("      %3.0f    ",trace_bclrBL);
04102         printf("      %3.0f    ",trace_bclrTR);
04103         printf("      %3.0f    ",trace_bclrBR);
04104         printf("      %3.0f\n", ipixel->bclrflt);
04105     }
04106 #endif /* DEBUG */
04107 ;
04108 #           ifndef SKIP_ERT
04109                 if (iopc >= max_opacity) {
04110                     ASSERT(ipixel->lnk == 0);
04111                     ipixel->lnk = 1;
04112                 }
04113 #           endif
04114         };
04115                     ipixel += 1; shadow_pixel += 1;
04116                     topRLEdata += 1 * voxel_istride;
04117                     botRLEdata += 1 * voxel_istride;
04118                     count--;
04119                     SET_VOXELS_LOADED;
04120                 }
04121                 break;
04122             case TOP_NONZERO__BOT_NONZERO:
04123                 /* first pixel: top-left and bottom-right voxels contribute */
04124                 if (!voxels_loaded) {
04125                     
04126     
04127             opac_param = VoxelField(topRLEdata - voxel_istride, param0_offset, param0_size);
04128             opacity = param0_table[opac_param];
04129             if (param1_size != 0) {
04130                 opac_param = VoxelField(topRLEdata - voxel_istride, param1_offset, param1_size);
04131                 opacity *= param1_table[opac_param];
04132                 if (param2_size != 0) {
04133                     opac_param = VoxelField(topRLEdata - voxel_istride, param2_offset, param2_size);
04134                     opacity *= param2_table[opac_param];
04135                 }
04136             }
04137             if (opacity > min_opacity) {
04138                 opacity_int = opacity*255.;
04139                 top_opc = opac_correct[opacity_int];
04140             } else {
04141                 top_opc = (float)0.;
04142             };
04143     
04144     
04145     shade_index=num_materials*3*ShortField(topRLEdata - voxel_istride,norm_offset);
04146     weight_index = num_materials * ByteField(topRLEdata - voxel_istride, wgt_offset);
04147     
04148         
04149         
04150     top_rclr = 
04151     shade_table[shade_index + 3*0 + 0] * 
04152         ((num_materials > 1) ? weight_table[weight_index] : (float)1.0);
04153         
04154     top_gclr = 
04155     shade_table[shade_index + 3*0 + 1] * 
04156         ((num_materials > 1) ? weight_table[weight_index] : (float)1.0);
04157         
04158     top_bclr = 
04159     shade_table[shade_index + 3*0 + 2] * 
04160         ((num_materials > 1) ? weight_table[weight_index] : (float)1.0);
04161         
04162         top_rsclr = 
04163     shadow_table[shade_index + 3*0 + 0] * 
04164         ((num_materials > 1) ? weight_table[weight_index] : (float)1.0);
04165         
04166         top_gsclr = 
04167     shadow_table[shade_index + 3*0 + 1] * 
04168         ((num_materials > 1) ? weight_table[weight_index] : (float)1.0);
04169         
04170         top_bsclr = 
04171     shadow_table[shade_index + 3*0 + 2] * 
04172         ((num_materials > 1) ? weight_table[weight_index] : (float)1.0);
04173         for (m = 1; m < num_materials; m++) {
04174              
04175         
04176     top_rclr += 
04177     shade_table[shade_index + 3*m + 0] * 
04178         weight_table[weight_index + m];
04179         
04180     top_gclr += 
04181     shade_table[shade_index + 3*m + 1] * 
04182         weight_table[weight_index + m];
04183         
04184     top_bclr += 
04185     shade_table[shade_index + 3*m + 2] * 
04186         weight_table[weight_index + m];
04187         
04188         top_rsclr += 
04189     shadow_table[shade_index + 3*m + 0] * 
04190         weight_table[weight_index + m];
04191         
04192         top_gsclr += 
04193     shadow_table[shade_index + 3*m + 1] * 
04194         weight_table[weight_index + m];
04195         
04196         top_bsclr += 
04197     shadow_table[shade_index + 3*m + 2] * 
04198         weight_table[weight_index + m];
04199         };
04200     shade_factor = top_opc * slice_depth_cueing;
04201     
04202         top_rclr *= shade_factor;
04203         top_gclr *= shade_factor;
04204         top_bclr *= shade_factor;
04205     
04206             top_rsclr *= shade_factor;
04207             top_gsclr *= shade_factor;
04208             top_bsclr *= shade_factor;
04209                 }
04210                 
04211 #ifdef DEBUG
04212     if (ipixel == trace_pixel_ptr) {
04213         trace_opcTL = 0.; trace_opcBL = 0.; trace_opcTR = 0.; trace_opcBR = 0.;
04214         trace_rsclrTL=0.; trace_rsclrBL=0.; trace_rsclrTR=0.; trace_rsclrBR=0.;
04215         trace_rclrTL= 0.; trace_rclrBL= 0.; trace_rclrTR= 0.; trace_rclrBR= 0.;
04216         trace_gclrTL= 0.; trace_gclrBL= 0.; trace_gclrTR= 0.; trace_gclrBR= 0.;
04217         trace_bclrTL= 0.; trace_bclrBL= 0.; trace_bclrTR= 0.; trace_bclrBR= 0.;
04218     }
04219 #endif
04220 ;
04221                 
04222        acc_opc = top_opc * wgtTL;
04223        
04224             acc_rclr = (top_rclr + top_rsclr *
04225                          ((float)1.0 - shadow_pixel->opcflt)) * wgtTL;
04226             acc_gclr = (top_gclr + top_gsclr *
04227                          ((float)1.0 - shadow_pixel->opcflt)) * wgtTL;
04228             acc_bclr = (top_bclr + top_bsclr *
04229                          ((float)1.0 - shadow_pixel->opcflt)) * wgtTL;
04230        
04231 #ifdef DEBUG
04232     if (ipixel == trace_pixel_ptr) {
04233         trace_opcTL = top_opc;
04234         trace_rclrTL = top_rclr;
04235                      trace_gclrTL = top_gclr;
04236                      trace_bclrTL = top_bclr;
04237         
04238     }
04239 #endif
04240 ;
04241                 
04242     
04243             opac_param = VoxelField(botRLEdata, param0_offset, param0_size);
04244             opacity = param0_table[opac_param];
04245             if (param1_size != 0) {
04246                 opac_param = VoxelField(botRLEdata, param1_offset, param1_size);
04247                 opacity *= param1_table[opac_param];
04248                 if (param2_size != 0) {
04249                     opac_param = VoxelField(botRLEdata, param2_offset, param2_size);
04250                     opacity *= param2_table[opac_param];
04251                 }
04252             }
04253             if (opacity > min_opacity) {
04254                 opacity_int = opacity*255.;
04255                 bot_opc = opac_correct[opacity_int];
04256             } else {
04257                 bot_opc = (float)0.;
04258             };
04259     
04260     
04261     shade_index=num_materials*3*ShortField(botRLEdata,norm_offset);
04262     weight_index = num_materials * ByteField(botRLEdata, wgt_offset);
04263     
04264         
04265         
04266     bot_rclr = 
04267     shade_table[shade_index + 3*0 + 0] * 
04268         ((num_materials > 1) ? weight_table[weight_index] : (float)1.0);
04269         
04270     bot_gclr = 
04271     shade_table[shade_index + 3*0 + 1] * 
04272         ((num_materials > 1) ? weight_table[weight_index] : (float)1.0);
04273         
04274     bot_bclr = 
04275     shade_table[shade_index + 3*0 + 2] * 
04276         ((num_materials > 1) ? weight_table[weight_index] : (float)1.0);
04277         
04278         bot_rsclr = 
04279     shadow_table[shade_index + 3*0 + 0] * 
04280         ((num_materials > 1) ? weight_table[weight_index] : (float)1.0);
04281         
04282         bot_gsclr = 
04283     shadow_table[shade_index + 3*0 + 1] * 
04284         ((num_materials > 1) ? weight_table[weight_index] : (float)1.0);
04285         
04286         bot_bsclr = 
04287     shadow_table[shade_index + 3*0 + 2] * 
04288         ((num_materials > 1) ? weight_table[weight_index] : (float)1.0);
04289         for (m = 1; m < num_materials; m++) {
04290              
04291         
04292     bot_rclr += 
04293     shade_table[shade_index + 3*m + 0] * 
04294         weight_table[weight_index + m];
04295         
04296     bot_gclr += 
04297     shade_table[shade_index + 3*m + 1] * 
04298         weight_table[weight_index + m];
04299         
04300     bot_bclr += 
04301     shade_table[shade_index + 3*m + 2] * 
04302         weight_table[weight_index + m];
04303         
04304         bot_rsclr += 
04305     shadow_table[shade_index + 3*m + 0] * 
04306         weight_table[weight_index + m];
04307         
04308         bot_gsclr += 
04309     shadow_table[shade_index + 3*m + 1] * 
04310         weight_table[weight_index + m];
04311         
04312         bot_bsclr += 
04313     shadow_table[shade_index + 3*m + 2] * 
04314         weight_table[weight_index + m];
04315         };
04316     shade_factor = bot_opc * slice_depth_cueing;
04317     
04318         bot_rclr *= shade_factor;
04319         bot_gclr *= shade_factor;
04320         bot_bclr *= shade_factor;
04321     
04322             bot_rsclr *= shade_factor;
04323             bot_gsclr *= shade_factor;
04324             bot_bsclr *= shade_factor;
04325                 
04326        acc_opc += bot_opc * wgtBR;
04327        
04328             acc_rclr += (bot_rclr + bot_rsclr *
04329                          ((float)1.0 - shadow_pixel->opcflt)) * wgtBR;
04330             acc_gclr += (bot_gclr + bot_gsclr *
04331                          ((float)1.0 - shadow_pixel->opcflt)) * wgtBR;
04332             acc_bclr += (bot_bclr + bot_bsclr *
04333                          ((float)1.0 - shadow_pixel->opcflt)) * wgtBR;
04334        
04335 #ifdef DEBUG
04336     if (ipixel == trace_pixel_ptr) {
04337         trace_opcBR = bot_opc;
04338         trace_rclrBR = bot_rclr;
04339                      trace_gclrBR = bot_gclr;
04340                      trace_bclrBR = bot_bclr;
04341         
04342     }
04343 #endif
04344 ;
04345                 
04346         COUNT_RESAMPLE;
04347         if (acc_opc > min_opacity) {
04348             COUNT_COMPOSITE;
04349             iopc = ipixel->opcflt;
04350 #           ifndef SKIP_ERT
04351                 ASSERT(iopc < max_opacity);
04352 #           endif
04353             iopc_inv = (float)1. - iopc;
04354             
04355         ipixel->rclrflt += acc_rclr * iopc_inv;
04356         ipixel->gclrflt += acc_gclr * iopc_inv;
04357         ipixel->bclrflt += acc_bclr * iopc_inv;
04358             iopc += acc_opc * iopc_inv;
04359             ipixel->opcflt = iopc;
04360             
04361 #ifdef DEBUG
04362     if (ipixel == trace_pixel_ptr) {
04363 #ifdef COMPUTE_SHADOW_BUFFER
04364         printf("{%3d}  %3d %3d", k, icount-i-count, j);
04365 #else
04366         printf("[%3d]  %3d %3d", k, icount-i-count, j);
04367 #endif
04368         printf("  %3.0f %3.0f %3.0f",trace_opcTL*255.,trace_rclrTL,wgtTL*100.);
04369         printf("  %3.0f %3.0f %3.0f",trace_opcBL*255.,trace_rclrBL,wgtBL*100.);
04370         printf("  %3.0f %3.0f %3.0f",trace_opcTR*255.,trace_rclrTR,wgtTR*100.);
04371         printf("  %3.0f %3.0f %3.0f",trace_opcBR*255.,trace_rclrBR,wgtBR*100.);
04372         printf("  %3.0f %3.0f\n", iopc*255., 
04373                ipixel->rclrflt);
04374         
04375         printf("              ");
04376         printf("      %3.0f    ",trace_rsclrTL);
04377         printf("      %3.0f    ",trace_rsclrBL);
04378         printf("      %3.0f    ",trace_rsclrTR);
04379         printf("      %3.0f    ",trace_rsclrBR);
04380         printf("  %3.0f\n", shadow_pixel->opcflt * 255.);
04381         
04382         printf("              ");
04383         printf("      %3.0f    ",trace_gclrTL);
04384         printf("      %3.0f    ",trace_gclrBL);
04385         printf("      %3.0f    ",trace_gclrTR);
04386         printf("      %3.0f    ",trace_gclrBR);
04387         printf("      %3.0f\n", ipixel->gclrflt);
04388         printf("              ");
04389         printf("      %3.0f    ",trace_bclrTL);
04390         printf("      %3.0f    ",trace_bclrBL);
04391         printf("      %3.0f    ",trace_bclrTR);
04392         printf("      %3.0f    ",trace_bclrBR);
04393         printf("      %3.0f\n", ipixel->bclrflt);
04394     }
04395 #endif /* DEBUG */
04396 ;
04397 #           ifndef SKIP_ERT
04398                 if (iopc >= max_opacity) {
04399                     ASSERT(ipixel->lnk == 0);
04400                     ipixel->lnk = 1;
04401                 }
04402 #           endif
04403         };
04404                 ipixel += 1; shadow_pixel += 1;
04405                 topRLEdata += 1 * voxel_istride;
04406                 botRLEdata += 1 * voxel_istride;
04407                 count--;
04408                 SET_VOXELS_LOADED;
04409 
04410                 /* do the rest of the pixels in this run;
04411                    bottom-left and bottom-right voxels contribute */
04412                 while (count > 0) {
04413                     if (PIXEL_IS_OPAQUE(ipixel))
04414                         break;
04415                     if (!voxels_loaded) {
04416                         
04417     
04418             opac_param = VoxelField(botRLEdata - voxel_istride, param0_offset, param0_size);
04419             opacity = param0_table[opac_param];
04420             if (param1_size != 0) {
04421                 opac_param = VoxelField(botRLEdata - voxel_istride, param1_offset, param1_size);
04422                 opacity *= param1_table[opac_param];
04423                 if (param2_size != 0) {
04424                     opac_param = VoxelField(botRLEdata - voxel_istride, param2_offset, param2_size);
04425                     opacity *= param2_table[opac_param];
04426                 }
04427             }
04428             if (opacity > min_opacity) {
04429                 opacity_int = opacity*255.;
04430                 bot_opc = opac_correct[opacity_int];
04431             } else {
04432                 bot_opc = (float)0.;
04433             };
04434     
04435     
04436     shade_index=num_materials*3*ShortField(botRLEdata - voxel_istride,norm_offset);
04437     weight_index = num_materials * ByteField(botRLEdata - voxel_istride, wgt_offset);
04438     
04439         
04440         
04441     bot_rclr = 
04442     shade_table[shade_index + 3*0 + 0] * 
04443         ((num_materials > 1) ? weight_table[weight_index] : (float)1.0);
04444         
04445     bot_gclr = 
04446     shade_table[shade_index + 3*0 + 1] * 
04447         ((num_materials > 1) ? weight_table[weight_index] : (float)1.0);
04448         
04449     bot_bclr = 
04450     shade_table[shade_index + 3*0 + 2] * 
04451         ((num_materials > 1) ? weight_table[weight_index] : (float)1.0);
04452         
04453         bot_rsclr = 
04454     shadow_table[shade_index + 3*0 + 0] * 
04455         ((num_materials > 1) ? weight_table[weight_index] : (float)1.0);
04456         
04457         bot_gsclr = 
04458     shadow_table[shade_index + 3*0 + 1] * 
04459         ((num_materials > 1) ? weight_table[weight_index] : (float)1.0);
04460         
04461         bot_bsclr = 
04462     shadow_table[shade_index + 3*0 + 2] * 
04463         ((num_materials > 1) ? weight_table[weight_index] : (float)1.0);
04464         for (m = 1; m < num_materials; m++) {
04465              
04466         
04467     bot_rclr += 
04468     shade_table[shade_index + 3*m + 0] * 
04469         weight_table[weight_index + m];
04470         
04471     bot_gclr += 
04472     shade_table[shade_index + 3*m + 1] * 
04473         weight_table[weight_index + m];
04474         
04475     bot_bclr += 
04476     shade_table[shade_index + 3*m + 2] * 
04477         weight_table[weight_index + m];
04478         
04479         bot_rsclr += 
04480     shadow_table[shade_index + 3*m + 0] * 
04481         weight_table[weight_index + m];
04482         
04483         bot_gsclr += 
04484     shadow_table[shade_index + 3*m + 1] * 
04485         weight_table[weight_index + m];
04486         
04487         bot_bsclr += 
04488     shadow_table[shade_index + 3*m + 2] * 
04489         weight_table[weight_index + m];
04490         };
04491     shade_factor = bot_opc * slice_depth_cueing;
04492     
04493         bot_rclr *= shade_factor;
04494         bot_gclr *= shade_factor;
04495         bot_bclr *= shade_factor;
04496     
04497             bot_rsclr *= shade_factor;
04498             bot_gsclr *= shade_factor;
04499             bot_bsclr *= shade_factor;
04500                     }
04501                     
04502 #ifdef DEBUG
04503     if (ipixel == trace_pixel_ptr) {
04504         trace_opcTL = 0.; trace_opcBL = 0.; trace_opcTR = 0.; trace_opcBR = 0.;
04505         trace_rsclrTL=0.; trace_rsclrBL=0.; trace_rsclrTR=0.; trace_rsclrBR=0.;
04506         trace_rclrTL= 0.; trace_rclrBL= 0.; trace_rclrTR= 0.; trace_rclrBR= 0.;
04507         trace_gclrTL= 0.; trace_gclrBL= 0.; trace_gclrTR= 0.; trace_gclrBR= 0.;
04508         trace_bclrTL= 0.; trace_bclrBL= 0.; trace_bclrTR= 0.; trace_bclrBR= 0.;
04509     }
04510 #endif
04511 ;
04512                     
04513        acc_opc = bot_opc * wgtBL;
04514        
04515             acc_rclr = (bot_rclr + bot_rsclr *
04516                          ((float)1.0 - shadow_pixel->opcflt)) * wgtBL;
04517             acc_gclr = (bot_gclr + bot_gsclr *
04518                          ((float)1.0 - shadow_pixel->opcflt)) * wgtBL;
04519             acc_bclr = (bot_bclr + bot_bsclr *
04520                          ((float)1.0 - shadow_pixel->opcflt)) * wgtBL;
04521        
04522 #ifdef DEBUG
04523     if (ipixel == trace_pixel_ptr) {
04524         trace_opcBL = bot_opc;
04525         trace_rclrBL = bot_rclr;
04526                      trace_gclrBL = bot_gclr;
04527                      trace_bclrBL = bot_bclr;
04528         
04529     }
04530 #endif
04531 ;
04532                     
04533     
04534             opac_param = VoxelField(botRLEdata, param0_offset, param0_size);
04535             opacity = param0_table[opac_param];
04536             if (param1_size != 0) {
04537                 opac_param = VoxelField(botRLEdata, param1_offset, param1_size);
04538                 opacity *= param1_table[opac_param];
04539                 if (param2_size != 0) {
04540                     opac_param = VoxelField(botRLEdata, param2_offset, param2_size);
04541                     opacity *= param2_table[opac_param];
04542                 }
04543             }
04544             if (opacity > min_opacity) {
04545                 opacity_int = opacity*255.;
04546                 bot_opc = opac_correct[opacity_int];
04547             } else {
04548                 bot_opc = (float)0.;
04549             };
04550     
04551     
04552     shade_index=num_materials*3*ShortField(botRLEdata,norm_offset);
04553     weight_index = num_materials * ByteField(botRLEdata, wgt_offset);
04554     
04555         
04556         
04557     bot_rclr = 
04558     shade_table[shade_index + 3*0 + 0] * 
04559         ((num_materials > 1) ? weight_table[weight_index] : (float)1.0);
04560         
04561     bot_gclr = 
04562     shade_table[shade_index + 3*0 + 1] * 
04563         ((num_materials > 1) ? weight_table[weight_index] : (float)1.0);
04564         
04565     bot_bclr = 
04566     shade_table[shade_index + 3*0 + 2] * 
04567         ((num_materials > 1) ? weight_table[weight_index] : (float)1.0);
04568         
04569         bot_rsclr = 
04570     shadow_table[shade_index + 3*0 + 0] * 
04571         ((num_materials > 1) ? weight_table[weight_index] : (float)1.0);
04572         
04573         bot_gsclr = 
04574     shadow_table[shade_index + 3*0 + 1] * 
04575         ((num_materials > 1) ? weight_table[weight_index] : (float)1.0);
04576         
04577         bot_bsclr = 
04578     shadow_table[shade_index + 3*0 + 2] * 
04579         ((num_materials > 1) ? weight_table[weight_index] : (float)1.0);
04580         for (m = 1; m < num_materials; m++) {
04581              
04582         
04583     bot_rclr += 
04584     shade_table[shade_index + 3*m + 0] * 
04585         weight_table[weight_index + m];
04586         
04587     bot_gclr += 
04588     shade_table[shade_index + 3*m + 1] * 
04589         weight_table[weight_index + m];
04590         
04591     bot_bclr += 
04592     shade_table[shade_index + 3*m + 2] * 
04593         weight_table[weight_index + m];
04594         
04595         bot_rsclr += 
04596     shadow_table[shade_index + 3*m + 0] * 
04597         weight_table[weight_index + m];
04598         
04599         bot_gsclr += 
04600     shadow_table[shade_index + 3*m + 1] * 
04601         weight_table[weight_index + m];
04602         
04603         bot_bsclr += 
04604     shadow_table[shade_index + 3*m + 2] * 
04605         weight_table[weight_index + m];
04606         };
04607     shade_factor = bot_opc * slice_depth_cueing;
04608     
04609         bot_rclr *= shade_factor;
04610         bot_gclr *= shade_factor;
04611         bot_bclr *= shade_factor;
04612     
04613             bot_rsclr *= shade_factor;
04614             bot_gsclr *= shade_factor;
04615             bot_bsclr *= shade_factor;
04616                     
04617        acc_opc += bot_opc * wgtBR;
04618        
04619             acc_rclr += (bot_rclr + bot_rsclr *
04620                          ((float)1.0 - shadow_pixel->opcflt)) * wgtBR;
04621             acc_gclr += (bot_gclr + bot_gsclr *
04622                          ((float)1.0 - shadow_pixel->opcflt)) * wgtBR;
04623             acc_bclr += (bot_bclr + bot_bsclr *
04624                          ((float)1.0 - shadow_pixel->opcflt)) * wgtBR;
04625        
04626 #ifdef DEBUG
04627     if (ipixel == trace_pixel_ptr) {
04628         trace_opcBR = bot_opc;
04629         trace_rclrBR = bot_rclr;
04630                      trace_gclrBR = bot_gclr;
04631                      trace_bclrBR = bot_bclr;
04632         
04633     }
04634 #endif
04635 ;
04636                     
04637         COUNT_RESAMPLE;
04638         if (acc_opc > min_opacity) {
04639             COUNT_COMPOSITE;
04640             iopc = ipixel->opcflt;
04641 #           ifndef SKIP_ERT
04642                 ASSERT(iopc < max_opacity);
04643 #           endif
04644             iopc_inv = (float)1. - iopc;
04645             
04646         ipixel->rclrflt += acc_rclr * iopc_inv;
04647         ipixel->gclrflt += acc_gclr * iopc_inv;
04648         ipixel->bclrflt += acc_bclr * iopc_inv;
04649             iopc += acc_opc * iopc_inv;
04650             ipixel->opcflt = iopc;
04651             
04652 #ifdef DEBUG
04653     if (ipixel == trace_pixel_ptr) {
04654 #ifdef COMPUTE_SHADOW_BUFFER
04655         printf("{%3d}  %3d %3d", k, icount-i-count, j);
04656 #else
04657         printf("[%3d]  %3d %3d", k, icount-i-count, j);
04658 #endif
04659         printf("  %3.0f %3.0f %3.0f",trace_opcTL*255.,trace_rclrTL,wgtTL*100.);
04660         printf("  %3.0f %3.0f %3.0f",trace_opcBL*255.,trace_rclrBL,wgtBL*100.);
04661         printf("  %3.0f %3.0f %3.0f",trace_opcTR*255.,trace_rclrTR,wgtTR*100.);
04662         printf("  %3.0f %3.0f %3.0f",trace_opcBR*255.,trace_rclrBR,wgtBR*100.);
04663         printf("  %3.0f %3.0f\n", iopc*255., 
04664                ipixel->rclrflt);
04665         
04666         printf("              ");
04667         printf("      %3.0f    ",trace_rsclrTL);
04668         printf("      %3.0f    ",trace_rsclrBL);
04669         printf("      %3.0f    ",trace_rsclrTR);
04670         printf("      %3.0f    ",trace_rsclrBR);
04671         printf("  %3.0f\n", shadow_pixel->opcflt * 255.);
04672         
04673         printf("              ");
04674         printf("      %3.0f    ",trace_gclrTL);
04675         printf("      %3.0f    ",trace_gclrBL);
04676         printf("      %3.0f    ",trace_gclrTR);
04677         printf("      %3.0f    ",trace_gclrBR);
04678         printf("      %3.0f\n", ipixel->gclrflt);
04679         printf("              ");
04680         printf("      %3.0f    ",trace_bclrTL);
04681         printf("      %3.0f    ",trace_bclrBL);
04682         printf("      %3.0f    ",trace_bclrTR);
04683         printf("      %3.0f    ",trace_bclrBR);
04684         printf("      %3.0f\n", ipixel->bclrflt);
04685     }
04686 #endif /* DEBUG */
04687 ;
04688 #           ifndef SKIP_ERT
04689                 if (iopc >= max_opacity) {
04690                     ASSERT(ipixel->lnk == 0);
04691                     ipixel->lnk = 1;
04692                 }
04693 #           endif
04694         };
04695                     ipixel += 1; shadow_pixel += 1;
04696                     topRLEdata += 1 * voxel_istride;
04697                     botRLEdata += 1 * voxel_istride;
04698                     count--;
04699                     SET_VOXELS_LOADED;
04700                 }
04701                 break;
04702             case BOT_NONZERO__BOT_NONZERO:
04703                 /* do the pixels in this run; bottom-left and
04704                    bottom-right voxels contribute */
04705                 while (count > 0) {
04706                     if (PIXEL_IS_OPAQUE(ipixel))
04707                         break;
04708                     if (!voxels_loaded) {
04709                         
04710     
04711             opac_param = VoxelField(botRLEdata - voxel_istride, param0_offset, param0_size);
04712             opacity = param0_table[opac_param];
04713             if (param1_size != 0) {
04714                 opac_param = VoxelField(botRLEdata - voxel_istride, param1_offset, param1_size);
04715                 opacity *= param1_table[opac_param];
04716                 if (param2_size != 0) {
04717                     opac_param = VoxelField(botRLEdata - voxel_istride, param2_offset, param2_size);
04718                     opacity *= param2_table[opac_param];
04719                 }
04720             }
04721             if (opacity > min_opacity) {
04722                 opacity_int = opacity*255.;
04723                 bot_opc = opac_correct[opacity_int];
04724             } else {
04725                 bot_opc = (float)0.;
04726             };
04727     
04728     
04729     shade_index=num_materials*3*ShortField(botRLEdata - voxel_istride,norm_offset);
04730     weight_index = num_materials * ByteField(botRLEdata - voxel_istride, wgt_offset);
04731     
04732         
04733         
04734     bot_rclr = 
04735     shade_table[shade_index + 3*0 + 0] * 
04736         ((num_materials > 1) ? weight_table[weight_index] : (float)1.0);
04737         
04738     bot_gclr = 
04739     shade_table[shade_index + 3*0 + 1] * 
04740         ((num_materials > 1) ? weight_table[weight_index] : (float)1.0);
04741         
04742     bot_bclr = 
04743     shade_table[shade_index + 3*0 + 2] * 
04744         ((num_materials > 1) ? weight_table[weight_index] : (float)1.0);
04745         
04746         bot_rsclr = 
04747     shadow_table[shade_index + 3*0 + 0] * 
04748         ((num_materials > 1) ? weight_table[weight_index] : (float)1.0);
04749         
04750         bot_gsclr = 
04751     shadow_table[shade_index + 3*0 + 1] * 
04752         ((num_materials > 1) ? weight_table[weight_index] : (float)1.0);
04753         
04754         bot_bsclr = 
04755     shadow_table[shade_index + 3*0 + 2] * 
04756         ((num_materials > 1) ? weight_table[weight_index] : (float)1.0);
04757         for (m = 1; m < num_materials; m++) {
04758              
04759         
04760     bot_rclr += 
04761     shade_table[shade_index + 3*m + 0] * 
04762         weight_table[weight_index + m];
04763         
04764     bot_gclr += 
04765     shade_table[shade_index + 3*m + 1] * 
04766         weight_table[weight_index + m];
04767         
04768     bot_bclr += 
04769     shade_table[shade_index + 3*m + 2] * 
04770         weight_table[weight_index + m];
04771         
04772         bot_rsclr += 
04773     shadow_table[shade_index + 3*m + 0] * 
04774         weight_table[weight_index + m];
04775         
04776         bot_gsclr += 
04777     shadow_table[shade_index + 3*m + 1] * 
04778         weight_table[weight_index + m];
04779         
04780         bot_bsclr += 
04781     shadow_table[shade_index + 3*m + 2] * 
04782         weight_table[weight_index + m];
04783         };
04784     shade_factor = bot_opc * slice_depth_cueing;
04785     
04786         bot_rclr *= shade_factor;
04787         bot_gclr *= shade_factor;
04788         bot_bclr *= shade_factor;
04789     
04790             bot_rsclr *= shade_factor;
04791             bot_gsclr *= shade_factor;
04792             bot_bsclr *= shade_factor;
04793                     }
04794                     
04795 #ifdef DEBUG
04796     if (ipixel == trace_pixel_ptr) {
04797         trace_opcTL = 0.; trace_opcBL = 0.; trace_opcTR = 0.; trace_opcBR = 0.;
04798         trace_rsclrTL=0.; trace_rsclrBL=0.; trace_rsclrTR=0.; trace_rsclrBR=0.;
04799         trace_rclrTL= 0.; trace_rclrBL= 0.; trace_rclrTR= 0.; trace_rclrBR= 0.;
04800         trace_gclrTL= 0.; trace_gclrBL= 0.; trace_gclrTR= 0.; trace_gclrBR= 0.;
04801         trace_bclrTL= 0.; trace_bclrBL= 0.; trace_bclrTR= 0.; trace_bclrBR= 0.;
04802     }
04803 #endif
04804 ;
04805                     
04806        acc_opc = bot_opc * wgtBL;
04807        
04808             acc_rclr = (bot_rclr + bot_rsclr *
04809                          ((float)1.0 - shadow_pixel->opcflt)) * wgtBL;
04810             acc_gclr = (bot_gclr + bot_gsclr *
04811                          ((float)1.0 - shadow_pixel->opcflt)) * wgtBL;
04812             acc_bclr = (bot_bclr + bot_bsclr *
04813                          ((float)1.0 - shadow_pixel->opcflt)) * wgtBL;
04814        
04815 #ifdef DEBUG
04816     if (ipixel == trace_pixel_ptr) {
04817         trace_opcBL = bot_opc;
04818         trace_rclrBL = bot_rclr;
04819                      trace_gclrBL = bot_gclr;
04820                      trace_bclrBL = bot_bclr;
04821         
04822     }
04823 #endif
04824 ;
04825                     
04826     
04827             opac_param = VoxelField(botRLEdata, param0_offset, param0_size);
04828             opacity = param0_table[opac_param];
04829             if (param1_size != 0) {
04830                 opac_param = VoxelField(botRLEdata, param1_offset, param1_size);
04831                 opacity *= param1_table[opac_param];
04832                 if (param2_size != 0) {
04833                     opac_param = VoxelField(botRLEdata, param2_offset, param2_size);
04834                     opacity *= param2_table[opac_param];
04835                 }
04836             }
04837             if (opacity > min_opacity) {
04838                 opacity_int = opacity*255.;
04839                 bot_opc = opac_correct[opacity_int];
04840             } else {
04841                 bot_opc = (float)0.;
04842             };
04843     
04844     
04845     shade_index=num_materials*3*ShortField(botRLEdata,norm_offset);
04846     weight_index = num_materials * ByteField(botRLEdata, wgt_offset);
04847     
04848         
04849         
04850     bot_rclr = 
04851     shade_table[shade_index + 3*0 + 0] * 
04852         ((num_materials > 1) ? weight_table[weight_index] : (float)1.0);
04853         
04854     bot_gclr = 
04855     shade_table[shade_index + 3*0 + 1] * 
04856         ((num_materials > 1) ? weight_table[weight_index] : (float)1.0);
04857         
04858     bot_bclr = 
04859     shade_table[shade_index + 3*0 + 2] * 
04860         ((num_materials > 1) ? weight_table[weight_index] : (float)1.0);
04861         
04862         bot_rsclr = 
04863     shadow_table[shade_index + 3*0 + 0] * 
04864         ((num_materials > 1) ? weight_table[weight_index] : (float)1.0);
04865         
04866         bot_gsclr = 
04867     shadow_table[shade_index + 3*0 + 1] * 
04868         ((num_materials > 1) ? weight_table[weight_index] : (float)1.0);
04869         
04870         bot_bsclr = 
04871     shadow_table[shade_index + 3*0 + 2] * 
04872         ((num_materials > 1) ? weight_table[weight_index] : (float)1.0);
04873         for (m = 1; m < num_materials; m++) {
04874              
04875         
04876     bot_rclr += 
04877     shade_table[shade_index + 3*m + 0] * 
04878         weight_table[weight_index + m];
04879         
04880     bot_gclr += 
04881     shade_table[shade_index + 3*m + 1] * 
04882         weight_table[weight_index + m];
04883         
04884     bot_bclr += 
04885     shade_table[shade_index + 3*m + 2] * 
04886         weight_table[weight_index + m];
04887         
04888         bot_rsclr += 
04889     shadow_table[shade_index + 3*m + 0] * 
04890         weight_table[weight_index + m];
04891         
04892         bot_gsclr += 
04893     shadow_table[shade_index + 3*m + 1] * 
04894         weight_table[weight_index + m];
04895         
04896         bot_bsclr += 
04897     shadow_table[shade_index + 3*m + 2] * 
04898         weight_table[weight_index + m];
04899         };
04900     shade_factor = bot_opc * slice_depth_cueing;
04901     
04902         bot_rclr *= shade_factor;
04903         bot_gclr *= shade_factor;
04904         bot_bclr *= shade_factor;
04905     
04906             bot_rsclr *= shade_factor;
04907             bot_gsclr *= shade_factor;
04908             bot_bsclr *= shade_factor;
04909                     
04910        acc_opc += bot_opc * wgtBR;
04911        
04912             acc_rclr += (bot_rclr + bot_rsclr *
04913                          ((float)1.0 - shadow_pixel->opcflt)) * wgtBR;
04914             acc_gclr += (bot_gclr + bot_gsclr *
04915                          ((float)1.0 - shadow_pixel->opcflt)) * wgtBR;
04916             acc_bclr += (bot_bclr + bot_bsclr *
04917                          ((float)1.0 - shadow_pixel->opcflt)) * wgtBR;
04918        
04919 #ifdef DEBUG
04920     if (ipixel == trace_pixel_ptr) {
04921         trace_opcBR = bot_opc;
04922         trace_rclrBR = bot_rclr;
04923                      trace_gclrBR = bot_gclr;
04924                      trace_bclrBR = bot_bclr;
04925         
04926     }
04927 #endif
04928 ;
04929                     
04930         COUNT_RESAMPLE;
04931         if (acc_opc > min_opacity) {
04932             COUNT_COMPOSITE;
04933             iopc = ipixel->opcflt;
04934 #           ifndef SKIP_ERT
04935                 ASSERT(iopc < max_opacity);
04936 #           endif
04937             iopc_inv = (float)1. - iopc;
04938             
04939         ipixel->rclrflt += acc_rclr * iopc_inv;
04940         ipixel->gclrflt += acc_gclr * iopc_inv;
04941         ipixel->bclrflt += acc_bclr * iopc_inv;
04942             iopc += acc_opc * iopc_inv;
04943             ipixel->opcflt = iopc;
04944             
04945 #ifdef DEBUG
04946     if (ipixel == trace_pixel_ptr) {
04947 #ifdef COMPUTE_SHADOW_BUFFER
04948         printf("{%3d}  %3d %3d", k, icount-i-count, j);
04949 #else
04950         printf("[%3d]  %3d %3d", k, icount-i-count, j);
04951 #endif
04952         printf("  %3.0f %3.0f %3.0f",trace_opcTL*255.,trace_rclrTL,wgtTL*100.);
04953         printf("  %3.0f %3.0f %3.0f",trace_opcBL*255.,trace_rclrBL,wgtBL*100.);
04954         printf("  %3.0f %3.0f %3.0f",trace_opcTR*255.,trace_rclrTR,wgtTR*100.);
04955         printf("  %3.0f %3.0f %3.0f",trace_opcBR*255.,trace_rclrBR,wgtBR*100.);
04956         printf("  %3.0f %3.0f\n", iopc*255., 
04957                ipixel->rclrflt);
04958         
04959         printf("              ");
04960         printf("      %3.0f    ",trace_rsclrTL);
04961         printf("      %3.0f    ",trace_rsclrBL);
04962         printf("      %3.0f    ",trace_rsclrTR);
04963         printf("      %3.0f    ",trace_rsclrBR);
04964         printf("  %3.0f\n", shadow_pixel->opcflt * 255.);
04965         
04966         printf("              ");
04967         printf("      %3.0f    ",trace_gclrTL);
04968         printf("      %3.0f    ",trace_gclrBL);
04969         printf("      %3.0f    ",trace_gclrTR);
04970         printf("      %3.0f    ",trace_gclrBR);
04971         printf("      %3.0f\n", ipixel->gclrflt);
04972         printf("              ");
04973         printf("      %3.0f    ",trace_bclrTL);
04974         printf("      %3.0f    ",trace_bclrBL);
04975         printf("      %3.0f    ",trace_bclrTR);
04976         printf("      %3.0f    ",trace_bclrBR);
04977         printf("      %3.0f\n", ipixel->bclrflt);
04978     }
04979 #endif /* DEBUG */
04980 ;
04981 #           ifndef SKIP_ERT
04982                 if (iopc >= max_opacity) {
04983                     ASSERT(ipixel->lnk == 0);
04984                     ipixel->lnk = 1;
04985                 }
04986 #           endif
04987         };
04988                     ipixel += 1; shadow_pixel += 1;
04989                     topRLEdata += 1 * voxel_istride;
04990                     botRLEdata += 1 * voxel_istride;
04991                     count--;
04992                     SET_VOXELS_LOADED;
04993                 }
04994                 break;
04995             case ALL_NONZERO__BOT_NONZERO:
04996                 /* first pixel: top-left, bottom-left and bottom-right
04997                    voxels contribute */
04998                 if (!voxels_loaded) {
04999                     
05000     
05001             opac_param = VoxelField(topRLEdata - voxel_istride, param0_offset, param0_size);
05002             opacity = param0_table[opac_param];
05003             if (param1_size != 0) {
05004                 opac_param = VoxelField(topRLEdata - voxel_istride, param1_offset, param1_size);
05005                 opacity *= param1_table[opac_param];
05006                 if (param2_size != 0) {
05007                     opac_param = VoxelField(topRLEdata - voxel_istride, param2_offset, param2_size);
05008                     opacity *= param2_table[opac_param];
05009                 }
05010             }
05011             if (opacity > min_opacity) {
05012                 opacity_int = opacity*255.;
05013                 top_opc = opac_correct[opacity_int];
05014             } else {
05015                 top_opc = (float)0.;
05016             };
05017     
05018     
05019     shade_index=num_materials*3*ShortField(topRLEdata - voxel_istride,norm_offset);
05020     weight_index = num_materials * ByteField(topRLEdata - voxel_istride, wgt_offset);
05021     
05022         
05023         
05024     top_rclr = 
05025     shade_table[shade_index + 3*0 + 0] * 
05026         ((num_materials > 1) ? weight_table[weight_index] : (float)1.0);
05027         
05028     top_gclr = 
05029     shade_table[shade_index + 3*0 + 1] * 
05030         ((num_materials > 1) ? weight_table[weight_index] : (float)1.0);
05031         
05032     top_bclr = 
05033     shade_table[shade_index + 3*0 + 2] * 
05034         ((num_materials > 1) ? weight_table[weight_index] : (float)1.0);
05035         
05036         top_rsclr = 
05037     shadow_table[shade_index + 3*0 + 0] * 
05038         ((num_materials > 1) ? weight_table[weight_index] : (float)1.0);
05039         
05040         top_gsclr = 
05041     shadow_table[shade_index + 3*0 + 1] * 
05042         ((num_materials > 1) ? weight_table[weight_index] : (float)1.0);
05043         
05044         top_bsclr = 
05045     shadow_table[shade_index + 3*0 + 2] * 
05046         ((num_materials > 1) ? weight_table[weight_index] : (float)1.0);
05047         for (m = 1; m < num_materials; m++) {
05048              
05049         
05050     top_rclr += 
05051     shade_table[shade_index + 3*m + 0] * 
05052         weight_table[weight_index + m];
05053         
05054     top_gclr += 
05055     shade_table[shade_index + 3*m + 1] * 
05056         weight_table[weight_index + m];
05057         
05058     top_bclr += 
05059     shade_table[shade_index + 3*m + 2] * 
05060         weight_table[weight_index + m];
05061         
05062         top_rsclr += 
05063     shadow_table[shade_index + 3*m + 0] * 
05064         weight_table[weight_index + m];
05065         
05066         top_gsclr += 
05067     shadow_table[shade_index + 3*m + 1] * 
05068         weight_table[weight_index + m];
05069         
05070         top_bsclr += 
05071     shadow_table[shade_index + 3*m + 2] * 
05072         weight_table[weight_index + m];
05073         };
05074     shade_factor = top_opc * slice_depth_cueing;
05075     
05076         top_rclr *= shade_factor;
05077         top_gclr *= shade_factor;
05078         top_bclr *= shade_factor;
05079     
05080             top_rsclr *= shade_factor;
05081             top_gsclr *= shade_factor;
05082             top_bsclr *= shade_factor;
05083                     
05084     
05085             opac_param = VoxelField(botRLEdata - voxel_istride, param0_offset, param0_size);
05086             opacity = param0_table[opac_param];
05087             if (param1_size != 0) {
05088                 opac_param = VoxelField(botRLEdata - voxel_istride, param1_offset, param1_size);
05089                 opacity *= param1_table[opac_param];
05090                 if (param2_size != 0) {
05091                     opac_param = VoxelField(botRLEdata - voxel_istride, param2_offset, param2_size);
05092                     opacity *= param2_table[opac_param];
05093                 }
05094             }
05095             if (opacity > min_opacity) {
05096                 opacity_int = opacity*255.;
05097                 bot_opc = opac_correct[opacity_int];
05098             } else {
05099                 bot_opc = (float)0.;
05100             };
05101     
05102     
05103     shade_index=num_materials*3*ShortField(botRLEdata - voxel_istride,norm_offset);
05104     weight_index = num_materials * ByteField(botRLEdata - voxel_istride, wgt_offset);
05105     
05106         
05107         
05108     bot_rclr = 
05109     shade_table[shade_index + 3*0 + 0] * 
05110         ((num_materials > 1) ? weight_table[weight_index] : (float)1.0);
05111         
05112     bot_gclr = 
05113     shade_table[shade_index + 3*0 + 1] * 
05114         ((num_materials > 1) ? weight_table[weight_index] : (float)1.0);
05115         
05116     bot_bclr = 
05117     shade_table[shade_index + 3*0 + 2] * 
05118         ((num_materials > 1) ? weight_table[weight_index] : (float)1.0);
05119         
05120         bot_rsclr = 
05121     shadow_table[shade_index + 3*0 + 0] * 
05122         ((num_materials > 1) ? weight_table[weight_index] : (float)1.0);
05123         
05124         bot_gsclr = 
05125     shadow_table[shade_index + 3*0 + 1] * 
05126         ((num_materials > 1) ? weight_table[weight_index] : (float)1.0);
05127         
05128         bot_bsclr = 
05129     shadow_table[shade_index + 3*0 + 2] * 
05130         ((num_materials > 1) ? weight_table[weight_index] : (float)1.0);
05131         for (m = 1; m < num_materials; m++) {
05132              
05133         
05134     bot_rclr += 
05135     shade_table[shade_index + 3*m + 0] * 
05136         weight_table[weight_index + m];
05137         
05138     bot_gclr += 
05139     shade_table[shade_index + 3*m + 1] * 
05140         weight_table[weight_index + m];
05141         
05142     bot_bclr += 
05143     shade_table[shade_index + 3*m + 2] * 
05144         weight_table[weight_index + m];
05145         
05146         bot_rsclr += 
05147     shadow_table[shade_index + 3*m + 0] * 
05148         weight_table[weight_index + m];
05149         
05150         bot_gsclr += 
05151     shadow_table[shade_index + 3*m + 1] * 
05152         weight_table[weight_index + m];
05153         
05154         bot_bsclr += 
05155     shadow_table[shade_index + 3*m + 2] * 
05156         weight_table[weight_index + m];
05157         };
05158     shade_factor = bot_opc * slice_depth_cueing;
05159     
05160         bot_rclr *= shade_factor;
05161         bot_gclr *= shade_factor;
05162         bot_bclr *= shade_factor;
05163     
05164             bot_rsclr *= shade_factor;
05165             bot_gsclr *= shade_factor;
05166             bot_bsclr *= shade_factor;
05167                 }
05168                 
05169 #ifdef DEBUG
05170     if (ipixel == trace_pixel_ptr) {
05171         trace_opcTL = 0.; trace_opcBL = 0.; trace_opcTR = 0.; trace_opcBR = 0.;
05172         trace_rsclrTL=0.; trace_rsclrBL=0.; trace_rsclrTR=0.; trace_rsclrBR=0.;
05173         trace_rclrTL= 0.; trace_rclrBL= 0.; trace_rclrTR= 0.; trace_rclrBR= 0.;
05174         trace_gclrTL= 0.; trace_gclrBL= 0.; trace_gclrTR= 0.; trace_gclrBR= 0.;
05175         trace_bclrTL= 0.; trace_bclrBL= 0.; trace_bclrTR= 0.; trace_bclrBR= 0.;
05176     }
05177 #endif
05178 ;
05179                 
05180        acc_opc = top_opc * wgtTL;
05181        
05182             acc_rclr = (top_rclr + top_rsclr *
05183                          ((float)1.0 - shadow_pixel->opcflt)) * wgtTL;
05184             acc_gclr = (top_gclr + top_gsclr *
05185                          ((float)1.0 - shadow_pixel->opcflt)) * wgtTL;
05186             acc_bclr = (top_bclr + top_bsclr *
05187                          ((float)1.0 - shadow_pixel->opcflt)) * wgtTL;
05188        
05189 #ifdef DEBUG
05190     if (ipixel == trace_pixel_ptr) {
05191         trace_opcTL = top_opc;
05192         trace_rclrTL = top_rclr;
05193                      trace_gclrTL = top_gclr;
05194                      trace_bclrTL = top_bclr;
05195         
05196     }
05197 #endif
05198 ;
05199                 
05200        acc_opc += bot_opc * wgtBL;
05201        
05202             acc_rclr += (bot_rclr + bot_rsclr *
05203                          ((float)1.0 - shadow_pixel->opcflt)) * wgtBL;
05204             acc_gclr += (bot_gclr + bot_gsclr *
05205                          ((float)1.0 - shadow_pixel->opcflt)) * wgtBL;
05206             acc_bclr += (bot_bclr + bot_bsclr *
05207                          ((float)1.0 - shadow_pixel->opcflt)) * wgtBL;
05208        
05209 #ifdef DEBUG
05210     if (ipixel == trace_pixel_ptr) {
05211         trace_opcBL = bot_opc;
05212         trace_rclrBL = bot_rclr;
05213                      trace_gclrBL = bot_gclr;
05214                      trace_bclrBL = bot_bclr;
05215         
05216     }
05217 #endif
05218 ;
05219                 
05220     
05221             opac_param = VoxelField(botRLEdata, param0_offset, param0_size);
05222             opacity = param0_table[opac_param];
05223             if (param1_size != 0) {
05224                 opac_param = VoxelField(botRLEdata, param1_offset, param1_size);
05225                 opacity *= param1_table[opac_param];
05226                 if (param2_size != 0) {
05227                     opac_param = VoxelField(botRLEdata, param2_offset, param2_size);
05228                     opacity *= param2_table[opac_param];
05229                 }
05230             }
05231             if (opacity > min_opacity) {
05232                 opacity_int = opacity*255.;
05233                 bot_opc = opac_correct[opacity_int];
05234             } else {
05235                 bot_opc = (float)0.;
05236             };
05237     
05238     
05239     shade_index=num_materials*3*ShortField(botRLEdata,norm_offset);
05240     weight_index = num_materials * ByteField(botRLEdata, wgt_offset);
05241     
05242         
05243         
05244     bot_rclr = 
05245     shade_table[shade_index + 3*0 + 0] * 
05246         ((num_materials > 1) ? weight_table[weight_index] : (float)1.0);
05247         
05248     bot_gclr = 
05249     shade_table[shade_index + 3*0 + 1] * 
05250         ((num_materials > 1) ? weight_table[weight_index] : (float)1.0);
05251         
05252     bot_bclr = 
05253     shade_table[shade_index + 3*0 + 2] * 
05254         ((num_materials > 1) ? weight_table[weight_index] : (float)1.0);
05255         
05256         bot_rsclr = 
05257     shadow_table[shade_index + 3*0 + 0] * 
05258         ((num_materials > 1) ? weight_table[weight_index] : (float)1.0);
05259         
05260         bot_gsclr = 
05261     shadow_table[shade_index + 3*0 + 1] * 
05262         ((num_materials > 1) ? weight_table[weight_index] : (float)1.0);
05263         
05264         bot_bsclr = 
05265     shadow_table[shade_index + 3*0 + 2] * 
05266         ((num_materials > 1) ? weight_table[weight_index] : (float)1.0);
05267         for (m = 1; m < num_materials; m++) {
05268              
05269         
05270     bot_rclr += 
05271     shade_table[shade_index + 3*m + 0] * 
05272         weight_table[weight_index + m];
05273         
05274     bot_gclr += 
05275     shade_table[shade_index + 3*m + 1] * 
05276         weight_table[weight_index + m];
05277         
05278     bot_bclr += 
05279     shade_table[shade_index + 3*m + 2] * 
05280         weight_table[weight_index + m];
05281         
05282         bot_rsclr += 
05283     shadow_table[shade_index + 3*m + 0] * 
05284         weight_table[weight_index + m];
05285         
05286         bot_gsclr += 
05287     shadow_table[shade_index + 3*m + 1] * 
05288         weight_table[weight_index + m];
05289         
05290         bot_bsclr += 
05291     shadow_table[shade_index + 3*m + 2] * 
05292         weight_table[weight_index + m];
05293         };
05294     shade_factor = bot_opc * slice_depth_cueing;
05295     
05296         bot_rclr *= shade_factor;
05297         bot_gclr *= shade_factor;
05298         bot_bclr *= shade_factor;
05299     
05300             bot_rsclr *= shade_factor;
05301             bot_gsclr *= shade_factor;
05302             bot_bsclr *= shade_factor;
05303                 
05304        acc_opc += bot_opc * wgtBR;
05305        
05306             acc_rclr += (bot_rclr + bot_rsclr *
05307                          ((float)1.0 - shadow_pixel->opcflt)) * wgtBR;
05308             acc_gclr += (bot_gclr + bot_gsclr *
05309                          ((float)1.0 - shadow_pixel->opcflt)) * wgtBR;
05310             acc_bclr += (bot_bclr + bot_bsclr *
05311                          ((float)1.0 - shadow_pixel->opcflt)) * wgtBR;
05312        
05313 #ifdef DEBUG
05314     if (ipixel == trace_pixel_ptr) {
05315         trace_opcBR = bot_opc;
05316         trace_rclrBR = bot_rclr;
05317                      trace_gclrBR = bot_gclr;
05318                      trace_bclrBR = bot_bclr;
05319         
05320     }
05321 #endif
05322 ;
05323                 
05324         COUNT_RESAMPLE;
05325         if (acc_opc > min_opacity) {
05326             COUNT_COMPOSITE;
05327             iopc = ipixel->opcflt;
05328 #           ifndef SKIP_ERT
05329                 ASSERT(iopc < max_opacity);
05330 #           endif
05331             iopc_inv = (float)1. - iopc;
05332             
05333         ipixel->rclrflt += acc_rclr * iopc_inv;
05334         ipixel->gclrflt += acc_gclr * iopc_inv;
05335         ipixel->bclrflt += acc_bclr * iopc_inv;
05336             iopc += acc_opc * iopc_inv;
05337             ipixel->opcflt = iopc;
05338             
05339 #ifdef DEBUG
05340     if (ipixel == trace_pixel_ptr) {
05341 #ifdef COMPUTE_SHADOW_BUFFER
05342         printf("{%3d}  %3d %3d", k, icount-i-count, j);
05343 #else
05344         printf("[%3d]  %3d %3d", k, icount-i-count, j);
05345 #endif
05346         printf("  %3.0f %3.0f %3.0f",trace_opcTL*255.,trace_rclrTL,wgtTL*100.);
05347         printf("  %3.0f %3.0f %3.0f",trace_opcBL*255.,trace_rclrBL,wgtBL*100.);
05348         printf("  %3.0f %3.0f %3.0f",trace_opcTR*255.,trace_rclrTR,wgtTR*100.);
05349         printf("  %3.0f %3.0f %3.0f",trace_opcBR*255.,trace_rclrBR,wgtBR*100.);
05350         printf("  %3.0f %3.0f\n", iopc*255., 
05351                ipixel->rclrflt);
05352         
05353         printf("              ");
05354         printf("      %3.0f    ",trace_rsclrTL);
05355         printf("      %3.0f    ",trace_rsclrBL);
05356         printf("      %3.0f    ",trace_rsclrTR);
05357         printf("      %3.0f    ",trace_rsclrBR);
05358         printf("  %3.0f\n", shadow_pixel->opcflt * 255.);
05359         
05360         printf("              ");
05361         printf("      %3.0f    ",trace_gclrTL);
05362         printf("      %3.0f    ",trace_gclrBL);
05363         printf("      %3.0f    ",trace_gclrTR);
05364         printf("      %3.0f    ",trace_gclrBR);
05365         printf("      %3.0f\n", ipixel->gclrflt);
05366         printf("              ");
05367         printf("      %3.0f    ",trace_bclrTL);
05368         printf("      %3.0f    ",trace_bclrBL);
05369         printf("      %3.0f    ",trace_bclrTR);
05370         printf("      %3.0f    ",trace_bclrBR);
05371         printf("      %3.0f\n", ipixel->bclrflt);
05372     }
05373 #endif /* DEBUG */
05374 ;
05375 #           ifndef SKIP_ERT
05376                 if (iopc >= max_opacity) {
05377                     ASSERT(ipixel->lnk == 0);
05378                     ipixel->lnk = 1;
05379                 }
05380 #           endif
05381         };
05382                 ipixel += 1; shadow_pixel += 1;
05383                 topRLEdata += 1 * voxel_istride;
05384                 botRLEdata += 1 * voxel_istride;
05385                 count--;
05386                 SET_VOXELS_LOADED;
05387 
05388                 /* do the rest of the pixels in this run;
05389                    bottom-left and bottom-right voxels contribute */
05390                 while (count > 0) {
05391                     if (PIXEL_IS_OPAQUE(ipixel))
05392                         break;
05393                     if (!voxels_loaded) {
05394                         
05395     
05396             opac_param = VoxelField(botRLEdata - voxel_istride, param0_offset, param0_size);
05397             opacity = param0_table[opac_param];
05398             if (param1_size != 0) {
05399                 opac_param = VoxelField(botRLEdata - voxel_istride, param1_offset, param1_size);
05400                 opacity *= param1_table[opac_param];
05401                 if (param2_size != 0) {
05402                     opac_param = VoxelField(botRLEdata - voxel_istride, param2_offset, param2_size);
05403                     opacity *= param2_table[opac_param];
05404                 }
05405             }
05406             if (opacity > min_opacity) {
05407                 opacity_int = opacity*255.;
05408                 bot_opc = opac_correct[opacity_int];
05409             } else {
05410                 bot_opc = (float)0.;
05411             };
05412     
05413     
05414     shade_index=num_materials*3*ShortField(botRLEdata - voxel_istride,norm_offset);
05415     weight_index = num_materials * ByteField(botRLEdata - voxel_istride, wgt_offset);
05416     
05417         
05418         
05419     bot_rclr = 
05420     shade_table[shade_index + 3*0 + 0] * 
05421         ((num_materials > 1) ? weight_table[weight_index] : (float)1.0);
05422         
05423     bot_gclr = 
05424     shade_table[shade_index + 3*0 + 1] * 
05425         ((num_materials > 1) ? weight_table[weight_index] : (float)1.0);
05426         
05427     bot_bclr = 
05428     shade_table[shade_index + 3*0 + 2] * 
05429         ((num_materials > 1) ? weight_table[weight_index] : (float)1.0);
05430         
05431         bot_rsclr = 
05432     shadow_table[shade_index + 3*0 + 0] * 
05433         ((num_materials > 1) ? weight_table[weight_index] : (float)1.0);
05434         
05435         bot_gsclr = 
05436     shadow_table[shade_index + 3*0 + 1] * 
05437         ((num_materials > 1) ? weight_table[weight_index] : (float)1.0);
05438         
05439         bot_bsclr = 
05440     shadow_table[shade_index + 3*0 + 2] * 
05441         ((num_materials > 1) ? weight_table[weight_index] : (float)1.0);
05442         for (m = 1; m < num_materials; m++) {
05443              
05444         
05445     bot_rclr += 
05446     shade_table[shade_index + 3*m + 0] * 
05447         weight_table[weight_index + m];
05448         
05449     bot_gclr += 
05450     shade_table[shade_index + 3*m + 1] * 
05451         weight_table[weight_index + m];
05452         
05453     bot_bclr += 
05454     shade_table[shade_index + 3*m + 2] * 
05455         weight_table[weight_index + m];
05456         
05457         bot_rsclr += 
05458     shadow_table[shade_index + 3*m + 0] * 
05459         weight_table[weight_index + m];
05460         
05461         bot_gsclr += 
05462     shadow_table[shade_index + 3*m + 1] * 
05463         weight_table[weight_index + m];
05464         
05465         bot_bsclr += 
05466     shadow_table[shade_index + 3*m + 2] * 
05467         weight_table[weight_index + m];
05468         };
05469     shade_factor = bot_opc * slice_depth_cueing;
05470     
05471         bot_rclr *= shade_factor;
05472         bot_gclr *= shade_factor;
05473         bot_bclr *= shade_factor;
05474     
05475             bot_rsclr *= shade_factor;
05476             bot_gsclr *= shade_factor;
05477             bot_bsclr *= shade_factor;
05478                     }
05479                     
05480 #ifdef DEBUG
05481     if (ipixel == trace_pixel_ptr) {
05482         trace_opcTL = 0.; trace_opcBL = 0.; trace_opcTR = 0.; trace_opcBR = 0.;
05483         trace_rsclrTL=0.; trace_rsclrBL=0.; trace_rsclrTR=0.; trace_rsclrBR=0.;
05484         trace_rclrTL= 0.; trace_rclrBL= 0.; trace_rclrTR= 0.; trace_rclrBR= 0.;
05485         trace_gclrTL= 0.; trace_gclrBL= 0.; trace_gclrTR= 0.; trace_gclrBR= 0.;
05486         trace_bclrTL= 0.; trace_bclrBL= 0.; trace_bclrTR= 0.; trace_bclrBR= 0.;
05487     }
05488 #endif
05489 ;
05490                     
05491        acc_opc = bot_opc * wgtBL;
05492        
05493             acc_rclr = (bot_rclr + bot_rsclr *
05494                          ((float)1.0 - shadow_pixel->opcflt)) * wgtBL;
05495             acc_gclr = (bot_gclr + bot_gsclr *
05496                          ((float)1.0 - shadow_pixel->opcflt)) * wgtBL;
05497             acc_bclr = (bot_bclr + bot_bsclr *
05498                          ((float)1.0 - shadow_pixel->opcflt)) * wgtBL;
05499        
05500 #ifdef DEBUG
05501     if (ipixel == trace_pixel_ptr) {
05502         trace_opcBL = bot_opc;
05503         trace_rclrBL = bot_rclr;
05504                      trace_gclrBL = bot_gclr;
05505                      trace_bclrBL = bot_bclr;
05506         
05507     }
05508 #endif
05509 ;
05510                     
05511     
05512             opac_param = VoxelField(botRLEdata, param0_offset, param0_size);
05513             opacity = param0_table[opac_param];
05514             if (param1_size != 0) {
05515                 opac_param = VoxelField(botRLEdata, param1_offset, param1_size);
05516                 opacity *= param1_table[opac_param];
05517                 if (param2_size != 0) {
05518                     opac_param = VoxelField(botRLEdata, param2_offset, param2_size);
05519                     opacity *= param2_table[opac_param];
05520                 }
05521             }
05522             if (opacity > min_opacity) {
05523                 opacity_int = opacity*255.;
05524                 bot_opc = opac_correct[opacity_int];
05525             } else {
05526                 bot_opc = (float)0.;
05527             };
05528     
05529     
05530     shade_index=num_materials*3*ShortField(botRLEdata,norm_offset);
05531     weight_index = num_materials * ByteField(botRLEdata, wgt_offset);
05532     
05533         
05534         
05535     bot_rclr = 
05536     shade_table[shade_index + 3*0 + 0] * 
05537         ((num_materials > 1) ? weight_table[weight_index] : (float)1.0);
05538         
05539     bot_gclr = 
05540     shade_table[shade_index + 3*0 + 1] * 
05541         ((num_materials > 1) ? weight_table[weight_index] : (float)1.0);
05542         
05543     bot_bclr = 
05544     shade_table[shade_index + 3*0 + 2] * 
05545         ((num_materials > 1) ? weight_table[weight_index] : (float)1.0);
05546         
05547         bot_rsclr = 
05548     shadow_table[shade_index + 3*0 + 0] * 
05549         ((num_materials > 1) ? weight_table[weight_index] : (float)1.0);
05550         
05551         bot_gsclr = 
05552     shadow_table[shade_index + 3*0 + 1] * 
05553         ((num_materials > 1) ? weight_table[weight_index] : (float)1.0);
05554         
05555         bot_bsclr = 
05556     shadow_table[shade_index + 3*0 + 2] * 
05557         ((num_materials > 1) ? weight_table[weight_index] : (float)1.0);
05558         for (m = 1; m < num_materials; m++) {
05559              
05560         
05561     bot_rclr += 
05562     shade_table[shade_index + 3*m + 0] * 
05563         weight_table[weight_index + m];
05564         
05565     bot_gclr += 
05566     shade_table[shade_index + 3*m + 1] * 
05567         weight_table[weight_index + m];
05568         
05569     bot_bclr += 
05570     shade_table[shade_index + 3*m + 2] * 
05571         weight_table[weight_index + m];
05572         
05573         bot_rsclr += 
05574     shadow_table[shade_index + 3*m + 0] * 
05575         weight_table[weight_index + m];
05576         
05577         bot_gsclr += 
05578     shadow_table[shade_index + 3*m + 1] * 
05579         weight_table[weight_index + m];
05580         
05581         bot_bsclr += 
05582     shadow_table[shade_index + 3*m + 2] * 
05583         weight_table[weight_index + m];
05584         };
05585     shade_factor = bot_opc * slice_depth_cueing;
05586     
05587         bot_rclr *= shade_factor;
05588         bot_gclr *= shade_factor;
05589         bot_bclr *= shade_factor;
05590     
05591             bot_rsclr *= shade_factor;
05592             bot_gsclr *= shade_factor;
05593             bot_bsclr *= shade_factor;
05594                     
05595        acc_opc += bot_opc * wgtBR;
05596        
05597             acc_rclr += (bot_rclr + bot_rsclr *
05598                          ((float)1.0 - shadow_pixel->opcflt)) * wgtBR;
05599             acc_gclr += (bot_gclr + bot_gsclr *
05600                          ((float)1.0 - shadow_pixel->opcflt)) * wgtBR;
05601             acc_bclr += (bot_bclr + bot_bsclr *
05602                          ((float)1.0 - shadow_pixel->opcflt)) * wgtBR;
05603        
05604 #ifdef DEBUG
05605     if (ipixel == trace_pixel_ptr) {
05606         trace_opcBR = bot_opc;
05607         trace_rclrBR = bot_rclr;
05608                      trace_gclrBR = bot_gclr;
05609                      trace_bclrBR = bot_bclr;
05610         
05611     }
05612 #endif
05613 ;
05614                     
05615         COUNT_RESAMPLE;
05616         if (acc_opc > min_opacity) {
05617             COUNT_COMPOSITE;
05618             iopc = ipixel->opcflt;
05619 #           ifndef SKIP_ERT
05620                 ASSERT(iopc < max_opacity);
05621 #           endif
05622             iopc_inv = (float)1. - iopc;
05623             
05624         ipixel->rclrflt += acc_rclr * iopc_inv;
05625         ipixel->gclrflt += acc_gclr * iopc_inv;
05626         ipixel->bclrflt += acc_bclr * iopc_inv;
05627             iopc += acc_opc * iopc_inv;
05628             ipixel->opcflt = iopc;
05629             
05630 #ifdef DEBUG
05631     if (ipixel == trace_pixel_ptr) {
05632 #ifdef COMPUTE_SHADOW_BUFFER
05633         printf("{%3d}  %3d %3d", k, icount-i-count, j);
05634 #else
05635         printf("[%3d]  %3d %3d", k, icount-i-count, j);
05636 #endif
05637         printf("  %3.0f %3.0f %3.0f",trace_opcTL*255.,trace_rclrTL,wgtTL*100.);
05638         printf("  %3.0f %3.0f %3.0f",trace_opcBL*255.,trace_rclrBL,wgtBL*100.);
05639         printf("  %3.0f %3.0f %3.0f",trace_opcTR*255.,trace_rclrTR,wgtTR*100.);
05640         printf("  %3.0f %3.0f %3.0f",trace_opcBR*255.,trace_rclrBR,wgtBR*100.);
05641         printf("  %3.0f %3.0f\n", iopc*255., 
05642                ipixel->rclrflt);
05643         
05644         printf("              ");
05645         printf("      %3.0f    ",trace_rsclrTL);
05646         printf("      %3.0f    ",trace_rsclrBL);
05647         printf("      %3.0f    ",trace_rsclrTR);
05648         printf("      %3.0f    ",trace_rsclrBR);
05649         printf("  %3.0f\n", shadow_pixel->opcflt * 255.);
05650         
05651         printf("              ");
05652         printf("      %3.0f    ",trace_gclrTL);
05653         printf("      %3.0f    ",trace_gclrBL);
05654         printf("      %3.0f    ",trace_gclrTR);
05655         printf("      %3.0f    ",trace_gclrBR);
05656         printf("      %3.0f\n", ipixel->gclrflt);
05657         printf("              ");
05658         printf("      %3.0f    ",trace_bclrTL);
05659         printf("      %3.0f    ",trace_bclrBL);
05660         printf("      %3.0f    ",trace_bclrTR);
05661         printf("      %3.0f    ",trace_bclrBR);
05662         printf("      %3.0f\n", ipixel->bclrflt);
05663     }
05664 #endif /* DEBUG */
05665 ;
05666 #           ifndef SKIP_ERT
05667                 if (iopc >= max_opacity) {
05668                     ASSERT(ipixel->lnk == 0);
05669                     ipixel->lnk = 1;
05670                 }
05671 #           endif
05672         };
05673                     ipixel += 1; shadow_pixel += 1;
05674                     topRLEdata += 1 * voxel_istride;
05675                     botRLEdata += 1 * voxel_istride;
05676                     count--;
05677                     SET_VOXELS_LOADED;
05678                 }
05679                 break;
05680             case ALL_ZERO__ALL_NONZERO:
05681                 /* first pixel: top-right and bottom-right voxels contribute */
05682                 
05683     
05684             opac_param = VoxelField(topRLEdata, param0_offset, param0_size);
05685             opacity = param0_table[opac_param];
05686             if (param1_size != 0) {
05687                 opac_param = VoxelField(topRLEdata, param1_offset, param1_size);
05688                 opacity *= param1_table[opac_param];
05689                 if (param2_size != 0) {
05690                     opac_param = VoxelField(topRLEdata, param2_offset, param2_size);
05691                     opacity *= param2_table[opac_param];
05692                 }
05693             }
05694             if (opacity > min_opacity) {
05695                 opacity_int = opacity*255.;
05696                 top_opc = opac_correct[opacity_int];
05697             } else {
05698                 top_opc = (float)0.;
05699             };
05700     
05701     
05702     shade_index=num_materials*3*ShortField(topRLEdata,norm_offset);
05703     weight_index = num_materials * ByteField(topRLEdata, wgt_offset);
05704     
05705         
05706         
05707     top_rclr = 
05708     shade_table[shade_index + 3*0 + 0] * 
05709         ((num_materials > 1) ? weight_table[weight_index] : (float)1.0);
05710         
05711     top_gclr = 
05712     shade_table[shade_index + 3*0 + 1] * 
05713         ((num_materials > 1) ? weight_table[weight_index] : (float)1.0);
05714         
05715     top_bclr = 
05716     shade_table[shade_index + 3*0 + 2] * 
05717         ((num_materials > 1) ? weight_table[weight_index] : (float)1.0);
05718         
05719         top_rsclr = 
05720     shadow_table[shade_index + 3*0 + 0] * 
05721         ((num_materials > 1) ? weight_table[weight_index] : (float)1.0);
05722         
05723         top_gsclr = 
05724     shadow_table[shade_index + 3*0 + 1] * 
05725         ((num_materials > 1) ? weight_table[weight_index] : (float)1.0);
05726         
05727         top_bsclr = 
05728     shadow_table[shade_index + 3*0 + 2] * 
05729         ((num_materials > 1) ? weight_table[weight_index] : (float)1.0);
05730         for (m = 1; m < num_materials; m++) {
05731              
05732         
05733     top_rclr += 
05734     shade_table[shade_index + 3*m + 0] * 
05735         weight_table[weight_index + m];
05736         
05737     top_gclr += 
05738     shade_table[shade_index + 3*m + 1] * 
05739         weight_table[weight_index + m];
05740         
05741     top_bclr += 
05742     shade_table[shade_index + 3*m + 2] * 
05743         weight_table[weight_index + m];
05744         
05745         top_rsclr += 
05746     shadow_table[shade_index + 3*m + 0] * 
05747         weight_table[weight_index + m];
05748         
05749         top_gsclr += 
05750     shadow_table[shade_index + 3*m + 1] * 
05751         weight_table[weight_index + m];
05752         
05753         top_bsclr += 
05754     shadow_table[shade_index + 3*m + 2] * 
05755         weight_table[weight_index + m];
05756         };
05757     shade_factor = top_opc * slice_depth_cueing;
05758     
05759         top_rclr *= shade_factor;
05760         top_gclr *= shade_factor;
05761         top_bclr *= shade_factor;
05762     
05763             top_rsclr *= shade_factor;
05764             top_gsclr *= shade_factor;
05765             top_bsclr *= shade_factor;
05766                 
05767     
05768             opac_param = VoxelField(botRLEdata, param0_offset, param0_size);
05769             opacity = param0_table[opac_param];
05770             if (param1_size != 0) {
05771                 opac_param = VoxelField(botRLEdata, param1_offset, param1_size);
05772                 opacity *= param1_table[opac_param];
05773                 if (param2_size != 0) {
05774                     opac_param = VoxelField(botRLEdata, param2_offset, param2_size);
05775                     opacity *= param2_table[opac_param];
05776                 }
05777             }
05778             if (opacity > min_opacity) {
05779                 opacity_int = opacity*255.;
05780                 bot_opc = opac_correct[opacity_int];
05781             } else {
05782                 bot_opc = (float)0.;
05783             };
05784     
05785     
05786     shade_index=num_materials*3*ShortField(botRLEdata,norm_offset);
05787     weight_index = num_materials * ByteField(botRLEdata, wgt_offset);
05788     
05789         
05790         
05791     bot_rclr = 
05792     shade_table[shade_index + 3*0 + 0] * 
05793         ((num_materials > 1) ? weight_table[weight_index] : (float)1.0);
05794         
05795     bot_gclr = 
05796     shade_table[shade_index + 3*0 + 1] * 
05797         ((num_materials > 1) ? weight_table[weight_index] : (float)1.0);
05798         
05799     bot_bclr = 
05800     shade_table[shade_index + 3*0 + 2] * 
05801         ((num_materials > 1) ? weight_table[weight_index] : (float)1.0);
05802         
05803         bot_rsclr = 
05804     shadow_table[shade_index + 3*0 + 0] * 
05805         ((num_materials > 1) ? weight_table[weight_index] : (float)1.0);
05806         
05807         bot_gsclr = 
05808     shadow_table[shade_index + 3*0 + 1] * 
05809         ((num_materials > 1) ? weight_table[weight_index] : (float)1.0);
05810         
05811         bot_bsclr = 
05812     shadow_table[shade_index + 3*0 + 2] * 
05813         ((num_materials > 1) ? weight_table[weight_index] : (float)1.0);
05814         for (m = 1; m < num_materials; m++) {
05815              
05816         
05817     bot_rclr += 
05818     shade_table[shade_index + 3*m + 0] * 
05819         weight_table[weight_index + m];
05820         
05821     bot_gclr += 
05822     shade_table[shade_index + 3*m + 1] * 
05823         weight_table[weight_index + m];
05824         
05825     bot_bclr += 
05826     shade_table[shade_index + 3*m + 2] * 
05827         weight_table[weight_index + m];
05828         
05829         bot_rsclr += 
05830     shadow_table[shade_index + 3*m + 0] * 
05831         weight_table[weight_index + m];
05832         
05833         bot_gsclr += 
05834     shadow_table[shade_index + 3*m + 1] * 
05835         weight_table[weight_index + m];
05836         
05837         bot_bsclr += 
05838     shadow_table[shade_index + 3*m + 2] * 
05839         weight_table[weight_index + m];
05840         };
05841     shade_factor = bot_opc * slice_depth_cueing;
05842     
05843         bot_rclr *= shade_factor;
05844         bot_gclr *= shade_factor;
05845         bot_bclr *= shade_factor;
05846     
05847             bot_rsclr *= shade_factor;
05848             bot_gsclr *= shade_factor;
05849             bot_bsclr *= shade_factor;
05850                 
05851 #ifdef DEBUG
05852     if (ipixel == trace_pixel_ptr) {
05853         trace_opcTL = 0.; trace_opcBL = 0.; trace_opcTR = 0.; trace_opcBR = 0.;
05854         trace_rsclrTL=0.; trace_rsclrBL=0.; trace_rsclrTR=0.; trace_rsclrBR=0.;
05855         trace_rclrTL= 0.; trace_rclrBL= 0.; trace_rclrTR= 0.; trace_rclrBR= 0.;
05856         trace_gclrTL= 0.; trace_gclrBL= 0.; trace_gclrTR= 0.; trace_gclrBR= 0.;
05857         trace_bclrTL= 0.; trace_bclrBL= 0.; trace_bclrTR= 0.; trace_bclrBR= 0.;
05858     }
05859 #endif
05860 ;
05861                 
05862        acc_opc = top_opc * wgtTR;
05863        
05864             acc_rclr = (top_rclr + top_rsclr *
05865                          ((float)1.0 - shadow_pixel->opcflt)) * wgtTR;
05866             acc_gclr = (top_gclr + top_gsclr *
05867                          ((float)1.0 - shadow_pixel->opcflt)) * wgtTR;
05868             acc_bclr = (top_bclr + top_bsclr *
05869                          ((float)1.0 - shadow_pixel->opcflt)) * wgtTR;
05870        
05871 #ifdef DEBUG
05872     if (ipixel == trace_pixel_ptr) {
05873         trace_opcTR = top_opc;
05874         trace_rclrTR = top_rclr;
05875                      trace_gclrTR = top_gclr;
05876                      trace_bclrTR = top_bclr;
05877         
05878     }
05879 #endif
05880 ;
05881                 
05882        acc_opc += bot_opc * wgtBR;
05883        
05884             acc_rclr += (bot_rclr + bot_rsclr *
05885                          ((float)1.0 - shadow_pixel->opcflt)) * wgtBR;
05886             acc_gclr += (bot_gclr + bot_gsclr *
05887                          ((float)1.0 - shadow_pixel->opcflt)) * wgtBR;
05888             acc_bclr += (bot_bclr + bot_bsclr *
05889                          ((float)1.0 - shadow_pixel->opcflt)) * wgtBR;
05890        
05891 #ifdef DEBUG
05892     if (ipixel == trace_pixel_ptr) {
05893         trace_opcBR = bot_opc;
05894         trace_rclrBR = bot_rclr;
05895                      trace_gclrBR = bot_gclr;
05896                      trace_bclrBR = bot_bclr;
05897         
05898     }
05899 #endif
05900 ;
05901                 
05902         COUNT_RESAMPLE;
05903         if (acc_opc > min_opacity) {
05904             COUNT_COMPOSITE;
05905             iopc = ipixel->opcflt;
05906 #           ifndef SKIP_ERT
05907                 ASSERT(iopc < max_opacity);
05908 #           endif
05909             iopc_inv = (float)1. - iopc;
05910             
05911         ipixel->rclrflt += acc_rclr * iopc_inv;
05912         ipixel->gclrflt += acc_gclr * iopc_inv;
05913         ipixel->bclrflt += acc_bclr * iopc_inv;
05914             iopc += acc_opc * iopc_inv;
05915             ipixel->opcflt = iopc;
05916             
05917 #ifdef DEBUG
05918     if (ipixel == trace_pixel_ptr) {
05919 #ifdef COMPUTE_SHADOW_BUFFER
05920         printf("{%3d}  %3d %3d", k, icount-i-count, j);
05921 #else
05922         printf("[%3d]  %3d %3d", k, icount-i-count, j);
05923 #endif
05924         printf("  %3.0f %3.0f %3.0f",trace_opcTL*255.,trace_rclrTL,wgtTL*100.);
05925         printf("  %3.0f %3.0f %3.0f",trace_opcBL*255.,trace_rclrBL,wgtBL*100.);
05926         printf("  %3.0f %3.0f %3.0f",trace_opcTR*255.,trace_rclrTR,wgtTR*100.);
05927         printf("  %3.0f %3.0f %3.0f",trace_opcBR*255.,trace_rclrBR,wgtBR*100.);
05928         printf("  %3.0f %3.0f\n", iopc*255., 
05929                ipixel->rclrflt);
05930         
05931         printf("              ");
05932         printf("      %3.0f    ",trace_rsclrTL);
05933         printf("      %3.0f    ",trace_rsclrBL);
05934         printf("      %3.0f    ",trace_rsclrTR);
05935         printf("      %3.0f    ",trace_rsclrBR);
05936         printf("  %3.0f\n", shadow_pixel->opcflt * 255.);
05937         
05938         printf("              ");
05939         printf("      %3.0f    ",trace_gclrTL);
05940         printf("      %3.0f    ",trace_gclrBL);
05941         printf("      %3.0f    ",trace_gclrTR);
05942         printf("      %3.0f    ",trace_gclrBR);
05943         printf("      %3.0f\n", ipixel->gclrflt);
05944         printf("              ");
05945         printf("      %3.0f    ",trace_bclrTL);
05946         printf("      %3.0f    ",trace_bclrBL);
05947         printf("      %3.0f    ",trace_bclrTR);
05948         printf("      %3.0f    ",trace_bclrBR);
05949         printf("      %3.0f\n", ipixel->bclrflt);
05950     }
05951 #endif /* DEBUG */
05952 ;
05953 #           ifndef SKIP_ERT
05954                 if (iopc >= max_opacity) {
05955                     ASSERT(ipixel->lnk == 0);
05956                     ipixel->lnk = 1;
05957                 }
05958 #           endif
05959         };
05960                 ipixel += 1; shadow_pixel += 1;
05961                 topRLEdata += 1 * voxel_istride;
05962                 botRLEdata += 1 * voxel_istride;
05963                 count--;
05964                 SET_VOXELS_LOADED;
05965 
05966                 /* do the rest of the pixels in this run;
05967                    all four voxels contribute */
05968                 while (count > 0) {
05969                     if (PIXEL_IS_OPAQUE(ipixel))
05970                         break;
05971                     if (!voxels_loaded) {
05972                         
05973     
05974             opac_param = VoxelField(topRLEdata - voxel_istride, param0_offset, param0_size);
05975             opacity = param0_table[opac_param];
05976             if (param1_size != 0) {
05977                 opac_param = VoxelField(topRLEdata - voxel_istride, param1_offset, param1_size);
05978                 opacity *= param1_table[opac_param];
05979                 if (param2_size != 0) {
05980                     opac_param = VoxelField(topRLEdata - voxel_istride, param2_offset, param2_size);
05981                     opacity *= param2_table[opac_param];
05982                 }
05983             }
05984             if (opacity > min_opacity) {
05985                 opacity_int = opacity*255.;
05986                 top_opc = opac_correct[opacity_int];
05987             } else {
05988                 top_opc = (float)0.;
05989             };
05990     
05991     
05992     shade_index=num_materials*3*ShortField(topRLEdata - voxel_istride,norm_offset);
05993     weight_index = num_materials * ByteField(topRLEdata - voxel_istride, wgt_offset);
05994     
05995         
05996         
05997     top_rclr = 
05998     shade_table[shade_index + 3*0 + 0] * 
05999         ((num_materials > 1) ? weight_table[weight_index] : (float)1.0);
06000         
06001     top_gclr = 
06002     shade_table[shade_index + 3*0 + 1] * 
06003         ((num_materials > 1) ? weight_table[weight_index] : (float)1.0);
06004         
06005     top_bclr = 
06006     shade_table[shade_index + 3*0 + 2] * 
06007         ((num_materials > 1) ? weight_table[weight_index] : (float)1.0);
06008         
06009         top_rsclr = 
06010     shadow_table[shade_index + 3*0 + 0] * 
06011         ((num_materials > 1) ? weight_table[weight_index] : (float)1.0);
06012         
06013         top_gsclr = 
06014     shadow_table[shade_index + 3*0 + 1] * 
06015         ((num_materials > 1) ? weight_table[weight_index] : (float)1.0);
06016         
06017         top_bsclr = 
06018     shadow_table[shade_index + 3*0 + 2] * 
06019         ((num_materials > 1) ? weight_table[weight_index] : (float)1.0);
06020         for (m = 1; m < num_materials; m++) {
06021              
06022         
06023     top_rclr += 
06024     shade_table[shade_index + 3*m + 0] * 
06025         weight_table[weight_index + m];
06026         
06027     top_gclr += 
06028     shade_table[shade_index + 3*m + 1] * 
06029         weight_table[weight_index + m];
06030         
06031     top_bclr += 
06032     shade_table[shade_index + 3*m + 2] * 
06033         weight_table[weight_index + m];
06034         
06035         top_rsclr += 
06036     shadow_table[shade_index + 3*m + 0] * 
06037         weight_table[weight_index + m];
06038         
06039         top_gsclr += 
06040     shadow_table[shade_index + 3*m + 1] * 
06041         weight_table[weight_index + m];
06042         
06043         top_bsclr += 
06044     shadow_table[shade_index + 3*m + 2] * 
06045         weight_table[weight_index + m];
06046         };
06047     shade_factor = top_opc * slice_depth_cueing;
06048     
06049         top_rclr *= shade_factor;
06050         top_gclr *= shade_factor;
06051         top_bclr *= shade_factor;
06052     
06053             top_rsclr *= shade_factor;
06054             top_gsclr *= shade_factor;
06055             top_bsclr *= shade_factor;
06056                         
06057     
06058             opac_param = VoxelField(botRLEdata - voxel_istride, param0_offset, param0_size);
06059             opacity = param0_table[opac_param];
06060             if (param1_size != 0) {
06061                 opac_param = VoxelField(botRLEdata - voxel_istride, param1_offset, param1_size);
06062                 opacity *= param1_table[opac_param];
06063                 if (param2_size != 0) {
06064                     opac_param = VoxelField(botRLEdata - voxel_istride, param2_offset, param2_size);
06065                     opacity *= param2_table[opac_param];
06066                 }
06067             }
06068             if (opacity > min_opacity) {
06069                 opacity_int = opacity*255.;
06070                 bot_opc = opac_correct[opacity_int];
06071             } else {
06072                 bot_opc = (float)0.;
06073             };
06074     
06075     
06076     shade_index=num_materials*3*ShortField(botRLEdata - voxel_istride,norm_offset);
06077     weight_index = num_materials * ByteField(botRLEdata - voxel_istride, wgt_offset);
06078     
06079         
06080         
06081     bot_rclr = 
06082     shade_table[shade_index + 3*0 + 0] * 
06083         ((num_materials > 1) ? weight_table[weight_index] : (float)1.0);
06084         
06085     bot_gclr = 
06086     shade_table[shade_index + 3*0 + 1] * 
06087         ((num_materials > 1) ? weight_table[weight_index] : (float)1.0);
06088         
06089     bot_bclr = 
06090     shade_table[shade_index + 3*0 + 2] * 
06091         ((num_materials > 1) ? weight_table[weight_index] : (float)1.0);
06092         
06093         bot_rsclr = 
06094     shadow_table[shade_index + 3*0 + 0] * 
06095         ((num_materials > 1) ? weight_table[weight_index] : (float)1.0);
06096         
06097         bot_gsclr = 
06098     shadow_table[shade_index + 3*0 + 1] * 
06099         ((num_materials > 1) ? weight_table[weight_index] : (float)1.0);
06100         
06101         bot_bsclr = 
06102     shadow_table[shade_index + 3*0 + 2] * 
06103         ((num_materials > 1) ? weight_table[weight_index] : (float)1.0);
06104         for (m = 1; m < num_materials; m++) {
06105              
06106         
06107     bot_rclr += 
06108     shade_table[shade_index + 3*m + 0] * 
06109         weight_table[weight_index + m];
06110         
06111     bot_gclr += 
06112     shade_table[shade_index + 3*m + 1] * 
06113         weight_table[weight_index + m];
06114         
06115     bot_bclr += 
06116     shade_table[shade_index + 3*m + 2] * 
06117         weight_table[weight_index + m];
06118         
06119         bot_rsclr += 
06120     shadow_table[shade_index + 3*m + 0] * 
06121         weight_table[weight_index + m];
06122         
06123         bot_gsclr += 
06124     shadow_table[shade_index + 3*m + 1] * 
06125         weight_table[weight_index + m];
06126         
06127         bot_bsclr += 
06128     shadow_table[shade_index + 3*m + 2] * 
06129         weight_table[weight_index + m];
06130         };
06131     shade_factor = bot_opc * slice_depth_cueing;
06132     
06133         bot_rclr *= shade_factor;
06134         bot_gclr *= shade_factor;
06135         bot_bclr *= shade_factor;
06136     
06137             bot_rsclr *= shade_factor;
06138             bot_gsclr *= shade_factor;
06139             bot_bsclr *= shade_factor;
06140                     }
06141                     
06142 #ifdef DEBUG
06143     if (ipixel == trace_pixel_ptr) {
06144         trace_opcTL = 0.; trace_opcBL = 0.; trace_opcTR = 0.; trace_opcBR = 0.;
06145         trace_rsclrTL=0.; trace_rsclrBL=0.; trace_rsclrTR=0.; trace_rsclrBR=0.;
06146         trace_rclrTL= 0.; trace_rclrBL= 0.; trace_rclrTR= 0.; trace_rclrBR= 0.;
06147         trace_gclrTL= 0.; trace_gclrBL= 0.; trace_gclrTR= 0.; trace_gclrBR= 0.;
06148         trace_bclrTL= 0.; trace_bclrBL= 0.; trace_bclrTR= 0.; trace_bclrBR= 0.;
06149     }
06150 #endif
06151 ;
06152                     
06153        acc_opc = top_opc * wgtTL;
06154        
06155             acc_rclr = (top_rclr + top_rsclr *
06156                          ((float)1.0 - shadow_pixel->opcflt)) * wgtTL;
06157             acc_gclr = (top_gclr + top_gsclr *
06158                          ((float)1.0 - shadow_pixel->opcflt)) * wgtTL;
06159             acc_bclr = (top_bclr + top_bsclr *
06160                          ((float)1.0 - shadow_pixel->opcflt)) * wgtTL;
06161        
06162 #ifdef DEBUG
06163     if (ipixel == trace_pixel_ptr) {
06164         trace_opcTL = top_opc;
06165         trace_rclrTL = top_rclr;
06166                      trace_gclrTL = top_gclr;
06167                      trace_bclrTL = top_bclr;
06168         
06169     }
06170 #endif
06171 ;
06172                     
06173        acc_opc += bot_opc * wgtBL;
06174        
06175             acc_rclr += (bot_rclr + bot_rsclr *
06176                          ((float)1.0 - shadow_pixel->opcflt)) * wgtBL;
06177             acc_gclr += (bot_gclr + bot_gsclr *
06178                          ((float)1.0 - shadow_pixel->opcflt)) * wgtBL;
06179             acc_bclr += (bot_bclr + bot_bsclr *
06180                          ((float)1.0 - shadow_pixel->opcflt)) * wgtBL;
06181        
06182 #ifdef DEBUG
06183     if (ipixel == trace_pixel_ptr) {
06184         trace_opcBL = bot_opc;
06185         trace_rclrBL = bot_rclr;
06186                      trace_gclrBL = bot_gclr;
06187                      trace_bclrBL = bot_bclr;
06188         
06189     }
06190 #endif
06191 ;
06192                     
06193     
06194             opac_param = VoxelField(topRLEdata, param0_offset, param0_size);
06195             opacity = param0_table[opac_param];
06196             if (param1_size != 0) {
06197                 opac_param = VoxelField(topRLEdata, param1_offset, param1_size);
06198                 opacity *= param1_table[opac_param];
06199                 if (param2_size != 0) {
06200                     opac_param = VoxelField(topRLEdata, param2_offset, param2_size);
06201                     opacity *= param2_table[opac_param];
06202                 }
06203             }
06204             if (opacity > min_opacity) {
06205                 opacity_int = opacity*255.;
06206                 top_opc = opac_correct[opacity_int];
06207             } else {
06208                 top_opc = (float)0.;
06209             };
06210     
06211     
06212     shade_index=num_materials*3*ShortField(topRLEdata,norm_offset);
06213     weight_index = num_materials * ByteField(topRLEdata, wgt_offset);
06214     
06215         
06216         
06217     top_rclr = 
06218     shade_table[shade_index + 3*0 + 0] * 
06219         ((num_materials > 1) ? weight_table[weight_index] : (float)1.0);
06220         
06221     top_gclr = 
06222     shade_table[shade_index + 3*0 + 1] * 
06223         ((num_materials > 1) ? weight_table[weight_index] : (float)1.0);
06224         
06225     top_bclr = 
06226     shade_table[shade_index + 3*0 + 2] * 
06227         ((num_materials > 1) ? weight_table[weight_index] : (float)1.0);
06228         
06229         top_rsclr = 
06230     shadow_table[shade_index + 3*0 + 0] * 
06231         ((num_materials > 1) ? weight_table[weight_index] : (float)1.0);
06232         
06233         top_gsclr = 
06234     shadow_table[shade_index + 3*0 + 1] * 
06235         ((num_materials > 1) ? weight_table[weight_index] : (float)1.0);
06236         
06237         top_bsclr = 
06238     shadow_table[shade_index + 3*0 + 2] * 
06239         ((num_materials > 1) ? weight_table[weight_index] : (float)1.0);
06240         for (m = 1; m < num_materials; m++) {
06241              
06242         
06243     top_rclr += 
06244     shade_table[shade_index + 3*m + 0] * 
06245         weight_table[weight_index + m];
06246         
06247     top_gclr += 
06248     shade_table[shade_index + 3*m + 1] * 
06249         weight_table[weight_index + m];
06250         
06251     top_bclr += 
06252     shade_table[shade_index + 3*m + 2] * 
06253         weight_table[weight_index + m];
06254         
06255         top_rsclr += 
06256     shadow_table[shade_index + 3*m + 0] * 
06257         weight_table[weight_index + m];
06258         
06259         top_gsclr += 
06260     shadow_table[shade_index + 3*m + 1] * 
06261         weight_table[weight_index + m];
06262         
06263         top_bsclr += 
06264     shadow_table[shade_index + 3*m + 2] * 
06265         weight_table[weight_index + m];
06266         };
06267     shade_factor = top_opc * slice_depth_cueing;
06268     
06269         top_rclr *= shade_factor;
06270         top_gclr *= shade_factor;
06271         top_bclr *= shade_factor;
06272     
06273             top_rsclr *= shade_factor;
06274             top_gsclr *= shade_factor;
06275             top_bsclr *= shade_factor;
06276                     
06277     
06278             opac_param = VoxelField(botRLEdata, param0_offset, param0_size);
06279             opacity = param0_table[opac_param];
06280             if (param1_size != 0) {
06281                 opac_param = VoxelField(botRLEdata, param1_offset, param1_size);
06282                 opacity *= param1_table[opac_param];
06283                 if (param2_size != 0) {
06284                     opac_param = VoxelField(botRLEdata, param2_offset, param2_size);
06285                     opacity *= param2_table[opac_param];
06286                 }
06287             }
06288             if (opacity > min_opacity) {
06289                 opacity_int = opacity*255.;
06290                 bot_opc = opac_correct[opacity_int];
06291             } else {
06292                 bot_opc = (float)0.;
06293             };
06294     
06295     
06296     shade_index=num_materials*3*ShortField(botRLEdata,norm_offset);
06297     weight_index = num_materials * ByteField(botRLEdata, wgt_offset);
06298     
06299         
06300         
06301     bot_rclr = 
06302     shade_table[shade_index + 3*0 + 0] * 
06303         ((num_materials > 1) ? weight_table[weight_index] : (float)1.0);
06304         
06305     bot_gclr = 
06306     shade_table[shade_index + 3*0 + 1] * 
06307         ((num_materials > 1) ? weight_table[weight_index] : (float)1.0);
06308         
06309     bot_bclr = 
06310     shade_table[shade_index + 3*0 + 2] * 
06311         ((num_materials > 1) ? weight_table[weight_index] : (float)1.0);
06312         
06313         bot_rsclr = 
06314     shadow_table[shade_index + 3*0 + 0] * 
06315         ((num_materials > 1) ? weight_table[weight_index] : (float)1.0);
06316         
06317         bot_gsclr = 
06318     shadow_table[shade_index + 3*0 + 1] * 
06319         ((num_materials > 1) ? weight_table[weight_index] : (float)1.0);
06320         
06321         bot_bsclr = 
06322     shadow_table[shade_index + 3*0 + 2] * 
06323         ((num_materials > 1) ? weight_table[weight_index] : (float)1.0);
06324         for (m = 1; m < num_materials; m++) {
06325              
06326         
06327     bot_rclr += 
06328     shade_table[shade_index + 3*m + 0] * 
06329         weight_table[weight_index + m];
06330         
06331     bot_gclr += 
06332     shade_table[shade_index + 3*m + 1] * 
06333         weight_table[weight_index + m];
06334         
06335     bot_bclr += 
06336     shade_table[shade_index + 3*m + 2] * 
06337         weight_table[weight_index + m];
06338         
06339         bot_rsclr += 
06340     shadow_table[shade_index + 3*m + 0] * 
06341         weight_table[weight_index + m];
06342         
06343         bot_gsclr += 
06344     shadow_table[shade_index + 3*m + 1] * 
06345         weight_table[weight_index + m];
06346         
06347         bot_bsclr += 
06348     shadow_table[shade_index + 3*m + 2] * 
06349         weight_table[weight_index + m];
06350         };
06351     shade_factor = bot_opc * slice_depth_cueing;
06352     
06353         bot_rclr *= shade_factor;
06354         bot_gclr *= shade_factor;
06355         bot_bclr *= shade_factor;
06356     
06357             bot_rsclr *= shade_factor;
06358             bot_gsclr *= shade_factor;
06359             bot_bsclr *= shade_factor;
06360                     
06361        acc_opc += top_opc * wgtTR;
06362        
06363             acc_rclr += (top_rclr + top_rsclr *
06364                          ((float)1.0 - shadow_pixel->opcflt)) * wgtTR;
06365             acc_gclr += (top_gclr + top_gsclr *
06366                          ((float)1.0 - shadow_pixel->opcflt)) * wgtTR;
06367             acc_bclr += (top_bclr + top_bsclr *
06368                          ((float)1.0 - shadow_pixel->opcflt)) * wgtTR;
06369        
06370 #ifdef DEBUG
06371     if (ipixel == trace_pixel_ptr) {
06372         trace_opcTR = top_opc;
06373         trace_rclrTR = top_rclr;
06374                      trace_gclrTR = top_gclr;
06375                      trace_bclrTR = top_bclr;
06376         
06377     }
06378 #endif
06379 ;
06380                     
06381        acc_opc += bot_opc * wgtBR;
06382        
06383             acc_rclr += (bot_rclr + bot_rsclr *
06384                          ((float)1.0 - shadow_pixel->opcflt)) * wgtBR;
06385             acc_gclr += (bot_gclr + bot_gsclr *
06386                          ((float)1.0 - shadow_pixel->opcflt)) * wgtBR;
06387             acc_bclr += (bot_bclr + bot_bsclr *
06388                          ((float)1.0 - shadow_pixel->opcflt)) * wgtBR;
06389        
06390 #ifdef DEBUG
06391     if (ipixel == trace_pixel_ptr) {
06392         trace_opcBR = bot_opc;
06393         trace_rclrBR = bot_rclr;
06394                      trace_gclrBR = bot_gclr;
06395                      trace_bclrBR = bot_bclr;
06396         
06397     }
06398 #endif
06399 ;
06400                     
06401         COUNT_RESAMPLE;
06402         if (acc_opc > min_opacity) {
06403             COUNT_COMPOSITE;
06404             iopc = ipixel->opcflt;
06405 #           ifndef SKIP_ERT
06406                 ASSERT(iopc < max_opacity);
06407 #           endif
06408             iopc_inv = (float)1. - iopc;
06409             
06410         ipixel->rclrflt += acc_rclr * iopc_inv;
06411         ipixel->gclrflt += acc_gclr * iopc_inv;
06412         ipixel->bclrflt += acc_bclr * iopc_inv;
06413             iopc += acc_opc * iopc_inv;
06414             ipixel->opcflt = iopc;
06415             
06416 #ifdef DEBUG
06417     if (ipixel == trace_pixel_ptr) {
06418 #ifdef COMPUTE_SHADOW_BUFFER
06419         printf("{%3d}  %3d %3d", k, icount-i-count, j);
06420 #else
06421         printf("[%3d]  %3d %3d", k, icount-i-count, j);
06422 #endif
06423         printf("  %3.0f %3.0f %3.0f",trace_opcTL*255.,trace_rclrTL,wgtTL*100.);
06424         printf("  %3.0f %3.0f %3.0f",trace_opcBL*255.,trace_rclrBL,wgtBL*100.);
06425         printf("  %3.0f %3.0f %3.0f",trace_opcTR*255.,trace_rclrTR,wgtTR*100.);
06426         printf("  %3.0f %3.0f %3.0f",trace_opcBR*255.,trace_rclrBR,wgtBR*100.);
06427         printf("  %3.0f %3.0f\n", iopc*255., 
06428                ipixel->rclrflt);
06429         
06430         printf("              ");
06431         printf("      %3.0f    ",trace_rsclrTL);
06432         printf("      %3.0f    ",trace_rsclrBL);
06433         printf("      %3.0f    ",trace_rsclrTR);
06434         printf("      %3.0f    ",trace_rsclrBR);
06435         printf("  %3.0f\n", shadow_pixel->opcflt * 255.);
06436         
06437         printf("              ");
06438         printf("      %3.0f    ",trace_gclrTL);
06439         printf("      %3.0f    ",trace_gclrBL);
06440         printf("      %3.0f    ",trace_gclrTR);
06441         printf("      %3.0f    ",trace_gclrBR);
06442         printf("      %3.0f\n", ipixel->gclrflt);
06443         printf("              ");
06444         printf("      %3.0f    ",trace_bclrTL);
06445         printf("      %3.0f    ",trace_bclrBL);
06446         printf("      %3.0f    ",trace_bclrTR);
06447         printf("      %3.0f    ",trace_bclrBR);
06448         printf("      %3.0f\n", ipixel->bclrflt);
06449     }
06450 #endif /* DEBUG */
06451 ;
06452 #           ifndef SKIP_ERT
06453                 if (iopc >= max_opacity) {
06454                     ASSERT(ipixel->lnk == 0);
06455                     ipixel->lnk = 1;
06456                 }
06457 #           endif
06458         };
06459                     ipixel += 1; shadow_pixel += 1;
06460                     topRLEdata += 1 * voxel_istride;
06461                     botRLEdata += 1 * voxel_istride;
06462                     count--;
06463                     SET_VOXELS_LOADED;
06464                 }
06465                 break;
06466             case TOP_NONZERO__ALL_NONZERO:
06467                 /* first pixel: top-left, top-right and bottom-right
06468                    voxels contribute */
06469                 if (!voxels_loaded) {
06470                     
06471     
06472             opac_param = VoxelField(topRLEdata - voxel_istride, param0_offset, param0_size);
06473             opacity = param0_table[opac_param];
06474             if (param1_size != 0) {
06475                 opac_param = VoxelField(topRLEdata - voxel_istride, param1_offset, param1_size);
06476                 opacity *= param1_table[opac_param];
06477                 if (param2_size != 0) {
06478                     opac_param = VoxelField(topRLEdata - voxel_istride, param2_offset, param2_size);
06479                     opacity *= param2_table[opac_param];
06480                 }
06481             }
06482             if (opacity > min_opacity) {
06483                 opacity_int = opacity*255.;
06484                 top_opc = opac_correct[opacity_int];
06485             } else {
06486                 top_opc = (float)0.;
06487             };
06488     
06489     
06490     shade_index=num_materials*3*ShortField(topRLEdata - voxel_istride,norm_offset);
06491     weight_index = num_materials * ByteField(topRLEdata - voxel_istride, wgt_offset);
06492     
06493         
06494         
06495     top_rclr = 
06496     shade_table[shade_index + 3*0 + 0] * 
06497         ((num_materials > 1) ? weight_table[weight_index] : (float)1.0);
06498         
06499     top_gclr = 
06500     shade_table[shade_index + 3*0 + 1] * 
06501         ((num_materials > 1) ? weight_table[weight_index] : (float)1.0);
06502         
06503     top_bclr = 
06504     shade_table[shade_index + 3*0 + 2] * 
06505         ((num_materials > 1) ? weight_table[weight_index] : (float)1.0);
06506         
06507         top_rsclr = 
06508     shadow_table[shade_index + 3*0 + 0] * 
06509         ((num_materials > 1) ? weight_table[weight_index] : (float)1.0);
06510         
06511         top_gsclr = 
06512     shadow_table[shade_index + 3*0 + 1] * 
06513         ((num_materials > 1) ? weight_table[weight_index] : (float)1.0);
06514         
06515         top_bsclr = 
06516     shadow_table[shade_index + 3*0 + 2] * 
06517         ((num_materials > 1) ? weight_table[weight_index] : (float)1.0);
06518         for (m = 1; m < num_materials; m++) {
06519              
06520         
06521     top_rclr += 
06522     shade_table[shade_index + 3*m + 0] * 
06523         weight_table[weight_index + m];
06524         
06525     top_gclr += 
06526     shade_table[shade_index + 3*m + 1] * 
06527         weight_table[weight_index + m];
06528         
06529     top_bclr += 
06530     shade_table[shade_index + 3*m + 2] * 
06531         weight_table[weight_index + m];
06532         
06533         top_rsclr += 
06534     shadow_table[shade_index + 3*m + 0] * 
06535         weight_table[weight_index + m];
06536         
06537         top_gsclr += 
06538     shadow_table[shade_index + 3*m + 1] * 
06539         weight_table[weight_index + m];
06540         
06541         top_bsclr += 
06542     shadow_table[shade_index + 3*m + 2] * 
06543         weight_table[weight_index + m];
06544         };
06545     shade_factor = top_opc * slice_depth_cueing;
06546     
06547         top_rclr *= shade_factor;
06548         top_gclr *= shade_factor;
06549         top_bclr *= shade_factor;
06550     
06551             top_rsclr *= shade_factor;
06552             top_gsclr *= shade_factor;
06553             top_bsclr *= shade_factor;
06554                 }
06555                 
06556 #ifdef DEBUG
06557     if (ipixel == trace_pixel_ptr) {
06558         trace_opcTL = 0.; trace_opcBL = 0.; trace_opcTR = 0.; trace_opcBR = 0.;
06559         trace_rsclrTL=0.; trace_rsclrBL=0.; trace_rsclrTR=0.; trace_rsclrBR=0.;
06560         trace_rclrTL= 0.; trace_rclrBL= 0.; trace_rclrTR= 0.; trace_rclrBR= 0.;
06561         trace_gclrTL= 0.; trace_gclrBL= 0.; trace_gclrTR= 0.; trace_gclrBR= 0.;
06562         trace_bclrTL= 0.; trace_bclrBL= 0.; trace_bclrTR= 0.; trace_bclrBR= 0.;
06563     }
06564 #endif
06565 ;
06566                 
06567        acc_opc = top_opc * wgtTL;
06568        
06569             acc_rclr = (top_rclr + top_rsclr *
06570                          ((float)1.0 - shadow_pixel->opcflt)) * wgtTL;
06571             acc_gclr = (top_gclr + top_gsclr *
06572                          ((float)1.0 - shadow_pixel->opcflt)) * wgtTL;
06573             acc_bclr = (top_bclr + top_bsclr *
06574                          ((float)1.0 - shadow_pixel->opcflt)) * wgtTL;
06575        
06576 #ifdef DEBUG
06577     if (ipixel == trace_pixel_ptr) {
06578         trace_opcTL = top_opc;
06579         trace_rclrTL = top_rclr;
06580                      trace_gclrTL = top_gclr;
06581                      trace_bclrTL = top_bclr;
06582         
06583     }
06584 #endif
06585 ;
06586                 
06587     
06588             opac_param = VoxelField(topRLEdata, param0_offset, param0_size);
06589             opacity = param0_table[opac_param];
06590             if (param1_size != 0) {
06591                 opac_param = VoxelField(topRLEdata, param1_offset, param1_size);
06592                 opacity *= param1_table[opac_param];
06593                 if (param2_size != 0) {
06594                     opac_param = VoxelField(topRLEdata, param2_offset, param2_size);
06595                     opacity *= param2_table[opac_param];
06596                 }
06597             }
06598             if (opacity > min_opacity) {
06599                 opacity_int = opacity*255.;
06600                 top_opc = opac_correct[opacity_int];
06601             } else {
06602                 top_opc = (float)0.;
06603             };
06604     
06605     
06606     shade_index=num_materials*3*ShortField(topRLEdata,norm_offset);
06607     weight_index = num_materials * ByteField(topRLEdata, wgt_offset);
06608     
06609         
06610         
06611     top_rclr = 
06612     shade_table[shade_index + 3*0 + 0] * 
06613         ((num_materials > 1) ? weight_table[weight_index] : (float)1.0);
06614         
06615     top_gclr = 
06616     shade_table[shade_index + 3*0 + 1] * 
06617         ((num_materials > 1) ? weight_table[weight_index] : (float)1.0);
06618         
06619     top_bclr = 
06620     shade_table[shade_index + 3*0 + 2] * 
06621         ((num_materials > 1) ? weight_table[weight_index] : (float)1.0);
06622         
06623         top_rsclr = 
06624     shadow_table[shade_index + 3*0 + 0] * 
06625         ((num_materials > 1) ? weight_table[weight_index] : (float)1.0);
06626         
06627         top_gsclr = 
06628     shadow_table[shade_index + 3*0 + 1] * 
06629         ((num_materials > 1) ? weight_table[weight_index] : (float)1.0);
06630         
06631         top_bsclr = 
06632     shadow_table[shade_index + 3*0 + 2] * 
06633         ((num_materials > 1) ? weight_table[weight_index] : (float)1.0);
06634         for (m = 1; m < num_materials; m++) {
06635              
06636         
06637     top_rclr += 
06638     shade_table[shade_index + 3*m + 0] * 
06639         weight_table[weight_index + m];
06640         
06641     top_gclr += 
06642     shade_table[shade_index + 3*m + 1] * 
06643         weight_table[weight_index + m];
06644         
06645     top_bclr += 
06646     shade_table[shade_index + 3*m + 2] * 
06647         weight_table[weight_index + m];
06648         
06649         top_rsclr += 
06650     shadow_table[shade_index + 3*m + 0] * 
06651         weight_table[weight_index + m];
06652         
06653         top_gsclr += 
06654     shadow_table[shade_index + 3*m + 1] * 
06655         weight_table[weight_index + m];
06656         
06657         top_bsclr += 
06658     shadow_table[shade_index + 3*m + 2] * 
06659         weight_table[weight_index + m];
06660         };
06661     shade_factor = top_opc * slice_depth_cueing;
06662     
06663         top_rclr *= shade_factor;
06664         top_gclr *= shade_factor;
06665         top_bclr *= shade_factor;
06666     
06667             top_rsclr *= shade_factor;
06668             top_gsclr *= shade_factor;
06669             top_bsclr *= shade_factor;
06670                 
06671     
06672             opac_param = VoxelField(botRLEdata, param0_offset, param0_size);
06673             opacity = param0_table[opac_param];
06674             if (param1_size != 0) {
06675                 opac_param = VoxelField(botRLEdata, param1_offset, param1_size);
06676                 opacity *= param1_table[opac_param];
06677                 if (param2_size != 0) {
06678                     opac_param = VoxelField(botRLEdata, param2_offset, param2_size);
06679                     opacity *= param2_table[opac_param];
06680                 }
06681             }
06682             if (opacity > min_opacity) {
06683                 opacity_int = opacity*255.;
06684                 bot_opc = opac_correct[opacity_int];
06685             } else {
06686                 bot_opc = (float)0.;
06687             };
06688     
06689     
06690     shade_index=num_materials*3*ShortField(botRLEdata,norm_offset);
06691     weight_index = num_materials * ByteField(botRLEdata, wgt_offset);
06692     
06693         
06694         
06695     bot_rclr = 
06696     shade_table[shade_index + 3*0 + 0] * 
06697         ((num_materials > 1) ? weight_table[weight_index] : (float)1.0);
06698         
06699     bot_gclr = 
06700     shade_table[shade_index + 3*0 + 1] * 
06701         ((num_materials > 1) ? weight_table[weight_index] : (float)1.0);
06702         
06703     bot_bclr = 
06704     shade_table[shade_index + 3*0 + 2] * 
06705         ((num_materials > 1) ? weight_table[weight_index] : (float)1.0);
06706         
06707         bot_rsclr = 
06708     shadow_table[shade_index + 3*0 + 0] * 
06709         ((num_materials > 1) ? weight_table[weight_index] : (float)1.0);
06710         
06711         bot_gsclr = 
06712     shadow_table[shade_index + 3*0 + 1] * 
06713         ((num_materials > 1) ? weight_table[weight_index] : (float)1.0);
06714         
06715         bot_bsclr = 
06716     shadow_table[shade_index + 3*0 + 2] * 
06717         ((num_materials > 1) ? weight_table[weight_index] : (float)1.0);
06718         for (m = 1; m < num_materials; m++) {
06719              
06720         
06721     bot_rclr += 
06722     shade_table[shade_index + 3*m + 0] * 
06723         weight_table[weight_index + m];
06724         
06725     bot_gclr += 
06726     shade_table[shade_index + 3*m + 1] * 
06727         weight_table[weight_index + m];
06728         
06729     bot_bclr += 
06730     shade_table[shade_index + 3*m + 2] * 
06731         weight_table[weight_index + m];
06732         
06733         bot_rsclr += 
06734     shadow_table[shade_index + 3*m + 0] * 
06735         weight_table[weight_index + m];
06736         
06737         bot_gsclr += 
06738     shadow_table[shade_index + 3*m + 1] * 
06739         weight_table[weight_index + m];
06740         
06741         bot_bsclr += 
06742     shadow_table[shade_index + 3*m + 2] * 
06743         weight_table[weight_index + m];
06744         };
06745     shade_factor = bot_opc * slice_depth_cueing;
06746     
06747         bot_rclr *= shade_factor;
06748         bot_gclr *= shade_factor;
06749         bot_bclr *= shade_factor;
06750     
06751             bot_rsclr *= shade_factor;
06752             bot_gsclr *= shade_factor;
06753             bot_bsclr *= shade_factor;
06754                 
06755        acc_opc += top_opc * wgtTR;
06756        
06757             acc_rclr += (top_rclr + top_rsclr *
06758                          ((float)1.0 - shadow_pixel->opcflt)) * wgtTR;
06759             acc_gclr += (top_gclr + top_gsclr *
06760                          ((float)1.0 - shadow_pixel->opcflt)) * wgtTR;
06761             acc_bclr += (top_bclr + top_bsclr *
06762                          ((float)1.0 - shadow_pixel->opcflt)) * wgtTR;
06763        
06764 #ifdef DEBUG
06765     if (ipixel == trace_pixel_ptr) {
06766         trace_opcTR = top_opc;
06767         trace_rclrTR = top_rclr;
06768                      trace_gclrTR = top_gclr;
06769                      trace_bclrTR = top_bclr;
06770         
06771     }
06772 #endif
06773 ;
06774                 
06775        acc_opc += bot_opc * wgtBR;
06776        
06777             acc_rclr += (bot_rclr + bot_rsclr *
06778                          ((float)1.0 - shadow_pixel->opcflt)) * wgtBR;
06779             acc_gclr += (bot_gclr + bot_gsclr *
06780                          ((float)1.0 - shadow_pixel->opcflt)) * wgtBR;
06781             acc_bclr += (bot_bclr + bot_bsclr *
06782                          ((float)1.0 - shadow_pixel->opcflt)) * wgtBR;
06783        
06784 #ifdef DEBUG
06785     if (ipixel == trace_pixel_ptr) {
06786         trace_opcBR = bot_opc;
06787         trace_rclrBR = bot_rclr;
06788                      trace_gclrBR = bot_gclr;
06789                      trace_bclrBR = bot_bclr;
06790         
06791     }
06792 #endif
06793 ;
06794                 
06795         COUNT_RESAMPLE;
06796         if (acc_opc > min_opacity) {
06797             COUNT_COMPOSITE;
06798             iopc = ipixel->opcflt;
06799 #           ifndef SKIP_ERT
06800                 ASSERT(iopc < max_opacity);
06801 #           endif
06802             iopc_inv = (float)1. - iopc;
06803             
06804         ipixel->rclrflt += acc_rclr * iopc_inv;
06805         ipixel->gclrflt += acc_gclr * iopc_inv;
06806         ipixel->bclrflt += acc_bclr * iopc_inv;
06807             iopc += acc_opc * iopc_inv;
06808             ipixel->opcflt = iopc;
06809             
06810 #ifdef DEBUG
06811     if (ipixel == trace_pixel_ptr) {
06812 #ifdef COMPUTE_SHADOW_BUFFER
06813         printf("{%3d}  %3d %3d", k, icount-i-count, j);
06814 #else
06815         printf("[%3d]  %3d %3d", k, icount-i-count, j);
06816 #endif
06817         printf("  %3.0f %3.0f %3.0f",trace_opcTL*255.,trace_rclrTL,wgtTL*100.);
06818         printf("  %3.0f %3.0f %3.0f",trace_opcBL*255.,trace_rclrBL,wgtBL*100.);
06819         printf("  %3.0f %3.0f %3.0f",trace_opcTR*255.,trace_rclrTR,wgtTR*100.);
06820         printf("  %3.0f %3.0f %3.0f",trace_opcBR*255.,trace_rclrBR,wgtBR*100.);
06821         printf("  %3.0f %3.0f\n", iopc*255., 
06822                ipixel->rclrflt);
06823         
06824         printf("              ");
06825         printf("      %3.0f    ",trace_rsclrTL);
06826         printf("      %3.0f    ",trace_rsclrBL);
06827         printf("      %3.0f    ",trace_rsclrTR);
06828         printf("      %3.0f    ",trace_rsclrBR);
06829         printf("  %3.0f\n", shadow_pixel->opcflt * 255.);
06830         
06831         printf("              ");
06832         printf("      %3.0f    ",trace_gclrTL);
06833         printf("      %3.0f    ",trace_gclrBL);
06834         printf("      %3.0f    ",trace_gclrTR);
06835         printf("      %3.0f    ",trace_gclrBR);
06836         printf("      %3.0f\n", ipixel->gclrflt);
06837         printf("              ");
06838         printf("      %3.0f    ",trace_bclrTL);
06839         printf("      %3.0f    ",trace_bclrBL);
06840         printf("      %3.0f    ",trace_bclrTR);
06841         printf("      %3.0f    ",trace_bclrBR);
06842         printf("      %3.0f\n", ipixel->bclrflt);
06843     }
06844 #endif /* DEBUG */
06845 ;
06846 #           ifndef SKIP_ERT
06847                 if (iopc >= max_opacity) {
06848                     ASSERT(ipixel->lnk == 0);
06849                     ipixel->lnk = 1;
06850                 }
06851 #           endif
06852         };
06853                 ipixel += 1; shadow_pixel += 1;
06854                 topRLEdata += 1 * voxel_istride;
06855                 botRLEdata += 1 * voxel_istride;
06856                 count--;
06857                 SET_VOXELS_LOADED;
06858                     
06859                 /* do the rest of the pixels in this run;
06860                    all four voxels contribute */
06861                 while (count > 0) {
06862                     if (PIXEL_IS_OPAQUE(ipixel))
06863                         break;
06864                     if (!voxels_loaded) {
06865                         
06866     
06867             opac_param = VoxelField(topRLEdata - voxel_istride, param0_offset, param0_size);
06868             opacity = param0_table[opac_param];
06869             if (param1_size != 0) {
06870                 opac_param = VoxelField(topRLEdata - voxel_istride, param1_offset, param1_size);
06871                 opacity *= param1_table[opac_param];
06872                 if (param2_size != 0) {
06873                     opac_param = VoxelField(topRLEdata - voxel_istride, param2_offset, param2_size);
06874                     opacity *= param2_table[opac_param];
06875                 }
06876             }
06877             if (opacity > min_opacity) {
06878                 opacity_int = opacity*255.;
06879                 top_opc = opac_correct[opacity_int];
06880             } else {
06881                 top_opc = (float)0.;
06882             };
06883     
06884     
06885     shade_index=num_materials*3*ShortField(topRLEdata - voxel_istride,norm_offset);
06886     weight_index = num_materials * ByteField(topRLEdata - voxel_istride, wgt_offset);
06887     
06888         
06889         
06890     top_rclr = 
06891     shade_table[shade_index + 3*0 + 0] * 
06892         ((num_materials > 1) ? weight_table[weight_index] : (float)1.0);
06893         
06894     top_gclr = 
06895     shade_table[shade_index + 3*0 + 1] * 
06896         ((num_materials > 1) ? weight_table[weight_index] : (float)1.0);
06897         
06898     top_bclr = 
06899     shade_table[shade_index + 3*0 + 2] * 
06900         ((num_materials > 1) ? weight_table[weight_index] : (float)1.0);
06901         
06902         top_rsclr = 
06903     shadow_table[shade_index + 3*0 + 0] * 
06904         ((num_materials > 1) ? weight_table[weight_index] : (float)1.0);
06905         
06906         top_gsclr = 
06907     shadow_table[shade_index + 3*0 + 1] * 
06908         ((num_materials > 1) ? weight_table[weight_index] : (float)1.0);
06909         
06910         top_bsclr = 
06911     shadow_table[shade_index + 3*0 + 2] * 
06912         ((num_materials > 1) ? weight_table[weight_index] : (float)1.0);
06913         for (m = 1; m < num_materials; m++) {
06914              
06915         
06916     top_rclr += 
06917     shade_table[shade_index + 3*m + 0] * 
06918         weight_table[weight_index + m];
06919         
06920     top_gclr += 
06921     shade_table[shade_index + 3*m + 1] * 
06922         weight_table[weight_index + m];
06923         
06924     top_bclr += 
06925     shade_table[shade_index + 3*m + 2] * 
06926         weight_table[weight_index + m];
06927         
06928         top_rsclr += 
06929     shadow_table[shade_index + 3*m + 0] * 
06930         weight_table[weight_index + m];
06931         
06932         top_gsclr += 
06933     shadow_table[shade_index + 3*m + 1] * 
06934         weight_table[weight_index + m];
06935         
06936         top_bsclr += 
06937     shadow_table[shade_index + 3*m + 2] * 
06938         weight_table[weight_index + m];
06939         };
06940     shade_factor = top_opc * slice_depth_cueing;
06941     
06942         top_rclr *= shade_factor;
06943         top_gclr *= shade_factor;
06944         top_bclr *= shade_factor;
06945     
06946             top_rsclr *= shade_factor;
06947             top_gsclr *= shade_factor;
06948             top_bsclr *= shade_factor;
06949                         
06950     
06951             opac_param = VoxelField(botRLEdata - voxel_istride, param0_offset, param0_size);
06952             opacity = param0_table[opac_param];
06953             if (param1_size != 0) {
06954                 opac_param = VoxelField(botRLEdata - voxel_istride, param1_offset, param1_size);
06955                 opacity *= param1_table[opac_param];
06956                 if (param2_size != 0) {
06957                     opac_param = VoxelField(botRLEdata - voxel_istride, param2_offset, param2_size);
06958                     opacity *= param2_table[opac_param];
06959                 }
06960             }
06961             if (opacity > min_opacity) {
06962                 opacity_int = opacity*255.;
06963                 bot_opc = opac_correct[opacity_int];
06964             } else {
06965                 bot_opc = (float)0.;
06966             };
06967     
06968     
06969     shade_index=num_materials*3*ShortField(botRLEdata - voxel_istride,norm_offset);
06970     weight_index = num_materials * ByteField(botRLEdata - voxel_istride, wgt_offset);
06971     
06972         
06973         
06974     bot_rclr = 
06975     shade_table[shade_index + 3*0 + 0] * 
06976         ((num_materials > 1) ? weight_table[weight_index] : (float)1.0);
06977         
06978     bot_gclr = 
06979     shade_table[shade_index + 3*0 + 1] * 
06980         ((num_materials > 1) ? weight_table[weight_index] : (float)1.0);
06981         
06982     bot_bclr = 
06983     shade_table[shade_index + 3*0 + 2] * 
06984         ((num_materials > 1) ? weight_table[weight_index] : (float)1.0);
06985         
06986         bot_rsclr = 
06987     shadow_table[shade_index + 3*0 + 0] * 
06988         ((num_materials > 1) ? weight_table[weight_index] : (float)1.0);
06989         
06990         bot_gsclr = 
06991     shadow_table[shade_index + 3*0 + 1] * 
06992         ((num_materials > 1) ? weight_table[weight_index] : (float)1.0);
06993         
06994         bot_bsclr = 
06995     shadow_table[shade_index + 3*0 + 2] * 
06996         ((num_materials > 1) ? weight_table[weight_index] : (float)1.0);
06997         for (m = 1; m < num_materials; m++) {
06998              
06999         
07000     bot_rclr += 
07001     shade_table[shade_index + 3*m + 0] * 
07002         weight_table[weight_index + m];
07003         
07004     bot_gclr += 
07005     shade_table[shade_index + 3*m + 1] * 
07006         weight_table[weight_index + m];
07007         
07008     bot_bclr += 
07009     shade_table[shade_index + 3*m + 2] * 
07010         weight_table[weight_index + m];
07011         
07012         bot_rsclr += 
07013     shadow_table[shade_index + 3*m + 0] * 
07014         weight_table[weight_index + m];
07015         
07016         bot_gsclr += 
07017     shadow_table[shade_index + 3*m + 1] * 
07018         weight_table[weight_index + m];
07019         
07020         bot_bsclr += 
07021     shadow_table[shade_index + 3*m + 2] * 
07022         weight_table[weight_index + m];
07023         };
07024     shade_factor = bot_opc * slice_depth_cueing;
07025     
07026         bot_rclr *= shade_factor;
07027         bot_gclr *= shade_factor;
07028         bot_bclr *= shade_factor;
07029     
07030             bot_rsclr *= shade_factor;
07031             bot_gsclr *= shade_factor;
07032             bot_bsclr *= shade_factor;
07033                     }
07034                     
07035 #ifdef DEBUG
07036     if (ipixel == trace_pixel_ptr) {
07037         trace_opcTL = 0.; trace_opcBL = 0.; trace_opcTR = 0.; trace_opcBR = 0.;
07038         trace_rsclrTL=0.; trace_rsclrBL=0.; trace_rsclrTR=0.; trace_rsclrBR=0.;
07039         trace_rclrTL= 0.; trace_rclrBL= 0.; trace_rclrTR= 0.; trace_rclrBR= 0.;
07040         trace_gclrTL= 0.; trace_gclrBL= 0.; trace_gclrTR= 0.; trace_gclrBR= 0.;
07041         trace_bclrTL= 0.; trace_bclrBL= 0.; trace_bclrTR= 0.; trace_bclrBR= 0.;
07042     }
07043 #endif
07044 ;
07045                     
07046        acc_opc = top_opc * wgtTL;
07047        
07048             acc_rclr = (top_rclr + top_rsclr *
07049                          ((float)1.0 - shadow_pixel->opcflt)) * wgtTL;
07050             acc_gclr = (top_gclr + top_gsclr *
07051                          ((float)1.0 - shadow_pixel->opcflt)) * wgtTL;
07052             acc_bclr = (top_bclr + top_bsclr *
07053                          ((float)1.0 - shadow_pixel->opcflt)) * wgtTL;
07054        
07055 #ifdef DEBUG
07056     if (ipixel == trace_pixel_ptr) {
07057         trace_opcTL = top_opc;
07058         trace_rclrTL = top_rclr;
07059                      trace_gclrTL = top_gclr;
07060                      trace_bclrTL = top_bclr;
07061         
07062     }
07063 #endif
07064 ;
07065                     
07066        acc_opc += bot_opc * wgtBL;
07067        
07068             acc_rclr += (bot_rclr + bot_rsclr *
07069                          ((float)1.0 - shadow_pixel->opcflt)) * wgtBL;
07070             acc_gclr += (bot_gclr + bot_gsclr *
07071                          ((float)1.0 - shadow_pixel->opcflt)) * wgtBL;
07072             acc_bclr += (bot_bclr + bot_bsclr *
07073                          ((float)1.0 - shadow_pixel->opcflt)) * wgtBL;
07074        
07075 #ifdef DEBUG
07076     if (ipixel == trace_pixel_ptr) {
07077         trace_opcBL = bot_opc;
07078         trace_rclrBL = bot_rclr;
07079                      trace_gclrBL = bot_gclr;
07080                      trace_bclrBL = bot_bclr;
07081         
07082     }
07083 #endif
07084 ;
07085                     
07086     
07087             opac_param = VoxelField(topRLEdata, param0_offset, param0_size);
07088             opacity = param0_table[opac_param];
07089             if (param1_size != 0) {
07090                 opac_param = VoxelField(topRLEdata, param1_offset, param1_size);
07091                 opacity *= param1_table[opac_param];
07092                 if (param2_size != 0) {
07093                     opac_param = VoxelField(topRLEdata, param2_offset, param2_size);
07094                     opacity *= param2_table[opac_param];
07095                 }
07096             }
07097             if (opacity > min_opacity) {
07098                 opacity_int = opacity*255.;
07099                 top_opc = opac_correct[opacity_int];
07100             } else {
07101                 top_opc = (float)0.;
07102             };
07103     
07104     
07105     shade_index=num_materials*3*ShortField(topRLEdata,norm_offset);
07106     weight_index = num_materials * ByteField(topRLEdata, wgt_offset);
07107     
07108         
07109         
07110     top_rclr = 
07111     shade_table[shade_index + 3*0 + 0] * 
07112         ((num_materials > 1) ? weight_table[weight_index] : (float)1.0);
07113         
07114     top_gclr = 
07115     shade_table[shade_index + 3*0 + 1] * 
07116         ((num_materials > 1) ? weight_table[weight_index] : (float)1.0);
07117         
07118     top_bclr = 
07119     shade_table[shade_index + 3*0 + 2] * 
07120         ((num_materials > 1) ? weight_table[weight_index] : (float)1.0);
07121         
07122         top_rsclr = 
07123     shadow_table[shade_index + 3*0 + 0] * 
07124         ((num_materials > 1) ? weight_table[weight_index] : (float)1.0);
07125         
07126         top_gsclr = 
07127     shadow_table[shade_index + 3*0 + 1] * 
07128         ((num_materials > 1) ? weight_table[weight_index] : (float)1.0);
07129         
07130         top_bsclr = 
07131     shadow_table[shade_index + 3*0 + 2] * 
07132         ((num_materials > 1) ? weight_table[weight_index] : (float)1.0);
07133         for (m = 1; m < num_materials; m++) {
07134              
07135         
07136     top_rclr += 
07137     shade_table[shade_index + 3*m + 0] * 
07138         weight_table[weight_index + m];
07139         
07140     top_gclr += 
07141     shade_table[shade_index + 3*m + 1] * 
07142         weight_table[weight_index + m];
07143         
07144     top_bclr += 
07145     shade_table[shade_index + 3*m + 2] * 
07146         weight_table[weight_index + m];
07147         
07148         top_rsclr += 
07149     shadow_table[shade_index + 3*m + 0] * 
07150         weight_table[weight_index + m];
07151         
07152         top_gsclr += 
07153     shadow_table[shade_index + 3*m + 1] * 
07154         weight_table[weight_index + m];
07155         
07156         top_bsclr += 
07157     shadow_table[shade_index + 3*m + 2] * 
07158         weight_table[weight_index + m];
07159         };
07160     shade_factor = top_opc * slice_depth_cueing;
07161     
07162         top_rclr *= shade_factor;
07163         top_gclr *= shade_factor;
07164         top_bclr *= shade_factor;
07165     
07166             top_rsclr *= shade_factor;
07167             top_gsclr *= shade_factor;
07168             top_bsclr *= shade_factor;
07169                     
07170     
07171             opac_param = VoxelField(botRLEdata, param0_offset, param0_size);
07172             opacity = param0_table[opac_param];
07173             if (param1_size != 0) {
07174                 opac_param = VoxelField(botRLEdata, param1_offset, param1_size);
07175                 opacity *= param1_table[opac_param];
07176                 if (param2_size != 0) {
07177                     opac_param = VoxelField(botRLEdata, param2_offset, param2_size);
07178                     opacity *= param2_table[opac_param];
07179                 }
07180             }
07181             if (opacity > min_opacity) {
07182                 opacity_int = opacity*255.;
07183                 bot_opc = opac_correct[opacity_int];
07184             } else {
07185                 bot_opc = (float)0.;
07186             };
07187     
07188     
07189     shade_index=num_materials*3*ShortField(botRLEdata,norm_offset);
07190     weight_index = num_materials * ByteField(botRLEdata, wgt_offset);
07191     
07192         
07193         
07194     bot_rclr = 
07195     shade_table[shade_index + 3*0 + 0] * 
07196         ((num_materials > 1) ? weight_table[weight_index] : (float)1.0);
07197         
07198     bot_gclr = 
07199     shade_table[shade_index + 3*0 + 1] * 
07200         ((num_materials > 1) ? weight_table[weight_index] : (float)1.0);
07201         
07202     bot_bclr = 
07203     shade_table[shade_index + 3*0 + 2] * 
07204         ((num_materials > 1) ? weight_table[weight_index] : (float)1.0);
07205         
07206         bot_rsclr = 
07207     shadow_table[shade_index + 3*0 + 0] * 
07208         ((num_materials > 1) ? weight_table[weight_index] : (float)1.0);
07209         
07210         bot_gsclr = 
07211     shadow_table[shade_index + 3*0 + 1] * 
07212         ((num_materials > 1) ? weight_table[weight_index] : (float)1.0);
07213         
07214         bot_bsclr = 
07215     shadow_table[shade_index + 3*0 + 2] * 
07216         ((num_materials > 1) ? weight_table[weight_index] : (float)1.0);
07217         for (m = 1; m < num_materials; m++) {
07218              
07219         
07220     bot_rclr += 
07221     shade_table[shade_index + 3*m + 0] * 
07222         weight_table[weight_index + m];
07223         
07224     bot_gclr += 
07225     shade_table[shade_index + 3*m + 1] * 
07226         weight_table[weight_index + m];
07227         
07228     bot_bclr += 
07229     shade_table[shade_index + 3*m + 2] * 
07230         weight_table[weight_index + m];
07231         
07232         bot_rsclr += 
07233     shadow_table[shade_index + 3*m + 0] * 
07234         weight_table[weight_index + m];
07235         
07236         bot_gsclr += 
07237     shadow_table[shade_index + 3*m + 1] * 
07238         weight_table[weight_index + m];
07239         
07240         bot_bsclr += 
07241     shadow_table[shade_index + 3*m + 2] * 
07242         weight_table[weight_index + m];
07243         };
07244     shade_factor = bot_opc * slice_depth_cueing;
07245     
07246         bot_rclr *= shade_factor;
07247         bot_gclr *= shade_factor;
07248         bot_bclr *= shade_factor;
07249     
07250             bot_rsclr *= shade_factor;
07251             bot_gsclr *= shade_factor;
07252             bot_bsclr *= shade_factor;
07253                     
07254        acc_opc += top_opc * wgtTR;
07255        
07256             acc_rclr += (top_rclr + top_rsclr *
07257                          ((float)1.0 - shadow_pixel->opcflt)) * wgtTR;
07258             acc_gclr += (top_gclr + top_gsclr *
07259                          ((float)1.0 - shadow_pixel->opcflt)) * wgtTR;
07260             acc_bclr += (top_bclr + top_bsclr *
07261                          ((float)1.0 - shadow_pixel->opcflt)) * wgtTR;
07262        
07263 #ifdef DEBUG
07264     if (ipixel == trace_pixel_ptr) {
07265         trace_opcTR = top_opc;
07266         trace_rclrTR = top_rclr;
07267                      trace_gclrTR = top_gclr;
07268                      trace_bclrTR = top_bclr;
07269         
07270     }
07271 #endif
07272 ;
07273                     
07274        acc_opc += bot_opc * wgtBR;
07275        
07276             acc_rclr += (bot_rclr + bot_rsclr *
07277                          ((float)1.0 - shadow_pixel->opcflt)) * wgtBR;
07278             acc_gclr += (bot_gclr + bot_gsclr *
07279                          ((float)1.0 - shadow_pixel->opcflt)) * wgtBR;
07280             acc_bclr += (bot_bclr + bot_bsclr *
07281                          ((float)1.0 - shadow_pixel->opcflt)) * wgtBR;
07282        
07283 #ifdef DEBUG
07284     if (ipixel == trace_pixel_ptr) {
07285         trace_opcBR = bot_opc;
07286         trace_rclrBR = bot_rclr;
07287                      trace_gclrBR = bot_gclr;
07288                      trace_bclrBR = bot_bclr;
07289         
07290     }
07291 #endif
07292 ;
07293                     
07294         COUNT_RESAMPLE;
07295         if (acc_opc > min_opacity) {
07296             COUNT_COMPOSITE;
07297             iopc = ipixel->opcflt;
07298 #           ifndef SKIP_ERT
07299                 ASSERT(iopc < max_opacity);
07300 #           endif
07301             iopc_inv = (float)1. - iopc;
07302             
07303         ipixel->rclrflt += acc_rclr * iopc_inv;
07304         ipixel->gclrflt += acc_gclr * iopc_inv;
07305         ipixel->bclrflt += acc_bclr * iopc_inv;
07306             iopc += acc_opc * iopc_inv;
07307             ipixel->opcflt = iopc;
07308             
07309 #ifdef DEBUG
07310     if (ipixel == trace_pixel_ptr) {
07311 #ifdef COMPUTE_SHADOW_BUFFER
07312         printf("{%3d}  %3d %3d", k, icount-i-count, j);
07313 #else
07314         printf("[%3d]  %3d %3d", k, icount-i-count, j);
07315 #endif
07316         printf("  %3.0f %3.0f %3.0f",trace_opcTL*255.,trace_rclrTL,wgtTL*100.);
07317         printf("  %3.0f %3.0f %3.0f",trace_opcBL*255.,trace_rclrBL,wgtBL*100.);
07318         printf("  %3.0f %3.0f %3.0f",trace_opcTR*255.,trace_rclrTR,wgtTR*100.);
07319         printf("  %3.0f %3.0f %3.0f",trace_opcBR*255.,trace_rclrBR,wgtBR*100.);
07320         printf("  %3.0f %3.0f\n", iopc*255., 
07321                ipixel->rclrflt);
07322         
07323         printf("              ");
07324         printf("      %3.0f    ",trace_rsclrTL);
07325         printf("      %3.0f    ",trace_rsclrBL);
07326         printf("      %3.0f    ",trace_rsclrTR);
07327         printf("      %3.0f    ",trace_rsclrBR);
07328         printf("  %3.0f\n", shadow_pixel->opcflt * 255.);
07329         
07330         printf("              ");
07331         printf("      %3.0f    ",trace_gclrTL);
07332         printf("      %3.0f    ",trace_gclrBL);
07333         printf("      %3.0f    ",trace_gclrTR);
07334         printf("      %3.0f    ",trace_gclrBR);
07335         printf("      %3.0f\n", ipixel->gclrflt);
07336         printf("              ");
07337         printf("      %3.0f    ",trace_bclrTL);
07338         printf("      %3.0f    ",trace_bclrBL);
07339         printf("      %3.0f    ",trace_bclrTR);
07340         printf("      %3.0f    ",trace_bclrBR);
07341         printf("      %3.0f\n", ipixel->bclrflt);
07342     }
07343 #endif /* DEBUG */
07344 ;
07345 #           ifndef SKIP_ERT
07346                 if (iopc >= max_opacity) {
07347                     ASSERT(ipixel->lnk == 0);
07348                     ipixel->lnk = 1;
07349                 }
07350 #           endif
07351         };
07352                     ipixel += 1; shadow_pixel += 1;
07353                     topRLEdata += 1 * voxel_istride;
07354                     botRLEdata += 1 * voxel_istride;
07355                     count--;
07356                     SET_VOXELS_LOADED;
07357                 }
07358                 break;
07359             case BOT_NONZERO__ALL_NONZERO:
07360                 /* first pixel: bottom-left, top-right and bottom-right
07361                    voxels contribute */
07362                 if (!voxels_loaded) {
07363                     
07364     
07365             opac_param = VoxelField(botRLEdata - voxel_istride, param0_offset, param0_size);
07366             opacity = param0_table[opac_param];
07367             if (param1_size != 0) {
07368                 opac_param = VoxelField(botRLEdata - voxel_istride, param1_offset, param1_size);
07369                 opacity *= param1_table[opac_param];
07370                 if (param2_size != 0) {
07371                     opac_param = VoxelField(botRLEdata - voxel_istride, param2_offset, param2_size);
07372                     opacity *= param2_table[opac_param];
07373                 }
07374             }
07375             if (opacity > min_opacity) {
07376                 opacity_int = opacity*255.;
07377                 bot_opc = opac_correct[opacity_int];
07378             } else {
07379                 bot_opc = (float)0.;
07380             };
07381     
07382     
07383     shade_index=num_materials*3*ShortField(botRLEdata - voxel_istride,norm_offset);
07384     weight_index = num_materials * ByteField(botRLEdata - voxel_istride, wgt_offset);
07385     
07386         
07387         
07388     bot_rclr = 
07389     shade_table[shade_index + 3*0 + 0] * 
07390         ((num_materials > 1) ? weight_table[weight_index] : (float)1.0);
07391         
07392     bot_gclr = 
07393     shade_table[shade_index + 3*0 + 1] * 
07394         ((num_materials > 1) ? weight_table[weight_index] : (float)1.0);
07395         
07396     bot_bclr = 
07397     shade_table[shade_index + 3*0 + 2] * 
07398         ((num_materials > 1) ? weight_table[weight_index] : (float)1.0);
07399         
07400         bot_rsclr = 
07401     shadow_table[shade_index + 3*0 + 0] * 
07402         ((num_materials > 1) ? weight_table[weight_index] : (float)1.0);
07403         
07404         bot_gsclr = 
07405     shadow_table[shade_index + 3*0 + 1] * 
07406         ((num_materials > 1) ? weight_table[weight_index] : (float)1.0);
07407         
07408         bot_bsclr = 
07409     shadow_table[shade_index + 3*0 + 2] * 
07410         ((num_materials > 1) ? weight_table[weight_index] : (float)1.0);
07411         for (m = 1; m < num_materials; m++) {
07412              
07413         
07414     bot_rclr += 
07415     shade_table[shade_index + 3*m + 0] * 
07416         weight_table[weight_index + m];
07417         
07418     bot_gclr += 
07419     shade_table[shade_index + 3*m + 1] * 
07420         weight_table[weight_index + m];
07421         
07422     bot_bclr += 
07423     shade_table[shade_index + 3*m + 2] * 
07424         weight_table[weight_index + m];
07425         
07426         bot_rsclr += 
07427     shadow_table[shade_index + 3*m + 0] * 
07428         weight_table[weight_index + m];
07429         
07430         bot_gsclr += 
07431     shadow_table[shade_index + 3*m + 1] * 
07432         weight_table[weight_index + m];
07433         
07434         bot_bsclr += 
07435     shadow_table[shade_index + 3*m + 2] * 
07436         weight_table[weight_index + m];
07437         };
07438     shade_factor = bot_opc * slice_depth_cueing;
07439     
07440         bot_rclr *= shade_factor;
07441         bot_gclr *= shade_factor;
07442         bot_bclr *= shade_factor;
07443     
07444             bot_rsclr *= shade_factor;
07445             bot_gsclr *= shade_factor;
07446             bot_bsclr *= shade_factor;
07447                 }
07448                 
07449 #ifdef DEBUG
07450     if (ipixel == trace_pixel_ptr) {
07451         trace_opcTL = 0.; trace_opcBL = 0.; trace_opcTR = 0.; trace_opcBR = 0.;
07452         trace_rsclrTL=0.; trace_rsclrBL=0.; trace_rsclrTR=0.; trace_rsclrBR=0.;
07453         trace_rclrTL= 0.; trace_rclrBL= 0.; trace_rclrTR= 0.; trace_rclrBR= 0.;
07454         trace_gclrTL= 0.; trace_gclrBL= 0.; trace_gclrTR= 0.; trace_gclrBR= 0.;
07455         trace_bclrTL= 0.; trace_bclrBL= 0.; trace_bclrTR= 0.; trace_bclrBR= 0.;
07456     }
07457 #endif
07458 ;
07459                 
07460        acc_opc = bot_opc * wgtBL;
07461        
07462             acc_rclr = (bot_rclr + bot_rsclr *
07463                          ((float)1.0 - shadow_pixel->opcflt)) * wgtBL;
07464             acc_gclr = (bot_gclr + bot_gsclr *
07465                          ((float)1.0 - shadow_pixel->opcflt)) * wgtBL;
07466             acc_bclr = (bot_bclr + bot_bsclr *
07467                          ((float)1.0 - shadow_pixel->opcflt)) * wgtBL;
07468        
07469 #ifdef DEBUG
07470     if (ipixel == trace_pixel_ptr) {
07471         trace_opcBL = bot_opc;
07472         trace_rclrBL = bot_rclr;
07473                      trace_gclrBL = bot_gclr;
07474                      trace_bclrBL = bot_bclr;
07475         
07476     }
07477 #endif
07478 ;
07479                 
07480     
07481             opac_param = VoxelField(topRLEdata, param0_offset, param0_size);
07482             opacity = param0_table[opac_param];
07483             if (param1_size != 0) {
07484                 opac_param = VoxelField(topRLEdata, param1_offset, param1_size);
07485                 opacity *= param1_table[opac_param];
07486                 if (param2_size != 0) {
07487                     opac_param = VoxelField(topRLEdata, param2_offset, param2_size);
07488                     opacity *= param2_table[opac_param];
07489                 }
07490             }
07491             if (opacity > min_opacity) {
07492                 opacity_int = opacity*255.;
07493                 top_opc = opac_correct[opacity_int];
07494             } else {
07495                 top_opc = (float)0.;
07496             };
07497     
07498     
07499     shade_index=num_materials*3*ShortField(topRLEdata,norm_offset);
07500     weight_index = num_materials * ByteField(topRLEdata, wgt_offset);
07501     
07502         
07503         
07504     top_rclr = 
07505     shade_table[shade_index + 3*0 + 0] * 
07506         ((num_materials > 1) ? weight_table[weight_index] : (float)1.0);
07507         
07508     top_gclr = 
07509     shade_table[shade_index + 3*0 + 1] * 
07510         ((num_materials > 1) ? weight_table[weight_index] : (float)1.0);
07511         
07512     top_bclr = 
07513     shade_table[shade_index + 3*0 + 2] * 
07514         ((num_materials > 1) ? weight_table[weight_index] : (float)1.0);
07515         
07516         top_rsclr = 
07517     shadow_table[shade_index + 3*0 + 0] * 
07518         ((num_materials > 1) ? weight_table[weight_index] : (float)1.0);
07519         
07520         top_gsclr = 
07521     shadow_table[shade_index + 3*0 + 1] * 
07522         ((num_materials > 1) ? weight_table[weight_index] : (float)1.0);
07523         
07524         top_bsclr = 
07525     shadow_table[shade_index + 3*0 + 2] * 
07526         ((num_materials > 1) ? weight_table[weight_index] : (float)1.0);
07527         for (m = 1; m < num_materials; m++) {
07528              
07529         
07530     top_rclr += 
07531     shade_table[shade_index + 3*m + 0] * 
07532         weight_table[weight_index + m];
07533         
07534     top_gclr += 
07535     shade_table[shade_index + 3*m + 1] * 
07536         weight_table[weight_index + m];
07537         
07538     top_bclr += 
07539     shade_table[shade_index + 3*m + 2] * 
07540         weight_table[weight_index + m];
07541         
07542         top_rsclr += 
07543     shadow_table[shade_index + 3*m + 0] * 
07544         weight_table[weight_index + m];
07545         
07546         top_gsclr += 
07547     shadow_table[shade_index + 3*m + 1] * 
07548         weight_table[weight_index + m];
07549         
07550         top_bsclr += 
07551     shadow_table[shade_index + 3*m + 2] * 
07552         weight_table[weight_index + m];
07553         };
07554     shade_factor = top_opc * slice_depth_cueing;
07555     
07556         top_rclr *= shade_factor;
07557         top_gclr *= shade_factor;
07558         top_bclr *= shade_factor;
07559     
07560             top_rsclr *= shade_factor;
07561             top_gsclr *= shade_factor;
07562             top_bsclr *= shade_factor;
07563                 
07564     
07565             opac_param = VoxelField(botRLEdata, param0_offset, param0_size);
07566             opacity = param0_table[opac_param];
07567             if (param1_size != 0) {
07568                 opac_param = VoxelField(botRLEdata, param1_offset, param1_size);
07569                 opacity *= param1_table[opac_param];
07570                 if (param2_size != 0) {
07571                     opac_param = VoxelField(botRLEdata, param2_offset, param2_size);
07572                     opacity *= param2_table[opac_param];
07573                 }
07574             }
07575             if (opacity > min_opacity) {
07576                 opacity_int = opacity*255.;
07577                 bot_opc = opac_correct[opacity_int];
07578             } else {
07579                 bot_opc = (float)0.;
07580             };
07581     
07582     
07583     shade_index=num_materials*3*ShortField(botRLEdata,norm_offset);
07584     weight_index = num_materials * ByteField(botRLEdata, wgt_offset);
07585     
07586         
07587         
07588     bot_rclr = 
07589     shade_table[shade_index + 3*0 + 0] * 
07590         ((num_materials > 1) ? weight_table[weight_index] : (float)1.0);
07591         
07592     bot_gclr = 
07593     shade_table[shade_index + 3*0 + 1] * 
07594         ((num_materials > 1) ? weight_table[weight_index] : (float)1.0);
07595         
07596     bot_bclr = 
07597     shade_table[shade_index + 3*0 + 2] * 
07598         ((num_materials > 1) ? weight_table[weight_index] : (float)1.0);
07599         
07600         bot_rsclr = 
07601     shadow_table[shade_index + 3*0 + 0] * 
07602         ((num_materials > 1) ? weight_table[weight_index] : (float)1.0);
07603         
07604         bot_gsclr = 
07605     shadow_table[shade_index + 3*0 + 1] * 
07606         ((num_materials > 1) ? weight_table[weight_index] : (float)1.0);
07607         
07608         bot_bsclr = 
07609     shadow_table[shade_index + 3*0 + 2] * 
07610         ((num_materials > 1) ? weight_table[weight_index] : (float)1.0);
07611         for (m = 1; m < num_materials; m++) {
07612              
07613         
07614     bot_rclr += 
07615     shade_table[shade_index + 3*m + 0] * 
07616         weight_table[weight_index + m];
07617         
07618     bot_gclr += 
07619     shade_table[shade_index + 3*m + 1] * 
07620         weight_table[weight_index + m];
07621         
07622     bot_bclr += 
07623     shade_table[shade_index + 3*m + 2] * 
07624         weight_table[weight_index + m];
07625         
07626         bot_rsclr += 
07627     shadow_table[shade_index + 3*m + 0] * 
07628         weight_table[weight_index + m];
07629         
07630         bot_gsclr += 
07631     shadow_table[shade_index + 3*m + 1] * 
07632         weight_table[weight_index + m];
07633         
07634         bot_bsclr += 
07635     shadow_table[shade_index + 3*m + 2] * 
07636         weight_table[weight_index + m];
07637         };
07638     shade_factor = bot_opc * slice_depth_cueing;
07639     
07640         bot_rclr *= shade_factor;
07641         bot_gclr *= shade_factor;
07642         bot_bclr *= shade_factor;
07643     
07644             bot_rsclr *= shade_factor;
07645             bot_gsclr *= shade_factor;
07646             bot_bsclr *= shade_factor;
07647                 
07648        acc_opc += top_opc * wgtTR;
07649        
07650             acc_rclr += (top_rclr + top_rsclr *
07651                          ((float)1.0 - shadow_pixel->opcflt)) * wgtTR;
07652             acc_gclr += (top_gclr + top_gsclr *
07653                          ((float)1.0 - shadow_pixel->opcflt)) * wgtTR;
07654             acc_bclr += (top_bclr + top_bsclr *
07655                          ((float)1.0 - shadow_pixel->opcflt)) * wgtTR;
07656        
07657 #ifdef DEBUG
07658     if (ipixel == trace_pixel_ptr) {
07659         trace_opcTR = top_opc;
07660         trace_rclrTR = top_rclr;
07661                      trace_gclrTR = top_gclr;
07662                      trace_bclrTR = top_bclr;
07663         
07664     }
07665 #endif
07666 ;
07667                 
07668        acc_opc += bot_opc * wgtBR;
07669        
07670             acc_rclr += (bot_rclr + bot_rsclr *
07671                          ((float)1.0 - shadow_pixel->opcflt)) * wgtBR;
07672             acc_gclr += (bot_gclr + bot_gsclr *
07673                          ((float)1.0 - shadow_pixel->opcflt)) * wgtBR;
07674             acc_bclr += (bot_bclr + bot_bsclr *
07675                          ((float)1.0 - shadow_pixel->opcflt)) * wgtBR;
07676        
07677 #ifdef DEBUG
07678     if (ipixel == trace_pixel_ptr) {
07679         trace_opcBR = bot_opc;
07680         trace_rclrBR = bot_rclr;
07681                      trace_gclrBR = bot_gclr;
07682                      trace_bclrBR = bot_bclr;
07683         
07684     }
07685 #endif
07686 ;
07687                 
07688         COUNT_RESAMPLE;
07689         if (acc_opc > min_opacity) {
07690             COUNT_COMPOSITE;
07691             iopc = ipixel->opcflt;
07692 #           ifndef SKIP_ERT
07693                 ASSERT(iopc < max_opacity);
07694 #           endif
07695             iopc_inv = (float)1. - iopc;
07696             
07697         ipixel->rclrflt += acc_rclr * iopc_inv;
07698         ipixel->gclrflt += acc_gclr * iopc_inv;
07699         ipixel->bclrflt += acc_bclr * iopc_inv;
07700             iopc += acc_opc * iopc_inv;
07701             ipixel->opcflt = iopc;
07702             
07703 #ifdef DEBUG
07704     if (ipixel == trace_pixel_ptr) {
07705 #ifdef COMPUTE_SHADOW_BUFFER
07706         printf("{%3d}  %3d %3d", k, icount-i-count, j);
07707 #else
07708         printf("[%3d]  %3d %3d", k, icount-i-count, j);
07709 #endif
07710         printf("  %3.0f %3.0f %3.0f",trace_opcTL*255.,trace_rclrTL,wgtTL*100.);
07711         printf("  %3.0f %3.0f %3.0f",trace_opcBL*255.,trace_rclrBL,wgtBL*100.);
07712         printf("  %3.0f %3.0f %3.0f",trace_opcTR*255.,trace_rclrTR,wgtTR*100.);
07713         printf("  %3.0f %3.0f %3.0f",trace_opcBR*255.,trace_rclrBR,wgtBR*100.);
07714         printf("  %3.0f %3.0f\n", iopc*255., 
07715                ipixel->rclrflt);
07716         
07717         printf("              ");
07718         printf("      %3.0f    ",trace_rsclrTL);
07719         printf("      %3.0f    ",trace_rsclrBL);
07720         printf("      %3.0f    ",trace_rsclrTR);
07721         printf("      %3.0f    ",trace_rsclrBR);
07722         printf("  %3.0f\n", shadow_pixel->opcflt * 255.);
07723         
07724         printf("              ");
07725         printf("      %3.0f    ",trace_gclrTL);
07726         printf("      %3.0f    ",trace_gclrBL);
07727         printf("      %3.0f    ",trace_gclrTR);
07728         printf("      %3.0f    ",trace_gclrBR);
07729         printf("      %3.0f\n", ipixel->gclrflt);
07730         printf("              ");
07731         printf("      %3.0f    ",trace_bclrTL);
07732         printf("      %3.0f    ",trace_bclrBL);
07733         printf("      %3.0f    ",trace_bclrTR);
07734         printf("      %3.0f    ",trace_bclrBR);
07735         printf("      %3.0f\n", ipixel->bclrflt);
07736     }
07737 #endif /* DEBUG */
07738 ;
07739 #           ifndef SKIP_ERT
07740                 if (iopc >= max_opacity) {
07741                     ASSERT(ipixel->lnk == 0);
07742                     ipixel->lnk = 1;
07743                 }
07744 #           endif
07745         };
07746                 ipixel += 1; shadow_pixel += 1;
07747                 topRLEdata += 1 * voxel_istride;
07748                 botRLEdata += 1 * voxel_istride;
07749                 count--;
07750                 SET_VOXELS_LOADED;
07751                     
07752                 /* do the rest of the pixels in this run;
07753                    all four voxels contribute */
07754                 while (count > 0) {
07755                     if (PIXEL_IS_OPAQUE(ipixel))
07756                         break;
07757                     if (!voxels_loaded) {
07758                         
07759     
07760             opac_param = VoxelField(topRLEdata - voxel_istride, param0_offset, param0_size);
07761             opacity = param0_table[opac_param];
07762             if (param1_size != 0) {
07763                 opac_param = VoxelField(topRLEdata - voxel_istride, param1_offset, param1_size);
07764                 opacity *= param1_table[opac_param];
07765                 if (param2_size != 0) {
07766                     opac_param = VoxelField(topRLEdata - voxel_istride, param2_offset, param2_size);
07767                     opacity *= param2_table[opac_param];
07768                 }
07769             }
07770             if (opacity > min_opacity) {
07771                 opacity_int = opacity*255.;
07772                 top_opc = opac_correct[opacity_int];
07773             } else {
07774                 top_opc = (float)0.;
07775             };
07776     
07777     
07778     shade_index=num_materials*3*ShortField(topRLEdata - voxel_istride,norm_offset);
07779     weight_index = num_materials * ByteField(topRLEdata - voxel_istride, wgt_offset);
07780     
07781         
07782         
07783     top_rclr = 
07784     shade_table[shade_index + 3*0 + 0] * 
07785         ((num_materials > 1) ? weight_table[weight_index] : (float)1.0);
07786         
07787     top_gclr = 
07788     shade_table[shade_index + 3*0 + 1] * 
07789         ((num_materials > 1) ? weight_table[weight_index] : (float)1.0);
07790         
07791     top_bclr = 
07792     shade_table[shade_index + 3*0 + 2] * 
07793         ((num_materials > 1) ? weight_table[weight_index] : (float)1.0);
07794         
07795         top_rsclr = 
07796     shadow_table[shade_index + 3*0 + 0] * 
07797         ((num_materials > 1) ? weight_table[weight_index] : (float)1.0);
07798         
07799         top_gsclr = 
07800     shadow_table[shade_index + 3*0 + 1] * 
07801         ((num_materials > 1) ? weight_table[weight_index] : (float)1.0);
07802         
07803         top_bsclr = 
07804     shadow_table[shade_index + 3*0 + 2] * 
07805         ((num_materials > 1) ? weight_table[weight_index] : (float)1.0);
07806         for (m = 1; m < num_materials; m++) {
07807              
07808         
07809     top_rclr += 
07810     shade_table[shade_index + 3*m + 0] * 
07811         weight_table[weight_index + m];
07812         
07813     top_gclr += 
07814     shade_table[shade_index + 3*m + 1] * 
07815         weight_table[weight_index + m];
07816         
07817     top_bclr += 
07818     shade_table[shade_index + 3*m + 2] * 
07819         weight_table[weight_index + m];
07820         
07821         top_rsclr += 
07822     shadow_table[shade_index + 3*m + 0] * 
07823         weight_table[weight_index + m];
07824         
07825         top_gsclr += 
07826     shadow_table[shade_index + 3*m + 1] * 
07827         weight_table[weight_index + m];
07828         
07829         top_bsclr += 
07830     shadow_table[shade_index + 3*m + 2] * 
07831         weight_table[weight_index + m];
07832         };
07833     shade_factor = top_opc * slice_depth_cueing;
07834     
07835         top_rclr *= shade_factor;
07836         top_gclr *= shade_factor;
07837         top_bclr *= shade_factor;
07838     
07839             top_rsclr *= shade_factor;
07840             top_gsclr *= shade_factor;
07841             top_bsclr *= shade_factor;
07842                         
07843     
07844             opac_param = VoxelField(botRLEdata - voxel_istride, param0_offset, param0_size);
07845             opacity = param0_table[opac_param];
07846             if (param1_size != 0) {
07847                 opac_param = VoxelField(botRLEdata - voxel_istride, param1_offset, param1_size);
07848                 opacity *= param1_table[opac_param];
07849                 if (param2_size != 0) {
07850                     opac_param = VoxelField(botRLEdata - voxel_istride, param2_offset, param2_size);
07851                     opacity *= param2_table[opac_param];
07852                 }
07853             }
07854             if (opacity > min_opacity) {
07855                 opacity_int = opacity*255.;
07856                 bot_opc = opac_correct[opacity_int];
07857             } else {
07858                 bot_opc = (float)0.;
07859             };
07860     
07861     
07862     shade_index=num_materials*3*ShortField(botRLEdata - voxel_istride,norm_offset);
07863     weight_index = num_materials * ByteField(botRLEdata - voxel_istride, wgt_offset);
07864     
07865         
07866         
07867     bot_rclr = 
07868     shade_table[shade_index + 3*0 + 0] * 
07869         ((num_materials > 1) ? weight_table[weight_index] : (float)1.0);
07870         
07871     bot_gclr = 
07872     shade_table[shade_index + 3*0 + 1] * 
07873         ((num_materials > 1) ? weight_table[weight_index] : (float)1.0);
07874         
07875     bot_bclr = 
07876     shade_table[shade_index + 3*0 + 2] * 
07877         ((num_materials > 1) ? weight_table[weight_index] : (float)1.0);
07878         
07879         bot_rsclr = 
07880     shadow_table[shade_index + 3*0 + 0] * 
07881         ((num_materials > 1) ? weight_table[weight_index] : (float)1.0);
07882         
07883         bot_gsclr = 
07884     shadow_table[shade_index + 3*0 + 1] * 
07885         ((num_materials > 1) ? weight_table[weight_index] : (float)1.0);
07886         
07887         bot_bsclr = 
07888     shadow_table[shade_index + 3*0 + 2] * 
07889         ((num_materials > 1) ? weight_table[weight_index] : (float)1.0);
07890         for (m = 1; m < num_materials; m++) {
07891              
07892         
07893     bot_rclr += 
07894     shade_table[shade_index + 3*m + 0] * 
07895         weight_table[weight_index + m];
07896         
07897     bot_gclr += 
07898     shade_table[shade_index + 3*m + 1] * 
07899         weight_table[weight_index + m];
07900         
07901     bot_bclr += 
07902     shade_table[shade_index + 3*m + 2] * 
07903         weight_table[weight_index + m];
07904         
07905         bot_rsclr += 
07906     shadow_table[shade_index + 3*m + 0] * 
07907         weight_table[weight_index + m];
07908         
07909         bot_gsclr += 
07910     shadow_table[shade_index + 3*m + 1] * 
07911         weight_table[weight_index + m];
07912         
07913         bot_bsclr += 
07914     shadow_table[shade_index + 3*m + 2] * 
07915         weight_table[weight_index + m];
07916         };
07917     shade_factor = bot_opc * slice_depth_cueing;
07918     
07919         bot_rclr *= shade_factor;
07920         bot_gclr *= shade_factor;
07921         bot_bclr *= shade_factor;
07922     
07923             bot_rsclr *= shade_factor;
07924             bot_gsclr *= shade_factor;
07925             bot_bsclr *= shade_factor;
07926                     }
07927                     
07928 #ifdef DEBUG
07929     if (ipixel == trace_pixel_ptr) {
07930         trace_opcTL = 0.; trace_opcBL = 0.; trace_opcTR = 0.; trace_opcBR = 0.;
07931         trace_rsclrTL=0.; trace_rsclrBL=0.; trace_rsclrTR=0.; trace_rsclrBR=0.;
07932         trace_rclrTL= 0.; trace_rclrBL= 0.; trace_rclrTR= 0.; trace_rclrBR= 0.;
07933         trace_gclrTL= 0.; trace_gclrBL= 0.; trace_gclrTR= 0.; trace_gclrBR= 0.;
07934         trace_bclrTL= 0.; trace_bclrBL= 0.; trace_bclrTR= 0.; trace_bclrBR= 0.;
07935     }
07936 #endif
07937 ;
07938                     
07939        acc_opc = top_opc * wgtTL;
07940        
07941             acc_rclr = (top_rclr + top_rsclr *
07942                          ((float)1.0 - shadow_pixel->opcflt)) * wgtTL;
07943             acc_gclr = (top_gclr + top_gsclr *
07944                          ((float)1.0 - shadow_pixel->opcflt)) * wgtTL;
07945             acc_bclr = (top_bclr + top_bsclr *
07946                          ((float)1.0 - shadow_pixel->opcflt)) * wgtTL;
07947        
07948 #ifdef DEBUG
07949     if (ipixel == trace_pixel_ptr) {
07950         trace_opcTL = top_opc;
07951         trace_rclrTL = top_rclr;
07952                      trace_gclrTL = top_gclr;
07953                      trace_bclrTL = top_bclr;
07954         
07955     }
07956 #endif
07957 ;
07958                     
07959        acc_opc += bot_opc * wgtBL;
07960        
07961             acc_rclr += (bot_rclr + bot_rsclr *
07962                          ((float)1.0 - shadow_pixel->opcflt)) * wgtBL;
07963             acc_gclr += (bot_gclr + bot_gsclr *
07964                          ((float)1.0 - shadow_pixel->opcflt)) * wgtBL;
07965             acc_bclr += (bot_bclr + bot_bsclr *
07966                          ((float)1.0 - shadow_pixel->opcflt)) * wgtBL;
07967        
07968 #ifdef DEBUG
07969     if (ipixel == trace_pixel_ptr) {
07970         trace_opcBL = bot_opc;
07971         trace_rclrBL = bot_rclr;
07972                      trace_gclrBL = bot_gclr;
07973                      trace_bclrBL = bot_bclr;
07974         
07975     }
07976 #endif
07977 ;
07978                     
07979     
07980             opac_param = VoxelField(topRLEdata, param0_offset, param0_size);
07981             opacity = param0_table[opac_param];
07982             if (param1_size != 0) {
07983                 opac_param = VoxelField(topRLEdata, param1_offset, param1_size);
07984                 opacity *= param1_table[opac_param];
07985                 if (param2_size != 0) {
07986                     opac_param = VoxelField(topRLEdata, param2_offset, param2_size);
07987                     opacity *= param2_table[opac_param];
07988                 }
07989             }
07990             if (opacity > min_opacity) {
07991                 opacity_int = opacity*255.;
07992                 top_opc = opac_correct[opacity_int];
07993             } else {
07994                 top_opc = (float)0.;
07995             };
07996     
07997     
07998     shade_index=num_materials*3*ShortField(topRLEdata,norm_offset);
07999     weight_index = num_materials * ByteField(topRLEdata, wgt_offset);
08000     
08001         
08002         
08003     top_rclr = 
08004     shade_table[shade_index + 3*0 + 0] * 
08005         ((num_materials > 1) ? weight_table[weight_index] : (float)1.0);
08006         
08007     top_gclr = 
08008     shade_table[shade_index + 3*0 + 1] * 
08009         ((num_materials > 1) ? weight_table[weight_index] : (float)1.0);
08010         
08011     top_bclr = 
08012     shade_table[shade_index + 3*0 + 2] * 
08013         ((num_materials > 1) ? weight_table[weight_index] : (float)1.0);
08014         
08015         top_rsclr = 
08016     shadow_table[shade_index + 3*0 + 0] * 
08017         ((num_materials > 1) ? weight_table[weight_index] : (float)1.0);
08018         
08019         top_gsclr = 
08020     shadow_table[shade_index + 3*0 + 1] * 
08021         ((num_materials > 1) ? weight_table[weight_index] : (float)1.0);
08022         
08023         top_bsclr = 
08024     shadow_table[shade_index + 3*0 + 2] * 
08025         ((num_materials > 1) ? weight_table[weight_index] : (float)1.0);
08026         for (m = 1; m < num_materials; m++) {
08027              
08028         
08029     top_rclr += 
08030     shade_table[shade_index + 3*m + 0] * 
08031         weight_table[weight_index + m];
08032         
08033     top_gclr += 
08034     shade_table[shade_index + 3*m + 1] * 
08035         weight_table[weight_index + m];
08036         
08037     top_bclr += 
08038     shade_table[shade_index + 3*m + 2] * 
08039         weight_table[weight_index + m];
08040         
08041         top_rsclr += 
08042     shadow_table[shade_index + 3*m + 0] * 
08043         weight_table[weight_index + m];
08044         
08045         top_gsclr += 
08046     shadow_table[shade_index + 3*m + 1] * 
08047         weight_table[weight_index + m];
08048         
08049         top_bsclr += 
08050     shadow_table[shade_index + 3*m + 2] * 
08051         weight_table[weight_index + m];
08052         };
08053     shade_factor = top_opc * slice_depth_cueing;
08054     
08055         top_rclr *= shade_factor;
08056         top_gclr *= shade_factor;
08057         top_bclr *= shade_factor;
08058     
08059             top_rsclr *= shade_factor;
08060             top_gsclr *= shade_factor;
08061             top_bsclr *= shade_factor;
08062                     
08063     
08064             opac_param = VoxelField(botRLEdata, param0_offset, param0_size);
08065             opacity = param0_table[opac_param];
08066             if (param1_size != 0) {
08067                 opac_param = VoxelField(botRLEdata, param1_offset, param1_size);
08068                 opacity *= param1_table[opac_param];
08069                 if (param2_size != 0) {
08070                     opac_param = VoxelField(botRLEdata, param2_offset, param2_size);
08071                     opacity *= param2_table[opac_param];
08072                 }
08073             }
08074             if (opacity > min_opacity) {
08075                 opacity_int = opacity*255.;
08076                 bot_opc = opac_correct[opacity_int];
08077             } else {
08078                 bot_opc = (float)0.;
08079             };
08080     
08081     
08082     shade_index=num_materials*3*ShortField(botRLEdata,norm_offset);
08083     weight_index = num_materials * ByteField(botRLEdata, wgt_offset);
08084     
08085         
08086         
08087     bot_rclr = 
08088     shade_table[shade_index + 3*0 + 0] * 
08089         ((num_materials > 1) ? weight_table[weight_index] : (float)1.0);
08090         
08091     bot_gclr = 
08092     shade_table[shade_index + 3*0 + 1] * 
08093         ((num_materials > 1) ? weight_table[weight_index] : (float)1.0);
08094         
08095     bot_bclr = 
08096     shade_table[shade_index + 3*0 + 2] * 
08097         ((num_materials > 1) ? weight_table[weight_index] : (float)1.0);
08098         
08099         bot_rsclr = 
08100     shadow_table[shade_index + 3*0 + 0] * 
08101         ((num_materials > 1) ? weight_table[weight_index] : (float)1.0);
08102         
08103         bot_gsclr = 
08104     shadow_table[shade_index + 3*0 + 1] * 
08105         ((num_materials > 1) ? weight_table[weight_index] : (float)1.0);
08106         
08107         bot_bsclr = 
08108     shadow_table[shade_index + 3*0 + 2] * 
08109         ((num_materials > 1) ? weight_table[weight_index] : (float)1.0);
08110         for (m = 1; m < num_materials; m++) {
08111              
08112         
08113     bot_rclr += 
08114     shade_table[shade_index + 3*m + 0] * 
08115         weight_table[weight_index + m];
08116         
08117     bot_gclr += 
08118     shade_table[shade_index + 3*m + 1] * 
08119         weight_table[weight_index + m];
08120         
08121     bot_bclr += 
08122     shade_table[shade_index + 3*m + 2] * 
08123         weight_table[weight_index + m];
08124         
08125         bot_rsclr += 
08126     shadow_table[shade_index + 3*m + 0] * 
08127         weight_table[weight_index + m];
08128         
08129         bot_gsclr += 
08130     shadow_table[shade_index + 3*m + 1] * 
08131         weight_table[weight_index + m];
08132         
08133         bot_bsclr += 
08134     shadow_table[shade_index + 3*m + 2] * 
08135         weight_table[weight_index + m];
08136         };
08137     shade_factor = bot_opc * slice_depth_cueing;
08138     
08139         bot_rclr *= shade_factor;
08140         bot_gclr *= shade_factor;
08141         bot_bclr *= shade_factor;
08142     
08143             bot_rsclr *= shade_factor;
08144             bot_gsclr *= shade_factor;
08145             bot_bsclr *= shade_factor;
08146                     
08147        acc_opc += top_opc * wgtTR;
08148        
08149             acc_rclr += (top_rclr + top_rsclr *
08150                          ((float)1.0 - shadow_pixel->opcflt)) * wgtTR;
08151             acc_gclr += (top_gclr + top_gsclr *
08152                          ((float)1.0 - shadow_pixel->opcflt)) * wgtTR;
08153             acc_bclr += (top_bclr + top_bsclr *
08154                          ((float)1.0 - shadow_pixel->opcflt)) * wgtTR;
08155        
08156 #ifdef DEBUG
08157     if (ipixel == trace_pixel_ptr) {
08158         trace_opcTR = top_opc;
08159         trace_rclrTR = top_rclr;
08160                      trace_gclrTR = top_gclr;
08161                      trace_bclrTR = top_bclr;
08162         
08163     }
08164 #endif
08165 ;
08166                     
08167        acc_opc += bot_opc * wgtBR;
08168        
08169             acc_rclr += (bot_rclr + bot_rsclr *
08170                          ((float)1.0 - shadow_pixel->opcflt)) * wgtBR;
08171             acc_gclr += (bot_gclr + bot_gsclr *
08172                          ((float)1.0 - shadow_pixel->opcflt)) * wgtBR;
08173             acc_bclr += (bot_bclr + bot_bsclr *
08174                          ((float)1.0 - shadow_pixel->opcflt)) * wgtBR;
08175        
08176 #ifdef DEBUG
08177     if (ipixel == trace_pixel_ptr) {
08178         trace_opcBR = bot_opc;
08179         trace_rclrBR = bot_rclr;
08180                      trace_gclrBR = bot_gclr;
08181                      trace_bclrBR = bot_bclr;
08182         
08183     }
08184 #endif
08185 ;
08186                     
08187         COUNT_RESAMPLE;
08188         if (acc_opc > min_opacity) {
08189             COUNT_COMPOSITE;
08190             iopc = ipixel->opcflt;
08191 #           ifndef SKIP_ERT
08192                 ASSERT(iopc < max_opacity);
08193 #           endif
08194             iopc_inv = (float)1. - iopc;
08195             
08196         ipixel->rclrflt += acc_rclr * iopc_inv;
08197         ipixel->gclrflt += acc_gclr * iopc_inv;
08198         ipixel->bclrflt += acc_bclr * iopc_inv;
08199             iopc += acc_opc * iopc_inv;
08200             ipixel->opcflt = iopc;
08201             
08202 #ifdef DEBUG
08203     if (ipixel == trace_pixel_ptr) {
08204 #ifdef COMPUTE_SHADOW_BUFFER
08205         printf("{%3d}  %3d %3d", k, icount-i-count, j);
08206 #else
08207         printf("[%3d]  %3d %3d", k, icount-i-count, j);
08208 #endif
08209         printf("  %3.0f %3.0f %3.0f",trace_opcTL*255.,trace_rclrTL,wgtTL*100.);
08210         printf("  %3.0f %3.0f %3.0f",trace_opcBL*255.,trace_rclrBL,wgtBL*100.);
08211         printf("  %3.0f %3.0f %3.0f",trace_opcTR*255.,trace_rclrTR,wgtTR*100.);
08212         printf("  %3.0f %3.0f %3.0f",trace_opcBR*255.,trace_rclrBR,wgtBR*100.);
08213         printf("  %3.0f %3.0f\n", iopc*255., 
08214                ipixel->rclrflt);
08215         
08216         printf("              ");
08217         printf("      %3.0f    ",trace_rsclrTL);
08218         printf("      %3.0f    ",trace_rsclrBL);
08219         printf("      %3.0f    ",trace_rsclrTR);
08220         printf("      %3.0f    ",trace_rsclrBR);
08221         printf("  %3.0f\n", shadow_pixel->opcflt * 255.);
08222         
08223         printf("              ");
08224         printf("      %3.0f    ",trace_gclrTL);
08225         printf("      %3.0f    ",trace_gclrBL);
08226         printf("      %3.0f    ",trace_gclrTR);
08227         printf("      %3.0f    ",trace_gclrBR);
08228         printf("      %3.0f\n", ipixel->gclrflt);
08229         printf("              ");
08230         printf("      %3.0f    ",trace_bclrTL);
08231         printf("      %3.0f    ",trace_bclrBL);
08232         printf("      %3.0f    ",trace_bclrTR);
08233         printf("      %3.0f    ",trace_bclrBR);
08234         printf("      %3.0f\n", ipixel->bclrflt);
08235     }
08236 #endif /* DEBUG */
08237 ;
08238 #           ifndef SKIP_ERT
08239                 if (iopc >= max_opacity) {
08240                     ASSERT(ipixel->lnk == 0);
08241                     ipixel->lnk = 1;
08242                 }
08243 #           endif
08244         };
08245                     ipixel += 1; shadow_pixel += 1;
08246                     topRLEdata += 1 * voxel_istride;
08247                     botRLEdata += 1 * voxel_istride;
08248                     count--;
08249                     SET_VOXELS_LOADED;
08250                 }
08251                 break;
08252             case ALL_NONZERO__ALL_NONZERO:
08253                 /* do the pixels in this run; all four voxels contribute */
08254                 while (count > 0) {
08255                     if (PIXEL_IS_OPAQUE(ipixel))
08256                         break;
08257                     if (!voxels_loaded) {
08258                         
08259     
08260             opac_param = VoxelField(topRLEdata - voxel_istride, param0_offset, param0_size);
08261             opacity = param0_table[opac_param];
08262             if (param1_size != 0) {
08263                 opac_param = VoxelField(topRLEdata - voxel_istride, param1_offset, param1_size);
08264                 opacity *= param1_table[opac_param];
08265                 if (param2_size != 0) {
08266                     opac_param = VoxelField(topRLEdata - voxel_istride, param2_offset, param2_size);
08267                     opacity *= param2_table[opac_param];
08268                 }
08269             }
08270             if (opacity > min_opacity) {
08271                 opacity_int = opacity*255.;
08272                 top_opc = opac_correct[opacity_int];
08273             } else {
08274                 top_opc = (float)0.;
08275             };
08276     
08277     
08278     shade_index=num_materials*3*ShortField(topRLEdata - voxel_istride,norm_offset);
08279     weight_index = num_materials * ByteField(topRLEdata - voxel_istride, wgt_offset);
08280     
08281         
08282         
08283     top_rclr = 
08284     shade_table[shade_index + 3*0 + 0] * 
08285         ((num_materials > 1) ? weight_table[weight_index] : (float)1.0);
08286         
08287     top_gclr = 
08288     shade_table[shade_index + 3*0 + 1] * 
08289         ((num_materials > 1) ? weight_table[weight_index] : (float)1.0);
08290         
08291     top_bclr = 
08292     shade_table[shade_index + 3*0 + 2] * 
08293         ((num_materials > 1) ? weight_table[weight_index] : (float)1.0);
08294         
08295         top_rsclr = 
08296     shadow_table[shade_index + 3*0 + 0] * 
08297         ((num_materials > 1) ? weight_table[weight_index] : (float)1.0);
08298         
08299         top_gsclr = 
08300     shadow_table[shade_index + 3*0 + 1] * 
08301         ((num_materials > 1) ? weight_table[weight_index] : (float)1.0);
08302         
08303         top_bsclr = 
08304     shadow_table[shade_index + 3*0 + 2] * 
08305         ((num_materials > 1) ? weight_table[weight_index] : (float)1.0);
08306         for (m = 1; m < num_materials; m++) {
08307              
08308         
08309     top_rclr += 
08310     shade_table[shade_index + 3*m + 0] * 
08311         weight_table[weight_index + m];
08312         
08313     top_gclr += 
08314     shade_table[shade_index + 3*m + 1] * 
08315         weight_table[weight_index + m];
08316         
08317     top_bclr += 
08318     shade_table[shade_index + 3*m + 2] * 
08319         weight_table[weight_index + m];
08320         
08321         top_rsclr += 
08322     shadow_table[shade_index + 3*m + 0] * 
08323         weight_table[weight_index + m];
08324         
08325         top_gsclr += 
08326     shadow_table[shade_index + 3*m + 1] * 
08327         weight_table[weight_index + m];
08328         
08329         top_bsclr += 
08330     shadow_table[shade_index + 3*m + 2] * 
08331         weight_table[weight_index + m];
08332         };
08333     shade_factor = top_opc * slice_depth_cueing;
08334     
08335         top_rclr *= shade_factor;
08336         top_gclr *= shade_factor;
08337         top_bclr *= shade_factor;
08338     
08339             top_rsclr *= shade_factor;
08340             top_gsclr *= shade_factor;
08341             top_bsclr *= shade_factor;
08342                         
08343     
08344             opac_param = VoxelField(botRLEdata - voxel_istride, param0_offset, param0_size);
08345             opacity = param0_table[opac_param];
08346             if (param1_size != 0) {
08347                 opac_param = VoxelField(botRLEdata - voxel_istride, param1_offset, param1_size);
08348                 opacity *= param1_table[opac_param];
08349                 if (param2_size != 0) {
08350                     opac_param = VoxelField(botRLEdata - voxel_istride, param2_offset, param2_size);
08351                     opacity *= param2_table[opac_param];
08352                 }
08353             }
08354             if (opacity > min_opacity) {
08355                 opacity_int = opacity*255.;
08356                 bot_opc = opac_correct[opacity_int];
08357             } else {
08358                 bot_opc = (float)0.;
08359             };
08360     
08361     
08362     shade_index=num_materials*3*ShortField(botRLEdata - voxel_istride,norm_offset);
08363     weight_index = num_materials * ByteField(botRLEdata - voxel_istride, wgt_offset);
08364     
08365         
08366         
08367     bot_rclr = 
08368     shade_table[shade_index + 3*0 + 0] * 
08369         ((num_materials > 1) ? weight_table[weight_index] : (float)1.0);
08370         
08371     bot_gclr = 
08372     shade_table[shade_index + 3*0 + 1] * 
08373         ((num_materials > 1) ? weight_table[weight_index] : (float)1.0);
08374         
08375     bot_bclr = 
08376     shade_table[shade_index + 3*0 + 2] * 
08377         ((num_materials > 1) ? weight_table[weight_index] : (float)1.0);
08378         
08379         bot_rsclr = 
08380     shadow_table[shade_index + 3*0 + 0] * 
08381         ((num_materials > 1) ? weight_table[weight_index] : (float)1.0);
08382         
08383         bot_gsclr = 
08384     shadow_table[shade_index + 3*0 + 1] * 
08385         ((num_materials > 1) ? weight_table[weight_index] : (float)1.0);
08386         
08387         bot_bsclr = 
08388     shadow_table[shade_index + 3*0 + 2] * 
08389         ((num_materials > 1) ? weight_table[weight_index] : (float)1.0);
08390         for (m = 1; m < num_materials; m++) {
08391              
08392         
08393     bot_rclr += 
08394     shade_table[shade_index + 3*m + 0] * 
08395         weight_table[weight_index + m];
08396         
08397     bot_gclr += 
08398     shade_table[shade_index + 3*m + 1] * 
08399         weight_table[weight_index + m];
08400         
08401     bot_bclr += 
08402     shade_table[shade_index + 3*m + 2] * 
08403         weight_table[weight_index + m];
08404         
08405         bot_rsclr += 
08406     shadow_table[shade_index + 3*m + 0] * 
08407         weight_table[weight_index + m];
08408         
08409         bot_gsclr += 
08410     shadow_table[shade_index + 3*m + 1] * 
08411         weight_table[weight_index + m];
08412         
08413         bot_bsclr += 
08414     shadow_table[shade_index + 3*m + 2] * 
08415         weight_table[weight_index + m];
08416         };
08417     shade_factor = bot_opc * slice_depth_cueing;
08418     
08419         bot_rclr *= shade_factor;
08420         bot_gclr *= shade_factor;
08421         bot_bclr *= shade_factor;
08422     
08423             bot_rsclr *= shade_factor;
08424             bot_gsclr *= shade_factor;
08425             bot_bsclr *= shade_factor;
08426                     }
08427                     
08428 #ifdef DEBUG
08429     if (ipixel == trace_pixel_ptr) {
08430         trace_opcTL = 0.; trace_opcBL = 0.; trace_opcTR = 0.; trace_opcBR = 0.;
08431         trace_rsclrTL=0.; trace_rsclrBL=0.; trace_rsclrTR=0.; trace_rsclrBR=0.;
08432         trace_rclrTL= 0.; trace_rclrBL= 0.; trace_rclrTR= 0.; trace_rclrBR= 0.;
08433         trace_gclrTL= 0.; trace_gclrBL= 0.; trace_gclrTR= 0.; trace_gclrBR= 0.;
08434         trace_bclrTL= 0.; trace_bclrBL= 0.; trace_bclrTR= 0.; trace_bclrBR= 0.;
08435     }
08436 #endif
08437 ;
08438                     
08439        acc_opc = top_opc * wgtTL;
08440        
08441             acc_rclr = (top_rclr + top_rsclr *
08442                          ((float)1.0 - shadow_pixel->opcflt)) * wgtTL;
08443             acc_gclr = (top_gclr + top_gsclr *
08444                          ((float)1.0 - shadow_pixel->opcflt)) * wgtTL;
08445             acc_bclr = (top_bclr + top_bsclr *
08446                          ((float)1.0 - shadow_pixel->opcflt)) * wgtTL;
08447        
08448 #ifdef DEBUG
08449     if (ipixel == trace_pixel_ptr) {
08450         trace_opcTL = top_opc;
08451         trace_rclrTL = top_rclr;
08452                      trace_gclrTL = top_gclr;
08453                      trace_bclrTL = top_bclr;
08454         
08455     }
08456 #endif
08457 ;
08458                     
08459        acc_opc += bot_opc * wgtBL;
08460        
08461             acc_rclr += (bot_rclr + bot_rsclr *
08462                          ((float)1.0 - shadow_pixel->opcflt)) * wgtBL;
08463             acc_gclr += (bot_gclr + bot_gsclr *
08464                          ((float)1.0 - shadow_pixel->opcflt)) * wgtBL;
08465             acc_bclr += (bot_bclr + bot_bsclr *
08466                          ((float)1.0 - shadow_pixel->opcflt)) * wgtBL;
08467        
08468 #ifdef DEBUG
08469     if (ipixel == trace_pixel_ptr) {
08470         trace_opcBL = bot_opc;
08471         trace_rclrBL = bot_rclr;
08472                      trace_gclrBL = bot_gclr;
08473                      trace_bclrBL = bot_bclr;
08474         
08475     }
08476 #endif
08477 ;
08478                     
08479     
08480             opac_param = VoxelField(topRLEdata, param0_offset, param0_size);
08481             opacity = param0_table[opac_param];
08482             if (param1_size != 0) {
08483                 opac_param = VoxelField(topRLEdata, param1_offset, param1_size);
08484                 opacity *= param1_table[opac_param];
08485                 if (param2_size != 0) {
08486                     opac_param = VoxelField(topRLEdata, param2_offset, param2_size);
08487                     opacity *= param2_table[opac_param];
08488                 }
08489             }
08490             if (opacity > min_opacity) {
08491                 opacity_int = opacity*255.;
08492                 top_opc = opac_correct[opacity_int];
08493             } else {
08494                 top_opc = (float)0.;
08495             };
08496     
08497     
08498     shade_index=num_materials*3*ShortField(topRLEdata,norm_offset);
08499     weight_index = num_materials * ByteField(topRLEdata, wgt_offset);
08500     
08501         
08502         
08503     top_rclr = 
08504     shade_table[shade_index + 3*0 + 0] * 
08505         ((num_materials > 1) ? weight_table[weight_index] : (float)1.0);
08506         
08507     top_gclr = 
08508     shade_table[shade_index + 3*0 + 1] * 
08509         ((num_materials > 1) ? weight_table[weight_index] : (float)1.0);
08510         
08511     top_bclr = 
08512     shade_table[shade_index + 3*0 + 2] * 
08513         ((num_materials > 1) ? weight_table[weight_index] : (float)1.0);
08514         
08515         top_rsclr = 
08516     shadow_table[shade_index + 3*0 + 0] * 
08517         ((num_materials > 1) ? weight_table[weight_index] : (float)1.0);
08518         
08519         top_gsclr = 
08520     shadow_table[shade_index + 3*0 + 1] * 
08521         ((num_materials > 1) ? weight_table[weight_index] : (float)1.0);
08522         
08523         top_bsclr = 
08524     shadow_table[shade_index + 3*0 + 2] * 
08525         ((num_materials > 1) ? weight_table[weight_index] : (float)1.0);
08526         for (m = 1; m < num_materials; m++) {
08527              
08528         
08529     top_rclr += 
08530     shade_table[shade_index + 3*m + 0] * 
08531         weight_table[weight_index + m];
08532         
08533     top_gclr += 
08534     shade_table[shade_index + 3*m + 1] * 
08535         weight_table[weight_index + m];
08536         
08537     top_bclr += 
08538     shade_table[shade_index + 3*m + 2] * 
08539         weight_table[weight_index + m];
08540         
08541         top_rsclr += 
08542     shadow_table[shade_index + 3*m + 0] * 
08543         weight_table[weight_index + m];
08544         
08545         top_gsclr += 
08546     shadow_table[shade_index + 3*m + 1] * 
08547         weight_table[weight_index + m];
08548         
08549         top_bsclr += 
08550     shadow_table[shade_index + 3*m + 2] * 
08551         weight_table[weight_index + m];
08552         };
08553     shade_factor = top_opc * slice_depth_cueing;
08554     
08555         top_rclr *= shade_factor;
08556         top_gclr *= shade_factor;
08557         top_bclr *= shade_factor;
08558     
08559             top_rsclr *= shade_factor;
08560             top_gsclr *= shade_factor;
08561             top_bsclr *= shade_factor;
08562                     
08563     
08564             opac_param = VoxelField(botRLEdata, param0_offset, param0_size);
08565             opacity = param0_table[opac_param];
08566             if (param1_size != 0) {
08567                 opac_param = VoxelField(botRLEdata, param1_offset, param1_size);
08568                 opacity *= param1_table[opac_param];
08569                 if (param2_size != 0) {
08570                     opac_param = VoxelField(botRLEdata, param2_offset, param2_size);
08571                     opacity *= param2_table[opac_param];
08572                 }
08573             }
08574             if (opacity > min_opacity) {
08575                 opacity_int = opacity*255.;
08576                 bot_opc = opac_correct[opacity_int];
08577             } else {
08578                 bot_opc = (float)0.;
08579             };
08580     
08581     
08582     shade_index=num_materials*3*ShortField(botRLEdata,norm_offset);
08583     weight_index = num_materials * ByteField(botRLEdata, wgt_offset);
08584     
08585         
08586         
08587     bot_rclr = 
08588     shade_table[shade_index + 3*0 + 0] * 
08589         ((num_materials > 1) ? weight_table[weight_index] : (float)1.0);
08590         
08591     bot_gclr = 
08592     shade_table[shade_index + 3*0 + 1] * 
08593         ((num_materials > 1) ? weight_table[weight_index] : (float)1.0);
08594         
08595     bot_bclr = 
08596     shade_table[shade_index + 3*0 + 2] * 
08597         ((num_materials > 1) ? weight_table[weight_index] : (float)1.0);
08598         
08599         bot_rsclr = 
08600     shadow_table[shade_index + 3*0 + 0] * 
08601         ((num_materials > 1) ? weight_table[weight_index] : (float)1.0);
08602         
08603         bot_gsclr = 
08604     shadow_table[shade_index + 3*0 + 1] * 
08605         ((num_materials > 1) ? weight_table[weight_index] : (float)1.0);
08606         
08607         bot_bsclr = 
08608     shadow_table[shade_index + 3*0 + 2] * 
08609         ((num_materials > 1) ? weight_table[weight_index] : (float)1.0);
08610         for (m = 1; m < num_materials; m++) {
08611              
08612         
08613     bot_rclr += 
08614     shade_table[shade_index + 3*m + 0] * 
08615         weight_table[weight_index + m];
08616         
08617     bot_gclr += 
08618     shade_table[shade_index + 3*m + 1] * 
08619         weight_table[weight_index + m];
08620         
08621     bot_bclr += 
08622     shade_table[shade_index + 3*m + 2] * 
08623         weight_table[weight_index + m];
08624         
08625         bot_rsclr += 
08626     shadow_table[shade_index + 3*m + 0] * 
08627         weight_table[weight_index + m];
08628         
08629         bot_gsclr += 
08630     shadow_table[shade_index + 3*m + 1] * 
08631         weight_table[weight_index + m];
08632         
08633         bot_bsclr += 
08634     shadow_table[shade_index + 3*m + 2] * 
08635         weight_table[weight_index + m];
08636         };
08637     shade_factor = bot_opc * slice_depth_cueing;
08638     
08639         bot_rclr *= shade_factor;
08640         bot_gclr *= shade_factor;
08641         bot_bclr *= shade_factor;
08642     
08643             bot_rsclr *= shade_factor;
08644             bot_gsclr *= shade_factor;
08645             bot_bsclr *= shade_factor;
08646                     
08647        acc_opc += top_opc * wgtTR;
08648        
08649             acc_rclr += (top_rclr + top_rsclr *
08650                          ((float)1.0 - shadow_pixel->opcflt)) * wgtTR;
08651             acc_gclr += (top_gclr + top_gsclr *
08652                          ((float)1.0 - shadow_pixel->opcflt)) * wgtTR;
08653             acc_bclr += (top_bclr + top_bsclr *
08654                          ((float)1.0 - shadow_pixel->opcflt)) * wgtTR;
08655        
08656 #ifdef DEBUG
08657     if (ipixel == trace_pixel_ptr) {
08658         trace_opcTR = top_opc;
08659         trace_rclrTR = top_rclr;
08660                      trace_gclrTR = top_gclr;
08661                      trace_bclrTR = top_bclr;
08662         
08663     }
08664 #endif
08665 ;
08666                     
08667        acc_opc += bot_opc * wgtBR;
08668        
08669             acc_rclr += (bot_rclr + bot_rsclr *
08670                          ((float)1.0 - shadow_pixel->opcflt)) * wgtBR;
08671             acc_gclr += (bot_gclr + bot_gsclr *
08672                          ((float)1.0 - shadow_pixel->opcflt)) * wgtBR;
08673             acc_bclr += (bot_bclr + bot_bsclr *
08674                          ((float)1.0 - shadow_pixel->opcflt)) * wgtBR;
08675        
08676 #ifdef DEBUG
08677     if (ipixel == trace_pixel_ptr) {
08678         trace_opcBR = bot_opc;
08679         trace_rclrBR = bot_rclr;
08680                      trace_gclrBR = bot_gclr;
08681                      trace_bclrBR = bot_bclr;
08682         
08683     }
08684 #endif
08685 ;
08686                     
08687         COUNT_RESAMPLE;
08688         if (acc_opc > min_opacity) {
08689             COUNT_COMPOSITE;
08690             iopc = ipixel->opcflt;
08691 #           ifndef SKIP_ERT
08692                 ASSERT(iopc < max_opacity);
08693 #           endif
08694             iopc_inv = (float)1. - iopc;
08695             
08696         ipixel->rclrflt += acc_rclr * iopc_inv;
08697         ipixel->gclrflt += acc_gclr * iopc_inv;
08698         ipixel->bclrflt += acc_bclr * iopc_inv;
08699             iopc += acc_opc * iopc_inv;
08700             ipixel->opcflt = iopc;
08701             
08702 #ifdef DEBUG
08703     if (ipixel == trace_pixel_ptr) {
08704 #ifdef COMPUTE_SHADOW_BUFFER
08705         printf("{%3d}  %3d %3d", k, icount-i-count, j);
08706 #else
08707         printf("[%3d]  %3d %3d", k, icount-i-count, j);
08708 #endif
08709         printf("  %3.0f %3.0f %3.0f",trace_opcTL*255.,trace_rclrTL,wgtTL*100.);
08710         printf("  %3.0f %3.0f %3.0f",trace_opcBL*255.,trace_rclrBL,wgtBL*100.);
08711         printf("  %3.0f %3.0f %3.0f",trace_opcTR*255.,trace_rclrTR,wgtTR*100.);
08712         printf("  %3.0f %3.0f %3.0f",trace_opcBR*255.,trace_rclrBR,wgtBR*100.);
08713         printf("  %3.0f %3.0f\n", iopc*255., 
08714                ipixel->rclrflt);
08715         
08716         printf("              ");
08717         printf("      %3.0f    ",trace_rsclrTL);
08718         printf("      %3.0f    ",trace_rsclrBL);
08719         printf("      %3.0f    ",trace_rsclrTR);
08720         printf("      %3.0f    ",trace_rsclrBR);
08721         printf("  %3.0f\n", shadow_pixel->opcflt * 255.);
08722         
08723         printf("              ");
08724         printf("      %3.0f    ",trace_gclrTL);
08725         printf("      %3.0f    ",trace_gclrBL);
08726         printf("      %3.0f    ",trace_gclrTR);
08727         printf("      %3.0f    ",trace_gclrBR);
08728         printf("      %3.0f\n", ipixel->gclrflt);
08729         printf("              ");
08730         printf("      %3.0f    ",trace_bclrTL);
08731         printf("      %3.0f    ",trace_bclrBL);
08732         printf("      %3.0f    ",trace_bclrTR);
08733         printf("      %3.0f    ",trace_bclrBR);
08734         printf("      %3.0f\n", ipixel->bclrflt);
08735     }
08736 #endif /* DEBUG */
08737 ;
08738 #           ifndef SKIP_ERT
08739                 if (iopc >= max_opacity) {
08740                     ASSERT(ipixel->lnk == 0);
08741                     ipixel->lnk = 1;
08742                 }
08743 #           endif
08744         };
08745                     ipixel += 1; shadow_pixel += 1;
08746                     topRLEdata += 1 * voxel_istride;
08747                     botRLEdata += 1 * voxel_istride;
08748                     count--;
08749                     SET_VOXELS_LOADED;
08750                 }
08751                 break;
08752             default:
08753                 VPBug("illegal value for run states in compositing loop");
08754             }
08755 #else /* UNROLL_RUN_LOOP */
08756             /* this run contains pixels, so process them */
08757             while (count > 0) {
08758                 if (last_run_state == ALL_ZERO && run_state == ALL_ZERO) {
08759                     ipixel += count; shadow_pixel += count;
08760                     if (i != -1) {
08761                         topRLEdata += count * voxel_istride;
08762                         botRLEdata += count * voxel_istride;
08763                     }
08764                     count = 0;
08765                     break;
08766                 }
08767                 if (ipixel->lnk != 0)
08768                     break;
08769                 
08770 #ifdef DEBUG
08771     if (ipixel == trace_pixel_ptr) {
08772         trace_opcTL = 0.; trace_opcBL = 0.; trace_opcTR = 0.; trace_opcBR = 0.;
08773         trace_rsclrTL=0.; trace_rsclrBL=0.; trace_rsclrTR=0.; trace_rsclrBR=0.;
08774         trace_rclrTL= 0.; trace_rclrBL= 0.; trace_rclrTR= 0.; trace_rclrBR= 0.;
08775         trace_gclrTL= 0.; trace_gclrBL= 0.; trace_gclrTR= 0.; trace_gclrBR= 0.;
08776         trace_bclrTL= 0.; trace_bclrBL= 0.; trace_bclrTR= 0.; trace_bclrBR= 0.;
08777     }
08778 #endif
08779 ;
08780                 
08781        acc_opc = 0;
08782        acc_rclr = acc_gclr = acc_bclr = 0;
08783                 if (last_run_state & TOP_NONZERO) {
08784                     if (!voxels_loaded) {
08785                         
08786     
08787             opac_param = VoxelField(topRLEdata - voxel_istride, param0_offset, param0_size);
08788             opacity = param0_table[opac_param];
08789             if (param1_size != 0) {
08790                 opac_param = VoxelField(topRLEdata - voxel_istride, param1_offset, param1_size);
08791                 opacity *= param1_table[opac_param];
08792                 if (param2_size != 0) {
08793                     opac_param = VoxelField(topRLEdata - voxel_istride, param2_offset, param2_size);
08794                     opacity *= param2_table[opac_param];
08795                 }
08796             }
08797             if (opacity > min_opacity) {
08798                 opacity_int = opacity*255.;
08799                 top_opc = opac_correct[opacity_int];
08800             } else {
08801                 top_opc = (float)0.;
08802             };
08803     
08804     
08805     shade_index=num_materials*3*ShortField(topRLEdata - voxel_istride,norm_offset);
08806     weight_index = num_materials * ByteField(topRLEdata - voxel_istride, wgt_offset);
08807     
08808         
08809         
08810     top_rclr = 
08811     shade_table[shade_index + 3*0 + 0] * 
08812         ((num_materials > 1) ? weight_table[weight_index] : (float)1.0);
08813         
08814     top_gclr = 
08815     shade_table[shade_index + 3*0 + 1] * 
08816         ((num_materials > 1) ? weight_table[weight_index] : (float)1.0);
08817         
08818     top_bclr = 
08819     shade_table[shade_index + 3*0 + 2] * 
08820         ((num_materials > 1) ? weight_table[weight_index] : (float)1.0);
08821         
08822         top_rsclr = 
08823     shadow_table[shade_index + 3*0 + 0] * 
08824         ((num_materials > 1) ? weight_table[weight_index] : (float)1.0);
08825         
08826         top_gsclr = 
08827     shadow_table[shade_index + 3*0 + 1] * 
08828         ((num_materials > 1) ? weight_table[weight_index] : (float)1.0);
08829         
08830         top_bsclr = 
08831     shadow_table[shade_index + 3*0 + 2] * 
08832         ((num_materials > 1) ? weight_table[weight_index] : (float)1.0);
08833         for (m = 1; m < num_materials; m++) {
08834              
08835         
08836     top_rclr += 
08837     shade_table[shade_index + 3*m + 0] * 
08838         weight_table[weight_index + m];
08839         
08840     top_gclr += 
08841     shade_table[shade_index + 3*m + 1] * 
08842         weight_table[weight_index + m];
08843         
08844     top_bclr += 
08845     shade_table[shade_index + 3*m + 2] * 
08846         weight_table[weight_index + m];
08847         
08848         top_rsclr += 
08849     shadow_table[shade_index + 3*m + 0] * 
08850         weight_table[weight_index + m];
08851         
08852         top_gsclr += 
08853     shadow_table[shade_index + 3*m + 1] * 
08854         weight_table[weight_index + m];
08855         
08856         top_bsclr += 
08857     shadow_table[shade_index + 3*m + 2] * 
08858         weight_table[weight_index + m];
08859         };
08860     shade_factor = top_opc * slice_depth_cueing;
08861     
08862         top_rclr *= shade_factor;
08863         top_gclr *= shade_factor;
08864         top_bclr *= shade_factor;
08865     
08866             top_rsclr *= shade_factor;
08867             top_gsclr *= shade_factor;
08868             top_bsclr *= shade_factor;
08869                     }
08870                     
08871        acc_opc += top_opc * wgtTL;
08872        
08873             acc_rclr += (top_rclr + top_rsclr *
08874                          ((float)1.0 - shadow_pixel->opcflt)) * wgtTL;
08875             acc_gclr += (top_gclr + top_gsclr *
08876                          ((float)1.0 - shadow_pixel->opcflt)) * wgtTL;
08877             acc_bclr += (top_bclr + top_bsclr *
08878                          ((float)1.0 - shadow_pixel->opcflt)) * wgtTL;
08879        
08880 #ifdef DEBUG
08881     if (ipixel == trace_pixel_ptr) {
08882         trace_opcTL = top_opc;
08883         trace_rclrTL = top_rclr;
08884                      trace_gclrTL = top_gclr;
08885                      trace_bclrTL = top_bclr;
08886         
08887     }
08888 #endif
08889 ;
08890                 }
08891                 if (last_run_state & BOT_NONZERO) {
08892                     if (!voxels_loaded) {
08893                         
08894     
08895             opac_param = VoxelField(botRLEdata - voxel_istride, param0_offset, param0_size);
08896             opacity = param0_table[opac_param];
08897             if (param1_size != 0) {
08898                 opac_param = VoxelField(botRLEdata - voxel_istride, param1_offset, param1_size);
08899                 opacity *= param1_table[opac_param];
08900                 if (param2_size != 0) {
08901                     opac_param = VoxelField(botRLEdata - voxel_istride, param2_offset, param2_size);
08902                     opacity *= param2_table[opac_param];
08903                 }
08904             }
08905             if (opacity > min_opacity) {
08906                 opacity_int = opacity*255.;
08907                 bot_opc = opac_correct[opacity_int];
08908             } else {
08909                 bot_opc = (float)0.;
08910             };
08911     
08912     
08913     shade_index=num_materials*3*ShortField(botRLEdata - voxel_istride,norm_offset);
08914     weight_index = num_materials * ByteField(botRLEdata - voxel_istride, wgt_offset);
08915     
08916         
08917         
08918     bot_rclr = 
08919     shade_table[shade_index + 3*0 + 0] * 
08920         ((num_materials > 1) ? weight_table[weight_index] : (float)1.0);
08921         
08922     bot_gclr = 
08923     shade_table[shade_index + 3*0 + 1] * 
08924         ((num_materials > 1) ? weight_table[weight_index] : (float)1.0);
08925         
08926     bot_bclr = 
08927     shade_table[shade_index + 3*0 + 2] * 
08928         ((num_materials > 1) ? weight_table[weight_index] : (float)1.0);
08929         
08930         bot_rsclr = 
08931     shadow_table[shade_index + 3*0 + 0] * 
08932         ((num_materials > 1) ? weight_table[weight_index] : (float)1.0);
08933         
08934         bot_gsclr = 
08935     shadow_table[shade_index + 3*0 + 1] * 
08936         ((num_materials > 1) ? weight_table[weight_index] : (float)1.0);
08937         
08938         bot_bsclr = 
08939     shadow_table[shade_index + 3*0 + 2] * 
08940         ((num_materials > 1) ? weight_table[weight_index] : (float)1.0);
08941         for (m = 1; m < num_materials; m++) {
08942              
08943         
08944     bot_rclr += 
08945     shade_table[shade_index + 3*m + 0] * 
08946         weight_table[weight_index + m];
08947         
08948     bot_gclr += 
08949     shade_table[shade_index + 3*m + 1] * 
08950         weight_table[weight_index + m];
08951         
08952     bot_bclr += 
08953     shade_table[shade_index + 3*m + 2] * 
08954         weight_table[weight_index + m];
08955         
08956         bot_rsclr += 
08957     shadow_table[shade_index + 3*m + 0] * 
08958         weight_table[weight_index + m];
08959         
08960         bot_gsclr += 
08961     shadow_table[shade_index + 3*m + 1] * 
08962         weight_table[weight_index + m];
08963         
08964         bot_bsclr += 
08965     shadow_table[shade_index + 3*m + 2] * 
08966         weight_table[weight_index + m];
08967         };
08968     shade_factor = bot_opc * slice_depth_cueing;
08969     
08970         bot_rclr *= shade_factor;
08971         bot_gclr *= shade_factor;
08972         bot_bclr *= shade_factor;
08973     
08974             bot_rsclr *= shade_factor;
08975             bot_gsclr *= shade_factor;
08976             bot_bsclr *= shade_factor;
08977                     }
08978                     
08979        acc_opc += bot_opc * wgtBL;
08980        
08981             acc_rclr += (bot_rclr + bot_rsclr *
08982                          ((float)1.0 - shadow_pixel->opcflt)) * wgtBL;
08983             acc_gclr += (bot_gclr + bot_gsclr *
08984                          ((float)1.0 - shadow_pixel->opcflt)) * wgtBL;
08985             acc_bclr += (bot_bclr + bot_bsclr *
08986                          ((float)1.0 - shadow_pixel->opcflt)) * wgtBL;
08987        
08988 #ifdef DEBUG
08989     if (ipixel == trace_pixel_ptr) {
08990         trace_opcBL = bot_opc;
08991         trace_rclrBL = bot_rclr;
08992                      trace_gclrBL = bot_gclr;
08993                      trace_bclrBL = bot_bclr;
08994         
08995     }
08996 #endif
08997 ;
08998                 }
08999                 if (run_state & TOP_NONZERO) {
09000                     
09001     
09002             opac_param = VoxelField(topRLEdata, param0_offset, param0_size);
09003             opacity = param0_table[opac_param];
09004             if (param1_size != 0) {
09005                 opac_param = VoxelField(topRLEdata, param1_offset, param1_size);
09006                 opacity *= param1_table[opac_param];
09007                 if (param2_size != 0) {
09008                     opac_param = VoxelField(topRLEdata, param2_offset, param2_size);
09009                     opacity *= param2_table[opac_param];
09010                 }
09011             }
09012             if (opacity > min_opacity) {
09013                 opacity_int = opacity*255.;
09014                 top_opc = opac_correct[opacity_int];
09015             } else {
09016                 top_opc = (float)0.;
09017             };
09018     
09019     
09020     shade_index=num_materials*3*ShortField(topRLEdata,norm_offset);
09021     weight_index = num_materials * ByteField(topRLEdata, wgt_offset);
09022     
09023         
09024         
09025     top_rclr = 
09026     shade_table[shade_index + 3*0 + 0] * 
09027         ((num_materials > 1) ? weight_table[weight_index] : (float)1.0);
09028         
09029     top_gclr = 
09030     shade_table[shade_index + 3*0 + 1] * 
09031         ((num_materials > 1) ? weight_table[weight_index] : (float)1.0);
09032         
09033     top_bclr = 
09034     shade_table[shade_index + 3*0 + 2] * 
09035         ((num_materials > 1) ? weight_table[weight_index] : (float)1.0);
09036         
09037         top_rsclr = 
09038     shadow_table[shade_index + 3*0 + 0] * 
09039         ((num_materials > 1) ? weight_table[weight_index] : (float)1.0);
09040         
09041         top_gsclr = 
09042     shadow_table[shade_index + 3*0 + 1] * 
09043         ((num_materials > 1) ? weight_table[weight_index] : (float)1.0);
09044         
09045         top_bsclr = 
09046     shadow_table[shade_index + 3*0 + 2] * 
09047         ((num_materials > 1) ? weight_table[weight_index] : (float)1.0);
09048         for (m = 1; m < num_materials; m++) {
09049              
09050         
09051     top_rclr += 
09052     shade_table[shade_index + 3*m + 0] * 
09053         weight_table[weight_index + m];
09054         
09055     top_gclr += 
09056     shade_table[shade_index + 3*m + 1] * 
09057         weight_table[weight_index + m];
09058         
09059     top_bclr += 
09060     shade_table[shade_index + 3*m + 2] * 
09061         weight_table[weight_index + m];
09062         
09063         top_rsclr += 
09064     shadow_table[shade_index + 3*m + 0] * 
09065         weight_table[weight_index + m];
09066         
09067         top_gsclr += 
09068     shadow_table[shade_index + 3*m + 1] * 
09069         weight_table[weight_index + m];
09070         
09071         top_bsclr += 
09072     shadow_table[shade_index + 3*m + 2] * 
09073         weight_table[weight_index + m];
09074         };
09075     shade_factor = top_opc * slice_depth_cueing;
09076     
09077         top_rclr *= shade_factor;
09078         top_gclr *= shade_factor;
09079         top_bclr *= shade_factor;
09080     
09081             top_rsclr *= shade_factor;
09082             top_gsclr *= shade_factor;
09083             top_bsclr *= shade_factor;
09084                     
09085        acc_opc += top_opc * wgtTR;
09086        
09087             acc_rclr += (top_rclr + top_rsclr *
09088                          ((float)1.0 - shadow_pixel->opcflt)) * wgtTR;
09089             acc_gclr += (top_gclr + top_gsclr *
09090                          ((float)1.0 - shadow_pixel->opcflt)) * wgtTR;
09091             acc_bclr += (top_bclr + top_bsclr *
09092                          ((float)1.0 - shadow_pixel->opcflt)) * wgtTR;
09093        
09094 #ifdef DEBUG
09095     if (ipixel == trace_pixel_ptr) {
09096         trace_opcTR = top_opc;
09097         trace_rclrTR = top_rclr;
09098                      trace_gclrTR = top_gclr;
09099                      trace_bclrTR = top_bclr;
09100         
09101     }
09102 #endif
09103 ;
09104                     topRLEdata += 1 * voxel_istride;
09105                 } else {
09106                     if (i != -1) {
09107                         topRLEdata += 1 * voxel_istride;
09108                     }
09109                 }
09110                 if (run_state & BOT_NONZERO) {
09111                     
09112     
09113             opac_param = VoxelField(botRLEdata, param0_offset, param0_size);
09114             opacity = param0_table[opac_param];
09115             if (param1_size != 0) {
09116                 opac_param = VoxelField(botRLEdata, param1_offset, param1_size);
09117                 opacity *= param1_table[opac_param];
09118                 if (param2_size != 0) {
09119                     opac_param = VoxelField(botRLEdata, param2_offset, param2_size);
09120                     opacity *= param2_table[opac_param];
09121                 }
09122             }
09123             if (opacity > min_opacity) {
09124                 opacity_int = opacity*255.;
09125                 bot_opc = opac_correct[opacity_int];
09126             } else {
09127                 bot_opc = (float)0.;
09128             };
09129     
09130     
09131     shade_index=num_materials*3*ShortField(botRLEdata,norm_offset);
09132     weight_index = num_materials * ByteField(botRLEdata, wgt_offset);
09133     
09134         
09135         
09136     bot_rclr = 
09137     shade_table[shade_index + 3*0 + 0] * 
09138         ((num_materials > 1) ? weight_table[weight_index] : (float)1.0);
09139         
09140     bot_gclr = 
09141     shade_table[shade_index + 3*0 + 1] * 
09142         ((num_materials > 1) ? weight_table[weight_index] : (float)1.0);
09143         
09144     bot_bclr = 
09145     shade_table[shade_index + 3*0 + 2] * 
09146         ((num_materials > 1) ? weight_table[weight_index] : (float)1.0);
09147         
09148         bot_rsclr = 
09149     shadow_table[shade_index + 3*0 + 0] * 
09150         ((num_materials > 1) ? weight_table[weight_index] : (float)1.0);
09151         
09152         bot_gsclr = 
09153     shadow_table[shade_index + 3*0 + 1] * 
09154         ((num_materials > 1) ? weight_table[weight_index] : (float)1.0);
09155         
09156         bot_bsclr = 
09157     shadow_table[shade_index + 3*0 + 2] * 
09158         ((num_materials > 1) ? weight_table[weight_index] : (float)1.0);
09159         for (m = 1; m < num_materials; m++) {
09160              
09161         
09162     bot_rclr += 
09163     shade_table[shade_index + 3*m + 0] * 
09164         weight_table[weight_index + m];
09165         
09166     bot_gclr += 
09167     shade_table[shade_index + 3*m + 1] * 
09168         weight_table[weight_index + m];
09169         
09170     bot_bclr += 
09171     shade_table[shade_index + 3*m + 2] * 
09172         weight_table[weight_index + m];
09173         
09174         bot_rsclr += 
09175     shadow_table[shade_index + 3*m + 0] * 
09176         weight_table[weight_index + m];
09177         
09178         bot_gsclr += 
09179     shadow_table[shade_index + 3*m + 1] * 
09180         weight_table[weight_index + m];
09181         
09182         bot_bsclr += 
09183     shadow_table[shade_index + 3*m + 2] * 
09184         weight_table[weight_index + m];
09185         };
09186     shade_factor = bot_opc * slice_depth_cueing;
09187     
09188         bot_rclr *= shade_factor;
09189         bot_gclr *= shade_factor;
09190         bot_bclr *= shade_factor;
09191     
09192             bot_rsclr *= shade_factor;
09193             bot_gsclr *= shade_factor;
09194             bot_bsclr *= shade_factor;
09195                     
09196        acc_opc += bot_opc * wgtBR;
09197        
09198             acc_rclr += (bot_rclr + bot_rsclr *
09199                          ((float)1.0 - shadow_pixel->opcflt)) * wgtBR;
09200             acc_gclr += (bot_gclr + bot_gsclr *
09201                          ((float)1.0 - shadow_pixel->opcflt)) * wgtBR;
09202             acc_bclr += (bot_bclr + bot_bsclr *
09203                          ((float)1.0 - shadow_pixel->opcflt)) * wgtBR;
09204        
09205 #ifdef DEBUG
09206     if (ipixel == trace_pixel_ptr) {
09207         trace_opcBR = bot_opc;
09208         trace_rclrBR = bot_rclr;
09209                      trace_gclrBR = bot_gclr;
09210                      trace_bclrBR = bot_bclr;
09211         
09212     }
09213 #endif
09214 ;
09215                     botRLEdata += 1 * voxel_istride;
09216                 } else {
09217                     if (i != -1) {
09218                         botRLEdata += 1 * voxel_istride;
09219                     }
09220                 }
09221                 
09222         COUNT_RESAMPLE;
09223         if (acc_opc > min_opacity) {
09224             COUNT_COMPOSITE;
09225             iopc = ipixel->opcflt;
09226 #           ifndef SKIP_ERT
09227                 ASSERT(iopc < max_opacity);
09228 #           endif
09229             iopc_inv = (float)1. - iopc;
09230             
09231         ipixel->rclrflt += acc_rclr * iopc_inv;
09232         ipixel->gclrflt += acc_gclr * iopc_inv;
09233         ipixel->bclrflt += acc_bclr * iopc_inv;
09234             iopc += acc_opc * iopc_inv;
09235             ipixel->opcflt = iopc;
09236             
09237 #ifdef DEBUG
09238     if (ipixel == trace_pixel_ptr) {
09239 #ifdef COMPUTE_SHADOW_BUFFER
09240         printf("{%3d}  %3d %3d", k, icount-i-count, j);
09241 #else
09242         printf("[%3d]  %3d %3d", k, icount-i-count, j);
09243 #endif
09244         printf("  %3.0f %3.0f %3.0f",trace_opcTL*255.,trace_rclrTL,wgtTL*100.);
09245         printf("  %3.0f %3.0f %3.0f",trace_opcBL*255.,trace_rclrBL,wgtBL*100.);
09246         printf("  %3.0f %3.0f %3.0f",trace_opcTR*255.,trace_rclrTR,wgtTR*100.);
09247         printf("  %3.0f %3.0f %3.0f",trace_opcBR*255.,trace_rclrBR,wgtBR*100.);
09248         printf("  %3.0f %3.0f\n", iopc*255., 
09249                ipixel->rclrflt);
09250         
09251         printf("              ");
09252         printf("      %3.0f    ",trace_rsclrTL);
09253         printf("      %3.0f    ",trace_rsclrBL);
09254         printf("      %3.0f    ",trace_rsclrTR);
09255         printf("      %3.0f    ",trace_rsclrBR);
09256         printf("  %3.0f\n", shadow_pixel->opcflt * 255.);
09257         
09258         printf("              ");
09259         printf("      %3.0f    ",trace_gclrTL);
09260         printf("      %3.0f    ",trace_gclrBL);
09261         printf("      %3.0f    ",trace_gclrTR);
09262         printf("      %3.0f    ",trace_gclrBR);
09263         printf("      %3.0f\n", ipixel->gclrflt);
09264         printf("              ");
09265         printf("      %3.0f    ",trace_bclrTL);
09266         printf("      %3.0f    ",trace_bclrBL);
09267         printf("      %3.0f    ",trace_bclrTR);
09268         printf("      %3.0f    ",trace_bclrBR);
09269         printf("      %3.0f\n", ipixel->bclrflt);
09270     }
09271 #endif /* DEBUG */
09272 ;
09273 #           ifndef SKIP_ERT
09274                 if (iopc >= max_opacity) {
09275                     ASSERT(ipixel->lnk == 0);
09276                     ipixel->lnk = 1;
09277                 }
09278 #           endif
09279         };
09280                 ipixel += 1; shadow_pixel += 1;
09281                 count--;
09282                 SET_VOXELS_LOADED;
09283                 last_run_state = run_state;
09284             }
09285 #endif /* UNROLL_RUN_LOOP */
09286 
09287             GET_HIRES_TIME(vpc, t1);
09288             STORE_HIRES_TIME(vpc, VPTIMER_PROCESS_VOXELS, t0, t1);
09289             COPY_HIRES_TIME(t0, t1);
09290 
09291             if (count > 0) {
09292                 Debug((vpc, VPDEBUG_COMPOSITE, "Backup(%d)\n", count));
09293                 toprun_count += count;
09294                 botrun_count += count;
09295                 i += count;
09296             }
09297 #endif /* SKIP_COMPOSITE */
09298 
09299             /***********************************************************
09300              * Go on to next voxel run.
09301              ***********************************************************/
09302 
09303             last_run_state = run_state;
09304         } /* while (i > 0) */
09305 
09306         /***************************************************************
09307          * Finish processing voxel scanline and go on to next one.
09308          ***************************************************************/
09309 
09310 #ifdef UNROLL_RUN_LOOP
09311         ASSERT(i == 0);
09312 #else
09313         ASSERT(i == -1);
09314 #endif
09315 
09316 #ifndef SKIP_COMPOSITE
09317 #ifdef UNROLL_RUN_LOOP
09318         /* do the last pixel (to the right of the last voxel) */
09319         if (last_run_state != ALL_ZERO && !PIXEL_IS_OPAQUE(ipixel)) {
09320             /* last voxels are nonzero and the pixel is not opaque yet
09321                so there is work to be done */
09322             Debug((vpc, VPDEBUG_COMPOSITE, "Run(1)End\n"));
09323             switch (last_run_state) {
09324             case TOP_NONZERO:
09325                 /* only the top-left voxel contributes */
09326                 if (!voxels_loaded) {
09327                     
09328     
09329             opac_param = VoxelField(topRLEdata - voxel_istride, param0_offset, param0_size);
09330             opacity = param0_table[opac_param];
09331             if (param1_size != 0) {
09332                 opac_param = VoxelField(topRLEdata - voxel_istride, param1_offset, param1_size);
09333                 opacity *= param1_table[opac_param];
09334                 if (param2_size != 0) {
09335                     opac_param = VoxelField(topRLEdata - voxel_istride, param2_offset, param2_size);
09336                     opacity *= param2_table[opac_param];
09337                 }
09338             }
09339             if (opacity > min_opacity) {
09340                 opacity_int = opacity*255.;
09341                 top_opc = opac_correct[opacity_int];
09342             } else {
09343                 top_opc = (float)0.;
09344             };
09345     
09346     
09347     shade_index=num_materials*3*ShortField(topRLEdata - voxel_istride,norm_offset);
09348     weight_index = num_materials * ByteField(topRLEdata - voxel_istride, wgt_offset);
09349     
09350         
09351         
09352     top_rclr = 
09353     shade_table[shade_index + 3*0 + 0] * 
09354         ((num_materials > 1) ? weight_table[weight_index] : (float)1.0);
09355         
09356     top_gclr = 
09357     shade_table[shade_index + 3*0 + 1] * 
09358         ((num_materials > 1) ? weight_table[weight_index] : (float)1.0);
09359         
09360     top_bclr = 
09361     shade_table[shade_index + 3*0 + 2] * 
09362         ((num_materials > 1) ? weight_table[weight_index] : (float)1.0);
09363         
09364         top_rsclr = 
09365     shadow_table[shade_index + 3*0 + 0] * 
09366         ((num_materials > 1) ? weight_table[weight_index] : (float)1.0);
09367         
09368         top_gsclr = 
09369     shadow_table[shade_index + 3*0 + 1] * 
09370         ((num_materials > 1) ? weight_table[weight_index] : (float)1.0);
09371         
09372         top_bsclr = 
09373     shadow_table[shade_index + 3*0 + 2] * 
09374         ((num_materials > 1) ? weight_table[weight_index] : (float)1.0);
09375         for (m = 1; m < num_materials; m++) {
09376              
09377         
09378     top_rclr += 
09379     shade_table[shade_index + 3*m + 0] * 
09380         weight_table[weight_index + m];
09381         
09382     top_gclr += 
09383     shade_table[shade_index + 3*m + 1] * 
09384         weight_table[weight_index + m];
09385         
09386     top_bclr += 
09387     shade_table[shade_index + 3*m + 2] * 
09388         weight_table[weight_index + m];
09389         
09390         top_rsclr += 
09391     shadow_table[shade_index + 3*m + 0] * 
09392         weight_table[weight_index + m];
09393         
09394         top_gsclr += 
09395     shadow_table[shade_index + 3*m + 1] * 
09396         weight_table[weight_index + m];
09397         
09398         top_bsclr += 
09399     shadow_table[shade_index + 3*m + 2] * 
09400         weight_table[weight_index + m];
09401         };
09402     shade_factor = top_opc * slice_depth_cueing;
09403     
09404         top_rclr *= shade_factor;
09405         top_gclr *= shade_factor;
09406         top_bclr *= shade_factor;
09407     
09408             top_rsclr *= shade_factor;
09409             top_gsclr *= shade_factor;
09410             top_bsclr *= shade_factor;
09411                 }
09412                 
09413 #ifdef DEBUG
09414     if (ipixel == trace_pixel_ptr) {
09415         trace_opcTL = 0.; trace_opcBL = 0.; trace_opcTR = 0.; trace_opcBR = 0.;
09416         trace_rsclrTL=0.; trace_rsclrBL=0.; trace_rsclrTR=0.; trace_rsclrBR=0.;
09417         trace_rclrTL= 0.; trace_rclrBL= 0.; trace_rclrTR= 0.; trace_rclrBR= 0.;
09418         trace_gclrTL= 0.; trace_gclrBL= 0.; trace_gclrTR= 0.; trace_gclrBR= 0.;
09419         trace_bclrTL= 0.; trace_bclrBL= 0.; trace_bclrTR= 0.; trace_bclrBR= 0.;
09420     }
09421 #endif
09422 ;
09423                 
09424        acc_opc = top_opc * wgtTL;
09425        
09426             acc_rclr = (top_rclr + top_rsclr *
09427                          ((float)1.0 - shadow_pixel->opcflt)) * wgtTL;
09428             acc_gclr = (top_gclr + top_gsclr *
09429                          ((float)1.0 - shadow_pixel->opcflt)) * wgtTL;
09430             acc_bclr = (top_bclr + top_bsclr *
09431                          ((float)1.0 - shadow_pixel->opcflt)) * wgtTL;
09432        
09433 #ifdef DEBUG
09434     if (ipixel == trace_pixel_ptr) {
09435         trace_opcTL = top_opc;
09436         trace_rclrTL = top_rclr;
09437                      trace_gclrTL = top_gclr;
09438                      trace_bclrTL = top_bclr;
09439         
09440     }
09441 #endif
09442 ;
09443                 
09444         COUNT_RESAMPLE;
09445         if (acc_opc > min_opacity) {
09446             COUNT_COMPOSITE;
09447             iopc = ipixel->opcflt;
09448 #           ifndef SKIP_ERT
09449                 ASSERT(iopc < max_opacity);
09450 #           endif
09451             iopc_inv = (float)1. - iopc;
09452             
09453         ipixel->rclrflt += acc_rclr * iopc_inv;
09454         ipixel->gclrflt += acc_gclr * iopc_inv;
09455         ipixel->bclrflt += acc_bclr * iopc_inv;
09456             iopc += acc_opc * iopc_inv;
09457             ipixel->opcflt = iopc;
09458             
09459 #ifdef DEBUG
09460     if (ipixel == trace_pixel_ptr) {
09461 #ifdef COMPUTE_SHADOW_BUFFER
09462         printf("{%3d}  %3d %3d", k, icount-i-count, j);
09463 #else
09464         printf("[%3d]  %3d %3d", k, icount-i-count, j);
09465 #endif
09466         printf("  %3.0f %3.0f %3.0f",trace_opcTL*255.,trace_rclrTL,wgtTL*100.);
09467         printf("  %3.0f %3.0f %3.0f",trace_opcBL*255.,trace_rclrBL,wgtBL*100.);
09468         printf("  %3.0f %3.0f %3.0f",trace_opcTR*255.,trace_rclrTR,wgtTR*100.);
09469         printf("  %3.0f %3.0f %3.0f",trace_opcBR*255.,trace_rclrBR,wgtBR*100.);
09470         printf("  %3.0f %3.0f\n", iopc*255., 
09471                ipixel->rclrflt);
09472         
09473         printf("              ");
09474         printf("      %3.0f    ",trace_rsclrTL);
09475         printf("      %3.0f    ",trace_rsclrBL);
09476         printf("      %3.0f    ",trace_rsclrTR);
09477         printf("      %3.0f    ",trace_rsclrBR);
09478         printf("  %3.0f\n", shadow_pixel->opcflt * 255.);
09479         
09480         printf("              ");
09481         printf("      %3.0f    ",trace_gclrTL);
09482         printf("      %3.0f    ",trace_gclrBL);
09483         printf("      %3.0f    ",trace_gclrTR);
09484         printf("      %3.0f    ",trace_gclrBR);
09485         printf("      %3.0f\n", ipixel->gclrflt);
09486         printf("              ");
09487         printf("      %3.0f    ",trace_bclrTL);
09488         printf("      %3.0f    ",trace_bclrBL);
09489         printf("      %3.0f    ",trace_bclrTR);
09490         printf("      %3.0f    ",trace_bclrBR);
09491         printf("      %3.0f\n", ipixel->bclrflt);
09492     }
09493 #endif /* DEBUG */
09494 ;
09495 #           ifndef SKIP_ERT
09496                 if (iopc >= max_opacity) {
09497                     ASSERT(ipixel->lnk == 0);
09498                     ipixel->lnk = 1;
09499                 }
09500 #           endif
09501         };
09502                 break;
09503             case BOT_NONZERO:
09504                 /* only the bottom left voxel contributes */
09505                 if (!voxels_loaded) {
09506                     
09507     
09508             opac_param = VoxelField(botRLEdata - voxel_istride, param0_offset, param0_size);
09509             opacity = param0_table[opac_param];
09510             if (param1_size != 0) {
09511                 opac_param = VoxelField(botRLEdata - voxel_istride, param1_offset, param1_size);
09512                 opacity *= param1_table[opac_param];
09513                 if (param2_size != 0) {
09514                     opac_param = VoxelField(botRLEdata - voxel_istride, param2_offset, param2_size);
09515                     opacity *= param2_table[opac_param];
09516                 }
09517             }
09518             if (opacity > min_opacity) {
09519                 opacity_int = opacity*255.;
09520                 bot_opc = opac_correct[opacity_int];
09521             } else {
09522                 bot_opc = (float)0.;
09523             };
09524     
09525     
09526     shade_index=num_materials*3*ShortField(botRLEdata - voxel_istride,norm_offset);
09527     weight_index = num_materials * ByteField(botRLEdata - voxel_istride, wgt_offset);
09528     
09529         
09530         
09531     bot_rclr = 
09532     shade_table[shade_index + 3*0 + 0] * 
09533         ((num_materials > 1) ? weight_table[weight_index] : (float)1.0);
09534         
09535     bot_gclr = 
09536     shade_table[shade_index + 3*0 + 1] * 
09537         ((num_materials > 1) ? weight_table[weight_index] : (float)1.0);
09538         
09539     bot_bclr = 
09540     shade_table[shade_index + 3*0 + 2] * 
09541         ((num_materials > 1) ? weight_table[weight_index] : (float)1.0);
09542         
09543         bot_rsclr = 
09544     shadow_table[shade_index + 3*0 + 0] * 
09545         ((num_materials > 1) ? weight_table[weight_index] : (float)1.0);
09546         
09547         bot_gsclr = 
09548     shadow_table[shade_index + 3*0 + 1] * 
09549         ((num_materials > 1) ? weight_table[weight_index] : (float)1.0);
09550         
09551         bot_bsclr = 
09552     shadow_table[shade_index + 3*0 + 2] * 
09553         ((num_materials > 1) ? weight_table[weight_index] : (float)1.0);
09554         for (m = 1; m < num_materials; m++) {
09555              
09556         
09557     bot_rclr += 
09558     shade_table[shade_index + 3*m + 0] * 
09559         weight_table[weight_index + m];
09560         
09561     bot_gclr += 
09562     shade_table[shade_index + 3*m + 1] * 
09563         weight_table[weight_index + m];
09564         
09565     bot_bclr += 
09566     shade_table[shade_index + 3*m + 2] * 
09567         weight_table[weight_index + m];
09568         
09569         bot_rsclr += 
09570     shadow_table[shade_index + 3*m + 0] * 
09571         weight_table[weight_index + m];
09572         
09573         bot_gsclr += 
09574     shadow_table[shade_index + 3*m + 1] * 
09575         weight_table[weight_index + m];
09576         
09577         bot_bsclr += 
09578     shadow_table[shade_index + 3*m + 2] * 
09579         weight_table[weight_index + m];
09580         };
09581     shade_factor = bot_opc * slice_depth_cueing;
09582     
09583         bot_rclr *= shade_factor;
09584         bot_gclr *= shade_factor;
09585         bot_bclr *= shade_factor;
09586     
09587             bot_rsclr *= shade_factor;
09588             bot_gsclr *= shade_factor;
09589             bot_bsclr *= shade_factor;
09590                 }
09591                 
09592 #ifdef DEBUG
09593     if (ipixel == trace_pixel_ptr) {
09594         trace_opcTL = 0.; trace_opcBL = 0.; trace_opcTR = 0.; trace_opcBR = 0.;
09595         trace_rsclrTL=0.; trace_rsclrBL=0.; trace_rsclrTR=0.; trace_rsclrBR=0.;
09596         trace_rclrTL= 0.; trace_rclrBL= 0.; trace_rclrTR= 0.; trace_rclrBR= 0.;
09597         trace_gclrTL= 0.; trace_gclrBL= 0.; trace_gclrTR= 0.; trace_gclrBR= 0.;
09598         trace_bclrTL= 0.; trace_bclrBL= 0.; trace_bclrTR= 0.; trace_bclrBR= 0.;
09599     }
09600 #endif
09601 ;
09602                 
09603        acc_opc = bot_opc * wgtBL;
09604        
09605             acc_rclr = (bot_rclr + bot_rsclr *
09606                          ((float)1.0 - shadow_pixel->opcflt)) * wgtBL;
09607             acc_gclr = (bot_gclr + bot_gsclr *
09608                          ((float)1.0 - shadow_pixel->opcflt)) * wgtBL;
09609             acc_bclr = (bot_bclr + bot_bsclr *
09610                          ((float)1.0 - shadow_pixel->opcflt)) * wgtBL;
09611        
09612 #ifdef DEBUG
09613     if (ipixel == trace_pixel_ptr) {
09614         trace_opcBL = bot_opc;
09615         trace_rclrBL = bot_rclr;
09616                      trace_gclrBL = bot_gclr;
09617                      trace_bclrBL = bot_bclr;
09618         
09619     }
09620 #endif
09621 ;
09622                 
09623         COUNT_RESAMPLE;
09624         if (acc_opc > min_opacity) {
09625             COUNT_COMPOSITE;
09626             iopc = ipixel->opcflt;
09627 #           ifndef SKIP_ERT
09628                 ASSERT(iopc < max_opacity);
09629 #           endif
09630             iopc_inv = (float)1. - iopc;
09631             
09632         ipixel->rclrflt += acc_rclr * iopc_inv;
09633         ipixel->gclrflt += acc_gclr * iopc_inv;
09634         ipixel->bclrflt += acc_bclr * iopc_inv;
09635             iopc += acc_opc * iopc_inv;
09636             ipixel->opcflt = iopc;
09637             
09638 #ifdef DEBUG
09639     if (ipixel == trace_pixel_ptr) {
09640 #ifdef COMPUTE_SHADOW_BUFFER
09641         printf("{%3d}  %3d %3d", k, icount-i-count, j);
09642 #else
09643         printf("[%3d]  %3d %3d", k, icount-i-count, j);
09644 #endif
09645         printf("  %3.0f %3.0f %3.0f",trace_opcTL*255.,trace_rclrTL,wgtTL*100.);
09646         printf("  %3.0f %3.0f %3.0f",trace_opcBL*255.,trace_rclrBL,wgtBL*100.);
09647         printf("  %3.0f %3.0f %3.0f",trace_opcTR*255.,trace_rclrTR,wgtTR*100.);
09648         printf("  %3.0f %3.0f %3.0f",trace_opcBR*255.,trace_rclrBR,wgtBR*100.);
09649         printf("  %3.0f %3.0f\n", iopc*255., 
09650                ipixel->rclrflt);
09651         
09652         printf("              ");
09653         printf("      %3.0f    ",trace_rsclrTL);
09654         printf("      %3.0f    ",trace_rsclrBL);
09655         printf("      %3.0f    ",trace_rsclrTR);
09656         printf("      %3.0f    ",trace_rsclrBR);
09657         printf("  %3.0f\n", shadow_pixel->opcflt * 255.);
09658         
09659         printf("              ");
09660         printf("      %3.0f    ",trace_gclrTL);
09661         printf("      %3.0f    ",trace_gclrBL);
09662         printf("      %3.0f    ",trace_gclrTR);
09663         printf("      %3.0f    ",trace_gclrBR);
09664         printf("      %3.0f\n", ipixel->gclrflt);
09665         printf("              ");
09666         printf("      %3.0f    ",trace_bclrTL);
09667         printf("      %3.0f    ",trace_bclrBL);
09668         printf("      %3.0f    ",trace_bclrTR);
09669         printf("      %3.0f    ",trace_bclrBR);
09670         printf("      %3.0f\n", ipixel->bclrflt);
09671     }
09672 #endif /* DEBUG */
09673 ;
09674 #           ifndef SKIP_ERT
09675                 if (iopc >= max_opacity) {
09676                     ASSERT(ipixel->lnk == 0);
09677                     ipixel->lnk = 1;
09678                 }
09679 #           endif
09680         };
09681                 break;
09682             case ALL_NONZERO:
09683                 /* the top and bottom left voxels contribute */
09684                 if (!voxels_loaded) {
09685                     
09686     
09687             opac_param = VoxelField(topRLEdata - voxel_istride, param0_offset, param0_size);
09688             opacity = param0_table[opac_param];
09689             if (param1_size != 0) {
09690                 opac_param = VoxelField(topRLEdata - voxel_istride, param1_offset, param1_size);
09691                 opacity *= param1_table[opac_param];
09692                 if (param2_size != 0) {
09693                     opac_param = VoxelField(topRLEdata - voxel_istride, param2_offset, param2_size);
09694                     opacity *= param2_table[opac_param];
09695                 }
09696             }
09697             if (opacity > min_opacity) {
09698                 opacity_int = opacity*255.;
09699                 top_opc = opac_correct[opacity_int];
09700             } else {
09701                 top_opc = (float)0.;
09702             };
09703     
09704     
09705     shade_index=num_materials*3*ShortField(topRLEdata - voxel_istride,norm_offset);
09706     weight_index = num_materials * ByteField(topRLEdata - voxel_istride, wgt_offset);
09707     
09708         
09709         
09710     top_rclr = 
09711     shade_table[shade_index + 3*0 + 0] * 
09712         ((num_materials > 1) ? weight_table[weight_index] : (float)1.0);
09713         
09714     top_gclr = 
09715     shade_table[shade_index + 3*0 + 1] * 
09716         ((num_materials > 1) ? weight_table[weight_index] : (float)1.0);
09717         
09718     top_bclr = 
09719     shade_table[shade_index + 3*0 + 2] * 
09720         ((num_materials > 1) ? weight_table[weight_index] : (float)1.0);
09721         
09722         top_rsclr = 
09723     shadow_table[shade_index + 3*0 + 0] * 
09724         ((num_materials > 1) ? weight_table[weight_index] : (float)1.0);
09725         
09726         top_gsclr = 
09727     shadow_table[shade_index + 3*0 + 1] * 
09728         ((num_materials > 1) ? weight_table[weight_index] : (float)1.0);
09729         
09730         top_bsclr = 
09731     shadow_table[shade_index + 3*0 + 2] * 
09732         ((num_materials > 1) ? weight_table[weight_index] : (float)1.0);
09733         for (m = 1; m < num_materials; m++) {
09734              
09735         
09736     top_rclr += 
09737     shade_table[shade_index + 3*m + 0] * 
09738         weight_table[weight_index + m];
09739         
09740     top_gclr += 
09741     shade_table[shade_index + 3*m + 1] * 
09742         weight_table[weight_index + m];
09743         
09744     top_bclr += 
09745     shade_table[shade_index + 3*m + 2] * 
09746         weight_table[weight_index + m];
09747         
09748         top_rsclr += 
09749     shadow_table[shade_index + 3*m + 0] * 
09750         weight_table[weight_index + m];
09751         
09752         top_gsclr += 
09753     shadow_table[shade_index + 3*m + 1] * 
09754         weight_table[weight_index + m];
09755         
09756         top_bsclr += 
09757     shadow_table[shade_index + 3*m + 2] * 
09758         weight_table[weight_index + m];
09759         };
09760     shade_factor = top_opc * slice_depth_cueing;
09761     
09762         top_rclr *= shade_factor;
09763         top_gclr *= shade_factor;
09764         top_bclr *= shade_factor;
09765     
09766             top_rsclr *= shade_factor;
09767             top_gsclr *= shade_factor;
09768             top_bsclr *= shade_factor;
09769                     
09770     
09771             opac_param = VoxelField(botRLEdata - voxel_istride, param0_offset, param0_size);
09772             opacity = param0_table[opac_param];
09773             if (param1_size != 0) {
09774                 opac_param = VoxelField(botRLEdata - voxel_istride, param1_offset, param1_size);
09775                 opacity *= param1_table[opac_param];
09776                 if (param2_size != 0) {
09777                     opac_param = VoxelField(botRLEdata - voxel_istride, param2_offset, param2_size);
09778                     opacity *= param2_table[opac_param];
09779                 }
09780             }
09781             if (opacity > min_opacity) {
09782                 opacity_int = opacity*255.;
09783                 bot_opc = opac_correct[opacity_int];
09784             } else {
09785                 bot_opc = (float)0.;
09786             };
09787     
09788     
09789     shade_index=num_materials*3*ShortField(botRLEdata - voxel_istride,norm_offset);
09790     weight_index = num_materials * ByteField(botRLEdata - voxel_istride, wgt_offset);
09791     
09792         
09793         
09794     bot_rclr = 
09795     shade_table[shade_index + 3*0 + 0] * 
09796         ((num_materials > 1) ? weight_table[weight_index] : (float)1.0);
09797         
09798     bot_gclr = 
09799     shade_table[shade_index + 3*0 + 1] * 
09800         ((num_materials > 1) ? weight_table[weight_index] : (float)1.0);
09801         
09802     bot_bclr = 
09803     shade_table[shade_index + 3*0 + 2] * 
09804         ((num_materials > 1) ? weight_table[weight_index] : (float)1.0);
09805         
09806         bot_rsclr = 
09807     shadow_table[shade_index + 3*0 + 0] * 
09808         ((num_materials > 1) ? weight_table[weight_index] : (float)1.0);
09809         
09810         bot_gsclr = 
09811     shadow_table[shade_index + 3*0 + 1] * 
09812         ((num_materials > 1) ? weight_table[weight_index] : (float)1.0);
09813         
09814         bot_bsclr = 
09815     shadow_table[shade_index + 3*0 + 2] * 
09816         ((num_materials > 1) ? weight_table[weight_index] : (float)1.0);
09817         for (m = 1; m < num_materials; m++) {
09818              
09819         
09820     bot_rclr += 
09821     shade_table[shade_index + 3*m + 0] * 
09822         weight_table[weight_index + m];
09823         
09824     bot_gclr += 
09825     shade_table[shade_index + 3*m + 1] * 
09826         weight_table[weight_index + m];
09827         
09828     bot_bclr += 
09829     shade_table[shade_index + 3*m + 2] * 
09830         weight_table[weight_index + m];
09831         
09832         bot_rsclr += 
09833     shadow_table[shade_index + 3*m + 0] * 
09834         weight_table[weight_index + m];
09835         
09836         bot_gsclr += 
09837     shadow_table[shade_index + 3*m + 1] * 
09838         weight_table[weight_index + m];
09839         
09840         bot_bsclr += 
09841     shadow_table[shade_index + 3*m + 2] * 
09842         weight_table[weight_index + m];
09843         };
09844     shade_factor = bot_opc * slice_depth_cueing;
09845     
09846         bot_rclr *= shade_factor;
09847         bot_gclr *= shade_factor;
09848         bot_bclr *= shade_factor;
09849     
09850             bot_rsclr *= shade_factor;
09851             bot_gsclr *= shade_factor;
09852             bot_bsclr *= shade_factor;
09853                 }
09854                 
09855 #ifdef DEBUG
09856     if (ipixel == trace_pixel_ptr) {
09857         trace_opcTL = 0.; trace_opcBL = 0.; trace_opcTR = 0.; trace_opcBR = 0.;
09858         trace_rsclrTL=0.; trace_rsclrBL=0.; trace_rsclrTR=0.; trace_rsclrBR=0.;
09859         trace_rclrTL= 0.; trace_rclrBL= 0.; trace_rclrTR= 0.; trace_rclrBR= 0.;
09860         trace_gclrTL= 0.; trace_gclrBL= 0.; trace_gclrTR= 0.; trace_gclrBR= 0.;
09861         trace_bclrTL= 0.; trace_bclrBL= 0.; trace_bclrTR= 0.; trace_bclrBR= 0.;
09862     }
09863 #endif
09864 ;
09865                 
09866        acc_opc = top_opc * wgtTL;
09867        
09868             acc_rclr = (top_rclr + top_rsclr *
09869                          ((float)1.0 - shadow_pixel->opcflt)) * wgtTL;
09870             acc_gclr = (top_gclr + top_gsclr *
09871                          ((float)1.0 - shadow_pixel->opcflt)) * wgtTL;
09872             acc_bclr = (top_bclr + top_bsclr *
09873                          ((float)1.0 - shadow_pixel->opcflt)) * wgtTL;
09874        
09875 #ifdef DEBUG
09876     if (ipixel == trace_pixel_ptr) {
09877         trace_opcTL = top_opc;
09878         trace_rclrTL = top_rclr;
09879                      trace_gclrTL = top_gclr;
09880                      trace_bclrTL = top_bclr;
09881         
09882     }
09883 #endif
09884 ;
09885                 
09886        acc_opc += bot_opc * wgtBL;
09887        
09888             acc_rclr += (bot_rclr + bot_rsclr *
09889                          ((float)1.0 - shadow_pixel->opcflt)) * wgtBL;
09890             acc_gclr += (bot_gclr + bot_gsclr *
09891                          ((float)1.0 - shadow_pixel->opcflt)) * wgtBL;
09892             acc_bclr += (bot_bclr + bot_bsclr *
09893                          ((float)1.0 - shadow_pixel->opcflt)) * wgtBL;
09894        
09895 #ifdef DEBUG
09896     if (ipixel == trace_pixel_ptr) {
09897         trace_opcBL = bot_opc;
09898         trace_rclrBL = bot_rclr;
09899                      trace_gclrBL = bot_gclr;
09900                      trace_bclrBL = bot_bclr;
09901         
09902     }
09903 #endif
09904 ;
09905                 
09906         COUNT_RESAMPLE;
09907         if (acc_opc > min_opacity) {
09908             COUNT_COMPOSITE;
09909             iopc = ipixel->opcflt;
09910 #           ifndef SKIP_ERT
09911                 ASSERT(iopc < max_opacity);
09912 #           endif
09913             iopc_inv = (float)1. - iopc;
09914             
09915         ipixel->rclrflt += acc_rclr * iopc_inv;
09916         ipixel->gclrflt += acc_gclr * iopc_inv;
09917         ipixel->bclrflt += acc_bclr * iopc_inv;
09918             iopc += acc_opc * iopc_inv;
09919             ipixel->opcflt = iopc;
09920             
09921 #ifdef DEBUG
09922     if (ipixel == trace_pixel_ptr) {
09923 #ifdef COMPUTE_SHADOW_BUFFER
09924         printf("{%3d}  %3d %3d", k, icount-i-count, j);
09925 #else
09926         printf("[%3d]  %3d %3d", k, icount-i-count, j);
09927 #endif
09928         printf("  %3.0f %3.0f %3.0f",trace_opcTL*255.,trace_rclrTL,wgtTL*100.);
09929         printf("  %3.0f %3.0f %3.0f",trace_opcBL*255.,trace_rclrBL,wgtBL*100.);
09930         printf("  %3.0f %3.0f %3.0f",trace_opcTR*255.,trace_rclrTR,wgtTR*100.);
09931         printf("  %3.0f %3.0f %3.0f",trace_opcBR*255.,trace_rclrBR,wgtBR*100.);
09932         printf("  %3.0f %3.0f\n", iopc*255., 
09933                ipixel->rclrflt);
09934         
09935         printf("              ");
09936         printf("      %3.0f    ",trace_rsclrTL);
09937         printf("      %3.0f    ",trace_rsclrBL);
09938         printf("      %3.0f    ",trace_rsclrTR);
09939         printf("      %3.0f    ",trace_rsclrBR);
09940         printf("  %3.0f\n", shadow_pixel->opcflt * 255.);
09941         
09942         printf("              ");
09943         printf("      %3.0f    ",trace_gclrTL);
09944         printf("      %3.0f    ",trace_gclrBL);
09945         printf("      %3.0f    ",trace_gclrTR);
09946         printf("      %3.0f    ",trace_gclrBR);
09947         printf("      %3.0f\n", ipixel->gclrflt);
09948         printf("              ");
09949         printf("      %3.0f    ",trace_bclrTL);
09950         printf("      %3.0f    ",trace_bclrBL);
09951         printf("      %3.0f    ",trace_bclrTR);
09952         printf("      %3.0f    ",trace_bclrBR);
09953         printf("      %3.0f\n", ipixel->bclrflt);
09954     }
09955 #endif /* DEBUG */
09956 ;
09957 #           ifndef SKIP_ERT
09958                 if (iopc >= max_opacity) {
09959                     ASSERT(ipixel->lnk == 0);
09960                     ipixel->lnk = 1;
09961                 }
09962 #           endif
09963         };
09964                 break;
09965             default:
09966                 VPBug("illegal value for run state at end of scanline");
09967             }
09968         } else if (last_run_state == ALL_ZERO) {
09969             Debug((vpc, VPDEBUG_COMPOSITE, "ZeroSkip(1)End\n"));
09970         } else {
09971             Debug((vpc, VPDEBUG_COMPOSITE, "ERTSkip(1)End\n"));
09972         }
09973 #endif /* UNROLL_RUN_LOOP */
09974 #endif /* SKIP_COMPOSITE */
09975 
09976 #ifndef UNROLL_RUN_LOOP
09977         run_state = final_run_state;
09978 #endif
09979         /* skip over any zero-length runs remaining in this scanline */
09980         if (j != 0 && ((run_state & 1) == 0)) {
09981             toprun_count = *topRLElen++;
09982             ASSERT(toprun_count == 0);
09983         }
09984         if (j != jcount && ((run_state & 2) == 0)) {
09985             botrun_count = *botRLElen++;
09986             ASSERT(botrun_count == 0);
09987         }
09988 
09989         /* go to next intermediate image scanline */
09990 #ifdef UNROLL_RUN_LOOP
09991         ipixel += intermediate_width - icount;
09992 #ifdef USE_SHADOW_BUFFER
09993         shadow_pixel += shadow_width - icount;
09994 #endif
09995 #else /* UNROLL_RUN_LOOP */
09996         ipixel += intermediate_width - (icount+1);
09997 #ifdef USE_SHADOW_BUFFER
09998         shadow_pixel += shadow_width - (icount+1);
09999 #endif
10000 #endif /* UNROLL_RUN_LOOP */
10001 
10002         Debug((vpc, VPDEBUG_COMPOSITE, "ScanDone\n"));
10003     } /* for j */
10004 
10005     /***************************************************************
10006      * Finish processing the voxel slice.
10007      ***************************************************************/
10008 
10009     GET_HIRES_TIME(vpc, t1);
10010     STORE_HIRES_TIME(vpc, VPTIMER_TRAVERSE_RUNS, t0, t1);
10011 
10012     Debug((vpc, VPDEBUG_COMPOSITE, "SliceDone\n"));
10013 }
 

Powered by Plone

This site conforms to the following standards: