vtkSlicerFixedPointVolumeRayCastMapper.h

Go to the documentation of this file.
00001 /*=========================================================================
00002 
00003   Program:   Visualization Toolkit
00004   Module:    $RCSfile: vtkSlicerFixedPointVolumeRayCastMapper.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 =========================================================================*/
00015 // .NAME vtkSlicerFixedPointVolumeRayCastMapper - A fixed point mapper for volumes
00016 // .SECTION Description
00017 // This is a software ray caster for rendering volumes in vtkImageData.
00018 // It works with all input data types and up to four components. It performs
00019 // composite or MIP rendering, and can be intermixed with geometric data.
00020 // Space leaping is used to speed up the rendering process. In addition,
00021 // calculation are performed in 15 bit fixed point precision. This mapper
00022 // is threaded, and will interleave scan lines across processors.
00023 //
00024 // This mapper is a good replacement for vtkVolumeRayCastMapper EXCEPT:
00025 //   - it does not do isosurface ray casting
00026 //   - it does only interpolate before classify compositing
00027 //   - it does only maximum scalar value MIP
00028 //
00029 // The vtkVolumeRayCastMapper CANNOT be used in these instances when a
00030 // vtkSlicerFixedPointVolumeRayCastMapper can be used:
00031 //   - if the data is not unsigned char or unsigned short
00032 //   - if the data has more than one component
00033 //
00034 // This mapper handles all data type from unsigned char through double.
00035 // However, some of the internal calcultions are performed in float and
00036 // therefore even the full float range may cause problems for this mapper
00037 // (both in scalar data values and in spacing between samples).
00038 //
00039 // Space leaping is performed by creating a sub-sampled volume. 4x4x4
00040 // cells in the original volume are represented by a min, max, and
00041 // combined gradient and flag value. The min max volume has three
00042 // unsigned shorts per 4x4x4 group of cells from the original volume -
00043 // one reprenting the minumum scalar index (the scalar value adjusted
00044 // to fit in the 15 bit range), the maximum scalar index, and a
00045 // third unsigned short which is both the maximum gradient opacity in
00046 // the neighborhood (an unsigned char) and the flag that is filled
00047 // in for the current lookup tables to indicate whether this region
00048 // can be skipped.
00049 
00050 // .SECTION see also
00051 // vtkVolumeMapper
00052 
00053 #ifndef __vtkSlicerFixedPointVolumeRayCastMapper_h
00054 #define __vtkSlicerFixedPointVolumeRayCastMapper_h
00055 
00056 #include "vtkVolumeMapper.h"
00057 #include "vtkVolumeRenderingReplacements.h"
00058 
00059 #define VTKKW_FP_SHIFT       15
00060 #define VTKKW_FPMM_SHIFT     17
00061 #define VTKKW_FP_MASK        0x7fff
00062 #define VTKKW_FP_SCALE       32767.0
00063 
00064 class vtkMatrix4x4;
00065 class vtkMultiThreader;
00066 class vtkPlaneCollection;
00067 class vtkRenderer;
00068 class vtkTimerLog;
00069 class vtkVolume;
00070 class vtkTransform;
00071 class vtkRenderWindow;
00072 class vtkColorTransferFunction;
00073 class vtkPiecewiseFunction;
00074 class vtkSlicerFixedPointVolumeRayCastMIPHelper;
00075 class vtkSlicerFixedPointVolumeRayCastCompositeHelper;
00076 class vtkSlicerFixedPointVolumeRayCastCompositeGOHelper;
00077 class vtkSlicerFixedPointVolumeRayCastCompositeGOShadeHelper;
00078 class vtkSlicerFixedPointVolumeRayCastCompositeShadeHelper;
00079 class vtkDirectionEncoder;
00080 class vtkEncodedGradientShader;
00081 class vtkFiniteDifferenceGradientEstimator;
00082 #include "vtkSlicerRayCastImageDisplayHelper.h"
00083 class vtkSlicerFixedPointRayCastImage;
00084 
00085 // Forward declaration needed for use by friend declaration below.
00086 VTK_THREAD_RETURN_TYPE SlicerFixedPointVolumeRayCastMapper_CastRays( void *arg );
00087 
00088 class VTK_VOLUMERENDERINGREPLACEMENTS_EXPORT vtkSlicerFixedPointVolumeRayCastMapper : public vtkVolumeMapper
00089 {
00090 public:
00091   //SLICERADD
00092     vtkGetMacro(ManualInteractive,int);
00093     vtkSetMacro(ManualInteractive,int);
00094     vtkBooleanMacro(ManualInteractive,int);
00095     vtkGetMacro(ManualInteractiveRate,double);
00096     vtkSetMacro(ManualInteractiveRate,double);
00097 
00098   //ENDSLICERADD
00099 
00100   static vtkSlicerFixedPointVolumeRayCastMapper *New();
00101   vtkTypeRevisionMacro(vtkSlicerFixedPointVolumeRayCastMapper,vtkVolumeMapper);
00102   void PrintSelf( ostream& os, vtkIndent indent );
00103 
00104   // Description:
00105   // Set/Get the distance between samples used for rendering
00106   // when AutoAdjustSampleDistances is off, or when this mapper
00107   // has more than 1 second allocated to it for rendering.
00108   vtkSetMacro( SampleDistance, float );
00109   vtkGetMacro( SampleDistance, float );
00110 
00111   // Description:
00112   // Set/Get the distance between samples when interactive rendering is happening.
00113   // In this case, interactive is defined as this volume mapper having less than 1
00114   // second allocated for rendering. When AutoAdjustSampleDistance is On, and the
00115   // allocated render time is less than 1 second, then this InteractiveSampleDistance
00116   // will be used instead of the SampleDistance above.
00117   vtkSetMacro( InteractiveSampleDistance, float );
00118   vtkGetMacro( InteractiveSampleDistance, float );
00119 
00120   // Description:
00121   // Sampling distance in the XY image dimensions. Default value of 1 meaning
00122   // 1 ray cast per pixel. If set to 0.5, 4 rays will be cast per pixel. If
00123   // set to 2.0, 1 ray will be cast for every 4 (2 by 2) pixels. This value
00124   // will be adjusted to meet a desired frame rate when AutoAdjustSampleDistances
00125   // is on.
00126   vtkSetClampMacro( ImageSampleDistance, float, 0.1f, 100.0f );
00127   vtkGetMacro( ImageSampleDistance, float );
00128 
00129   // Description:
00130   // This is the minimum image sample distance allow when the image
00131   // sample distance is being automatically adjusted.
00132   vtkSetClampMacro( MinimumImageSampleDistance, float, 0.1f, 100.0f );
00133   vtkGetMacro( MinimumImageSampleDistance, float );
00134 
00135   // Description:
00136   // This is the maximum image sample distance allow when the image
00137   // sample distance is being automatically adjusted.
00138   vtkSetClampMacro( MaximumImageSampleDistance, float, 0.1f, 100.0f );
00139   vtkGetMacro( MaximumImageSampleDistance, float );
00140 
00141   // Description:
00142   // If AutoAdjustSampleDistances is on, the the ImageSampleDistance
00143   // and the SampleDistance will be varied to achieve the allocated
00144   // render time of this prop (controlled by the desired update rate
00145   // and any culling in use). If this is an interactive render (more
00146   // than 1 frame per second) the SampleDistance will be increased,
00147   // otherwise it will not be altered (a binary decision, as opposed
00148   // to the ImageSampleDistance which will vary continuously).
00149   vtkSetClampMacro( AutoAdjustSampleDistances, int, 0, 1 );
00150   vtkGetMacro( AutoAdjustSampleDistances, int );
00151   vtkBooleanMacro( AutoAdjustSampleDistances, int );
00152 
00153   // Description:
00154   // Set/Get the number of threads to use. This by default is equal to
00155   // the number of available processors detected.
00156   void SetNumberOfThreads( int num );
00157   int GetNumberOfThreads();
00158 
00159   // Description:
00160   // If IntermixIntersectingGeometry is turned on, the zbuffer will be
00161   // captured and used to limit the traversal of the rays.
00162   vtkSetClampMacro( IntermixIntersectingGeometry, int, 0, 1 );
00163   vtkGetMacro( IntermixIntersectingGeometry, int );
00164   vtkBooleanMacro( IntermixIntersectingGeometry, int );
00165 
00166   // Description:
00167   // What is the image sample distance required to achieve the desired time?
00168   // A version of this method is provided that does not require the volume
00169   // argument since if you are using an LODProp3D you may not know this information.
00170   // If you use this version you must be certain that the ray cast mapper is
00171   // only used for one volume (and not shared among multiple volumes)
00172   float ComputeRequiredImageSampleDistance( float desiredTime,
00173                                             vtkRenderer *ren );
00174   float ComputeRequiredImageSampleDistance( float desiredTime,
00175                                             vtkRenderer *ren,
00176                                             vtkVolume *vol );
00177 
00178 //BTX
00179   // Description:
00180   // WARNING: INTERNAL METHOD - NOT INTENDED FOR GENERAL USE
00181   // Initialize rendering for this volume.
00182   void Render( vtkRenderer *, vtkVolume * );
00183 
00184   unsigned int ToSlicerFixedPointPosition( float val );
00185   void ToSlicerFixedPointPosition( float in[3], unsigned int out[3] );
00186   unsigned int ToSlicerFixedPointDirection( float dir );
00187   void ToSlicerFixedPointDirection( float in[3], unsigned int out[3] );
00188   void FixedPointIncrement( unsigned int position[3], unsigned int increment[3] );
00189   void GetFloatTripleFromPointer( float v[3], float *ptr );
00190   void GetUIntTripleFromPointer( unsigned int v[3], unsigned int *ptr );
00191   void ShiftVectorDown( unsigned int in[3], unsigned int out[3] );
00192   int CheckMinMaxVolumeFlag( unsigned int pos[3], int c );
00193   int CheckMIPMinMaxVolumeFlag( unsigned int pos[3], int c, unsigned short maxIdx );
00194 
00195   void LookupColorUC( unsigned short *colorTable,
00196                       unsigned short *scalarOpacityTable,
00197                       unsigned short index,
00198                       unsigned char  color[4] );
00199   void LookupDependentColorUC( unsigned short *colorTable,
00200                                unsigned short *scalarOpacityTable,
00201                                unsigned short index[4],
00202                                int            components,
00203                                unsigned char  color[4] );
00204   void LookupAndCombineIndependentColorsUC(
00205     unsigned short *colorTable[4],
00206     unsigned short *scalarOpacityTable[4],
00207     unsigned short index[4],
00208     float          weights[4],
00209     int            components,
00210     unsigned char  color[4] );
00211   int CheckIfCropped( unsigned int pos[3] );
00212 
00213 //ETX
00214 
00215   vtkGetObjectMacro( RenderWindow, vtkRenderWindow );
00216   vtkGetObjectMacro( MIPHelper, vtkSlicerFixedPointVolumeRayCastMIPHelper );
00217   vtkGetObjectMacro( CompositeHelper, vtkSlicerFixedPointVolumeRayCastCompositeHelper );
00218   vtkGetObjectMacro( CompositeGOHelper, vtkSlicerFixedPointVolumeRayCastCompositeGOHelper );
00219   vtkGetObjectMacro( CompositeGOShadeHelper, vtkSlicerFixedPointVolumeRayCastCompositeGOShadeHelper );
00220   vtkGetObjectMacro( CompositeShadeHelper, vtkSlicerFixedPointVolumeRayCastCompositeShadeHelper );
00221   vtkGetVectorMacro( TableShift, float, 4 );
00222   vtkGetVectorMacro( TableScale, float, 4 );
00223   vtkGetMacro( ShadingRequired, int );
00224   vtkGetMacro( GradientOpacityRequired, int );
00225 
00226   int             *GetRowBounds()                 {return this->RowBounds;}
00227   unsigned short  *GetColorTable(int c)           {return this->ColorTable[c];}
00228   unsigned short  *GetScalarOpacityTable(int c)   {return this->ScalarOpacityTable[c];}
00229   unsigned short  *GetGradientOpacityTable(int c) {return this->GradientOpacityTable[c];}
00230   vtkVolume       *GetVolume()                    {return this->Volume;}
00231   unsigned short **GetGradientNormal()            {return this->GradientNormal;}
00232   unsigned char  **GetGradientMagnitude()         {return this->GradientMagnitude;}
00233   unsigned short  *GetDiffuseShadingTable(int c)  {return this->DiffuseShadingTable[c];}
00234   unsigned short  *GetSpecularShadingTable(int c) {return this->SpecularShadingTable[c];}
00235 
00236   void ComputeRayInfo( int x, int y,
00237                        unsigned int pos[3],
00238                        unsigned int dir[3],
00239                        unsigned int *numSteps );
00240 
00241   void InitializeRayInfo( vtkVolume *vol );
00242 
00243   int ShouldUseNearestNeighborInterpolation( vtkVolume *vol );
00244 
00245   // Description:
00246   // Set / Get the underlying image object. One will be automatically
00247   // created - only need to set it when using from an AMR mapper which
00248   // renders multiple times into the same image.
00249   void SetRayCastImage( vtkSlicerFixedPointRayCastImage * );
00250   vtkGetObjectMacro( RayCastImage, vtkSlicerFixedPointRayCastImage  );
00251 
00252   int PerImageInitialization( vtkRenderer *, vtkVolume *, int,
00253                               double *, double *, int * );
00254   void PerVolumeInitialization( vtkRenderer *, vtkVolume * );
00255   void PerSubVolumeInitialization( vtkRenderer *, vtkVolume *, int );
00256   void RenderSubVolume();
00257   void DisplayRenderedImage( vtkRenderer *, vtkVolume * );
00258   void AbortRender();
00259 
00260 
00261 protected:
00262 
00263     //SLICERADD
00264     int ManualInteractive;
00265     double ManualInteractiveRate;
00266   //ENDSLICERADD
00267 
00268 
00269   vtkSlicerFixedPointVolumeRayCastMapper();
00270   ~vtkSlicerFixedPointVolumeRayCastMapper();
00271 
00272   // The helper class that displays the image
00273   vtkSlicerRayCastImageDisplayHelper *ImageDisplayHelper;
00274 
00275   // The distance between sample points along the ray
00276   float                        SampleDistance;
00277   float                        InteractiveSampleDistance;
00278 
00279   // The distance between rays in the image
00280   float                        ImageSampleDistance;
00281   float                        MinimumImageSampleDistance;
00282   float                        MaximumImageSampleDistance;
00283   int                          AutoAdjustSampleDistances;
00284 
00285   // Saved values used to restore
00286   float                        OldSampleDistance;
00287   float                        OldImageSampleDistance;
00288 
00289   // Internal method for computing matrices needed during
00290   // ray casting
00291   void ComputeMatrices( double volumeOrigin[3],
00292                         double volumeSpacing[3],
00293                         int volumeExtent[6],
00294                         vtkRenderer  *ren,
00295                         vtkVolume    *vol );
00296 
00297   int ComputeRowBounds( vtkRenderer *ren,
00298                         int imageFlag, int rowBoundsFlag,
00299                         int volumeExtent[6]);
00300 
00301   void CaptureZBuffer( vtkRenderer *ren );
00302 
00303   friend VTK_THREAD_RETURN_TYPE SlicerFixedPointVolumeRayCastMapper_CastRays( void *arg );
00304 
00305   vtkMultiThreader  *Threader;
00306 
00307   vtkMatrix4x4   *PerspectiveMatrix;
00308   vtkMatrix4x4   *ViewToWorldMatrix;
00309   vtkMatrix4x4   *ViewToVoxelsMatrix;
00310   vtkMatrix4x4   *VoxelsToViewMatrix;
00311   vtkMatrix4x4   *WorldToVoxelsMatrix;
00312   vtkMatrix4x4   *VoxelsToWorldMatrix;
00313 
00314   vtkMatrix4x4   *VolumeMatrix;
00315 
00316   vtkTransform   *PerspectiveTransform;
00317   vtkTransform   *VoxelsTransform;
00318   vtkTransform   *VoxelsToViewTransform;
00319 
00320   // This object encapsulated the image and all related information
00321   vtkSlicerFixedPointRayCastImage *RayCastImage;
00322 
00323   int             *RowBounds;
00324   int             *OldRowBounds;
00325 
00326   float           *RenderTimeTable;
00327   vtkVolume      **RenderVolumeTable;
00328   vtkRenderer    **RenderRendererTable;
00329   int              RenderTableSize;
00330   int              RenderTableEntries;
00331 
00332   void             StoreRenderTime( vtkRenderer *ren, vtkVolume *vol, float t );
00333   float            RetrieveRenderTime( vtkRenderer *ren, vtkVolume *vol );
00334   float            RetrieveRenderTime( vtkRenderer *ren );
00335 
00336   int              IntermixIntersectingGeometry;
00337 
00338   float            MinimumViewDistance;
00339 
00340   vtkColorTransferFunction *SavedRGBFunction[4];
00341   vtkPiecewiseFunction     *SavedGrayFunction[4];
00342   vtkPiecewiseFunction     *SavedScalarOpacityFunction[4];
00343   vtkPiecewiseFunction     *SavedGradientOpacityFunction[4];
00344   int                       SavedColorChannels[4];
00345   float                     SavedScalarOpacityDistance[4];
00346   int                       SavedBlendMode;
00347   vtkImageData             *SavedParametersInput;
00348   vtkTimeStamp              SavedParametersMTime;
00349 
00350   vtkImageData             *SavedGradientsInput;
00351   vtkTimeStamp              SavedGradientsMTime;
00352 
00353   float                     SavedSampleDistance;
00354 
00355 
00356   unsigned short            ColorTable[4][32768*3];
00357   unsigned short            ScalarOpacityTable[4][32768];
00358   unsigned short            GradientOpacityTable[4][256];
00359   int                       TableSize[4];
00360   float                     TableScale[4];
00361   float                     TableShift[4];
00362 
00363   float                     GradientMagnitudeScale[4];
00364   float                     GradientMagnitudeShift[4];
00365 
00366   unsigned short           **GradientNormal;
00367   unsigned char            **GradientMagnitude;
00368   unsigned short            *ContiguousGradientNormal;
00369   unsigned char             *ContiguousGradientMagnitude;
00370 
00371   int                        NumberOfGradientSlices;
00372 
00373   vtkDirectionEncoder       *DirectionEncoder;
00374 
00375   vtkEncodedGradientShader  *GradientShader;
00376 
00377   vtkFiniteDifferenceGradientEstimator *GradientEstimator;
00378 
00379   unsigned short             DiffuseShadingTable [4][65536*3];
00380   unsigned short             SpecularShadingTable[4][65536*3];
00381 
00382   int                        ShadingRequired;
00383   int                        GradientOpacityRequired;
00384 
00385   vtkRenderWindow           *RenderWindow;
00386   vtkVolume                 *Volume;
00387 
00388   int           ClipRayAgainstVolume( float rayStart[3],
00389                                       float rayEnd[3],
00390                                       float rayDirection[3],
00391                                       double bounds[6] );
00392 
00393   int           UpdateColorTable( vtkVolume *vol );
00394   int           UpdateGradients( vtkVolume *vol );
00395   int           UpdateShadingTable( vtkRenderer *ren,
00396                                     vtkVolume *vol );
00397   void          UpdateCroppingRegions();
00398 
00399   void          ComputeGradients( vtkVolume *vol );
00400 
00401   int           ClipRayAgainstClippingPlanes( float  rayStart[3],
00402                                               float  rayEnd[3],
00403                                               int    numClippingPlanes,
00404                                               float *clippingPlanes );
00405 
00406   unsigned int  SlicerFixedPointCroppingRegionPlanes[6];
00407   unsigned int  CroppingRegionMask[27];
00408 
00409   // Get the ZBuffer value corresponding to location (x,y) where (x,y)
00410   // are indexing into the ImageInUse image. This must be converted to
00411   // the zbuffer image coordinates. Nearest neighbor value is returned.
00412   float         GetZBufferValue( int x, int y );
00413 
00414   vtkSlicerFixedPointVolumeRayCastMIPHelper              *MIPHelper;
00415   vtkSlicerFixedPointVolumeRayCastCompositeHelper        *CompositeHelper;
00416   vtkSlicerFixedPointVolumeRayCastCompositeGOHelper      *CompositeGOHelper;
00417   vtkSlicerFixedPointVolumeRayCastCompositeShadeHelper   *CompositeShadeHelper;
00418   vtkSlicerFixedPointVolumeRayCastCompositeGOShadeHelper *CompositeGOShadeHelper;
00419 
00420   // Some variables used for ray computation
00421   float ViewToVoxelsArray[16];
00422   float WorldToVoxelsArray[16];
00423   float VoxelsToWorldArray[16];
00424 
00425   double CroppingBounds[6];
00426 
00427   int NumTransformedClippingPlanes;
00428   float *TransformedClippingPlanes;
00429 
00430   double SavedSpacing[3];
00431 
00432 
00433   // Min Max structured used to do space leaping
00434   unsigned short *MinMaxVolume;
00435   int             MinMaxVolumeSize[4];
00436   vtkImageData   *SavedMinMaxInput;
00437   vtkTimeStamp    SavedMinMaxBuildTime;
00438   vtkTimeStamp    SavedMinMaxGradientTime;
00439   vtkTimeStamp    SavedMinMaxFlagTime;
00440 
00441   void            UpdateMinMaxVolume( vtkVolume *vol );
00442   void            FillInMaxGradientMagnitudes( int fullDim[3],
00443                                                int smallDim[3] );
00444   void            InitMapperHelpers();
00445 
00446 private:
00447   vtkSlicerFixedPointVolumeRayCastMapper(const vtkSlicerFixedPointVolumeRayCastMapper&);  // Not implemented.
00448   void operator=(const vtkSlicerFixedPointVolumeRayCastMapper&);  // Not implemented.
00449 };
00450 
00451 
00452 inline unsigned int vtkSlicerFixedPointVolumeRayCastMapper::ToSlicerFixedPointPosition( float val )
00453 {
00454   return static_cast<unsigned int>(val * VTKKW_FP_SCALE + 0.5);
00455 }
00456 
00457 inline void vtkSlicerFixedPointVolumeRayCastMapper::ToSlicerFixedPointPosition( float in[3], unsigned int out[3] )
00458 {
00459   out[0] = static_cast<unsigned int>(in[0] * VTKKW_FP_SCALE + 0.5);
00460   out[1] = static_cast<unsigned int>(in[1] * VTKKW_FP_SCALE + 0.5);
00461   out[2] = static_cast<unsigned int>(in[2] * VTKKW_FP_SCALE + 0.5);
00462 }
00463 
00464 inline unsigned int vtkSlicerFixedPointVolumeRayCastMapper::ToSlicerFixedPointDirection( float dir )
00465 {
00466   return ((dir<0.0)?
00467           (static_cast<unsigned int>(-dir * VTKKW_FP_SCALE + 0.5)):
00468           (0x80000000+static_cast<unsigned int>(dir*VTKKW_FP_SCALE + 0.5)));
00469 }
00470 
00471 inline void vtkSlicerFixedPointVolumeRayCastMapper::ToSlicerFixedPointDirection( float in[3], unsigned int out[3] )
00472 {
00473   out[0] = ((in[0]<0.0)?
00474             (static_cast<unsigned int>(-in[0] * VTKKW_FP_SCALE + 0.5)):
00475             (0x80000000+
00476              static_cast<unsigned int>(in[0]*VTKKW_FP_SCALE + 0.5)));
00477   out[1] = ((in[1]<0.0)?
00478             (static_cast<unsigned int>(-in[1] * VTKKW_FP_SCALE + 0.5)):
00479             (0x80000000+
00480              static_cast<unsigned int>(in[1]*VTKKW_FP_SCALE + 0.5)));
00481   out[2] = ((in[2]<0.0)?
00482             (static_cast<unsigned int>(-in[2] * VTKKW_FP_SCALE + 0.5)):
00483             (0x80000000+
00484              static_cast<unsigned int>(in[2]*VTKKW_FP_SCALE + 0.5)));
00485 }
00486 
00487 inline void vtkSlicerFixedPointVolumeRayCastMapper::FixedPointIncrement( unsigned int position[3], unsigned int increment[3] )
00488 {
00489   if ( increment[0]&0x80000000 )
00490     {
00491     position[0] += (increment[0]&0x7fffffff);
00492     }
00493   else
00494     {
00495     position[0] -= increment[0];
00496     }
00497   if ( increment[1]&0x80000000 )
00498     {
00499     position[1] += (increment[1]&0x7fffffff);
00500     }
00501   else
00502     {
00503     position[1] -= increment[1];
00504     }
00505   if ( increment[2]&0x80000000 )
00506     {
00507     position[2] += (increment[2]&0x7fffffff);
00508     }
00509   else
00510     {
00511     position[2] -= increment[2];
00512     }
00513 }
00514 
00515 
00516 inline void vtkSlicerFixedPointVolumeRayCastMapper::GetFloatTripleFromPointer( float v[3], float *ptr )
00517 {
00518   v[0] = *(ptr);
00519   v[1] = *(ptr+1);
00520   v[2] = *(ptr+2);
00521 }
00522 
00523 inline void vtkSlicerFixedPointVolumeRayCastMapper::GetUIntTripleFromPointer( unsigned int v[3], unsigned int *ptr )
00524 {
00525   v[0] = *(ptr);
00526   v[1] = *(ptr+1);
00527   v[2] = *(ptr+2);
00528 }
00529 
00530 inline void vtkSlicerFixedPointVolumeRayCastMapper::ShiftVectorDown( unsigned int in[3],
00531                                                        unsigned int out[3] )
00532 {
00533   out[0] = in[0] >> VTKKW_FP_SHIFT;
00534   out[1] = in[1] >> VTKKW_FP_SHIFT;
00535   out[2] = in[2] >> VTKKW_FP_SHIFT;
00536 }
00537 
00538 inline int vtkSlicerFixedPointVolumeRayCastMapper::CheckMinMaxVolumeFlag( unsigned int mmpos[3], int c )
00539 {
00540   unsigned int offset =
00541     this->MinMaxVolumeSize[3] *
00542     ( mmpos[2]*this->MinMaxVolumeSize[0]*this->MinMaxVolumeSize[1] +
00543       mmpos[1]*this->MinMaxVolumeSize[0] +
00544       mmpos[0] ) + c;
00545 
00546   return ((*(this->MinMaxVolume + 3*offset + 2))&0x00ff);
00547 }
00548 
00549 inline int vtkSlicerFixedPointVolumeRayCastMapper::CheckMIPMinMaxVolumeFlag( unsigned int mmpos[3], int c,
00550                                                                        unsigned short maxIdx )
00551 {
00552   unsigned int offset =
00553     this->MinMaxVolumeSize[3] *
00554     ( mmpos[2]*this->MinMaxVolumeSize[0]*this->MinMaxVolumeSize[1] +
00555       mmpos[1]*this->MinMaxVolumeSize[0] +
00556       mmpos[0] ) + c;
00557 
00558   if ( (*(this->MinMaxVolume + 3*offset + 2)&0x00ff) )
00559     {
00560     return ( *(this->MinMaxVolume + 3*offset + 1) > maxIdx );
00561     }
00562   else
00563     {
00564     return 0;
00565     }
00566 }
00567 
00568 inline void vtkSlicerFixedPointVolumeRayCastMapper::LookupColorUC( unsigned short *colorTable,
00569                                                      unsigned short *scalarOpacityTable,
00570                                                      unsigned short index,
00571                                                      unsigned char  color[4] )
00572 {
00573   unsigned short alpha = scalarOpacityTable[index];
00574   color[0] = static_cast<unsigned char>
00575     ((colorTable[3*index  ]*alpha + 0x7fff)>>(2*VTKKW_FP_SHIFT - 8));
00576   color[1] = static_cast<unsigned char>
00577     ((colorTable[3*index+1]*alpha + 0x7fff)>>(2*VTKKW_FP_SHIFT - 8));
00578   color[2] = static_cast<unsigned char>
00579     ((colorTable[3*index+2]*alpha + 0x7fff)>>(2*VTKKW_FP_SHIFT - 8));
00580   color[3] = static_cast<unsigned char>(alpha>>(VTKKW_FP_SHIFT - 8));
00581 }
00582 
00583 inline void vtkSlicerFixedPointVolumeRayCastMapper::LookupDependentColorUC( unsigned short *colorTable,
00584                                                               unsigned short *scalarOpacityTable,
00585                                                               unsigned short index[4],
00586                                                               int            components,
00587                                                               unsigned char  color[4] )
00588 {
00589   unsigned short alpha;
00590   switch ( components )
00591     {
00592     case 2:
00593       alpha = scalarOpacityTable[index[1]];
00594       color[0] = static_cast<unsigned char>
00595         ((colorTable[3*index[0]  ]*alpha + 0x7fff)>>(2*VTKKW_FP_SHIFT - 8));
00596       color[1] = static_cast<unsigned char>
00597         ((colorTable[3*index[0]+1]*alpha + 0x7fff)>>(2*VTKKW_FP_SHIFT - 8));
00598       color[2] = static_cast<unsigned char>
00599         ((colorTable[3*index[0]+2]*alpha + 0x7fff)>>(2*VTKKW_FP_SHIFT - 8));
00600       color[3] = static_cast<unsigned char>(alpha>>(VTKKW_FP_SHIFT - 8));
00601       break;
00602     case 4:
00603       alpha = scalarOpacityTable[index[3]];
00604       color[0] = static_cast<unsigned char>((index[0]*alpha + 0x7fff)>>VTKKW_FP_SHIFT );
00605       color[1] = static_cast<unsigned char>((index[1]*alpha + 0x7fff)>>VTKKW_FP_SHIFT );
00606       color[2] = static_cast<unsigned char>((index[2]*alpha + 0x7fff)>>VTKKW_FP_SHIFT );
00607       color[3] = static_cast<unsigned char>(alpha>>(VTKKW_FP_SHIFT - 8));
00608       break;
00609     }
00610 }
00611 
00612 
00613 inline void vtkSlicerFixedPointVolumeRayCastMapper::LookupAndCombineIndependentColorsUC( unsigned short *colorTable[4],
00614                                                                            unsigned short *scalarOpacityTable[4],
00615                                                                            unsigned short  index[4],
00616                                                                            float           weights[4],
00617                                                                            int             components,
00618                                                                            unsigned char   color[4] )
00619 {
00620   unsigned int tmp[4] = {0,0,0,0};
00621 
00622   for ( int i = 0; i < components; i++ )
00623     {
00624     unsigned short alpha = static_cast<unsigned short>(scalarOpacityTable[i][index[i]]*weights[i]);
00625     tmp[0] += static_cast<unsigned char>(((colorTable[i][3*index[i]  ])*alpha + 0x7fff)>>(2*VTKKW_FP_SHIFT - 8));
00626     tmp[1] += static_cast<unsigned char>(((colorTable[i][3*index[i]+1])*alpha + 0x7fff)>>(2*VTKKW_FP_SHIFT - 8));
00627     tmp[2] += static_cast<unsigned char>(((colorTable[i][3*index[i]+2])*alpha + 0x7fff)>>(2*VTKKW_FP_SHIFT - 8));
00628     tmp[3] += static_cast<unsigned char>(alpha>>(VTKKW_FP_SHIFT - 8));
00629     }
00630 
00631   color[0] = (tmp[0]>255)?(255):(tmp[0]);
00632   color[1] = (tmp[1]>255)?(255):(tmp[1]);
00633   color[2] = (tmp[2]>255)?(255):(tmp[2]);
00634   color[3] = (tmp[3]>255)?(255):(tmp[3]);
00635 
00636 }
00637 
00638 inline int vtkSlicerFixedPointVolumeRayCastMapper::CheckIfCropped( unsigned int pos[3] )
00639 {
00640   int idx;
00641 
00642   if ( pos[2] < this->SlicerFixedPointCroppingRegionPlanes[4] )
00643     {
00644     idx = 0;
00645     }
00646   else if ( pos[2] > this->SlicerFixedPointCroppingRegionPlanes[5] )
00647     {
00648     idx = 18;
00649     }
00650   else
00651     {
00652     idx = 9;
00653     }
00654 
00655   if ( pos[1] >= this->SlicerFixedPointCroppingRegionPlanes[2] )
00656     {
00657     if ( pos[1] > this->SlicerFixedPointCroppingRegionPlanes[3] )
00658       {
00659       idx += 6;
00660       }
00661     else
00662       {
00663       idx += 3;
00664       }
00665     }
00666 
00667   if ( pos[0] >= this->SlicerFixedPointCroppingRegionPlanes[0] )
00668     {
00669     if ( pos[0] > this->SlicerFixedPointCroppingRegionPlanes[1] )
00670       {
00671       idx += 2;
00672       }
00673     else
00674       {
00675       idx += 1;
00676       }
00677     }
00678 
00679   return !(this->CroppingRegionFlags&this->CroppingRegionMask[idx]);
00680 }
00681 
00682 #endif

Generated on 6 Apr 2011 for Slicer3 by  doxygen 1.6.1