Main Page | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Class Members | File Members | Related Pages

vtkFixedPointVolumeRayCastMapper.h

Go to the documentation of this file.
00001 /*=========================================================================
00002 
00003   Program:   Visualization Toolkit
00004   Module:    $RCSfile: vtkFixedPointVolumeRayCastMapper.h,v $
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 =========================================================================*/
00061 #ifndef __vtkFixedPointVolumeRayCastMapper_h
00062 #define __vtkFixedPointVolumeRayCastMapper_h
00063 
00064 #include "vtkVolumeMapper.h"
00065 
00066 #define VTKKW_FP_SHIFT       15
00067 #define VTKKW_FPMM_SHIFT     17
00068 #define VTKKW_FP_MASK        0x7fff
00069 #define VTKKW_FP_SCALE       32767.0
00070 
00071 class vtkMatrix4x4;
00072 class vtkMultiThreader;
00073 class vtkPlaneCollection;
00074 class vtkRenderer;
00075 class vtkTimerLog;
00076 class vtkVolume;
00077 class vtkTransform;
00078 class vtkRenderWindow;
00079 class vtkColorTransferFunction;
00080 class vtkPiecewiseFunction;
00081 class vtkFixedPointVolumeRayCastMIPHelper;
00082 class vtkFixedPointVolumeRayCastCompositeHelper;
00083 class vtkFixedPointVolumeRayCastCompositeGOHelper;
00084 class vtkFixedPointVolumeRayCastCompositeGOShadeHelper;
00085 class vtkFixedPointVolumeRayCastCompositeShadeHelper;
00086 class vtkDirectionEncoder;
00087 class vtkEncodedGradientShader;
00088 class vtkFiniteDifferenceGradientEstimator;
00089 class vtkRayCastImageDisplayHelper;
00090 class vtkFixedPointRayCastImage;
00091 
00092 // Forward declaration needed for use by friend declaration below.
00093 VTK_THREAD_RETURN_TYPE FixedPointVolumeRayCastMapper_CastRays( void *arg );
00094 
00095 class VTK_VOLUMERENDERING_EXPORT vtkFixedPointVolumeRayCastMapper : public vtkVolumeMapper
00096 {
00097 public:
00098   static vtkFixedPointVolumeRayCastMapper *New();
00099   vtkTypeRevisionMacro(vtkFixedPointVolumeRayCastMapper,vtkVolumeMapper);
00100   void PrintSelf( ostream& os, vtkIndent indent );
00101 
00103 
00106   vtkSetMacro( SampleDistance, float );
00107   vtkGetMacro( SampleDistance, float );
00109 
00111 
00117   vtkSetMacro( InteractiveSampleDistance, float );
00118   vtkGetMacro( InteractiveSampleDistance, float );
00120   
00122 
00127   vtkSetClampMacro( ImageSampleDistance, float, 0.1f, 100.0f );
00128   vtkGetMacro( ImageSampleDistance, float );
00130 
00132 
00134   vtkSetClampMacro( MinimumImageSampleDistance, float, 0.1f, 100.0f );
00135   vtkGetMacro( MinimumImageSampleDistance, float );
00137 
00139 
00141   vtkSetClampMacro( MaximumImageSampleDistance, float, 0.1f, 100.0f );
00142   vtkGetMacro( MaximumImageSampleDistance, float );
00144 
00146 
00153   vtkSetClampMacro( AutoAdjustSampleDistances, int, 0, 1 );
00154   vtkGetMacro( AutoAdjustSampleDistances, int );
00155   vtkBooleanMacro( AutoAdjustSampleDistances, int );
00157   
00159 
00161   void SetNumberOfThreads( int num );
00162   int GetNumberOfThreads();
00164 
00166 
00168   vtkSetClampMacro( IntermixIntersectingGeometry, int, 0, 1 );
00169   vtkGetMacro( IntermixIntersectingGeometry, int );
00170   vtkBooleanMacro( IntermixIntersectingGeometry, int );
00172 
00174 
00180   float ComputeRequiredImageSampleDistance( float desiredTime,
00181                                             vtkRenderer *ren );
00182   float ComputeRequiredImageSampleDistance( float desiredTime,
00183                                             vtkRenderer *ren,
00184                                             vtkVolume *vol );
00186   
00187 //BTX
00190   void Render( vtkRenderer *, vtkVolume * );
00191 
00192   unsigned int ToFixedPointPosition( float val );
00193   void ToFixedPointPosition( float in[3], unsigned int out[3] );
00194   unsigned int ToFixedPointDirection( float dir );
00195   void ToFixedPointDirection( float in[3], unsigned int out[3] );
00196   void FixedPointIncrement( unsigned int position[3], unsigned int increment[3] );
00197   void GetFloatTripleFromPointer( float v[3], float *ptr );
00198   void GetUIntTripleFromPointer( unsigned int v[3], unsigned int *ptr );
00199   void ShiftVectorDown( unsigned int in[3], unsigned int out[3] );
00200   int CheckMinMaxVolumeFlag( unsigned int pos[3], int c );
00201   int CheckMIPMinMaxVolumeFlag( unsigned int pos[3], int c, unsigned short maxIdx );
00202   
00203   void LookupColorUC( unsigned short *colorTable,
00204                       unsigned short *scalarOpacityTable,
00205                       unsigned short index,
00206                       unsigned char  color[4] );
00207   void LookupDependentColorUC( unsigned short *colorTable,
00208                                unsigned short *scalarOpacityTable,
00209                                unsigned short index[4],
00210                                int            components,
00211                                unsigned char  color[4] );  
00212   void LookupAndCombineIndependentColorsUC( 
00213     unsigned short *colorTable[4],
00214     unsigned short *scalarOpacityTable[4],
00215     unsigned short index[4],
00216     float          weights[4],
00217     int            components,
00218     unsigned char  color[4] );  
00219   int CheckIfCropped( unsigned int pos[3] );
00220   
00221 //ETX
00222 
00223   vtkGetObjectMacro( RenderWindow, vtkRenderWindow );
00224   vtkGetObjectMacro( MIPHelper, vtkFixedPointVolumeRayCastMIPHelper );
00225   vtkGetObjectMacro( CompositeHelper, vtkFixedPointVolumeRayCastCompositeHelper );
00226   vtkGetObjectMacro( CompositeGOHelper, vtkFixedPointVolumeRayCastCompositeGOHelper );
00227   vtkGetObjectMacro( CompositeGOShadeHelper, vtkFixedPointVolumeRayCastCompositeGOShadeHelper );
00228   vtkGetObjectMacro( CompositeShadeHelper, vtkFixedPointVolumeRayCastCompositeShadeHelper );
00229   vtkGetVectorMacro( TableShift, float, 4 );
00230   vtkGetVectorMacro( TableScale, float, 4 );
00231   vtkGetMacro( ShadingRequired, int );
00232   vtkGetMacro( GradientOpacityRequired, int );
00233   
00234   int             *GetRowBounds()                 {return this->RowBounds;}
00235   unsigned short  *GetColorTable(int c)           {return this->ColorTable[c];}
00236   unsigned short  *GetScalarOpacityTable(int c)   {return this->ScalarOpacityTable[c];}
00237   unsigned short  *GetGradientOpacityTable(int c) {return this->GradientOpacityTable[c];}
00238   vtkVolume       *GetVolume()                    {return this->Volume;}
00239   unsigned short **GetGradientNormal()            {return this->GradientNormal;}
00240   unsigned char  **GetGradientMagnitude()         {return this->GradientMagnitude;}
00241   unsigned short  *GetDiffuseShadingTable(int c)  {return this->DiffuseShadingTable[c];}
00242   unsigned short  *GetSpecularShadingTable(int c) {return this->SpecularShadingTable[c];}
00243   
00244   void ComputeRayInfo( int x, int y,
00245                        unsigned int pos[3],
00246                        unsigned int dir[3],
00247                        unsigned int *numSteps );
00248 
00249   void InitializeRayInfo( vtkVolume *vol );
00250   
00251   int ShouldUseNearestNeighborInterpolation( vtkVolume *vol );
00252   
00254 
00257   void SetRayCastImage( vtkFixedPointRayCastImage * );
00258   vtkGetObjectMacro( RayCastImage, vtkFixedPointRayCastImage  );
00260 
00261   int PerImageInitialization( vtkRenderer *, vtkVolume *, int,
00262                               double *, double *, int * );
00263   void PerVolumeInitialization( vtkRenderer *, vtkVolume * );
00264   void PerSubVolumeInitialization( vtkRenderer *, vtkVolume *, int );
00265   void RenderSubVolume();
00266   void DisplayRenderedImage( vtkRenderer *, vtkVolume * );
00267   void AbortRender();
00268   
00269   
00270 protected:
00271   vtkFixedPointVolumeRayCastMapper();
00272   ~vtkFixedPointVolumeRayCastMapper();
00273 
00274   // The helper class that displays the image
00275   vtkRayCastImageDisplayHelper *ImageDisplayHelper;
00276 
00277   // The distance between sample points along the ray
00278   float                        SampleDistance;
00279   float                        InteractiveSampleDistance;
00280   
00281   // The distance between rays in the image
00282   float                        ImageSampleDistance;
00283   float                        MinimumImageSampleDistance;
00284   float                        MaximumImageSampleDistance;
00285   int                          AutoAdjustSampleDistances;
00286 
00287   // Saved values used to restore 
00288   float                        OldSampleDistance;
00289   float                        OldImageSampleDistance;
00290   
00291   // Internal method for computing matrices needed during
00292   // ray casting
00293   void ComputeMatrices( double volumeOrigin[3],
00294                         double volumeSpacing[3],
00295                         int volumeExtent[6], 
00296                         vtkRenderer  *ren,
00297                         vtkVolume    *vol );
00298   
00299   int ComputeRowBounds( vtkRenderer *ren,
00300                         int imageFlag, int rowBoundsFlag,
00301                         int volumeExtent[6]);
00302 
00303   void CaptureZBuffer( vtkRenderer *ren );
00304   
00305   friend VTK_THREAD_RETURN_TYPE FixedPointVolumeRayCastMapper_CastRays( void *arg );
00306   
00307   vtkMultiThreader  *Threader;
00308 
00309   vtkMatrix4x4   *PerspectiveMatrix;
00310   vtkMatrix4x4   *ViewToWorldMatrix;
00311   vtkMatrix4x4   *ViewToVoxelsMatrix;
00312   vtkMatrix4x4   *VoxelsToViewMatrix;
00313   vtkMatrix4x4   *WorldToVoxelsMatrix;
00314   vtkMatrix4x4   *VoxelsToWorldMatrix;
00315 
00316   vtkMatrix4x4   *VolumeMatrix;
00317   
00318   vtkTransform   *PerspectiveTransform;
00319   vtkTransform   *VoxelsTransform;
00320   vtkTransform   *VoxelsToViewTransform;
00321 
00322   // This object encapsulated the image and all related information
00323   vtkFixedPointRayCastImage *RayCastImage;
00324   
00325   int             *RowBounds;
00326   int             *OldRowBounds;
00327 
00328   float           *RenderTimeTable;
00329   vtkVolume      **RenderVolumeTable;
00330   vtkRenderer    **RenderRendererTable;
00331   int              RenderTableSize;
00332   int              RenderTableEntries;
00333 
00334   void             StoreRenderTime( vtkRenderer *ren, vtkVolume *vol, float t );
00335   float            RetrieveRenderTime( vtkRenderer *ren, vtkVolume *vol );
00336   float            RetrieveRenderTime( vtkRenderer *ren );
00337 
00338   int              IntermixIntersectingGeometry;
00339 
00340   float            MinimumViewDistance;
00341 
00342   vtkColorTransferFunction *SavedRGBFunction[4];
00343   vtkPiecewiseFunction     *SavedGrayFunction[4];
00344   vtkPiecewiseFunction     *SavedScalarOpacityFunction[4];
00345   vtkPiecewiseFunction     *SavedGradientOpacityFunction[4];
00346   int                       SavedColorChannels[4];
00347   float                     SavedScalarOpacityDistance[4];
00348   int                       SavedBlendMode;
00349   vtkImageData             *SavedParametersInput;
00350   vtkTimeStamp              SavedParametersMTime;
00351   
00352   vtkImageData             *SavedGradientsInput;
00353   vtkTimeStamp              SavedGradientsMTime;
00354  
00355   float                     SavedSampleDistance;
00356   
00357   
00358   unsigned short            ColorTable[4][32768*3];
00359   unsigned short            ScalarOpacityTable[4][32768];
00360   unsigned short            GradientOpacityTable[4][256];
00361   int                       TableSize[4];
00362   float                     TableScale[4];
00363   float                     TableShift[4]; 
00364 
00365   float                     GradientMagnitudeScale[4];
00366   float                     GradientMagnitudeShift[4];
00367   
00368   unsigned short           **GradientNormal;
00369   unsigned char            **GradientMagnitude;
00370   unsigned short            *ContiguousGradientNormal;
00371   unsigned char             *ContiguousGradientMagnitude;
00372   
00373   int                        NumberOfGradientSlices;
00374   
00375   vtkDirectionEncoder       *DirectionEncoder;
00376 
00377   vtkEncodedGradientShader  *GradientShader;
00378   
00379   vtkFiniteDifferenceGradientEstimator *GradientEstimator;
00380   
00381   unsigned short             DiffuseShadingTable [4][65536*3];
00382   unsigned short             SpecularShadingTable[4][65536*3];
00383   
00384   int                        ShadingRequired;
00385   int                        GradientOpacityRequired;
00386   
00387   vtkRenderWindow           *RenderWindow;
00388   vtkVolume                 *Volume; 
00389   
00390   int           ClipRayAgainstVolume( float rayStart[3],
00391                                       float rayEnd[3],
00392                                       float rayDirection[3],
00393                                       double bounds[6] );
00394   
00395   int           UpdateColorTable( vtkVolume *vol );
00396   int           UpdateGradients( vtkVolume *vol );
00397   int           UpdateShadingTable( vtkRenderer *ren,
00398                                     vtkVolume *vol );
00399   void          UpdateCroppingRegions();
00400   
00401   void          ComputeGradients( vtkVolume *vol );
00402   
00403   int           ClipRayAgainstClippingPlanes( float  rayStart[3],
00404                                               float  rayEnd[3],
00405                                               int    numClippingPlanes,
00406                                               float *clippingPlanes );
00407   
00408   unsigned int  FixedPointCroppingRegionPlanes[6];
00409   unsigned int  CroppingRegionMask[27];
00410   
00411   // Get the ZBuffer value corresponding to location (x,y) where (x,y)
00412   // are indexing into the ImageInUse image. This must be converted to
00413   // the zbuffer image coordinates. Nearest neighbor value is returned.
00414   float         GetZBufferValue( int x, int y );
00415 
00416   vtkFixedPointVolumeRayCastMIPHelper              *MIPHelper;
00417   vtkFixedPointVolumeRayCastCompositeHelper        *CompositeHelper;
00418   vtkFixedPointVolumeRayCastCompositeGOHelper      *CompositeGOHelper;
00419   vtkFixedPointVolumeRayCastCompositeShadeHelper   *CompositeShadeHelper;
00420   vtkFixedPointVolumeRayCastCompositeGOShadeHelper *CompositeGOShadeHelper;
00421   
00422   // Some variables used for ray computation
00423   float ViewToVoxelsArray[16];
00424   float WorldToVoxelsArray[16];
00425   float VoxelsToWorldArray[16];
00426   
00427   double CroppingBounds[6];
00428   
00429   int NumTransformedClippingPlanes;
00430   float *TransformedClippingPlanes;
00431   
00432   double SavedSpacing[3];
00433   
00434   
00435   // Min Max structured used to do space leaping
00436   unsigned short *MinMaxVolume;
00437   int             MinMaxVolumeSize[4];
00438   vtkImageData   *SavedMinMaxInput;
00439   vtkTimeStamp    SavedMinMaxBuildTime;
00440   vtkTimeStamp    SavedMinMaxGradientTime;
00441   vtkTimeStamp    SavedMinMaxFlagTime;
00442 
00443   void            UpdateMinMaxVolume( vtkVolume *vol );
00444   void            FillInMaxGradientMagnitudes( int fullDim[3],
00445                                                int smallDim[3] );
00446   
00447 private:
00448   vtkFixedPointVolumeRayCastMapper(const vtkFixedPointVolumeRayCastMapper&);  // Not implemented.
00449   void operator=(const vtkFixedPointVolumeRayCastMapper&);  // Not implemented.
00450 };
00451 
00452 
00453 inline unsigned int vtkFixedPointVolumeRayCastMapper::ToFixedPointPosition( float val )
00454 {
00455   return static_cast<unsigned int>(val * VTKKW_FP_SCALE + 0.5);
00456 }
00457 
00458 inline void vtkFixedPointVolumeRayCastMapper::ToFixedPointPosition( float in[3], unsigned int out[3] )
00459 {
00460   out[0] = static_cast<unsigned int>(in[0] * VTKKW_FP_SCALE + 0.5);
00461   out[1] = static_cast<unsigned int>(in[1] * VTKKW_FP_SCALE + 0.5);
00462   out[2] = static_cast<unsigned int>(in[2] * VTKKW_FP_SCALE + 0.5);
00463 }
00464 
00465 inline unsigned int vtkFixedPointVolumeRayCastMapper::ToFixedPointDirection( float dir )
00466 {
00467   return ((dir<0.0)?
00468           (static_cast<unsigned int>(-dir * VTKKW_FP_SCALE + 0.5)):
00469           (0x80000000+static_cast<unsigned int>(dir*VTKKW_FP_SCALE + 0.5)));
00470 }
00471 
00472 inline void vtkFixedPointVolumeRayCastMapper::ToFixedPointDirection( float in[3], unsigned int out[3] )
00473 {
00474   out[0] = ((in[0]<0.0)?
00475             (static_cast<unsigned int>(-in[0] * VTKKW_FP_SCALE + 0.5)):
00476             (0x80000000+
00477              static_cast<unsigned int>(in[0]*VTKKW_FP_SCALE + 0.5)));
00478   out[1] = ((in[1]<0.0)?
00479             (static_cast<unsigned int>(-in[1] * VTKKW_FP_SCALE + 0.5)):
00480             (0x80000000+
00481              static_cast<unsigned int>(in[1]*VTKKW_FP_SCALE + 0.5)));
00482   out[2] = ((in[2]<0.0)?
00483             (static_cast<unsigned int>(-in[2] * VTKKW_FP_SCALE + 0.5)):
00484             (0x80000000+
00485              static_cast<unsigned int>(in[2]*VTKKW_FP_SCALE + 0.5)));
00486 }
00487 
00488 inline void vtkFixedPointVolumeRayCastMapper::FixedPointIncrement( unsigned int position[3], unsigned int increment[3] )
00489 {
00490   if ( increment[0]&0x80000000 )
00491     {
00492     position[0] += (increment[0]&0x7fffffff);
00493     }
00494   else
00495     {
00496     position[0] -= increment[0];
00497     }
00498   if ( increment[1]&0x80000000 )
00499     {
00500     position[1] += (increment[1]&0x7fffffff);
00501     }
00502   else
00503     {
00504     position[1] -= increment[1];
00505     }
00506   if ( increment[2]&0x80000000 )
00507     {
00508     position[2] += (increment[2]&0x7fffffff);
00509     }
00510   else
00511     {
00512     position[2] -= increment[2];
00513     }
00514 }
00515 
00516 
00517 inline void vtkFixedPointVolumeRayCastMapper::GetFloatTripleFromPointer( float v[3], float *ptr )
00518 {
00519   v[0] = *(ptr);
00520   v[1] = *(ptr+1);
00521   v[2] = *(ptr+2);
00522 }
00523 
00524 inline void vtkFixedPointVolumeRayCastMapper::GetUIntTripleFromPointer( unsigned int v[3], unsigned int *ptr )
00525 {
00526   v[0] = *(ptr);
00527   v[1] = *(ptr+1);
00528   v[2] = *(ptr+2);
00529 }
00530 
00531 inline void vtkFixedPointVolumeRayCastMapper::ShiftVectorDown( unsigned int in[3],
00532                                                        unsigned int out[3] )
00533 {
00534   out[0] = in[0] >> VTKKW_FP_SHIFT;
00535   out[1] = in[1] >> VTKKW_FP_SHIFT;
00536   out[2] = in[2] >> VTKKW_FP_SHIFT;
00537 } 
00538 
00539 inline int vtkFixedPointVolumeRayCastMapper::CheckMinMaxVolumeFlag( unsigned int mmpos[3], int c )
00540 {
00541   unsigned int offset = 
00542     this->MinMaxVolumeSize[3] * 
00543     ( mmpos[2]*this->MinMaxVolumeSize[0]*this->MinMaxVolumeSize[1] +
00544       mmpos[1]*this->MinMaxVolumeSize[0] +
00545       mmpos[0] ) + c;
00546   
00547   return ((*(this->MinMaxVolume + 3*offset + 2))&0x00ff);
00548 }
00549 
00550 inline int vtkFixedPointVolumeRayCastMapper::CheckMIPMinMaxVolumeFlag( unsigned int mmpos[3], int c, 
00551                                                                        unsigned short maxIdx )
00552 {
00553   unsigned int offset = 
00554     this->MinMaxVolumeSize[3] * 
00555     ( mmpos[2]*this->MinMaxVolumeSize[0]*this->MinMaxVolumeSize[1] +
00556       mmpos[1]*this->MinMaxVolumeSize[0] +
00557       mmpos[0] ) + c;
00558   
00559   if ( (*(this->MinMaxVolume + 3*offset + 2)&0x00ff) )
00560     {
00561     return ( *(this->MinMaxVolume + 3*offset + 1) > maxIdx );
00562     }
00563   else
00564     { 
00565     return 0;
00566     }
00567 }
00568 
00569 inline void vtkFixedPointVolumeRayCastMapper::LookupColorUC( unsigned short *colorTable,
00570                                                      unsigned short *scalarOpacityTable,
00571                                                      unsigned short index,
00572                                                      unsigned char  color[4] )
00573 {
00574   unsigned short alpha = scalarOpacityTable[index];
00575   color[0] = static_cast<unsigned char>
00576     ((colorTable[3*index  ]*alpha + 0x7fff)>>(2*VTKKW_FP_SHIFT - 8));
00577   color[1] = static_cast<unsigned char>
00578     ((colorTable[3*index+1]*alpha + 0x7fff)>>(2*VTKKW_FP_SHIFT - 8));
00579   color[2] = static_cast<unsigned char>
00580     ((colorTable[3*index+2]*alpha + 0x7fff)>>(2*VTKKW_FP_SHIFT - 8));
00581   color[3] = static_cast<unsigned char>(alpha>>(VTKKW_FP_SHIFT - 8));
00582 }
00583 
00584 inline void vtkFixedPointVolumeRayCastMapper::LookupDependentColorUC( unsigned short *colorTable,
00585                                                               unsigned short *scalarOpacityTable,
00586                                                               unsigned short index[4],
00587                                                               int            components,
00588                                                               unsigned char  color[4] )
00589 {
00590   unsigned short alpha;
00591   switch ( components )
00592     {
00593     case 2:
00594       alpha = scalarOpacityTable[index[1]];
00595       color[0] = static_cast<unsigned char>
00596         ((colorTable[3*index[0]  ]*alpha + 0x7fff)>>(2*VTKKW_FP_SHIFT - 8));
00597       color[1] = static_cast<unsigned char>
00598         ((colorTable[3*index[0]+1]*alpha + 0x7fff)>>(2*VTKKW_FP_SHIFT - 8));
00599       color[2] = static_cast<unsigned char>
00600         ((colorTable[3*index[0]+2]*alpha + 0x7fff)>>(2*VTKKW_FP_SHIFT - 8));
00601       color[3] = static_cast<unsigned char>(alpha>>(VTKKW_FP_SHIFT - 8));
00602       break;
00603     case 4:
00604       alpha = scalarOpacityTable[index[3]];
00605       color[0] = static_cast<unsigned char>((index[0]*alpha + 0x7fff)>>VTKKW_FP_SHIFT );
00606       color[1] = static_cast<unsigned char>((index[1]*alpha + 0x7fff)>>VTKKW_FP_SHIFT );
00607       color[2] = static_cast<unsigned char>((index[2]*alpha + 0x7fff)>>VTKKW_FP_SHIFT );
00608       color[3] = static_cast<unsigned char>(alpha>>(VTKKW_FP_SHIFT - 8));
00609       break;
00610     }
00611 }
00612 
00613 
00614 inline void vtkFixedPointVolumeRayCastMapper::LookupAndCombineIndependentColorsUC( unsigned short *colorTable[4],
00615                                                                            unsigned short *scalarOpacityTable[4],
00616                                                                            unsigned short  index[4],
00617                                                                            float           weights[4],
00618                                                                            int             components,
00619                                                                            unsigned char   color[4] )
00620 {
00621   unsigned int tmp[4] = {0,0,0,0};
00622   
00623   for ( int i = 0; i < components; i++ )
00624     {
00625     unsigned short alpha = static_cast<unsigned short>(scalarOpacityTable[i][index[i]]*weights[i]);
00626     tmp[0] += static_cast<unsigned char>(((colorTable[i][3*index[i]  ])*alpha + 0x7fff)>>(2*VTKKW_FP_SHIFT - 8));
00627     tmp[1] += static_cast<unsigned char>(((colorTable[i][3*index[i]+1])*alpha + 0x7fff)>>(2*VTKKW_FP_SHIFT - 8));
00628     tmp[2] += static_cast<unsigned char>(((colorTable[i][3*index[i]+2])*alpha + 0x7fff)>>(2*VTKKW_FP_SHIFT - 8));
00629     tmp[3] += static_cast<unsigned char>(alpha>>(VTKKW_FP_SHIFT - 8));
00630     }
00631 
00632   color[0] = (tmp[0]>255)?(255):(tmp[0]);
00633   color[1] = (tmp[1]>255)?(255):(tmp[1]);
00634   color[2] = (tmp[2]>255)?(255):(tmp[2]);
00635   color[3] = (tmp[3]>255)?(255):(tmp[3]);
00636   
00637 }
00638 
00639 inline int vtkFixedPointVolumeRayCastMapper::CheckIfCropped( unsigned int pos[3] )
00640 {
00641   int idx;
00642   
00643   if ( pos[2] < this->FixedPointCroppingRegionPlanes[4] )
00644     {
00645     idx = 0;
00646     }
00647   else if ( pos[2] > this->FixedPointCroppingRegionPlanes[5] )
00648     {
00649     idx = 18;
00650     }
00651   else
00652     {
00653     idx = 9;
00654     }
00655 
00656   if ( pos[1] >= this->FixedPointCroppingRegionPlanes[2] )
00657     {
00658     if ( pos[1] > this->FixedPointCroppingRegionPlanes[3] )
00659       {
00660       idx += 6;
00661       }
00662     else
00663       {
00664       idx += 3;
00665       }
00666     }
00667 
00668   if ( pos[0] >= this->FixedPointCroppingRegionPlanes[0] )
00669     {
00670     if ( pos[0] > this->FixedPointCroppingRegionPlanes[1] )
00671       {
00672       idx += 2;
00673       }
00674     else
00675       {
00676       idx += 1;
00677       }
00678     }
00679   
00680   return !(this->CroppingRegionFlags&this->CroppingRegionMask[idx]);
00681 }
00682 
00683 #endif

Generated on Mon Jan 21 23:07:37 2008 for VTK by  doxygen 1.4.3-20050530