vtkFixedPointVolumeRayCastHelper.h 94.7 KB
Newer Older
1 2
/*=========================================================================

3 4
  Program:   Visualization Toolkit
  Module:    vtkFixedPointVolumeRayCastHelper.h
5

6 7 8
  Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
  All rights reserved.
  See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
9

10 11 12
     This software is distributed WITHOUT ANY WARRANTY; without even
     the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
     PURPOSE.  See the above copyright notice for more information.
13 14

=========================================================================*/
15 16 17 18 19 20 21 22 23 24
/**
 * @class   vtkFixedPointVolumeRayCastHelper
 * @brief   An abstract helper that generates images for the volume ray cast mapper
 *
 * This is the abstract superclass of all helper classes for the
 * vtkFixedPointVolumeRayCastMapper. This class should not be used directly.
 *
 * @sa
 * vtkFixedPointVolumeRayCastMapper
*/
25

26 27
#ifndef vtkFixedPointVolumeRayCastHelper_h
#define vtkFixedPointVolumeRayCastHelper_h
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78

#define VTKKWRCHelper_GetCellScalarValues( DATA, SCALE, SHIFT ) \
  A = static_cast<unsigned int >(SCALE*(*(DATA     ) + SHIFT)); \
  B = static_cast<unsigned int >(SCALE*(*(DATA+Binc) + SHIFT)); \
  C = static_cast<unsigned int >(SCALE*(*(DATA+Cinc) + SHIFT)); \
  D = static_cast<unsigned int >(SCALE*(*(DATA+Dinc) + SHIFT)); \
  E = static_cast<unsigned int >(SCALE*(*(DATA+Einc) + SHIFT)); \
  F = static_cast<unsigned int >(SCALE*(*(DATA+Finc) + SHIFT)); \
  G = static_cast<unsigned int >(SCALE*(*(DATA+Ginc) + SHIFT)); \
  H = static_cast<unsigned int >(SCALE*(*(DATA+Hinc) + SHIFT))

#define VTKKWRCHelper_GetCellScalarValuesSimple( DATA )  \
  A = static_cast<unsigned int >(*(DATA     ));          \
  B = static_cast<unsigned int >(*(DATA+Binc));          \
  C = static_cast<unsigned int >(*(DATA+Cinc));          \
  D = static_cast<unsigned int >(*(DATA+Dinc));          \
  E = static_cast<unsigned int >(*(DATA+Einc));          \
  F = static_cast<unsigned int >(*(DATA+Finc));          \
  G = static_cast<unsigned int >(*(DATA+Ginc));          \
  H = static_cast<unsigned int >(*(DATA+Hinc))

#define VTKKWRCHelper_GetCellMagnitudeValues( ABCD, EFGH )       \
  mA = static_cast<unsigned int >(*(ABCD      ));                \
  mB = static_cast<unsigned int >(*(ABCD+mBFinc));               \
  mC = static_cast<unsigned int >(*(ABCD+mCGinc));               \
  mD = static_cast<unsigned int >(*(ABCD+mDHinc));               \
  mE = static_cast<unsigned int >(*(EFGH       ));               \
  mF = static_cast<unsigned int >(*(EFGH+mBFinc));               \
  mG = static_cast<unsigned int >(*(EFGH+mCGinc));               \
  mH = static_cast<unsigned int >(*(EFGH+mDHinc))

#define VTKKWRCHelper_GetCellDirectionValues( ABCD, EFGH )      \
  normalA   = static_cast<unsigned int >(*(ABCD       ));       \
  normalB   = static_cast<unsigned int >(*(ABCD+dBFinc));       \
  normalC   = static_cast<unsigned int >(*(ABCD+dCGinc));       \
  normalD   = static_cast<unsigned int >(*(ABCD+dDHinc));       \
  normalE   = static_cast<unsigned int >(*(EFGH       ));       \
  normalF   = static_cast<unsigned int >(*(EFGH+dBFinc));       \
  normalG   = static_cast<unsigned int >(*(EFGH+dCGinc));       \
  normalH   = static_cast<unsigned int >(*(EFGH+dDHinc));

#define VTKKWRCHelper_GetCellComponentScalarValues( DATA, CIDX, SCALE, SHIFT )    \
  A[CIDX] = static_cast<unsigned int >(SCALE*(*(DATA     ) + SHIFT));             \
  B[CIDX] = static_cast<unsigned int >(SCALE*(*(DATA+Binc) + SHIFT));             \
  C[CIDX] = static_cast<unsigned int >(SCALE*(*(DATA+Cinc) + SHIFT));             \
  D[CIDX] = static_cast<unsigned int >(SCALE*(*(DATA+Dinc) + SHIFT));             \
  E[CIDX] = static_cast<unsigned int >(SCALE*(*(DATA+Einc) + SHIFT));             \
  F[CIDX] = static_cast<unsigned int >(SCALE*(*(DATA+Finc) + SHIFT));             \
  G[CIDX] = static_cast<unsigned int >(SCALE*(*(DATA+Ginc) + SHIFT));             \
  H[CIDX] = static_cast<unsigned int >(SCALE*(*(DATA+Hinc) + SHIFT))

79 80 81 82 83 84 85 86 87 88
#define VTKKWRCHelper_GetCellComponentRawScalarValues( DATA, CIDX ) \
  A[CIDX] = static_cast<unsigned int >((*(DATA     )));             \
  B[CIDX] = static_cast<unsigned int >((*(DATA+Binc)));             \
  C[CIDX] = static_cast<unsigned int >((*(DATA+Cinc)));             \
  D[CIDX] = static_cast<unsigned int >((*(DATA+Dinc)));             \
  E[CIDX] = static_cast<unsigned int >((*(DATA+Einc)));             \
  F[CIDX] = static_cast<unsigned int >((*(DATA+Finc)));             \
  G[CIDX] = static_cast<unsigned int >((*(DATA+Ginc)));             \
  H[CIDX] = static_cast<unsigned int >((*(DATA+Hinc)))

89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146
#define VTKKWRCHelper_GetCellComponentMagnitudeValues( ABCD, EFGH, CIDX )      \
  mA[CIDX] = static_cast<unsigned int >(*(ABCD       ));                       \
  mB[CIDX] = static_cast<unsigned int >(*(ABCD+mBFinc));                       \
  mC[CIDX] = static_cast<unsigned int >(*(ABCD+mCGinc));                       \
  mD[CIDX] = static_cast<unsigned int >(*(ABCD+mDHinc));                       \
  mE[CIDX] = static_cast<unsigned int >(*(EFGH       ));                       \
  mF[CIDX] = static_cast<unsigned int >(*(EFGH+mBFinc));                       \
  mG[CIDX] = static_cast<unsigned int >(*(EFGH+mCGinc));                       \
  mH[CIDX] = static_cast<unsigned int >(*(EFGH+mDHinc))

#define VTKKWRCHelper_GetCellComponentDirectionValues( ABCD, EFGH, CIDX )       \
  normalA[CIDX]   = static_cast<unsigned int >(*(ABCD       ));                 \
  normalB[CIDX]   = static_cast<unsigned int >(*(ABCD+dBFinc));                 \
  normalC[CIDX]   = static_cast<unsigned int >(*(ABCD+dCGinc));                 \
  normalD[CIDX]   = static_cast<unsigned int >(*(ABCD+dDHinc));                 \
  normalE[CIDX]   = static_cast<unsigned int >(*(EFGH       ));                 \
  normalF[CIDX]   = static_cast<unsigned int >(*(EFGH+dBFinc));                 \
  normalG[CIDX]   = static_cast<unsigned int >(*(EFGH+dCGinc));                 \
  normalH[CIDX]   = static_cast<unsigned int >(*(EFGH+dDHinc));

#define VTKKWRCHelper_ComputeWeights( POS )                                             \
  w2X = (POS[0]&VTKKW_FP_MASK);                                                         \
  w2Y = (POS[1]&VTKKW_FP_MASK);                                                         \
  w2Z = (POS[2]&VTKKW_FP_MASK);                                                         \
                                                                                        \
  w1X = ((~w2X)&VTKKW_FP_MASK);                                                         \
  w1Y = ((~w2Y)&VTKKW_FP_MASK);                                                         \
  w1Z = ((~w2Z)&VTKKW_FP_MASK);                                                         \
                                                                                        \
  w1Xw1Y = (0x4000+(w1X*w1Y))>>VTKKW_FP_SHIFT;                                          \
  w2Xw1Y = (0x4000+(w2X*w1Y))>>VTKKW_FP_SHIFT;                                          \
  w1Xw2Y = (0x4000+(w1X*w2Y))>>VTKKW_FP_SHIFT;                                          \
  w2Xw2Y = (0x4000+(w2X*w2Y))>>VTKKW_FP_SHIFT;                                          \

#define VTKKWRCHelper_InterpolateScalar( VAL )                                  \
  VAL =                                                                         \
    (0x7fff + ((A*((0x4000 + w1Xw1Y*w1Z)>>VTKKW_FP_SHIFT)) +                    \
               (B*((0x4000 + w2Xw1Y*w1Z)>>VTKKW_FP_SHIFT)) +                    \
               (C*((0x4000 + w1Xw2Y*w1Z)>>VTKKW_FP_SHIFT)) +                    \
               (D*((0x4000 + w2Xw2Y*w1Z)>>VTKKW_FP_SHIFT)) +                    \
               (E*((0x4000 + w1Xw1Y*w2Z)>>VTKKW_FP_SHIFT)) +                    \
               (F*((0x4000 + w2Xw1Y*w2Z)>>VTKKW_FP_SHIFT)) +                    \
               (G*((0x4000 + w1Xw2Y*w2Z)>>VTKKW_FP_SHIFT)) +                    \
               (H*((0x4000 + w2Xw2Y*w2Z)>>VTKKW_FP_SHIFT)))) >> VTKKW_FP_SHIFT;

#define VTKKWRCHelper_InterpolateMagnitude( VAL )                                       \
  VAL =                                                                                 \
    (0x7fff + ((mA*((0x4000 + w1Xw1Y*w1Z)>>VTKKW_FP_SHIFT)) +                           \
               (mB*((0x4000 + w2Xw1Y*w1Z)>>VTKKW_FP_SHIFT)) +                           \
               (mC*((0x4000 + w1Xw2Y*w1Z)>>VTKKW_FP_SHIFT)) +                           \
               (mD*((0x4000 + w2Xw2Y*w1Z)>>VTKKW_FP_SHIFT)) +                           \
               (mE*((0x4000 + w1Xw1Y*w2Z)>>VTKKW_FP_SHIFT)) +                           \
               (mF*((0x4000 + w2Xw1Y*w2Z)>>VTKKW_FP_SHIFT)) +                           \
               (mG*((0x4000 + w1Xw2Y*w2Z)>>VTKKW_FP_SHIFT)) +                           \
               (mH*((0x4000 + w2Xw2Y*w2Z)>>VTKKW_FP_SHIFT)))) >> VTKKW_FP_SHIFT;

#define VTKKWRCHelper_InterpolateScalarComponent( VAL, CIDX, COMPONENTS )               \
  for ( CIDX = 0; CIDX < COMPONENTS; CIDX++ )                                           \
147
  {                                                                                   \
148 149 150 151 152 153 154 155 156
    VAL[CIDX] =                                                                         \
    (0x7fff + ((A[CIDX]*((0x4000 + w1Xw1Y*w1Z)>>VTKKW_FP_SHIFT)) +                      \
               (B[CIDX]*((0x4000 + w2Xw1Y*w1Z)>>VTKKW_FP_SHIFT)) +                      \
               (C[CIDX]*((0x4000 + w1Xw2Y*w1Z)>>VTKKW_FP_SHIFT)) +                      \
               (D[CIDX]*((0x4000 + w2Xw2Y*w1Z)>>VTKKW_FP_SHIFT)) +                      \
               (E[CIDX]*((0x4000 + w1Xw1Y*w2Z)>>VTKKW_FP_SHIFT)) +                      \
               (F[CIDX]*((0x4000 + w2Xw1Y*w2Z)>>VTKKW_FP_SHIFT)) +                      \
               (G[CIDX]*((0x4000 + w1Xw2Y*w2Z)>>VTKKW_FP_SHIFT)) +                      \
               (H[CIDX]*((0x4000 + w2Xw2Y*w2Z)>>VTKKW_FP_SHIFT)))) >> VTKKW_FP_SHIFT;   \
157
  }                                                                                   \
158

159 160
#define VTKKWRCHelper_InterpolateMagnitudeComponent( VAL, CIDX, COMPONENTS )            \
  for ( CIDX = 0; CIDX < COMPONENTS; CIDX++ )                                           \
161
  {                                                                                   \
162 163 164 165 166 167 168 169 170
    VAL[CIDX] =                                                                         \
    (0x7fff + ((mA[CIDX]*((0x4000 + w1Xw1Y*w1Z)>>VTKKW_FP_SHIFT)) +                     \
               (mB[CIDX]*((0x4000 + w2Xw1Y*w1Z)>>VTKKW_FP_SHIFT)) +                     \
               (mC[CIDX]*((0x4000 + w1Xw2Y*w1Z)>>VTKKW_FP_SHIFT)) +                     \
               (mD[CIDX]*((0x4000 + w2Xw2Y*w1Z)>>VTKKW_FP_SHIFT)) +                     \
               (mE[CIDX]*((0x4000 + w1Xw1Y*w2Z)>>VTKKW_FP_SHIFT)) +                     \
               (mF[CIDX]*((0x4000 + w2Xw1Y*w2Z)>>VTKKW_FP_SHIFT)) +                     \
               (mG[CIDX]*((0x4000 + w1Xw2Y*w2Z)>>VTKKW_FP_SHIFT)) +                     \
               (mH[CIDX]*((0x4000 + w2Xw2Y*w2Z)>>VTKKW_FP_SHIFT)))) >> VTKKW_FP_SHIFT;  \
171
  }
172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326

#define VTKKWRCHelper_InterpolateShading( DTABLE, STABLE, COLOR )                                       \
  unsigned int _tmpDColor[3];                                                                           \
  unsigned int _tmpSColor[3];                                                                           \
                                                                                                        \
  _tmpDColor[0] =                                                                                       \
    (0x7fff + ((DTABLE[3*normalA] * ((0x4000 + w1Xw1Y*w1Z)>>VTKKW_FP_SHIFT)) +                          \
               (DTABLE[3*normalB] * ((0x4000 + w2Xw1Y*w1Z)>>VTKKW_FP_SHIFT)) +                          \
               (DTABLE[3*normalC] * ((0x4000 + w1Xw2Y*w1Z)>>VTKKW_FP_SHIFT)) +                          \
               (DTABLE[3*normalD] * ((0x4000 + w2Xw2Y*w1Z)>>VTKKW_FP_SHIFT)) +                          \
               (DTABLE[3*normalE] * ((0x4000 + w1Xw1Y*w2Z)>>VTKKW_FP_SHIFT)) +                          \
               (DTABLE[3*normalF] * ((0x4000 + w2Xw1Y*w2Z)>>VTKKW_FP_SHIFT)) +                          \
               (DTABLE[3*normalG] * ((0x4000 + w1Xw2Y*w2Z)>>VTKKW_FP_SHIFT)) +                          \
               (DTABLE[3*normalH] * ((0x4000 + w2Xw2Y*w2Z)>>VTKKW_FP_SHIFT)))) >> VTKKW_FP_SHIFT;       \
                                                                                                        \
  _tmpDColor[1] =                                                                                       \
    (0x7fff + ((DTABLE[3*normalA+1] * ((0x4000 + w1Xw1Y*w1Z)>>VTKKW_FP_SHIFT)) +                        \
               (DTABLE[3*normalB+1] * ((0x4000 + w2Xw1Y*w1Z)>>VTKKW_FP_SHIFT)) +                        \
               (DTABLE[3*normalC+1] * ((0x4000 + w1Xw2Y*w1Z)>>VTKKW_FP_SHIFT)) +                        \
               (DTABLE[3*normalD+1] * ((0x4000 + w2Xw2Y*w1Z)>>VTKKW_FP_SHIFT)) +                        \
               (DTABLE[3*normalE+1] * ((0x4000 + w1Xw1Y*w2Z)>>VTKKW_FP_SHIFT)) +                        \
               (DTABLE[3*normalF+1] * ((0x4000 + w2Xw1Y*w2Z)>>VTKKW_FP_SHIFT)) +                        \
               (DTABLE[3*normalG+1] * ((0x4000 + w1Xw2Y*w2Z)>>VTKKW_FP_SHIFT)) +                        \
               (DTABLE[3*normalH+1] * ((0x4000 + w2Xw2Y*w2Z)>>VTKKW_FP_SHIFT)))) >> VTKKW_FP_SHIFT;     \
                                                                                                        \
  _tmpDColor[2] =                                                                                       \
    (0x7fff + ((DTABLE[3*normalA+2] * ((0x4000 + w1Xw1Y*w1Z)>>VTKKW_FP_SHIFT)) +                        \
               (DTABLE[3*normalB+2] * ((0x4000 + w2Xw1Y*w1Z)>>VTKKW_FP_SHIFT)) +                        \
               (DTABLE[3*normalC+2] * ((0x4000 + w1Xw2Y*w1Z)>>VTKKW_FP_SHIFT)) +                        \
               (DTABLE[3*normalD+2] * ((0x4000 + w2Xw2Y*w1Z)>>VTKKW_FP_SHIFT)) +                        \
               (DTABLE[3*normalE+2] * ((0x4000 + w1Xw1Y*w2Z)>>VTKKW_FP_SHIFT)) +                        \
               (DTABLE[3*normalF+2] * ((0x4000 + w2Xw1Y*w2Z)>>VTKKW_FP_SHIFT)) +                        \
               (DTABLE[3*normalG+2] * ((0x4000 + w1Xw2Y*w2Z)>>VTKKW_FP_SHIFT)) +                        \
               (DTABLE[3*normalH+2] * ((0x4000 + w2Xw2Y*w2Z)>>VTKKW_FP_SHIFT)))) >> VTKKW_FP_SHIFT;     \
                                                                                                        \
  _tmpSColor[0] =                                                                                       \
    (0x7fff + ((STABLE[3*normalA] * ((0x4000 + w1Xw1Y*w1Z)>>VTKKW_FP_SHIFT)) +                          \
               (STABLE[3*normalB] * ((0x4000 + w2Xw1Y*w1Z)>>VTKKW_FP_SHIFT)) +                          \
               (STABLE[3*normalC] * ((0x4000 + w1Xw2Y*w1Z)>>VTKKW_FP_SHIFT)) +                          \
               (STABLE[3*normalD] * ((0x4000 + w2Xw2Y*w1Z)>>VTKKW_FP_SHIFT)) +                          \
               (STABLE[3*normalE] * ((0x4000 + w1Xw1Y*w2Z)>>VTKKW_FP_SHIFT)) +                          \
               (STABLE[3*normalF] * ((0x4000 + w2Xw1Y*w2Z)>>VTKKW_FP_SHIFT)) +                          \
               (STABLE[3*normalG] * ((0x4000 + w1Xw2Y*w2Z)>>VTKKW_FP_SHIFT)) +                          \
               (STABLE[3*normalH] * ((0x4000 + w2Xw2Y*w2Z)>>VTKKW_FP_SHIFT)))) >> VTKKW_FP_SHIFT;       \
                                                                                                        \
  _tmpSColor[1] =                                                                                       \
    (0x7fff + ((STABLE[3*normalA+1] * ((0x4000 + w1Xw1Y*w1Z)>>VTKKW_FP_SHIFT)) +                        \
               (STABLE[3*normalB+1] * ((0x4000 + w2Xw1Y*w1Z)>>VTKKW_FP_SHIFT)) +                        \
               (STABLE[3*normalC+1] * ((0x4000 + w1Xw2Y*w1Z)>>VTKKW_FP_SHIFT)) +                        \
               (STABLE[3*normalD+1] * ((0x4000 + w2Xw2Y*w1Z)>>VTKKW_FP_SHIFT)) +                        \
               (STABLE[3*normalE+1] * ((0x4000 + w1Xw1Y*w2Z)>>VTKKW_FP_SHIFT)) +                        \
               (STABLE[3*normalF+1] * ((0x4000 + w2Xw1Y*w2Z)>>VTKKW_FP_SHIFT)) +                        \
               (STABLE[3*normalG+1] * ((0x4000 + w1Xw2Y*w2Z)>>VTKKW_FP_SHIFT)) +                        \
               (STABLE[3*normalH+1] * ((0x4000 + w2Xw2Y*w2Z)>>VTKKW_FP_SHIFT)))) >> VTKKW_FP_SHIFT;     \
                                                                                                        \
  _tmpSColor[2] =                                                                                       \
    (0x7fff + ((STABLE[3*normalA+2] * ((0x4000 + w1Xw1Y*w1Z)>>VTKKW_FP_SHIFT)) +                        \
               (STABLE[3*normalB+2] * ((0x4000 + w2Xw1Y*w1Z)>>VTKKW_FP_SHIFT)) +                        \
               (STABLE[3*normalC+2] * ((0x4000 + w1Xw2Y*w1Z)>>VTKKW_FP_SHIFT)) +                        \
               (STABLE[3*normalD+2] * ((0x4000 + w2Xw2Y*w1Z)>>VTKKW_FP_SHIFT)) +                        \
               (STABLE[3*normalE+2] * ((0x4000 + w1Xw1Y*w2Z)>>VTKKW_FP_SHIFT)) +                        \
               (STABLE[3*normalF+2] * ((0x4000 + w2Xw1Y*w2Z)>>VTKKW_FP_SHIFT)) +                        \
               (STABLE[3*normalG+2] * ((0x4000 + w1Xw2Y*w2Z)>>VTKKW_FP_SHIFT)) +                        \
               (STABLE[3*normalH+2] * ((0x4000 + w2Xw2Y*w2Z)>>VTKKW_FP_SHIFT)))) >> VTKKW_FP_SHIFT;     \
                                                                                                        \
                                                                                                        \
  COLOR[0] = static_cast<unsigned short>((_tmpDColor[0]*COLOR[0]+0x7fff)>>VTKKW_FP_SHIFT);              \
  COLOR[1] = static_cast<unsigned short>((_tmpDColor[1]*COLOR[1]+0x7fff)>>VTKKW_FP_SHIFT);              \
  COLOR[2] = static_cast<unsigned short>((_tmpDColor[2]*COLOR[2]+0x7fff)>>VTKKW_FP_SHIFT);              \
  COLOR[0] += (_tmpSColor[0]*COLOR[3] + 0x7fff)>>VTKKW_FP_SHIFT;                                        \
  COLOR[1] += (_tmpSColor[1]*COLOR[3] + 0x7fff)>>VTKKW_FP_SHIFT;                                        \
  COLOR[2] += (_tmpSColor[2]*COLOR[3] + 0x7fff)>>VTKKW_FP_SHIFT;

#define VTKKWRCHelper_InterpolateShadingComponent( DTABLE, STABLE, COLOR, CIDX )                                \
  unsigned int _tmpDColor[3];                                                                                   \
  unsigned int _tmpSColor[3];                                                                                   \
                                                                                                                \
  _tmpDColor[0] =                                                                                               \
    (0x7fff + ((DTABLE[CIDX][3*normalA[CIDX]] * ((0x4000 + w1Xw1Y*w1Z)>>VTKKW_FP_SHIFT)) +                      \
               (DTABLE[CIDX][3*normalB[CIDX]] * ((0x4000 + w2Xw1Y*w1Z)>>VTKKW_FP_SHIFT)) +                      \
               (DTABLE[CIDX][3*normalC[CIDX]] * ((0x4000 + w1Xw2Y*w1Z)>>VTKKW_FP_SHIFT)) +                      \
               (DTABLE[CIDX][3*normalD[CIDX]] * ((0x4000 + w2Xw2Y*w1Z)>>VTKKW_FP_SHIFT)) +                      \
               (DTABLE[CIDX][3*normalE[CIDX]] * ((0x4000 + w1Xw1Y*w2Z)>>VTKKW_FP_SHIFT)) +                      \
               (DTABLE[CIDX][3*normalF[CIDX]] * ((0x4000 + w2Xw1Y*w2Z)>>VTKKW_FP_SHIFT)) +                      \
               (DTABLE[CIDX][3*normalG[CIDX]] * ((0x4000 + w1Xw2Y*w2Z)>>VTKKW_FP_SHIFT)) +                      \
               (DTABLE[CIDX][3*normalH[CIDX]] * ((0x4000 + w2Xw2Y*w2Z)>>VTKKW_FP_SHIFT)))) >> VTKKW_FP_SHIFT;   \
                                                                                                                \
  _tmpDColor[1] =                                                                                               \
    (0x7fff + ((DTABLE[CIDX][3*normalA[CIDX]+1] * ((0x4000 + w1Xw1Y*w1Z)>>VTKKW_FP_SHIFT)) +                    \
               (DTABLE[CIDX][3*normalB[CIDX]+1] * ((0x4000 + w2Xw1Y*w1Z)>>VTKKW_FP_SHIFT)) +                    \
               (DTABLE[CIDX][3*normalC[CIDX]+1] * ((0x4000 + w1Xw2Y*w1Z)>>VTKKW_FP_SHIFT)) +                    \
               (DTABLE[CIDX][3*normalD[CIDX]+1] * ((0x4000 + w2Xw2Y*w1Z)>>VTKKW_FP_SHIFT)) +                    \
               (DTABLE[CIDX][3*normalE[CIDX]+1] * ((0x4000 + w1Xw1Y*w2Z)>>VTKKW_FP_SHIFT)) +                    \
               (DTABLE[CIDX][3*normalF[CIDX]+1] * ((0x4000 + w2Xw1Y*w2Z)>>VTKKW_FP_SHIFT)) +                    \
               (DTABLE[CIDX][3*normalG[CIDX]+1] * ((0x4000 + w1Xw2Y*w2Z)>>VTKKW_FP_SHIFT)) +                    \
               (DTABLE[CIDX][3*normalH[CIDX]+1] * ((0x4000 + w2Xw2Y*w2Z)>>VTKKW_FP_SHIFT)))) >> VTKKW_FP_SHIFT; \
                                                                                                                \
  _tmpDColor[2] =                                                                                               \
    (0x7fff + ((DTABLE[CIDX][3*normalA[CIDX]+2] * ((0x4000 + w1Xw1Y*w1Z)>>VTKKW_FP_SHIFT)) +                    \
               (DTABLE[CIDX][3*normalB[CIDX]+2] * ((0x4000 + w2Xw1Y*w1Z)>>VTKKW_FP_SHIFT)) +                    \
               (DTABLE[CIDX][3*normalC[CIDX]+2] * ((0x4000 + w1Xw2Y*w1Z)>>VTKKW_FP_SHIFT)) +                    \
               (DTABLE[CIDX][3*normalD[CIDX]+2] * ((0x4000 + w2Xw2Y*w1Z)>>VTKKW_FP_SHIFT)) +                    \
               (DTABLE[CIDX][3*normalE[CIDX]+2] * ((0x4000 + w1Xw1Y*w2Z)>>VTKKW_FP_SHIFT)) +                    \
               (DTABLE[CIDX][3*normalF[CIDX]+2] * ((0x4000 + w2Xw1Y*w2Z)>>VTKKW_FP_SHIFT)) +                    \
               (DTABLE[CIDX][3*normalG[CIDX]+2] * ((0x4000 + w1Xw2Y*w2Z)>>VTKKW_FP_SHIFT)) +                    \
               (DTABLE[CIDX][3*normalH[CIDX]+2] * ((0x4000 + w2Xw2Y*w2Z)>>VTKKW_FP_SHIFT)))) >> VTKKW_FP_SHIFT; \
                                                                                                                \
  _tmpSColor[0] =                                                                                               \
    (0x7fff + ((STABLE[CIDX][3*normalA[CIDX]] * ((0x4000 + w1Xw1Y*w1Z)>>VTKKW_FP_SHIFT)) +                      \
               (STABLE[CIDX][3*normalB[CIDX]] * ((0x4000 + w2Xw1Y*w1Z)>>VTKKW_FP_SHIFT)) +                      \
               (STABLE[CIDX][3*normalC[CIDX]] * ((0x4000 + w1Xw2Y*w1Z)>>VTKKW_FP_SHIFT)) +                      \
               (STABLE[CIDX][3*normalD[CIDX]] * ((0x4000 + w2Xw2Y*w1Z)>>VTKKW_FP_SHIFT)) +                      \
               (STABLE[CIDX][3*normalE[CIDX]] * ((0x4000 + w1Xw1Y*w2Z)>>VTKKW_FP_SHIFT)) +                      \
               (STABLE[CIDX][3*normalF[CIDX]] * ((0x4000 + w2Xw1Y*w2Z)>>VTKKW_FP_SHIFT)) +                      \
               (STABLE[CIDX][3*normalG[CIDX]] * ((0x4000 + w1Xw2Y*w2Z)>>VTKKW_FP_SHIFT)) +                      \
               (STABLE[CIDX][3*normalH[CIDX]] * ((0x4000 + w2Xw2Y*w2Z)>>VTKKW_FP_SHIFT)))) >> VTKKW_FP_SHIFT;   \
                                                                                                                \
  _tmpSColor[1] =                                                                                               \
    (0x7fff + ((STABLE[CIDX][3*normalA[CIDX]+1] * ((0x4000 + w1Xw1Y*w1Z)>>VTKKW_FP_SHIFT)) +                    \
               (STABLE[CIDX][3*normalB[CIDX]+1] * ((0x4000 + w2Xw1Y*w1Z)>>VTKKW_FP_SHIFT)) +                    \
               (STABLE[CIDX][3*normalC[CIDX]+1] * ((0x4000 + w1Xw2Y*w1Z)>>VTKKW_FP_SHIFT)) +                    \
               (STABLE[CIDX][3*normalD[CIDX]+1] * ((0x4000 + w2Xw2Y*w1Z)>>VTKKW_FP_SHIFT)) +                    \
               (STABLE[CIDX][3*normalE[CIDX]+1] * ((0x4000 + w1Xw1Y*w2Z)>>VTKKW_FP_SHIFT)) +                    \
               (STABLE[CIDX][3*normalF[CIDX]+1] * ((0x4000 + w2Xw1Y*w2Z)>>VTKKW_FP_SHIFT)) +                    \
               (STABLE[CIDX][3*normalG[CIDX]+1] * ((0x4000 + w1Xw2Y*w2Z)>>VTKKW_FP_SHIFT)) +                    \
               (STABLE[CIDX][3*normalH[CIDX]+1] * ((0x4000 + w2Xw2Y*w2Z)>>VTKKW_FP_SHIFT)))) >> VTKKW_FP_SHIFT; \
                                                                                                                \
  _tmpSColor[2] =                                                                                               \
    (0x7fff + ((STABLE[CIDX][3*normalA[CIDX]+2] * ((0x4000 + w1Xw1Y*w1Z)>>VTKKW_FP_SHIFT)) +                    \
               (STABLE[CIDX][3*normalB[CIDX]+2] * ((0x4000 + w2Xw1Y*w1Z)>>VTKKW_FP_SHIFT)) +                    \
               (STABLE[CIDX][3*normalC[CIDX]+2] * ((0x4000 + w1Xw2Y*w1Z)>>VTKKW_FP_SHIFT)) +                    \
               (STABLE[CIDX][3*normalD[CIDX]+2] * ((0x4000 + w2Xw2Y*w1Z)>>VTKKW_FP_SHIFT)) +                    \
               (STABLE[CIDX][3*normalE[CIDX]+2] * ((0x4000 + w1Xw1Y*w2Z)>>VTKKW_FP_SHIFT)) +                    \
               (STABLE[CIDX][3*normalF[CIDX]+2] * ((0x4000 + w2Xw1Y*w2Z)>>VTKKW_FP_SHIFT)) +                    \
               (STABLE[CIDX][3*normalG[CIDX]+2] * ((0x4000 + w1Xw2Y*w2Z)>>VTKKW_FP_SHIFT)) +                    \
               (STABLE[CIDX][3*normalH[CIDX]+2] * ((0x4000 + w2Xw2Y*w2Z)>>VTKKW_FP_SHIFT)))) >> VTKKW_FP_SHIFT; \
                                                                                                                \
                                                                                                                \
  COLOR[0] = static_cast<unsigned short>((_tmpDColor[0]*COLOR[0]+0x7fff)>>VTKKW_FP_SHIFT);                      \
  COLOR[1] = static_cast<unsigned short>((_tmpDColor[1]*COLOR[1]+0x7fff)>>VTKKW_FP_SHIFT);                      \
  COLOR[2] = static_cast<unsigned short>((_tmpDColor[2]*COLOR[2]+0x7fff)>>VTKKW_FP_SHIFT);                      \
  COLOR[0] += (_tmpSColor[0]*COLOR[3] + 0x7fff)>>VTKKW_FP_SHIFT;                                                \
  COLOR[1] += (_tmpSColor[1]*COLOR[3] + 0x7fff)>>VTKKW_FP_SHIFT;                                                \
  COLOR[2] += (_tmpSColor[2]*COLOR[3] + 0x7fff)>>VTKKW_FP_SHIFT;

#define VTKKWRCHelper_LookupColorUS( COLORTABLE, SCALAROPACITYTABLE, IDX, COLOR )       \
  COLOR[3] = SCALAROPACITYTABLE[IDX];                                                   \
  if ( !COLOR[3] ) {continue;}                                                          \
  COLOR[0] = static_cast<unsigned short>                                                \
    ((COLORTABLE[3*IDX  ]*COLOR[3] + 0x7fff)>>(VTKKW_FP_SHIFT));                        \
  COLOR[1] = static_cast<unsigned short>                                                \
    ((COLORTABLE[3*IDX+1]*COLOR[3] + 0x7fff)>>(VTKKW_FP_SHIFT));                        \
  COLOR[2] = static_cast<unsigned short>                                                \
    ((COLORTABLE[3*IDX+2]*COLOR[3] + 0x7fff)>>(VTKKW_FP_SHIFT));

327 328 329 330 331 332 333
#define VTKKWRCHelper_LookupColorMax( COLORTABLE, SCALAROPACITYTABLE, IDX, COLOR )    \
  COLOR[3] = SCALAROPACITYTABLE[IDX];                                                 \
  COLOR[0] = static_cast<unsigned short>                                              \
    ((COLORTABLE[3*IDX  ]*COLOR[3] + 0x7fff)>>(VTKKW_FP_SHIFT));                      \
  COLOR[1] = static_cast<unsigned short>                                              \
    ((COLORTABLE[3*IDX+1]*COLOR[3] + 0x7fff)>>(VTKKW_FP_SHIFT));                      \
  COLOR[2] = static_cast<unsigned short>                                              \
334
    ((COLORTABLE[3*IDX+2]*COLOR[3] + 0x7fff)>>(VTKKW_FP_SHIFT));
335 336 337 338 339

#define VTKKWRCHelper_LookupDependentColorUS( COLORTABLE, SCALAROPACITYTABLE, IDX, CMPS, COLOR )        \
  {                                                                                                     \
  unsigned short _alpha;                                                                                \
  switch ( CMPS )                                                                                       \
340
  {                                                                                                   \
341 342 343 344 345 346 347 348 349 350 351 352
    case 2:                                                                                             \
      _alpha = SCALAROPACITYTABLE[IDX[1]];                                                              \
      COLOR[0] = static_cast<unsigned short>                                                            \
        ((COLORTABLE[3*IDX[0]  ]*_alpha + 0x7fff)>>(VTKKW_FP_SHIFT));                                   \
      COLOR[1] = static_cast<unsigned short>                                                            \
        ((COLORTABLE[3*IDX[0]+1]*_alpha + 0x7fff)>>(VTKKW_FP_SHIFT));                                   \
      COLOR[2] = static_cast<unsigned short>                                                            \
        ((COLORTABLE[3*IDX[0]+2]*_alpha + 0x7fff)>>(VTKKW_FP_SHIFT));                                   \
      COLOR[3] = _alpha;                                                                                \
      break;                                                                                            \
    case 4:                                                                                             \
      _alpha = SCALAROPACITYTABLE[IDX[3]];                                                              \
353 354 355
      COLOR[0] = static_cast<unsigned short>((IDX[0]*_alpha + 0x7f)>>8 );                               \
      COLOR[1] = static_cast<unsigned short>((IDX[1]*_alpha + 0x7f)>>8 );                               \
      COLOR[2] = static_cast<unsigned short>((IDX[2]*_alpha + 0x7f)>>8 );                               \
356 357
      COLOR[3] = _alpha;                                                                                \
      break;                                                                                            \
358
  }                                                                                                   \
359 360
  }

361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385
#define VTKKWRCHelper_LookupColorGOUS( CTABLE, SOTABLE, GOTABLE, IDX, IDX2, COLOR )     \
  COLOR[3] = (SOTABLE[IDX] * GOTABLE[IDX2] + 0x7fff)>>VTKKW_FP_SHIFT;                   \
  if ( !COLOR[3] ) {continue;}                                                          \
  COLOR[0] = static_cast<unsigned short>                                                \
    ((CTABLE[3*IDX  ]*COLOR[3] + 0x7fff)>>(VTKKW_FP_SHIFT));                            \
  COLOR[1] = static_cast<unsigned short>                                                \
    ((CTABLE[3*IDX+1]*COLOR[3] + 0x7fff)>>(VTKKW_FP_SHIFT));                            \
  COLOR[2] = static_cast<unsigned short>                                                \
    ((CTABLE[3*IDX+2]*COLOR[3] + 0x7fff)>>(VTKKW_FP_SHIFT));

#define VTKKWRCHelper_LookupShading( DTABLE, STABLE, NORMAL, COLOR )                            \
  COLOR[0] = static_cast<unsigned short>((DTABLE[3*NORMAL  ]*COLOR[0]+0x7fff)>>VTKKW_FP_SHIFT); \
  COLOR[1] = static_cast<unsigned short>((DTABLE[3*NORMAL+1]*COLOR[1]+0x7fff)>>VTKKW_FP_SHIFT); \
  COLOR[2] = static_cast<unsigned short>((DTABLE[3*NORMAL+2]*COLOR[2]+0x7fff)>>VTKKW_FP_SHIFT); \
  COLOR[0] += (STABLE[3*NORMAL  ]*COLOR[3] + 0x7fff)>>VTKKW_FP_SHIFT;                           \
  COLOR[1] += (STABLE[3*NORMAL+1]*COLOR[3] + 0x7fff)>>VTKKW_FP_SHIFT;                           \
  COLOR[2] += (STABLE[3*NORMAL+2]*COLOR[3] + 0x7fff)>>VTKKW_FP_SHIFT;

#define VTKKWRCHelper_LookupAndCombineIndependentColorsUS( COLORTABLE, SOTABLE,                                                 \
                                                           SCALAR, WEIGHTS,                                                     \
                                                           COMPONENTS, COLOR )                                                  \
  unsigned int _tmp[4] = {0,0,0,0};                                                                                             \
  unsigned short _alpha[4] = {0,0,0,0};                                                                                         \
  unsigned int _totalAlpha = 0;                                                                                                 \
                                                                                                                                \
386
  {for ( int _idx = 0; _idx < COMPONENTS; _idx++ )                                                                              \
387 388 389
    {                                                                                                                           \
    _alpha[_idx] = static_cast<unsigned short>(SOTABLE[_idx][SCALAR[_idx]]*WEIGHTS[_idx]);                                      \
    _totalAlpha += _alpha[_idx];                                                                                                \
390
    }}                                                                                                                          \
391 392
                                                                                                                                \
  if ( !_totalAlpha ) {continue;}                                                                                               \
393
  {for ( int _idx = 0; _idx < COMPONENTS; _idx++ )                                                                              \
394 395
    {                                                                                                                           \
    if ( _alpha[_idx] )                                                                                                         \
396
    {                                                                                                                         \
397 398 399 400
      _tmp[0] += static_cast<unsigned short>(((COLORTABLE[_idx][3*SCALAR[_idx]  ])*_alpha[_idx] + 0x7fff)>>(VTKKW_FP_SHIFT));   \
      _tmp[1] += static_cast<unsigned short>(((COLORTABLE[_idx][3*SCALAR[_idx]+1])*_alpha[_idx] + 0x7fff)>>(VTKKW_FP_SHIFT));   \
      _tmp[2] += static_cast<unsigned short>(((COLORTABLE[_idx][3*SCALAR[_idx]+2])*_alpha[_idx] + 0x7fff)>>(VTKKW_FP_SHIFT));   \
      _tmp[3] += ((_alpha[_idx]*_alpha[_idx])/_totalAlpha);                                                                     \
401
    }                                                                                                                         \
402
    }}                                                                                                                          \
403 404 405 406 407 408
  if ( !_tmp[3] ) {continue;}                                                                                                   \
  COLOR[0] = (_tmp[0]>32767)?(32767):(_tmp[0]);                                                                                 \
  COLOR[1] = (_tmp[1]>32767)?(32767):(_tmp[1]);                                                                                 \
  COLOR[2] = (_tmp[2]>32767)?(32767):(_tmp[2]);                                                                                 \
  COLOR[3] = (_tmp[3]>32767)?(32767):(_tmp[3]);

409 410
#define VTKKWRCHelper_LookupAndCombineIndependentColorsMax( COLORTABLE, SCALAROPACITYTABLE,                             \
                                                            IDX, WEIGHTS, CMPS, COLOR )                                 \
411
{                                                                                                                     \
412 413
  unsigned int _tmp[4] = {0,0,0,0};                                                                                     \
  for ( int _idx = 0; _idx < CMPS; _idx++ )                                                                             \
414
  {                                                                                                                   \
415 416 417 418 419
    unsigned short _alpha = static_cast<unsigned short>(SCALAROPACITYTABLE[_idx][IDX[_idx]]*WEIGHTS[_idx]);             \
    _tmp[0] += static_cast<unsigned short>(((COLORTABLE[_idx][3*IDX[_idx]  ])*_alpha + 0x7fff)>>(VTKKW_FP_SHIFT));      \
    _tmp[1] += static_cast<unsigned short>(((COLORTABLE[_idx][3*IDX[_idx]+1])*_alpha + 0x7fff)>>(VTKKW_FP_SHIFT));      \
    _tmp[2] += static_cast<unsigned short>(((COLORTABLE[_idx][3*IDX[_idx]+2])*_alpha + 0x7fff)>>(VTKKW_FP_SHIFT));      \
    _tmp[3] += _alpha;                                                                                                  \
420
  }                                                                                                                   \
421 422 423 424
  COLOR[0] = (_tmp[0]>32767)?(32767):(_tmp[0]);                                                                         \
  COLOR[1] = (_tmp[1]>32767)?(32767):(_tmp[1]);                                                                         \
  COLOR[2] = (_tmp[2]>32767)?(32767):(_tmp[2]);                                                                         \
  COLOR[3] = (_tmp[3]>32767)?(32767):(_tmp[3]);                                                                         \
425
}
426

427 428 429 430 431 432 433
#define VTKKWRCHelper_LookupAndCombineIndependentColorsGOUS( COLORTABLE, SOTABLE,                                               \
                                                           GOTABLE,                                                             \
                                                           SCALAR, MAG, WEIGHTS,                                                \
                                                           COMPONENTS, COLOR )                                                  \
  unsigned int _tmp[4] = {0,0,0,0};                                                                                             \
  unsigned short _alpha[4] = {0,0,0,0};                                                                                         \
  unsigned int _totalAlpha = 0;                                                                                                 \
434
  COMPONENTS = (COMPONENTS < 4) ? COMPONENTS : 4;                                                                               \
435
  {for ( int _idx = 0; _idx < COMPONENTS; _idx++ )                                                                              \
436 437 438
    {                                                                                                                           \
    _alpha[_idx] =  static_cast<unsigned short>(SOTABLE[_idx][SCALAR[_idx]]*WEIGHTS[_idx]);                                     \
    if ( _alpha[_idx] )                                                                                                         \
439
    {                                                                                                                         \
440 441
      _alpha[_idx] = static_cast<unsigned short>((_alpha[_idx]*GOTABLE[_idx][MAG[_idx]] + 0x7fff)>>(VTKKW_FP_SHIFT));           \
      _totalAlpha += _alpha[_idx];                                                                                              \
442
    }                                                                                                                         \
443
    }}                                                                                                                          \
444 445
                                                                                                                                \
  if ( !_totalAlpha ) {continue;}                                                                                               \
446
  {for ( int _idx = 0; _idx < COMPONENTS; _idx++ )                                                                              \
447 448
    {                                                                                                                           \
    if ( _alpha[_idx] )                                                                                                         \
449
    {                                                                                                                         \
450 451 452 453
      _tmp[0] += static_cast<unsigned short>(((COLORTABLE[_idx][3*SCALAR[_idx]  ])*_alpha[_idx] + 0x7fff)>>(VTKKW_FP_SHIFT));   \
      _tmp[1] += static_cast<unsigned short>(((COLORTABLE[_idx][3*SCALAR[_idx]+1])*_alpha[_idx] + 0x7fff)>>(VTKKW_FP_SHIFT));   \
      _tmp[2] += static_cast<unsigned short>(((COLORTABLE[_idx][3*SCALAR[_idx]+2])*_alpha[_idx] + 0x7fff)>>(VTKKW_FP_SHIFT));   \
      _tmp[3] += ((_alpha[_idx]*_alpha[_idx])/_totalAlpha);                                                                     \
454
    }                                                                                                                         \
455
    }}                                                                                                                          \
456 457 458 459 460 461 462 463 464 465 466 467 468 469 470
  if ( !_tmp[3] ) {continue;};                                                                                                  \
  COLOR[0] = (_tmp[0]>32767)?(32767):(_tmp[0]);                                                                                 \
  COLOR[1] = (_tmp[1]>32767)?(32767):(_tmp[1]);                                                                                 \
  COLOR[2] = (_tmp[2]>32767)?(32767):(_tmp[2]);                                                                                 \
  COLOR[3] = (_tmp[3]>32767)?(32767):(_tmp[3]);

#define VTKKWRCHelper_LookupAndCombineIndependentColorsShadeUS( COLORTABLE, SOTABLE,                                            \
                                                                DTABLE, STABLE,                                                 \
                                                                SCALAR, NORMAL, WEIGHTS,                                        \
                                                                COMPONENTS, COLOR )                                             \
  unsigned int _tmp[4] = {0,0,0,0};                                                                                             \
  unsigned int _tmpC[3];                                                                                                        \
  unsigned short _alpha[4] = {0,0,0,0};                                                                                         \
  unsigned int _totalAlpha = 0;                                                                                                 \
                                                                                                                                \
471
  {for ( int _idx = 0; _idx < COMPONENTS; _idx++ )                                                                              \
472 473 474
    {                                                                                                                           \
    _alpha[_idx] = static_cast<unsigned short>(SOTABLE[_idx][SCALAR[_idx]]*WEIGHTS[_idx]);                                      \
    _totalAlpha += _alpha[_idx];                                                                                                \
475
    }}                                                                                                                          \
476 477
                                                                                                                                \
  if ( !_totalAlpha ) {continue;}                                                                                               \
478
  {for ( int _idx = 0; _idx < COMPONENTS; _idx++ )                                                                              \
479 480
    {                                                                                                                           \
    if ( _alpha[_idx] )                                                                                                         \
481
    {                                                                                                                         \
482 483 484 485 486 487 488 489 490 491 492 493 494
      _tmpC[0] = static_cast<unsigned short>(((COLORTABLE[_idx][3*SCALAR[_idx]  ])*_alpha[_idx] + 0x7fff)>>(VTKKW_FP_SHIFT));   \
      _tmpC[1] = static_cast<unsigned short>(((COLORTABLE[_idx][3*SCALAR[_idx]+1])*_alpha[_idx] + 0x7fff)>>(VTKKW_FP_SHIFT));   \
      _tmpC[2] = static_cast<unsigned short>(((COLORTABLE[_idx][3*SCALAR[_idx]+2])*_alpha[_idx] + 0x7fff)>>(VTKKW_FP_SHIFT));   \
      _tmpC[0] = static_cast<unsigned short>((DTABLE[_idx][3*NORMAL[_idx]  ]*_tmpC[0]+0x7fff)>>VTKKW_FP_SHIFT);                 \
      _tmpC[1] = static_cast<unsigned short>((DTABLE[_idx][3*NORMAL[_idx]+1]*_tmpC[1]+0x7fff)>>VTKKW_FP_SHIFT);                 \
      _tmpC[2] = static_cast<unsigned short>((DTABLE[_idx][3*NORMAL[_idx]+2]*_tmpC[2]+0x7fff)>>VTKKW_FP_SHIFT);                 \
      _tmpC[0] += (STABLE[_idx][3*NORMAL[_idx]  ]*_alpha[_idx] + 0x7fff)>>VTKKW_FP_SHIFT;                                       \
      _tmpC[1] += (STABLE[_idx][3*NORMAL[_idx]+1]*_alpha[_idx] + 0x7fff)>>VTKKW_FP_SHIFT;                                       \
      _tmpC[2] += (STABLE[_idx][3*NORMAL[_idx]+2]*_alpha[_idx] + 0x7fff)>>VTKKW_FP_SHIFT;                                       \
      _tmp[0] += _tmpC[0];                                                                                                      \
      _tmp[1] += _tmpC[1];                                                                                                      \
      _tmp[2] += _tmpC[2];                                                                                                      \
      _tmp[3] += ((_alpha[_idx]*_alpha[_idx])/_totalAlpha);                                                                     \
495
    }                                                                                                                         \
496
    }}                                                                                                                           \
497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512
  if ( !_tmp[3] ) {continue;}                                                                                                   \
                                                                                                                                \
  COLOR[0] = (_tmp[0]>32767)?(32767):(_tmp[0]);                                                                                 \
  COLOR[1] = (_tmp[1]>32767)?(32767):(_tmp[1]);                                                                                 \
  COLOR[2] = (_tmp[2]>32767)?(32767):(_tmp[2]);                                                                                 \
  COLOR[3] = (_tmp[3]>32767)?(32767):(_tmp[3]);

#define VTKKWRCHelper_LookupAndCombineIndependentColorsInterpolateShadeUS( COLORTABLE, SOTABLE,                                 \
                                                                           DTABLE, STABLE,                                      \
                                                                           SCALAR, WEIGHTS,                                     \
                                                                           COMPONENTS, COLOR )                                  \
  unsigned int _tmp[4] = {0,0,0,0};                                                                                             \
  unsigned int _tmpC[4];                                                                                                        \
  unsigned short _alpha[4] = {0,0,0,0};                                                                                         \
  unsigned int _totalAlpha = 0;                                                                                                 \
                                                                                                                                \
513
  {for ( int _idx = 0; _idx < COMPONENTS; _idx++ )                                                                              \
514 515 516
    {                                                                                                                           \
    _alpha[_idx] = static_cast<unsigned short>(SOTABLE[_idx][SCALAR[_idx]]*WEIGHTS[_idx]);                                      \
    _totalAlpha += _alpha[_idx];                                                                                                \
517
    }}                                                                                                                          \
518 519
                                                                                                                                \
  if ( !_totalAlpha ) {continue;}                                                                                               \
520
  {for ( int _idx = 0; _idx < COMPONENTS; _idx++ )                                                                              \
521 522
    {                                                                                                                           \
    if ( _alpha[_idx] )                                                                                                         \
523
    {                                                                                                                         \
524 525 526 527 528 529 530 531 532
      _tmpC[0] = static_cast<unsigned short>(((COLORTABLE[_idx][3*SCALAR[_idx]  ])*_alpha[_idx] + 0x7fff)>>(VTKKW_FP_SHIFT));   \
      _tmpC[1] = static_cast<unsigned short>(((COLORTABLE[_idx][3*SCALAR[_idx]+1])*_alpha[_idx] + 0x7fff)>>(VTKKW_FP_SHIFT));   \
      _tmpC[2] = static_cast<unsigned short>(((COLORTABLE[_idx][3*SCALAR[_idx]+2])*_alpha[_idx] + 0x7fff)>>(VTKKW_FP_SHIFT));   \
      _tmpC[3] = _alpha[_idx];                                                                                                  \
      VTKKWRCHelper_InterpolateShadingComponent( DTABLE, STABLE, _tmpC, _idx );                                                 \
      _tmp[0] += _tmpC[0];                                                                                                      \
      _tmp[1] += _tmpC[1];                                                                                                      \
      _tmp[2] += _tmpC[2];                                                                                                      \
      _tmp[3] += ((_alpha[_idx]*_alpha[_idx])/_totalAlpha);                                                                     \
533
    }                                                                                                                         \
534
    }}                                                                                                                          \
535 536 537 538 539 540 541 542 543 544 545 546
  if (!_tmp[3]) {continue;}                                                                                                     \
  COLOR[0] = (_tmp[0]>32767)?(32767):(_tmp[0]);                                                                                 \
  COLOR[1] = (_tmp[1]>32767)?(32767):(_tmp[1]);                                                                                 \
  COLOR[2] = (_tmp[2]>32767)?(32767):(_tmp[2]);                                                                                 \
  COLOR[3] = (_tmp[3]>32767)?(32767):(_tmp[3]);

#define VTKKWRCHelper_CompositeColorAndCheckEarlyTermination( COLOR, TMP, REMAININGOPACITY )    \
  COLOR[0] += (TMP[0]*REMAININGOPACITY+0x7fff)>>VTKKW_FP_SHIFT;                                 \
  COLOR[1] += (TMP[1]*REMAININGOPACITY+0x7fff)>>VTKKW_FP_SHIFT;                                 \
  COLOR[2] += (TMP[2]*REMAININGOPACITY+0x7fff)>>VTKKW_FP_SHIFT;                                 \
  REMAININGOPACITY = (REMAININGOPACITY*((~(TMP[3])&VTKKW_FP_MASK))+0x7fff)>>VTKKW_FP_SHIFT;     \
  if ( REMAININGOPACITY < 0xff )                                                                \
547
  {                                                                                           \
548
    break;                                                                                      \
549
  }
550 551 552 553 554 555 556 557 558 559

#define VTKKWRCHelper_LookupAndCombineIndependentColorsGOShadeUS( COLORTABLE, SOTABLE, GOTABLE,                                 \
                                                                DTABLE, STABLE,                                                 \
                                                                SCALAR, MAG, NORMAL, WEIGHTS,                                   \
                                                                COMPONENTS, COLOR )                                             \
  unsigned int _tmp[4] = {0,0,0,0};                                                                                             \
  unsigned int _tmpC[3];                                                                                                        \
  unsigned short _alpha[4] = {0,0,0,0};                                                                                         \
  unsigned int _totalAlpha = 0;                                                                                                 \
                                                                                                                                \
560
  {for ( int _idx = 0; _idx < COMPONENTS; _idx++ )                                                                              \
561 562 563
    {                                                                                                                           \
    _alpha[_idx] =  static_cast<unsigned short>(SOTABLE[_idx][SCALAR[_idx]]*WEIGHTS[_idx]);                                     \
    if ( _alpha[_idx] )                                                                                                         \
564
    {                                                                                                                         \
565 566
      _alpha[_idx] = static_cast<unsigned short>((_alpha[_idx]*GOTABLE[_idx][MAG[_idx]] + 0x7fff)>>(VTKKW_FP_SHIFT));           \
      _totalAlpha += _alpha[_idx];                                                                                              \
567
    }                                                                                                                         \
568
    }}                                                                                                                          \
569 570 571
                                                                                                                                \
  if ( !_totalAlpha ) {continue;}                                                                                               \
                                                                                                                                \
572
  {for ( int _idx = 0; _idx < COMPONENTS; _idx++ )                                                                              \
573 574
    {                                                                                                                           \
    if ( _alpha[_idx] )                                                                                                         \
575
    {                                                                                                                         \
576 577 578 579 580 581 582 583 584 585 586 587 588
      _tmpC[0] = static_cast<unsigned short>(((COLORTABLE[_idx][3*SCALAR[_idx]  ])*_alpha[_idx] + 0x7fff)>>(VTKKW_FP_SHIFT));   \
      _tmpC[1] = static_cast<unsigned short>(((COLORTABLE[_idx][3*SCALAR[_idx]+1])*_alpha[_idx] + 0x7fff)>>(VTKKW_FP_SHIFT));   \
      _tmpC[2] = static_cast<unsigned short>(((COLORTABLE[_idx][3*SCALAR[_idx]+2])*_alpha[_idx] + 0x7fff)>>(VTKKW_FP_SHIFT));   \
      _tmpC[0] = static_cast<unsigned short>((DTABLE[_idx][3*NORMAL[_idx]  ]*_tmpC[0]+0x7fff)>>VTKKW_FP_SHIFT);                 \
      _tmpC[1] = static_cast<unsigned short>((DTABLE[_idx][3*NORMAL[_idx]+1]*_tmpC[1]+0x7fff)>>VTKKW_FP_SHIFT);                 \
      _tmpC[2] = static_cast<unsigned short>((DTABLE[_idx][3*NORMAL[_idx]+2]*_tmpC[2]+0x7fff)>>VTKKW_FP_SHIFT);                 \
      _tmpC[0] += (STABLE[_idx][3*NORMAL[_idx]  ]*_alpha[_idx] + 0x7fff)>>VTKKW_FP_SHIFT;                                       \
      _tmpC[1] += (STABLE[_idx][3*NORMAL[_idx]+1]*_alpha[_idx] + 0x7fff)>>VTKKW_FP_SHIFT;                                       \
      _tmpC[2] += (STABLE[_idx][3*NORMAL[_idx]+2]*_alpha[_idx] + 0x7fff)>>VTKKW_FP_SHIFT;                                       \
      _tmp[0] += _tmpC[0];                                                                                                      \
      _tmp[1] += _tmpC[1];                                                                                                      \
      _tmp[2] += _tmpC[2];                                                                                                      \
      _tmp[3] += ((_alpha[_idx]*_alpha[_idx])/_totalAlpha);                                                                     \
589
    }                                                                                                                         \
590
    }}                                                                                                                          \
591 592 593 594 595 596 597 598 599 600 601 602 603 604 605
  if ( !_tmp[3] ) {continue;}                                                                                                   \
  COLOR[0] = (_tmp[0]>32767)?(32767):(_tmp[0]);                                                                                 \
  COLOR[1] = (_tmp[1]>32767)?(32767):(_tmp[1]);                                                                                 \
  COLOR[2] = (_tmp[2]>32767)?(32767):(_tmp[2]);                                                                                 \
  COLOR[3] = (_tmp[3]>32767)?(32767):(_tmp[3]);

#define VTKKWRCHelper_LookupAndCombineIndependentColorsGOInterpolateShadeUS( COLORTABLE, SOTABLE, GOTABLE,                      \
                                                                DTABLE, STABLE,                                                 \
                                                                SCALAR, MAG, WEIGHTS,                                           \
                                                                COMPONENTS, COLOR )                                             \
  unsigned int _tmp[4] = {0,0,0,0};                                                                                             \
  unsigned int _tmpC[4];                                                                                                        \
  unsigned short _alpha[4] = {0,0,0,0};                                                                                         \
  unsigned int _totalAlpha = 0;                                                                                                 \
                                                                                                                                \
606
  {for ( int _idx = 0; _idx < COMPONENTS; _idx++ )                                                                              \
607 608 609
    {                                                                                                                           \
    _alpha[_idx] =  static_cast<unsigned short>(SOTABLE[_idx][SCALAR[_idx]]*WEIGHTS[_idx]);                                     \
    if ( _alpha[_idx] )                                                                                                         \
610
    {                                                                                                                         \
611 612
      _alpha[_idx] = static_cast<unsigned short>((_alpha[_idx]*GOTABLE[_idx][MAG[_idx]] + 0x7fff)>>(VTKKW_FP_SHIFT));           \
      _totalAlpha += _alpha[_idx];                                                                                              \
613
    }                                                                                                                         \
614
    }}                                                                                                                          \
615 616
                                                                                                                                \
  if ( !_totalAlpha ) {continue;}                                                                                               \
617
  {for ( int _idx = 0; _idx < COMPONENTS; _idx++ )                                                                              \
618 619
    {                                                                                                                           \
    if ( _alpha[_idx] )                                                                                                         \
620
    {                                                                                                                         \
621 622 623 624 625 626 627 628 629
      _tmpC[0] = static_cast<unsigned short>(((COLORTABLE[_idx][3*SCALAR[_idx]  ])*_alpha[_idx] + 0x7fff)>>(VTKKW_FP_SHIFT));   \
      _tmpC[1] = static_cast<unsigned short>(((COLORTABLE[_idx][3*SCALAR[_idx]+1])*_alpha[_idx] + 0x7fff)>>(VTKKW_FP_SHIFT));   \
      _tmpC[2] = static_cast<unsigned short>(((COLORTABLE[_idx][3*SCALAR[_idx]+2])*_alpha[_idx] + 0x7fff)>>(VTKKW_FP_SHIFT));   \
      _tmpC[3] = _alpha[_idx];                                                                                                  \
      VTKKWRCHelper_InterpolateShadingComponent( DTABLE, STABLE, _tmpC, _idx );                                                 \
      _tmp[0] += _tmpC[0];                                                                                                      \
      _tmp[1] += _tmpC[1];                                                                                                      \
      _tmp[2] += _tmpC[2];                                                                                                      \
      _tmp[3] += ((_alpha[_idx]*_alpha[_idx])/_totalAlpha);                                                                     \
630
    }                                                                                                                         \
631
    }}                                                                                                                           \
632 633 634 635 636 637 638
  if ( !_tmp[3] ) {continue;}                                                                                                   \
  COLOR[0] = (_tmp[0]>32767)?(32767):(_tmp[0]);                                                                                 \
  COLOR[1] = (_tmp[1]>32767)?(32767):(_tmp[1]);                                                                                 \
  COLOR[2] = (_tmp[2]>32767)?(32767):(_tmp[2]);                                                                                 \
  COLOR[3] = (_tmp[3]>32767)?(32767):(_tmp[3]);

#define VTKKWRCHelper_SetPixelColor( IMAGEPTR, COLOR, REMAININGOPACITY )        \
639 640 641
  IMAGEPTR[0] = (COLOR[0]>32767)?(32767):(COLOR[0]);                            \
  IMAGEPTR[1] = (COLOR[1]>32767)?(32767):(COLOR[1]);                            \
  IMAGEPTR[2] = (COLOR[2]>32767)?(32767):(COLOR[2]);                           \
642
  unsigned int tmpAlpha = (~REMAININGOPACITY)&VTKKW_FP_MASK;                    \
643
  IMAGEPTR[3] = (tmpAlpha>32767)?(32767):(tmpAlpha);
644 645 646

#define VTKKWRCHelper_MoveToNextSampleNN()                                      \
  if ( k < numSteps-1 )                                                         \
647
  {                                                                           \
648 649 650
    mapper->FixedPointIncrement( pos, dir );                                    \
    mapper->ShiftVectorDown( pos, spos );                                       \
    dptr = data +  spos[0]*inc[0] + spos[1]*inc[1] + spos[2]*inc[2];            \
651
  }
652 653 654

#define VTKKWRCHelper_MoveToNextSampleGONN()                            \
  if ( k < numSteps-1 )                                                 \
655
  {                                                                   \
656 657 658 659
    mapper->FixedPointIncrement( pos, dir );                            \
    mapper->ShiftVectorDown( pos, spos );                               \
    dptr = data +  spos[0]*inc[0] + spos[1]*inc[1] + spos[2]*inc[2];    \
    magPtr = gradientMag[spos[2]] + spos[0]*mInc[0] + spos[1]*mInc[1];  \
660
  }
661 662 663

#define VTKKWRCHelper_MoveToNextSampleShadeNN()                         \
  if ( k < numSteps-1 )                                                 \
664
  {                                                                   \
665 666 667 668
    mapper->FixedPointIncrement( pos, dir );                            \
    mapper->ShiftVectorDown( pos, spos );                               \
    dptr = data +  spos[0]*inc[0] + spos[1]*inc[1] + spos[2]*inc[2];    \
    dirPtr = gradientDir[spos[2]] + spos[0]*dInc[0] + spos[1]*dInc[1];  \
669
  }
670 671 672

#define VTKKWRCHelper_MoveToNextSampleGOShadeNN()                       \
  if ( k < numSteps-1 )                                                 \
673
  {                                                                   \
674 675 676 677 678
    mapper->FixedPointIncrement( pos, dir );                            \
    mapper->ShiftVectorDown( pos, spos );                               \
    dptr = data +  spos[0]*inc[0] + spos[1]*inc[1] + spos[2]*inc[2];    \
    magPtr = gradientMag[spos[2]] + spos[0]*mInc[0] + spos[1]*mInc[1];  \
    dirPtr = gradientDir[spos[2]] + spos[0]*dInc[0] + spos[1]*dInc[1];  \
679
  }
680 681 682

#define VTKKWRCHelper_InitializeVariables()                                                     \
  int i, j;                                                                                     \
683
  unsigned short *imagePtr;                                                                     \
684 685 686 687 688 689 690 691 692
                                                                                                \
  int imageInUseSize[2];                                                                        \
  int imageMemorySize[2];                                                                       \
  int imageViewportSize[2];                                                                     \
  int imageOrigin[2];                                                                           \
  int dim[3];                                                                                   \
  float shift[4];                                                                               \
  float scale[4];                                                                               \
                                                                                                \
693 694 695 696
  mapper->GetRayCastImage()->GetImageInUseSize(imageInUseSize);                                 \
  mapper->GetRayCastImage()->GetImageMemorySize(imageMemorySize);                               \
  mapper->GetRayCastImage()->GetImageViewportSize(imageViewportSize);                           \
  mapper->GetRayCastImage()->GetImageOrigin(imageOrigin);                                       \
697 698 699 700 701
  mapper->GetInput()->GetDimensions(dim);                                                       \
  mapper->GetTableShift( shift );                                                               \
  mapper->GetTableScale( scale );                                                               \
                                                                                                \
  int *rowBounds                     = mapper->GetRowBounds();                                  \
702
  unsigned short *image              = mapper->GetRayCastImage()->GetImage();                   \
703 704 705 706 707
  vtkRenderWindow *renWin            = mapper->GetRenderWindow();                               \
  int components                     = mapper->GetInput()->GetNumberOfScalarComponents();       \
  int cropping                       = (mapper->GetCropping() &&                                \
                                        mapper->GetCroppingRegionFlags() != 0x2000 );           \
                                                                                                \
708
  components = (components < 4) ? components : 4;                                               \
709 710 711 712 713
  unsigned short *colorTable[4];                                                                \
  unsigned short *scalarOpacityTable[4];                                                        \
                                                                                                \
  int c;                                                                                        \
  for ( c = 0; c < 4; c++ )                                                                     \
714
  {                                                                                           \
715
    colorTable[c]         = mapper->GetColorTable(c);                                           \
716
    (void)(colorTable[c]);                                                                      \
717
    scalarOpacityTable[c] = mapper->GetScalarOpacityTable(c);                                   \
718
  }                                                                                           \
719
                                                                                                \
720
  vtkIdType inc[3];                                                                             \
721
  inc[0] = components;                                                                          \
722 723
  inc[1] = inc[0]*dim[0];                                                                       \
  inc[2] = inc[1]*dim[1];
724

725
#define VTKKWRCHelper_InitializeWeights()                       \
726
  float weights[4] = {};                                        \
727 728 729 730 731
  weights[0] = vol->GetProperty()->GetComponentWeight(0);       \
  weights[1] = vol->GetProperty()->GetComponentWeight(1);       \
  weights[2] = vol->GetProperty()->GetComponentWeight(2);       \
  weights[3] = vol->GetProperty()->GetComponentWeight(3);

732 733 734
#define VTKKWRCHelper_InitializeVariablesGO()                           \
  unsigned short *gradientOpacityTable[4];                              \
  for ( c = 0; c < 4; c++ )                                             \
735
  {                                                                   \
736
    gradientOpacityTable[c] = mapper->GetGradientOpacityTable(c);       \
737
  }                                                                   \
738 739
  unsigned char **gradientMag = mapper->GetGradientMagnitude();         \
                                                                        \
740
  vtkIdType mInc[3];                                                    \
741
  if ( vol->GetProperty()->GetIndependentComponents() )                 \
742
  {                                                                   \
743 744 745
    mInc[0] = inc[0];                                                   \
    mInc[1] = inc[1];                                                   \
    mInc[2] = inc[2];                                                   \
746
  }                                                                   \
747
  else                                                                  \
748
  {                                                                   \
749
    mInc[0] = 1;                                                        \
750 751
    mInc[1] = mInc[0]*dim[0];                                           \
    mInc[2] = mInc[1]*dim[1];                                           \
752
  }
753 754 755 756 757

#define VTKKWRCHelper_InitializeVariablesShade()                        \
  unsigned short *diffuseShadingTable[4];                               \
  unsigned short *specularShadingTable[4];                              \
  for ( c = 0; c < 4; c++ )                                             \
758
  {                                                                   \
759 760
    diffuseShadingTable[c] = mapper->GetDiffuseShadingTable(c);         \
    specularShadingTable[c] = mapper->GetSpecularShadingTable(c);       \
761
  }                                                                   \
762
  unsigned short **gradientDir = mapper->GetGradientNormal();           \
763
  vtkIdType dInc[3];                                                    \
764
  if ( vol->GetProperty()->GetIndependentComponents() )                 \
765
  {                                                                   \
766 767 768
    dInc[0] = inc[0];                                                   \
    dInc[1] = inc[1];                                                   \
    dInc[2] = inc[2];                                                   \
769
  }                                                                   \
770
  else                                                                  \
771
  {                                                                   \
772
    dInc[0] = 1;                                                        \
773 774
    dInc[1] = dInc[0]*dim[0];                                           \
    dInc[2] = dInc[1]*dim[1];                                           \
775
  }
776

777 778 779 780 781 782 783 784
#define VTKKWRCHelper_InitializeTrilinVariables() \
  vtkIdType Binc = components;                    \
  vtkIdType Cinc = Binc*dim[0];                   \
  vtkIdType Dinc = Cinc + Binc;                   \
  vtkIdType Einc = Cinc*dim[1];                   \
  vtkIdType Finc = Einc + Binc;                   \
  vtkIdType Ginc = Einc + Cinc;                   \
  vtkIdType Hinc = Ginc + Binc;
785 786

#define VTKKWRCHelper_InitializeTrilinVariablesGO()             \
787
  vtkIdType magOffset;                                          \
788
  if (  vol->GetProperty()->GetIndependentComponents() )        \
789
  {                                                           \
790
    magOffset = components;                                     \
791
  }                                                           \
792
  else                                                          \
793
  {                                                           \
794
    magOffset = 1;                                              \
795
  }                                                           \
796
                                                                \
797 798 799
  vtkIdType mBFinc =                    magOffset;              \
  vtkIdType mCGinc = dim[0]*magOffset;                          \
  vtkIdType mDHinc = dim[0]*magOffset + magOffset;
800 801

#define VTKKWRCHelper_InitializeTrilinVariablesShade()          \
802
  vtkIdType dirOffset;                                          \
803
  if (  vol->GetProperty()->GetIndependentComponents() )        \
804
  {                                                           \
805
    dirOffset = components;                                     \
806
  }                                                           \
807
  else                                                          \
808
  {                                                           \
809
    dirOffset = 1;                                              \
810
  }                                                           \
811
                                                                \
812 813 814
  vtkIdType dBFinc =                    dirOffset;              \
  vtkIdType dCGinc = dim[0]*dirOffset;                          \
  vtkIdType dDHinc = dim[0]*dirOffset + dirOffset;
815 816 817

#define VTKKWRCHelper_OuterInitialization()                             \
    if ( j%threadCount != threadID )                                    \
818
    {                                                                 \
819
      continue;                                                         \
820
    }                                                                 \
821
     if ( !threadID )                                                   \
822
     {                                                                 \
823
      if ( renWin->CheckAbortStatus() )                                 \
824
      {                                                               \
825
        break;                                                          \
826 827
      }                                                               \
     }                                                                 \
828
    else if ( renWin->GetAbortRender() )                                \
829
    {                                                                 \
830
      break;                                                            \
831
    }                                                                 \
832
    imagePtr = image + 4*(j*imageMemorySize[0] + rowBounds[j*2]);
833 834 835 836 837 838 839

#define VTKKWRCHelper_InnerInitialization()             \
  unsigned int   numSteps;                              \
  unsigned int   pos[3];                                \
  unsigned int   dir[3];                                \
  mapper->ComputeRayInfo( i, j, pos, dir, &numSteps );  \
  if ( numSteps == 0 )                                  \
840
  {                                                   \
841 842 843 844 845 846
    *(imagePtr  ) = 0;                                  \
    *(imagePtr+1) = 0;                                  \
    *(imagePtr+2) = 0;                                  \
    *(imagePtr+3) = 0;                                  \
    imagePtr += 4;                                      \
    continue;                                           \
847
  }                                                   \
848 849 850 851 852 853 854 855 856 857 858
  unsigned int   spos[3];                               \
  unsigned int   k;

#define VTKKWRCHelper_InitializeMIPOneNN()                              \
  mapper->ShiftVectorDown( pos, spos );                                 \
  T *dptr = data +  spos[0]*inc[0] + spos[1]*inc[1] + spos[2]*inc[2];   \
  T maxValue = *(dptr);

#define VTKKWRCHelper_InitializeMIPMultiNN()                            \
  mapper->ShiftVectorDown( pos, spos );                                 \
  T *dptr = data +  spos[0]*inc[0] + spos[1]*inc[1] + spos[2]*inc[2];   \
859
  T maxValue[4] = {};                                                   \
860
  for ( c = 0; c < components; c++ )                                    \
861
  {                                                                   \
862
    maxValue[c] = *(dptr+c);                                            \
863
  }
864 865 866 867 868 869

#define VTKKWRCHelper_InitializeMIPOneTrilin()          \
  T *dptr;                                              \
  unsigned int oldSPos[3];                              \
                                                        \
  oldSPos[0] = (pos[0] >> VTKKW_FP_SHIFT) + 1;          \
870 871
  oldSPos[1] = 0;                                       \
  oldSPos[2] = 0;                                       \
872
                                                        \
873 874 875
  unsigned int w1X, w1Y, w1Z;                           \
  unsigned int w2X, w2Y, w2Z;                           \
  unsigned int w1Xw1Y, w2Xw1Y, w1Xw2Y, w2Xw2Y;          \
876 877 878
                                                        \
  unsigned short  maxValue=0;                           \
  unsigned short  val;                                  \
879
  unsigned int A=0,B=0,C=0,D=0,E=0,F=0,G=0,H=0;
880 881 882 883 884 885

#define VTKKWRCHelper_InitializeMIPMultiTrilin()                \
  T *dptr;                                                      \
  unsigned int oldSPos[3];                                      \
                                                                \
  oldSPos[0] = (pos[0] >> VTKKW_FP_SHIFT) + 1;                  \
886 887
  oldSPos[1] = 0;                                               \
  oldSPos[2] = 0;                                               \
888
                                                                \
889 890 891
  unsigned int w1X, w1Y, w1Z;                                   \
  unsigned int w2X, w2Y, w2Z;                                   \
  unsigned int w1Xw1Y, w2Xw1Y, w1Xw2Y, w2Xw2Y;                  \
892
                                                                \
893 894 895 896
  unsigned short  maxValue[4] = {};                             \
  unsigned short  val[4] = {};                                  \
  unsigned int    A[4] = {}, B[4] = {}, C[4] = {}, D[4] = {},   \
                  E[4] = {}, F[4] = {}, G[4] = {}, H[4] = {};
897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915

#define VTKKWRCHelper_InitializeCompositeGONN()                                      \
  unsigned char *magPtr = gradientMag[spos[2]] + spos[0]*mInc[0] + spos[1]*mInc[1];

#define VTKKWRCHelper_InitializeCompositeShadeNN()                                      \
  unsigned short *dirPtr = gradientDir[spos[2]] + spos[0]*dInc[0] + spos[1]*dInc[1];

#define VTKKWRCHelper_InitializeCompositeOneNN()                        \
  mapper->ShiftVectorDown( pos, spos );                                 \
  T *dptr = data +  spos[0]*inc[0] + spos[1]*inc[1] + spos[2]*inc[2];   \
  unsigned int color[3] = {0,0,0};                                      \
  unsigned short remainingOpacity = 0x7fff;                             \
  unsigned short tmp[4];

#define VTKKWRCHelper_InitializeCompositeMultiNN()                      \
  mapper->ShiftVectorDown( pos, spos );                                 \
  T *dptr = data +  spos[0]*inc[0] + spos[1]*inc[1] + spos[2]*inc[2];   \
  unsigned int color[3] = {0,0,0};                                      \
  unsigned int remainingOpacity = 0x7fff;                               \
916 917
  unsigned short tmp[4] = {};                                           \
  unsigned short val[4] = {};
918 919 920 921 922 923

#define VTKKWRCHelper_InitializeCompositeOneTrilin()    \
  T *dptr;                                              \
  unsigned int oldSPos[3];                              \
                                                        \
  oldSPos[0] = (pos[0] >> VTKKW_FP_SHIFT) + 1;          \
924 925
  oldSPos[1] = 0;                                       \
  oldSPos[2] = 0;                                       \
926 927 928 929 930 931 932 933 934 935 936 937 938
                                                        \
  unsigned int w1X, w1Y, w1Z;                           \
  unsigned int w2X, w2Y, w2Z;                           \
  unsigned int w1Xw1Y, w2Xw1Y, w1Xw2Y, w2Xw2Y;          \
                                                        \
  unsigned short  val;                                  \
  unsigned int    A=0,B=0,C=0,D=0,E=0,F=0,G=0,H=0;      \
                                                        \
  unsigned int color[3] = {0,0,0};                      \
  unsigned short remainingOpacity = 0x7fff;             \
  unsigned short tmp[4];

#define VTKKWRCHelper_InitializeCompositeOneGOTrilin()          \
939
  unsigned char  *magPtrABCD = nullptr, *magPtrEFGH = nullptr;  \
940 941 942 943 944 945 946 947 948 949 950 951 952
  unsigned short  mag;                                          \
  unsigned int    mA=0,mB=0,mC=0,mD=0,mE=0,mF=0,mG=0,mH=0;

#define VTKKWRCHelper_InitializeCompositeOneShadeTrilin()       \
  unsigned short *dirPtrABCD = 0, *dirPtrEFGH = 0;              \
  unsigned int    normalA=0,normalB=0,normalC=0,normalD=0;      \
  unsigned int    normalE=0,normalF=0,normalG=0,normalH=0;

#define VTKKWRCHelper_InitializeCompositeMultiTrilin()          \
  T *dptr;                                                      \
  unsigned int oldSPos[3];                                      \
                                                                \
  oldSPos[0] = (pos[0] >> VTKKW_FP_SHIFT) + 1;                  \
953 954
  oldSPos[1] = 0;                                               \
  oldSPos[2] = 0;                                               \
955 956 957 958 959
                                                                \
  unsigned int w1X, w1Y, w1Z;                                   \
  unsigned int w2X, w2Y, w2Z;                                   \
  unsigned int w1Xw1Y, w2Xw1Y, w1Xw2Y, w2Xw2Y;                  \
                                                                \
960 961 962 963 964 965 966 967 968
  unsigned short  val[4] = {0, 0, 0, 0};                        \
  unsigned int    A[4]   = {0, 0, 0, 0};                        \
  unsigned int    B[4]   = {0, 0, 0, 0};                        \
  unsigned int    C[4]   = {0, 0, 0, 0};                        \
  unsigned int    D[4]   = {0, 0, 0, 0};                        \
  unsigned int    E[4]   = {0, 0, 0, 0};                        \
  unsigned int    F[4]   = {0, 0, 0, 0};                        \
  unsigned int    G[4]   = {0, 0, 0, 0};                        \
  unsigned int    H[4]   = {0, 0, 0, 0};                        \
969 970 971 972 973 974 975
                                                                \
  unsigned int color[3] = {0,0,0};                              \
  unsigned short remainingOpacity = 0x7fff;                     \
  unsigned short tmp[4];

#define VTKKWRCHelper_InitializeCompositeMultiGOTrilin()                \
  unsigned char  *magPtrABCD = 0, *magPtrEFGH = 0;                      \
976 977 978 979
  unsigned short  mag[4] = {};                                          \
  unsigned int    mA[4] = {}, mB[4] = {}, mC[4] = {},                   \
                  mD[4] = {}, mE[4] = {}, mF[4] = {},                   \
                  mG[4] = {}, mH[4] = {};
980 981 982 983 984 985 986 987 988

#define VTKKWRCHelper_InitializeCompositeMultiShadeTrilin()     \
  unsigned short *dirPtrABCD = 0, *dirPtrEFGH = 0;              \
  unsigned int    normalA[4],normalB[4],normalC[4],normalD[4];  \
  unsigned int    normalE[4],normalF[4],normalG[4],normalH[4];

#define VTKKWRCHelper_InitializationAndLoopStartNN()            \
  VTKKWRCHelper_InitializeVariables();                          \
  for ( j = 0; j < imageInUseSize[1]; j++ )                     \
989
  {                                                           \
990 991
    VTKKWRCHelper_OuterInitialization();                        \
    for ( i = rowBounds[j*2]; i <= rowBounds[j*2+1]; i++ )      \
992
    {                                                         \
993 994 995 996 997 998
      VTKKWRCHelper_InnerInitialization();

#define VTKKWRCHelper_InitializationAndLoopStartGONN()          \
  VTKKWRCHelper_InitializeVariables();                          \
  VTKKWRCHelper_InitializeVariablesGO();                        \
  for ( j = 0; j < imageInUseSize[1]; j++ )                     \
999
  {                                                           \
1000 1001
    VTKKWRCHelper_OuterInitialization();                        \
    for ( i = rowBounds[j*2]; i <= rowBounds[j*2+1]; i++ )      \
1002
    {                                                         \
1003 1004 1005 1006 1007 1008
      VTKKWRCHelper_InnerInitialization();

#define VTKKWRCHelper_InitializationAndLoopStartShadeNN()       \
  VTKKWRCHelper_InitializeVariables();                          \
  VTKKWRCHelper_InitializeVariablesShade();                     \
  for ( j = 0; j < imageInUseSize[1]; j++ )                     \
1009
  {                                                           \
1010 1011
    VTKKWRCHelper_OuterInitialization();                        \
    for ( i = rowBounds[j*2]; i <= rowBounds[j*2+1]; i++ )      \
1012
    {                                                         \
1013 1014 1015 1016 1017 1018 1019
      VTKKWRCHelper_InnerInitialization();

#define VTKKWRCHelper_InitializationAndLoopStartGOShadeNN()     \
  VTKKWRCHelper_InitializeVariables();                          \
  VTKKWRCHelper_InitializeVariablesGO();                        \
  VTKKWRCHelper_InitializeVariablesShade();                     \
  for ( j = 0; j < imageInUseSize[1]; j++ )                     \
1020
  {                                                           \
1021 1022
    VTKKWRCHelper_OuterInitialization();                        \
    for ( i = rowBounds[j*2]; i <= rowBounds[j*2+1]; i++ )      \
1023
    {                                                         \
1024 1025 1026 1027 1028 1029
      VTKKWRCHelper_InnerInitialization();

#define VTKKWRCHelper_InitializationAndLoopStartTrilin()        \
  VTKKWRCHelper_InitializeVariables();                          \
  VTKKWRCHelper_InitializeTrilinVariables();                    \
  for ( j = 0; j < imageInUseSize[1]; j++ )                     \
1030
  {                                                           \
1031 1032
    VTKKWRCHelper_OuterInitialization();                        \
    for ( i = rowBounds[j*2]; i <= rowBounds[j*2+1]; i++ )      \
1033
    {                                                         \
1034 1035 1036 1037 1038 1039 1040 1041
      VTKKWRCHelper_InnerInitialization();

#define VTKKWRCHelper_InitializationAndLoopStartGOTrilin()      \
  VTKKWRCHelper_InitializeVariables();                          \
  VTKKWRCHelper_InitializeVariablesGO();                        \
  VTKKWRCHelper_InitializeTrilinVariables();                    \
  VTKKWRCHelper_InitializeTrilinVariablesGO();                  \
  for ( j = 0; j < imageInUseSize[1]; j++ )                     \
1042
  {                                                           \
1043 1044
    VTKKWRCHelper_OuterInitialization();                        \
    for ( i = rowBounds[j*2]; i <= rowBounds[j*2+1]; i++ )      \
1045
    {                                                         \
1046 1047 1048 1049 1050 1051 1052 1053
      VTKKWRCHelper_InnerInitialization();

#define VTKKWRCHelper_InitializationAndLoopStartShadeTrilin()   \
  VTKKWRCHelper_InitializeVariables();                          \
  VTKKWRCHelper_InitializeVariablesShade();                     \
  VTKKWRCHelper_InitializeTrilinVariables();                    \
  VTKKWRCHelper_InitializeTrilinVariablesShade();               \
  for ( j = 0; j < imageInUseSize[1]; j++ )                     \
1054
  {                                                           \
1055 1056
    VTKKWRCHelper_OuterInitialization();                        \
    for ( i = rowBounds[j*2]; i <= rowBounds[j*2+1]; i++ )      \
1057
    {                                                         \
1058 1059 1060 1061 1062 1063 1064 1065 1066 1067
      VTKKWRCHelper_InnerInitialization();

#define VTKKWRCHelper_InitializationAndLoopStartGOShadeTrilin() \
  VTKKWRCHelper_InitializeVariables();                          \
  VTKKWRCHelper_InitializeVariablesShade();                     \
  VTKKWRCHelper_InitializeVariablesGO();                        \
  VTKKWRCHelper_InitializeTrilinVariables();                    \
  VTKKWRCHelper_InitializeTrilinVariablesShade();               \
  VTKKWRCHelper_InitializeTrilinVariablesGO();                  \
  for ( j = 0; j < imageInUseSize[1]; j++ )                     \
1068
  {                                                           \
1069 1070
    VTKKWRCHelper_OuterInitialization();                        \
    for ( i = rowBounds[j*2]; i <= rowBounds[j*2+1]; i++ )      \
1071
    {                                                         \
1072 1073
      VTKKWRCHelper_InnerInitialization();

1074 1075 1076
#define VTKKWRCHelper_IncrementAndLoopEnd()                                             \
      imagePtr+=4;                                                                      \
      }                                                                                 \
1077
    if ( (j/threadCount)%8 == 7 && threadID == 0)                                       \
1078
    {                                                                                 \
1079 1080 1081
      double fargs[1];                                                                  \
      fargs[0] = static_cast<double>(j)/static_cast<float>(imageInUseSize[1]-1);        \
      mapper->InvokeEvent( vtkCommand::VolumeMapperRenderProgressEvent, fargs );        \
1082
    }                                                                                 \
1083 1084 1085 1086
    }

#define VTKKWRCHelper_CroppingCheckTrilin( POS )        \
  if ( cropping )                                       \
1087
  {                                                   \
1088
    if ( mapper->CheckIfCropped( POS ) )                \
1089
    {                                                 \
1090
      continue;                                         \
1091 1092
    }                                                 \
  }
1093 1094 1095

#define VTKKWRCHelper_CroppingCheckNN( POS )            \
  if ( cropping )                                       \
1096
  {                                                   \
1097
    if ( mapper->CheckIfCropped( POS ) )                \
1098
    {                                                 \
1099
      continue;                                         \
1100 1101
    }                                                 \
  }
1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120

#define VTKKWRCHelper_SpaceLeapSetup()          \
  unsigned int mmpos[3];                        \
  mmpos[0] = (pos[0] >> VTKKW_FPMM_SHIFT) + 1;  \
  mmpos[1] = 0;                                 \
  mmpos[2] = 0;                                 \
  int mmvalid = 0;

#define VTKKWRCHelper_SpaceLeapSetupMulti()     \
  unsigned int mmpos[3];                        \
  mmpos[0] = (pos[0] >> VTKKW_FPMM_SHIFT) + 1;  \
  mmpos[1] = 0;                                 \
  mmpos[2] = 0;                                 \
  int mmvalid[4] = {0,0,0,0};

#define VTKKWRCHelper_SpaceLeapCheck()                          \
  if ( pos[0] >> VTKKW_FPMM_SHIFT != mmpos[0] ||                \
       pos[1] >> VTKKW_FPMM_SHIFT != mmpos[1] ||                \
       pos[2] >> VTKKW_FPMM_SHIFT != mmpos[2] )                 \
1121
  {                                                           \
1122 1123 1124 1125
    mmpos[0] = pos[0] >> VTKKW_FPMM_SHIFT;                      \
    mmpos[1] = pos[1] >> VTKKW_FPMM_SHIFT;                      \
    mmpos[2] = pos[2] >> VTKKW_FPMM_SHIFT;                      \
    mmvalid = mapper->CheckMinMaxVolumeFlag( mmpos, 0 );        \
1126
  }                                                           \
1127 1128
                                                                \
  if ( !mmvalid )                                               \
1129
  {                                                           \
1130
    continue;                                                   \
1131
  }
1132

1133
#define VTKKWRCHelper_MIPSpaceLeapCheck( MAXIDX, MAXIDXDEF, FLIP )      \
1134 1135 1136
  if ( pos[0] >> VTKKW_FPMM_SHIFT != mmpos[0] ||                        \
       pos[1] >> VTKKW_FPMM_SHIFT != mmpos[1] ||                        \
       pos[2] >> VTKKW_FPMM_SHIFT != mmpos[2] )                         \
1137
  {                                                                   \
1138 1139 1140 1141
    mmpos[0] = pos[0] >> VTKKW_FPMM_SHIFT;                              \
    mmpos[1] = pos[1] >> VTKKW_FPMM_SHIFT;                              \
    mmpos[2] = pos[2] >> VTKKW_FPMM_SHIFT;                              \
    mmvalid = (MAXIDXDEF)?                                              \
1142
     (mapper->CheckMIPMinMaxVolumeFlag( mmpos, 0, MAXIDX, FLIP )):(1);  \
1143
  }                                                                   \
1144 1145
                                                                        \
  if ( !mmvalid )                                                       \
1146
  {                                                                   \
1147
    continue;                                                           \
1148
  }
1149

1150 1151 1152 1153
#define VTKKWRCHelper_MIPSpaceLeapPopulateMulti( MAXIDX, FLIP )                   \
  if ( pos[0] >> VTKKW_FPMM_SHIFT != mmpos[0] ||                                  \
       pos[1] >> VTKKW_FPMM_SHIFT != mmpos[1] ||                                  \
       pos[2] >> VTKKW_FPMM_SHIFT != mmpos[2] )                                   \
1154
  {                                                                             \
1155 1156 1157 1158
    mmpos[0] = pos[0] >> VTKKW_FPMM_SHIFT;                                        \
    mmpos[1] = pos[1] >> VTKKW_FPMM_SHIFT;                                        \
    mmpos[2] = pos[2] >> VTKKW_FPMM_SHIFT;                                        \
    for ( c = 0; c < components; c++ )                                            \
1159
    {                                                                           \
1160
      mmvalid[c] = mapper->CheckMIPMinMaxVolumeFlag( mmpos, c, MAXIDX[c], FLIP ); \
1161 1162
    }                                                                           \
  }
1163

1164
#define VTKKWRCHelper_MIPSpaceLeapCheckMulti( COMP, FLIP )  mmvalid[COMP]
1165

1166
#include "vtkRenderingVolumeModule.h" // For export macro
1167 1168 1169 1170 1171
#include "vtkObject.h"

class vtkFixedPointVolumeRayCastMapper;
class vtkVolume;

1172
class VTKRENDERINGVOLUME_EXPORT vtkFixedPointVolumeRayCastHelper : public vtkObject
1173 1174 1175
{
public:
  static vtkFixedPointVolumeRayCastHelper *New();
1176
  vtkTypeMacro(vtkFixedPointVolumeRayCastHelper,vtkObject);
1177
  void PrintSelf( ostream& os, vtkIndent indent ) override;
1178

1179
  virtual void   GenerateImage( int,
1180 1181 1182
                                int,
                                vtkVolume *,
                                vtkFixedPointVolumeRayCastMapper *) {}
1183

1184 1185
protected:
  vtkFixedPointVolumeRayCastHelper();
1186
  ~vtkFixedPointVolumeRayCastHelper() override;
1187 1188 1189


private:
1190 1191
  vtkFixedPointVolumeRayCastHelper(const vtkFixedPointVolumeRayCastHelper&) = delete;
  void operator=(const vtkFixedPointVolumeRayCastHelper&) = delete;
1192 1193 1194 1195 1196 1197
};

#endif