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

Rendering/vtkVolumeRayCastMapper.h

Go to the documentation of this file.
00001 /*=========================================================================
00002 
00003   Program:   Visualization Toolkit
00004   Module:    $RCSfile: vtkVolumeRayCastMapper.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 
00031 #ifndef __vtkVolumeRayCastMapper_h
00032 #define __vtkVolumeRayCastMapper_h
00033 
00034 #include "vtkVolumeMapper.h"
00035 #include "vtkVolumeRayCastFunction.h" // For vtkVolumeRayCastStaticInfo 
00036                                       // and vtkVolumeRayCastDynamicInfo
00037 class vtkEncodedGradientEstimator;
00038 class vtkEncodedGradientShader;
00039 class vtkMatrix4x4;
00040 class vtkMultiThreader;
00041 class vtkPlaneCollection;
00042 class vtkRenderer;
00043 class vtkTimerLog;
00044 class vtkVolume;
00045 class vtkVolumeRayCastFunction;
00046 class vtkVolumeTransform;
00047 class vtkTransform;
00048 
00049 //BTX
00050 // Macro for floor of x
00051 inline int vtkFloorFuncMacro(double x)
00052 {
00053 #if defined i386 || defined _M_IX86
00054   double tempval;
00055   // use 52-bit precision of IEEE double to round (x - 0.25) to 
00056   // the nearest multiple of 0.5, according to prevailing rounding
00057   // mode which is IEEE round-to-nearest,even
00058   tempval = (x - 0.25) + 3377699720527872.0; // (2**51)*1.5
00059   // extract mantissa, use shift to divide by 2 and hence get rid
00060   // of the bit that gets messed up because the FPU uses
00061   // round-to-nearest,even mode instead of round-to-nearest,+infinity
00062   return ((int*)&tempval)[0] >> 1;
00063 #else
00064   // quick-and-dirty, assumes x >= 0
00065   return (int)(x);
00066 #endif
00067 }
00068 
00069 // Macro for rounding x (for x >= 0)
00070 inline int vtkRoundFuncMacro(double x)
00071 {
00072   return vtkFloorFuncMacro(x + 0.5);
00073 }
00074 //ETX
00075 
00076 // Macro for tri-linear interpolation - do four linear interpolations on
00077 // edges, two linear interpolations between pairs of edges, then a final
00078 // interpolation between faces
00079 #define vtkTrilinFuncMacro(v,x,y,z,a,b,c,d,e,f,g,h)         \
00080         t00 =   a + (x)*(b-a);      \
00081         t01 =   c + (x)*(d-c);      \
00082         t10 =   e + (x)*(f-e);      \
00083         t11 =   g + (x)*(h-g);      \
00084         t0  = t00 + (y)*(t01-t00);  \
00085         t1  = t10 + (y)*(t11-t10);  \
00086         v   =  t0 + (z)*(t1-t0);
00087 
00088 // Forward declaration needed for use by friend declaration below.
00089 VTK_THREAD_RETURN_TYPE VolumeRayCastMapper_CastRays( void *arg );
00090 
00091 class VTK_RENDERING_EXPORT vtkVolumeRayCastMapper : public vtkVolumeMapper
00092 {
00093 public:
00094   static vtkVolumeRayCastMapper *New();
00095   vtkTypeRevisionMacro(vtkVolumeRayCastMapper,vtkVolumeMapper);
00096   void PrintSelf( ostream& os, vtkIndent indent );
00097 
00099 
00102   vtkSetMacro( SampleDistance, double );
00103   vtkGetMacro( SampleDistance, double );
00105 
00107 
00109   virtual void SetVolumeRayCastFunction(vtkVolumeRayCastFunction*);
00110   vtkGetObjectMacro( VolumeRayCastFunction, vtkVolumeRayCastFunction );
00112 
00114 
00115   virtual void SetGradientEstimator(vtkEncodedGradientEstimator *gradest);
00116   vtkGetObjectMacro( GradientEstimator, vtkEncodedGradientEstimator );
00118 
00120 
00121   vtkGetObjectMacro( GradientShader, vtkEncodedGradientShader );
00123 
00125 
00128   vtkSetClampMacro( ImageSampleDistance, double, 0.1f, 100.0f );
00129   vtkGetMacro( ImageSampleDistance, double );
00131 
00133 
00135   vtkSetClampMacro( MinimumImageSampleDistance, double, 0.1f, 100.0f );
00136   vtkGetMacro( MinimumImageSampleDistance, double );
00138 
00140 
00142   vtkSetClampMacro( MaximumImageSampleDistance, double, 0.1f, 100.0f );
00143   vtkGetMacro( MaximumImageSampleDistance, double );
00145 
00147 
00150   vtkSetClampMacro( AutoAdjustSampleDistances, int, 0, 1 );
00151   vtkGetMacro( AutoAdjustSampleDistances, int );
00152   vtkBooleanMacro( AutoAdjustSampleDistances, int );
00154   
00156 
00158   void SetNumberOfThreads( int num );
00159   vtkGetMacro( NumberOfThreads, int );
00161 
00163 
00165   vtkSetClampMacro( IntermixIntersectingGeometry, int, 0, 1 );
00166   vtkGetMacro( IntermixIntersectingGeometry, int );
00167   vtkBooleanMacro( IntermixIntersectingGeometry, int );
00169   
00170 //BTX
00173   void Render( vtkRenderer *, vtkVolume * );
00174 
00179   void ReleaseGraphicsResources(vtkWindow *);
00180 
00183   float GetZeroOpacityThreshold( vtkVolume *vol );
00184 
00186 
00188   virtual float GetGradientMagnitudeScale();
00189   virtual float GetGradientMagnitudeBias();
00190   virtual float GetGradientMagnitudeScale(int)
00191     {return this->GetGradientMagnitudeScale();};
00192   virtual float GetGradientMagnitudeBias(int)
00193     {return this->GetGradientMagnitudeBias();};
00195   
00196 //ETX
00197 
00198 protected:
00199   vtkVolumeRayCastMapper();
00200   ~vtkVolumeRayCastMapper();
00201 
00202   vtkVolumeRayCastFunction     *VolumeRayCastFunction;
00203   vtkEncodedGradientEstimator  *GradientEstimator;
00204   vtkEncodedGradientShader     *GradientShader;
00205 
00206   // The distance between sample points along the ray
00207   double                       SampleDistance;
00208   double                       ImageSampleDistance;
00209   double                       MinimumImageSampleDistance;
00210   double                       MaximumImageSampleDistance;
00211   int                          AutoAdjustSampleDistances;
00212   
00213   double                       WorldSampleDistance;
00214   int                          ScalarDataType;
00215   void                         *ScalarDataPointer;
00216 
00217   void                         UpdateShadingTables( vtkRenderer *ren, 
00218                                                     vtkVolume *vol );
00219 
00220   void ComputeMatrices( vtkImageData *data, vtkVolume *vol );
00221   virtual void RenderTexture( vtkVolume *vol, vtkRenderer *ren)=0;
00222   int ComputeRowBounds( vtkVolume *vol, vtkRenderer *ren );
00223   
00224   friend VTK_THREAD_RETURN_TYPE VolumeRayCastMapper_CastRays( void *arg );
00225 
00226   vtkMultiThreader  *Threader;
00227   int               NumberOfThreads;
00228 
00229   vtkMatrix4x4 *PerspectiveMatrix;
00230   vtkMatrix4x4 *ViewToWorldMatrix;
00231   vtkMatrix4x4 *ViewToVoxelsMatrix;
00232   vtkMatrix4x4 *VoxelsToViewMatrix;
00233   vtkMatrix4x4 *WorldToVoxelsMatrix;
00234   vtkMatrix4x4 *VoxelsToWorldMatrix;
00235 
00236   vtkMatrix4x4 *VolumeMatrix;
00237   
00238   vtkTransform *PerspectiveTransform;
00239   vtkTransform *VoxelsTransform;
00240   vtkTransform *VoxelsToViewTransform;
00241   
00242   // This is how big the image would be if it covered the entire viewport
00243   int            ImageViewportSize[2];
00244   
00245   // This is how big the allocated memory for image is. This may be bigger
00246   // or smaller than ImageFullSize - it will be bigger if necessary to 
00247   // ensure a power of 2, it will be smaller if the volume only covers a
00248   // small region of the viewport
00249   int            ImageMemorySize[2];
00250   
00251   // This is the size of subregion in ImageSize image that we are using for
00252   // the current image. Since ImageSize is a power of 2, there is likely
00253   // wasted space in it. This number will be used for things such as clearing
00254   // the image if necessary.
00255   int            ImageInUseSize[2];
00256   
00257   // This is the location in ImageFullSize image where our ImageSize image
00258   // is located.
00259   int            ImageOrigin[2];
00260   
00261   // This is the allocated image
00262   unsigned char *Image;
00263   
00264   int  *RowBounds;
00265   int  *OldRowBounds;
00266 
00267   float        *RenderTimeTable;
00268   vtkVolume   **RenderVolumeTable;
00269   vtkRenderer **RenderRendererTable;
00270   int           RenderTableSize;
00271   int           RenderTableEntries;
00272 
00273   void StoreRenderTime( vtkRenderer *ren, vtkVolume *vol, float t );
00274   float RetrieveRenderTime( vtkRenderer *ren, vtkVolume *vol );
00275 
00276   int           IntermixIntersectingGeometry;
00277 
00278   float        *ZBuffer;
00279   int           ZBufferSize[2];
00280   int           ZBufferOrigin[2];
00281 
00282   float         MinimumViewDistance;
00283   
00284   int           ClipRayAgainstVolume( vtkVolumeRayCastDynamicInfo *dynamicInfo,
00285                                       float bounds[6] );
00286 
00287   void          InitializeClippingPlanes( vtkVolumeRayCastStaticInfo *staticInfo,
00288                                           vtkPlaneCollection *planes );
00289 
00290   int           ClipRayAgainstClippingPlanes( vtkVolumeRayCastDynamicInfo *dynamicInfo,
00291                                               vtkVolumeRayCastStaticInfo *staticInfo);
00292   
00293   // Get the ZBuffer value corresponding to location (x,y) where (x,y)
00294   // are indexing into the ImageInUse image. This must be converted to
00295   // the zbuffer image coordinates. Nearest neighbor value is returned.
00296   double         GetZBufferValue( int x, int y );
00297 
00298 private:
00299   vtkVolumeRayCastMapper(const vtkVolumeRayCastMapper&);  // Not implemented.
00300   void operator=(const vtkVolumeRayCastMapper&);  // Not implemented.
00301 };
00302 
00303 #endif
00304