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

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