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_compAR1NS.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 #define GRAYSCALE
00126     
00127     
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  * VPCompAR1NS
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 VPCompAR1NS (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 GrayIntPixel *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     GrayIntPixel *ipixel;       /* current intermediate image pixel */
00245     GrayIntPixel *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     GrayIntPixel *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(GrayIntPixel)) % vpc->intermediate_width,
00617                (((int)ipixel - (int)vpc->int_image.gray_intim) /
00618                 sizeof(GrayIntPixel)) / 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*1*ShortField(topRLEdata - voxel_istride,norm_offset);
00984     weight_index = num_materials * ByteField(topRLEdata - voxel_istride, wgt_offset);
00985     
00986         
00987         
00988     top_clr = 
00989     shade_table[shade_index + 1*0 + 0] * 
00990         ((num_materials > 1) ? weight_table[weight_index] : (float)1.0);
00991         
00992         top_sclr = 
00993     shadow_table[shade_index + 1*0 + 0] * 
00994         ((num_materials > 1) ? weight_table[weight_index] : (float)1.0);
00995         for (m = 1; m < num_materials; m++) {
00996              
00997         
00998     top_clr += 
00999     shade_table[shade_index + 1*m + 0] * 
01000         weight_table[weight_index + m];
01001         
01002         top_sclr += 
01003     shadow_table[shade_index + 1*m + 0] * 
01004         weight_table[weight_index + m];
01005         };
01006     shade_factor = top_opc * slice_depth_cueing;
01007     
01008         top_clr *= shade_factor;
01009     
01010             top_sclr *= shade_factor;
01011                 }
01012                 
01013 #ifdef DEBUG
01014     if (ipixel == trace_pixel_ptr) {
01015         trace_opcTL = 0.; trace_opcBL = 0.; trace_opcTR = 0.; trace_opcBR = 0.;
01016         trace_rsclrTL=0.; trace_rsclrBL=0.; trace_rsclrTR=0.; trace_rsclrBR=0.;
01017         trace_rclrTL= 0.; trace_rclrBL= 0.; trace_rclrTR= 0.; trace_rclrBR= 0.;
01018         trace_gclrTL= 0.; trace_gclrBL= 0.; trace_gclrTR= 0.; trace_gclrBR= 0.;
01019         trace_bclrTL= 0.; trace_bclrBL= 0.; trace_bclrTR= 0.; trace_bclrBR= 0.;
01020     }
01021 #endif
01022 ;
01023                 
01024        acc_opc = top_opc * wgtTL;
01025        acc_clr = (top_clr + top_sclr *
01026                             ((float)1.0 - shadow_pixel->opcflt)) * wgtTL;
01027        
01028 #ifdef DEBUG
01029     if (ipixel == trace_pixel_ptr) {
01030         trace_opcTL = top_opc;
01031         trace_rclrTL = top_clr;
01032         trace_rsclrTL = top_sclr;
01033     }
01034 #endif
01035 ;
01036                 
01037         COUNT_RESAMPLE;
01038         if (acc_opc > min_opacity) {
01039             COUNT_COMPOSITE;
01040             iopc = ipixel->opcflt;
01041 #           ifndef SKIP_ERT
01042                 ASSERT(iopc < max_opacity);
01043 #           endif
01044             iopc_inv = (float)1. - iopc;
01045             ipixel->clrflt += acc_clr * iopc_inv;
01046             iopc += acc_opc * iopc_inv;
01047             ipixel->opcflt = iopc;
01048             
01049 #ifdef DEBUG
01050     if (ipixel == trace_pixel_ptr) {
01051 #ifdef COMPUTE_SHADOW_BUFFER
01052         printf("{%3d}  %3d %3d", k, icount-i-count, j);
01053 #else
01054         printf("[%3d]  %3d %3d", k, icount-i-count, j);
01055 #endif
01056         printf("  %3.0f %3.0f %3.0f",trace_opcTL*255.,trace_rclrTL,wgtTL*100.);
01057         printf("  %3.0f %3.0f %3.0f",trace_opcBL*255.,trace_rclrBL,wgtBL*100.);
01058         printf("  %3.0f %3.0f %3.0f",trace_opcTR*255.,trace_rclrTR,wgtTR*100.);
01059         printf("  %3.0f %3.0f %3.0f",trace_opcBR*255.,trace_rclrBR,wgtBR*100.);
01060         printf("  %3.0f %3.0f\n", iopc*255., 
01061                ipixel->clrflt);
01062         
01063         printf("              ");
01064         printf("      %3.0f    ",trace_rsclrTL);
01065         printf("      %3.0f    ",trace_rsclrBL);
01066         printf("      %3.0f    ",trace_rsclrTR);
01067         printf("      %3.0f    ",trace_rsclrBR);
01068         printf("  %3.0f\n", shadow_pixel->opcflt * 255.);
01069         
01070     }
01071 #endif /* DEBUG */
01072 ;
01073 #           ifndef SKIP_ERT
01074                 if (iopc >= max_opacity) {
01075                     ASSERT(ipixel->lnk == 0);
01076                     ipixel->lnk = 1;
01077                 }
01078 #           endif
01079         };
01080                 ipixel += count; shadow_pixel += count;
01081                 topRLEdata += count * voxel_istride;
01082                 botRLEdata += count * voxel_istride;
01083                 count = 0;
01084                 break;
01085             case BOT_NONZERO__ALL_ZERO:
01086                 /* only the bottom left voxel contributes to the first
01087                    pixel of the run, and the rest are zero */
01088                 if (!voxels_loaded) {
01089                     
01090     
01091             opac_param = VoxelField(botRLEdata - voxel_istride, param0_offset, param0_size);
01092             opacity = param0_table[opac_param];
01093             if (param1_size != 0) {
01094                 opac_param = VoxelField(botRLEdata - voxel_istride, param1_offset, param1_size);
01095                 opacity *= param1_table[opac_param];
01096                 if (param2_size != 0) {
01097                     opac_param = VoxelField(botRLEdata - voxel_istride, param2_offset, param2_size);
01098                     opacity *= param2_table[opac_param];
01099                 }
01100             }
01101             if (opacity > min_opacity) {
01102                 opacity_int = opacity*255.;
01103                 bot_opc = opac_correct[opacity_int];
01104             } else {
01105                 bot_opc = (float)0.;
01106             };
01107     
01108     
01109     shade_index=num_materials*1*ShortField(botRLEdata - voxel_istride,norm_offset);
01110     weight_index = num_materials * ByteField(botRLEdata - voxel_istride, wgt_offset);
01111     
01112         
01113         
01114     bot_clr = 
01115     shade_table[shade_index + 1*0 + 0] * 
01116         ((num_materials > 1) ? weight_table[weight_index] : (float)1.0);
01117         
01118         bot_sclr = 
01119     shadow_table[shade_index + 1*0 + 0] * 
01120         ((num_materials > 1) ? weight_table[weight_index] : (float)1.0);
01121         for (m = 1; m < num_materials; m++) {
01122              
01123         
01124     bot_clr += 
01125     shade_table[shade_index + 1*m + 0] * 
01126         weight_table[weight_index + m];
01127         
01128         bot_sclr += 
01129     shadow_table[shade_index + 1*m + 0] * 
01130         weight_table[weight_index + m];
01131         };
01132     shade_factor = bot_opc * slice_depth_cueing;
01133     
01134         bot_clr *= shade_factor;
01135     
01136             bot_sclr *= shade_factor;
01137                 }
01138                 
01139 #ifdef DEBUG
01140     if (ipixel == trace_pixel_ptr) {
01141         trace_opcTL = 0.; trace_opcBL = 0.; trace_opcTR = 0.; trace_opcBR = 0.;
01142         trace_rsclrTL=0.; trace_rsclrBL=0.; trace_rsclrTR=0.; trace_rsclrBR=0.;
01143         trace_rclrTL= 0.; trace_rclrBL= 0.; trace_rclrTR= 0.; trace_rclrBR= 0.;
01144         trace_gclrTL= 0.; trace_gclrBL= 0.; trace_gclrTR= 0.; trace_gclrBR= 0.;
01145         trace_bclrTL= 0.; trace_bclrBL= 0.; trace_bclrTR= 0.; trace_bclrBR= 0.;
01146     }
01147 #endif
01148 ;
01149                 
01150        acc_opc = bot_opc * wgtBL;
01151        acc_clr = (bot_clr + bot_sclr *
01152                             ((float)1.0 - shadow_pixel->opcflt)) * wgtBL;
01153        
01154 #ifdef DEBUG
01155     if (ipixel == trace_pixel_ptr) {
01156         trace_opcBL = bot_opc;
01157         trace_rclrBL = bot_clr;
01158         trace_rsclrBL = bot_sclr;
01159     }
01160 #endif
01161 ;
01162                 
01163         COUNT_RESAMPLE;
01164         if (acc_opc > min_opacity) {
01165             COUNT_COMPOSITE;
01166             iopc = ipixel->opcflt;
01167 #           ifndef SKIP_ERT
01168                 ASSERT(iopc < max_opacity);
01169 #           endif
01170             iopc_inv = (float)1. - iopc;
01171             ipixel->clrflt += acc_clr * iopc_inv;
01172             iopc += acc_opc * iopc_inv;
01173             ipixel->opcflt = iopc;
01174             
01175 #ifdef DEBUG
01176     if (ipixel == trace_pixel_ptr) {
01177 #ifdef COMPUTE_SHADOW_BUFFER
01178         printf("{%3d}  %3d %3d", k, icount-i-count, j);
01179 #else
01180         printf("[%3d]  %3d %3d", k, icount-i-count, j);
01181 #endif
01182         printf("  %3.0f %3.0f %3.0f",trace_opcTL*255.,trace_rclrTL,wgtTL*100.);
01183         printf("  %3.0f %3.0f %3.0f",trace_opcBL*255.,trace_rclrBL,wgtBL*100.);
01184         printf("  %3.0f %3.0f %3.0f",trace_opcTR*255.,trace_rclrTR,wgtTR*100.);
01185         printf("  %3.0f %3.0f %3.0f",trace_opcBR*255.,trace_rclrBR,wgtBR*100.);
01186         printf("  %3.0f %3.0f\n", iopc*255., 
01187                ipixel->clrflt);
01188         
01189         printf("              ");
01190         printf("      %3.0f    ",trace_rsclrTL);
01191         printf("      %3.0f    ",trace_rsclrBL);
01192         printf("      %3.0f    ",trace_rsclrTR);
01193         printf("      %3.0f    ",trace_rsclrBR);
01194         printf("  %3.0f\n", shadow_pixel->opcflt * 255.);
01195         
01196     }
01197 #endif /* DEBUG */
01198 ;
01199 #           ifndef SKIP_ERT
01200                 if (iopc >= max_opacity) {
01201                     ASSERT(ipixel->lnk == 0);
01202                     ipixel->lnk = 1;
01203                 }
01204 #           endif
01205         };
01206                 ipixel += count; shadow_pixel += count;
01207                 topRLEdata += count * voxel_istride;
01208                 botRLEdata += count * voxel_istride;
01209                 count = 0;
01210                 break;
01211             case ALL_NONZERO__ALL_ZERO:
01212                 /* the top and bottom left voxels contribute to the
01213                    first pixel of the run, and the rest are zero */
01214                 if (!voxels_loaded) {
01215                     
01216     
01217             opac_param = VoxelField(topRLEdata - voxel_istride, param0_offset, param0_size);
01218             opacity = param0_table[opac_param];
01219             if (param1_size != 0) {
01220                 opac_param = VoxelField(topRLEdata - voxel_istride, param1_offset, param1_size);
01221                 opacity *= param1_table[opac_param];
01222                 if (param2_size != 0) {
01223                     opac_param = VoxelField(topRLEdata - voxel_istride, param2_offset, param2_size);
01224                     opacity *= param2_table[opac_param];
01225                 }
01226             }
01227             if (opacity > min_opacity) {
01228                 opacity_int = opacity*255.;
01229                 top_opc = opac_correct[opacity_int];
01230             } else {
01231                 top_opc = (float)0.;
01232             };
01233     
01234     
01235     shade_index=num_materials*1*ShortField(topRLEdata - voxel_istride,norm_offset);
01236     weight_index = num_materials * ByteField(topRLEdata - voxel_istride, wgt_offset);
01237     
01238         
01239         
01240     top_clr = 
01241     shade_table[shade_index + 1*0 + 0] * 
01242         ((num_materials > 1) ? weight_table[weight_index] : (float)1.0);
01243         
01244         top_sclr = 
01245     shadow_table[shade_index + 1*0 + 0] * 
01246         ((num_materials > 1) ? weight_table[weight_index] : (float)1.0);
01247         for (m = 1; m < num_materials; m++) {
01248              
01249         
01250     top_clr += 
01251     shade_table[shade_index + 1*m + 0] * 
01252         weight_table[weight_index + m];
01253         
01254         top_sclr += 
01255     shadow_table[shade_index + 1*m + 0] * 
01256         weight_table[weight_index + m];
01257         };
01258     shade_factor = top_opc * slice_depth_cueing;
01259     
01260         top_clr *= shade_factor;
01261     
01262             top_sclr *= shade_factor;
01263                     
01264     
01265             opac_param = VoxelField(botRLEdata - voxel_istride, param0_offset, param0_size);
01266             opacity = param0_table[opac_param];
01267             if (param1_size != 0) {
01268                 opac_param = VoxelField(botRLEdata - voxel_istride, param1_offset, param1_size);
01269                 opacity *= param1_table[opac_param];
01270                 if (param2_size != 0) {
01271                     opac_param = VoxelField(botRLEdata - voxel_istride, param2_offset, param2_size);
01272                     opacity *= param2_table[opac_param];
01273                 }
01274             }
01275             if (opacity > min_opacity) {
01276                 opacity_int = opacity*255.;
01277                 bot_opc = opac_correct[opacity_int];
01278             } else {
01279                 bot_opc = (float)0.;
01280             };
01281     
01282     
01283     shade_index=num_materials*1*ShortField(botRLEdata - voxel_istride,norm_offset);
01284     weight_index = num_materials * ByteField(botRLEdata - voxel_istride, wgt_offset);
01285     
01286         
01287         
01288     bot_clr = 
01289     shade_table[shade_index + 1*0 + 0] * 
01290         ((num_materials > 1) ? weight_table[weight_index] : (float)1.0);
01291         
01292         bot_sclr = 
01293     shadow_table[shade_index + 1*0 + 0] * 
01294         ((num_materials > 1) ? weight_table[weight_index] : (float)1.0);
01295         for (m = 1; m < num_materials; m++) {
01296              
01297         
01298     bot_clr += 
01299     shade_table[shade_index + 1*m + 0] * 
01300         weight_table[weight_index + m];
01301         
01302         bot_sclr += 
01303     shadow_table[shade_index + 1*m + 0] * 
01304         weight_table[weight_index + m];
01305         };
01306     shade_factor = bot_opc * slice_depth_cueing;
01307     
01308         bot_clr *= shade_factor;
01309     
01310             bot_sclr *= shade_factor;
01311                 }
01312                 
01313 #ifdef DEBUG
01314     if (ipixel == trace_pixel_ptr) {
01315         trace_opcTL = 0.; trace_opcBL = 0.; trace_opcTR = 0.; trace_opcBR = 0.;
01316         trace_rsclrTL=0.; trace_rsclrBL=0.; trace_rsclrTR=0.; trace_rsclrBR=0.;
01317         trace_rclrTL= 0.; trace_rclrBL= 0.; trace_rclrTR= 0.; trace_rclrBR= 0.;
01318         trace_gclrTL= 0.; trace_gclrBL= 0.; trace_gclrTR= 0.; trace_gclrBR= 0.;
01319         trace_bclrTL= 0.; trace_bclrBL= 0.; trace_bclrTR= 0.; trace_bclrBR= 0.;
01320     }
01321 #endif
01322 ;
01323                 
01324        acc_opc = top_opc * wgtTL;
01325        acc_clr = (top_clr + top_sclr *
01326                             ((float)1.0 - shadow_pixel->opcflt)) * wgtTL;
01327        
01328 #ifdef DEBUG
01329     if (ipixel == trace_pixel_ptr) {
01330         trace_opcTL = top_opc;
01331         trace_rclrTL = top_clr;
01332         trace_rsclrTL = top_sclr;
01333     }
01334 #endif
01335 ;
01336                 
01337        acc_opc += bot_opc * wgtBL;
01338        acc_clr += (bot_clr + bot_sclr *
01339                             ((float)1.0 - shadow_pixel->opcflt)) * wgtBL;
01340        
01341 #ifdef DEBUG
01342     if (ipixel == trace_pixel_ptr) {
01343         trace_opcBL = bot_opc;
01344         trace_rclrBL = bot_clr;
01345         trace_rsclrBL = bot_sclr;
01346     }
01347 #endif
01348 ;
01349                 
01350         COUNT_RESAMPLE;
01351         if (acc_opc > min_opacity) {
01352             COUNT_COMPOSITE;
01353             iopc = ipixel->opcflt;
01354 #           ifndef SKIP_ERT
01355                 ASSERT(iopc < max_opacity);
01356 #           endif
01357             iopc_inv = (float)1. - iopc;
01358             ipixel->clrflt += acc_clr * iopc_inv;
01359             iopc += acc_opc * iopc_inv;
01360             ipixel->opcflt = iopc;
01361             
01362 #ifdef DEBUG
01363     if (ipixel == trace_pixel_ptr) {
01364 #ifdef COMPUTE_SHADOW_BUFFER
01365         printf("{%3d}  %3d %3d", k, icount-i-count, j);
01366 #else
01367         printf("[%3d]  %3d %3d", k, icount-i-count, j);
01368 #endif
01369         printf("  %3.0f %3.0f %3.0f",trace_opcTL*255.,trace_rclrTL,wgtTL*100.);
01370         printf("  %3.0f %3.0f %3.0f",trace_opcBL*255.,trace_rclrBL,wgtBL*100.);
01371         printf("  %3.0f %3.0f %3.0f",trace_opcTR*255.,trace_rclrTR,wgtTR*100.);
01372         printf("  %3.0f %3.0f %3.0f",trace_opcBR*255.,trace_rclrBR,wgtBR*100.);
01373         printf("  %3.0f %3.0f\n", iopc*255., 
01374                ipixel->clrflt);
01375         
01376         printf("              ");
01377         printf("      %3.0f    ",trace_rsclrTL);
01378         printf("      %3.0f    ",trace_rsclrBL);
01379         printf("      %3.0f    ",trace_rsclrTR);
01380         printf("      %3.0f    ",trace_rsclrBR);
01381         printf("  %3.0f\n", shadow_pixel->opcflt * 255.);
01382         
01383     }
01384 #endif /* DEBUG */
01385 ;
01386 #           ifndef SKIP_ERT
01387                 if (iopc >= max_opacity) {
01388                     ASSERT(ipixel->lnk == 0);
01389                     ipixel->lnk = 1;
01390                 }
01391 #           endif
01392         };
01393                 ipixel += count; shadow_pixel += count;
01394                 topRLEdata += count * voxel_istride;
01395                 botRLEdata += count * voxel_istride;
01396                 count = 0;
01397                 break;
01398             case ALL_ZERO__TOP_NONZERO:
01399                 /* first pixel: only the top-right voxel contributes */
01400                 
01401     
01402             opac_param = VoxelField(topRLEdata, param0_offset, param0_size);
01403             opacity = param0_table[opac_param];
01404             if (param1_size != 0) {
01405                 opac_param = VoxelField(topRLEdata, param1_offset, param1_size);
01406                 opacity *= param1_table[opac_param];
01407                 if (param2_size != 0) {
01408                     opac_param = VoxelField(topRLEdata, param2_offset, param2_size);
01409                     opacity *= param2_table[opac_param];
01410                 }
01411             }
01412             if (opacity > min_opacity) {
01413                 opacity_int = opacity*255.;
01414                 top_opc = opac_correct[opacity_int];
01415             } else {
01416                 top_opc = (float)0.;
01417             };
01418     
01419     
01420     shade_index=num_materials*1*ShortField(topRLEdata,norm_offset);
01421     weight_index = num_materials * ByteField(topRLEdata, wgt_offset);
01422     
01423         
01424         
01425     top_clr = 
01426     shade_table[shade_index + 1*0 + 0] * 
01427         ((num_materials > 1) ? weight_table[weight_index] : (float)1.0);
01428         
01429         top_sclr = 
01430     shadow_table[shade_index + 1*0 + 0] * 
01431         ((num_materials > 1) ? weight_table[weight_index] : (float)1.0);
01432         for (m = 1; m < num_materials; m++) {
01433              
01434         
01435     top_clr += 
01436     shade_table[shade_index + 1*m + 0] * 
01437         weight_table[weight_index + m];
01438         
01439         top_sclr += 
01440     shadow_table[shade_index + 1*m + 0] * 
01441         weight_table[weight_index + m];
01442         };
01443     shade_factor = top_opc * slice_depth_cueing;
01444     
01445         top_clr *= shade_factor;
01446     
01447             top_sclr *= shade_factor;
01448                 
01449 #ifdef DEBUG
01450     if (ipixel == trace_pixel_ptr) {
01451         trace_opcTL = 0.; trace_opcBL = 0.; trace_opcTR = 0.; trace_opcBR = 0.;
01452         trace_rsclrTL=0.; trace_rsclrBL=0.; trace_rsclrTR=0.; trace_rsclrBR=0.;
01453         trace_rclrTL= 0.; trace_rclrBL= 0.; trace_rclrTR= 0.; trace_rclrBR= 0.;
01454         trace_gclrTL= 0.; trace_gclrBL= 0.; trace_gclrTR= 0.; trace_gclrBR= 0.;
01455         trace_bclrTL= 0.; trace_bclrBL= 0.; trace_bclrTR= 0.; trace_bclrBR= 0.;
01456     }
01457 #endif
01458 ;
01459                 
01460        acc_opc = top_opc * wgtTR;
01461        acc_clr = (top_clr + top_sclr *
01462                             ((float)1.0 - shadow_pixel->opcflt)) * wgtTR;
01463        
01464 #ifdef DEBUG
01465     if (ipixel == trace_pixel_ptr) {
01466         trace_opcTR = top_opc;
01467         trace_rclrTR = top_clr;
01468         trace_rsclrTR = top_sclr;
01469     }
01470 #endif
01471 ;
01472                 
01473         COUNT_RESAMPLE;
01474         if (acc_opc > min_opacity) {
01475             COUNT_COMPOSITE;
01476             iopc = ipixel->opcflt;
01477 #           ifndef SKIP_ERT
01478                 ASSERT(iopc < max_opacity);
01479 #           endif
01480             iopc_inv = (float)1. - iopc;
01481             ipixel->clrflt += acc_clr * iopc_inv;
01482             iopc += acc_opc * iopc_inv;
01483             ipixel->opcflt = iopc;
01484             
01485 #ifdef DEBUG
01486     if (ipixel == trace_pixel_ptr) {
01487 #ifdef COMPUTE_SHADOW_BUFFER
01488         printf("{%3d}  %3d %3d", k, icount-i-count, j);
01489 #else
01490         printf("[%3d]  %3d %3d", k, icount-i-count, j);
01491 #endif
01492         printf("  %3.0f %3.0f %3.0f",trace_opcTL*255.,trace_rclrTL,wgtTL*100.);
01493         printf("  %3.0f %3.0f %3.0f",trace_opcBL*255.,trace_rclrBL,wgtBL*100.);
01494         printf("  %3.0f %3.0f %3.0f",trace_opcTR*255.,trace_rclrTR,wgtTR*100.);
01495         printf("  %3.0f %3.0f %3.0f",trace_opcBR*255.,trace_rclrBR,wgtBR*100.);
01496         printf("  %3.0f %3.0f\n", iopc*255., 
01497                ipixel->clrflt);
01498         
01499         printf("              ");
01500         printf("      %3.0f    ",trace_rsclrTL);
01501         printf("      %3.0f    ",trace_rsclrBL);
01502         printf("      %3.0f    ",trace_rsclrTR);
01503         printf("      %3.0f    ",trace_rsclrBR);
01504         printf("  %3.0f\n", shadow_pixel->opcflt * 255.);
01505         
01506     }
01507 #endif /* DEBUG */
01508 ;
01509 #           ifndef SKIP_ERT
01510                 if (iopc >= max_opacity) {
01511                     ASSERT(ipixel->lnk == 0);
01512                     ipixel->lnk = 1;
01513                 }
01514 #           endif
01515         };
01516                 ipixel += 1; shadow_pixel += 1;
01517                 topRLEdata += 1 * voxel_istride;
01518                 botRLEdata += 1 * voxel_istride;
01519                 count--;
01520                 SET_VOXELS_LOADED;
01521 
01522                 /* do the rest of the pixels in this run;
01523                    the top-left and top-right voxels contribute */
01524                 while (count > 0) {
01525                     if (PIXEL_IS_OPAQUE(ipixel))
01526                         break;
01527                     if (!voxels_loaded) {
01528                         
01529     
01530             opac_param = VoxelField(topRLEdata - voxel_istride, param0_offset, param0_size);
01531             opacity = param0_table[opac_param];
01532             if (param1_size != 0) {
01533                 opac_param = VoxelField(topRLEdata - voxel_istride, param1_offset, param1_size);
01534                 opacity *= param1_table[opac_param];
01535                 if (param2_size != 0) {
01536                     opac_param = VoxelField(topRLEdata - voxel_istride, param2_offset, param2_size);
01537                     opacity *= param2_table[opac_param];
01538                 }
01539             }
01540             if (opacity > min_opacity) {
01541                 opacity_int = opacity*255.;
01542                 top_opc = opac_correct[opacity_int];
01543             } else {
01544                 top_opc = (float)0.;
01545             };
01546     
01547     
01548     shade_index=num_materials*1*ShortField(topRLEdata - voxel_istride,norm_offset);
01549     weight_index = num_materials * ByteField(topRLEdata - voxel_istride, wgt_offset);
01550     
01551         
01552         
01553     top_clr = 
01554     shade_table[shade_index + 1*0 + 0] * 
01555         ((num_materials > 1) ? weight_table[weight_index] : (float)1.0);
01556         
01557         top_sclr = 
01558     shadow_table[shade_index + 1*0 + 0] * 
01559         ((num_materials > 1) ? weight_table[weight_index] : (float)1.0);
01560         for (m = 1; m < num_materials; m++) {
01561              
01562         
01563     top_clr += 
01564     shade_table[shade_index + 1*m + 0] * 
01565         weight_table[weight_index + m];
01566         
01567         top_sclr += 
01568     shadow_table[shade_index + 1*m + 0] * 
01569         weight_table[weight_index + m];
01570         };
01571     shade_factor = top_opc * slice_depth_cueing;
01572     
01573         top_clr *= shade_factor;
01574     
01575             top_sclr *= shade_factor;
01576                     }
01577                     
01578 #ifdef DEBUG
01579     if (ipixel == trace_pixel_ptr) {
01580         trace_opcTL = 0.; trace_opcBL = 0.; trace_opcTR = 0.; trace_opcBR = 0.;
01581         trace_rsclrTL=0.; trace_rsclrBL=0.; trace_rsclrTR=0.; trace_rsclrBR=0.;
01582         trace_rclrTL= 0.; trace_rclrBL= 0.; trace_rclrTR= 0.; trace_rclrBR= 0.;
01583         trace_gclrTL= 0.; trace_gclrBL= 0.; trace_gclrTR= 0.; trace_gclrBR= 0.;
01584         trace_bclrTL= 0.; trace_bclrBL= 0.; trace_bclrTR= 0.; trace_bclrBR= 0.;
01585     }
01586 #endif
01587 ;
01588                     
01589        acc_opc = top_opc * wgtTL;
01590        acc_clr = (top_clr + top_sclr *
01591                             ((float)1.0 - shadow_pixel->opcflt)) * wgtTL;
01592        
01593 #ifdef DEBUG
01594     if (ipixel == trace_pixel_ptr) {
01595         trace_opcTL = top_opc;
01596         trace_rclrTL = top_clr;
01597         trace_rsclrTL = top_sclr;
01598     }
01599 #endif
01600 ;
01601                     
01602     
01603             opac_param = VoxelField(topRLEdata, param0_offset, param0_size);
01604             opacity = param0_table[opac_param];
01605             if (param1_size != 0) {
01606                 opac_param = VoxelField(topRLEdata, param1_offset, param1_size);
01607                 opacity *= param1_table[opac_param];
01608                 if (param2_size != 0) {
01609                     opac_param = VoxelField(topRLEdata, param2_offset, param2_size);
01610                     opacity *= param2_table[opac_param];
01611                 }
01612             }
01613             if (opacity > min_opacity) {
01614                 opacity_int = opacity*255.;
01615                 top_opc = opac_correct[opacity_int];
01616             } else {
01617                 top_opc = (float)0.;
01618             };
01619     
01620     
01621     shade_index=num_materials*1*ShortField(topRLEdata,norm_offset);
01622     weight_index = num_materials * ByteField(topRLEdata, wgt_offset);
01623     
01624         
01625         
01626     top_clr = 
01627     shade_table[shade_index + 1*0 + 0] * 
01628         ((num_materials > 1) ? weight_table[weight_index] : (float)1.0);
01629         
01630         top_sclr = 
01631     shadow_table[shade_index + 1*0 + 0] * 
01632         ((num_materials > 1) ? weight_table[weight_index] : (float)1.0);
01633         for (m = 1; m < num_materials; m++) {
01634              
01635         
01636     top_clr += 
01637     shade_table[shade_index + 1*m + 0] * 
01638         weight_table[weight_index + m];
01639         
01640         top_sclr += 
01641     shadow_table[shade_index + 1*m + 0] * 
01642         weight_table[weight_index + m];
01643         };
01644     shade_factor = top_opc * slice_depth_cueing;
01645     
01646         top_clr *= shade_factor;
01647     
01648             top_sclr *= shade_factor;
01649                     
01650        acc_opc += top_opc * wgtTR;
01651        acc_clr += (top_clr + top_sclr *
01652                             ((float)1.0 - shadow_pixel->opcflt)) * wgtTR;
01653        
01654 #ifdef DEBUG
01655     if (ipixel == trace_pixel_ptr) {
01656         trace_opcTR = top_opc;
01657         trace_rclrTR = top_clr;
01658         trace_rsclrTR = top_sclr;
01659     }
01660 #endif
01661 ;
01662                     
01663         COUNT_RESAMPLE;
01664         if (acc_opc > min_opacity) {
01665             COUNT_COMPOSITE;
01666             iopc = ipixel->opcflt;
01667 #           ifndef SKIP_ERT
01668                 ASSERT(iopc < max_opacity);
01669 #           endif
01670             iopc_inv = (float)1. - iopc;
01671             ipixel->clrflt += acc_clr * iopc_inv;
01672             iopc += acc_opc * iopc_inv;
01673             ipixel->opcflt = iopc;
01674             
01675 #ifdef DEBUG
01676     if (ipixel == trace_pixel_ptr) {
01677 #ifdef COMPUTE_SHADOW_BUFFER
01678         printf("{%3d}  %3d %3d", k, icount-i-count, j);
01679 #else
01680         printf("[%3d]  %3d %3d", k, icount-i-count, j);
01681 #endif
01682         printf("  %3.0f %3.0f %3.0f",trace_opcTL*255.,trace_rclrTL,wgtTL*100.);
01683         printf("  %3.0f %3.0f %3.0f",trace_opcBL*255.,trace_rclrBL,wgtBL*100.);
01684         printf("  %3.0f %3.0f %3.0f",trace_opcTR*255.,trace_rclrTR,wgtTR*100.);
01685         printf("  %3.0f %3.0f %3.0f",trace_opcBR*255.,trace_rclrBR,wgtBR*100.);
01686         printf("  %3.0f %3.0f\n", iopc*255., 
01687                ipixel->clrflt);
01688         
01689         printf("              ");
01690         printf("      %3.0f    ",trace_rsclrTL);
01691         printf("      %3.0f    ",trace_rsclrBL);
01692         printf("      %3.0f    ",trace_rsclrTR);
01693         printf("      %3.0f    ",trace_rsclrBR);
01694         printf("  %3.0f\n", shadow_pixel->opcflt * 255.);
01695         
01696     }
01697 #endif /* DEBUG */
01698 ;
01699 #           ifndef SKIP_ERT
01700                 if (iopc >= max_opacity) {
01701                     ASSERT(ipixel->lnk == 0);
01702                     ipixel->lnk = 1;
01703                 }
01704 #           endif
01705         };
01706                     ipixel += 1; shadow_pixel += 1;
01707                     topRLEdata += 1 * voxel_istride;
01708                     botRLEdata += 1 * voxel_istride;
01709                     count--;
01710                     SET_VOXELS_LOADED;
01711                 }
01712                 break;
01713             case TOP_NONZERO__TOP_NONZERO:
01714                 /* do the pixels in this run; the top-left and
01715                    top-right voxels contribute */
01716                 while (count > 0) {
01717                     if (PIXEL_IS_OPAQUE(ipixel))
01718                         break;
01719                     if (!voxels_loaded) {
01720                         
01721     
01722             opac_param = VoxelField(topRLEdata - voxel_istride, param0_offset, param0_size);
01723             opacity = param0_table[opac_param];
01724             if (param1_size != 0) {
01725                 opac_param = VoxelField(topRLEdata - voxel_istride, param1_offset, param1_size);
01726                 opacity *= param1_table[opac_param];
01727                 if (param2_size != 0) {
01728                     opac_param = VoxelField(topRLEdata - voxel_istride, param2_offset, param2_size);
01729                     opacity *= param2_table[opac_param];
01730                 }
01731             }
01732             if (opacity > min_opacity) {
01733                 opacity_int = opacity*255.;
01734                 top_opc = opac_correct[opacity_int];
01735             } else {
01736                 top_opc = (float)0.;
01737             };
01738     
01739     
01740     shade_index=num_materials*1*ShortField(topRLEdata - voxel_istride,norm_offset);
01741     weight_index = num_materials * ByteField(topRLEdata - voxel_istride, wgt_offset);
01742     
01743         
01744         
01745     top_clr = 
01746     shade_table[shade_index + 1*0 + 0] * 
01747         ((num_materials > 1) ? weight_table[weight_index] : (float)1.0);
01748         
01749         top_sclr = 
01750     shadow_table[shade_index + 1*0 + 0] * 
01751         ((num_materials > 1) ? weight_table[weight_index] : (float)1.0);
01752         for (m = 1; m < num_materials; m++) {
01753              
01754         
01755     top_clr += 
01756     shade_table[shade_index + 1*m + 0] * 
01757         weight_table[weight_index + m];
01758         
01759         top_sclr += 
01760     shadow_table[shade_index + 1*m + 0] * 
01761         weight_table[weight_index + m];
01762         };
01763     shade_factor = top_opc * slice_depth_cueing;
01764     
01765         top_clr *= shade_factor;
01766     
01767             top_sclr *= shade_factor;
01768                     }
01769                     
01770 #ifdef DEBUG
01771     if (ipixel == trace_pixel_ptr) {
01772         trace_opcTL = 0.; trace_opcBL = 0.; trace_opcTR = 0.; trace_opcBR = 0.;
01773         trace_rsclrTL=0.; trace_rsclrBL=0.; trace_rsclrTR=0.; trace_rsclrBR=0.;
01774         trace_rclrTL= 0.; trace_rclrBL= 0.; trace_rclrTR= 0.; trace_rclrBR= 0.;
01775         trace_gclrTL= 0.; trace_gclrBL= 0.; trace_gclrTR= 0.; trace_gclrBR= 0.;
01776         trace_bclrTL= 0.; trace_bclrBL= 0.; trace_bclrTR= 0.; trace_bclrBR= 0.;
01777     }
01778 #endif
01779 ;
01780                     
01781        acc_opc = top_opc * wgtTL;
01782        acc_clr = (top_clr + top_sclr *
01783                             ((float)1.0 - shadow_pixel->opcflt)) * wgtTL;
01784        
01785 #ifdef DEBUG
01786     if (ipixel == trace_pixel_ptr) {
01787         trace_opcTL = top_opc;
01788         trace_rclrTL = top_clr;
01789         trace_rsclrTL = top_sclr;
01790     }
01791 #endif
01792 ;
01793                     
01794     
01795             opac_param = VoxelField(topRLEdata, param0_offset, param0_size);
01796             opacity = param0_table[opac_param];
01797             if (param1_size != 0) {
01798                 opac_param = VoxelField(topRLEdata, param1_offset, param1_size);
01799                 opacity *= param1_table[opac_param];
01800                 if (param2_size != 0) {
01801                     opac_param = VoxelField(topRLEdata, param2_offset, param2_size);
01802                     opacity *= param2_table[opac_param];
01803                 }
01804             }
01805             if (opacity > min_opacity) {
01806                 opacity_int = opacity*255.;
01807                 top_opc = opac_correct[opacity_int];
01808             } else {
01809                 top_opc = (float)0.;
01810             };
01811     
01812     
01813     shade_index=num_materials*1*ShortField(topRLEdata,norm_offset);
01814     weight_index = num_materials * ByteField(topRLEdata, wgt_offset);
01815     
01816         
01817         
01818     top_clr = 
01819     shade_table[shade_index + 1*0 + 0] * 
01820         ((num_materials > 1) ? weight_table[weight_index] : (float)1.0);
01821         
01822         top_sclr = 
01823     shadow_table[shade_index + 1*0 + 0] * 
01824         ((num_materials > 1) ? weight_table[weight_index] : (float)1.0);
01825         for (m = 1; m < num_materials; m++) {
01826              
01827         
01828     top_clr += 
01829     shade_table[shade_index + 1*m + 0] * 
01830         weight_table[weight_index + m];
01831         
01832         top_sclr += 
01833     shadow_table[shade_index + 1*m + 0] * 
01834         weight_table[weight_index + m];
01835         };
01836     shade_factor = top_opc * slice_depth_cueing;
01837     
01838         top_clr *= shade_factor;
01839     
01840             top_sclr *= shade_factor;
01841                     
01842        acc_opc += top_opc * wgtTR;
01843        acc_clr += (top_clr + top_sclr *
01844                             ((float)1.0 - shadow_pixel->opcflt)) * wgtTR;
01845        
01846 #ifdef DEBUG
01847     if (ipixel == trace_pixel_ptr) {
01848         trace_opcTR = top_opc;
01849         trace_rclrTR = top_clr;
01850         trace_rsclrTR = top_sclr;
01851     }
01852 #endif
01853 ;
01854                     
01855         COUNT_RESAMPLE;
01856         if (acc_opc > min_opacity) {
01857             COUNT_COMPOSITE;
01858             iopc = ipixel->opcflt;
01859 #           ifndef SKIP_ERT
01860                 ASSERT(iopc < max_opacity);
01861 #           endif
01862             iopc_inv = (float)1. - iopc;
01863             ipixel->clrflt += acc_clr * iopc_inv;
01864             iopc += acc_opc * iopc_inv;
01865             ipixel->opcflt = iopc;
01866             
01867 #ifdef DEBUG
01868     if (ipixel == trace_pixel_ptr) {
01869 #ifdef COMPUTE_SHADOW_BUFFER
01870         printf("{%3d}  %3d %3d", k, icount-i-count, j);
01871 #else
01872         printf("[%3d]  %3d %3d", k, icount-i-count, j);
01873 #endif
01874         printf("  %3.0f %3.0f %3.0f",trace_opcTL*255.,trace_rclrTL,wgtTL*100.);
01875         printf("  %3.0f %3.0f %3.0f",trace_opcBL*255.,trace_rclrBL,wgtBL*100.);
01876         printf("  %3.0f %3.0f %3.0f",trace_opcTR*255.,trace_rclrTR,wgtTR*100.);
01877         printf("  %3.0f %3.0f %3.0f",trace_opcBR*255.,trace_rclrBR,wgtBR*100.);
01878         printf("  %3.0f %3.0f\n", iopc*255., 
01879                ipixel->clrflt);
01880         
01881         printf("              ");
01882         printf("      %3.0f    ",trace_rsclrTL);
01883         printf("      %3.0f    ",trace_rsclrBL);
01884         printf("      %3.0f    ",trace_rsclrTR);
01885         printf("      %3.0f    ",trace_rsclrBR);
01886         printf("  %3.0f\n", shadow_pixel->opcflt * 255.);
01887         
01888     }
01889 #endif /* DEBUG */
01890 ;
01891 #           ifndef SKIP_ERT
01892                 if (iopc >= max_opacity) {
01893                     ASSERT(ipixel->lnk == 0);
01894                     ipixel->lnk = 1;
01895                 }
01896 #           endif
01897         };
01898                     ipixel += 1; shadow_pixel += 1;
01899                     topRLEdata += 1 * voxel_istride;
01900                     botRLEdata += 1 * voxel_istride;
01901                     count--;
01902                     SET_VOXELS_LOADED;
01903                 }
01904                 break;
01905             case BOT_NONZERO__TOP_NONZERO:
01906                 /* first pixel: bottom-left and top-right voxels
01907                    contribute */
01908                 if (!voxels_loaded) {
01909                     
01910     
01911             opac_param = VoxelField(botRLEdata - voxel_istride, param0_offset, param0_size);
01912             opacity = param0_table[opac_param];
01913             if (param1_size != 0) {
01914                 opac_param = VoxelField(botRLEdata - voxel_istride, param1_offset, param1_size);
01915                 opacity *= param1_table[opac_param];
01916                 if (param2_size != 0) {
01917                     opac_param = VoxelField(botRLEdata - voxel_istride, param2_offset, param2_size);
01918                     opacity *= param2_table[opac_param];
01919                 }
01920             }
01921             if (opacity > min_opacity) {
01922                 opacity_int = opacity*255.;
01923                 bot_opc = opac_correct[opacity_int];
01924             } else {
01925                 bot_opc = (float)0.;
01926             };
01927     
01928     
01929     shade_index=num_materials*1*ShortField(botRLEdata - voxel_istride,norm_offset);
01930     weight_index = num_materials * ByteField(botRLEdata - voxel_istride, wgt_offset);
01931     
01932         
01933         
01934     bot_clr = 
01935     shade_table[shade_index + 1*0 + 0] * 
01936         ((num_materials > 1) ? weight_table[weight_index] : (float)1.0);
01937         
01938         bot_sclr = 
01939     shadow_table[shade_index + 1*0 + 0] * 
01940         ((num_materials > 1) ? weight_table[weight_index] : (float)1.0);
01941         for (m = 1; m < num_materials; m++) {
01942              
01943         
01944     bot_clr += 
01945     shade_table[shade_index + 1*m + 0] * 
01946         weight_table[weight_index + m];
01947         
01948         bot_sclr += 
01949     shadow_table[shade_index + 1*m + 0] * 
01950         weight_table[weight_index + m];
01951         };
01952     shade_factor = bot_opc * slice_depth_cueing;
01953     
01954         bot_clr *= shade_factor;
01955     
01956             bot_sclr *= shade_factor;
01957                 }
01958                 
01959 #ifdef DEBUG
01960     if (ipixel == trace_pixel_ptr) {
01961         trace_opcTL = 0.; trace_opcBL = 0.; trace_opcTR = 0.; trace_opcBR = 0.;
01962         trace_rsclrTL=0.; trace_rsclrBL=0.; trace_rsclrTR=0.; trace_rsclrBR=0.;
01963         trace_rclrTL= 0.; trace_rclrBL= 0.; trace_rclrTR= 0.; trace_rclrBR= 0.;
01964         trace_gclrTL= 0.; trace_gclrBL= 0.; trace_gclrTR= 0.; trace_gclrBR= 0.;
01965         trace_bclrTL= 0.; trace_bclrBL= 0.; trace_bclrTR= 0.; trace_bclrBR= 0.;
01966     }
01967 #endif
01968 ;
01969                 
01970        acc_opc = bot_opc * wgtBL;
01971        acc_clr = (bot_clr + bot_sclr *
01972                             ((float)1.0 - shadow_pixel->opcflt)) * wgtBL;
01973        
01974 #ifdef DEBUG
01975     if (ipixel == trace_pixel_ptr) {
01976         trace_opcBL = bot_opc;
01977         trace_rclrBL = bot_clr;
01978         trace_rsclrBL = bot_sclr;
01979     }
01980 #endif
01981 ;
01982                 
01983     
01984             opac_param = VoxelField(topRLEdata, param0_offset, param0_size);
01985             opacity = param0_table[opac_param];
01986             if (param1_size != 0) {
01987                 opac_param = VoxelField(topRLEdata, param1_offset, param1_size);
01988                 opacity *= param1_table[opac_param];
01989                 if (param2_size != 0) {
01990                     opac_param = VoxelField(topRLEdata, param2_offset, param2_size);
01991                     opacity *= param2_table[opac_param];
01992                 }
01993             }
01994             if (opacity > min_opacity) {
01995                 opacity_int = opacity*255.;
01996                 top_opc = opac_correct[opacity_int];
01997             } else {
01998                 top_opc = (float)0.;
01999             };
02000     
02001     
02002     shade_index=num_materials*1*ShortField(topRLEdata,norm_offset);
02003     weight_index = num_materials * ByteField(topRLEdata, wgt_offset);
02004     
02005         
02006         
02007     top_clr = 
02008     shade_table[shade_index + 1*0 + 0] * 
02009         ((num_materials > 1) ? weight_table[weight_index] : (float)1.0);
02010         
02011         top_sclr = 
02012     shadow_table[shade_index + 1*0 + 0] * 
02013         ((num_materials > 1) ? weight_table[weight_index] : (float)1.0);
02014         for (m = 1; m < num_materials; m++) {
02015              
02016         
02017     top_clr += 
02018     shade_table[shade_index + 1*m + 0] * 
02019         weight_table[weight_index + m];
02020         
02021         top_sclr += 
02022     shadow_table[shade_index + 1*m + 0] * 
02023         weight_table[weight_index + m];
02024         };
02025     shade_factor = top_opc * slice_depth_cueing;
02026     
02027         top_clr *= shade_factor;
02028     
02029             top_sclr *= shade_factor;
02030                 
02031        acc_opc += top_opc * wgtTR;
02032        acc_clr += (top_clr + top_sclr *
02033                             ((float)1.0 - shadow_pixel->opcflt)) * wgtTR;
02034        
02035 #ifdef DEBUG
02036     if (ipixel == trace_pixel_ptr) {
02037         trace_opcTR = top_opc;
02038         trace_rclrTR = top_clr;
02039         trace_rsclrTR = top_sclr;
02040     }
02041 #endif
02042 ;
02043                 
02044         COUNT_RESAMPLE;
02045         if (acc_opc > min_opacity) {
02046             COUNT_COMPOSITE;
02047             iopc = ipixel->opcflt;
02048 #           ifndef SKIP_ERT
02049                 ASSERT(iopc < max_opacity);
02050 #           endif
02051             iopc_inv = (float)1. - iopc;
02052             ipixel->clrflt += acc_clr * iopc_inv;
02053             iopc += acc_opc * iopc_inv;
02054             ipixel->opcflt = iopc;
02055             
02056 #ifdef DEBUG
02057     if (ipixel == trace_pixel_ptr) {
02058 #ifdef COMPUTE_SHADOW_BUFFER
02059         printf("{%3d}  %3d %3d", k, icount-i-count, j);
02060 #else
02061         printf("[%3d]  %3d %3d", k, icount-i-count, j);
02062 #endif
02063         printf("  %3.0f %3.0f %3.0f",trace_opcTL*255.,trace_rclrTL,wgtTL*100.);
02064         printf("  %3.0f %3.0f %3.0f",trace_opcBL*255.,trace_rclrBL,wgtBL*100.);
02065         printf("  %3.0f %3.0f %3.0f",trace_opcTR*255.,trace_rclrTR,wgtTR*100.);
02066         printf("  %3.0f %3.0f %3.0f",trace_opcBR*255.,trace_rclrBR,wgtBR*100.);
02067         printf("  %3.0f %3.0f\n", iopc*255., 
02068                ipixel->clrflt);
02069         
02070         printf("              ");
02071         printf("      %3.0f    ",trace_rsclrTL);
02072         printf("      %3.0f    ",trace_rsclrBL);
02073         printf("      %3.0f    ",trace_rsclrTR);
02074         printf("      %3.0f    ",trace_rsclrBR);
02075         printf("  %3.0f\n", shadow_pixel->opcflt * 255.);
02076         
02077     }
02078 #endif /* DEBUG */
02079 ;
02080 #           ifndef SKIP_ERT
02081                 if (iopc >= max_opacity) {
02082                     ASSERT(ipixel->lnk == 0);
02083                     ipixel->lnk = 1;
02084                 }
02085 #           endif
02086         };
02087                 ipixel += 1; shadow_pixel += 1;
02088                 topRLEdata += 1 * voxel_istride;
02089                 botRLEdata += 1 * voxel_istride;
02090                 count--;
02091                 SET_VOXELS_LOADED;
02092 
02093                 /* do the rest of the pixels in this run;
02094                    the top-left and top-right voxels contribute */
02095                 while (count > 0) {
02096                     if (PIXEL_IS_OPAQUE(ipixel))
02097                         break;
02098                     if (!voxels_loaded) {
02099                         
02100     
02101             opac_param = VoxelField(topRLEdata - voxel_istride, param0_offset, param0_size);
02102             opacity = param0_table[opac_param];
02103             if (param1_size != 0) {
02104                 opac_param = VoxelField(topRLEdata - voxel_istride, param1_offset, param1_size);
02105                 opacity *= param1_table[opac_param];
02106                 if (param2_size != 0) {
02107                     opac_param = VoxelField(topRLEdata - voxel_istride, param2_offset, param2_size);
02108                     opacity *= param2_table[opac_param];
02109                 }
02110             }
02111             if (opacity > min_opacity) {
02112                 opacity_int = opacity*255.;
02113                 top_opc = opac_correct[opacity_int];
02114             } else {
02115                 top_opc = (float)0.;
02116             };
02117     
02118     
02119     shade_index=num_materials*1*ShortField(topRLEdata - voxel_istride,norm_offset);
02120     weight_index = num_materials * ByteField(topRLEdata - voxel_istride, wgt_offset);
02121     
02122         
02123         
02124     top_clr = 
02125     shade_table[shade_index + 1*0 + 0] * 
02126         ((num_materials > 1) ? weight_table[weight_index] : (float)1.0);
02127         
02128         top_sclr = 
02129     shadow_table[shade_index + 1*0 + 0] * 
02130         ((num_materials > 1) ? weight_table[weight_index] : (float)1.0);
02131         for (m = 1; m < num_materials; m++) {
02132              
02133         
02134     top_clr += 
02135     shade_table[shade_index + 1*m + 0] * 
02136         weight_table[weight_index + m];
02137         
02138         top_sclr += 
02139     shadow_table[shade_index + 1*m + 0] * 
02140         weight_table[weight_index + m];
02141         };
02142     shade_factor = top_opc * slice_depth_cueing;
02143     
02144         top_clr *= shade_factor;
02145     
02146             top_sclr *= shade_factor;
02147                     }
02148                     
02149 #ifdef DEBUG
02150     if (ipixel == trace_pixel_ptr) {
02151         trace_opcTL = 0.; trace_opcBL = 0.; trace_opcTR = 0.; trace_opcBR = 0.;
02152         trace_rsclrTL=0.; trace_rsclrBL=0.; trace_rsclrTR=0.; trace_rsclrBR=0.;
02153         trace_rclrTL= 0.; trace_rclrBL= 0.; trace_rclrTR= 0.; trace_rclrBR= 0.;
02154         trace_gclrTL= 0.; trace_gclrBL= 0.; trace_gclrTR= 0.; trace_gclrBR= 0.;
02155         trace_bclrTL= 0.; trace_bclrBL= 0.; trace_bclrTR= 0.; trace_bclrBR= 0.;
02156     }
02157 #endif
02158 ;
02159                     
02160        acc_opc = top_opc * wgtTL;
02161        acc_clr = (top_clr + top_sclr *
02162                             ((float)1.0 - shadow_pixel->opcflt)) * wgtTL;
02163        
02164 #ifdef DEBUG
02165     if (ipixel == trace_pixel_ptr) {
02166         trace_opcTL = top_opc;
02167         trace_rclrTL = top_clr;
02168         trace_rsclrTL = top_sclr;
02169     }
02170 #endif
02171 ;
02172                     
02173     
02174             opac_param = VoxelField(topRLEdata, param0_offset, param0_size);
02175             opacity = param0_table[opac_param];
02176             if (param1_size != 0) {
02177                 opac_param = VoxelField(topRLEdata, param1_offset, param1_size);
02178                 opacity *= param1_table[opac_param];
02179                 if (param2_size != 0) {
02180                     opac_param = VoxelField(topRLEdata, param2_offset, param2_size);
02181                     opacity *= param2_table[opac_param];
02182                 }
02183             }
02184             if (opacity > min_opacity) {
02185                 opacity_int = opacity*255.;
02186                 top_opc = opac_correct[opacity_int];
02187             } else {
02188                 top_opc = (float)0.;
02189             };
02190     
02191     
02192     shade_index=num_materials*1*ShortField(topRLEdata,norm_offset);
02193     weight_index = num_materials * ByteField(topRLEdata, wgt_offset);
02194     
02195         
02196         
02197     top_clr = 
02198     shade_table[shade_index + 1*0 + 0] * 
02199         ((num_materials > 1) ? weight_table[weight_index] : (float)1.0);
02200         
02201         top_sclr = 
02202     shadow_table[shade_index + 1*0 + 0] * 
02203         ((num_materials > 1) ? weight_table[weight_index] : (float)1.0);
02204         for (m = 1; m < num_materials; m++) {
02205              
02206         
02207     top_clr += 
02208     shade_table[shade_index + 1*m + 0] * 
02209         weight_table[weight_index + m];
02210         
02211         top_sclr += 
02212     shadow_table[shade_index + 1*m + 0] * 
02213         weight_table[weight_index + m];
02214         };
02215     shade_factor = top_opc * slice_depth_cueing;
02216     
02217         top_clr *= shade_factor;
02218     
02219             top_sclr *= shade_factor;
02220                     
02221        acc_opc += top_opc * wgtTR;
02222        acc_clr += (top_clr + top_sclr *
02223                             ((float)1.0 - shadow_pixel->opcflt)) * wgtTR;
02224        
02225 #ifdef DEBUG
02226     if (ipixel == trace_pixel_ptr) {
02227         trace_opcTR = top_opc;
02228         trace_rclrTR = top_clr;
02229         trace_rsclrTR = top_sclr;
02230     }
02231 #endif
02232 ;
02233                     
02234         COUNT_RESAMPLE;
02235         if (acc_opc > min_opacity) {
02236             COUNT_COMPOSITE;
02237             iopc = ipixel->opcflt;
02238 #           ifndef SKIP_ERT
02239                 ASSERT(iopc < max_opacity);
02240 #           endif
02241             iopc_inv = (float)1. - iopc;
02242             ipixel->clrflt += acc_clr * iopc_inv;
02243             iopc += acc_opc * iopc_inv;
02244             ipixel->opcflt = iopc;
02245             
02246 #ifdef DEBUG
02247     if (ipixel == trace_pixel_ptr) {
02248 #ifdef COMPUTE_SHADOW_BUFFER
02249         printf("{%3d}  %3d %3d", k, icount-i-count, j);
02250 #else
02251         printf("[%3d]  %3d %3d", k, icount-i-count, j);
02252 #endif
02253         printf("  %3.0f %3.0f %3.0f",trace_opcTL*255.,trace_rclrTL,wgtTL*100.);
02254         printf("  %3.0f %3.0f %3.0f",trace_opcBL*255.,trace_rclrBL,wgtBL*100.);
02255         printf("  %3.0f %3.0f %3.0f",trace_opcTR*255.,trace_rclrTR,wgtTR*100.);
02256         printf("  %3.0f %3.0f %3.0f",trace_opcBR*255.,trace_rclrBR,wgtBR*100.);
02257         printf("  %3.0f %3.0f\n", iopc*255., 
02258                ipixel->clrflt);
02259         
02260         printf("              ");
02261         printf("      %3.0f    ",trace_rsclrTL);
02262         printf("      %3.0f    ",trace_rsclrBL);
02263         printf("      %3.0f    ",trace_rsclrTR);
02264         printf("      %3.0f    ",trace_rsclrBR);
02265         printf("  %3.0f\n", shadow_pixel->opcflt * 255.);
02266         
02267     }
02268 #endif /* DEBUG */
02269 ;
02270 #           ifndef SKIP_ERT
02271                 if (iopc >= max_opacity) {
02272                     ASSERT(ipixel->lnk == 0);
02273                     ipixel->lnk = 1;
02274                 }
02275 #           endif
02276         };
02277                     ipixel += 1; shadow_pixel += 1;
02278                     topRLEdata += 1 * voxel_istride;
02279                     botRLEdata += 1 * voxel_istride;
02280                     count--;
02281                     SET_VOXELS_LOADED;
02282                 }
02283                 break;
02284             case ALL_NONZERO__TOP_NONZERO:
02285                 /* first pixel: top-left, bottom-left and top-right voxels
02286                    contribute */
02287                 if (!voxels_loaded) {
02288                     
02289     
02290             opac_param = VoxelField(topRLEdata - voxel_istride, param0_offset, param0_size);
02291             opacity = param0_table[opac_param];
02292             if (param1_size != 0) {
02293                 opac_param = VoxelField(topRLEdata - voxel_istride, param1_offset, param1_size);
02294                 opacity *= param1_table[opac_param];
02295                 if (param2_size != 0) {
02296                     opac_param = VoxelField(topRLEdata - voxel_istride, param2_offset, param2_size);
02297                     opacity *= param2_table[opac_param];
02298                 }
02299             }
02300             if (opacity > min_opacity) {
02301                 opacity_int = opacity*255.;
02302                 top_opc = opac_correct[opacity_int];
02303             } else {
02304                 top_opc = (float)0.;
02305             };
02306     
02307     
02308     shade_index=num_materials*1*ShortField(topRLEdata - voxel_istride,norm_offset);
02309     weight_index = num_materials * ByteField(topRLEdata - voxel_istride, wgt_offset);
02310     
02311         
02312         
02313     top_clr = 
02314     shade_table[shade_index + 1*0 + 0] * 
02315         ((num_materials > 1) ? weight_table[weight_index] : (float)1.0);
02316         
02317         top_sclr = 
02318     shadow_table[shade_index + 1*0 + 0] * 
02319         ((num_materials > 1) ? weight_table[weight_index] : (float)1.0);
02320         for (m = 1; m < num_materials; m++) {
02321              
02322         
02323     top_clr += 
02324     shade_table[shade_index + 1*m + 0] * 
02325         weight_table[weight_index + m];
02326         
02327         top_sclr += 
02328     shadow_table[shade_index + 1*m + 0] * 
02329         weight_table[weight_index + m];
02330         };
02331     shade_factor = top_opc * slice_depth_cueing;
02332     
02333         top_clr *= shade_factor;
02334     
02335             top_sclr *= shade_factor;
02336                     
02337     
02338             opac_param = VoxelField(botRLEdata - voxel_istride, param0_offset, param0_size);
02339             opacity = param0_table[opac_param];
02340             if (param1_size != 0) {
02341                 opac_param = VoxelField(botRLEdata - voxel_istride, param1_offset, param1_size);
02342                 opacity *= param1_table[opac_param];
02343                 if (param2_size != 0) {
02344                     opac_param = VoxelField(botRLEdata - voxel_istride, param2_offset, param2_size);
02345                     opacity *= param2_table[opac_param];
02346                 }
02347             }
02348             if (opacity > min_opacity) {
02349                 opacity_int = opacity*255.;
02350                 bot_opc = opac_correct[opacity_int];
02351             } else {
02352                 bot_opc = (float)0.;
02353             };
02354     
02355     
02356     shade_index=num_materials*1*ShortField(botRLEdata - voxel_istride,norm_offset);
02357     weight_index = num_materials * ByteField(botRLEdata - voxel_istride, wgt_offset);
02358     
02359         
02360         
02361     bot_clr = 
02362     shade_table[shade_index + 1*0 + 0] * 
02363         ((num_materials > 1) ? weight_table[weight_index] : (float)1.0);
02364         
02365         bot_sclr = 
02366     shadow_table[shade_index + 1*0 + 0] * 
02367         ((num_materials > 1) ? weight_table[weight_index] : (float)1.0);
02368         for (m = 1; m < num_materials; m++) {
02369              
02370         
02371     bot_clr += 
02372     shade_table[shade_index + 1*m + 0] * 
02373         weight_table[weight_index + m];
02374         
02375         bot_sclr += 
02376     shadow_table[shade_index + 1*m + 0] * 
02377         weight_table[weight_index + m];
02378         };
02379     shade_factor = bot_opc * slice_depth_cueing;
02380     
02381         bot_clr *= shade_factor;
02382     
02383             bot_sclr *= shade_factor;
02384                 }
02385                 
02386 #ifdef DEBUG
02387     if (ipixel == trace_pixel_ptr) {
02388         trace_opcTL = 0.; trace_opcBL = 0.; trace_opcTR = 0.; trace_opcBR = 0.;
02389         trace_rsclrTL=0.; trace_rsclrBL=0.; trace_rsclrTR=0.; trace_rsclrBR=0.;
02390         trace_rclrTL= 0.; trace_rclrBL= 0.; trace_rclrTR= 0.; trace_rclrBR= 0.;
02391         trace_gclrTL= 0.; trace_gclrBL= 0.; trace_gclrTR= 0.; trace_gclrBR= 0.;
02392         trace_bclrTL= 0.; trace_bclrBL= 0.; trace_bclrTR= 0.; trace_bclrBR= 0.;
02393     }
02394 #endif
02395 ;
02396                 
02397        acc_opc = top_opc * wgtTL;
02398        acc_clr = (top_clr + top_sclr *
02399                             ((float)1.0 - shadow_pixel->opcflt)) * wgtTL;
02400        
02401 #ifdef DEBUG
02402     if (ipixel == trace_pixel_ptr) {
02403         trace_opcTL = top_opc;
02404         trace_rclrTL = top_clr;
02405         trace_rsclrTL = top_sclr;
02406     }
02407 #endif
02408 ;
02409                 
02410        acc_opc += bot_opc * wgtBL;
02411        acc_clr += (bot_clr + bot_sclr *
02412                             ((float)1.0 - shadow_pixel->opcflt)) * wgtBL;
02413        
02414 #ifdef DEBUG
02415     if (ipixel == trace_pixel_ptr) {
02416         trace_opcBL = bot_opc;
02417         trace_rclrBL = bot_clr;
02418         trace_rsclrBL = bot_sclr;
02419     }
02420 #endif
02421 ;
02422                 
02423     
02424             opac_param = VoxelField(topRLEdata, param0_offset, param0_size);
02425             opacity = param0_table[opac_param];
02426             if (param1_size != 0) {
02427                 opac_param = VoxelField(topRLEdata, param1_offset, param1_size);
02428                 opacity *= param1_table[opac_param];
02429                 if (param2_size != 0) {
02430                     opac_param = VoxelField(topRLEdata, param2_offset, param2_size);
02431                     opacity *= param2_table[opac_param];
02432                 }
02433             }
02434             if (opacity > min_opacity) {
02435                 opacity_int = opacity*255.;
02436                 top_opc = opac_correct[opacity_int];
02437             } else {
02438                 top_opc = (float)0.;
02439             };
02440     
02441     
02442     shade_index=num_materials*1*ShortField(topRLEdata,norm_offset);
02443     weight_index = num_materials * ByteField(topRLEdata, wgt_offset);
02444     
02445         
02446         
02447     top_clr = 
02448     shade_table[shade_index + 1*0 + 0] * 
02449         ((num_materials > 1) ? weight_table[weight_index] : (float)1.0);
02450         
02451         top_sclr = 
02452     shadow_table[shade_index + 1*0 + 0] * 
02453         ((num_materials > 1) ? weight_table[weight_index] : (float)1.0);
02454         for (m = 1; m < num_materials; m++) {
02455              
02456         
02457     top_clr += 
02458     shade_table[shade_index + 1*m + 0] * 
02459         weight_table[weight_index + m];
02460         
02461         top_sclr += 
02462     shadow_table[shade_index + 1*m + 0] * 
02463         weight_table[weight_index + m];
02464         };
02465     shade_factor = top_opc * slice_depth_cueing;
02466     
02467         top_clr *= shade_factor;
02468     
02469             top_sclr *= shade_factor;
02470                 
02471        acc_opc += top_opc * wgtTR;
02472        acc_clr += (top_clr + top_sclr *
02473                             ((float)1.0 - shadow_pixel->opcflt)) * wgtTR;
02474        
02475 #ifdef DEBUG
02476     if (ipixel == trace_pixel_ptr) {
02477         trace_opcTR = top_opc;
02478         trace_rclrTR = top_clr;
02479         trace_rsclrTR = top_sclr;
02480     }
02481 #endif
02482 ;
02483                 
02484         COUNT_RESAMPLE;
02485         if (acc_opc > min_opacity) {
02486             COUNT_COMPOSITE;
02487             iopc = ipixel->opcflt;
02488 #           ifndef SKIP_ERT
02489                 ASSERT(iopc < max_opacity);
02490 #           endif
02491             iopc_inv = (float)1. - iopc;
02492             ipixel->clrflt += acc_clr * iopc_inv;
02493             iopc += acc_opc * iopc_inv;
02494             ipixel->opcflt = iopc;
02495             
02496 #ifdef DEBUG
02497     if (ipixel == trace_pixel_ptr) {
02498 #ifdef COMPUTE_SHADOW_BUFFER
02499         printf("{%3d}  %3d %3d", k, icount-i-count, j);
02500 #else
02501         printf("[%3d]  %3d %3d", k, icount-i-count, j);
02502 #endif
02503         printf("  %3.0f %3.0f %3.0f",trace_opcTL*255.,trace_rclrTL,wgtTL*100.);
02504         printf("  %3.0f %3.0f %3.0f",trace_opcBL*255.,trace_rclrBL,wgtBL*100.);
02505         printf("  %3.0f %3.0f %3.0f",trace_opcTR*255.,trace_rclrTR,wgtTR*100.);
02506         printf("  %3.0f %3.0f %3.0f",trace_opcBR*255.,trace_rclrBR,wgtBR*100.);
02507         printf("  %3.0f %3.0f\n", iopc*255., 
02508                ipixel->clrflt);
02509         
02510         printf("              ");
02511         printf("      %3.0f    ",trace_rsclrTL);
02512         printf("      %3.0f    ",trace_rsclrBL);
02513         printf("      %3.0f    ",trace_rsclrTR);
02514         printf("      %3.0f    ",trace_rsclrBR);
02515         printf("  %3.0f\n", shadow_pixel->opcflt * 255.);
02516         
02517     }
02518 #endif /* DEBUG */
02519 ;
02520 #           ifndef SKIP_ERT
02521                 if (iopc >= max_opacity) {
02522                     ASSERT(ipixel->lnk == 0);
02523                     ipixel->lnk = 1;
02524                 }
02525 #           endif
02526         };
02527                 ipixel += 1; shadow_pixel += 1;
02528                 topRLEdata += 1 * voxel_istride;
02529                 botRLEdata += 1 * voxel_istride;
02530                 count--;
02531                 SET_VOXELS_LOADED;
02532 
02533                 /* do the rest of the pixels in this run;
02534                    the top-left and top-right voxels contribute */
02535                 while (count > 0) {
02536                     if (PIXEL_IS_OPAQUE(ipixel))
02537                         break;
02538                     if (!voxels_loaded) {
02539                         
02540     
02541             opac_param = VoxelField(topRLEdata - voxel_istride, param0_offset, param0_size);
02542             opacity = param0_table[opac_param];
02543             if (param1_size != 0) {
02544                 opac_param = VoxelField(topRLEdata - voxel_istride, param1_offset, param1_size);
02545                 opacity *= param1_table[opac_param];
02546                 if (param2_size != 0) {
02547                     opac_param = VoxelField(topRLEdata - voxel_istride, param2_offset, param2_size);
02548                     opacity *= param2_table[opac_param];
02549                 }
02550             }
02551             if (opacity > min_opacity) {
02552                 opacity_int = opacity*255.;
02553                 top_opc = opac_correct[opacity_int];
02554             } else {
02555                 top_opc = (float)0.;
02556             };
02557     
02558     
02559     shade_index=num_materials*1*ShortField(topRLEdata - voxel_istride,norm_offset);
02560     weight_index = num_materials * ByteField(topRLEdata - voxel_istride, wgt_offset);
02561     
02562         
02563         
02564     top_clr = 
02565     shade_table[shade_index + 1*0 + 0] * 
02566         ((num_materials > 1) ? weight_table[weight_index] : (float)1.0);
02567         
02568         top_sclr = 
02569     shadow_table[shade_index + 1*0 + 0] * 
02570         ((num_materials > 1) ? weight_table[weight_index] : (float)1.0);
02571         for (m = 1; m < num_materials; m++) {
02572              
02573         
02574     top_clr += 
02575     shade_table[shade_index + 1*m + 0] * 
02576         weight_table[weight_index + m];
02577         
02578         top_sclr += 
02579     shadow_table[shade_index + 1*m + 0] * 
02580         weight_table[weight_index + m];
02581         };
02582     shade_factor = top_opc * slice_depth_cueing;
02583     
02584         top_clr *= shade_factor;
02585     
02586             top_sclr *= shade_factor;
02587                     }
02588                     
02589 #ifdef DEBUG
02590     if (ipixel == trace_pixel_ptr) {
02591         trace_opcTL = 0.; trace_opcBL = 0.; trace_opcTR = 0.; trace_opcBR = 0.;
02592         trace_rsclrTL=0.; trace_rsclrBL=0.; trace_rsclrTR=0.; trace_rsclrBR=0.;
02593         trace_rclrTL= 0.; trace_rclrBL= 0.; trace_rclrTR= 0.; trace_rclrBR= 0.;
02594         trace_gclrTL= 0.; trace_gclrBL= 0.; trace_gclrTR= 0.; trace_gclrBR= 0.;
02595         trace_bclrTL= 0.; trace_bclrBL= 0.; trace_bclrTR= 0.; trace_bclrBR= 0.;
02596     }
02597 #endif
02598 ;
02599                     
02600        acc_opc = top_opc * wgtTL;
02601        acc_clr = (top_clr + top_sclr *
02602                             ((float)1.0 - shadow_pixel->opcflt)) * wgtTL;
02603        
02604 #ifdef DEBUG
02605     if (ipixel == trace_pixel_ptr) {
02606         trace_opcTL = top_opc;
02607         trace_rclrTL = top_clr;
02608         trace_rsclrTL = top_sclr;
02609     }
02610 #endif
02611 ;
02612                     
02613     
02614             opac_param = VoxelField(topRLEdata, param0_offset, param0_size);
02615             opacity = param0_table[opac_param];
02616             if (param1_size != 0) {
02617                 opac_param = VoxelField(topRLEdata, param1_offset, param1_size);
02618                 opacity *= param1_table[opac_param];
02619                 if (param2_size != 0) {
02620                     opac_param = VoxelField(topRLEdata, param2_offset, param2_size);
02621                     opacity *= param2_table[opac_param];
02622                 }
02623             }
02624             if (opacity > min_opacity) {
02625                 opacity_int = opacity*255.;
02626                 top_opc = opac_correct[opacity_int];
02627             } else {
02628                 top_opc = (float)0.;
02629             };
02630     
02631     
02632     shade_index=num_materials*1*ShortField(topRLEdata,norm_offset);
02633     weight_index = num_materials * ByteField(topRLEdata, wgt_offset);
02634     
02635         
02636         
02637     top_clr = 
02638     shade_table[shade_index + 1*0 + 0] * 
02639         ((num_materials > 1) ? weight_table[weight_index] : (float)1.0);
02640         
02641         top_sclr = 
02642     shadow_table[shade_index + 1*0 + 0] * 
02643         ((num_materials > 1) ? weight_table[weight_index] : (float)1.0);
02644         for (m = 1; m < num_materials; m++) {
02645              
02646         
02647     top_clr += 
02648     shade_table[shade_index + 1*m + 0] * 
02649         weight_table[weight_index + m];
02650         
02651         top_sclr += 
02652     shadow_table[shade_index + 1*m + 0] * 
02653         weight_table[weight_index + m];
02654         };
02655     shade_factor = top_opc * slice_depth_cueing;
02656     
02657         top_clr *= shade_factor;
02658     
02659             top_sclr *= shade_factor;
02660                     
02661        acc_opc += top_opc * wgtTR;
02662        acc_clr += (top_clr + top_sclr *
02663                             ((float)1.0 - shadow_pixel->opcflt)) * wgtTR;
02664        
02665 #ifdef DEBUG
02666     if (ipixel == trace_pixel_ptr) {
02667         trace_opcTR = top_opc;
02668         trace_rclrTR = top_clr;
02669         trace_rsclrTR = top_sclr;
02670     }
02671 #endif
02672 ;
02673                     
02674         COUNT_RESAMPLE;
02675         if (acc_opc > min_opacity) {
02676             COUNT_COMPOSITE;
02677             iopc = ipixel->opcflt;
02678 #           ifndef SKIP_ERT
02679                 ASSERT(iopc < max_opacity);
02680 #           endif
02681             iopc_inv = (float)1. - iopc;
02682             ipixel->clrflt += acc_clr * iopc_inv;
02683             iopc += acc_opc * iopc_inv;
02684             ipixel->opcflt = iopc;
02685             
02686 #ifdef DEBUG
02687     if (ipixel == trace_pixel_ptr) {
02688 #ifdef COMPUTE_SHADOW_BUFFER
02689         printf("{%3d}  %3d %3d", k, icount-i-count, j);
02690 #else
02691         printf("[%3d]  %3d %3d", k, icount-i-count, j);
02692 #endif
02693         printf("  %3.0f %3.0f %3.0f",trace_opcTL*255.,trace_rclrTL,wgtTL*100.);
02694         printf("  %3.0f %3.0f %3.0f",trace_opcBL*255.,trace_rclrBL,wgtBL*100.);
02695         printf("  %3.0f %3.0f %3.0f",trace_opcTR*255.,trace_rclrTR,wgtTR*100.);
02696         printf("  %3.0f %3.0f %3.0f",trace_opcBR*255.,trace_rclrBR,wgtBR*100.);
02697         printf("  %3.0f %3.0f\n", iopc*255., 
02698                ipixel->clrflt);
02699         
02700         printf("              ");
02701         printf("      %3.0f    ",trace_rsclrTL);
02702         printf("      %3.0f    ",trace_rsclrBL);
02703         printf("      %3.0f    ",trace_rsclrTR);
02704         printf("      %3.0f    ",trace_rsclrBR);
02705         printf("  %3.0f\n", shadow_pixel->opcflt * 255.);
02706         
02707     }
02708 #endif /* DEBUG */
02709 ;
02710 #           ifndef SKIP_ERT
02711                 if (iopc >= max_opacity) {
02712                     ASSERT(ipixel->lnk == 0);
02713                     ipixel->lnk = 1;
02714                 }
02715 #           endif
02716         };
02717                     ipixel += 1; shadow_pixel += 1;
02718                     topRLEdata += 1 * voxel_istride;
02719                     botRLEdata += 1 * voxel_istride;
02720                     count--;
02721                     SET_VOXELS_LOADED;
02722                 }
02723                 break;
02724             case ALL_ZERO__BOT_NONZERO:
02725                 /* first pixel: only the bottom-right voxel contributes */
02726                 
02727     
02728             opac_param = VoxelField(botRLEdata, param0_offset, param0_size);
02729             opacity = param0_table[opac_param];
02730             if (param1_size != 0) {
02731                 opac_param = VoxelField(botRLEdata, param1_offset, param1_size);
02732                 opacity *= param1_table[opac_param];
02733                 if (param2_size != 0) {
02734                     opac_param = VoxelField(botRLEdata, param2_offset, param2_size);
02735                     opacity *= param2_table[opac_param];
02736                 }
02737             }
02738             if (opacity > min_opacity) {
02739                 opacity_int = opacity*255.;
02740                 bot_opc = opac_correct[opacity_int];
02741             } else {
02742                 bot_opc = (float)0.;
02743             };
02744     
02745     
02746     shade_index=num_materials*1*ShortField(botRLEdata,norm_offset);
02747     weight_index = num_materials * ByteField(botRLEdata, wgt_offset);
02748     
02749         
02750         
02751     bot_clr = 
02752     shade_table[shade_index + 1*0 + 0] * 
02753         ((num_materials > 1) ? weight_table[weight_index] : (float)1.0);
02754         
02755         bot_sclr = 
02756     shadow_table[shade_index + 1*0 + 0] * 
02757         ((num_materials > 1) ? weight_table[weight_index] : (float)1.0);
02758         for (m = 1; m < num_materials; m++) {
02759              
02760         
02761     bot_clr += 
02762     shade_table[shade_index + 1*m + 0] * 
02763         weight_table[weight_index + m];
02764         
02765         bot_sclr += 
02766     shadow_table[shade_index + 1*m + 0] * 
02767         weight_table[weight_index + m];
02768         };
02769     shade_factor = bot_opc * slice_depth_cueing;
02770     
02771         bot_clr *= shade_factor;
02772     
02773             bot_sclr *= shade_factor;
02774                 
02775 #ifdef DEBUG
02776     if (ipixel == trace_pixel_ptr) {
02777         trace_opcTL = 0.; trace_opcBL = 0.; trace_opcTR = 0.; trace_opcBR = 0.;
02778         trace_rsclrTL=0.; trace_rsclrBL=0.; trace_rsclrTR=0.; trace_rsclrBR=0.;
02779         trace_rclrTL= 0.; trace_rclrBL= 0.; trace_rclrTR= 0.; trace_rclrBR= 0.;
02780         trace_gclrTL= 0.; trace_gclrBL= 0.; trace_gclrTR= 0.; trace_gclrBR= 0.;
02781         trace_bclrTL= 0.; trace_bclrBL= 0.; trace_bclrTR= 0.; trace_bclrBR= 0.;
02782     }
02783 #endif
02784 ;
02785                 
02786        acc_opc = bot_opc * wgtBR;
02787        acc_clr = (bot_clr + bot_sclr *
02788                             ((float)1.0 - shadow_pixel->opcflt)) * wgtBR;
02789        
02790 #ifdef DEBUG
02791     if (ipixel == trace_pixel_ptr) {
02792         trace_opcBR = bot_opc;
02793         trace_rclrBR = bot_clr;
02794         trace_rsclrBR = bot_sclr;
02795     }
02796 #endif
02797 ;
02798                 
02799         COUNT_RESAMPLE;
02800         if (acc_opc > min_opacity) {
02801             COUNT_COMPOSITE;
02802             iopc = ipixel->opcflt;
02803 #           ifndef SKIP_ERT
02804                 ASSERT(iopc < max_opacity);
02805 #           endif
02806             iopc_inv = (float)1. - iopc;
02807             ipixel->clrflt += acc_clr * iopc_inv;
02808             iopc += acc_opc * iopc_inv;
02809             ipixel->opcflt = iopc;
02810             
02811 #ifdef DEBUG
02812     if (ipixel == trace_pixel_ptr) {
02813 #ifdef COMPUTE_SHADOW_BUFFER
02814         printf("{%3d}  %3d %3d", k, icount-i-count, j);
02815 #else
02816         printf("[%3d]  %3d %3d", k, icount-i-count, j);
02817 #endif
02818         printf("  %3.0f %3.0f %3.0f",trace_opcTL*255.,trace_rclrTL,wgtTL*100.);
02819         printf("  %3.0f %3.0f %3.0f",trace_opcBL*255.,trace_rclrBL,wgtBL*100.);
02820         printf("  %3.0f %3.0f %3.0f",trace_opcTR*255.,trace_rclrTR,wgtTR*100.);
02821         printf("  %3.0f %3.0f %3.0f",trace_opcBR*255.,trace_rclrBR,wgtBR*100.);
02822         printf("  %3.0f %3.0f\n", iopc*255., 
02823                ipixel->clrflt);
02824         
02825         printf("              ");
02826         printf("      %3.0f    ",trace_rsclrTL);
02827         printf("      %3.0f    ",trace_rsclrBL);
02828         printf("      %3.0f    ",trace_rsclrTR);
02829         printf("      %3.0f    ",trace_rsclrBR);
02830         printf("  %3.0f\n", shadow_pixel->opcflt * 255.);
02831         
02832     }
02833 #endif /* DEBUG */
02834 ;
02835 #           ifndef SKIP_ERT
02836                 if (iopc >= max_opacity) {
02837                     ASSERT(ipixel->lnk == 0);
02838                     ipixel->lnk = 1;
02839                 }
02840 #           endif
02841         };      
02842                 ipixel += 1; shadow_pixel += 1;
02843                 topRLEdata += 1 * voxel_istride;
02844                 botRLEdata += 1 * voxel_istride;
02845                 count--;
02846                 SET_VOXELS_LOADED;
02847 
02848                 /* do the rest of the pixels in this run;
02849                    bottom-left and bottom-right voxels contribute */
02850                 while (count > 0) {
02851                     if (PIXEL_IS_OPAQUE(ipixel))
02852                         break;
02853                     if (!voxels_loaded) {
02854                         
02855     
02856             opac_param = VoxelField(botRLEdata - voxel_istride, param0_offset, param0_size);
02857             opacity = param0_table[opac_param];
02858             if (param1_size != 0) {
02859                 opac_param = VoxelField(botRLEdata - voxel_istride, param1_offset, param1_size);
02860                 opacity *= param1_table[opac_param];
02861                 if (param2_size != 0) {
02862                     opac_param = VoxelField(botRLEdata - voxel_istride, param2_offset, param2_size);
02863                     opacity *= param2_table[opac_param];
02864                 }
02865             }
02866             if (opacity > min_opacity) {
02867                 opacity_int = opacity*255.;
02868                 bot_opc = opac_correct[opacity_int];
02869             } else {
02870                 bot_opc = (float)0.;
02871             };
02872     
02873     
02874     shade_index=num_materials*1*ShortField(botRLEdata - voxel_istride,norm_offset);
02875     weight_index = num_materials * ByteField(botRLEdata - voxel_istride, wgt_offset);
02876     
02877         
02878         
02879     bot_clr = 
02880     shade_table[shade_index + 1*0 + 0] * 
02881         ((num_materials > 1) ? weight_table[weight_index] : (float)1.0);
02882         
02883         bot_sclr = 
02884     shadow_table[shade_index + 1*0 + 0] * 
02885         ((num_materials > 1) ? weight_table[weight_index] : (float)1.0);
02886         for (m = 1; m < num_materials; m++) {
02887              
02888         
02889     bot_clr += 
02890     shade_table[shade_index + 1*m + 0] * 
02891         weight_table[weight_index + m];
02892         
02893         bot_sclr += 
02894     shadow_table[shade_index + 1*m + 0] * 
02895         weight_table[weight_index + m];
02896         };
02897     shade_factor = bot_opc * slice_depth_cueing;
02898     
02899         bot_clr *= shade_factor;
02900     
02901             bot_sclr *= shade_factor;
02902                     }
02903                     
02904 #ifdef DEBUG
02905     if (ipixel == trace_pixel_ptr) {
02906         trace_opcTL = 0.; trace_opcBL = 0.; trace_opcTR = 0.; trace_opcBR = 0.;
02907         trace_rsclrTL=0.; trace_rsclrBL=0.; trace_rsclrTR=0.; trace_rsclrBR=0.;
02908         trace_rclrTL= 0.; trace_rclrBL= 0.; trace_rclrTR= 0.; trace_rclrBR= 0.;
02909         trace_gclrTL= 0.; trace_gclrBL= 0.; trace_gclrTR= 0.; trace_gclrBR= 0.;
02910         trace_bclrTL= 0.; trace_bclrBL= 0.; trace_bclrTR= 0.; trace_bclrBR= 0.;
02911     }
02912 #endif
02913 ;
02914                     
02915        acc_opc = bot_opc * wgtBL;
02916        acc_clr = (bot_clr + bot_sclr *
02917                             ((float)1.0 - shadow_pixel->opcflt)) * wgtBL;
02918        
02919 #ifdef DEBUG
02920     if (ipixel == trace_pixel_ptr) {
02921         trace_opcBL = bot_opc;
02922         trace_rclrBL = bot_clr;
02923         trace_rsclrBL = bot_sclr;
02924     }
02925 #endif
02926 ;
02927                     
02928     
02929             opac_param = VoxelField(botRLEdata, param0_offset, param0_size);
02930             opacity = param0_table[opac_param];
02931             if (param1_size != 0) {
02932                 opac_param = VoxelField(botRLEdata, param1_offset, param1_size);
02933                 opacity *= param1_table[opac_param];
02934                 if (param2_size != 0) {
02935                     opac_param = VoxelField(botRLEdata, param2_offset, param2_size);
02936                     opacity *= param2_table[opac_param];
02937                 }
02938             }
02939             if (opacity > min_opacity) {
02940                 opacity_int = opacity*255.;
02941                 bot_opc = opac_correct[opacity_int];
02942             } else {
02943                 bot_opc = (float)0.;
02944             };
02945     
02946     
02947     shade_index=num_materials*1*ShortField(botRLEdata,norm_offset);
02948     weight_index = num_materials * ByteField(botRLEdata, wgt_offset);
02949     
02950         
02951         
02952     bot_clr = 
02953     shade_table[shade_index + 1*0 + 0] * 
02954         ((num_materials > 1) ? weight_table[weight_index] : (float)1.0);
02955         
02956         bot_sclr = 
02957     shadow_table[shade_index + 1*0 + 0] * 
02958         ((num_materials > 1) ? weight_table[weight_index] : (float)1.0);
02959         for (m = 1; m < num_materials; m++) {
02960              
02961         
02962     bot_clr += 
02963     shade_table[shade_index + 1*m + 0] * 
02964         weight_table[weight_index + m];
02965         
02966         bot_sclr += 
02967     shadow_table[shade_index + 1*m + 0] * 
02968         weight_table[weight_index + m];
02969         };
02970     shade_factor = bot_opc * slice_depth_cueing;
02971     
02972         bot_clr *= shade_factor;
02973     
02974             bot_sclr *= shade_factor;
02975                     
02976        acc_opc += bot_opc * wgtBR;
02977        acc_clr += (bot_clr + bot_sclr *
02978                             ((float)1.0 - shadow_pixel->opcflt)) * wgtBR;
02979        
02980 #ifdef DEBUG
02981     if (ipixel == trace_pixel_ptr) {
02982         trace_opcBR = bot_opc;
02983         trace_rclrBR = bot_clr;
02984         trace_rsclrBR = bot_sclr;
02985     }
02986 #endif
02987 ;
02988                     
02989         COUNT_RESAMPLE;
02990         if (acc_opc > min_opacity) {
02991             COUNT_COMPOSITE;
02992             iopc = ipixel->opcflt;
02993 #           ifndef SKIP_ERT
02994                 ASSERT(iopc < max_opacity);
02995 #           endif
02996             iopc_inv = (float)1. - iopc;
02997             ipixel->clrflt += acc_clr * iopc_inv;
02998             iopc += acc_opc * iopc_inv;
02999             ipixel->opcflt = iopc;
03000             
03001 #ifdef DEBUG
03002     if (ipixel == trace_pixel_ptr) {
03003 #ifdef COMPUTE_SHADOW_BUFFER
03004         printf("{%3d}  %3d %3d", k, icount-i-count, j);
03005 #else
03006         printf("[%3d]  %3d %3d", k, icount-i-count, j);
03007 #endif
03008         printf("  %3.0f %3.0f %3.0f",trace_opcTL*255.,trace_rclrTL,wgtTL*100.);
03009         printf("  %3.0f %3.0f %3.0f",trace_opcBL*255.,trace_rclrBL,wgtBL*100.);
03010         printf("  %3.0f %3.0f %3.0f",trace_opcTR*255.,trace_rclrTR,wgtTR*100.);
03011         printf("  %3.0f %3.0f %3.0f",trace_opcBR*255.,trace_rclrBR,wgtBR*100.);
03012         printf("  %3.0f %3.0f\n", iopc*255., 
03013                ipixel->clrflt);
03014         
03015         printf("              ");
03016         printf("      %3.0f    ",trace_rsclrTL);
03017         printf("      %3.0f    ",trace_rsclrBL);
03018         printf("      %3.0f    ",trace_rsclrTR);
03019         printf("      %3.0f    ",trace_rsclrBR);
03020         printf("  %3.0f\n", shadow_pixel->opcflt * 255.);
03021         
03022     }
03023 #endif /* DEBUG */
03024 ;
03025 #           ifndef SKIP_ERT
03026                 if (iopc >= max_opacity) {
03027                     ASSERT(ipixel->lnk == 0);
03028                     ipixel->lnk = 1;
03029                 }
03030 #           endif
03031         };
03032                     ipixel += 1; shadow_pixel += 1;
03033                     topRLEdata += 1 * voxel_istride;
03034                     botRLEdata += 1 * voxel_istride;
03035                     count--;
03036                     SET_VOXELS_LOADED;
03037                 }
03038                 break;
03039             case TOP_NONZERO__BOT_NONZERO:
03040                 /* first pixel: top-left and bottom-right voxels contribute */
03041                 if (!voxels_loaded) {
03042                     
03043     
03044             opac_param = VoxelField(topRLEdata - voxel_istride, param0_offset, param0_size);
03045             opacity = param0_table[opac_param];
03046             if (param1_size != 0) {
03047                 opac_param = VoxelField(topRLEdata - voxel_istride, param1_offset, param1_size);
03048                 opacity *= param1_table[opac_param];
03049                 if (param2_size != 0) {
03050                     opac_param = VoxelField(topRLEdata - voxel_istride, param2_offset, param2_size);
03051                     opacity *= param2_table[opac_param];
03052                 }
03053             }
03054             if (opacity > min_opacity) {
03055                 opacity_int = opacity*255.;
03056                 top_opc = opac_correct[opacity_int];
03057             } else {
03058                 top_opc = (float)0.;
03059             };
03060     
03061     
03062     shade_index=num_materials*1*ShortField(topRLEdata - voxel_istride,norm_offset);
03063     weight_index = num_materials * ByteField(topRLEdata - voxel_istride, wgt_offset);
03064     
03065         
03066         
03067     top_clr = 
03068     shade_table[shade_index + 1*0 + 0] * 
03069         ((num_materials > 1) ? weight_table[weight_index] : (float)1.0);
03070         
03071         top_sclr = 
03072     shadow_table[shade_index + 1*0 + 0] * 
03073         ((num_materials > 1) ? weight_table[weight_index] : (float)1.0);
03074         for (m = 1; m < num_materials; m++) {
03075              
03076         
03077     top_clr += 
03078     shade_table[shade_index + 1*m + 0] * 
03079         weight_table[weight_index + m];
03080         
03081         top_sclr += 
03082     shadow_table[shade_index + 1*m + 0] * 
03083         weight_table[weight_index + m];
03084         };
03085     shade_factor = top_opc * slice_depth_cueing;
03086     
03087         top_clr *= shade_factor;
03088     
03089             top_sclr *= shade_factor;
03090                 }
03091                 
03092 #ifdef DEBUG
03093     if (ipixel == trace_pixel_ptr) {
03094         trace_opcTL = 0.; trace_opcBL = 0.; trace_opcTR = 0.; trace_opcBR = 0.;
03095         trace_rsclrTL=0.; trace_rsclrBL=0.; trace_rsclrTR=0.; trace_rsclrBR=0.;
03096         trace_rclrTL= 0.; trace_rclrBL= 0.; trace_rclrTR= 0.; trace_rclrBR= 0.;
03097         trace_gclrTL= 0.; trace_gclrBL= 0.; trace_gclrTR= 0.; trace_gclrBR= 0.;
03098         trace_bclrTL= 0.; trace_bclrBL= 0.; trace_bclrTR= 0.; trace_bclrBR= 0.;
03099     }
03100 #endif
03101 ;
03102                 
03103        acc_opc = top_opc * wgtTL;
03104        acc_clr = (top_clr + top_sclr *
03105                             ((float)1.0 - shadow_pixel->opcflt)) * wgtTL;
03106        
03107 #ifdef DEBUG
03108     if (ipixel == trace_pixel_ptr) {
03109         trace_opcTL = top_opc;
03110         trace_rclrTL = top_clr;
03111         trace_rsclrTL = top_sclr;
03112     }
03113 #endif
03114 ;
03115                 
03116     
03117             opac_param = VoxelField(botRLEdata, param0_offset, param0_size);
03118             opacity = param0_table[opac_param];
03119             if (param1_size != 0) {
03120                 opac_param = VoxelField(botRLEdata, param1_offset, param1_size);
03121                 opacity *= param1_table[opac_param];
03122                 if (param2_size != 0) {
03123                     opac_param = VoxelField(botRLEdata, param2_offset, param2_size);
03124                     opacity *= param2_table[opac_param];
03125                 }
03126             }
03127             if (opacity > min_opacity) {
03128                 opacity_int = opacity*255.;
03129                 bot_opc = opac_correct[opacity_int];
03130             } else {
03131                 bot_opc = (float)0.;
03132             };
03133     
03134     
03135     shade_index=num_materials*1*ShortField(botRLEdata,norm_offset);
03136     weight_index = num_materials * ByteField(botRLEdata, wgt_offset);
03137     
03138         
03139         
03140     bot_clr = 
03141     shade_table[shade_index + 1*0 + 0] * 
03142         ((num_materials > 1) ? weight_table[weight_index] : (float)1.0);
03143         
03144         bot_sclr = 
03145     shadow_table[shade_index + 1*0 + 0] * 
03146         ((num_materials > 1) ? weight_table[weight_index] : (float)1.0);
03147         for (m = 1; m < num_materials; m++) {
03148              
03149         
03150     bot_clr += 
03151     shade_table[shade_index + 1*m + 0] * 
03152         weight_table[weight_index + m];
03153         
03154         bot_sclr += 
03155     shadow_table[shade_index + 1*m + 0] * 
03156         weight_table[weight_index + m];
03157         };
03158     shade_factor = bot_opc * slice_depth_cueing;
03159     
03160         bot_clr *= shade_factor;
03161     
03162             bot_sclr *= shade_factor;
03163                 
03164        acc_opc += bot_opc * wgtBR;
03165        acc_clr += (bot_clr + bot_sclr *
03166                             ((float)1.0 - shadow_pixel->opcflt)) * wgtBR;
03167        
03168 #ifdef DEBUG
03169     if (ipixel == trace_pixel_ptr) {
03170         trace_opcBR = bot_opc;
03171         trace_rclrBR = bot_clr;
03172         trace_rsclrBR = bot_sclr;
03173     }
03174 #endif
03175 ;
03176                 
03177         COUNT_RESAMPLE;
03178         if (acc_opc > min_opacity) {
03179             COUNT_COMPOSITE;
03180             iopc = ipixel->opcflt;
03181 #           ifndef SKIP_ERT
03182                 ASSERT(iopc < max_opacity);
03183 #           endif
03184             iopc_inv = (float)1. - iopc;
03185             ipixel->clrflt += acc_clr * iopc_inv;
03186             iopc += acc_opc * iopc_inv;
03187             ipixel->opcflt = iopc;
03188             
03189 #ifdef DEBUG
03190     if (ipixel == trace_pixel_ptr) {
03191 #ifdef COMPUTE_SHADOW_BUFFER
03192         printf("{%3d}  %3d %3d", k, icount-i-count, j);
03193 #else
03194         printf("[%3d]  %3d %3d", k, icount-i-count, j);
03195 #endif
03196         printf("  %3.0f %3.0f %3.0f",trace_opcTL*255.,trace_rclrTL,wgtTL*100.);
03197         printf("  %3.0f %3.0f %3.0f",trace_opcBL*255.,trace_rclrBL,wgtBL*100.);
03198         printf("  %3.0f %3.0f %3.0f",trace_opcTR*255.,trace_rclrTR,wgtTR*100.);
03199         printf("  %3.0f %3.0f %3.0f",trace_opcBR*255.,trace_rclrBR,wgtBR*100.);
03200         printf("  %3.0f %3.0f\n", iopc*255., 
03201                ipixel->clrflt);
03202         
03203         printf("              ");
03204         printf("      %3.0f    ",trace_rsclrTL);
03205         printf("      %3.0f    ",trace_rsclrBL);
03206         printf("      %3.0f    ",trace_rsclrTR);
03207         printf("      %3.0f    ",trace_rsclrBR);
03208         printf("  %3.0f\n", shadow_pixel->opcflt * 255.);
03209         
03210     }
03211 #endif /* DEBUG */
03212 ;
03213 #           ifndef SKIP_ERT
03214                 if (iopc >= max_opacity) {
03215                     ASSERT(ipixel->lnk == 0);
03216                     ipixel->lnk = 1;
03217                 }
03218 #           endif
03219         };
03220                 ipixel += 1; shadow_pixel += 1;
03221                 topRLEdata += 1 * voxel_istride;
03222                 botRLEdata += 1 * voxel_istride;
03223                 count--;
03224                 SET_VOXELS_LOADED;
03225 
03226                 /* do the rest of the pixels in this run;
03227                    bottom-left and bottom-right voxels contribute */
03228                 while (count > 0) {
03229                     if (PIXEL_IS_OPAQUE(ipixel))
03230                         break;
03231                     if (!voxels_loaded) {
03232                         
03233     
03234             opac_param = VoxelField(botRLEdata - voxel_istride, param0_offset, param0_size);
03235             opacity = param0_table[opac_param];
03236             if (param1_size != 0) {
03237                 opac_param = VoxelField(botRLEdata - voxel_istride, param1_offset, param1_size);
03238                 opacity *= param1_table[opac_param];
03239                 if (param2_size != 0) {
03240                     opac_param = VoxelField(botRLEdata - voxel_istride, param2_offset, param2_size);
03241                     opacity *= param2_table[opac_param];
03242                 }
03243             }
03244             if (opacity > min_opacity) {
03245                 opacity_int = opacity*255.;
03246                 bot_opc = opac_correct[opacity_int];
03247             } else {
03248                 bot_opc = (float)0.;
03249             };
03250     
03251     
03252     shade_index=num_materials*1*ShortField(botRLEdata - voxel_istride,norm_offset);
03253     weight_index = num_materials * ByteField(botRLEdata - voxel_istride, wgt_offset);
03254     
03255         
03256         
03257     bot_clr = 
03258     shade_table[shade_index + 1*0 + 0] * 
03259         ((num_materials > 1) ? weight_table[weight_index] : (float)1.0);
03260         
03261         bot_sclr = 
03262     shadow_table[shade_index + 1*0 + 0] * 
03263         ((num_materials > 1) ? weight_table[weight_index] : (float)1.0);
03264         for (m = 1; m < num_materials; m++) {
03265              
03266         
03267     bot_clr += 
03268     shade_table[shade_index + 1*m + 0] * 
03269         weight_table[weight_index + m];
03270         
03271         bot_sclr += 
03272     shadow_table[shade_index + 1*m + 0] * 
03273         weight_table[weight_index + m];
03274         };
03275     shade_factor = bot_opc * slice_depth_cueing;
03276     
03277         bot_clr *= shade_factor;
03278     
03279             bot_sclr *= shade_factor;
03280                     }
03281                     
03282 #ifdef DEBUG
03283     if (ipixel == trace_pixel_ptr) {
03284         trace_opcTL = 0.; trace_opcBL = 0.; trace_opcTR = 0.; trace_opcBR = 0.;
03285         trace_rsclrTL=0.; trace_rsclrBL=0.; trace_rsclrTR=0.; trace_rsclrBR=0.;
03286         trace_rclrTL= 0.; trace_rclrBL= 0.; trace_rclrTR= 0.; trace_rclrBR= 0.;
03287         trace_gclrTL= 0.; trace_gclrBL= 0.; trace_gclrTR= 0.; trace_gclrBR= 0.;
03288         trace_bclrTL= 0.; trace_bclrBL= 0.; trace_bclrTR= 0.; trace_bclrBR= 0.;
03289     }
03290 #endif
03291 ;
03292                     
03293        acc_opc = bot_opc * wgtBL;
03294        acc_clr = (bot_clr + bot_sclr *
03295                             ((float)1.0 - shadow_pixel->opcflt)) * wgtBL;
03296        
03297 #ifdef DEBUG
03298     if (ipixel == trace_pixel_ptr) {
03299         trace_opcBL = bot_opc;
03300         trace_rclrBL = bot_clr;
03301         trace_rsclrBL = bot_sclr;
03302     }
03303 #endif
03304 ;
03305                     
03306     
03307             opac_param = VoxelField(botRLEdata, param0_offset, param0_size);
03308             opacity = param0_table[opac_param];
03309             if (param1_size != 0) {
03310                 opac_param = VoxelField(botRLEdata, param1_offset, param1_size);
03311                 opacity *= param1_table[opac_param];
03312                 if (param2_size != 0) {
03313                     opac_param = VoxelField(botRLEdata, param2_offset, param2_size);
03314                     opacity *= param2_table[opac_param];
03315                 }
03316             }
03317             if (opacity > min_opacity) {
03318                 opacity_int = opacity*255.;
03319                 bot_opc = opac_correct[opacity_int];
03320             } else {
03321                 bot_opc = (float)0.;
03322             };
03323     
03324     
03325     shade_index=num_materials*1*ShortField(botRLEdata,norm_offset);
03326     weight_index = num_materials * ByteField(botRLEdata, wgt_offset);
03327     
03328         
03329         
03330     bot_clr = 
03331     shade_table[shade_index + 1*0 + 0] * 
03332         ((num_materials > 1) ? weight_table[weight_index] : (float)1.0);
03333         
03334         bot_sclr = 
03335     shadow_table[shade_index + 1*0 + 0] * 
03336         ((num_materials > 1) ? weight_table[weight_index] : (float)1.0);
03337         for (m = 1; m < num_materials; m++) {
03338              
03339         
03340     bot_clr += 
03341     shade_table[shade_index + 1*m + 0] * 
03342         weight_table[weight_index + m];
03343         
03344         bot_sclr += 
03345     shadow_table[shade_index + 1*m + 0] * 
03346         weight_table[weight_index + m];
03347         };
03348     shade_factor = bot_opc * slice_depth_cueing;
03349     
03350         bot_clr *= shade_factor;
03351     
03352             bot_sclr *= shade_factor;
03353                     
03354        acc_opc += bot_opc * wgtBR;
03355        acc_clr += (bot_clr + bot_sclr *
03356                             ((float)1.0 - shadow_pixel->opcflt)) * wgtBR;
03357        
03358 #ifdef DEBUG
03359     if (ipixel == trace_pixel_ptr) {
03360         trace_opcBR = bot_opc;
03361         trace_rclrBR = bot_clr;
03362         trace_rsclrBR = bot_sclr;
03363     }
03364 #endif
03365 ;
03366                     
03367         COUNT_RESAMPLE;
03368         if (acc_opc > min_opacity) {
03369             COUNT_COMPOSITE;
03370             iopc = ipixel->opcflt;
03371 #           ifndef SKIP_ERT
03372                 ASSERT(iopc < max_opacity);
03373 #           endif
03374             iopc_inv = (float)1. - iopc;
03375             ipixel->clrflt += acc_clr * iopc_inv;
03376             iopc += acc_opc * iopc_inv;
03377             ipixel->opcflt = iopc;
03378             
03379 #ifdef DEBUG
03380     if (ipixel == trace_pixel_ptr) {
03381 #ifdef COMPUTE_SHADOW_BUFFER
03382         printf("{%3d}  %3d %3d", k, icount-i-count, j);
03383 #else
03384         printf("[%3d]  %3d %3d", k, icount-i-count, j);
03385 #endif
03386         printf("  %3.0f %3.0f %3.0f",trace_opcTL*255.,trace_rclrTL,wgtTL*100.);
03387         printf("  %3.0f %3.0f %3.0f",trace_opcBL*255.,trace_rclrBL,wgtBL*100.);
03388         printf("  %3.0f %3.0f %3.0f",trace_opcTR*255.,trace_rclrTR,wgtTR*100.);
03389         printf("  %3.0f %3.0f %3.0f",trace_opcBR*255.,trace_rclrBR,wgtBR*100.);
03390         printf("  %3.0f %3.0f\n", iopc*255., 
03391                ipixel->clrflt);
03392         
03393         printf("              ");
03394         printf("      %3.0f    ",trace_rsclrTL);
03395         printf("      %3.0f    ",trace_rsclrBL);
03396         printf("      %3.0f    ",trace_rsclrTR);
03397         printf("      %3.0f    ",trace_rsclrBR);
03398         printf("  %3.0f\n", shadow_pixel->opcflt * 255.);
03399         
03400     }
03401 #endif /* DEBUG */
03402 ;
03403 #           ifndef SKIP_ERT
03404                 if (iopc >= max_opacity) {
03405                     ASSERT(ipixel->lnk == 0);
03406                     ipixel->lnk = 1;
03407                 }
03408 #           endif
03409         };
03410                     ipixel += 1; shadow_pixel += 1;
03411                     topRLEdata += 1 * voxel_istride;
03412                     botRLEdata += 1 * voxel_istride;
03413                     count--;
03414                     SET_VOXELS_LOADED;
03415                 }
03416                 break;
03417             case BOT_NONZERO__BOT_NONZERO:
03418                 /* do the pixels in this run; bottom-left and
03419                    bottom-right voxels contribute */
03420                 while (count > 0) {
03421                     if (PIXEL_IS_OPAQUE(ipixel))
03422                         break;
03423                     if (!voxels_loaded) {
03424                         
03425     
03426             opac_param = VoxelField(botRLEdata - voxel_istride, param0_offset, param0_size);
03427             opacity = param0_table[opac_param];
03428             if (param1_size != 0) {
03429                 opac_param = VoxelField(botRLEdata - voxel_istride, param1_offset, param1_size);
03430                 opacity *= param1_table[opac_param];
03431                 if (param2_size != 0) {
03432                     opac_param = VoxelField(botRLEdata - voxel_istride, param2_offset, param2_size);
03433                     opacity *= param2_table[opac_param];
03434                 }
03435             }
03436             if (opacity > min_opacity) {
03437                 opacity_int = opacity*255.;
03438                 bot_opc = opac_correct[opacity_int];
03439             } else {
03440                 bot_opc = (float)0.;
03441             };
03442     
03443     
03444     shade_index=num_materials*1*ShortField(botRLEdata - voxel_istride,norm_offset);
03445     weight_index = num_materials * ByteField(botRLEdata - voxel_istride, wgt_offset);
03446     
03447         
03448         
03449     bot_clr = 
03450     shade_table[shade_index + 1*0 + 0] * 
03451         ((num_materials > 1) ? weight_table[weight_index] : (float)1.0);
03452         
03453         bot_sclr = 
03454     shadow_table[shade_index + 1*0 + 0] * 
03455         ((num_materials > 1) ? weight_table[weight_index] : (float)1.0);
03456         for (m = 1; m < num_materials; m++) {
03457              
03458         
03459     bot_clr += 
03460     shade_table[shade_index + 1*m + 0] * 
03461         weight_table[weight_index + m];
03462         
03463         bot_sclr += 
03464     shadow_table[shade_index + 1*m + 0] * 
03465         weight_table[weight_index + m];
03466         };
03467     shade_factor = bot_opc * slice_depth_cueing;
03468     
03469         bot_clr *= shade_factor;
03470     
03471             bot_sclr *= shade_factor;
03472                     }
03473                     
03474 #ifdef DEBUG
03475     if (ipixel == trace_pixel_ptr) {
03476         trace_opcTL = 0.; trace_opcBL = 0.; trace_opcTR = 0.; trace_opcBR = 0.;
03477         trace_rsclrTL=0.; trace_rsclrBL=0.; trace_rsclrTR=0.; trace_rsclrBR=0.;
03478         trace_rclrTL= 0.; trace_rclrBL= 0.; trace_rclrTR= 0.; trace_rclrBR= 0.;
03479         trace_gclrTL= 0.; trace_gclrBL= 0.; trace_gclrTR= 0.; trace_gclrBR= 0.;
03480         trace_bclrTL= 0.; trace_bclrBL= 0.; trace_bclrTR= 0.; trace_bclrBR= 0.;
03481     }
03482 #endif
03483 ;
03484                     
03485        acc_opc = bot_opc * wgtBL;
03486        acc_clr = (bot_clr + bot_sclr *
03487                             ((float)1.0 - shadow_pixel->opcflt)) * wgtBL;
03488        
03489 #ifdef DEBUG
03490     if (ipixel == trace_pixel_ptr) {
03491         trace_opcBL = bot_opc;
03492         trace_rclrBL = bot_clr;
03493         trace_rsclrBL = bot_sclr;
03494     }
03495 #endif
03496 ;
03497                     
03498     
03499             opac_param = VoxelField(botRLEdata, param0_offset, param0_size);
03500             opacity = param0_table[opac_param];
03501             if (param1_size != 0) {
03502                 opac_param = VoxelField(botRLEdata, param1_offset, param1_size);
03503                 opacity *= param1_table[opac_param];
03504                 if (param2_size != 0) {
03505                     opac_param = VoxelField(botRLEdata, param2_offset, param2_size);
03506                     opacity *= param2_table[opac_param];
03507                 }
03508             }
03509             if (opacity > min_opacity) {
03510                 opacity_int = opacity*255.;
03511                 bot_opc = opac_correct[opacity_int];
03512             } else {
03513                 bot_opc = (float)0.;
03514             };
03515     
03516     
03517     shade_index=num_materials*1*ShortField(botRLEdata,norm_offset);
03518     weight_index = num_materials * ByteField(botRLEdata, wgt_offset);
03519     
03520         
03521         
03522     bot_clr = 
03523     shade_table[shade_index + 1*0 + 0] * 
03524         ((num_materials > 1) ? weight_table[weight_index] : (float)1.0);
03525         
03526         bot_sclr = 
03527     shadow_table[shade_index + 1*0 + 0] * 
03528         ((num_materials > 1) ? weight_table[weight_index] : (float)1.0);
03529         for (m = 1; m < num_materials; m++) {
03530              
03531         
03532     bot_clr += 
03533     shade_table[shade_index + 1*m + 0] * 
03534         weight_table[weight_index + m];
03535         
03536         bot_sclr += 
03537     shadow_table[shade_index + 1*m + 0] * 
03538         weight_table[weight_index + m];
03539         };
03540     shade_factor = bot_opc * slice_depth_cueing;
03541     
03542         bot_clr *= shade_factor;
03543     
03544             bot_sclr *= shade_factor;
03545                     
03546        acc_opc += bot_opc * wgtBR;
03547        acc_clr += (bot_clr + bot_sclr *
03548                             ((float)1.0 - shadow_pixel->opcflt)) * wgtBR;
03549        
03550 #ifdef DEBUG
03551     if (ipixel == trace_pixel_ptr) {
03552         trace_opcBR = bot_opc;
03553         trace_rclrBR = bot_clr;
03554         trace_rsclrBR = bot_sclr;
03555     }
03556 #endif
03557 ;
03558                     
03559         COUNT_RESAMPLE;
03560         if (acc_opc > min_opacity) {
03561             COUNT_COMPOSITE;
03562             iopc = ipixel->opcflt;
03563 #           ifndef SKIP_ERT
03564                 ASSERT(iopc < max_opacity);
03565 #           endif
03566             iopc_inv = (float)1. - iopc;
03567             ipixel->clrflt += acc_clr * iopc_inv;
03568             iopc += acc_opc * iopc_inv;
03569             ipixel->opcflt = iopc;
03570             
03571 #ifdef DEBUG
03572     if (ipixel == trace_pixel_ptr) {
03573 #ifdef COMPUTE_SHADOW_BUFFER
03574         printf("{%3d}  %3d %3d", k, icount-i-count, j);
03575 #else
03576         printf("[%3d]  %3d %3d", k, icount-i-count, j);
03577 #endif
03578         printf("  %3.0f %3.0f %3.0f",trace_opcTL*255.,trace_rclrTL,wgtTL*100.);
03579         printf("  %3.0f %3.0f %3.0f",trace_opcBL*255.,trace_rclrBL,wgtBL*100.);
03580         printf("  %3.0f %3.0f %3.0f",trace_opcTR*255.,trace_rclrTR,wgtTR*100.);
03581         printf("  %3.0f %3.0f %3.0f",trace_opcBR*255.,trace_rclrBR,wgtBR*100.);
03582         printf("  %3.0f %3.0f\n", iopc*255., 
03583                ipixel->clrflt);
03584         
03585         printf("              ");
03586         printf("      %3.0f    ",trace_rsclrTL);
03587         printf("      %3.0f    ",trace_rsclrBL);
03588         printf("      %3.0f    ",trace_rsclrTR);
03589         printf("      %3.0f    ",trace_rsclrBR);
03590         printf("  %3.0f\n", shadow_pixel->opcflt * 255.);
03591         
03592     }
03593 #endif /* DEBUG */
03594 ;
03595 #           ifndef SKIP_ERT
03596                 if (iopc >= max_opacity) {
03597                     ASSERT(ipixel->lnk == 0);
03598                     ipixel->lnk = 1;
03599                 }
03600 #           endif
03601         };
03602                     ipixel += 1; shadow_pixel += 1;
03603                     topRLEdata += 1 * voxel_istride;
03604                     botRLEdata += 1 * voxel_istride;
03605                     count--;
03606                     SET_VOXELS_LOADED;
03607                 }
03608                 break;
03609             case ALL_NONZERO__BOT_NONZERO:
03610                 /* first pixel: top-left, bottom-left and bottom-right
03611                    voxels contribute */
03612                 if (!voxels_loaded) {
03613                     
03614     
03615             opac_param = VoxelField(topRLEdata - voxel_istride, param0_offset, param0_size);
03616             opacity = param0_table[opac_param];
03617             if (param1_size != 0) {
03618                 opac_param = VoxelField(topRLEdata - voxel_istride, param1_offset, param1_size);
03619                 opacity *= param1_table[opac_param];
03620                 if (param2_size != 0) {
03621                     opac_param = VoxelField(topRLEdata - voxel_istride, param2_offset, param2_size);
03622                     opacity *= param2_table[opac_param];
03623                 }
03624             }
03625             if (opacity > min_opacity) {
03626                 opacity_int = opacity*255.;
03627                 top_opc = opac_correct[opacity_int];
03628             } else {
03629                 top_opc = (float)0.;
03630             };
03631     
03632     
03633     shade_index=num_materials*1*ShortField(topRLEdata - voxel_istride,norm_offset);
03634     weight_index = num_materials * ByteField(topRLEdata - voxel_istride, wgt_offset);
03635     
03636         
03637         
03638     top_clr = 
03639     shade_table[shade_index + 1*0 + 0] * 
03640         ((num_materials > 1) ? weight_table[weight_index] : (float)1.0);
03641         
03642         top_sclr = 
03643     shadow_table[shade_index + 1*0 + 0] * 
03644         ((num_materials > 1) ? weight_table[weight_index] : (float)1.0);
03645         for (m = 1; m < num_materials; m++) {
03646              
03647         
03648     top_clr += 
03649     shade_table[shade_index + 1*m + 0] * 
03650         weight_table[weight_index + m];
03651         
03652         top_sclr += 
03653     shadow_table[shade_index + 1*m + 0] * 
03654         weight_table[weight_index + m];
03655         };
03656     shade_factor = top_opc * slice_depth_cueing;
03657     
03658         top_clr *= shade_factor;
03659     
03660             top_sclr *= shade_factor;
03661                     
03662     
03663             opac_param = VoxelField(botRLEdata - voxel_istride, param0_offset, param0_size);
03664             opacity = param0_table[opac_param];
03665             if (param1_size != 0) {
03666                 opac_param = VoxelField(botRLEdata - voxel_istride, param1_offset, param1_size);
03667                 opacity *= param1_table[opac_param];
03668                 if (param2_size != 0) {
03669                     opac_param = VoxelField(botRLEdata - voxel_istride, param2_offset, param2_size);
03670                     opacity *= param2_table[opac_param];
03671                 }
03672             }
03673             if (opacity > min_opacity) {
03674                 opacity_int = opacity*255.;
03675                 bot_opc = opac_correct[opacity_int];
03676             } else {
03677                 bot_opc = (float)0.;
03678             };
03679     
03680     
03681     shade_index=num_materials*1*ShortField(botRLEdata - voxel_istride,norm_offset);
03682     weight_index = num_materials * ByteField(botRLEdata - voxel_istride, wgt_offset);
03683     
03684         
03685         
03686     bot_clr = 
03687     shade_table[shade_index + 1*0 + 0] * 
03688         ((num_materials > 1) ? weight_table[weight_index] : (float)1.0);
03689         
03690         bot_sclr = 
03691     shadow_table[shade_index + 1*0 + 0] * 
03692         ((num_materials > 1) ? weight_table[weight_index] : (float)1.0);
03693         for (m = 1; m < num_materials; m++) {
03694              
03695         
03696     bot_clr += 
03697     shade_table[shade_index + 1*m + 0] * 
03698         weight_table[weight_index + m];
03699         
03700         bot_sclr += 
03701     shadow_table[shade_index + 1*m + 0] * 
03702         weight_table[weight_index + m];
03703         };
03704     shade_factor = bot_opc * slice_depth_cueing;
03705     
03706         bot_clr *= shade_factor;
03707     
03708             bot_sclr *= shade_factor;
03709                 }
03710                 
03711 #ifdef DEBUG
03712     if (ipixel == trace_pixel_ptr) {
03713         trace_opcTL = 0.; trace_opcBL = 0.; trace_opcTR = 0.; trace_opcBR = 0.;
03714         trace_rsclrTL=0.; trace_rsclrBL=0.; trace_rsclrTR=0.; trace_rsclrBR=0.;
03715         trace_rclrTL= 0.; trace_rclrBL= 0.; trace_rclrTR= 0.; trace_rclrBR= 0.;
03716         trace_gclrTL= 0.; trace_gclrBL= 0.; trace_gclrTR= 0.; trace_gclrBR= 0.;
03717         trace_bclrTL= 0.; trace_bclrBL= 0.; trace_bclrTR= 0.; trace_bclrBR= 0.;
03718     }
03719 #endif
03720 ;
03721                 
03722        acc_opc = top_opc * wgtTL;
03723        acc_clr = (top_clr + top_sclr *
03724                             ((float)1.0 - shadow_pixel->opcflt)) * wgtTL;
03725        
03726 #ifdef DEBUG
03727     if (ipixel == trace_pixel_ptr) {
03728         trace_opcTL = top_opc;
03729         trace_rclrTL = top_clr;
03730         trace_rsclrTL = top_sclr;
03731     }
03732 #endif
03733 ;
03734                 
03735        acc_opc += bot_opc * wgtBL;
03736        acc_clr += (bot_clr + bot_sclr *
03737                             ((float)1.0 - shadow_pixel->opcflt)) * wgtBL;
03738        
03739 #ifdef DEBUG
03740     if (ipixel == trace_pixel_ptr) {
03741         trace_opcBL = bot_opc;
03742         trace_rclrBL = bot_clr;
03743         trace_rsclrBL = bot_sclr;
03744     }
03745 #endif
03746 ;
03747                 
03748     
03749             opac_param = VoxelField(botRLEdata, param0_offset, param0_size);
03750             opacity = param0_table[opac_param];
03751             if (param1_size != 0) {
03752                 opac_param = VoxelField(botRLEdata, param1_offset, param1_size);
03753                 opacity *= param1_table[opac_param];
03754                 if (param2_size != 0) {
03755                     opac_param = VoxelField(botRLEdata, param2_offset, param2_size);
03756                     opacity *= param2_table[opac_param];
03757                 }
03758             }
03759             if (opacity > min_opacity) {
03760                 opacity_int = opacity*255.;
03761                 bot_opc = opac_correct[opacity_int];
03762             } else {
03763                 bot_opc = (float)0.;
03764             };
03765     
03766     
03767     shade_index=num_materials*1*ShortField(botRLEdata,norm_offset);
03768     weight_index = num_materials * ByteField(botRLEdata, wgt_offset);
03769     
03770         
03771         
03772     bot_clr = 
03773     shade_table[shade_index + 1*0 + 0] * 
03774         ((num_materials > 1) ? weight_table[weight_index] : (float)1.0);
03775         
03776         bot_sclr = 
03777     shadow_table[shade_index + 1*0 + 0] * 
03778         ((num_materials > 1) ? weight_table[weight_index] : (float)1.0);
03779         for (m = 1; m < num_materials; m++) {
03780              
03781         
03782     bot_clr += 
03783     shade_table[shade_index + 1*m + 0] * 
03784         weight_table[weight_index + m];
03785         
03786         bot_sclr += 
03787     shadow_table[shade_index + 1*m + 0] * 
03788         weight_table[weight_index + m];
03789         };
03790     shade_factor = bot_opc * slice_depth_cueing;
03791     
03792         bot_clr *= shade_factor;
03793     
03794             bot_sclr *= shade_factor;
03795                 
03796        acc_opc += bot_opc * wgtBR;
03797        acc_clr += (bot_clr + bot_sclr *
03798                             ((float)1.0 - shadow_pixel->opcflt)) * wgtBR;
03799        
03800 #ifdef DEBUG
03801     if (ipixel == trace_pixel_ptr) {
03802         trace_opcBR = bot_opc;
03803         trace_rclrBR = bot_clr;
03804         trace_rsclrBR = bot_sclr;
03805     }
03806 #endif
03807 ;
03808                 
03809         COUNT_RESAMPLE;
03810         if (acc_opc > min_opacity) {
03811             COUNT_COMPOSITE;
03812             iopc = ipixel->opcflt;
03813 #           ifndef SKIP_ERT
03814                 ASSERT(iopc < max_opacity);
03815 #           endif
03816             iopc_inv = (float)1. - iopc;
03817             ipixel->clrflt += acc_clr * iopc_inv;
03818             iopc += acc_opc * iopc_inv;
03819             ipixel->opcflt = iopc;
03820             
03821 #ifdef DEBUG
03822     if (ipixel == trace_pixel_ptr) {
03823 #ifdef COMPUTE_SHADOW_BUFFER
03824         printf("{%3d}  %3d %3d", k, icount-i-count, j);
03825 #else
03826         printf("[%3d]  %3d %3d", k, icount-i-count, j);
03827 #endif
03828         printf("  %3.0f %3.0f %3.0f",trace_opcTL*255.,trace_rclrTL,wgtTL*100.);
03829         printf("  %3.0f %3.0f %3.0f",trace_opcBL*255.,trace_rclrBL,wgtBL*100.);
03830         printf("  %3.0f %3.0f %3.0f",trace_opcTR*255.,trace_rclrTR,wgtTR*100.);
03831         printf("  %3.0f %3.0f %3.0f",trace_opcBR*255.,trace_rclrBR,wgtBR*100.);
03832         printf("  %3.0f %3.0f\n", iopc*255., 
03833                ipixel->clrflt);
03834         
03835         printf("              ");
03836         printf("      %3.0f    ",trace_rsclrTL);
03837         printf("      %3.0f    ",trace_rsclrBL);
03838         printf("      %3.0f    ",trace_rsclrTR);
03839         printf("      %3.0f    ",trace_rsclrBR);
03840         printf("  %3.0f\n", shadow_pixel->opcflt * 255.);
03841         
03842     }
03843 #endif /* DEBUG */
03844 ;
03845 #           ifndef SKIP_ERT
03846                 if (iopc >= max_opacity) {
03847                     ASSERT(ipixel->lnk == 0);
03848                     ipixel->lnk = 1;
03849                 }
03850 #           endif
03851         };
03852                 ipixel += 1; shadow_pixel += 1;
03853                 topRLEdata += 1 * voxel_istride;
03854                 botRLEdata += 1 * voxel_istride;
03855                 count--;
03856                 SET_VOXELS_LOADED;
03857 
03858                 /* do the rest of the pixels in this run;
03859                    bottom-left and bottom-right voxels contribute */
03860                 while (count > 0) {
03861                     if (PIXEL_IS_OPAQUE(ipixel))
03862                         break;
03863                     if (!voxels_loaded) {
03864                         
03865     
03866             opac_param = VoxelField(botRLEdata - voxel_istride, param0_offset, param0_size);
03867             opacity = param0_table[opac_param];
03868             if (param1_size != 0) {
03869                 opac_param = VoxelField(botRLEdata - voxel_istride, param1_offset, param1_size);
03870                 opacity *= param1_table[opac_param];
03871                 if (param2_size != 0) {
03872                     opac_param = VoxelField(botRLEdata - voxel_istride, param2_offset, param2_size);
03873                     opacity *= param2_table[opac_param];
03874                 }
03875             }
03876             if (opacity > min_opacity) {
03877                 opacity_int = opacity*255.;
03878                 bot_opc = opac_correct[opacity_int];
03879             } else {
03880                 bot_opc = (float)0.;
03881             };
03882     
03883     
03884     shade_index=num_materials*1*ShortField(botRLEdata - voxel_istride,norm_offset);
03885     weight_index = num_materials * ByteField(botRLEdata - voxel_istride, wgt_offset);
03886     
03887         
03888         
03889     bot_clr = 
03890     shade_table[shade_index + 1*0 + 0] * 
03891         ((num_materials > 1) ? weight_table[weight_index] : (float)1.0);
03892         
03893         bot_sclr = 
03894     shadow_table[shade_index + 1*0 + 0] * 
03895         ((num_materials > 1) ? weight_table[weight_index] : (float)1.0);
03896         for (m = 1; m < num_materials; m++) {
03897              
03898         
03899     bot_clr += 
03900     shade_table[shade_index + 1*m + 0] * 
03901         weight_table[weight_index + m];
03902         
03903         bot_sclr += 
03904     shadow_table[shade_index + 1*m + 0] * 
03905         weight_table[weight_index + m];
03906         };
03907     shade_factor = bot_opc * slice_depth_cueing;
03908     
03909         bot_clr *= shade_factor;
03910     
03911             bot_sclr *= shade_factor;
03912                     }
03913                     
03914 #ifdef DEBUG
03915     if (ipixel == trace_pixel_ptr) {
03916         trace_opcTL = 0.; trace_opcBL = 0.; trace_opcTR = 0.; trace_opcBR = 0.;
03917         trace_rsclrTL=0.; trace_rsclrBL=0.; trace_rsclrTR=0.; trace_rsclrBR=0.;
03918         trace_rclrTL= 0.; trace_rclrBL= 0.; trace_rclrTR= 0.; trace_rclrBR= 0.;
03919         trace_gclrTL= 0.; trace_gclrBL= 0.; trace_gclrTR= 0.; trace_gclrBR= 0.;
03920         trace_bclrTL= 0.; trace_bclrBL= 0.; trace_bclrTR= 0.; trace_bclrBR= 0.;
03921     }
03922 #endif
03923 ;
03924                     
03925        acc_opc = bot_opc * wgtBL;
03926        acc_clr = (bot_clr + bot_sclr *
03927                             ((float)1.0 - shadow_pixel->opcflt)) * wgtBL;
03928        
03929 #ifdef DEBUG
03930     if (ipixel == trace_pixel_ptr) {
03931         trace_opcBL = bot_opc;
03932         trace_rclrBL = bot_clr;
03933         trace_rsclrBL = bot_sclr;
03934     }
03935 #endif
03936 ;
03937                     
03938     
03939             opac_param = VoxelField(botRLEdata, param0_offset, param0_size);
03940             opacity = param0_table[opac_param];
03941             if (param1_size != 0) {
03942                 opac_param = VoxelField(botRLEdata, param1_offset, param1_size);
03943                 opacity *= param1_table[opac_param];
03944                 if (param2_size != 0) {
03945                     opac_param = VoxelField(botRLEdata, param2_offset, param2_size);
03946                     opacity *= param2_table[opac_param];
03947                 }
03948             }
03949             if (opacity > min_opacity) {
03950                 opacity_int = opacity*255.;
03951                 bot_opc = opac_correct[opacity_int];
03952             } else {
03953                 bot_opc = (float)0.;
03954             };
03955     
03956     
03957     shade_index=num_materials*1*ShortField(botRLEdata,norm_offset);
03958     weight_index = num_materials * ByteField(botRLEdata, wgt_offset);
03959     
03960         
03961         
03962     bot_clr = 
03963     shade_table[shade_index + 1*0 + 0] * 
03964         ((num_materials > 1) ? weight_table[weight_index] : (float)1.0);
03965         
03966         bot_sclr = 
03967     shadow_table[shade_index + 1*0 + 0] * 
03968         ((num_materials > 1) ? weight_table[weight_index] : (float)1.0);
03969         for (m = 1; m < num_materials; m++) {
03970              
03971         
03972     bot_clr += 
03973     shade_table[shade_index + 1*m + 0] * 
03974         weight_table[weight_index + m];
03975         
03976         bot_sclr += 
03977     shadow_table[shade_index + 1*m + 0] * 
03978         weight_table[weight_index + m];
03979         };
03980     shade_factor = bot_opc * slice_depth_cueing;
03981     
03982         bot_clr *= shade_factor;
03983     
03984             bot_sclr *= shade_factor;
03985                     
03986        acc_opc += bot_opc * wgtBR;
03987        acc_clr += (bot_clr + bot_sclr *
03988                             ((float)1.0 - shadow_pixel->opcflt)) * wgtBR;
03989        
03990 #ifdef DEBUG
03991     if (ipixel == trace_pixel_ptr) {
03992         trace_opcBR = bot_opc;
03993         trace_rclrBR = bot_clr;
03994         trace_rsclrBR = bot_sclr;
03995     }
03996 #endif
03997 ;
03998                     
03999         COUNT_RESAMPLE;
04000         if (acc_opc > min_opacity) {
04001             COUNT_COMPOSITE;
04002             iopc = ipixel->opcflt;
04003 #           ifndef SKIP_ERT
04004                 ASSERT(iopc < max_opacity);
04005 #           endif
04006             iopc_inv = (float)1. - iopc;
04007             ipixel->clrflt += acc_clr * iopc_inv;
04008             iopc += acc_opc * iopc_inv;
04009             ipixel->opcflt = iopc;
04010             
04011 #ifdef DEBUG
04012     if (ipixel == trace_pixel_ptr) {
04013 #ifdef COMPUTE_SHADOW_BUFFER
04014         printf("{%3d}  %3d %3d", k, icount-i-count, j);
04015 #else
04016         printf("[%3d]  %3d %3d", k, icount-i-count, j);
04017 #endif
04018         printf("  %3.0f %3.0f %3.0f",trace_opcTL*255.,trace_rclrTL,wgtTL*100.);
04019         printf("  %3.0f %3.0f %3.0f",trace_opcBL*255.,trace_rclrBL,wgtBL*100.);
04020         printf("  %3.0f %3.0f %3.0f",trace_opcTR*255.,trace_rclrTR,wgtTR*100.);
04021         printf("  %3.0f %3.0f %3.0f",trace_opcBR*255.,trace_rclrBR,wgtBR*100.);
04022         printf("  %3.0f %3.0f\n", iopc*255., 
04023                ipixel->clrflt);
04024         
04025         printf("              ");
04026         printf("      %3.0f    ",trace_rsclrTL);
04027         printf("      %3.0f    ",trace_rsclrBL);
04028         printf("      %3.0f    ",trace_rsclrTR);
04029         printf("      %3.0f    ",trace_rsclrBR);
04030         printf("  %3.0f\n", shadow_pixel->opcflt * 255.);
04031         
04032     }
04033 #endif /* DEBUG */
04034 ;
04035 #           ifndef SKIP_ERT
04036                 if (iopc >= max_opacity) {
04037                     ASSERT(ipixel->lnk == 0);
04038                     ipixel->lnk = 1;
04039                 }
04040 #           endif
04041         };
04042                     ipixel += 1; shadow_pixel += 1;
04043                     topRLEdata += 1 * voxel_istride;
04044                     botRLEdata += 1 * voxel_istride;
04045                     count--;
04046                     SET_VOXELS_LOADED;
04047                 }
04048                 break;
04049             case ALL_ZERO__ALL_NONZERO:
04050                 /* first pixel: top-right and bottom-right voxels contribute */
04051                 
04052     
04053             opac_param = VoxelField(topRLEdata, param0_offset, param0_size);
04054             opacity = param0_table[opac_param];
04055             if (param1_size != 0) {
04056                 opac_param = VoxelField(topRLEdata, param1_offset, param1_size);
04057                 opacity *= param1_table[opac_param];
04058                 if (param2_size != 0) {
04059                     opac_param = VoxelField(topRLEdata, param2_offset, param2_size);
04060                     opacity *= param2_table[opac_param];
04061                 }
04062             }
04063             if (opacity > min_opacity) {
04064                 opacity_int = opacity*255.;
04065                 top_opc = opac_correct[opacity_int];
04066             } else {
04067                 top_opc = (float)0.;
04068             };
04069     
04070     
04071     shade_index=num_materials*1*ShortField(topRLEdata,norm_offset);
04072     weight_index = num_materials * ByteField(topRLEdata, wgt_offset);
04073     
04074         
04075         
04076     top_clr = 
04077     shade_table[shade_index + 1*0 + 0] * 
04078         ((num_materials > 1) ? weight_table[weight_index] : (float)1.0);
04079         
04080         top_sclr = 
04081     shadow_table[shade_index + 1*0 + 0] * 
04082         ((num_materials > 1) ? weight_table[weight_index] : (float)1.0);
04083         for (m = 1; m < num_materials; m++) {
04084              
04085         
04086     top_clr += 
04087     shade_table[shade_index + 1*m + 0] * 
04088         weight_table[weight_index + m];
04089         
04090         top_sclr += 
04091     shadow_table[shade_index + 1*m + 0] * 
04092         weight_table[weight_index + m];
04093         };
04094     shade_factor = top_opc * slice_depth_cueing;
04095     
04096         top_clr *= shade_factor;
04097     
04098             top_sclr *= shade_factor;
04099                 
04100     
04101             opac_param = VoxelField(botRLEdata, param0_offset, param0_size);
04102             opacity = param0_table[opac_param];
04103             if (param1_size != 0) {
04104                 opac_param = VoxelField(botRLEdata, param1_offset, param1_size);
04105                 opacity *= param1_table[opac_param];
04106                 if (param2_size != 0) {
04107                     opac_param = VoxelField(botRLEdata, param2_offset, param2_size);
04108                     opacity *= param2_table[opac_param];
04109                 }
04110             }
04111             if (opacity > min_opacity) {
04112                 opacity_int = opacity*255.;
04113                 bot_opc = opac_correct[opacity_int];
04114             } else {
04115                 bot_opc = (float)0.;
04116             };
04117     
04118     
04119     shade_index=num_materials*1*ShortField(botRLEdata,norm_offset);
04120     weight_index = num_materials * ByteField(botRLEdata, wgt_offset);
04121     
04122         
04123         
04124     bot_clr = 
04125     shade_table[shade_index + 1*0 + 0] * 
04126         ((num_materials > 1) ? weight_table[weight_index] : (float)1.0);
04127         
04128         bot_sclr = 
04129     shadow_table[shade_index + 1*0 + 0] * 
04130         ((num_materials > 1) ? weight_table[weight_index] : (float)1.0);
04131         for (m = 1; m < num_materials; m++) {
04132              
04133         
04134     bot_clr += 
04135     shade_table[shade_index + 1*m + 0] * 
04136         weight_table[weight_index + m];
04137         
04138         bot_sclr += 
04139     shadow_table[shade_index + 1*m + 0] * 
04140         weight_table[weight_index + m];
04141         };
04142     shade_factor = bot_opc * slice_depth_cueing;
04143     
04144         bot_clr *= shade_factor;
04145     
04146             bot_sclr *= shade_factor;
04147                 
04148 #ifdef DEBUG
04149     if (ipixel == trace_pixel_ptr) {
04150         trace_opcTL = 0.; trace_opcBL = 0.; trace_opcTR = 0.; trace_opcBR = 0.;
04151         trace_rsclrTL=0.; trace_rsclrBL=0.; trace_rsclrTR=0.; trace_rsclrBR=0.;
04152         trace_rclrTL= 0.; trace_rclrBL= 0.; trace_rclrTR= 0.; trace_rclrBR= 0.;
04153         trace_gclrTL= 0.; trace_gclrBL= 0.; trace_gclrTR= 0.; trace_gclrBR= 0.;
04154         trace_bclrTL= 0.; trace_bclrBL= 0.; trace_bclrTR= 0.; trace_bclrBR= 0.;
04155     }
04156 #endif
04157 ;
04158                 
04159        acc_opc = top_opc * wgtTR;
04160        acc_clr = (top_clr + top_sclr *
04161                             ((float)1.0 - shadow_pixel->opcflt)) * wgtTR;
04162        
04163 #ifdef DEBUG
04164     if (ipixel == trace_pixel_ptr) {
04165         trace_opcTR = top_opc;
04166         trace_rclrTR = top_clr;
04167         trace_rsclrTR = top_sclr;
04168     }
04169 #endif
04170 ;
04171                 
04172        acc_opc += bot_opc * wgtBR;
04173        acc_clr += (bot_clr + bot_sclr *
04174                             ((float)1.0 - shadow_pixel->opcflt)) * wgtBR;
04175        
04176 #ifdef DEBUG
04177     if (ipixel == trace_pixel_ptr) {
04178         trace_opcBR = bot_opc;
04179         trace_rclrBR = bot_clr;
04180         trace_rsclrBR = bot_sclr;
04181     }
04182 #endif
04183 ;
04184                 
04185         COUNT_RESAMPLE;
04186         if (acc_opc > min_opacity) {
04187             COUNT_COMPOSITE;
04188             iopc = ipixel->opcflt;
04189 #           ifndef SKIP_ERT
04190                 ASSERT(iopc < max_opacity);
04191 #           endif
04192             iopc_inv = (float)1. - iopc;
04193             ipixel->clrflt += acc_clr * iopc_inv;
04194             iopc += acc_opc * iopc_inv;
04195             ipixel->opcflt = iopc;
04196             
04197 #ifdef DEBUG
04198     if (ipixel == trace_pixel_ptr) {
04199 #ifdef COMPUTE_SHADOW_BUFFER
04200         printf("{%3d}  %3d %3d", k, icount-i-count, j);
04201 #else
04202         printf("[%3d]  %3d %3d", k, icount-i-count, j);
04203 #endif
04204         printf("  %3.0f %3.0f %3.0f",trace_opcTL*255.,trace_rclrTL,wgtTL*100.);
04205         printf("  %3.0f %3.0f %3.0f",trace_opcBL*255.,trace_rclrBL,wgtBL*100.);
04206         printf("  %3.0f %3.0f %3.0f",trace_opcTR*255.,trace_rclrTR,wgtTR*100.);
04207         printf("  %3.0f %3.0f %3.0f",trace_opcBR*255.,trace_rclrBR,wgtBR*100.);
04208         printf("  %3.0f %3.0f\n", iopc*255., 
04209                ipixel->clrflt);
04210         
04211         printf("              ");
04212         printf("      %3.0f    ",trace_rsclrTL);
04213         printf("      %3.0f    ",trace_rsclrBL);
04214         printf("      %3.0f    ",trace_rsclrTR);
04215         printf("      %3.0f    ",trace_rsclrBR);
04216         printf("  %3.0f\n", shadow_pixel->opcflt * 255.);
04217         
04218     }
04219 #endif /* DEBUG */
04220 ;
04221 #           ifndef SKIP_ERT
04222                 if (iopc >= max_opacity) {
04223                     ASSERT(ipixel->lnk == 0);
04224                     ipixel->lnk = 1;
04225                 }
04226 #           endif
04227         };
04228                 ipixel += 1; shadow_pixel += 1;
04229                 topRLEdata += 1 * voxel_istride;
04230                 botRLEdata += 1 * voxel_istride;
04231                 count--;
04232                 SET_VOXELS_LOADED;
04233 
04234                 /* do the rest of the pixels in this run;
04235                    all four voxels contribute */
04236                 while (count > 0) {
04237                     if (PIXEL_IS_OPAQUE(ipixel))
04238                         break;
04239                     if (!voxels_loaded) {
04240                         
04241     
04242             opac_param = VoxelField(topRLEdata - voxel_istride, param0_offset, param0_size);
04243             opacity = param0_table[opac_param];
04244             if (param1_size != 0) {
04245                 opac_param = VoxelField(topRLEdata - voxel_istride, param1_offset, param1_size);
04246                 opacity *= param1_table[opac_param];
04247                 if (param2_size != 0) {
04248                     opac_param = VoxelField(topRLEdata - voxel_istride, param2_offset, param2_size);
04249                     opacity *= param2_table[opac_param];
04250                 }
04251             }
04252             if (opacity > min_opacity) {
04253                 opacity_int = opacity*255.;
04254                 top_opc = opac_correct[opacity_int];
04255             } else {
04256                 top_opc = (float)0.;
04257             };
04258     
04259     
04260     shade_index=num_materials*1*ShortField(topRLEdata - voxel_istride,norm_offset);
04261     weight_index = num_materials * ByteField(topRLEdata - voxel_istride, wgt_offset);
04262     
04263         
04264         
04265     top_clr = 
04266     shade_table[shade_index + 1*0 + 0] * 
04267         ((num_materials > 1) ? weight_table[weight_index] : (float)1.0);
04268         
04269         top_sclr = 
04270     shadow_table[shade_index + 1*0 + 0] * 
04271         ((num_materials > 1) ? weight_table[weight_index] : (float)1.0);
04272         for (m = 1; m < num_materials; m++) {
04273              
04274         
04275     top_clr += 
04276     shade_table[shade_index + 1*m + 0] * 
04277         weight_table[weight_index + m];
04278         
04279         top_sclr += 
04280     shadow_table[shade_index + 1*m + 0] * 
04281         weight_table[weight_index + m];
04282         };
04283     shade_factor = top_opc * slice_depth_cueing;
04284     
04285         top_clr *= shade_factor;
04286     
04287             top_sclr *= shade_factor;
04288                         
04289     
04290             opac_param = VoxelField(botRLEdata - voxel_istride, param0_offset, param0_size);
04291             opacity = param0_table[opac_param];
04292             if (param1_size != 0) {
04293                 opac_param = VoxelField(botRLEdata - voxel_istride, param1_offset, param1_size);
04294                 opacity *= param1_table[opac_param];
04295                 if (param2_size != 0) {
04296                     opac_param = VoxelField(botRLEdata - voxel_istride, param2_offset, param2_size);
04297                     opacity *= param2_table[opac_param];
04298                 }
04299             }
04300             if (opacity > min_opacity) {
04301                 opacity_int = opacity*255.;
04302                 bot_opc = opac_correct[opacity_int];
04303             } else {
04304                 bot_opc = (float)0.;
04305             };
04306     
04307     
04308     shade_index=num_materials*1*ShortField(botRLEdata - voxel_istride,norm_offset);
04309     weight_index = num_materials * ByteField(botRLEdata - voxel_istride, wgt_offset);
04310     
04311         
04312         
04313     bot_clr = 
04314     shade_table[shade_index + 1*0 + 0] * 
04315         ((num_materials > 1) ? weight_table[weight_index] : (float)1.0);
04316         
04317         bot_sclr = 
04318     shadow_table[shade_index + 1*0 + 0] * 
04319         ((num_materials > 1) ? weight_table[weight_index] : (float)1.0);
04320         for (m = 1; m < num_materials; m++) {
04321              
04322         
04323     bot_clr += 
04324     shade_table[shade_index + 1*m + 0] * 
04325         weight_table[weight_index + m];
04326         
04327         bot_sclr += 
04328     shadow_table[shade_index + 1*m + 0] * 
04329         weight_table[weight_index + m];
04330         };
04331     shade_factor = bot_opc * slice_depth_cueing;
04332     
04333         bot_clr *= shade_factor;
04334     
04335             bot_sclr *= shade_factor;
04336                     }
04337                     
04338 #ifdef DEBUG
04339     if (ipixel == trace_pixel_ptr) {
04340         trace_opcTL = 0.; trace_opcBL = 0.; trace_opcTR = 0.; trace_opcBR = 0.;
04341         trace_rsclrTL=0.; trace_rsclrBL=0.; trace_rsclrTR=0.; trace_rsclrBR=0.;
04342         trace_rclrTL= 0.; trace_rclrBL= 0.; trace_rclrTR= 0.; trace_rclrBR= 0.;
04343         trace_gclrTL= 0.; trace_gclrBL= 0.; trace_gclrTR= 0.; trace_gclrBR= 0.;
04344         trace_bclrTL= 0.; trace_bclrBL= 0.; trace_bclrTR= 0.; trace_bclrBR= 0.;
04345     }
04346 #endif
04347 ;
04348                     
04349        acc_opc = top_opc * wgtTL;
04350        acc_clr = (top_clr + top_sclr *
04351                             ((float)1.0 - shadow_pixel->opcflt)) * wgtTL;
04352        
04353 #ifdef DEBUG
04354     if (ipixel == trace_pixel_ptr) {
04355         trace_opcTL = top_opc;
04356         trace_rclrTL = top_clr;
04357         trace_rsclrTL = top_sclr;
04358     }
04359 #endif
04360 ;
04361                     
04362        acc_opc += bot_opc * wgtBL;
04363        acc_clr += (bot_clr + bot_sclr *
04364                             ((float)1.0 - shadow_pixel->opcflt)) * wgtBL;
04365        
04366 #ifdef DEBUG
04367     if (ipixel == trace_pixel_ptr) {
04368         trace_opcBL = bot_opc;
04369         trace_rclrBL = bot_clr;
04370         trace_rsclrBL = bot_sclr;
04371     }
04372 #endif
04373 ;
04374                     
04375     
04376             opac_param = VoxelField(topRLEdata, param0_offset, param0_size);
04377             opacity = param0_table[opac_param];
04378             if (param1_size != 0) {
04379                 opac_param = VoxelField(topRLEdata, param1_offset, param1_size);
04380                 opacity *= param1_table[opac_param];
04381                 if (param2_size != 0) {
04382                     opac_param = VoxelField(topRLEdata, param2_offset, param2_size);
04383                     opacity *= param2_table[opac_param];
04384                 }
04385             }
04386             if (opacity > min_opacity) {
04387                 opacity_int = opacity*255.;
04388                 top_opc = opac_correct[opacity_int];
04389             } else {
04390                 top_opc = (float)0.;
04391             };
04392     
04393     
04394     shade_index=num_materials*1*ShortField(topRLEdata,norm_offset);
04395     weight_index = num_materials * ByteField(topRLEdata, wgt_offset);
04396     
04397         
04398         
04399     top_clr = 
04400     shade_table[shade_index + 1*0 + 0] * 
04401         ((num_materials > 1) ? weight_table[weight_index] : (float)1.0);
04402         
04403         top_sclr = 
04404     shadow_table[shade_index + 1*0 + 0] * 
04405         ((num_materials > 1) ? weight_table[weight_index] : (float)1.0);
04406         for (m = 1; m < num_materials; m++) {
04407              
04408         
04409     top_clr += 
04410     shade_table[shade_index + 1*m + 0] * 
04411         weight_table[weight_index + m];
04412         
04413         top_sclr += 
04414     shadow_table[shade_index + 1*m + 0] * 
04415         weight_table[weight_index + m];
04416         };
04417     shade_factor = top_opc * slice_depth_cueing;
04418     
04419         top_clr *= shade_factor;
04420     
04421             top_sclr *= shade_factor;
04422                     
04423     
04424             opac_param = VoxelField(botRLEdata, param0_offset, param0_size);
04425             opacity = param0_table[opac_param];
04426             if (param1_size != 0) {
04427                 opac_param = VoxelField(botRLEdata, param1_offset, param1_size);
04428                 opacity *= param1_table[opac_param];
04429                 if (param2_size != 0) {
04430                     opac_param = VoxelField(botRLEdata, param2_offset, param2_size);
04431                     opacity *= param2_table[opac_param];
04432                 }
04433             }
04434             if (opacity > min_opacity) {
04435                 opacity_int = opacity*255.;
04436                 bot_opc = opac_correct[opacity_int];
04437             } else {
04438                 bot_opc = (float)0.;
04439             };
04440     
04441     
04442     shade_index=num_materials*1*ShortField(botRLEdata,norm_offset);
04443     weight_index = num_materials * ByteField(botRLEdata, wgt_offset);
04444     
04445         
04446         
04447     bot_clr = 
04448     shade_table[shade_index + 1*0 + 0] * 
04449         ((num_materials > 1) ? weight_table[weight_index] : (float)1.0);
04450         
04451         bot_sclr = 
04452     shadow_table[shade_index + 1*0 + 0] * 
04453         ((num_materials > 1) ? weight_table[weight_index] : (float)1.0);
04454         for (m = 1; m < num_materials; m++) {
04455              
04456         
04457     bot_clr += 
04458     shade_table[shade_index + 1*m + 0] * 
04459         weight_table[weight_index + m];
04460         
04461         bot_sclr += 
04462     shadow_table[shade_index + 1*m + 0] * 
04463         weight_table[weight_index + m];
04464         };
04465     shade_factor = bot_opc * slice_depth_cueing;
04466     
04467         bot_clr *= shade_factor;
04468     
04469             bot_sclr *= shade_factor;
04470                     
04471        acc_opc += top_opc * wgtTR;
04472        acc_clr += (top_clr + top_sclr *
04473                             ((float)1.0 - shadow_pixel->opcflt)) * wgtTR;
04474        
04475 #ifdef DEBUG
04476     if (ipixel == trace_pixel_ptr) {
04477         trace_opcTR = top_opc;
04478         trace_rclrTR = top_clr;
04479         trace_rsclrTR = top_sclr;
04480     }
04481 #endif
04482 ;
04483                     
04484        acc_opc += bot_opc * wgtBR;
04485        acc_clr += (bot_clr + bot_sclr *
04486                             ((float)1.0 - shadow_pixel->opcflt)) * wgtBR;
04487        
04488 #ifdef DEBUG
04489     if (ipixel == trace_pixel_ptr) {
04490         trace_opcBR = bot_opc;
04491         trace_rclrBR = bot_clr;
04492         trace_rsclrBR = bot_sclr;
04493     }
04494 #endif
04495 ;
04496                     
04497         COUNT_RESAMPLE;
04498         if (acc_opc > min_opacity) {
04499             COUNT_COMPOSITE;
04500             iopc = ipixel->opcflt;
04501 #           ifndef SKIP_ERT
04502                 ASSERT(iopc < max_opacity);
04503 #           endif
04504             iopc_inv = (float)1. - iopc;
04505             ipixel->clrflt += acc_clr * iopc_inv;
04506             iopc += acc_opc * iopc_inv;
04507             ipixel->opcflt = iopc;
04508             
04509 #ifdef DEBUG
04510     if (ipixel == trace_pixel_ptr) {
04511 #ifdef COMPUTE_SHADOW_BUFFER
04512         printf("{%3d}  %3d %3d", k, icount-i-count, j);
04513 #else
04514         printf("[%3d]  %3d %3d", k, icount-i-count, j);
04515 #endif
04516         printf("  %3.0f %3.0f %3.0f",trace_opcTL*255.,trace_rclrTL,wgtTL*100.);
04517         printf("  %3.0f %3.0f %3.0f",trace_opcBL*255.,trace_rclrBL,wgtBL*100.);
04518         printf("  %3.0f %3.0f %3.0f",trace_opcTR*255.,trace_rclrTR,wgtTR*100.);
04519         printf("  %3.0f %3.0f %3.0f",trace_opcBR*255.,trace_rclrBR,wgtBR*100.);
04520         printf("  %3.0f %3.0f\n", iopc*255., 
04521                ipixel->clrflt);
04522         
04523         printf("              ");
04524         printf("      %3.0f    ",trace_rsclrTL);
04525         printf("      %3.0f    ",trace_rsclrBL);
04526         printf("      %3.0f    ",trace_rsclrTR);
04527         printf("      %3.0f    ",trace_rsclrBR);
04528         printf("  %3.0f\n", shadow_pixel->opcflt * 255.);
04529         
04530     }
04531 #endif /* DEBUG */
04532 ;
04533 #           ifndef SKIP_ERT
04534                 if (iopc >= max_opacity) {
04535                     ASSERT(ipixel->lnk == 0);
04536                     ipixel->lnk = 1;
04537                 }
04538 #           endif
04539         };
04540                     ipixel += 1; shadow_pixel += 1;
04541                     topRLEdata += 1 * voxel_istride;
04542                     botRLEdata += 1 * voxel_istride;
04543                     count--;
04544                     SET_VOXELS_LOADED;
04545                 }
04546                 break;
04547             case TOP_NONZERO__ALL_NONZERO:
04548                 /* first pixel: top-left, top-right and bottom-right
04549                    voxels contribute */
04550                 if (!voxels_loaded) {
04551                     
04552     
04553             opac_param = VoxelField(topRLEdata - voxel_istride, param0_offset, param0_size);
04554             opacity = param0_table[opac_param];
04555             if (param1_size != 0) {
04556                 opac_param = VoxelField(topRLEdata - voxel_istride, param1_offset, param1_size);
04557                 opacity *= param1_table[opac_param];
04558                 if (param2_size != 0) {
04559                     opac_param = VoxelField(topRLEdata - voxel_istride, param2_offset, param2_size);
04560                     opacity *= param2_table[opac_param];
04561                 }
04562             }
04563             if (opacity > min_opacity) {
04564                 opacity_int = opacity*255.;
04565                 top_opc = opac_correct[opacity_int];
04566             } else {
04567                 top_opc = (float)0.;
04568             };
04569     
04570     
04571     shade_index=num_materials*1*ShortField(topRLEdata - voxel_istride,norm_offset);
04572     weight_index = num_materials * ByteField(topRLEdata - voxel_istride, wgt_offset);
04573     
04574         
04575         
04576     top_clr = 
04577     shade_table[shade_index + 1*0 + 0] * 
04578         ((num_materials > 1) ? weight_table[weight_index] : (float)1.0);
04579         
04580         top_sclr = 
04581     shadow_table[shade_index + 1*0 + 0] * 
04582         ((num_materials > 1) ? weight_table[weight_index] : (float)1.0);
04583         for (m = 1; m < num_materials; m++) {
04584              
04585         
04586     top_clr += 
04587     shade_table[shade_index + 1*m + 0] * 
04588         weight_table[weight_index + m];
04589         
04590         top_sclr += 
04591     shadow_table[shade_index + 1*m + 0] * 
04592         weight_table[weight_index + m];
04593         };
04594     shade_factor = top_opc * slice_depth_cueing;
04595     
04596         top_clr *= shade_factor;
04597     
04598             top_sclr *= shade_factor;
04599                 }
04600                 
04601 #ifdef DEBUG
04602     if (ipixel == trace_pixel_ptr) {
04603         trace_opcTL = 0.; trace_opcBL = 0.; trace_opcTR = 0.; trace_opcBR = 0.;
04604         trace_rsclrTL=0.; trace_rsclrBL=0.; trace_rsclrTR=0.; trace_rsclrBR=0.;
04605         trace_rclrTL= 0.; trace_rclrBL= 0.; trace_rclrTR= 0.; trace_rclrBR= 0.;
04606         trace_gclrTL= 0.; trace_gclrBL= 0.; trace_gclrTR= 0.; trace_gclrBR= 0.;
04607         trace_bclrTL= 0.; trace_bclrBL= 0.; trace_bclrTR= 0.; trace_bclrBR= 0.;
04608     }
04609 #endif
04610 ;
04611                 
04612        acc_opc = top_opc * wgtTL;
04613        acc_clr = (top_clr + top_sclr *
04614                             ((float)1.0 - shadow_pixel->opcflt)) * wgtTL;
04615        
04616 #ifdef DEBUG
04617     if (ipixel == trace_pixel_ptr) {
04618         trace_opcTL = top_opc;
04619         trace_rclrTL = top_clr;
04620         trace_rsclrTL = top_sclr;
04621     }
04622 #endif
04623 ;
04624                 
04625     
04626             opac_param = VoxelField(topRLEdata, param0_offset, param0_size);
04627             opacity = param0_table[opac_param];
04628             if (param1_size != 0) {
04629                 opac_param = VoxelField(topRLEdata, param1_offset, param1_size);
04630                 opacity *= param1_table[opac_param];
04631                 if (param2_size != 0) {
04632                     opac_param = VoxelField(topRLEdata, param2_offset, param2_size);
04633                     opacity *= param2_table[opac_param];
04634                 }
04635             }
04636             if (opacity > min_opacity) {
04637                 opacity_int = opacity*255.;
04638                 top_opc = opac_correct[opacity_int];
04639             } else {
04640                 top_opc = (float)0.;
04641             };
04642     
04643     
04644     shade_index=num_materials*1*ShortField(topRLEdata,norm_offset);
04645     weight_index = num_materials * ByteField(topRLEdata, wgt_offset);
04646     
04647         
04648         
04649     top_clr = 
04650     shade_table[shade_index + 1*0 + 0] * 
04651         ((num_materials > 1) ? weight_table[weight_index] : (float)1.0);
04652         
04653         top_sclr = 
04654     shadow_table[shade_index + 1*0 + 0] * 
04655         ((num_materials > 1) ? weight_table[weight_index] : (float)1.0);
04656         for (m = 1; m < num_materials; m++) {
04657              
04658         
04659     top_clr += 
04660     shade_table[shade_index + 1*m + 0] * 
04661         weight_table[weight_index + m];
04662         
04663         top_sclr += 
04664     shadow_table[shade_index + 1*m + 0] * 
04665         weight_table[weight_index + m];
04666         };
04667     shade_factor = top_opc * slice_depth_cueing;
04668     
04669         top_clr *= shade_factor;
04670     
04671             top_sclr *= shade_factor;
04672                 
04673     
04674             opac_param = VoxelField(botRLEdata, param0_offset, param0_size);
04675             opacity = param0_table[opac_param];
04676             if (param1_size != 0) {
04677                 opac_param = VoxelField(botRLEdata, param1_offset, param1_size);
04678                 opacity *= param1_table[opac_param];
04679                 if (param2_size != 0) {
04680                     opac_param = VoxelField(botRLEdata, param2_offset, param2_size);
04681                     opacity *= param2_table[opac_param];
04682                 }
04683             }
04684             if (opacity > min_opacity) {
04685                 opacity_int = opacity*255.;
04686                 bot_opc = opac_correct[opacity_int];
04687             } else {
04688                 bot_opc = (float)0.;
04689             };
04690     
04691     
04692     shade_index=num_materials*1*ShortField(botRLEdata,norm_offset);
04693     weight_index = num_materials * ByteField(botRLEdata, wgt_offset);
04694     
04695         
04696         
04697     bot_clr = 
04698     shade_table[shade_index + 1*0 + 0] * 
04699         ((num_materials > 1) ? weight_table[weight_index] : (float)1.0);
04700         
04701         bot_sclr = 
04702     shadow_table[shade_index + 1*0 + 0] * 
04703         ((num_materials > 1) ? weight_table[weight_index] : (float)1.0);
04704         for (m = 1; m < num_materials; m++) {
04705              
04706         
04707     bot_clr += 
04708     shade_table[shade_index + 1*m + 0] * 
04709         weight_table[weight_index + m];
04710         
04711         bot_sclr += 
04712     shadow_table[shade_index + 1*m + 0] * 
04713         weight_table[weight_index + m];
04714         };
04715     shade_factor = bot_opc * slice_depth_cueing;
04716     
04717         bot_clr *= shade_factor;
04718     
04719             bot_sclr *= shade_factor;
04720                 
04721        acc_opc += top_opc * wgtTR;
04722        acc_clr += (top_clr + top_sclr *
04723                             ((float)1.0 - shadow_pixel->opcflt)) * wgtTR;
04724        
04725 #ifdef DEBUG
04726     if (ipixel == trace_pixel_ptr) {
04727         trace_opcTR = top_opc;
04728         trace_rclrTR = top_clr;
04729         trace_rsclrTR = top_sclr;
04730     }
04731 #endif
04732 ;
04733                 
04734        acc_opc += bot_opc * wgtBR;
04735        acc_clr += (bot_clr + bot_sclr *
04736                             ((float)1.0 - shadow_pixel->opcflt)) * wgtBR;
04737        
04738 #ifdef DEBUG
04739     if (ipixel == trace_pixel_ptr) {
04740         trace_opcBR = bot_opc;
04741         trace_rclrBR = bot_clr;
04742         trace_rsclrBR = bot_sclr;
04743     }
04744 #endif
04745 ;
04746                 
04747         COUNT_RESAMPLE;
04748         if (acc_opc > min_opacity) {
04749             COUNT_COMPOSITE;
04750             iopc = ipixel->opcflt;
04751 #           ifndef SKIP_ERT
04752                 ASSERT(iopc < max_opacity);
04753 #           endif
04754             iopc_inv = (float)1. - iopc;
04755             ipixel->clrflt += acc_clr * iopc_inv;
04756             iopc += acc_opc * iopc_inv;
04757             ipixel->opcflt = iopc;
04758             
04759 #ifdef DEBUG
04760     if (ipixel == trace_pixel_ptr) {
04761 #ifdef COMPUTE_SHADOW_BUFFER
04762         printf("{%3d}  %3d %3d", k, icount-i-count, j);
04763 #else
04764         printf("[%3d]  %3d %3d", k, icount-i-count, j);
04765 #endif
04766         printf("  %3.0f %3.0f %3.0f",trace_opcTL*255.,trace_rclrTL,wgtTL*100.);
04767         printf("  %3.0f %3.0f %3.0f",trace_opcBL*255.,trace_rclrBL,wgtBL*100.);
04768         printf("  %3.0f %3.0f %3.0f",trace_opcTR*255.,trace_rclrTR,wgtTR*100.);
04769         printf("  %3.0f %3.0f %3.0f",trace_opcBR*255.,trace_rclrBR,wgtBR*100.);
04770         printf("  %3.0f %3.0f\n", iopc*255., 
04771                ipixel->clrflt);
04772         
04773         printf("              ");
04774         printf("      %3.0f    ",trace_rsclrTL);
04775         printf("      %3.0f    ",trace_rsclrBL);
04776         printf("      %3.0f    ",trace_rsclrTR);
04777         printf("      %3.0f    ",trace_rsclrBR);
04778         printf("  %3.0f\n", shadow_pixel->opcflt * 255.);
04779         
04780     }
04781 #endif /* DEBUG */
04782 ;
04783 #           ifndef SKIP_ERT
04784                 if (iopc >= max_opacity) {
04785                     ASSERT(ipixel->lnk == 0);
04786                     ipixel->lnk = 1;
04787                 }
04788 #           endif
04789         };
04790                 ipixel += 1; shadow_pixel += 1;
04791                 topRLEdata += 1 * voxel_istride;
04792                 botRLEdata += 1 * voxel_istride;
04793                 count--;
04794                 SET_VOXELS_LOADED;
04795                     
04796                 /* do the rest of the pixels in this run;
04797                    all four voxels contribute */
04798                 while (count > 0) {
04799                     if (PIXEL_IS_OPAQUE(ipixel))
04800                         break;
04801                     if (!voxels_loaded) {
04802                         
04803     
04804             opac_param = VoxelField(topRLEdata - voxel_istride, param0_offset, param0_size);
04805             opacity = param0_table[opac_param];
04806             if (param1_size != 0) {
04807                 opac_param = VoxelField(topRLEdata - voxel_istride, param1_offset, param1_size);
04808                 opacity *= param1_table[opac_param];
04809                 if (param2_size != 0) {
04810                     opac_param = VoxelField(topRLEdata - voxel_istride, param2_offset, param2_size);
04811                     opacity *= param2_table[opac_param];
04812                 }
04813             }
04814             if (opacity > min_opacity) {
04815                 opacity_int = opacity*255.;
04816                 top_opc = opac_correct[opacity_int];
04817             } else {
04818                 top_opc = (float)0.;
04819             };
04820     
04821     
04822     shade_index=num_materials*1*ShortField(topRLEdata - voxel_istride,norm_offset);
04823     weight_index = num_materials * ByteField(topRLEdata - voxel_istride, wgt_offset);
04824     
04825         
04826         
04827     top_clr = 
04828     shade_table[shade_index + 1*0 + 0] * 
04829         ((num_materials > 1) ? weight_table[weight_index] : (float)1.0);
04830         
04831         top_sclr = 
04832     shadow_table[shade_index + 1*0 + 0] * 
04833         ((num_materials > 1) ? weight_table[weight_index] : (float)1.0);
04834         for (m = 1; m < num_materials; m++) {
04835              
04836         
04837     top_clr += 
04838     shade_table[shade_index + 1*m + 0] * 
04839         weight_table[weight_index + m];
04840         
04841         top_sclr += 
04842     shadow_table[shade_index + 1*m + 0] * 
04843         weight_table[weight_index + m];
04844         };
04845     shade_factor = top_opc * slice_depth_cueing;
04846     
04847         top_clr *= shade_factor;
04848     
04849             top_sclr *= shade_factor;
04850                         
04851     
04852             opac_param = VoxelField(botRLEdata - voxel_istride, param0_offset, param0_size);
04853             opacity = param0_table[opac_param];
04854             if (param1_size != 0) {
04855                 opac_param = VoxelField(botRLEdata - voxel_istride, param1_offset, param1_size);
04856                 opacity *= param1_table[opac_param];
04857                 if (param2_size != 0) {
04858                     opac_param = VoxelField(botRLEdata - voxel_istride, param2_offset, param2_size);
04859                     opacity *= param2_table[opac_param];
04860                 }
04861             }
04862             if (opacity > min_opacity) {
04863                 opacity_int = opacity*255.;
04864                 bot_opc = opac_correct[opacity_int];
04865             } else {
04866                 bot_opc = (float)0.;
04867             };
04868     
04869     
04870     shade_index=num_materials*1*ShortField(botRLEdata - voxel_istride,norm_offset);
04871     weight_index = num_materials * ByteField(botRLEdata - voxel_istride, wgt_offset);
04872     
04873         
04874         
04875     bot_clr = 
04876     shade_table[shade_index + 1*0 + 0] * 
04877         ((num_materials > 1) ? weight_table[weight_index] : (float)1.0);
04878         
04879         bot_sclr = 
04880     shadow_table[shade_index + 1*0 + 0] * 
04881         ((num_materials > 1) ? weight_table[weight_index] : (float)1.0);
04882         for (m = 1; m < num_materials; m++) {
04883              
04884         
04885     bot_clr += 
04886     shade_table[shade_index + 1*m + 0] * 
04887         weight_table[weight_index + m];
04888         
04889         bot_sclr += 
04890     shadow_table[shade_index + 1*m + 0] * 
04891         weight_table[weight_index + m];
04892         };
04893     shade_factor = bot_opc * slice_depth_cueing;
04894     
04895         bot_clr *= shade_factor;
04896     
04897             bot_sclr *= shade_factor;
04898                     }
04899                     
04900 #ifdef DEBUG
04901     if (ipixel == trace_pixel_ptr) {
04902         trace_opcTL = 0.; trace_opcBL = 0.; trace_opcTR = 0.; trace_opcBR = 0.;
04903         trace_rsclrTL=0.; trace_rsclrBL=0.; trace_rsclrTR=0.; trace_rsclrBR=0.;
04904         trace_rclrTL= 0.; trace_rclrBL= 0.; trace_rclrTR= 0.; trace_rclrBR= 0.;
04905         trace_gclrTL= 0.; trace_gclrBL= 0.; trace_gclrTR= 0.; trace_gclrBR= 0.;
04906         trace_bclrTL= 0.; trace_bclrBL= 0.; trace_bclrTR= 0.; trace_bclrBR= 0.;
04907     }
04908 #endif
04909 ;
04910                     
04911        acc_opc = top_opc * wgtTL;
04912        acc_clr = (top_clr + top_sclr *
04913                             ((float)1.0 - shadow_pixel->opcflt)) * wgtTL;
04914        
04915 #ifdef DEBUG
04916     if (ipixel == trace_pixel_ptr) {
04917         trace_opcTL = top_opc;
04918         trace_rclrTL = top_clr;
04919         trace_rsclrTL = top_sclr;
04920     }
04921 #endif
04922 ;
04923                     
04924        acc_opc += bot_opc * wgtBL;
04925        acc_clr += (bot_clr + bot_sclr *
04926                             ((float)1.0 - shadow_pixel->opcflt)) * wgtBL;
04927        
04928 #ifdef DEBUG
04929     if (ipixel == trace_pixel_ptr) {
04930         trace_opcBL = bot_opc;
04931         trace_rclrBL = bot_clr;
04932         trace_rsclrBL = bot_sclr;
04933     }
04934 #endif
04935 ;
04936                     
04937     
04938             opac_param = VoxelField(topRLEdata, param0_offset, param0_size);
04939             opacity = param0_table[opac_param];
04940             if (param1_size != 0) {
04941                 opac_param = VoxelField(topRLEdata, param1_offset, param1_size);
04942                 opacity *= param1_table[opac_param];
04943                 if (param2_size != 0) {
04944                     opac_param = VoxelField(topRLEdata, param2_offset, param2_size);
04945                     opacity *= param2_table[opac_param];
04946                 }
04947             }
04948             if (opacity > min_opacity) {
04949                 opacity_int = opacity*255.;
04950                 top_opc = opac_correct[opacity_int];
04951             } else {
04952                 top_opc = (float)0.;
04953             };
04954     
04955     
04956     shade_index=num_materials*1*ShortField(topRLEdata,norm_offset);
04957     weight_index = num_materials * ByteField(topRLEdata, wgt_offset);
04958     
04959         
04960         
04961     top_clr = 
04962     shade_table[shade_index + 1*0 + 0] * 
04963         ((num_materials > 1) ? weight_table[weight_index] : (float)1.0);
04964         
04965         top_sclr = 
04966     shadow_table[shade_index + 1*0 + 0] * 
04967         ((num_materials > 1) ? weight_table[weight_index] : (float)1.0);
04968         for (m = 1; m < num_materials; m++) {
04969              
04970         
04971     top_clr += 
04972     shade_table[shade_index + 1*m + 0] * 
04973         weight_table[weight_index + m];
04974         
04975         top_sclr += 
04976     shadow_table[shade_index + 1*m + 0] * 
04977         weight_table[weight_index + m];
04978         };
04979     shade_factor = top_opc * slice_depth_cueing;
04980     
04981         top_clr *= shade_factor;
04982     
04983             top_sclr *= shade_factor;
04984                     
04985     
04986             opac_param = VoxelField(botRLEdata, param0_offset, param0_size);
04987             opacity = param0_table[opac_param];
04988             if (param1_size != 0) {
04989                 opac_param = VoxelField(botRLEdata, param1_offset, param1_size);
04990                 opacity *= param1_table[opac_param];
04991                 if (param2_size != 0) {
04992                     opac_param = VoxelField(botRLEdata, param2_offset, param2_size);
04993                     opacity *= param2_table[opac_param];
04994                 }
04995             }
04996             if (opacity > min_opacity) {
04997                 opacity_int = opacity*255.;
04998                 bot_opc = opac_correct[opacity_int];
04999             } else {
05000                 bot_opc = (float)0.;
05001             };
05002     
05003     
05004     shade_index=num_materials*1*ShortField(botRLEdata,norm_offset);
05005     weight_index = num_materials * ByteField(botRLEdata, wgt_offset);
05006     
05007         
05008         
05009     bot_clr = 
05010     shade_table[shade_index + 1*0 + 0] * 
05011         ((num_materials > 1) ? weight_table[weight_index] : (float)1.0);
05012         
05013         bot_sclr = 
05014     shadow_table[shade_index + 1*0 + 0] * 
05015         ((num_materials > 1) ? weight_table[weight_index] : (float)1.0);
05016         for (m = 1; m < num_materials; m++) {
05017              
05018         
05019     bot_clr += 
05020     shade_table[shade_index + 1*m + 0] * 
05021         weight_table[weight_index + m];
05022         
05023         bot_sclr += 
05024     shadow_table[shade_index + 1*m + 0] * 
05025         weight_table[weight_index + m];
05026         };
05027     shade_factor = bot_opc * slice_depth_cueing;
05028     
05029         bot_clr *= shade_factor;
05030     
05031             bot_sclr *= shade_factor;
05032                     
05033        acc_opc += top_opc * wgtTR;
05034        acc_clr += (top_clr + top_sclr *
05035                             ((float)1.0 - shadow_pixel->opcflt)) * wgtTR;
05036        
05037 #ifdef DEBUG
05038     if (ipixel == trace_pixel_ptr) {
05039         trace_opcTR = top_opc;
05040         trace_rclrTR = top_clr;
05041         trace_rsclrTR = top_sclr;
05042     }
05043 #endif
05044 ;
05045                     
05046        acc_opc += bot_opc * wgtBR;
05047        acc_clr += (bot_clr + bot_sclr *
05048                             ((float)1.0 - shadow_pixel->opcflt)) * wgtBR;
05049        
05050 #ifdef DEBUG
05051     if (ipixel == trace_pixel_ptr) {
05052         trace_opcBR = bot_opc;
05053         trace_rclrBR = bot_clr;
05054         trace_rsclrBR = bot_sclr;
05055     }
05056 #endif
05057 ;
05058                     
05059         COUNT_RESAMPLE;
05060         if (acc_opc > min_opacity) {
05061             COUNT_COMPOSITE;
05062             iopc = ipixel->opcflt;
05063 #           ifndef SKIP_ERT
05064                 ASSERT(iopc < max_opacity);
05065 #           endif
05066             iopc_inv = (float)1. - iopc;
05067             ipixel->clrflt += acc_clr * iopc_inv;
05068             iopc += acc_opc * iopc_inv;
05069             ipixel->opcflt = iopc;
05070             
05071 #ifdef DEBUG
05072     if (ipixel == trace_pixel_ptr) {
05073 #ifdef COMPUTE_SHADOW_BUFFER
05074         printf("{%3d}  %3d %3d", k, icount-i-count, j);
05075 #else
05076         printf("[%3d]  %3d %3d", k, icount-i-count, j);
05077 #endif
05078         printf("  %3.0f %3.0f %3.0f",trace_opcTL*255.,trace_rclrTL,wgtTL*100.);
05079         printf("  %3.0f %3.0f %3.0f",trace_opcBL*255.,trace_rclrBL,wgtBL*100.);
05080         printf("  %3.0f %3.0f %3.0f",trace_opcTR*255.,trace_rclrTR,wgtTR*100.);
05081         printf("  %3.0f %3.0f %3.0f",trace_opcBR*255.,trace_rclrBR,wgtBR*100.);
05082         printf("  %3.0f %3.0f\n", iopc*255., 
05083                ipixel->clrflt);
05084         
05085         printf("              ");
05086         printf("      %3.0f    ",trace_rsclrTL);
05087         printf("      %3.0f    ",trace_rsclrBL);
05088         printf("      %3.0f    ",trace_rsclrTR);
05089         printf("      %3.0f    ",trace_rsclrBR);
05090         printf("  %3.0f\n", shadow_pixel->opcflt * 255.);
05091         
05092     }
05093 #endif /* DEBUG */
05094 ;
05095 #           ifndef SKIP_ERT
05096                 if (iopc >= max_opacity) {
05097                     ASSERT(ipixel->lnk == 0);
05098                     ipixel->lnk = 1;
05099                 }
05100 #           endif
05101         };
05102                     ipixel += 1; shadow_pixel += 1;
05103                     topRLEdata += 1 * voxel_istride;
05104                     botRLEdata += 1 * voxel_istride;
05105                     count--;
05106                     SET_VOXELS_LOADED;
05107                 }
05108                 break;
05109             case BOT_NONZERO__ALL_NONZERO:
05110                 /* first pixel: bottom-left, top-right and bottom-right
05111                    voxels contribute */
05112                 if (!voxels_loaded) {
05113                     
05114     
05115             opac_param = VoxelField(botRLEdata - voxel_istride, param0_offset, param0_size);
05116             opacity = param0_table[opac_param];
05117             if (param1_size != 0) {
05118                 opac_param = VoxelField(botRLEdata - voxel_istride, param1_offset, param1_size);
05119                 opacity *= param1_table[opac_param];
05120                 if (param2_size != 0) {
05121                     opac_param = VoxelField(botRLEdata - voxel_istride, param2_offset, param2_size);
05122                     opacity *= param2_table[opac_param];
05123                 }
05124             }
05125             if (opacity > min_opacity) {
05126                 opacity_int = opacity*255.;
05127                 bot_opc = opac_correct[opacity_int];
05128             } else {
05129                 bot_opc = (float)0.;
05130             };
05131     
05132     
05133     shade_index=num_materials*1*ShortField(botRLEdata - voxel_istride,norm_offset);
05134     weight_index = num_materials * ByteField(botRLEdata - voxel_istride, wgt_offset);
05135     
05136         
05137         
05138     bot_clr = 
05139     shade_table[shade_index + 1*0 + 0] * 
05140         ((num_materials > 1) ? weight_table[weight_index] : (float)1.0);
05141         
05142         bot_sclr = 
05143     shadow_table[shade_index + 1*0 + 0] * 
05144         ((num_materials > 1) ? weight_table[weight_index] : (float)1.0);
05145         for (m = 1; m < num_materials; m++) {
05146              
05147         
05148     bot_clr += 
05149     shade_table[shade_index + 1*m + 0] * 
05150         weight_table[weight_index + m];
05151         
05152         bot_sclr += 
05153     shadow_table[shade_index + 1*m + 0] * 
05154         weight_table[weight_index + m];
05155         };
05156     shade_factor = bot_opc * slice_depth_cueing;
05157     
05158         bot_clr *= shade_factor;
05159     
05160             bot_sclr *= shade_factor;
05161                 }
05162                 
05163 #ifdef DEBUG
05164     if (ipixel == trace_pixel_ptr) {
05165         trace_opcTL = 0.; trace_opcBL = 0.; trace_opcTR = 0.; trace_opcBR = 0.;
05166         trace_rsclrTL=0.; trace_rsclrBL=0.; trace_rsclrTR=0.; trace_rsclrBR=0.;
05167         trace_rclrTL= 0.; trace_rclrBL= 0.; trace_rclrTR= 0.; trace_rclrBR= 0.;
05168         trace_gclrTL= 0.; trace_gclrBL= 0.; trace_gclrTR= 0.; trace_gclrBR= 0.;
05169         trace_bclrTL= 0.; trace_bclrBL= 0.; trace_bclrTR= 0.; trace_bclrBR= 0.;
05170     }
05171 #endif
05172 ;
05173                 
05174        acc_opc = bot_opc * wgtBL;
05175        acc_clr = (bot_clr + bot_sclr *
05176                             ((float)1.0 - shadow_pixel->opcflt)) * wgtBL;
05177        
05178 #ifdef DEBUG
05179     if (ipixel == trace_pixel_ptr) {
05180         trace_opcBL = bot_opc;
05181         trace_rclrBL = bot_clr;
05182         trace_rsclrBL = bot_sclr;
05183     }
05184 #endif
05185 ;
05186                 
05187     
05188             opac_param = VoxelField(topRLEdata, param0_offset, param0_size);
05189             opacity = param0_table[opac_param];
05190             if (param1_size != 0) {
05191                 opac_param = VoxelField(topRLEdata, param1_offset, param1_size);
05192                 opacity *= param1_table[opac_param];
05193                 if (param2_size != 0) {
05194                     opac_param = VoxelField(topRLEdata, param2_offset, param2_size);
05195                     opacity *= param2_table[opac_param];
05196                 }
05197             }
05198             if (opacity > min_opacity) {
05199                 opacity_int = opacity*255.;
05200                 top_opc = opac_correct[opacity_int];
05201             } else {
05202                 top_opc = (float)0.;
05203             };
05204     
05205     
05206     shade_index=num_materials*1*ShortField(topRLEdata,norm_offset);
05207     weight_index = num_materials * ByteField(topRLEdata, wgt_offset);
05208     
05209         
05210         
05211     top_clr = 
05212     shade_table[shade_index + 1*0 + 0] * 
05213         ((num_materials > 1) ? weight_table[weight_index] : (float)1.0);
05214         
05215         top_sclr = 
05216     shadow_table[shade_index + 1*0 + 0] * 
05217         ((num_materials > 1) ? weight_table[weight_index] : (float)1.0);
05218         for (m = 1; m < num_materials; m++) {
05219              
05220         
05221     top_clr += 
05222     shade_table[shade_index + 1*m + 0] * 
05223         weight_table[weight_index + m];
05224         
05225         top_sclr += 
05226     shadow_table[shade_index + 1*m + 0] * 
05227         weight_table[weight_index + m];
05228         };
05229     shade_factor = top_opc * slice_depth_cueing;
05230     
05231         top_clr *= shade_factor;
05232     
05233             top_sclr *= shade_factor;
05234                 
05235     
05236             opac_param = VoxelField(botRLEdata, param0_offset, param0_size);
05237             opacity = param0_table[opac_param];
05238             if (param1_size != 0) {
05239                 opac_param = VoxelField(botRLEdata, param1_offset, param1_size);
05240                 opacity *= param1_table[opac_param];
05241                 if (param2_size != 0) {
05242                     opac_param = VoxelField(botRLEdata, param2_offset, param2_size);
05243                     opacity *= param2_table[opac_param];
05244                 }
05245             }
05246             if (opacity > min_opacity) {
05247                 opacity_int = opacity*255.;
05248                 bot_opc = opac_correct[opacity_int];
05249             } else {
05250                 bot_opc = (float)0.;
05251             };
05252     
05253     
05254     shade_index=num_materials*1*ShortField(botRLEdata,norm_offset);
05255     weight_index = num_materials * ByteField(botRLEdata, wgt_offset);
05256     
05257         
05258         
05259     bot_clr = 
05260     shade_table[shade_index + 1*0 + 0] * 
05261         ((num_materials > 1) ? weight_table[weight_index] : (float)1.0);
05262         
05263         bot_sclr = 
05264     shadow_table[shade_index + 1*0 + 0] * 
05265         ((num_materials > 1) ? weight_table[weight_index] : (float)1.0);
05266         for (m = 1; m < num_materials; m++) {
05267              
05268         
05269     bot_clr += 
05270     shade_table[shade_index + 1*m + 0] * 
05271         weight_table[weight_index + m];
05272         
05273         bot_sclr += 
05274     shadow_table[shade_index + 1*m + 0] * 
05275         weight_table[weight_index + m];
05276         };
05277     shade_factor = bot_opc * slice_depth_cueing;
05278     
05279         bot_clr *= shade_factor;
05280     
05281             bot_sclr *= shade_factor;
05282                 
05283        acc_opc += top_opc * wgtTR;
05284        acc_clr += (top_clr + top_sclr *
05285                             ((float)1.0 - shadow_pixel->opcflt)) * wgtTR;
05286        
05287 #ifdef DEBUG
05288     if (ipixel == trace_pixel_ptr) {
05289         trace_opcTR = top_opc;
05290         trace_rclrTR = top_clr;
05291         trace_rsclrTR = top_sclr;
05292     }
05293 #endif
05294 ;
05295                 
05296        acc_opc += bot_opc * wgtBR;
05297        acc_clr += (bot_clr + bot_sclr *
05298                             ((float)1.0 - shadow_pixel->opcflt)) * wgtBR;
05299        
05300 #ifdef DEBUG
05301     if (ipixel == trace_pixel_ptr) {
05302         trace_opcBR = bot_opc;
05303         trace_rclrBR = bot_clr;
05304         trace_rsclrBR = bot_sclr;
05305     }
05306 #endif
05307 ;
05308                 
05309         COUNT_RESAMPLE;
05310         if (acc_opc > min_opacity) {
05311             COUNT_COMPOSITE;
05312             iopc = ipixel->opcflt;
05313 #           ifndef SKIP_ERT
05314                 ASSERT(iopc < max_opacity);
05315 #           endif
05316             iopc_inv = (float)1. - iopc;
05317             ipixel->clrflt += acc_clr * iopc_inv;
05318             iopc += acc_opc * iopc_inv;
05319             ipixel->opcflt = iopc;
05320             
05321 #ifdef DEBUG
05322     if (ipixel == trace_pixel_ptr) {
05323 #ifdef COMPUTE_SHADOW_BUFFER
05324         printf("{%3d}  %3d %3d", k, icount-i-count, j);
05325 #else
05326         printf("[%3d]  %3d %3d", k, icount-i-count, j);
05327 #endif
05328         printf("  %3.0f %3.0f %3.0f",trace_opcTL*255.,trace_rclrTL,wgtTL*100.);
05329         printf("  %3.0f %3.0f %3.0f",trace_opcBL*255.,trace_rclrBL,wgtBL*100.);
05330         printf("  %3.0f %3.0f %3.0f",trace_opcTR*255.,trace_rclrTR,wgtTR*100.);
05331         printf("  %3.0f %3.0f %3.0f",trace_opcBR*255.,trace_rclrBR,wgtBR*100.);
05332         printf("  %3.0f %3.0f\n", iopc*255., 
05333                ipixel->clrflt);
05334         
05335         printf("              ");
05336         printf("      %3.0f    ",trace_rsclrTL);
05337         printf("      %3.0f    ",trace_rsclrBL);
05338         printf("      %3.0f    ",trace_rsclrTR);
05339         printf("      %3.0f    ",trace_rsclrBR);
05340         printf("  %3.0f\n", shadow_pixel->opcflt * 255.);
05341         
05342     }
05343 #endif /* DEBUG */
05344 ;
05345 #           ifndef SKIP_ERT
05346                 if (iopc >= max_opacity) {
05347                     ASSERT(ipixel->lnk == 0);
05348                     ipixel->lnk = 1;
05349                 }
05350 #           endif
05351         };
05352                 ipixel += 1; shadow_pixel += 1;
05353                 topRLEdata += 1 * voxel_istride;
05354                 botRLEdata += 1 * voxel_istride;
05355                 count--;
05356                 SET_VOXELS_LOADED;
05357                     
05358                 /* do the rest of the pixels in this run;
05359                    all four voxels contribute */
05360                 while (count > 0) {
05361                     if (PIXEL_IS_OPAQUE(ipixel))
05362                         break;
05363                     if (!voxels_loaded) {
05364                         
05365     
05366             opac_param = VoxelField(topRLEdata - voxel_istride, param0_offset, param0_size);
05367             opacity = param0_table[opac_param];
05368             if (param1_size != 0) {
05369                 opac_param = VoxelField(topRLEdata - voxel_istride, param1_offset, param1_size);
05370                 opacity *= param1_table[opac_param];
05371                 if (param2_size != 0) {
05372                     opac_param = VoxelField(topRLEdata - voxel_istride, param2_offset, param2_size);
05373                     opacity *= param2_table[opac_param];
05374                 }
05375             }
05376             if (opacity > min_opacity) {
05377                 opacity_int = opacity*255.;
05378                 top_opc = opac_correct[opacity_int];
05379             } else {
05380                 top_opc = (float)0.;
05381             };
05382     
05383     
05384     shade_index=num_materials*1*ShortField(topRLEdata - voxel_istride,norm_offset);
05385     weight_index = num_materials * ByteField(topRLEdata - voxel_istride, wgt_offset);
05386     
05387         
05388         
05389     top_clr = 
05390     shade_table[shade_index + 1*0 + 0] * 
05391         ((num_materials > 1) ? weight_table[weight_index] : (float)1.0);
05392         
05393         top_sclr = 
05394     shadow_table[shade_index + 1*0 + 0] * 
05395         ((num_materials > 1) ? weight_table[weight_index] : (float)1.0);
05396         for (m = 1; m < num_materials; m++) {
05397              
05398         
05399     top_clr += 
05400     shade_table[shade_index + 1*m + 0] * 
05401         weight_table[weight_index + m];
05402         
05403         top_sclr += 
05404     shadow_table[shade_index + 1*m + 0] * 
05405         weight_table[weight_index + m];
05406         };
05407     shade_factor = top_opc * slice_depth_cueing;
05408     
05409         top_clr *= shade_factor;
05410     
05411             top_sclr *= shade_factor;
05412                         
05413     
05414             opac_param = VoxelField(botRLEdata - voxel_istride, param0_offset, param0_size);
05415             opacity = param0_table[opac_param];
05416             if (param1_size != 0) {
05417                 opac_param = VoxelField(botRLEdata - voxel_istride, param1_offset, param1_size);
05418                 opacity *= param1_table[opac_param];
05419                 if (param2_size != 0) {
05420                     opac_param = VoxelField(botRLEdata - voxel_istride, param2_offset, param2_size);
05421                     opacity *= param2_table[opac_param];
05422                 }
05423             }
05424             if (opacity > min_opacity) {
05425                 opacity_int = opacity*255.;
05426                 bot_opc = opac_correct[opacity_int];
05427             } else {
05428                 bot_opc = (float)0.;
05429             };
05430     
05431     
05432     shade_index=num_materials*1*ShortField(botRLEdata - voxel_istride,norm_offset);
05433     weight_index = num_materials * ByteField(botRLEdata - voxel_istride, wgt_offset);
05434     
05435         
05436         
05437     bot_clr = 
05438     shade_table[shade_index + 1*0 + 0] * 
05439         ((num_materials > 1) ? weight_table[weight_index] : (float)1.0);
05440         
05441         bot_sclr = 
05442     shadow_table[shade_index + 1*0 + 0] * 
05443         ((num_materials > 1) ? weight_table[weight_index] : (float)1.0);
05444         for (m = 1; m < num_materials; m++) {
05445              
05446         
05447     bot_clr += 
05448     shade_table[shade_index + 1*m + 0] * 
05449         weight_table[weight_index + m];
05450         
05451         bot_sclr += 
05452     shadow_table[shade_index + 1*m + 0] * 
05453         weight_table[weight_index + m];
05454         };
05455     shade_factor = bot_opc * slice_depth_cueing;
05456     
05457         bot_clr *= shade_factor;
05458     
05459             bot_sclr *= shade_factor;
05460                     }
05461                     
05462 #ifdef DEBUG
05463     if (ipixel == trace_pixel_ptr) {
05464         trace_opcTL = 0.; trace_opcBL = 0.; trace_opcTR = 0.; trace_opcBR = 0.;
05465         trace_rsclrTL=0.; trace_rsclrBL=0.; trace_rsclrTR=0.; trace_rsclrBR=0.;
05466         trace_rclrTL= 0.; trace_rclrBL= 0.; trace_rclrTR= 0.; trace_rclrBR= 0.;
05467         trace_gclrTL= 0.; trace_gclrBL= 0.; trace_gclrTR= 0.; trace_gclrBR= 0.;
05468         trace_bclrTL= 0.; trace_bclrBL= 0.; trace_bclrTR= 0.; trace_bclrBR= 0.;
05469     }
05470 #endif
05471 ;
05472                     
05473        acc_opc = top_opc * wgtTL;
05474        acc_clr = (top_clr + top_sclr *
05475                             ((float)1.0 - shadow_pixel->opcflt)) * wgtTL;
05476        
05477 #ifdef DEBUG
05478     if (ipixel == trace_pixel_ptr) {
05479         trace_opcTL = top_opc;
05480         trace_rclrTL = top_clr;
05481         trace_rsclrTL = top_sclr;
05482     }
05483 #endif
05484 ;
05485                     
05486        acc_opc += bot_opc * wgtBL;
05487        acc_clr += (bot_clr + bot_sclr *
05488                             ((float)1.0 - shadow_pixel->opcflt)) * wgtBL;
05489        
05490 #ifdef DEBUG
05491     if (ipixel == trace_pixel_ptr) {
05492         trace_opcBL = bot_opc;
05493         trace_rclrBL = bot_clr;
05494         trace_rsclrBL = bot_sclr;
05495     }
05496 #endif
05497 ;
05498                     
05499     
05500             opac_param = VoxelField(topRLEdata, param0_offset, param0_size);
05501             opacity = param0_table[opac_param];
05502             if (param1_size != 0) {
05503                 opac_param = VoxelField(topRLEdata, param1_offset, param1_size);
05504                 opacity *= param1_table[opac_param];
05505                 if (param2_size != 0) {
05506                     opac_param = VoxelField(topRLEdata, param2_offset, param2_size);
05507                     opacity *= param2_table[opac_param];
05508                 }
05509             }
05510             if (opacity > min_opacity) {
05511                 opacity_int = opacity*255.;
05512                 top_opc = opac_correct[opacity_int];
05513             } else {
05514                 top_opc = (float)0.;
05515             };
05516     
05517     
05518     shade_index=num_materials*1*ShortField(topRLEdata,norm_offset);
05519     weight_index = num_materials * ByteField(topRLEdata, wgt_offset);
05520     
05521         
05522         
05523     top_clr = 
05524     shade_table[shade_index + 1*0 + 0] * 
05525         ((num_materials > 1) ? weight_table[weight_index] : (float)1.0);
05526         
05527         top_sclr = 
05528     shadow_table[shade_index + 1*0 + 0] * 
05529         ((num_materials > 1) ? weight_table[weight_index] : (float)1.0);
05530         for (m = 1; m < num_materials; m++) {
05531              
05532         
05533     top_clr += 
05534     shade_table[shade_index + 1*m + 0] * 
05535         weight_table[weight_index + m];
05536         
05537         top_sclr += 
05538     shadow_table[shade_index + 1*m + 0] * 
05539         weight_table[weight_index + m];
05540         };
05541     shade_factor = top_opc * slice_depth_cueing;
05542     
05543         top_clr *= shade_factor;
05544     
05545             top_sclr *= shade_factor;
05546                     
05547     
05548             opac_param = VoxelField(botRLEdata, param0_offset, param0_size);
05549             opacity = param0_table[opac_param];
05550             if (param1_size != 0) {
05551                 opac_param = VoxelField(botRLEdata, param1_offset, param1_size);
05552                 opacity *= param1_table[opac_param];
05553                 if (param2_size != 0) {
05554                     opac_param = VoxelField(botRLEdata, param2_offset, param2_size);
05555                     opacity *= param2_table[opac_param];
05556                 }
05557             }
05558             if (opacity > min_opacity) {
05559                 opacity_int = opacity*255.;
05560                 bot_opc = opac_correct[opacity_int];
05561             } else {
05562                 bot_opc = (float)0.;
05563             };
05564     
05565     
05566     shade_index=num_materials*1*ShortField(botRLEdata,norm_offset);
05567     weight_index = num_materials * ByteField(botRLEdata, wgt_offset);
05568     
05569         
05570         
05571     bot_clr = 
05572     shade_table[shade_index + 1*0 + 0] * 
05573         ((num_materials > 1) ? weight_table[weight_index] : (float)1.0);
05574         
05575         bot_sclr = 
05576     shadow_table[shade_index + 1*0 + 0] * 
05577         ((num_materials > 1) ? weight_table[weight_index] : (float)1.0);
05578         for (m = 1; m < num_materials; m++) {
05579              
05580         
05581     bot_clr += 
05582     shade_table[shade_index + 1*m + 0] * 
05583         weight_table[weight_index + m];
05584         
05585         bot_sclr += 
05586     shadow_table[shade_index + 1*m + 0] * 
05587         weight_table[weight_index + m];
05588         };
05589     shade_factor = bot_opc * slice_depth_cueing;
05590     
05591         bot_clr *= shade_factor;
05592     
05593             bot_sclr *= shade_factor;
05594                     
05595        acc_opc += top_opc * wgtTR;
05596        acc_clr += (top_clr + top_sclr *
05597                             ((float)1.0 - shadow_pixel->opcflt)) * wgtTR;
05598        
05599 #ifdef DEBUG
05600     if (ipixel == trace_pixel_ptr) {
05601         trace_opcTR = top_opc;
05602         trace_rclrTR = top_clr;
05603         trace_rsclrTR = top_sclr;
05604     }
05605 #endif
05606 ;
05607                     
05608        acc_opc += bot_opc * wgtBR;
05609        acc_clr += (bot_clr + bot_sclr *
05610                             ((float)1.0 - shadow_pixel->opcflt)) * wgtBR;
05611        
05612 #ifdef DEBUG
05613     if (ipixel == trace_pixel_ptr) {
05614         trace_opcBR = bot_opc;
05615         trace_rclrBR = bot_clr;
05616         trace_rsclrBR = bot_sclr;
05617     }
05618 #endif
05619 ;
05620                     
05621         COUNT_RESAMPLE;
05622         if (acc_opc > min_opacity) {
05623             COUNT_COMPOSITE;
05624             iopc = ipixel->opcflt;
05625 #           ifndef SKIP_ERT
05626                 ASSERT(iopc < max_opacity);
05627 #           endif
05628             iopc_inv = (float)1. - iopc;
05629             ipixel->clrflt += acc_clr * iopc_inv;
05630             iopc += acc_opc * iopc_inv;
05631             ipixel->opcflt = iopc;
05632             
05633 #ifdef DEBUG
05634     if (ipixel == trace_pixel_ptr) {
05635 #ifdef COMPUTE_SHADOW_BUFFER
05636         printf("{%3d}  %3d %3d", k, icount-i-count, j);
05637 #else
05638         printf("[%3d]  %3d %3d", k, icount-i-count, j);
05639 #endif
05640         printf("  %3.0f %3.0f %3.0f",trace_opcTL*255.,trace_rclrTL,wgtTL*100.);
05641         printf("  %3.0f %3.0f %3.0f",trace_opcBL*255.,trace_rclrBL,wgtBL*100.);
05642         printf("  %3.0f %3.0f %3.0f",trace_opcTR*255.,trace_rclrTR,wgtTR*100.);
05643         printf("  %3.0f %3.0f %3.0f",trace_opcBR*255.,trace_rclrBR,wgtBR*100.);
05644         printf("  %3.0f %3.0f\n", iopc*255., 
05645                ipixel->clrflt);
05646         
05647         printf("              ");
05648         printf("      %3.0f    ",trace_rsclrTL);
05649         printf("      %3.0f    ",trace_rsclrBL);
05650         printf("      %3.0f    ",trace_rsclrTR);
05651         printf("      %3.0f    ",trace_rsclrBR);
05652         printf("  %3.0f\n", shadow_pixel->opcflt * 255.);
05653         
05654     }
05655 #endif /* DEBUG */
05656 ;
05657 #           ifndef SKIP_ERT
05658                 if (iopc >= max_opacity) {
05659                     ASSERT(ipixel->lnk == 0);
05660                     ipixel->lnk = 1;
05661                 }
05662 #           endif
05663         };
05664                     ipixel += 1; shadow_pixel += 1;
05665                     topRLEdata += 1 * voxel_istride;
05666                     botRLEdata += 1 * voxel_istride;
05667                     count--;
05668                     SET_VOXELS_LOADED;
05669                 }
05670                 break;
05671             case ALL_NONZERO__ALL_NONZERO:
05672                 /* do the pixels in this run; all four voxels contribute */
05673                 while (count > 0) {
05674                     if (PIXEL_IS_OPAQUE(ipixel))
05675                         break;
05676                     if (!voxels_loaded) {
05677                         
05678     
05679             opac_param = VoxelField(topRLEdata - voxel_istride, param0_offset, param0_size);
05680             opacity = param0_table[opac_param];
05681             if (param1_size != 0) {
05682                 opac_param = VoxelField(topRLEdata - voxel_istride, param1_offset, param1_size);
05683                 opacity *= param1_table[opac_param];
05684                 if (param2_size != 0) {
05685                     opac_param = VoxelField(topRLEdata - voxel_istride, param2_offset, param2_size);
05686                     opacity *= param2_table[opac_param];
05687                 }
05688             }
05689             if (opacity > min_opacity) {
05690                 opacity_int = opacity*255.;
05691                 top_opc = opac_correct[opacity_int];
05692             } else {
05693                 top_opc = (float)0.;
05694             };
05695     
05696     
05697     shade_index=num_materials*1*ShortField(topRLEdata - voxel_istride,norm_offset);
05698     weight_index = num_materials * ByteField(topRLEdata - voxel_istride, wgt_offset);
05699     
05700         
05701         
05702     top_clr = 
05703     shade_table[shade_index + 1*0 + 0] * 
05704         ((num_materials > 1) ? weight_table[weight_index] : (float)1.0);
05705         
05706         top_sclr = 
05707     shadow_table[shade_index + 1*0 + 0] * 
05708         ((num_materials > 1) ? weight_table[weight_index] : (float)1.0);
05709         for (m = 1; m < num_materials; m++) {
05710              
05711         
05712     top_clr += 
05713     shade_table[shade_index + 1*m + 0] * 
05714         weight_table[weight_index + m];
05715         
05716         top_sclr += 
05717     shadow_table[shade_index + 1*m + 0] * 
05718         weight_table[weight_index + m];
05719         };
05720     shade_factor = top_opc * slice_depth_cueing;
05721     
05722         top_clr *= shade_factor;
05723     
05724             top_sclr *= shade_factor;
05725                         
05726     
05727             opac_param = VoxelField(botRLEdata - voxel_istride, param0_offset, param0_size);
05728             opacity = param0_table[opac_param];
05729             if (param1_size != 0) {
05730                 opac_param = VoxelField(botRLEdata - voxel_istride, param1_offset, param1_size);
05731                 opacity *= param1_table[opac_param];
05732                 if (param2_size != 0) {
05733                     opac_param = VoxelField(botRLEdata - voxel_istride, param2_offset, param2_size);
05734                     opacity *= param2_table[opac_param];
05735                 }
05736             }
05737             if (opacity > min_opacity) {
05738                 opacity_int = opacity*255.;
05739                 bot_opc = opac_correct[opacity_int];
05740             } else {
05741                 bot_opc = (float)0.;
05742             };
05743     
05744     
05745     shade_index=num_materials*1*ShortField(botRLEdata - voxel_istride,norm_offset);
05746     weight_index = num_materials * ByteField(botRLEdata - voxel_istride, wgt_offset);
05747     
05748         
05749         
05750     bot_clr = 
05751     shade_table[shade_index + 1*0 + 0] * 
05752         ((num_materials > 1) ? weight_table[weight_index] : (float)1.0);
05753         
05754         bot_sclr = 
05755     shadow_table[shade_index + 1*0 + 0] * 
05756         ((num_materials > 1) ? weight_table[weight_index] : (float)1.0);
05757         for (m = 1; m < num_materials; m++) {
05758              
05759         
05760     bot_clr += 
05761     shade_table[shade_index + 1*m + 0] * 
05762         weight_table[weight_index + m];
05763         
05764         bot_sclr += 
05765     shadow_table[shade_index + 1*m + 0] * 
05766         weight_table[weight_index + m];
05767         };
05768     shade_factor = bot_opc * slice_depth_cueing;
05769     
05770         bot_clr *= shade_factor;
05771     
05772             bot_sclr *= shade_factor;
05773                     }
05774                     
05775 #ifdef DEBUG
05776     if (ipixel == trace_pixel_ptr) {
05777         trace_opcTL = 0.; trace_opcBL = 0.; trace_opcTR = 0.; trace_opcBR = 0.;
05778         trace_rsclrTL=0.; trace_rsclrBL=0.; trace_rsclrTR=0.; trace_rsclrBR=0.;
05779         trace_rclrTL= 0.; trace_rclrBL= 0.; trace_rclrTR= 0.; trace_rclrBR= 0.;
05780         trace_gclrTL= 0.; trace_gclrBL= 0.; trace_gclrTR= 0.; trace_gclrBR= 0.;
05781         trace_bclrTL= 0.; trace_bclrBL= 0.; trace_bclrTR= 0.; trace_bclrBR= 0.;
05782     }
05783 #endif
05784 ;
05785                     
05786        acc_opc = top_opc * wgtTL;
05787        acc_clr = (top_clr + top_sclr *
05788                             ((float)1.0 - shadow_pixel->opcflt)) * wgtTL;
05789        
05790 #ifdef DEBUG
05791     if (ipixel == trace_pixel_ptr) {
05792         trace_opcTL = top_opc;
05793         trace_rclrTL = top_clr;
05794         trace_rsclrTL = top_sclr;
05795     }
05796 #endif
05797 ;
05798                     
05799        acc_opc += bot_opc * wgtBL;
05800        acc_clr += (bot_clr + bot_sclr *
05801                             ((float)1.0 - shadow_pixel->opcflt)) * wgtBL;
05802        
05803 #ifdef DEBUG
05804     if (ipixel == trace_pixel_ptr) {
05805         trace_opcBL = bot_opc;
05806         trace_rclrBL = bot_clr;
05807         trace_rsclrBL = bot_sclr;
05808     }
05809 #endif
05810 ;
05811                     
05812     
05813             opac_param = VoxelField(topRLEdata, param0_offset, param0_size);
05814             opacity = param0_table[opac_param];
05815             if (param1_size != 0) {
05816                 opac_param = VoxelField(topRLEdata, param1_offset, param1_size);
05817                 opacity *= param1_table[opac_param];
05818                 if (param2_size != 0) {
05819                     opac_param = VoxelField(topRLEdata, param2_offset, param2_size);
05820                     opacity *= param2_table[opac_param];
05821                 }
05822             }
05823             if (opacity > min_opacity) {
05824                 opacity_int = opacity*255.;
05825                 top_opc = opac_correct[opacity_int];
05826             } else {
05827                 top_opc = (float)0.;
05828             };
05829     
05830     
05831     shade_index=num_materials*1*ShortField(topRLEdata,norm_offset);
05832     weight_index = num_materials * ByteField(topRLEdata, wgt_offset);
05833     
05834         
05835         
05836     top_clr = 
05837     shade_table[shade_index + 1*0 + 0] * 
05838         ((num_materials > 1) ? weight_table[weight_index] : (float)1.0);
05839         
05840         top_sclr = 
05841     shadow_table[shade_index + 1*0 + 0] * 
05842         ((num_materials > 1) ? weight_table[weight_index] : (float)1.0);
05843         for (m = 1; m < num_materials; m++) {
05844              
05845         
05846     top_clr += 
05847     shade_table[shade_index + 1*m + 0] * 
05848         weight_table[weight_index + m];
05849         
05850         top_sclr += 
05851     shadow_table[shade_index + 1*m + 0] * 
05852         weight_table[weight_index + m];
05853         };
05854     shade_factor = top_opc * slice_depth_cueing;
05855     
05856         top_clr *= shade_factor;
05857     
05858             top_sclr *= shade_factor;
05859                     
05860     
05861             opac_param = VoxelField(botRLEdata, param0_offset, param0_size);
05862             opacity = param0_table[opac_param];
05863             if (param1_size != 0) {
05864                 opac_param = VoxelField(botRLEdata, param1_offset, param1_size);
05865                 opacity *= param1_table[opac_param];
05866                 if (param2_size != 0) {
05867                     opac_param = VoxelField(botRLEdata, param2_offset, param2_size);
05868                     opacity *= param2_table[opac_param];
05869                 }
05870             }
05871             if (opacity > min_opacity) {
05872                 opacity_int = opacity*255.;
05873                 bot_opc = opac_correct[opacity_int];
05874             } else {
05875                 bot_opc = (float)0.;
05876             };
05877     
05878     
05879     shade_index=num_materials*1*ShortField(botRLEdata,norm_offset);
05880     weight_index = num_materials * ByteField(botRLEdata, wgt_offset);
05881     
05882         
05883         
05884     bot_clr = 
05885     shade_table[shade_index + 1*0 + 0] * 
05886         ((num_materials > 1) ? weight_table[weight_index] : (float)1.0);
05887         
05888         bot_sclr = 
05889     shadow_table[shade_index + 1*0 + 0] * 
05890         ((num_materials > 1) ? weight_table[weight_index] : (float)1.0);
05891         for (m = 1; m < num_materials; m++) {
05892              
05893         
05894     bot_clr += 
05895     shade_table[shade_index + 1*m + 0] * 
05896         weight_table[weight_index + m];
05897         
05898         bot_sclr += 
05899     shadow_table[shade_index + 1*m + 0] * 
05900         weight_table[weight_index + m];
05901         };
05902     shade_factor = bot_opc * slice_depth_cueing;
05903     
05904         bot_clr *= shade_factor;
05905     
05906             bot_sclr *= shade_factor;
05907                     
05908        acc_opc += top_opc * wgtTR;
05909        acc_clr += (top_clr + top_sclr *
05910                             ((float)1.0 - shadow_pixel->opcflt)) * wgtTR;
05911        
05912 #ifdef DEBUG
05913     if (ipixel == trace_pixel_ptr) {
05914         trace_opcTR = top_opc;
05915         trace_rclrTR = top_clr;
05916         trace_rsclrTR = top_sclr;
05917     }
05918 #endif
05919 ;
05920                     
05921        acc_opc += bot_opc * wgtBR;
05922        acc_clr += (bot_clr + bot_sclr *
05923                             ((float)1.0 - shadow_pixel->opcflt)) * wgtBR;
05924        
05925 #ifdef DEBUG
05926     if (ipixel == trace_pixel_ptr) {
05927         trace_opcBR = bot_opc;
05928         trace_rclrBR = bot_clr;
05929         trace_rsclrBR = bot_sclr;
05930     }
05931 #endif
05932 ;
05933                     
05934         COUNT_RESAMPLE;
05935         if (acc_opc > min_opacity) {
05936             COUNT_COMPOSITE;
05937             iopc = ipixel->opcflt;
05938 #           ifndef SKIP_ERT
05939                 ASSERT(iopc < max_opacity);
05940 #           endif
05941             iopc_inv = (float)1. - iopc;
05942             ipixel->clrflt += acc_clr * iopc_inv;
05943             iopc += acc_opc * iopc_inv;
05944             ipixel->opcflt = iopc;
05945             
05946 #ifdef DEBUG
05947     if (ipixel == trace_pixel_ptr) {
05948 #ifdef COMPUTE_SHADOW_BUFFER
05949         printf("{%3d}  %3d %3d", k, icount-i-count, j);
05950 #else
05951         printf("[%3d]  %3d %3d", k, icount-i-count, j);
05952 #endif
05953         printf("  %3.0f %3.0f %3.0f",trace_opcTL*255.,trace_rclrTL,wgtTL*100.);
05954         printf("  %3.0f %3.0f %3.0f",trace_opcBL*255.,trace_rclrBL,wgtBL*100.);
05955         printf("  %3.0f %3.0f %3.0f",trace_opcTR*255.,trace_rclrTR,wgtTR*100.);
05956         printf("  %3.0f %3.0f %3.0f",trace_opcBR*255.,trace_rclrBR,wgtBR*100.);
05957         printf("  %3.0f %3.0f\n", iopc*255., 
05958                ipixel->clrflt);
05959         
05960         printf("              ");
05961         printf("      %3.0f    ",trace_rsclrTL);
05962         printf("      %3.0f    ",trace_rsclrBL);
05963         printf("      %3.0f    ",trace_rsclrTR);
05964         printf("      %3.0f    ",trace_rsclrBR);
05965         printf("  %3.0f\n", shadow_pixel->opcflt * 255.);
05966         
05967     }
05968 #endif /* DEBUG */
05969 ;
05970 #           ifndef SKIP_ERT
05971                 if (iopc >= max_opacity) {
05972                     ASSERT(ipixel->lnk == 0);
05973                     ipixel->lnk = 1;
05974                 }
05975 #           endif
05976         };
05977                     ipixel += 1; shadow_pixel += 1;
05978                     topRLEdata += 1 * voxel_istride;
05979                     botRLEdata += 1 * voxel_istride;
05980                     count--;
05981                     SET_VOXELS_LOADED;
05982                 }
05983                 break;
05984             default:
05985                 VPBug("illegal value for run states in compositing loop");
05986             }
05987 #else /* UNROLL_RUN_LOOP */
05988             /* this run contains pixels, so process them */
05989             while (count > 0) {
05990                 if (last_run_state == ALL_ZERO && run_state == ALL_ZERO) {
05991                     ipixel += count; shadow_pixel += count;
05992                     if (i != -1) {
05993                         topRLEdata += count * voxel_istride;
05994                         botRLEdata += count * voxel_istride;
05995                     }
05996                     count = 0;
05997                     break;
05998                 }
05999                 if (ipixel->lnk != 0)
06000                     break;
06001                 
06002 #ifdef DEBUG
06003     if (ipixel == trace_pixel_ptr) {
06004         trace_opcTL = 0.; trace_opcBL = 0.; trace_opcTR = 0.; trace_opcBR = 0.;
06005         trace_rsclrTL=0.; trace_rsclrBL=0.; trace_rsclrTR=0.; trace_rsclrBR=0.;
06006         trace_rclrTL= 0.; trace_rclrBL= 0.; trace_rclrTR= 0.; trace_rclrBR= 0.;
06007         trace_gclrTL= 0.; trace_gclrBL= 0.; trace_gclrTR= 0.; trace_gclrBR= 0.;
06008         trace_bclrTL= 0.; trace_bclrBL= 0.; trace_bclrTR= 0.; trace_bclrBR= 0.;
06009     }
06010 #endif
06011 ;
06012                 
06013        acc_opc = 0;
06014        acc_clr = 0;
06015                 if (last_run_state & TOP_NONZERO) {
06016                     if (!voxels_loaded) {
06017                         
06018     
06019             opac_param = VoxelField(topRLEdata - voxel_istride, param0_offset, param0_size);
06020             opacity = param0_table[opac_param];
06021             if (param1_size != 0) {
06022                 opac_param = VoxelField(topRLEdata - voxel_istride, param1_offset, param1_size);
06023                 opacity *= param1_table[opac_param];
06024                 if (param2_size != 0) {
06025                     opac_param = VoxelField(topRLEdata - voxel_istride, param2_offset, param2_size);
06026                     opacity *= param2_table[opac_param];
06027                 }
06028             }
06029             if (opacity > min_opacity) {
06030                 opacity_int = opacity*255.;
06031                 top_opc = opac_correct[opacity_int];
06032             } else {
06033                 top_opc = (float)0.;
06034             };
06035     
06036     
06037     shade_index=num_materials*1*ShortField(topRLEdata - voxel_istride,norm_offset);
06038     weight_index = num_materials * ByteField(topRLEdata - voxel_istride, wgt_offset);
06039     
06040         
06041         
06042     top_clr = 
06043     shade_table[shade_index + 1*0 + 0] * 
06044         ((num_materials > 1) ? weight_table[weight_index] : (float)1.0);
06045         
06046         top_sclr = 
06047     shadow_table[shade_index + 1*0 + 0] * 
06048         ((num_materials > 1) ? weight_table[weight_index] : (float)1.0);
06049         for (m = 1; m < num_materials; m++) {
06050              
06051         
06052     top_clr += 
06053     shade_table[shade_index + 1*m + 0] * 
06054         weight_table[weight_index + m];
06055         
06056         top_sclr += 
06057     shadow_table[shade_index + 1*m + 0] * 
06058         weight_table[weight_index + m];
06059         };
06060     shade_factor = top_opc * slice_depth_cueing;
06061     
06062         top_clr *= shade_factor;
06063     
06064             top_sclr *= shade_factor;
06065                     }
06066                     
06067        acc_opc += top_opc * wgtTL;
06068        acc_clr += (top_clr + top_sclr *
06069                             ((float)1.0 - shadow_pixel->opcflt)) * wgtTL;
06070        
06071 #ifdef DEBUG
06072     if (ipixel == trace_pixel_ptr) {
06073         trace_opcTL = top_opc;
06074         trace_rclrTL = top_clr;
06075         trace_rsclrTL = top_sclr;
06076     }
06077 #endif
06078 ;
06079                 }
06080                 if (last_run_state & BOT_NONZERO) {
06081                     if (!voxels_loaded) {
06082                         
06083     
06084             opac_param = VoxelField(botRLEdata - voxel_istride, param0_offset, param0_size);
06085             opacity = param0_table[opac_param];
06086             if (param1_size != 0) {
06087                 opac_param = VoxelField(botRLEdata - voxel_istride, param1_offset, param1_size);
06088                 opacity *= param1_table[opac_param];
06089                 if (param2_size != 0) {
06090                     opac_param = VoxelField(botRLEdata - voxel_istride, param2_offset, param2_size);
06091                     opacity *= param2_table[opac_param];
06092                 }
06093             }
06094             if (opacity > min_opacity) {
06095                 opacity_int = opacity*255.;
06096                 bot_opc = opac_correct[opacity_int];
06097             } else {
06098                 bot_opc = (float)0.;
06099             };
06100     
06101     
06102     shade_index=num_materials*1*ShortField(botRLEdata - voxel_istride,norm_offset);
06103     weight_index = num_materials * ByteField(botRLEdata - voxel_istride, wgt_offset);
06104     
06105         
06106         
06107     bot_clr = 
06108     shade_table[shade_index + 1*0 + 0] * 
06109         ((num_materials > 1) ? weight_table[weight_index] : (float)1.0);
06110         
06111         bot_sclr = 
06112     shadow_table[shade_index + 1*0 + 0] * 
06113         ((num_materials > 1) ? weight_table[weight_index] : (float)1.0);
06114         for (m = 1; m < num_materials; m++) {
06115              
06116         
06117     bot_clr += 
06118     shade_table[shade_index + 1*m + 0] * 
06119         weight_table[weight_index + m];
06120         
06121         bot_sclr += 
06122     shadow_table[shade_index + 1*m + 0] * 
06123         weight_table[weight_index + m];
06124         };
06125     shade_factor = bot_opc * slice_depth_cueing;
06126     
06127         bot_clr *= shade_factor;
06128     
06129             bot_sclr *= shade_factor;
06130                     }
06131                     
06132        acc_opc += bot_opc * wgtBL;
06133        acc_clr += (bot_clr + bot_sclr *
06134                             ((float)1.0 - shadow_pixel->opcflt)) * wgtBL;
06135        
06136 #ifdef DEBUG
06137     if (ipixel == trace_pixel_ptr) {
06138         trace_opcBL = bot_opc;
06139         trace_rclrBL = bot_clr;
06140         trace_rsclrBL = bot_sclr;
06141     }
06142 #endif
06143 ;
06144                 }
06145                 if (run_state & TOP_NONZERO) {
06146                     
06147     
06148             opac_param = VoxelField(topRLEdata, param0_offset, param0_size);
06149             opacity = param0_table[opac_param];
06150             if (param1_size != 0) {
06151                 opac_param = VoxelField(topRLEdata, param1_offset, param1_size);
06152                 opacity *= param1_table[opac_param];
06153                 if (param2_size != 0) {
06154                     opac_param = VoxelField(topRLEdata, param2_offset, param2_size);
06155                     opacity *= param2_table[opac_param];
06156                 }
06157             }
06158             if (opacity > min_opacity) {
06159                 opacity_int = opacity*255.;
06160                 top_opc = opac_correct[opacity_int];
06161             } else {
06162                 top_opc = (float)0.;
06163             };
06164     
06165     
06166     shade_index=num_materials*1*ShortField(topRLEdata,norm_offset);
06167     weight_index = num_materials * ByteField(topRLEdata, wgt_offset);
06168     
06169         
06170         
06171     top_clr = 
06172     shade_table[shade_index + 1*0 + 0] * 
06173         ((num_materials > 1) ? weight_table[weight_index] : (float)1.0);
06174         
06175         top_sclr = 
06176     shadow_table[shade_index + 1*0 + 0] * 
06177         ((num_materials > 1) ? weight_table[weight_index] : (float)1.0);
06178         for (m = 1; m < num_materials; m++) {
06179              
06180         
06181     top_clr += 
06182     shade_table[shade_index + 1*m + 0] * 
06183         weight_table[weight_index + m];
06184         
06185         top_sclr += 
06186     shadow_table[shade_index + 1*m + 0] * 
06187         weight_table[weight_index + m];
06188         };
06189     shade_factor = top_opc * slice_depth_cueing;
06190     
06191         top_clr *= shade_factor;
06192     
06193             top_sclr *= shade_factor;
06194                     
06195        acc_opc += top_opc * wgtTR;
06196        acc_clr += (top_clr + top_sclr *
06197                             ((float)1.0 - shadow_pixel->opcflt)) * wgtTR;
06198        
06199 #ifdef DEBUG
06200     if (ipixel == trace_pixel_ptr) {
06201         trace_opcTR = top_opc;
06202         trace_rclrTR = top_clr;
06203         trace_rsclrTR = top_sclr;
06204     }
06205 #endif
06206 ;
06207                     topRLEdata += 1 * voxel_istride;
06208                 } else {
06209                     if (i != -1) {
06210                         topRLEdata += 1 * voxel_istride;
06211                     }
06212                 }
06213                 if (run_state & BOT_NONZERO) {
06214                     
06215     
06216             opac_param = VoxelField(botRLEdata, param0_offset, param0_size);
06217             opacity = param0_table[opac_param];
06218             if (param1_size != 0) {
06219                 opac_param = VoxelField(botRLEdata, param1_offset, param1_size);
06220                 opacity *= param1_table[opac_param];
06221                 if (param2_size != 0) {
06222                     opac_param = VoxelField(botRLEdata, param2_offset, param2_size);
06223                     opacity *= param2_table[opac_param];
06224                 }
06225             }
06226             if (opacity > min_opacity) {
06227                 opacity_int = opacity*255.;
06228                 bot_opc = opac_correct[opacity_int];
06229             } else {
06230                 bot_opc = (float)0.;
06231             };
06232     
06233     
06234     shade_index=num_materials*1*ShortField(botRLEdata,norm_offset);
06235     weight_index = num_materials * ByteField(botRLEdata, wgt_offset);
06236     
06237         
06238         
06239     bot_clr = 
06240     shade_table[shade_index + 1*0 + 0] * 
06241         ((num_materials > 1) ? weight_table[weight_index] : (float)1.0);
06242         
06243         bot_sclr = 
06244     shadow_table[shade_index + 1*0 + 0] * 
06245         ((num_materials > 1) ? weight_table[weight_index] : (float)1.0);
06246         for (m = 1; m < num_materials; m++) {
06247              
06248         
06249     bot_clr += 
06250     shade_table[shade_index + 1*m + 0] * 
06251         weight_table[weight_index + m];
06252         
06253         bot_sclr += 
06254     shadow_table[shade_index + 1*m + 0] * 
06255         weight_table[weight_index + m];
06256         };
06257     shade_factor = bot_opc * slice_depth_cueing;
06258     
06259         bot_clr *= shade_factor;
06260     
06261             bot_sclr *= shade_factor;
06262                     
06263        acc_opc += bot_opc * wgtBR;
06264        acc_clr += (bot_clr + bot_sclr *
06265                             ((float)1.0 - shadow_pixel->opcflt)) * wgtBR;
06266        
06267 #ifdef DEBUG
06268     if (ipixel == trace_pixel_ptr) {
06269         trace_opcBR = bot_opc;
06270         trace_rclrBR = bot_clr;
06271         trace_rsclrBR = bot_sclr;
06272     }
06273 #endif
06274 ;
06275                     botRLEdata += 1 * voxel_istride;
06276                 } else {
06277                     if (i != -1) {
06278                         botRLEdata += 1 * voxel_istride;
06279                     }
06280                 }
06281                 
06282         COUNT_RESAMPLE;
06283         if (acc_opc > min_opacity) {
06284             COUNT_COMPOSITE;
06285             iopc = ipixel->opcflt;
06286 #           ifndef SKIP_ERT
06287                 ASSERT(iopc < max_opacity);
06288 #           endif
06289             iopc_inv = (float)1. - iopc;
06290             ipixel->clrflt += acc_clr * iopc_inv;
06291             iopc += acc_opc * iopc_inv;
06292             ipixel->opcflt = iopc;
06293             
06294 #ifdef DEBUG
06295     if (ipixel == trace_pixel_ptr) {
06296 #ifdef COMPUTE_SHADOW_BUFFER
06297         printf("{%3d}  %3d %3d", k, icount-i-count, j);
06298 #else
06299         printf("[%3d]  %3d %3d", k, icount-i-count, j);
06300 #endif
06301         printf("  %3.0f %3.0f %3.0f",trace_opcTL*255.,trace_rclrTL,wgtTL*100.);
06302         printf("  %3.0f %3.0f %3.0f",trace_opcBL*255.,trace_rclrBL,wgtBL*100.);
06303         printf("  %3.0f %3.0f %3.0f",trace_opcTR*255.,trace_rclrTR,wgtTR*100.);
06304         printf("  %3.0f %3.0f %3.0f",trace_opcBR*255.,trace_rclrBR,wgtBR*100.);
06305         printf("  %3.0f %3.0f\n", iopc*255., 
06306                ipixel->clrflt);
06307         
06308         printf("              ");
06309         printf("      %3.0f    ",trace_rsclrTL);
06310         printf("      %3.0f    ",trace_rsclrBL);
06311         printf("      %3.0f    ",trace_rsclrTR);
06312         printf("      %3.0f    ",trace_rsclrBR);
06313         printf("  %3.0f\n", shadow_pixel->opcflt * 255.);
06314         
06315     }
06316 #endif /* DEBUG */
06317 ;
06318 #           ifndef SKIP_ERT
06319                 if (iopc >= max_opacity) {
06320                     ASSERT(ipixel->lnk == 0);
06321                     ipixel->lnk = 1;
06322                 }
06323 #           endif
06324         };
06325                 ipixel += 1; shadow_pixel += 1;
06326                 count--;
06327                 SET_VOXELS_LOADED;
06328                 last_run_state = run_state;
06329             }
06330 #endif /* UNROLL_RUN_LOOP */
06331 
06332             GET_HIRES_TIME(vpc, t1);
06333             STORE_HIRES_TIME(vpc, VPTIMER_PROCESS_VOXELS, t0, t1);
06334             COPY_HIRES_TIME(t0, t1);
06335 
06336             if (count > 0) {
06337                 Debug((vpc, VPDEBUG_COMPOSITE, "Backup(%d)\n", count));
06338                 toprun_count += count;
06339                 botrun_count += count;
06340                 i += count;
06341             }
06342 #endif /* SKIP_COMPOSITE */
06343 
06344             /***********************************************************
06345              * Go on to next voxel run.
06346              ***********************************************************/
06347 
06348             last_run_state = run_state;
06349         } /* while (i > 0) */
06350 
06351         /***************************************************************
06352          * Finish processing voxel scanline and go on to next one.
06353          ***************************************************************/
06354 
06355 #ifdef UNROLL_RUN_LOOP
06356         ASSERT(i == 0);
06357 #else
06358         ASSERT(i == -1);
06359 #endif
06360 
06361 #ifndef SKIP_COMPOSITE
06362 #ifdef UNROLL_RUN_LOOP
06363         /* do the last pixel (to the right of the last voxel) */
06364         if (last_run_state != ALL_ZERO && !PIXEL_IS_OPAQUE(ipixel)) {
06365             /* last voxels are nonzero and the pixel is not opaque yet
06366                so there is work to be done */
06367             Debug((vpc, VPDEBUG_COMPOSITE, "Run(1)End\n"));
06368             switch (last_run_state) {
06369             case TOP_NONZERO:
06370                 /* only the top-left voxel contributes */
06371                 if (!voxels_loaded) {
06372                     
06373     
06374             opac_param = VoxelField(topRLEdata - voxel_istride, param0_offset, param0_size);
06375             opacity = param0_table[opac_param];
06376             if (param1_size != 0) {
06377                 opac_param = VoxelField(topRLEdata - voxel_istride, param1_offset, param1_size);
06378                 opacity *= param1_table[opac_param];
06379                 if (param2_size != 0) {
06380                     opac_param = VoxelField(topRLEdata - voxel_istride, param2_offset, param2_size);
06381                     opacity *= param2_table[opac_param];
06382                 }
06383             }
06384             if (opacity > min_opacity) {
06385                 opacity_int = opacity*255.;
06386                 top_opc = opac_correct[opacity_int];
06387             } else {
06388                 top_opc = (float)0.;
06389             };
06390     
06391     
06392     shade_index=num_materials*1*ShortField(topRLEdata - voxel_istride,norm_offset);
06393     weight_index = num_materials * ByteField(topRLEdata - voxel_istride, wgt_offset);
06394     
06395         
06396         
06397     top_clr = 
06398     shade_table[shade_index + 1*0 + 0] * 
06399         ((num_materials > 1) ? weight_table[weight_index] : (float)1.0);
06400         
06401         top_sclr = 
06402     shadow_table[shade_index + 1*0 + 0] * 
06403         ((num_materials > 1) ? weight_table[weight_index] : (float)1.0);
06404         for (m = 1; m < num_materials; m++) {
06405              
06406         
06407     top_clr += 
06408     shade_table[shade_index + 1*m + 0] * 
06409         weight_table[weight_index + m];
06410         
06411         top_sclr += 
06412     shadow_table[shade_index + 1*m + 0] * 
06413         weight_table[weight_index + m];
06414         };
06415     shade_factor = top_opc * slice_depth_cueing;
06416     
06417         top_clr *= shade_factor;
06418     
06419             top_sclr *= shade_factor;
06420                 }
06421                 
06422 #ifdef DEBUG
06423     if (ipixel == trace_pixel_ptr) {
06424         trace_opcTL = 0.; trace_opcBL = 0.; trace_opcTR = 0.; trace_opcBR = 0.;
06425         trace_rsclrTL=0.; trace_rsclrBL=0.; trace_rsclrTR=0.; trace_rsclrBR=0.;
06426         trace_rclrTL= 0.; trace_rclrBL= 0.; trace_rclrTR= 0.; trace_rclrBR= 0.;
06427         trace_gclrTL= 0.; trace_gclrBL= 0.; trace_gclrTR= 0.; trace_gclrBR= 0.;
06428         trace_bclrTL= 0.; trace_bclrBL= 0.; trace_bclrTR= 0.; trace_bclrBR= 0.;
06429     }
06430 #endif
06431 ;
06432                 
06433        acc_opc = top_opc * wgtTL;
06434        acc_clr = (top_clr + top_sclr *
06435                             ((float)1.0 - shadow_pixel->opcflt)) * wgtTL;
06436        
06437 #ifdef DEBUG
06438     if (ipixel == trace_pixel_ptr) {
06439         trace_opcTL = top_opc;
06440         trace_rclrTL = top_clr;
06441         trace_rsclrTL = top_sclr;
06442     }
06443 #endif
06444 ;
06445                 
06446         COUNT_RESAMPLE;
06447         if (acc_opc > min_opacity) {
06448             COUNT_COMPOSITE;
06449             iopc = ipixel->opcflt;
06450 #           ifndef SKIP_ERT
06451                 ASSERT(iopc < max_opacity);
06452 #           endif
06453             iopc_inv = (float)1. - iopc;
06454             ipixel->clrflt += acc_clr * iopc_inv;
06455             iopc += acc_opc * iopc_inv;
06456             ipixel->opcflt = iopc;
06457             
06458 #ifdef DEBUG
06459     if (ipixel == trace_pixel_ptr) {
06460 #ifdef COMPUTE_SHADOW_BUFFER
06461         printf("{%3d}  %3d %3d", k, icount-i-count, j);
06462 #else
06463         printf("[%3d]  %3d %3d", k, icount-i-count, j);
06464 #endif
06465         printf("  %3.0f %3.0f %3.0f",trace_opcTL*255.,trace_rclrTL,wgtTL*100.);
06466         printf("  %3.0f %3.0f %3.0f",trace_opcBL*255.,trace_rclrBL,wgtBL*100.);
06467         printf("  %3.0f %3.0f %3.0f",trace_opcTR*255.,trace_rclrTR,wgtTR*100.);
06468         printf("  %3.0f %3.0f %3.0f",trace_opcBR*255.,trace_rclrBR,wgtBR*100.);
06469         printf("  %3.0f %3.0f\n", iopc*255., 
06470                ipixel->clrflt);
06471         
06472         printf("              ");
06473         printf("      %3.0f    ",trace_rsclrTL);
06474         printf("      %3.0f    ",trace_rsclrBL);
06475         printf("      %3.0f    ",trace_rsclrTR);
06476         printf("      %3.0f    ",trace_rsclrBR);
06477         printf("  %3.0f\n", shadow_pixel->opcflt * 255.);
06478         
06479     }
06480 #endif /* DEBUG */
06481 ;
06482 #           ifndef SKIP_ERT
06483                 if (iopc >= max_opacity) {
06484                     ASSERT(ipixel->lnk == 0);
06485                     ipixel->lnk = 1;
06486                 }
06487 #           endif
06488         };
06489                 break;
06490             case BOT_NONZERO:
06491                 /* only the bottom left voxel contributes */
06492                 if (!voxels_loaded) {
06493                     
06494     
06495             opac_param = VoxelField(botRLEdata - voxel_istride, param0_offset, param0_size);
06496             opacity = param0_table[opac_param];
06497             if (param1_size != 0) {
06498                 opac_param = VoxelField(botRLEdata - voxel_istride, param1_offset, param1_size);
06499                 opacity *= param1_table[opac_param];
06500                 if (param2_size != 0) {
06501                     opac_param = VoxelField(botRLEdata - voxel_istride, param2_offset, param2_size);
06502                     opacity *= param2_table[opac_param];
06503                 }
06504             }
06505             if (opacity > min_opacity) {
06506                 opacity_int = opacity*255.;
06507                 bot_opc = opac_correct[opacity_int];
06508             } else {
06509                 bot_opc = (float)0.;
06510             };
06511     
06512     
06513     shade_index=num_materials*1*ShortField(botRLEdata - voxel_istride,norm_offset);
06514     weight_index = num_materials * ByteField(botRLEdata - voxel_istride, wgt_offset);
06515     
06516         
06517         
06518     bot_clr = 
06519     shade_table[shade_index + 1*0 + 0] * 
06520         ((num_materials > 1) ? weight_table[weight_index] : (float)1.0);
06521         
06522         bot_sclr = 
06523     shadow_table[shade_index + 1*0 + 0] * 
06524         ((num_materials > 1) ? weight_table[weight_index] : (float)1.0);
06525         for (m = 1; m < num_materials; m++) {
06526              
06527         
06528     bot_clr += 
06529     shade_table[shade_index + 1*m + 0] * 
06530         weight_table[weight_index + m];
06531         
06532         bot_sclr += 
06533     shadow_table[shade_index + 1*m + 0] * 
06534         weight_table[weight_index + m];
06535         };
06536     shade_factor = bot_opc * slice_depth_cueing;
06537     
06538         bot_clr *= shade_factor;
06539     
06540             bot_sclr *= shade_factor;
06541                 }
06542                 
06543 #ifdef DEBUG
06544     if (ipixel == trace_pixel_ptr) {
06545         trace_opcTL = 0.; trace_opcBL = 0.; trace_opcTR = 0.; trace_opcBR = 0.;
06546         trace_rsclrTL=0.; trace_rsclrBL=0.; trace_rsclrTR=0.; trace_rsclrBR=0.;
06547         trace_rclrTL= 0.; trace_rclrBL= 0.; trace_rclrTR= 0.; trace_rclrBR= 0.;
06548         trace_gclrTL= 0.; trace_gclrBL= 0.; trace_gclrTR= 0.; trace_gclrBR= 0.;
06549         trace_bclrTL= 0.; trace_bclrBL= 0.; trace_bclrTR= 0.; trace_bclrBR= 0.;
06550     }
06551 #endif
06552 ;
06553                 
06554        acc_opc = bot_opc * wgtBL;
06555        acc_clr = (bot_clr + bot_sclr *
06556                             ((float)1.0 - shadow_pixel->opcflt)) * wgtBL;
06557        
06558 #ifdef DEBUG
06559     if (ipixel == trace_pixel_ptr) {
06560         trace_opcBL = bot_opc;
06561         trace_rclrBL = bot_clr;
06562         trace_rsclrBL = bot_sclr;
06563     }
06564 #endif
06565 ;
06566                 
06567         COUNT_RESAMPLE;
06568         if (acc_opc > min_opacity) {
06569             COUNT_COMPOSITE;
06570             iopc = ipixel->opcflt;
06571 #           ifndef SKIP_ERT
06572                 ASSERT(iopc < max_opacity);
06573 #           endif
06574             iopc_inv = (float)1. - iopc;
06575             ipixel->clrflt += acc_clr * iopc_inv;
06576             iopc += acc_opc * iopc_inv;
06577             ipixel->opcflt = iopc;
06578             
06579 #ifdef DEBUG
06580     if (ipixel == trace_pixel_ptr) {
06581 #ifdef COMPUTE_SHADOW_BUFFER
06582         printf("{%3d}  %3d %3d", k, icount-i-count, j);
06583 #else
06584         printf("[%3d]  %3d %3d", k, icount-i-count, j);
06585 #endif
06586         printf("  %3.0f %3.0f %3.0f",trace_opcTL*255.,trace_rclrTL,wgtTL*100.);
06587         printf("  %3.0f %3.0f %3.0f",trace_opcBL*255.,trace_rclrBL,wgtBL*100.);
06588         printf("  %3.0f %3.0f %3.0f",trace_opcTR*255.,trace_rclrTR,wgtTR*100.);
06589         printf("  %3.0f %3.0f %3.0f",trace_opcBR*255.,trace_rclrBR,wgtBR*100.);
06590         printf("  %3.0f %3.0f\n", iopc*255., 
06591                ipixel->clrflt);
06592         
06593         printf("              ");
06594         printf("      %3.0f    ",trace_rsclrTL);
06595         printf("      %3.0f    ",trace_rsclrBL);
06596         printf("      %3.0f    ",trace_rsclrTR);
06597         printf("      %3.0f    ",trace_rsclrBR);
06598         printf("  %3.0f\n", shadow_pixel->opcflt * 255.);
06599         
06600     }
06601 #endif /* DEBUG */
06602 ;
06603 #           ifndef SKIP_ERT
06604                 if (iopc >= max_opacity) {
06605                     ASSERT(ipixel->lnk == 0);
06606                     ipixel->lnk = 1;
06607                 }
06608 #           endif
06609         };
06610                 break;
06611             case ALL_NONZERO:
06612                 /* the top and bottom left voxels contribute */
06613                 if (!voxels_loaded) {
06614                     
06615     
06616             opac_param = VoxelField(topRLEdata - voxel_istride, param0_offset, param0_size);
06617             opacity = param0_table[opac_param];
06618             if (param1_size != 0) {
06619                 opac_param = VoxelField(topRLEdata - voxel_istride, param1_offset, param1_size);
06620                 opacity *= param1_table[opac_param];
06621                 if (param2_size != 0) {
06622                     opac_param = VoxelField(topRLEdata - voxel_istride, param2_offset, param2_size);
06623                     opacity *= param2_table[opac_param];
06624                 }
06625             }
06626             if (opacity > min_opacity) {
06627                 opacity_int = opacity*255.;
06628                 top_opc = opac_correct[opacity_int];
06629             } else {
06630                 top_opc = (float)0.;
06631             };
06632     
06633     
06634     shade_index=num_materials*1*ShortField(topRLEdata - voxel_istride,norm_offset);
06635     weight_index = num_materials * ByteField(topRLEdata - voxel_istride, wgt_offset);
06636     
06637         
06638         
06639     top_clr = 
06640     shade_table[shade_index + 1*0 + 0] * 
06641         ((num_materials > 1) ? weight_table[weight_index] : (float)1.0);
06642         
06643         top_sclr = 
06644     shadow_table[shade_index + 1*0 + 0] * 
06645         ((num_materials > 1) ? weight_table[weight_index] : (float)1.0);
06646         for (m = 1; m < num_materials; m++) {
06647              
06648         
06649     top_clr += 
06650     shade_table[shade_index + 1*m + 0] * 
06651         weight_table[weight_index + m];
06652         
06653         top_sclr += 
06654     shadow_table[shade_index + 1*m + 0] * 
06655         weight_table[weight_index + m];
06656         };
06657     shade_factor = top_opc * slice_depth_cueing;
06658     
06659         top_clr *= shade_factor;
06660     
06661             top_sclr *= shade_factor;
06662                     
06663     
06664             opac_param = VoxelField(botRLEdata - voxel_istride, param0_offset, param0_size);
06665             opacity = param0_table[opac_param];
06666             if (param1_size != 0) {
06667                 opac_param = VoxelField(botRLEdata - voxel_istride, param1_offset, param1_size);
06668                 opacity *= param1_table[opac_param];
06669                 if (param2_size != 0) {
06670                     opac_param = VoxelField(botRLEdata - voxel_istride, param2_offset, param2_size);
06671                     opacity *= param2_table[opac_param];
06672                 }
06673             }
06674             if (opacity > min_opacity) {
06675                 opacity_int = opacity*255.;
06676                 bot_opc = opac_correct[opacity_int];
06677             } else {
06678                 bot_opc = (float)0.;
06679             };
06680     
06681     
06682     shade_index=num_materials*1*ShortField(botRLEdata - voxel_istride,norm_offset);
06683     weight_index = num_materials * ByteField(botRLEdata - voxel_istride, wgt_offset);
06684     
06685         
06686         
06687     bot_clr = 
06688     shade_table[shade_index + 1*0 + 0] * 
06689         ((num_materials > 1) ? weight_table[weight_index] : (float)1.0);
06690         
06691         bot_sclr = 
06692     shadow_table[shade_index + 1*0 + 0] * 
06693         ((num_materials > 1) ? weight_table[weight_index] : (float)1.0);
06694         for (m = 1; m < num_materials; m++) {
06695              
06696         
06697     bot_clr += 
06698     shade_table[shade_index + 1*m + 0] * 
06699         weight_table[weight_index + m];
06700         
06701         bot_sclr += 
06702     shadow_table[shade_index + 1*m + 0] * 
06703         weight_table[weight_index + m];
06704         };
06705     shade_factor = bot_opc * slice_depth_cueing;
06706     
06707         bot_clr *= shade_factor;
06708     
06709             bot_sclr *= shade_factor;
06710                 }
06711                 
06712 #ifdef DEBUG
06713     if (ipixel == trace_pixel_ptr) {
06714         trace_opcTL = 0.; trace_opcBL = 0.; trace_opcTR = 0.; trace_opcBR = 0.;
06715         trace_rsclrTL=0.; trace_rsclrBL=0.; trace_rsclrTR=0.; trace_rsclrBR=0.;
06716         trace_rclrTL= 0.; trace_rclrBL= 0.; trace_rclrTR= 0.; trace_rclrBR= 0.;
06717         trace_gclrTL= 0.; trace_gclrBL= 0.; trace_gclrTR= 0.; trace_gclrBR= 0.;
06718         trace_bclrTL= 0.; trace_bclrBL= 0.; trace_bclrTR= 0.; trace_bclrBR= 0.;
06719     }
06720 #endif
06721 ;
06722                 
06723        acc_opc = top_opc * wgtTL;
06724        acc_clr = (top_clr + top_sclr *
06725                             ((float)1.0 - shadow_pixel->opcflt)) * wgtTL;
06726        
06727 #ifdef DEBUG
06728     if (ipixel == trace_pixel_ptr) {
06729         trace_opcTL = top_opc;
06730         trace_rclrTL = top_clr;
06731         trace_rsclrTL = top_sclr;
06732     }
06733 #endif
06734 ;
06735                 
06736        acc_opc += bot_opc * wgtBL;
06737        acc_clr += (bot_clr + bot_sclr *
06738                             ((float)1.0 - shadow_pixel->opcflt)) * wgtBL;
06739        
06740 #ifdef DEBUG
06741     if (ipixel == trace_pixel_ptr) {
06742         trace_opcBL = bot_opc;
06743         trace_rclrBL = bot_clr;
06744         trace_rsclrBL = bot_sclr;
06745     }
06746 #endif
06747 ;
06748                 
06749         COUNT_RESAMPLE;
06750         if (acc_opc > min_opacity) {
06751             COUNT_COMPOSITE;
06752             iopc = ipixel->opcflt;
06753 #           ifndef SKIP_ERT
06754                 ASSERT(iopc < max_opacity);
06755 #           endif
06756             iopc_inv = (float)1. - iopc;
06757             ipixel->clrflt += acc_clr * iopc_inv;
06758             iopc += acc_opc * iopc_inv;
06759             ipixel->opcflt = iopc;
06760             
06761 #ifdef DEBUG
06762     if (ipixel == trace_pixel_ptr) {
06763 #ifdef COMPUTE_SHADOW_BUFFER
06764         printf("{%3d}  %3d %3d", k, icount-i-count, j);
06765 #else
06766         printf("[%3d]  %3d %3d", k, icount-i-count, j);
06767 #endif
06768         printf("  %3.0f %3.0f %3.0f",trace_opcTL*255.,trace_rclrTL,wgtTL*100.);
06769         printf("  %3.0f %3.0f %3.0f",trace_opcBL*255.,trace_rclrBL,wgtBL*100.);
06770         printf("  %3.0f %3.0f %3.0f",trace_opcTR*255.,trace_rclrTR,wgtTR*100.);
06771         printf("  %3.0f %3.0f %3.0f",trace_opcBR*255.,trace_rclrBR,wgtBR*100.);
06772         printf("  %3.0f %3.0f\n", iopc*255., 
06773                ipixel->clrflt);
06774         
06775         printf("              ");
06776         printf("      %3.0f    ",trace_rsclrTL);
06777         printf("      %3.0f    ",trace_rsclrBL);
06778         printf("      %3.0f    ",trace_rsclrTR);
06779         printf("      %3.0f    ",trace_rsclrBR);
06780         printf("  %3.0f\n", shadow_pixel->opcflt * 255.);
06781         
06782     }
06783 #endif /* DEBUG */
06784 ;
06785 #           ifndef SKIP_ERT
06786                 if (iopc >= max_opacity) {
06787                     ASSERT(ipixel->lnk == 0);
06788                     ipixel->lnk = 1;
06789                 }
06790 #           endif
06791         };
06792                 break;
06793             default:
06794                 VPBug("illegal value for run state at end of scanline");
06795             }
06796         } else if (last_run_state == ALL_ZERO) {
06797             Debug((vpc, VPDEBUG_COMPOSITE, "ZeroSkip(1)End\n"));
06798         } else {
06799             Debug((vpc, VPDEBUG_COMPOSITE, "ERTSkip(1)End\n"));
06800         }
06801 #endif /* UNROLL_RUN_LOOP */
06802 #endif /* SKIP_COMPOSITE */
06803 
06804 #ifndef UNROLL_RUN_LOOP
06805         run_state = final_run_state;
06806 #endif
06807         /* skip over any zero-length runs remaining in this scanline */
06808         if (j != 0 && ((run_state & 1) == 0)) {
06809             toprun_count = *topRLElen++;
06810             ASSERT(toprun_count == 0);
06811         }
06812         if (j != jcount && ((run_state & 2) == 0)) {
06813             botrun_count = *botRLElen++;
06814             ASSERT(botrun_count == 0);
06815         }
06816 
06817         /* go to next intermediate image scanline */
06818 #ifdef UNROLL_RUN_LOOP
06819         ipixel += intermediate_width - icount;
06820 #ifdef USE_SHADOW_BUFFER
06821         shadow_pixel += shadow_width - icount;
06822 #endif
06823 #else /* UNROLL_RUN_LOOP */
06824         ipixel += intermediate_width - (icount+1);
06825 #ifdef USE_SHADOW_BUFFER
06826         shadow_pixel += shadow_width - (icount+1);
06827 #endif
06828 #endif /* UNROLL_RUN_LOOP */
06829 
06830         Debug((vpc, VPDEBUG_COMPOSITE, "ScanDone\n"));
06831     } /* for j */
06832 
06833     /***************************************************************
06834      * Finish processing the voxel slice.
06835      ***************************************************************/
06836 
06837     GET_HIRES_TIME(vpc, t1);
06838     STORE_HIRES_TIME(vpc, VPTIMER_TRAVERSE_RUNS, t0, t1);
06839 
06840     Debug((vpc, VPDEBUG_COMPOSITE, "SliceDone\n"));
06841 }
 

Powered by Plone

This site conforms to the following standards: