VTK
dox/Rendering/Volume/vtkFixedPointVolumeRayCastHelper.h
Go to the documentation of this file.
00001 /*=========================================================================
00002 
00003   Program:   Visualization Toolkit
00004   Module:    vtkFixedPointVolumeRayCastHelper.h
00005 
00006   Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
00007   All rights reserved.
00008   See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
00009 
00010      This software is distributed WITHOUT ANY WARRANTY; without even
00011      the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
00012      PURPOSE.  See the above copyright notice for more information.
00013 
00014 =========================================================================*/
00025 #ifndef __vtkFixedPointVolumeRayCastHelper_h
00026 #define __vtkFixedPointVolumeRayCastHelper_h
00027 
00028 //BTX
00029 #define VTKKWRCHelper_GetCellScalarValues( DATA, SCALE, SHIFT ) \
00030   A = static_cast<unsigned int >(SCALE*(*(DATA     ) + SHIFT)); \
00031   B = static_cast<unsigned int >(SCALE*(*(DATA+Binc) + SHIFT)); \
00032   C = static_cast<unsigned int >(SCALE*(*(DATA+Cinc) + SHIFT)); \
00033   D = static_cast<unsigned int >(SCALE*(*(DATA+Dinc) + SHIFT)); \
00034   E = static_cast<unsigned int >(SCALE*(*(DATA+Einc) + SHIFT)); \
00035   F = static_cast<unsigned int >(SCALE*(*(DATA+Finc) + SHIFT)); \
00036   G = static_cast<unsigned int >(SCALE*(*(DATA+Ginc) + SHIFT)); \
00037   H = static_cast<unsigned int >(SCALE*(*(DATA+Hinc) + SHIFT))
00038 //ETX
00039 
00040 //BTX
00041 #define VTKKWRCHelper_GetCellScalarValuesSimple( DATA )  \
00042   A = static_cast<unsigned int >(*(DATA     ));          \
00043   B = static_cast<unsigned int >(*(DATA+Binc));          \
00044   C = static_cast<unsigned int >(*(DATA+Cinc));          \
00045   D = static_cast<unsigned int >(*(DATA+Dinc));          \
00046   E = static_cast<unsigned int >(*(DATA+Einc));          \
00047   F = static_cast<unsigned int >(*(DATA+Finc));          \
00048   G = static_cast<unsigned int >(*(DATA+Ginc));          \
00049   H = static_cast<unsigned int >(*(DATA+Hinc))
00050 //ETX
00051 
00052 //BTX
00053 #define VTKKWRCHelper_GetCellMagnitudeValues( ABCD, EFGH )       \
00054   mA = static_cast<unsigned int >(*(ABCD      ));                \
00055   mB = static_cast<unsigned int >(*(ABCD+mBFinc));               \
00056   mC = static_cast<unsigned int >(*(ABCD+mCGinc));               \
00057   mD = static_cast<unsigned int >(*(ABCD+mDHinc));               \
00058   mE = static_cast<unsigned int >(*(EFGH       ));               \
00059   mF = static_cast<unsigned int >(*(EFGH+mBFinc));               \
00060   mG = static_cast<unsigned int >(*(EFGH+mCGinc));               \
00061   mH = static_cast<unsigned int >(*(EFGH+mDHinc))
00062 //ETX
00063 
00064 //BTX
00065 #define VTKKWRCHelper_GetCellDirectionValues( ABCD, EFGH )      \
00066   normalA   = static_cast<unsigned int >(*(ABCD       ));       \
00067   normalB   = static_cast<unsigned int >(*(ABCD+dBFinc));       \
00068   normalC   = static_cast<unsigned int >(*(ABCD+dCGinc));       \
00069   normalD   = static_cast<unsigned int >(*(ABCD+dDHinc));       \
00070   normalE   = static_cast<unsigned int >(*(EFGH       ));       \
00071   normalF   = static_cast<unsigned int >(*(EFGH+dBFinc));       \
00072   normalG   = static_cast<unsigned int >(*(EFGH+dCGinc));       \
00073   normalH   = static_cast<unsigned int >(*(EFGH+dDHinc));
00074 //ETX
00075 
00076 //BTX
00077 #define VTKKWRCHelper_GetCellComponentScalarValues( DATA, CIDX, SCALE, SHIFT )    \
00078   A[CIDX] = static_cast<unsigned int >(SCALE*(*(DATA     ) + SHIFT));             \
00079   B[CIDX] = static_cast<unsigned int >(SCALE*(*(DATA+Binc) + SHIFT));             \
00080   C[CIDX] = static_cast<unsigned int >(SCALE*(*(DATA+Cinc) + SHIFT));             \
00081   D[CIDX] = static_cast<unsigned int >(SCALE*(*(DATA+Dinc) + SHIFT));             \
00082   E[CIDX] = static_cast<unsigned int >(SCALE*(*(DATA+Einc) + SHIFT));             \
00083   F[CIDX] = static_cast<unsigned int >(SCALE*(*(DATA+Finc) + SHIFT));             \
00084   G[CIDX] = static_cast<unsigned int >(SCALE*(*(DATA+Ginc) + SHIFT));             \
00085   H[CIDX] = static_cast<unsigned int >(SCALE*(*(DATA+Hinc) + SHIFT))
00086 //ETX
00087 
00088 //BTX
00089 #define VTKKWRCHelper_GetCellComponentRawScalarValues( DATA, CIDX ) \
00090   A[CIDX] = static_cast<unsigned int >((*(DATA     )));             \
00091   B[CIDX] = static_cast<unsigned int >((*(DATA+Binc)));             \
00092   C[CIDX] = static_cast<unsigned int >((*(DATA+Cinc)));             \
00093   D[CIDX] = static_cast<unsigned int >((*(DATA+Dinc)));             \
00094   E[CIDX] = static_cast<unsigned int >((*(DATA+Einc)));             \
00095   F[CIDX] = static_cast<unsigned int >((*(DATA+Finc)));             \
00096   G[CIDX] = static_cast<unsigned int >((*(DATA+Ginc)));             \
00097   H[CIDX] = static_cast<unsigned int >((*(DATA+Hinc)))
00098 //ETX
00099 
00100 //BTX
00101 #define VTKKWRCHelper_GetCellComponentMagnitudeValues( ABCD, EFGH, CIDX )      \
00102   mA[CIDX] = static_cast<unsigned int >(*(ABCD       ));                       \
00103   mB[CIDX] = static_cast<unsigned int >(*(ABCD+mBFinc));                       \
00104   mC[CIDX] = static_cast<unsigned int >(*(ABCD+mCGinc));                       \
00105   mD[CIDX] = static_cast<unsigned int >(*(ABCD+mDHinc));                       \
00106   mE[CIDX] = static_cast<unsigned int >(*(EFGH       ));                       \
00107   mF[CIDX] = static_cast<unsigned int >(*(EFGH+mBFinc));                       \
00108   mG[CIDX] = static_cast<unsigned int >(*(EFGH+mCGinc));                       \
00109   mH[CIDX] = static_cast<unsigned int >(*(EFGH+mDHinc))
00110 //ETX
00111 
00112 //BTX
00113 #define VTKKWRCHelper_GetCellComponentDirectionValues( ABCD, EFGH, CIDX )       \
00114   normalA[CIDX]   = static_cast<unsigned int >(*(ABCD       ));                 \
00115   normalB[CIDX]   = static_cast<unsigned int >(*(ABCD+dBFinc));                 \
00116   normalC[CIDX]   = static_cast<unsigned int >(*(ABCD+dCGinc));                 \
00117   normalD[CIDX]   = static_cast<unsigned int >(*(ABCD+dDHinc));                 \
00118   normalE[CIDX]   = static_cast<unsigned int >(*(EFGH       ));                 \
00119   normalF[CIDX]   = static_cast<unsigned int >(*(EFGH+dBFinc));                 \
00120   normalG[CIDX]   = static_cast<unsigned int >(*(EFGH+dCGinc));                 \
00121   normalH[CIDX]   = static_cast<unsigned int >(*(EFGH+dDHinc));
00122 //ETX
00123 
00124 
00125 //BTX
00126 #define VTKKWRCHelper_ComputeWeights( POS )                                             \
00127   w2X = (POS[0]&VTKKW_FP_MASK);                                                         \
00128   w2Y = (POS[1]&VTKKW_FP_MASK);                                                         \
00129   w2Z = (POS[2]&VTKKW_FP_MASK);                                                         \
00130                                                                                         \
00131   w1X = ((~w2X)&VTKKW_FP_MASK);                                                         \
00132   w1Y = ((~w2Y)&VTKKW_FP_MASK);                                                         \
00133   w1Z = ((~w2Z)&VTKKW_FP_MASK);                                                         \
00134                                                                                         \
00135   w1Xw1Y = (0x4000+(w1X*w1Y))>>VTKKW_FP_SHIFT;                                          \
00136   w2Xw1Y = (0x4000+(w2X*w1Y))>>VTKKW_FP_SHIFT;                                          \
00137   w1Xw2Y = (0x4000+(w1X*w2Y))>>VTKKW_FP_SHIFT;                                          \
00138   w2Xw2Y = (0x4000+(w2X*w2Y))>>VTKKW_FP_SHIFT;                                          \
00139 //ETX
00140 
00141 
00142 //BTX
00143 #define VTKKWRCHelper_InterpolateScalar( VAL )                                  \
00144   VAL =                                                                         \
00145     (0x7fff + ((A*((0x4000 + w1Xw1Y*w1Z)>>VTKKW_FP_SHIFT)) +                    \
00146                (B*((0x4000 + w2Xw1Y*w1Z)>>VTKKW_FP_SHIFT)) +                    \
00147                (C*((0x4000 + w1Xw2Y*w1Z)>>VTKKW_FP_SHIFT)) +                    \
00148                (D*((0x4000 + w2Xw2Y*w1Z)>>VTKKW_FP_SHIFT)) +                    \
00149                (E*((0x4000 + w1Xw1Y*w2Z)>>VTKKW_FP_SHIFT)) +                    \
00150                (F*((0x4000 + w2Xw1Y*w2Z)>>VTKKW_FP_SHIFT)) +                    \
00151                (G*((0x4000 + w1Xw2Y*w2Z)>>VTKKW_FP_SHIFT)) +                    \
00152                (H*((0x4000 + w2Xw2Y*w2Z)>>VTKKW_FP_SHIFT)))) >> VTKKW_FP_SHIFT;
00153 //ETX
00154 
00155 //BTX
00156 #define VTKKWRCHelper_InterpolateMagnitude( VAL )                                       \
00157   VAL =                                                                                 \
00158     (0x7fff + ((mA*((0x4000 + w1Xw1Y*w1Z)>>VTKKW_FP_SHIFT)) +                           \
00159                (mB*((0x4000 + w2Xw1Y*w1Z)>>VTKKW_FP_SHIFT)) +                           \
00160                (mC*((0x4000 + w1Xw2Y*w1Z)>>VTKKW_FP_SHIFT)) +                           \
00161                (mD*((0x4000 + w2Xw2Y*w1Z)>>VTKKW_FP_SHIFT)) +                           \
00162                (mE*((0x4000 + w1Xw1Y*w2Z)>>VTKKW_FP_SHIFT)) +                           \
00163                (mF*((0x4000 + w2Xw1Y*w2Z)>>VTKKW_FP_SHIFT)) +                           \
00164                (mG*((0x4000 + w1Xw2Y*w2Z)>>VTKKW_FP_SHIFT)) +                           \
00165                (mH*((0x4000 + w2Xw2Y*w2Z)>>VTKKW_FP_SHIFT)))) >> VTKKW_FP_SHIFT;
00166 //ETX
00167 
00168 //BTX
00169 #define VTKKWRCHelper_InterpolateScalarComponent( VAL, CIDX, COMPONENTS )               \
00170   for ( CIDX = 0; CIDX < COMPONENTS; CIDX++ )                                           \
00171     {                                                                                   \
00172     VAL[CIDX] =                                                                         \
00173     (0x7fff + ((A[CIDX]*((0x4000 + w1Xw1Y*w1Z)>>VTKKW_FP_SHIFT)) +                      \
00174                (B[CIDX]*((0x4000 + w2Xw1Y*w1Z)>>VTKKW_FP_SHIFT)) +                      \
00175                (C[CIDX]*((0x4000 + w1Xw2Y*w1Z)>>VTKKW_FP_SHIFT)) +                      \
00176                (D[CIDX]*((0x4000 + w2Xw2Y*w1Z)>>VTKKW_FP_SHIFT)) +                      \
00177                (E[CIDX]*((0x4000 + w1Xw1Y*w2Z)>>VTKKW_FP_SHIFT)) +                      \
00178                (F[CIDX]*((0x4000 + w2Xw1Y*w2Z)>>VTKKW_FP_SHIFT)) +                      \
00179                (G[CIDX]*((0x4000 + w1Xw2Y*w2Z)>>VTKKW_FP_SHIFT)) +                      \
00180                (H[CIDX]*((0x4000 + w2Xw2Y*w2Z)>>VTKKW_FP_SHIFT)))) >> VTKKW_FP_SHIFT;   \
00181     }                                                                                   \
00182 //ETX
00183 
00184 //BTX
00185 #define VTKKWRCHelper_InterpolateMagnitudeComponent( VAL, CIDX, COMPONENTS )            \
00186   for ( CIDX = 0; CIDX < COMPONENTS; CIDX++ )                                           \
00187     {                                                                                   \
00188     VAL[CIDX] =                                                                         \
00189     (0x7fff + ((mA[CIDX]*((0x4000 + w1Xw1Y*w1Z)>>VTKKW_FP_SHIFT)) +                     \
00190                (mB[CIDX]*((0x4000 + w2Xw1Y*w1Z)>>VTKKW_FP_SHIFT)) +                     \
00191                (mC[CIDX]*((0x4000 + w1Xw2Y*w1Z)>>VTKKW_FP_SHIFT)) +                     \
00192                (mD[CIDX]*((0x4000 + w2Xw2Y*w1Z)>>VTKKW_FP_SHIFT)) +                     \
00193                (mE[CIDX]*((0x4000 + w1Xw1Y*w2Z)>>VTKKW_FP_SHIFT)) +                     \
00194                (mF[CIDX]*((0x4000 + w2Xw1Y*w2Z)>>VTKKW_FP_SHIFT)) +                     \
00195                (mG[CIDX]*((0x4000 + w1Xw2Y*w2Z)>>VTKKW_FP_SHIFT)) +                     \
00196                (mH[CIDX]*((0x4000 + w2Xw2Y*w2Z)>>VTKKW_FP_SHIFT)))) >> VTKKW_FP_SHIFT;  \
00197     }
00198 //ETX
00199 
00200 //BTX
00201 #define VTKKWRCHelper_InterpolateShading( DTABLE, STABLE, COLOR )                                       \
00202   unsigned int _tmpDColor[3];                                                                           \
00203   unsigned int _tmpSColor[3];                                                                           \
00204                                                                                                         \
00205   _tmpDColor[0] =                                                                                       \
00206     (0x7fff + ((DTABLE[3*normalA] * ((0x4000 + w1Xw1Y*w1Z)>>VTKKW_FP_SHIFT)) +                          \
00207                (DTABLE[3*normalB] * ((0x4000 + w2Xw1Y*w1Z)>>VTKKW_FP_SHIFT)) +                          \
00208                (DTABLE[3*normalC] * ((0x4000 + w1Xw2Y*w1Z)>>VTKKW_FP_SHIFT)) +                          \
00209                (DTABLE[3*normalD] * ((0x4000 + w2Xw2Y*w1Z)>>VTKKW_FP_SHIFT)) +                          \
00210                (DTABLE[3*normalE] * ((0x4000 + w1Xw1Y*w2Z)>>VTKKW_FP_SHIFT)) +                          \
00211                (DTABLE[3*normalF] * ((0x4000 + w2Xw1Y*w2Z)>>VTKKW_FP_SHIFT)) +                          \
00212                (DTABLE[3*normalG] * ((0x4000 + w1Xw2Y*w2Z)>>VTKKW_FP_SHIFT)) +                          \
00213                (DTABLE[3*normalH] * ((0x4000 + w2Xw2Y*w2Z)>>VTKKW_FP_SHIFT)))) >> VTKKW_FP_SHIFT;       \
00214                                                                                                         \
00215   _tmpDColor[1] =                                                                                       \
00216     (0x7fff + ((DTABLE[3*normalA+1] * ((0x4000 + w1Xw1Y*w1Z)>>VTKKW_FP_SHIFT)) +                        \
00217                (DTABLE[3*normalB+1] * ((0x4000 + w2Xw1Y*w1Z)>>VTKKW_FP_SHIFT)) +                        \
00218                (DTABLE[3*normalC+1] * ((0x4000 + w1Xw2Y*w1Z)>>VTKKW_FP_SHIFT)) +                        \
00219                (DTABLE[3*normalD+1] * ((0x4000 + w2Xw2Y*w1Z)>>VTKKW_FP_SHIFT)) +                        \
00220                (DTABLE[3*normalE+1] * ((0x4000 + w1Xw1Y*w2Z)>>VTKKW_FP_SHIFT)) +                        \
00221                (DTABLE[3*normalF+1] * ((0x4000 + w2Xw1Y*w2Z)>>VTKKW_FP_SHIFT)) +                        \
00222                (DTABLE[3*normalG+1] * ((0x4000 + w1Xw2Y*w2Z)>>VTKKW_FP_SHIFT)) +                        \
00223                (DTABLE[3*normalH+1] * ((0x4000 + w2Xw2Y*w2Z)>>VTKKW_FP_SHIFT)))) >> VTKKW_FP_SHIFT;     \
00224                                                                                                         \
00225   _tmpDColor[2] =                                                                                       \
00226     (0x7fff + ((DTABLE[3*normalA+2] * ((0x4000 + w1Xw1Y*w1Z)>>VTKKW_FP_SHIFT)) +                        \
00227                (DTABLE[3*normalB+2] * ((0x4000 + w2Xw1Y*w1Z)>>VTKKW_FP_SHIFT)) +                        \
00228                (DTABLE[3*normalC+2] * ((0x4000 + w1Xw2Y*w1Z)>>VTKKW_FP_SHIFT)) +                        \
00229                (DTABLE[3*normalD+2] * ((0x4000 + w2Xw2Y*w1Z)>>VTKKW_FP_SHIFT)) +                        \
00230                (DTABLE[3*normalE+2] * ((0x4000 + w1Xw1Y*w2Z)>>VTKKW_FP_SHIFT)) +                        \
00231                (DTABLE[3*normalF+2] * ((0x4000 + w2Xw1Y*w2Z)>>VTKKW_FP_SHIFT)) +                        \
00232                (DTABLE[3*normalG+2] * ((0x4000 + w1Xw2Y*w2Z)>>VTKKW_FP_SHIFT)) +                        \
00233                (DTABLE[3*normalH+2] * ((0x4000 + w2Xw2Y*w2Z)>>VTKKW_FP_SHIFT)))) >> VTKKW_FP_SHIFT;     \
00234                                                                                                         \
00235   _tmpSColor[0] =                                                                                       \
00236     (0x7fff + ((STABLE[3*normalA] * ((0x4000 + w1Xw1Y*w1Z)>>VTKKW_FP_SHIFT)) +                          \
00237                (STABLE[3*normalB] * ((0x4000 + w2Xw1Y*w1Z)>>VTKKW_FP_SHIFT)) +                          \
00238                (STABLE[3*normalC] * ((0x4000 + w1Xw2Y*w1Z)>>VTKKW_FP_SHIFT)) +                          \
00239                (STABLE[3*normalD] * ((0x4000 + w2Xw2Y*w1Z)>>VTKKW_FP_SHIFT)) +                          \
00240                (STABLE[3*normalE] * ((0x4000 + w1Xw1Y*w2Z)>>VTKKW_FP_SHIFT)) +                          \
00241                (STABLE[3*normalF] * ((0x4000 + w2Xw1Y*w2Z)>>VTKKW_FP_SHIFT)) +                          \
00242                (STABLE[3*normalG] * ((0x4000 + w1Xw2Y*w2Z)>>VTKKW_FP_SHIFT)) +                          \
00243                (STABLE[3*normalH] * ((0x4000 + w2Xw2Y*w2Z)>>VTKKW_FP_SHIFT)))) >> VTKKW_FP_SHIFT;       \
00244                                                                                                         \
00245   _tmpSColor[1] =                                                                                       \
00246     (0x7fff + ((STABLE[3*normalA+1] * ((0x4000 + w1Xw1Y*w1Z)>>VTKKW_FP_SHIFT)) +                        \
00247                (STABLE[3*normalB+1] * ((0x4000 + w2Xw1Y*w1Z)>>VTKKW_FP_SHIFT)) +                        \
00248                (STABLE[3*normalC+1] * ((0x4000 + w1Xw2Y*w1Z)>>VTKKW_FP_SHIFT)) +                        \
00249                (STABLE[3*normalD+1] * ((0x4000 + w2Xw2Y*w1Z)>>VTKKW_FP_SHIFT)) +                        \
00250                (STABLE[3*normalE+1] * ((0x4000 + w1Xw1Y*w2Z)>>VTKKW_FP_SHIFT)) +                        \
00251                (STABLE[3*normalF+1] * ((0x4000 + w2Xw1Y*w2Z)>>VTKKW_FP_SHIFT)) +                        \
00252                (STABLE[3*normalG+1] * ((0x4000 + w1Xw2Y*w2Z)>>VTKKW_FP_SHIFT)) +                        \
00253                (STABLE[3*normalH+1] * ((0x4000 + w2Xw2Y*w2Z)>>VTKKW_FP_SHIFT)))) >> VTKKW_FP_SHIFT;     \
00254                                                                                                         \
00255   _tmpSColor[2] =                                                                                       \
00256     (0x7fff + ((STABLE[3*normalA+2] * ((0x4000 + w1Xw1Y*w1Z)>>VTKKW_FP_SHIFT)) +                        \
00257                (STABLE[3*normalB+2] * ((0x4000 + w2Xw1Y*w1Z)>>VTKKW_FP_SHIFT)) +                        \
00258                (STABLE[3*normalC+2] * ((0x4000 + w1Xw2Y*w1Z)>>VTKKW_FP_SHIFT)) +                        \
00259                (STABLE[3*normalD+2] * ((0x4000 + w2Xw2Y*w1Z)>>VTKKW_FP_SHIFT)) +                        \
00260                (STABLE[3*normalE+2] * ((0x4000 + w1Xw1Y*w2Z)>>VTKKW_FP_SHIFT)) +                        \
00261                (STABLE[3*normalF+2] * ((0x4000 + w2Xw1Y*w2Z)>>VTKKW_FP_SHIFT)) +                        \
00262                (STABLE[3*normalG+2] * ((0x4000 + w1Xw2Y*w2Z)>>VTKKW_FP_SHIFT)) +                        \
00263                (STABLE[3*normalH+2] * ((0x4000 + w2Xw2Y*w2Z)>>VTKKW_FP_SHIFT)))) >> VTKKW_FP_SHIFT;     \
00264                                                                                                         \
00265                                                                                                         \
00266   COLOR[0] = static_cast<unsigned short>((_tmpDColor[0]*COLOR[0]+0x7fff)>>VTKKW_FP_SHIFT);              \
00267   COLOR[1] = static_cast<unsigned short>((_tmpDColor[1]*COLOR[1]+0x7fff)>>VTKKW_FP_SHIFT);              \
00268   COLOR[2] = static_cast<unsigned short>((_tmpDColor[2]*COLOR[2]+0x7fff)>>VTKKW_FP_SHIFT);              \
00269   COLOR[0] += (_tmpSColor[0]*COLOR[3] + 0x7fff)>>VTKKW_FP_SHIFT;                                        \
00270   COLOR[1] += (_tmpSColor[1]*COLOR[3] + 0x7fff)>>VTKKW_FP_SHIFT;                                        \
00271   COLOR[2] += (_tmpSColor[2]*COLOR[3] + 0x7fff)>>VTKKW_FP_SHIFT;
00272 //ETX
00273 
00274 
00275 //BTX
00276 #define VTKKWRCHelper_InterpolateShadingComponent( DTABLE, STABLE, COLOR, CIDX )                                \
00277   unsigned int _tmpDColor[3];                                                                                   \
00278   unsigned int _tmpSColor[3];                                                                                   \
00279                                                                                                                 \
00280   _tmpDColor[0] =                                                                                               \
00281     (0x7fff + ((DTABLE[CIDX][3*normalA[CIDX]] * ((0x4000 + w1Xw1Y*w1Z)>>VTKKW_FP_SHIFT)) +                      \
00282                (DTABLE[CIDX][3*normalB[CIDX]] * ((0x4000 + w2Xw1Y*w1Z)>>VTKKW_FP_SHIFT)) +                      \
00283                (DTABLE[CIDX][3*normalC[CIDX]] * ((0x4000 + w1Xw2Y*w1Z)>>VTKKW_FP_SHIFT)) +                      \
00284                (DTABLE[CIDX][3*normalD[CIDX]] * ((0x4000 + w2Xw2Y*w1Z)>>VTKKW_FP_SHIFT)) +                      \
00285                (DTABLE[CIDX][3*normalE[CIDX]] * ((0x4000 + w1Xw1Y*w2Z)>>VTKKW_FP_SHIFT)) +                      \
00286                (DTABLE[CIDX][3*normalF[CIDX]] * ((0x4000 + w2Xw1Y*w2Z)>>VTKKW_FP_SHIFT)) +                      \
00287                (DTABLE[CIDX][3*normalG[CIDX]] * ((0x4000 + w1Xw2Y*w2Z)>>VTKKW_FP_SHIFT)) +                      \
00288                (DTABLE[CIDX][3*normalH[CIDX]] * ((0x4000 + w2Xw2Y*w2Z)>>VTKKW_FP_SHIFT)))) >> VTKKW_FP_SHIFT;   \
00289                                                                                                                 \
00290   _tmpDColor[1] =                                                                                               \
00291     (0x7fff + ((DTABLE[CIDX][3*normalA[CIDX]+1] * ((0x4000 + w1Xw1Y*w1Z)>>VTKKW_FP_SHIFT)) +                    \
00292                (DTABLE[CIDX][3*normalB[CIDX]+1] * ((0x4000 + w2Xw1Y*w1Z)>>VTKKW_FP_SHIFT)) +                    \
00293                (DTABLE[CIDX][3*normalC[CIDX]+1] * ((0x4000 + w1Xw2Y*w1Z)>>VTKKW_FP_SHIFT)) +                    \
00294                (DTABLE[CIDX][3*normalD[CIDX]+1] * ((0x4000 + w2Xw2Y*w1Z)>>VTKKW_FP_SHIFT)) +                    \
00295                (DTABLE[CIDX][3*normalE[CIDX]+1] * ((0x4000 + w1Xw1Y*w2Z)>>VTKKW_FP_SHIFT)) +                    \
00296                (DTABLE[CIDX][3*normalF[CIDX]+1] * ((0x4000 + w2Xw1Y*w2Z)>>VTKKW_FP_SHIFT)) +                    \
00297                (DTABLE[CIDX][3*normalG[CIDX]+1] * ((0x4000 + w1Xw2Y*w2Z)>>VTKKW_FP_SHIFT)) +                    \
00298                (DTABLE[CIDX][3*normalH[CIDX]+1] * ((0x4000 + w2Xw2Y*w2Z)>>VTKKW_FP_SHIFT)))) >> VTKKW_FP_SHIFT; \
00299                                                                                                                 \
00300   _tmpDColor[2] =                                                                                               \
00301     (0x7fff + ((DTABLE[CIDX][3*normalA[CIDX]+2] * ((0x4000 + w1Xw1Y*w1Z)>>VTKKW_FP_SHIFT)) +                    \
00302                (DTABLE[CIDX][3*normalB[CIDX]+2] * ((0x4000 + w2Xw1Y*w1Z)>>VTKKW_FP_SHIFT)) +                    \
00303                (DTABLE[CIDX][3*normalC[CIDX]+2] * ((0x4000 + w1Xw2Y*w1Z)>>VTKKW_FP_SHIFT)) +                    \
00304                (DTABLE[CIDX][3*normalD[CIDX]+2] * ((0x4000 + w2Xw2Y*w1Z)>>VTKKW_FP_SHIFT)) +                    \
00305                (DTABLE[CIDX][3*normalE[CIDX]+2] * ((0x4000 + w1Xw1Y*w2Z)>>VTKKW_FP_SHIFT)) +                    \
00306                (DTABLE[CIDX][3*normalF[CIDX]+2] * ((0x4000 + w2Xw1Y*w2Z)>>VTKKW_FP_SHIFT)) +                    \
00307                (DTABLE[CIDX][3*normalG[CIDX]+2] * ((0x4000 + w1Xw2Y*w2Z)>>VTKKW_FP_SHIFT)) +                    \
00308                (DTABLE[CIDX][3*normalH[CIDX]+2] * ((0x4000 + w2Xw2Y*w2Z)>>VTKKW_FP_SHIFT)))) >> VTKKW_FP_SHIFT; \
00309                                                                                                                 \
00310   _tmpSColor[0] =                                                                                               \
00311     (0x7fff + ((STABLE[CIDX][3*normalA[CIDX]] * ((0x4000 + w1Xw1Y*w1Z)>>VTKKW_FP_SHIFT)) +                      \
00312                (STABLE[CIDX][3*normalB[CIDX]] * ((0x4000 + w2Xw1Y*w1Z)>>VTKKW_FP_SHIFT)) +                      \
00313                (STABLE[CIDX][3*normalC[CIDX]] * ((0x4000 + w1Xw2Y*w1Z)>>VTKKW_FP_SHIFT)) +                      \
00314                (STABLE[CIDX][3*normalD[CIDX]] * ((0x4000 + w2Xw2Y*w1Z)>>VTKKW_FP_SHIFT)) +                      \
00315                (STABLE[CIDX][3*normalE[CIDX]] * ((0x4000 + w1Xw1Y*w2Z)>>VTKKW_FP_SHIFT)) +                      \
00316                (STABLE[CIDX][3*normalF[CIDX]] * ((0x4000 + w2Xw1Y*w2Z)>>VTKKW_FP_SHIFT)) +                      \
00317                (STABLE[CIDX][3*normalG[CIDX]] * ((0x4000 + w1Xw2Y*w2Z)>>VTKKW_FP_SHIFT)) +                      \
00318                (STABLE[CIDX][3*normalH[CIDX]] * ((0x4000 + w2Xw2Y*w2Z)>>VTKKW_FP_SHIFT)))) >> VTKKW_FP_SHIFT;   \
00319                                                                                                                 \
00320   _tmpSColor[1] =                                                                                               \
00321     (0x7fff + ((STABLE[CIDX][3*normalA[CIDX]+1] * ((0x4000 + w1Xw1Y*w1Z)>>VTKKW_FP_SHIFT)) +                    \
00322                (STABLE[CIDX][3*normalB[CIDX]+1] * ((0x4000 + w2Xw1Y*w1Z)>>VTKKW_FP_SHIFT)) +                    \
00323                (STABLE[CIDX][3*normalC[CIDX]+1] * ((0x4000 + w1Xw2Y*w1Z)>>VTKKW_FP_SHIFT)) +                    \
00324                (STABLE[CIDX][3*normalD[CIDX]+1] * ((0x4000 + w2Xw2Y*w1Z)>>VTKKW_FP_SHIFT)) +                    \
00325                (STABLE[CIDX][3*normalE[CIDX]+1] * ((0x4000 + w1Xw1Y*w2Z)>>VTKKW_FP_SHIFT)) +                    \
00326                (STABLE[CIDX][3*normalF[CIDX]+1] * ((0x4000 + w2Xw1Y*w2Z)>>VTKKW_FP_SHIFT)) +                    \
00327                (STABLE[CIDX][3*normalG[CIDX]+1] * ((0x4000 + w1Xw2Y*w2Z)>>VTKKW_FP_SHIFT)) +                    \
00328                (STABLE[CIDX][3*normalH[CIDX]+1] * ((0x4000 + w2Xw2Y*w2Z)>>VTKKW_FP_SHIFT)))) >> VTKKW_FP_SHIFT; \
00329                                                                                                                 \
00330   _tmpSColor[2] =                                                                                               \
00331     (0x7fff + ((STABLE[CIDX][3*normalA[CIDX]+2] * ((0x4000 + w1Xw1Y*w1Z)>>VTKKW_FP_SHIFT)) +                    \
00332                (STABLE[CIDX][3*normalB[CIDX]+2] * ((0x4000 + w2Xw1Y*w1Z)>>VTKKW_FP_SHIFT)) +                    \
00333                (STABLE[CIDX][3*normalC[CIDX]+2] * ((0x4000 + w1Xw2Y*w1Z)>>VTKKW_FP_SHIFT)) +                    \
00334                (STABLE[CIDX][3*normalD[CIDX]+2] * ((0x4000 + w2Xw2Y*w1Z)>>VTKKW_FP_SHIFT)) +                    \
00335                (STABLE[CIDX][3*normalE[CIDX]+2] * ((0x4000 + w1Xw1Y*w2Z)>>VTKKW_FP_SHIFT)) +                    \
00336                (STABLE[CIDX][3*normalF[CIDX]+2] * ((0x4000 + w2Xw1Y*w2Z)>>VTKKW_FP_SHIFT)) +                    \
00337                (STABLE[CIDX][3*normalG[CIDX]+2] * ((0x4000 + w1Xw2Y*w2Z)>>VTKKW_FP_SHIFT)) +                    \
00338                (STABLE[CIDX][3*normalH[CIDX]+2] * ((0x4000 + w2Xw2Y*w2Z)>>VTKKW_FP_SHIFT)))) >> VTKKW_FP_SHIFT; \
00339                                                                                                                 \
00340                                                                                                                 \
00341   COLOR[0] = static_cast<unsigned short>((_tmpDColor[0]*COLOR[0]+0x7fff)>>VTKKW_FP_SHIFT);                      \
00342   COLOR[1] = static_cast<unsigned short>((_tmpDColor[1]*COLOR[1]+0x7fff)>>VTKKW_FP_SHIFT);                      \
00343   COLOR[2] = static_cast<unsigned short>((_tmpDColor[2]*COLOR[2]+0x7fff)>>VTKKW_FP_SHIFT);                      \
00344   COLOR[0] += (_tmpSColor[0]*COLOR[3] + 0x7fff)>>VTKKW_FP_SHIFT;                                                \
00345   COLOR[1] += (_tmpSColor[1]*COLOR[3] + 0x7fff)>>VTKKW_FP_SHIFT;                                                \
00346   COLOR[2] += (_tmpSColor[2]*COLOR[3] + 0x7fff)>>VTKKW_FP_SHIFT;
00347 //ETX
00348 
00349 //BTX
00350 #define VTKKWRCHelper_LookupColorUS( COLORTABLE, SCALAROPACITYTABLE, IDX, COLOR )       \
00351   COLOR[3] = SCALAROPACITYTABLE[IDX];                                                   \
00352   if ( !COLOR[3] ) {continue;}                                                          \
00353   COLOR[0] = static_cast<unsigned short>                                                \
00354     ((COLORTABLE[3*IDX  ]*COLOR[3] + 0x7fff)>>(VTKKW_FP_SHIFT));                        \
00355   COLOR[1] = static_cast<unsigned short>                                                \
00356     ((COLORTABLE[3*IDX+1]*COLOR[3] + 0x7fff)>>(VTKKW_FP_SHIFT));                        \
00357   COLOR[2] = static_cast<unsigned short>                                                \
00358     ((COLORTABLE[3*IDX+2]*COLOR[3] + 0x7fff)>>(VTKKW_FP_SHIFT));
00359 //ETX
00360 
00361 //BTX
00362 #define VTKKWRCHelper_LookupColorMax( COLORTABLE, SCALAROPACITYTABLE, IDX, COLOR )    \
00363   COLOR[3] = SCALAROPACITYTABLE[IDX];                                                 \
00364   COLOR[0] = static_cast<unsigned short>                                              \
00365     ((COLORTABLE[3*IDX  ]*COLOR[3] + 0x7fff)>>(VTKKW_FP_SHIFT));                      \
00366   COLOR[1] = static_cast<unsigned short>                                              \
00367     ((COLORTABLE[3*IDX+1]*COLOR[3] + 0x7fff)>>(VTKKW_FP_SHIFT));                      \
00368   COLOR[2] = static_cast<unsigned short>                                              \
00369     ((COLORTABLE[3*IDX+2]*COLOR[3] + 0x7fff)>>(VTKKW_FP_SHIFT));
00370 //ETX
00371 
00372 //BTX
00373 #define VTKKWRCHelper_LookupDependentColorUS( COLORTABLE, SCALAROPACITYTABLE, IDX, CMPS, COLOR )        \
00374   {                                                                                                     \
00375   unsigned short _alpha;                                                                                \
00376   switch ( CMPS )                                                                                       \
00377     {                                                                                                   \
00378     case 2:                                                                                             \
00379       _alpha = SCALAROPACITYTABLE[IDX[1]];                                                              \
00380       COLOR[0] = static_cast<unsigned short>                                                            \
00381         ((COLORTABLE[3*IDX[0]  ]*_alpha + 0x7fff)>>(VTKKW_FP_SHIFT));                                   \
00382       COLOR[1] = static_cast<unsigned short>                                                            \
00383         ((COLORTABLE[3*IDX[0]+1]*_alpha + 0x7fff)>>(VTKKW_FP_SHIFT));                                   \
00384       COLOR[2] = static_cast<unsigned short>                                                            \
00385         ((COLORTABLE[3*IDX[0]+2]*_alpha + 0x7fff)>>(VTKKW_FP_SHIFT));                                   \
00386       COLOR[3] = _alpha;                                                                                \
00387       break;                                                                                            \
00388     case 4:                                                                                             \
00389       _alpha = SCALAROPACITYTABLE[IDX[3]];                                                              \
00390       COLOR[0] = static_cast<unsigned short>((IDX[0]*_alpha + 0x7f)>>8 );                               \
00391       COLOR[1] = static_cast<unsigned short>((IDX[1]*_alpha + 0x7f)>>8 );                               \
00392       COLOR[2] = static_cast<unsigned short>((IDX[2]*_alpha + 0x7f)>>8 );                               \
00393       COLOR[3] = _alpha;                                                                                \
00394       break;                                                                                            \
00395     }                                                                                                   \
00396   }
00397 //ETX
00398 
00399 //BTX
00400 #define VTKKWRCHelper_LookupColorGOUS( CTABLE, SOTABLE, GOTABLE, IDX, IDX2, COLOR )     \
00401   COLOR[3] = (SOTABLE[IDX] * GOTABLE[IDX2] + 0x7fff)>>VTKKW_FP_SHIFT;                   \
00402   if ( !COLOR[3] ) {continue;}                                                          \
00403   COLOR[0] = static_cast<unsigned short>                                                \
00404     ((CTABLE[3*IDX  ]*COLOR[3] + 0x7fff)>>(VTKKW_FP_SHIFT));                            \
00405   COLOR[1] = static_cast<unsigned short>                                                \
00406     ((CTABLE[3*IDX+1]*COLOR[3] + 0x7fff)>>(VTKKW_FP_SHIFT));                            \
00407   COLOR[2] = static_cast<unsigned short>                                                \
00408     ((CTABLE[3*IDX+2]*COLOR[3] + 0x7fff)>>(VTKKW_FP_SHIFT));
00409 //ETX
00410 
00411 //BTX
00412 #define VTKKWRCHelper_LookupShading( DTABLE, STABLE, NORMAL, COLOR )                            \
00413   COLOR[0] = static_cast<unsigned short>((DTABLE[3*NORMAL  ]*COLOR[0]+0x7fff)>>VTKKW_FP_SHIFT); \
00414   COLOR[1] = static_cast<unsigned short>((DTABLE[3*NORMAL+1]*COLOR[1]+0x7fff)>>VTKKW_FP_SHIFT); \
00415   COLOR[2] = static_cast<unsigned short>((DTABLE[3*NORMAL+2]*COLOR[2]+0x7fff)>>VTKKW_FP_SHIFT); \
00416   COLOR[0] += (STABLE[3*NORMAL  ]*COLOR[3] + 0x7fff)>>VTKKW_FP_SHIFT;                           \
00417   COLOR[1] += (STABLE[3*NORMAL+1]*COLOR[3] + 0x7fff)>>VTKKW_FP_SHIFT;                           \
00418   COLOR[2] += (STABLE[3*NORMAL+2]*COLOR[3] + 0x7fff)>>VTKKW_FP_SHIFT;
00419 //ETX
00420 
00421 
00422 //BTX
00423 #define VTKKWRCHelper_LookupAndCombineIndependentColorsUS( COLORTABLE, SOTABLE,                                                 \
00424                                                            SCALAR, WEIGHTS,                                                     \
00425                                                            COMPONENTS, COLOR )                                                  \
00426   unsigned int _tmp[4] = {0,0,0,0};                                                                                             \
00427   unsigned short _alpha[4] = {0,0,0,0};                                                                                         \
00428   unsigned int _totalAlpha = 0;                                                                                                 \
00429                                                                                                                                 \
00430   {for ( int _idx = 0; _idx < COMPONENTS; _idx++ )                                                                              \
00431     {                                                                                                                           \
00432     _alpha[_idx] = static_cast<unsigned short>(SOTABLE[_idx][SCALAR[_idx]]*WEIGHTS[_idx]);                                      \
00433     _totalAlpha += _alpha[_idx];                                                                                                \
00434     }}                                                                                                                          \
00435                                                                                                                                 \
00436   if ( !_totalAlpha ) {continue;}                                                                                               \
00437   {for ( int _idx = 0; _idx < COMPONENTS; _idx++ )                                                                              \
00438     {                                                                                                                           \
00439     if ( _alpha[_idx] )                                                                                                         \
00440       {                                                                                                                         \
00441       _tmp[0] += static_cast<unsigned short>(((COLORTABLE[_idx][3*SCALAR[_idx]  ])*_alpha[_idx] + 0x7fff)>>(VTKKW_FP_SHIFT));   \
00442       _tmp[1] += static_cast<unsigned short>(((COLORTABLE[_idx][3*SCALAR[_idx]+1])*_alpha[_idx] + 0x7fff)>>(VTKKW_FP_SHIFT));   \
00443       _tmp[2] += static_cast<unsigned short>(((COLORTABLE[_idx][3*SCALAR[_idx]+2])*_alpha[_idx] + 0x7fff)>>(VTKKW_FP_SHIFT));   \
00444       _tmp[3] += ((_alpha[_idx]*_alpha[_idx])/_totalAlpha);                                                                     \
00445       }                                                                                                                         \
00446     }}                                                                                                                          \
00447   if ( !_tmp[3] ) {continue;}                                                                                                   \
00448   COLOR[0] = (_tmp[0]>32767)?(32767):(_tmp[0]);                                                                                 \
00449   COLOR[1] = (_tmp[1]>32767)?(32767):(_tmp[1]);                                                                                 \
00450   COLOR[2] = (_tmp[2]>32767)?(32767):(_tmp[2]);                                                                                 \
00451   COLOR[3] = (_tmp[3]>32767)?(32767):(_tmp[3]);
00452 //ETX
00453 
00454 //BTX
00455 #define VTKKWRCHelper_LookupAndCombineIndependentColorsMax( COLORTABLE, SCALAROPACITYTABLE,                             \
00456                                                             IDX, WEIGHTS, CMPS, COLOR )                                 \
00457   {                                                                                                                     \
00458   unsigned int _tmp[4] = {0,0,0,0};                                                                                     \
00459   for ( int _idx = 0; _idx < CMPS; _idx++ )                                                                             \
00460     {                                                                                                                   \
00461     unsigned short _alpha = static_cast<unsigned short>(SCALAROPACITYTABLE[_idx][IDX[_idx]]*WEIGHTS[_idx]);             \
00462     _tmp[0] += static_cast<unsigned short>(((COLORTABLE[_idx][3*IDX[_idx]  ])*_alpha + 0x7fff)>>(VTKKW_FP_SHIFT));      \
00463     _tmp[1] += static_cast<unsigned short>(((COLORTABLE[_idx][3*IDX[_idx]+1])*_alpha + 0x7fff)>>(VTKKW_FP_SHIFT));      \
00464     _tmp[2] += static_cast<unsigned short>(((COLORTABLE[_idx][3*IDX[_idx]+2])*_alpha + 0x7fff)>>(VTKKW_FP_SHIFT));      \
00465     _tmp[3] += _alpha;                                                                                                  \
00466     }                                                                                                                   \
00467   COLOR[0] = (_tmp[0]>32767)?(32767):(_tmp[0]);                                                                         \
00468   COLOR[1] = (_tmp[1]>32767)?(32767):(_tmp[1]);                                                                         \
00469   COLOR[2] = (_tmp[2]>32767)?(32767):(_tmp[2]);                                                                         \
00470   COLOR[3] = (_tmp[3]>32767)?(32767):(_tmp[3]);                                                                         \
00471   }
00472 //ETX
00473 
00474 //BTX
00475 #define VTKKWRCHelper_LookupAndCombineIndependentColorsGOUS( COLORTABLE, SOTABLE,                                               \
00476                                                            GOTABLE,                                                             \
00477                                                            SCALAR, MAG, WEIGHTS,                                                \
00478                                                            COMPONENTS, COLOR )                                                  \
00479   unsigned int _tmp[4] = {0,0,0,0};                                                                                             \
00480   unsigned short _alpha[4] = {0,0,0,0};                                                                                         \
00481   unsigned int _totalAlpha = 0;                                                                                                 \
00482                                                                                                                                 \
00483   {for ( int _idx = 0; _idx < COMPONENTS; _idx++ )                                                                              \
00484     {                                                                                                                           \
00485     _alpha[_idx] =  static_cast<unsigned short>(SOTABLE[_idx][SCALAR[_idx]]*WEIGHTS[_idx]);                                     \
00486     if ( _alpha[_idx] )                                                                                                         \
00487       {                                                                                                                         \
00488       _alpha[_idx] = static_cast<unsigned short>((_alpha[_idx]*GOTABLE[_idx][MAG[_idx]] + 0x7fff)>>(VTKKW_FP_SHIFT));           \
00489       _totalAlpha += _alpha[_idx];                                                                                              \
00490       }                                                                                                                         \
00491     }}                                                                                                                          \
00492                                                                                                                                 \
00493   if ( !_totalAlpha ) {continue;}                                                                                               \
00494   {for ( int _idx = 0; _idx < COMPONENTS; _idx++ )                                                                              \
00495     {                                                                                                                           \
00496     if ( _alpha[_idx] )                                                                                                         \
00497       {                                                                                                                         \
00498       _tmp[0] += static_cast<unsigned short>(((COLORTABLE[_idx][3*SCALAR[_idx]  ])*_alpha[_idx] + 0x7fff)>>(VTKKW_FP_SHIFT));   \
00499       _tmp[1] += static_cast<unsigned short>(((COLORTABLE[_idx][3*SCALAR[_idx]+1])*_alpha[_idx] + 0x7fff)>>(VTKKW_FP_SHIFT));   \
00500       _tmp[2] += static_cast<unsigned short>(((COLORTABLE[_idx][3*SCALAR[_idx]+2])*_alpha[_idx] + 0x7fff)>>(VTKKW_FP_SHIFT));   \
00501       _tmp[3] += ((_alpha[_idx]*_alpha[_idx])/_totalAlpha);                                                                     \
00502       }                                                                                                                         \
00503     }}                                                                                                                          \
00504   if ( !_tmp[3] ) {continue;};                                                                                                  \
00505   COLOR[0] = (_tmp[0]>32767)?(32767):(_tmp[0]);                                                                                 \
00506   COLOR[1] = (_tmp[1]>32767)?(32767):(_tmp[1]);                                                                                 \
00507   COLOR[2] = (_tmp[2]>32767)?(32767):(_tmp[2]);                                                                                 \
00508   COLOR[3] = (_tmp[3]>32767)?(32767):(_tmp[3]);
00509 //ETX
00510 
00511 //BTX
00512 #define VTKKWRCHelper_LookupAndCombineIndependentColorsShadeUS( COLORTABLE, SOTABLE,                                            \
00513                                                                 DTABLE, STABLE,                                                 \
00514                                                                 SCALAR, NORMAL, WEIGHTS,                                        \
00515                                                                 COMPONENTS, COLOR )                                             \
00516   unsigned int _tmp[4] = {0,0,0,0};                                                                                             \
00517   unsigned int _tmpC[3];                                                                                                        \
00518   unsigned short _alpha[4] = {0,0,0,0};                                                                                         \
00519   unsigned int _totalAlpha = 0;                                                                                                 \
00520                                                                                                                                 \
00521   {for ( int _idx = 0; _idx < COMPONENTS; _idx++ )                                                                              \
00522     {                                                                                                                           \
00523     _alpha[_idx] = static_cast<unsigned short>(SOTABLE[_idx][SCALAR[_idx]]*WEIGHTS[_idx]);                                      \
00524     _totalAlpha += _alpha[_idx];                                                                                                \
00525     }}                                                                                                                          \
00526                                                                                                                                 \
00527   if ( !_totalAlpha ) {continue;}                                                                                               \
00528   {for ( int _idx = 0; _idx < COMPONENTS; _idx++ )                                                                              \
00529     {                                                                                                                           \
00530     if ( _alpha[_idx] )                                                                                                         \
00531       {                                                                                                                         \
00532       _tmpC[0] = static_cast<unsigned short>(((COLORTABLE[_idx][3*SCALAR[_idx]  ])*_alpha[_idx] + 0x7fff)>>(VTKKW_FP_SHIFT));   \
00533       _tmpC[1] = static_cast<unsigned short>(((COLORTABLE[_idx][3*SCALAR[_idx]+1])*_alpha[_idx] + 0x7fff)>>(VTKKW_FP_SHIFT));   \
00534       _tmpC[2] = static_cast<unsigned short>(((COLORTABLE[_idx][3*SCALAR[_idx]+2])*_alpha[_idx] + 0x7fff)>>(VTKKW_FP_SHIFT));   \
00535       _tmpC[0] = static_cast<unsigned short>((DTABLE[_idx][3*NORMAL[_idx]  ]*_tmpC[0]+0x7fff)>>VTKKW_FP_SHIFT);                 \
00536       _tmpC[1] = static_cast<unsigned short>((DTABLE[_idx][3*NORMAL[_idx]+1]*_tmpC[1]+0x7fff)>>VTKKW_FP_SHIFT);                 \
00537       _tmpC[2] = static_cast<unsigned short>((DTABLE[_idx][3*NORMAL[_idx]+2]*_tmpC[2]+0x7fff)>>VTKKW_FP_SHIFT);                 \
00538       _tmpC[0] += (STABLE[_idx][3*NORMAL[_idx]  ]*_alpha[_idx] + 0x7fff)>>VTKKW_FP_SHIFT;                                       \
00539       _tmpC[1] += (STABLE[_idx][3*NORMAL[_idx]+1]*_alpha[_idx] + 0x7fff)>>VTKKW_FP_SHIFT;                                       \
00540       _tmpC[2] += (STABLE[_idx][3*NORMAL[_idx]+2]*_alpha[_idx] + 0x7fff)>>VTKKW_FP_SHIFT;                                       \
00541       _tmp[0] += _tmpC[0];                                                                                                      \
00542       _tmp[1] += _tmpC[1];                                                                                                      \
00543       _tmp[2] += _tmpC[2];                                                                                                      \
00544       _tmp[3] += ((_alpha[_idx]*_alpha[_idx])/_totalAlpha);                                                                     \
00545       }                                                                                                                         \
00546     }}                                                                                                                           \
00547   if ( !_tmp[3] ) {continue;}                                                                                                   \
00548                                                                                                                                 \
00549   COLOR[0] = (_tmp[0]>32767)?(32767):(_tmp[0]);                                                                                 \
00550   COLOR[1] = (_tmp[1]>32767)?(32767):(_tmp[1]);                                                                                 \
00551   COLOR[2] = (_tmp[2]>32767)?(32767):(_tmp[2]);                                                                                 \
00552   COLOR[3] = (_tmp[3]>32767)?(32767):(_tmp[3]);
00553 //ETX
00554 
00555 //BTX
00556 #define VTKKWRCHelper_LookupAndCombineIndependentColorsInterpolateShadeUS( COLORTABLE, SOTABLE,                                 \
00557                                                                            DTABLE, STABLE,                                      \
00558                                                                            SCALAR, WEIGHTS,                                     \
00559                                                                            COMPONENTS, COLOR )                                  \
00560   unsigned int _tmp[4] = {0,0,0,0};                                                                                             \
00561   unsigned int _tmpC[4];                                                                                                        \
00562   unsigned short _alpha[4] = {0,0,0,0};                                                                                         \
00563   unsigned int _totalAlpha = 0;                                                                                                 \
00564                                                                                                                                 \
00565   {for ( int _idx = 0; _idx < COMPONENTS; _idx++ )                                                                              \
00566     {                                                                                                                           \
00567     _alpha[_idx] = static_cast<unsigned short>(SOTABLE[_idx][SCALAR[_idx]]*WEIGHTS[_idx]);                                      \
00568     _totalAlpha += _alpha[_idx];                                                                                                \
00569     }}                                                                                                                          \
00570                                                                                                                                 \
00571   if ( !_totalAlpha ) {continue;}                                                                                               \
00572   {for ( int _idx = 0; _idx < COMPONENTS; _idx++ )                                                                              \
00573     {                                                                                                                           \
00574     if ( _alpha[_idx] )                                                                                                         \
00575       {                                                                                                                         \
00576       _tmpC[0] = static_cast<unsigned short>(((COLORTABLE[_idx][3*SCALAR[_idx]  ])*_alpha[_idx] + 0x7fff)>>(VTKKW_FP_SHIFT));   \
00577       _tmpC[1] = static_cast<unsigned short>(((COLORTABLE[_idx][3*SCALAR[_idx]+1])*_alpha[_idx] + 0x7fff)>>(VTKKW_FP_SHIFT));   \
00578       _tmpC[2] = static_cast<unsigned short>(((COLORTABLE[_idx][3*SCALAR[_idx]+2])*_alpha[_idx] + 0x7fff)>>(VTKKW_FP_SHIFT));   \
00579       _tmpC[3] = _alpha[_idx];                                                                                                  \
00580       VTKKWRCHelper_InterpolateShadingComponent( DTABLE, STABLE, _tmpC, _idx );                                                 \
00581       _tmp[0] += _tmpC[0];                                                                                                      \
00582       _tmp[1] += _tmpC[1];                                                                                                      \
00583       _tmp[2] += _tmpC[2];                                                                                                      \
00584       _tmp[3] += ((_alpha[_idx]*_alpha[_idx])/_totalAlpha);                                                                     \
00585       }                                                                                                                         \
00586     }}                                                                                                                          \
00587   if (!_tmp[3]) {continue;}                                                                                                     \
00588   COLOR[0] = (_tmp[0]>32767)?(32767):(_tmp[0]);                                                                                 \
00589   COLOR[1] = (_tmp[1]>32767)?(32767):(_tmp[1]);                                                                                 \
00590   COLOR[2] = (_tmp[2]>32767)?(32767):(_tmp[2]);                                                                                 \
00591   COLOR[3] = (_tmp[3]>32767)?(32767):(_tmp[3]);
00592 //ETX
00593 
00594 //BTX
00595 #define VTKKWRCHelper_CompositeColorAndCheckEarlyTermination( COLOR, TMP, REMAININGOPACITY )    \
00596   COLOR[0] += (TMP[0]*REMAININGOPACITY+0x7fff)>>VTKKW_FP_SHIFT;                                 \
00597   COLOR[1] += (TMP[1]*REMAININGOPACITY+0x7fff)>>VTKKW_FP_SHIFT;                                 \
00598   COLOR[2] += (TMP[2]*REMAININGOPACITY+0x7fff)>>VTKKW_FP_SHIFT;                                 \
00599   REMAININGOPACITY = (REMAININGOPACITY*((~(TMP[3])&VTKKW_FP_MASK))+0x7fff)>>VTKKW_FP_SHIFT;     \
00600   if ( REMAININGOPACITY < 0xff )                                                                \
00601     {                                                                                           \
00602     break;                                                                                      \
00603     }
00604 //ETX
00605 
00606 //BTX
00607 #define VTKKWRCHelper_LookupAndCombineIndependentColorsGOShadeUS( COLORTABLE, SOTABLE, GOTABLE,                                 \
00608                                                                 DTABLE, STABLE,                                                 \
00609                                                                 SCALAR, MAG, NORMAL, WEIGHTS,                                   \
00610                                                                 COMPONENTS, COLOR )                                             \
00611   unsigned int _tmp[4] = {0,0,0,0};                                                                                             \
00612   unsigned int _tmpC[3];                                                                                                        \
00613   unsigned short _alpha[4] = {0,0,0,0};                                                                                         \
00614   unsigned int _totalAlpha = 0;                                                                                                 \
00615                                                                                                                                 \
00616   {for ( int _idx = 0; _idx < COMPONENTS; _idx++ )                                                                              \
00617     {                                                                                                                           \
00618     _alpha[_idx] =  static_cast<unsigned short>(SOTABLE[_idx][SCALAR[_idx]]*WEIGHTS[_idx]);                                     \
00619     if ( _alpha[_idx] )                                                                                                         \
00620       {                                                                                                                         \
00621       _alpha[_idx] = static_cast<unsigned short>((_alpha[_idx]*GOTABLE[_idx][MAG[_idx]] + 0x7fff)>>(VTKKW_FP_SHIFT));           \
00622       _totalAlpha += _alpha[_idx];                                                                                              \
00623       }                                                                                                                         \
00624     }}                                                                                                                          \
00625                                                                                                                                 \
00626   if ( !_totalAlpha ) {continue;}                                                                                               \
00627                                                                                                                                 \
00628   {for ( int _idx = 0; _idx < COMPONENTS; _idx++ )                                                                              \
00629     {                                                                                                                           \
00630     if ( _alpha[_idx] )                                                                                                         \
00631       {                                                                                                                         \
00632       _tmpC[0] = static_cast<unsigned short>(((COLORTABLE[_idx][3*SCALAR[_idx]  ])*_alpha[_idx] + 0x7fff)>>(VTKKW_FP_SHIFT));   \
00633       _tmpC[1] = static_cast<unsigned short>(((COLORTABLE[_idx][3*SCALAR[_idx]+1])*_alpha[_idx] + 0x7fff)>>(VTKKW_FP_SHIFT));   \
00634       _tmpC[2] = static_cast<unsigned short>(((COLORTABLE[_idx][3*SCALAR[_idx]+2])*_alpha[_idx] + 0x7fff)>>(VTKKW_FP_SHIFT));   \
00635       _tmpC[0] = static_cast<unsigned short>((DTABLE[_idx][3*NORMAL[_idx]  ]*_tmpC[0]+0x7fff)>>VTKKW_FP_SHIFT);                 \
00636       _tmpC[1] = static_cast<unsigned short>((DTABLE[_idx][3*NORMAL[_idx]+1]*_tmpC[1]+0x7fff)>>VTKKW_FP_SHIFT);                 \
00637       _tmpC[2] = static_cast<unsigned short>((DTABLE[_idx][3*NORMAL[_idx]+2]*_tmpC[2]+0x7fff)>>VTKKW_FP_SHIFT);                 \
00638       _tmpC[0] += (STABLE[_idx][3*NORMAL[_idx]  ]*_alpha[_idx] + 0x7fff)>>VTKKW_FP_SHIFT;                                       \
00639       _tmpC[1] += (STABLE[_idx][3*NORMAL[_idx]+1]*_alpha[_idx] + 0x7fff)>>VTKKW_FP_SHIFT;                                       \
00640       _tmpC[2] += (STABLE[_idx][3*NORMAL[_idx]+2]*_alpha[_idx] + 0x7fff)>>VTKKW_FP_SHIFT;                                       \
00641       _tmp[0] += _tmpC[0];                                                                                                      \
00642       _tmp[1] += _tmpC[1];                                                                                                      \
00643       _tmp[2] += _tmpC[2];                                                                                                      \
00644       _tmp[3] += ((_alpha[_idx]*_alpha[_idx])/_totalAlpha);                                                                     \
00645       }                                                                                                                         \
00646     }}                                                                                                                          \
00647   if ( !_tmp[3] ) {continue;}                                                                                                   \
00648   COLOR[0] = (_tmp[0]>32767)?(32767):(_tmp[0]);                                                                                 \
00649   COLOR[1] = (_tmp[1]>32767)?(32767):(_tmp[1]);                                                                                 \
00650   COLOR[2] = (_tmp[2]>32767)?(32767):(_tmp[2]);                                                                                 \
00651   COLOR[3] = (_tmp[3]>32767)?(32767):(_tmp[3]);
00652 //ETX
00653 
00654 //BTX
00655 #define VTKKWRCHelper_LookupAndCombineIndependentColorsGOInterpolateShadeUS( COLORTABLE, SOTABLE, GOTABLE,                      \
00656                                                                 DTABLE, STABLE,                                                 \
00657                                                                 SCALAR, MAG, WEIGHTS,                                           \
00658                                                                 COMPONENTS, COLOR )                                             \
00659   unsigned int _tmp[4] = {0,0,0,0};                                                                                             \
00660   unsigned int _tmpC[4];                                                                                                        \
00661   unsigned short _alpha[4] = {0,0,0,0};                                                                                         \
00662   unsigned int _totalAlpha = 0;                                                                                                 \
00663                                                                                                                                 \
00664   {for ( int _idx = 0; _idx < COMPONENTS; _idx++ )                                                                              \
00665     {                                                                                                                           \
00666     _alpha[_idx] =  static_cast<unsigned short>(SOTABLE[_idx][SCALAR[_idx]]*WEIGHTS[_idx]);                                     \
00667     if ( _alpha[_idx] )                                                                                                         \
00668       {                                                                                                                         \
00669       _alpha[_idx] = static_cast<unsigned short>((_alpha[_idx]*GOTABLE[_idx][MAG[_idx]] + 0x7fff)>>(VTKKW_FP_SHIFT));           \
00670       _totalAlpha += _alpha[_idx];                                                                                              \
00671       }                                                                                                                         \
00672     }}                                                                                                                          \
00673                                                                                                                                 \
00674   if ( !_totalAlpha ) {continue;}                                                                                               \
00675   {for ( int _idx = 0; _idx < COMPONENTS; _idx++ )                                                                              \
00676     {                                                                                                                           \
00677     if ( _alpha[_idx] )                                                                                                         \
00678       {                                                                                                                         \
00679       _tmpC[0] = static_cast<unsigned short>(((COLORTABLE[_idx][3*SCALAR[_idx]  ])*_alpha[_idx] + 0x7fff)>>(VTKKW_FP_SHIFT));   \
00680       _tmpC[1] = static_cast<unsigned short>(((COLORTABLE[_idx][3*SCALAR[_idx]+1])*_alpha[_idx] + 0x7fff)>>(VTKKW_FP_SHIFT));   \
00681       _tmpC[2] = static_cast<unsigned short>(((COLORTABLE[_idx][3*SCALAR[_idx]+2])*_alpha[_idx] + 0x7fff)>>(VTKKW_FP_SHIFT));   \
00682       _tmpC[3] = _alpha[_idx];                                                                                                  \
00683       VTKKWRCHelper_InterpolateShadingComponent( DTABLE, STABLE, _tmpC, _idx );                                                 \
00684       _tmp[0] += _tmpC[0];                                                                                                      \
00685       _tmp[1] += _tmpC[1];                                                                                                      \
00686       _tmp[2] += _tmpC[2];                                                                                                      \
00687       _tmp[3] += ((_alpha[_idx]*_alpha[_idx])/_totalAlpha);                                                                     \
00688       }                                                                                                                         \
00689     }}                                                                                                                           \
00690   if ( !_tmp[3] ) {continue;}                                                                                                   \
00691   COLOR[0] = (_tmp[0]>32767)?(32767):(_tmp[0]);                                                                                 \
00692   COLOR[1] = (_tmp[1]>32767)?(32767):(_tmp[1]);                                                                                 \
00693   COLOR[2] = (_tmp[2]>32767)?(32767):(_tmp[2]);                                                                                 \
00694   COLOR[3] = (_tmp[3]>32767)?(32767):(_tmp[3]);
00695 //ETX
00696 
00697 
00698 //BTX
00699 #define VTKKWRCHelper_SetPixelColor( IMAGEPTR, COLOR, REMAININGOPACITY )        \
00700   IMAGEPTR[0] = (COLOR[0]>32767)?(32767):(COLOR[0]);                            \
00701   IMAGEPTR[1] = (COLOR[1]>32767)?(32767):(COLOR[1]);                            \
00702   IMAGEPTR[2] = (COLOR[2]>32767)?(32767):(COLOR[2]);                           \
00703   unsigned int tmpAlpha = (~REMAININGOPACITY)&VTKKW_FP_MASK;                    \
00704   IMAGEPTR[3] = (tmpAlpha>32767)?(32767):(tmpAlpha);
00705 //ETX
00706 
00707 //BTX
00708 #define VTKKWRCHelper_MoveToNextSampleNN()                                      \
00709   if ( k < numSteps-1 )                                                         \
00710     {                                                                           \
00711     mapper->FixedPointIncrement( pos, dir );                                    \
00712     mapper->ShiftVectorDown( pos, spos );                                       \
00713     dptr = data +  spos[0]*inc[0] + spos[1]*inc[1] + spos[2]*inc[2];            \
00714     }
00715 //ETX
00716 
00717 //BTX
00718 #define VTKKWRCHelper_MoveToNextSampleGONN()                            \
00719   if ( k < numSteps-1 )                                                 \
00720     {                                                                   \
00721     mapper->FixedPointIncrement( pos, dir );                            \
00722     mapper->ShiftVectorDown( pos, spos );                               \
00723     dptr = data +  spos[0]*inc[0] + spos[1]*inc[1] + spos[2]*inc[2];    \
00724     magPtr = gradientMag[spos[2]] + spos[0]*mInc[0] + spos[1]*mInc[1];  \
00725     }
00726 //ETX
00727 
00728 //BTX
00729 #define VTKKWRCHelper_MoveToNextSampleShadeNN()                         \
00730   if ( k < numSteps-1 )                                                 \
00731     {                                                                   \
00732     mapper->FixedPointIncrement( pos, dir );                            \
00733     mapper->ShiftVectorDown( pos, spos );                               \
00734     dptr = data +  spos[0]*inc[0] + spos[1]*inc[1] + spos[2]*inc[2];    \
00735     dirPtr = gradientDir[spos[2]] + spos[0]*dInc[0] + spos[1]*dInc[1];  \
00736     }
00737 //ETX
00738 
00739 //BTX
00740 #define VTKKWRCHelper_MoveToNextSampleGOShadeNN()                       \
00741   if ( k < numSteps-1 )                                                 \
00742     {                                                                   \
00743     mapper->FixedPointIncrement( pos, dir );                            \
00744     mapper->ShiftVectorDown( pos, spos );                               \
00745     dptr = data +  spos[0]*inc[0] + spos[1]*inc[1] + spos[2]*inc[2];    \
00746     magPtr = gradientMag[spos[2]] + spos[0]*mInc[0] + spos[1]*mInc[1];  \
00747     dirPtr = gradientDir[spos[2]] + spos[0]*dInc[0] + spos[1]*dInc[1];  \
00748     }
00749 //ETX
00750 
00751 //BTX
00752 #define VTKKWRCHelper_InitializeVariables()                                                     \
00753   int i, j;                                                                                     \
00754   unsigned short *imagePtr;                                                                     \
00755                                                                                                 \
00756   int imageInUseSize[2];                                                                        \
00757   int imageMemorySize[2];                                                                       \
00758   int imageViewportSize[2];                                                                     \
00759   int imageOrigin[2];                                                                           \
00760   int dim[3];                                                                                   \
00761   float shift[4];                                                                               \
00762   float scale[4];                                                                               \
00763                                                                                                 \
00764   mapper->GetRayCastImage()->GetImageInUseSize(imageInUseSize);                                 \
00765   mapper->GetRayCastImage()->GetImageMemorySize(imageMemorySize);                               \
00766   mapper->GetRayCastImage()->GetImageViewportSize(imageViewportSize);                           \
00767   mapper->GetRayCastImage()->GetImageOrigin(imageOrigin);                                       \
00768   mapper->GetInput()->GetDimensions(dim);                                                       \
00769   mapper->GetTableShift( shift );                                                               \
00770   mapper->GetTableScale( scale );                                                               \
00771                                                                                                 \
00772   int *rowBounds                     = mapper->GetRowBounds();                                  \
00773   unsigned short *image              = mapper->GetRayCastImage()->GetImage();                   \
00774   vtkRenderWindow *renWin            = mapper->GetRenderWindow();                               \
00775   int components                     = mapper->GetInput()->GetNumberOfScalarComponents();       \
00776   int cropping                       = (mapper->GetCropping() &&                                \
00777                                         mapper->GetCroppingRegionFlags() != 0x2000 );           \
00778                                                                                                 \
00779   unsigned short *colorTable[4];                                                                \
00780   unsigned short *scalarOpacityTable[4];                                                        \
00781                                                                                                 \
00782   int c;                                                                                        \
00783   for ( c = 0; c < 4; c++ )                                                                     \
00784     {                                                                                           \
00785     colorTable[c]         = mapper->GetColorTable(c);                                           \
00786     (void)(colorTable[c]);                                                                      \
00787     scalarOpacityTable[c] = mapper->GetScalarOpacityTable(c);                                   \
00788     }                                                                                           \
00789                                                                                                 \
00790   vtkIdType inc[3];                                                                             \
00791   inc[0] = components;                                                                          \
00792   inc[1] = inc[0]*dim[0];                                                                       \
00793   inc[2] = inc[1]*dim[1];
00794 //ETX
00795 
00796 //BTX
00797 #define VTKKWRCHelper_InitializeWeights()                       \
00798   float weights[4];                                             \
00799   weights[0] = vol->GetProperty()->GetComponentWeight(0);       \
00800   weights[1] = vol->GetProperty()->GetComponentWeight(1);       \
00801   weights[2] = vol->GetProperty()->GetComponentWeight(2);       \
00802   weights[3] = vol->GetProperty()->GetComponentWeight(3);
00803 //ETX
00804 
00805 //BTX
00806 #define VTKKWRCHelper_InitializeVariablesGO()                           \
00807   unsigned short *gradientOpacityTable[4];                              \
00808   for ( c = 0; c < 4; c++ )                                             \
00809     {                                                                   \
00810     gradientOpacityTable[c] = mapper->GetGradientOpacityTable(c);       \
00811     }                                                                   \
00812   unsigned char **gradientMag = mapper->GetGradientMagnitude();         \
00813                                                                         \
00814   vtkIdType mInc[3];                                                    \
00815   if ( vol->GetProperty()->GetIndependentComponents() )                 \
00816     {                                                                   \
00817     mInc[0] = inc[0];                                                   \
00818     mInc[1] = inc[1];                                                   \
00819     mInc[2] = inc[2];                                                   \
00820     }                                                                   \
00821   else                                                                  \
00822     {                                                                   \
00823     mInc[0] = 1;                                                        \
00824     mInc[1] = mInc[0]*dim[0];                                           \
00825     mInc[2] = mInc[1]*dim[1];                                           \
00826     }
00827 //ETX
00828 
00829 //BTX
00830 #define VTKKWRCHelper_InitializeVariablesShade()                        \
00831   unsigned short *diffuseShadingTable[4];                               \
00832   unsigned short *specularShadingTable[4];                              \
00833   for ( c = 0; c < 4; c++ )                                             \
00834     {                                                                   \
00835     diffuseShadingTable[c] = mapper->GetDiffuseShadingTable(c);         \
00836     specularShadingTable[c] = mapper->GetSpecularShadingTable(c);       \
00837     }                                                                   \
00838   unsigned short **gradientDir = mapper->GetGradientNormal();           \
00839   vtkIdType dInc[3];                                                    \
00840   if ( vol->GetProperty()->GetIndependentComponents() )                 \
00841     {                                                                   \
00842     dInc[0] = inc[0];                                                   \
00843     dInc[1] = inc[1];                                                   \
00844     dInc[2] = inc[2];                                                   \
00845     }                                                                   \
00846   else                                                                  \
00847     {                                                                   \
00848     dInc[0] = 1;                                                        \
00849     dInc[1] = dInc[0]*dim[0];                                           \
00850     dInc[2] = dInc[1]*dim[1];                                           \
00851     }
00852 //ETX
00853 
00854 //BTX
00855 #define VTKKWRCHelper_InitializeTrilinVariables() \
00856   vtkIdType Binc = components;                    \
00857   vtkIdType Cinc = Binc*dim[0];                   \
00858   vtkIdType Dinc = Cinc + Binc;                   \
00859   vtkIdType Einc = Cinc*dim[1];                   \
00860   vtkIdType Finc = Einc + Binc;                   \
00861   vtkIdType Ginc = Einc + Cinc;                   \
00862   vtkIdType Hinc = Ginc + Binc;
00863 //ETX
00864 
00865 //BTX
00866 #define VTKKWRCHelper_InitializeTrilinVariablesGO()             \
00867   vtkIdType magOffset;                                          \
00868   if (  vol->GetProperty()->GetIndependentComponents() )        \
00869     {                                                           \
00870     magOffset = components;                                     \
00871     }                                                           \
00872   else                                                          \
00873     {                                                           \
00874     magOffset = 1;                                              \
00875     }                                                           \
00876                                                                 \
00877   vtkIdType mBFinc =                    magOffset;              \
00878   vtkIdType mCGinc = dim[0]*magOffset;                          \
00879   vtkIdType mDHinc = dim[0]*magOffset + magOffset;
00880 //ETX
00881 
00882 //BTX
00883 #define VTKKWRCHelper_InitializeTrilinVariablesShade()          \
00884   vtkIdType dirOffset;                                          \
00885   if (  vol->GetProperty()->GetIndependentComponents() )        \
00886     {                                                           \
00887     dirOffset = components;                                     \
00888     }                                                           \
00889   else                                                          \
00890     {                                                           \
00891     dirOffset = 1;                                              \
00892     }                                                           \
00893                                                                 \
00894   vtkIdType dBFinc =                    dirOffset;              \
00895   vtkIdType dCGinc = dim[0]*dirOffset;                          \
00896   vtkIdType dDHinc = dim[0]*dirOffset + dirOffset;
00897 //ETX
00898 
00899 //BTX
00900 #define VTKKWRCHelper_OuterInitialization()                             \
00901     if ( j%threadCount != threadID )                                    \
00902       {                                                                 \
00903       continue;                                                         \
00904       }                                                                 \
00905      if ( !threadID )                                                   \
00906       {                                                                 \
00907       if ( renWin->CheckAbortStatus() )                                 \
00908         {                                                               \
00909         break;                                                          \
00910         }                                                               \
00911       }                                                                 \
00912     else if ( renWin->GetAbortRender() )                                \
00913       {                                                                 \
00914       break;                                                            \
00915       }                                                                 \
00916     imagePtr = image + 4*(j*imageMemorySize[0] + rowBounds[j*2]);
00917 
00918 //ETX
00919 
00920 //BTX
00921 #define VTKKWRCHelper_InnerInitialization()             \
00922   unsigned int   numSteps;                              \
00923   unsigned int   pos[3];                                \
00924   unsigned int   dir[3];                                \
00925   mapper->ComputeRayInfo( i, j, pos, dir, &numSteps );  \
00926   if ( numSteps == 0 )                                  \
00927     {                                                   \
00928     *(imagePtr  ) = 0;                                  \
00929     *(imagePtr+1) = 0;                                  \
00930     *(imagePtr+2) = 0;                                  \
00931     *(imagePtr+3) = 0;                                  \
00932     imagePtr += 4;                                      \
00933     continue;                                           \
00934     }                                                   \
00935   unsigned int   spos[3];                               \
00936   unsigned int   k;
00937 //ETX
00938 
00939 //BTX
00940 #define VTKKWRCHelper_InitializeMIPOneNN()                              \
00941   mapper->ShiftVectorDown( pos, spos );                                 \
00942   T *dptr = data +  spos[0]*inc[0] + spos[1]*inc[1] + spos[2]*inc[2];   \
00943   T maxValue = *(dptr);
00944 //ETX
00945 
00946 //BTX
00947 #define VTKKWRCHelper_InitializeMIPMultiNN()                            \
00948   mapper->ShiftVectorDown( pos, spos );                                 \
00949   T *dptr = data +  spos[0]*inc[0] + spos[1]*inc[1] + spos[2]*inc[2];   \
00950   T maxValue[4];                                                        \
00951   for ( c = 0; c < components; c++ )                                    \
00952     {                                                                   \
00953     maxValue[c] = *(dptr+c);                                            \
00954     }
00955 //ETX
00956 
00957 //BTX
00958 #define VTKKWRCHelper_InitializeMIPOneTrilin()          \
00959   T *dptr;                                              \
00960   unsigned int oldSPos[3];                              \
00961                                                         \
00962   oldSPos[0] = (pos[0] >> VTKKW_FP_SHIFT) + 1;          \
00963   oldSPos[1] = 0;                                       \
00964   oldSPos[2] = 0;                                       \
00965                                                         \
00966   unsigned int w1X, w1Y, w1Z;                              \
00967   unsigned int w2X, w2Y, w2Z;                              \
00968   unsigned int w1Xw1Y, w2Xw1Y, w1Xw2Y, w2Xw2Y;             \
00969                                                         \
00970   unsigned short  maxValue=0;                           \
00971   unsigned short  val;                                  \
00972   unsigned int A=0,B=0,C=0,D=0,E=0,F=0,G=0,H=0;
00973 //ETX
00974 
00975 //BTX
00976 #define VTKKWRCHelper_InitializeMIPMultiTrilin()                \
00977   T *dptr;                                                      \
00978   unsigned int oldSPos[3];                                      \
00979                                                                 \
00980   oldSPos[0] = (pos[0] >> VTKKW_FP_SHIFT) + 1;                  \
00981   oldSPos[1] = 0;                                               \
00982   oldSPos[2] = 0;                                               \
00983                                                                 \
00984   unsigned int w1X, w1Y, w1Z;                                      \
00985   unsigned int w2X, w2Y, w2Z;                                      \
00986   unsigned int w1Xw1Y, w2Xw1Y, w1Xw2Y, w2Xw2Y;                     \
00987                                                                 \
00988   unsigned short  maxValue[4];                                  \
00989   unsigned short  val[4];                                       \
00990   unsigned int    A[4],B[4],C[4],D[4],E[4],F[4],G[4],H[4];
00991 //ETX
00992 
00993 //BTX
00994 #define VTKKWRCHelper_InitializeCompositeGONN()                                      \
00995   unsigned char *magPtr = gradientMag[spos[2]] + spos[0]*mInc[0] + spos[1]*mInc[1];
00996 //ETX
00997 
00998 //BTX
00999 #define VTKKWRCHelper_InitializeCompositeShadeNN()                                      \
01000   unsigned short *dirPtr = gradientDir[spos[2]] + spos[0]*dInc[0] + spos[1]*dInc[1];
01001 //ETX
01002 
01003 //BTX
01004 #define VTKKWRCHelper_InitializeCompositeOneNN()                        \
01005   mapper->ShiftVectorDown( pos, spos );                                 \
01006   T *dptr = data +  spos[0]*inc[0] + spos[1]*inc[1] + spos[2]*inc[2];   \
01007   unsigned int color[3] = {0,0,0};                                      \
01008   unsigned short remainingOpacity = 0x7fff;                             \
01009   unsigned short tmp[4];
01010 //ETX
01011 
01012 //BTX
01013 #define VTKKWRCHelper_InitializeCompositeMultiNN()                      \
01014   mapper->ShiftVectorDown( pos, spos );                                 \
01015   T *dptr = data +  spos[0]*inc[0] + spos[1]*inc[1] + spos[2]*inc[2];   \
01016   unsigned int color[3] = {0,0,0};                                      \
01017   unsigned int remainingOpacity = 0x7fff;                               \
01018   unsigned short tmp[4];                                                \
01019   unsigned short val[4];
01020 //ETX
01021 
01022 //BTX
01023 #define VTKKWRCHelper_InitializeCompositeOneTrilin()    \
01024   T *dptr;                                              \
01025   unsigned int oldSPos[3];                              \
01026                                                         \
01027   oldSPos[0] = (pos[0] >> VTKKW_FP_SHIFT) + 1;          \
01028   oldSPos[1] = 0;                                       \
01029   oldSPos[2] = 0;                                       \
01030                                                         \
01031   unsigned int w1X, w1Y, w1Z;                           \
01032   unsigned int w2X, w2Y, w2Z;                           \
01033   unsigned int w1Xw1Y, w2Xw1Y, w1Xw2Y, w2Xw2Y;          \
01034                                                         \
01035   unsigned short  val;                                  \
01036   unsigned int    A=0,B=0,C=0,D=0,E=0,F=0,G=0,H=0;      \
01037                                                         \
01038   unsigned int color[3] = {0,0,0};                      \
01039   unsigned short remainingOpacity = 0x7fff;             \
01040   unsigned short tmp[4];
01041 //ETX
01042 
01043 //BTX
01044 #define VTKKWRCHelper_InitializeCompositeOneGOTrilin()          \
01045   unsigned char  *magPtrABCD = 0, *magPtrEFGH = 0;              \
01046   unsigned short  mag;                                          \
01047   unsigned int    mA=0,mB=0,mC=0,mD=0,mE=0,mF=0,mG=0,mH=0;
01048 //ETX
01049 
01050 //BTX
01051 #define VTKKWRCHelper_InitializeCompositeOneShadeTrilin()       \
01052   unsigned short *dirPtrABCD = 0, *dirPtrEFGH = 0;              \
01053   unsigned int    normalA=0,normalB=0,normalC=0,normalD=0;      \
01054   unsigned int    normalE=0,normalF=0,normalG=0,normalH=0;
01055 //ETX
01056 
01057 //BTX
01058 #define VTKKWRCHelper_InitializeCompositeMultiTrilin()          \
01059   T *dptr;                                                      \
01060   unsigned int oldSPos[3];                                      \
01061                                                                 \
01062   oldSPos[0] = (pos[0] >> VTKKW_FP_SHIFT) + 1;                  \
01063   oldSPos[1] = 0;                                               \
01064   oldSPos[2] = 0;                                               \
01065                                                                 \
01066   unsigned int w1X, w1Y, w1Z;                                   \
01067   unsigned int w2X, w2Y, w2Z;                                   \
01068   unsigned int w1Xw1Y, w2Xw1Y, w1Xw2Y, w2Xw2Y;                  \
01069                                                                 \
01070   unsigned short  val[4];                                       \
01071   unsigned int    A[4] = {0,0,0,0};                             \
01072   unsigned int    B[4] = {0,0,0,0};                             \
01073   unsigned int    C[4] = {0,0,0,0};                             \
01074   unsigned int    D[4] = {0,0,0,0};                             \
01075   unsigned int    E[4] = {0,0,0,0};                             \
01076   unsigned int    F[4] = {0,0,0,0};                             \
01077   unsigned int    G[4] = {0,0,0,0};                             \
01078   unsigned int    H[4] = {0,0,0,0};                             \
01079                                                                 \
01080   unsigned int color[3] = {0,0,0};                              \
01081   unsigned short remainingOpacity = 0x7fff;                     \
01082   unsigned short tmp[4];
01083 //ETX
01084 
01085 //BTX
01086 #define VTKKWRCHelper_InitializeCompositeMultiGOTrilin()                \
01087   unsigned char  *magPtrABCD = 0, *magPtrEFGH = 0;                      \
01088   unsigned short  mag[4];                                               \
01089   unsigned int    mA[4],mB[4],mC[4],mD[4],mE[4],mF[4],mG[4],mH[4];
01090 //ETX
01091 
01092 //BTX
01093 #define VTKKWRCHelper_InitializeCompositeMultiShadeTrilin()     \
01094   unsigned short *dirPtrABCD = 0, *dirPtrEFGH = 0;              \
01095   unsigned int    normalA[4],normalB[4],normalC[4],normalD[4];  \
01096   unsigned int    normalE[4],normalF[4],normalG[4],normalH[4];
01097 //ETX
01098 
01099 //BTX
01100 #define VTKKWRCHelper_InitializationAndLoopStartNN()            \
01101   VTKKWRCHelper_InitializeVariables();                          \
01102   for ( j = 0; j < imageInUseSize[1]; j++ )                     \
01103     {                                                           \
01104     VTKKWRCHelper_OuterInitialization();                        \
01105     for ( i = rowBounds[j*2]; i <= rowBounds[j*2+1]; i++ )      \
01106       {                                                         \
01107       VTKKWRCHelper_InnerInitialization();
01108 //ETX
01109 
01110 //BTX
01111 #define VTKKWRCHelper_InitializationAndLoopStartGONN()          \
01112   VTKKWRCHelper_InitializeVariables();                          \
01113   VTKKWRCHelper_InitializeVariablesGO();                        \
01114   for ( j = 0; j < imageInUseSize[1]; j++ )                     \
01115     {                                                           \
01116     VTKKWRCHelper_OuterInitialization();                        \
01117     for ( i = rowBounds[j*2]; i <= rowBounds[j*2+1]; i++ )      \
01118       {                                                         \
01119       VTKKWRCHelper_InnerInitialization();
01120 //ETX
01121 
01122 //BTX
01123 #define VTKKWRCHelper_InitializationAndLoopStartShadeNN()       \
01124   VTKKWRCHelper_InitializeVariables();                          \
01125   VTKKWRCHelper_InitializeVariablesShade();                     \
01126   for ( j = 0; j < imageInUseSize[1]; j++ )                     \
01127     {                                                           \
01128     VTKKWRCHelper_OuterInitialization();                        \
01129     for ( i = rowBounds[j*2]; i <= rowBounds[j*2+1]; i++ )      \
01130       {                                                         \
01131       VTKKWRCHelper_InnerInitialization();
01132 //ETX
01133 
01134 //BTX
01135 #define VTKKWRCHelper_InitializationAndLoopStartGOShadeNN()     \
01136   VTKKWRCHelper_InitializeVariables();                          \
01137   VTKKWRCHelper_InitializeVariablesGO();                        \
01138   VTKKWRCHelper_InitializeVariablesShade();                     \
01139   for ( j = 0; j < imageInUseSize[1]; j++ )                     \
01140     {                                                           \
01141     VTKKWRCHelper_OuterInitialization();                        \
01142     for ( i = rowBounds[j*2]; i <= rowBounds[j*2+1]; i++ )      \
01143       {                                                         \
01144       VTKKWRCHelper_InnerInitialization();
01145 //ETX
01146 
01147 //BTX
01148 #define VTKKWRCHelper_InitializationAndLoopStartTrilin()        \
01149   VTKKWRCHelper_InitializeVariables();                          \
01150   VTKKWRCHelper_InitializeTrilinVariables();                    \
01151   for ( j = 0; j < imageInUseSize[1]; j++ )                     \
01152     {                                                           \
01153     VTKKWRCHelper_OuterInitialization();                        \
01154     for ( i = rowBounds[j*2]; i <= rowBounds[j*2+1]; i++ )      \
01155       {                                                         \
01156       VTKKWRCHelper_InnerInitialization();
01157 //ETX
01158 
01159 //BTX
01160 #define VTKKWRCHelper_InitializationAndLoopStartGOTrilin()      \
01161   VTKKWRCHelper_InitializeVariables();                          \
01162   VTKKWRCHelper_InitializeVariablesGO();                        \
01163   VTKKWRCHelper_InitializeTrilinVariables();                    \
01164   VTKKWRCHelper_InitializeTrilinVariablesGO();                  \
01165   for ( j = 0; j < imageInUseSize[1]; j++ )                     \
01166     {                                                           \
01167     VTKKWRCHelper_OuterInitialization();                        \
01168     for ( i = rowBounds[j*2]; i <= rowBounds[j*2+1]; i++ )      \
01169       {                                                         \
01170       VTKKWRCHelper_InnerInitialization();
01171 //ETX
01172 
01173 //BTX
01174 #define VTKKWRCHelper_InitializationAndLoopStartShadeTrilin()   \
01175   VTKKWRCHelper_InitializeVariables();                          \
01176   VTKKWRCHelper_InitializeVariablesShade();                     \
01177   VTKKWRCHelper_InitializeTrilinVariables();                    \
01178   VTKKWRCHelper_InitializeTrilinVariablesShade();               \
01179   for ( j = 0; j < imageInUseSize[1]; j++ )                     \
01180     {                                                           \
01181     VTKKWRCHelper_OuterInitialization();                        \
01182     for ( i = rowBounds[j*2]; i <= rowBounds[j*2+1]; i++ )      \
01183       {                                                         \
01184       VTKKWRCHelper_InnerInitialization();
01185 //ETX
01186 
01187 //BTX
01188 #define VTKKWRCHelper_InitializationAndLoopStartGOShadeTrilin() \
01189   VTKKWRCHelper_InitializeVariables();                          \
01190   VTKKWRCHelper_InitializeVariablesShade();                     \
01191   VTKKWRCHelper_InitializeVariablesGO();                        \
01192   VTKKWRCHelper_InitializeTrilinVariables();                    \
01193   VTKKWRCHelper_InitializeTrilinVariablesShade();               \
01194   VTKKWRCHelper_InitializeTrilinVariablesGO();                  \
01195   for ( j = 0; j < imageInUseSize[1]; j++ )                     \
01196     {                                                           \
01197     VTKKWRCHelper_OuterInitialization();                        \
01198     for ( i = rowBounds[j*2]; i <= rowBounds[j*2+1]; i++ )      \
01199       {                                                         \
01200       VTKKWRCHelper_InnerInitialization();
01201 //ETX
01202 
01203 //BTX
01204 #define VTKKWRCHelper_IncrementAndLoopEnd()                                             \
01205       imagePtr+=4;                                                                      \
01206       }                                                                                 \
01207     if ( (j/threadCount)%8 == 7 && threadID == 0)                                       \
01208       {                                                                                 \
01209       double fargs[1];                                                                  \
01210       fargs[0] = static_cast<double>(j)/static_cast<float>(imageInUseSize[1]-1);        \
01211       mapper->InvokeEvent( vtkCommand::VolumeMapperRenderProgressEvent, fargs );        \
01212       }                                                                                 \
01213     }
01214 //ETX
01215 
01216 //BTX
01217 #define VTKKWRCHelper_CroppingCheckTrilin( POS )        \
01218   if ( cropping )                                       \
01219     {                                                   \
01220     if ( mapper->CheckIfCropped( POS ) )                \
01221       {                                                 \
01222       continue;                                         \
01223       }                                                 \
01224     }
01225 //ETX
01226 
01227 //BTX
01228 #define VTKKWRCHelper_CroppingCheckNN( POS )            \
01229   if ( cropping )                                       \
01230     {                                                   \
01231     if ( mapper->CheckIfCropped( POS ) )                \
01232       {                                                 \
01233       continue;                                         \
01234       }                                                 \
01235     }
01236 //ETX
01237 
01238 //BTX
01239 #define VTKKWRCHelper_SpaceLeapSetup()          \
01240   unsigned int mmpos[3];                        \
01241   mmpos[0] = (pos[0] >> VTKKW_FPMM_SHIFT) + 1;  \
01242   mmpos[1] = 0;                                 \
01243   mmpos[2] = 0;                                 \
01244   int mmvalid = 0;
01245 //ETX
01246 
01247 //BTX
01248 #define VTKKWRCHelper_SpaceLeapSetupMulti()     \
01249   unsigned int mmpos[3];                        \
01250   mmpos[0] = (pos[0] >> VTKKW_FPMM_SHIFT) + 1;  \
01251   mmpos[1] = 0;                                 \
01252   mmpos[2] = 0;                                 \
01253   int mmvalid[4] = {0,0,0,0};
01254 //ETX
01255 
01256 
01257 //BTX
01258 #define VTKKWRCHelper_SpaceLeapCheck()                          \
01259   if ( pos[0] >> VTKKW_FPMM_SHIFT != mmpos[0] ||                \
01260        pos[1] >> VTKKW_FPMM_SHIFT != mmpos[1] ||                \
01261        pos[2] >> VTKKW_FPMM_SHIFT != mmpos[2] )                 \
01262     {                                                           \
01263     mmpos[0] = pos[0] >> VTKKW_FPMM_SHIFT;                      \
01264     mmpos[1] = pos[1] >> VTKKW_FPMM_SHIFT;                      \
01265     mmpos[2] = pos[2] >> VTKKW_FPMM_SHIFT;                      \
01266     mmvalid = mapper->CheckMinMaxVolumeFlag( mmpos, 0 );        \
01267     }                                                           \
01268                                                                 \
01269   if ( !mmvalid )                                               \
01270     {                                                           \
01271     continue;                                                   \
01272     }
01273 //ETX
01274 
01275 //BTX
01276 #define VTKKWRCHelper_MIPSpaceLeapCheck( MAXIDX, MAXIDXDEF, FLIP )      \
01277   if ( pos[0] >> VTKKW_FPMM_SHIFT != mmpos[0] ||                        \
01278        pos[1] >> VTKKW_FPMM_SHIFT != mmpos[1] ||                        \
01279        pos[2] >> VTKKW_FPMM_SHIFT != mmpos[2] )                         \
01280     {                                                                   \
01281     mmpos[0] = pos[0] >> VTKKW_FPMM_SHIFT;                              \
01282     mmpos[1] = pos[1] >> VTKKW_FPMM_SHIFT;                              \
01283     mmpos[2] = pos[2] >> VTKKW_FPMM_SHIFT;                              \
01284     mmvalid = (MAXIDXDEF)?                                              \
01285      (mapper->CheckMIPMinMaxVolumeFlag( mmpos, 0, MAXIDX, FLIP )):(1);  \
01286     }                                                                   \
01287                                                                         \
01288   if ( !mmvalid )                                                       \
01289     {                                                                   \
01290     continue;                                                           \
01291     }
01292 //ETX
01293 
01294 
01295 //BTX
01296 #define VTKKWRCHelper_MIPSpaceLeapPopulateMulti( MAXIDX, FLIP )                   \
01297   if ( pos[0] >> VTKKW_FPMM_SHIFT != mmpos[0] ||                                  \
01298        pos[1] >> VTKKW_FPMM_SHIFT != mmpos[1] ||                                  \
01299        pos[2] >> VTKKW_FPMM_SHIFT != mmpos[2] )                                   \
01300     {                                                                             \
01301     mmpos[0] = pos[0] >> VTKKW_FPMM_SHIFT;                                        \
01302     mmpos[1] = pos[1] >> VTKKW_FPMM_SHIFT;                                        \
01303     mmpos[2] = pos[2] >> VTKKW_FPMM_SHIFT;                                        \
01304     for ( c = 0; c < components; c++ )                                            \
01305       {                                                                           \
01306       mmvalid[c] = mapper->CheckMIPMinMaxVolumeFlag( mmpos, c, MAXIDX[c], FLIP ); \
01307       }                                                                           \
01308     }
01309 //ETX
01310 
01311 //BTX
01312 #define VTKKWRCHelper_MIPSpaceLeapCheckMulti( COMP, FLIP )  mmvalid[COMP]
01313 //ETX
01314 
01315 #include "vtkRenderingVolumeModule.h" // For export macro
01316 #include "vtkObject.h"
01317 
01318 class vtkFixedPointVolumeRayCastMapper;
01319 class vtkVolume;
01320 
01321 class VTKRENDERINGVOLUME_EXPORT vtkFixedPointVolumeRayCastHelper : public vtkObject
01322 {
01323 public:
01324   static vtkFixedPointVolumeRayCastHelper *New();
01325   vtkTypeMacro(vtkFixedPointVolumeRayCastHelper,vtkObject);
01326   void PrintSelf( ostream& os, vtkIndent indent );
01327 
01328   virtual void   GenerateImage( int,
01329                                 int,
01330                                 vtkVolume *,
01331                                 vtkFixedPointVolumeRayCastMapper *) {}
01332 
01333 protected:
01334   vtkFixedPointVolumeRayCastHelper();
01335   ~vtkFixedPointVolumeRayCastHelper();
01336 
01337 
01338 private:
01339   vtkFixedPointVolumeRayCastHelper(const vtkFixedPointVolumeRayCastHelper&);  // Not implemented.
01340   void operator=(const vtkFixedPointVolumeRayCastHelper&);  // Not implemented.
01341 };
01342 
01343 #endif
01344 
01345 
01346