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

dox/Rendering/vtkVolumeRayCastMapper.h

Go to the documentation of this file.
00001 /*========================================================================= 00002 00003 Program: Visualization Toolkit 00004 Module: $RCSfile: vtkVolumeRayCastMapper.h,v $ 00005 Language: C++ 00006 00007 Copyright (c) 1993-2002 Ken Martin, Will Schroeder, Bill Lorensen 00008 All rights reserved. 00009 See Copyright.txt or http://www.kitware.com/Copyright.htm for details. 00010 00011 This software is distributed WITHOUT ANY WARRANTY; without even 00012 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 00013 PURPOSE. See the above copyright notice for more information. 00014 00015 =========================================================================*/ 00016 00035 #ifndef __vtkVolumeRayCastMapper_h 00036 #define __vtkVolumeRayCastMapper_h 00037 00038 #include "vtkVolumeMapper.h" 00039 #include "vtkVolumeRayCastFunction.h" // For vtkVolumeRayCastStaticInfo 00040 // and vtkVolumeRayCastDynamicInfo 00041 class vtkEncodedGradientEstimator; 00042 class vtkEncodedGradientShader; 00043 class vtkMatrix4x4; 00044 class vtkMultiThreader; 00045 class vtkPlaneCollection; 00046 class vtkRenderer; 00047 class vtkTimerLog; 00048 class vtkVolume; 00049 class vtkVolumeRayCastFunction; 00050 class vtkVolumeTransform; 00051 class vtkTransform; 00052 00053 //BTX 00054 // Macro for floor of x 00055 inline int vtkFloorFuncMacro(double x) 00056 { 00057 #if defined i386 || defined _M_IX86 00058 double tempval; 00059 // use 52-bit precision of IEEE double to round (x - 0.25) to 00060 // the nearest multiple of 0.5, according to prevailing rounding 00061 // mode which is IEEE round-to-nearest,even 00062 tempval = (x - 0.25) + 3377699720527872.0; // (2**51)*1.5 00063 // extract mantissa, use shift to divide by 2 and hence get rid 00064 // of the bit that gets messed up because the FPU uses 00065 // round-to-nearest,even mode instead of round-to-nearest,+infinity 00066 return ((int*)&tempval)[0] >> 1; 00067 #else 00068 // quick-and-dirty, assumes x >= 0 00069 return (int)(x); 00070 #endif 00071 } 00072 00073 // Macro for rounding x (for x >= 0) 00074 inline int vtkRoundFuncMacro(double x) 00075 { 00076 return vtkFloorFuncMacro(x + 0.5); 00077 } 00078 //ETX 00079 00080 // Macro for tri-linear interpolation - do four linear interpolations on 00081 // edges, two linear interpolations between pairs of edges, then a final 00082 // interpolation between faces 00083 #define vtkTrilinFuncMacro(v,x,y,z,a,b,c,d,e,f,g,h) \ 00084 t00 = a + (x)*(b-a); \ 00085 t01 = c + (x)*(d-c); \ 00086 t10 = e + (x)*(f-e); \ 00087 t11 = g + (x)*(h-g); \ 00088 t0 = t00 + (y)*(t01-t00); \ 00089 t1 = t10 + (y)*(t11-t10); \ 00090 v = t0 + (z)*(t1-t0); 00091 00092 class VTK_RENDERING_EXPORT vtkVolumeRayCastMapper : public vtkVolumeMapper 00093 { 00094 public: 00095 static vtkVolumeRayCastMapper *New(); 00096 vtkTypeRevisionMacro(vtkVolumeRayCastMapper,vtkVolumeMapper); 00097 void PrintSelf( ostream& os, vtkIndent indent ); 00098 00100 00103 vtkSetMacro( SampleDistance, float ); 00104 vtkGetMacro( SampleDistance, float ); 00106 00108 00110 virtual void SetVolumeRayCastFunction(vtkVolumeRayCastFunction*); 00111 vtkGetObjectMacro( VolumeRayCastFunction, vtkVolumeRayCastFunction ); 00113 00115 00116 virtual void SetGradientEstimator(vtkEncodedGradientEstimator *gradest); 00117 vtkGetObjectMacro( GradientEstimator, vtkEncodedGradientEstimator ); 00119 00121 00122 vtkGetObjectMacro( GradientShader, vtkEncodedGradientShader ); 00124 00126 00129 vtkSetClampMacro( ImageSampleDistance, float, 0.1f, 100.0f ); 00130 vtkGetMacro( ImageSampleDistance, float ); 00132 00134 00136 vtkSetClampMacro( MinimumImageSampleDistance, float, 0.1f, 100.0f ); 00137 vtkGetMacro( MinimumImageSampleDistance, float ); 00139 00141 00143 vtkSetClampMacro( MaximumImageSampleDistance, float, 0.1f, 100.0f ); 00144 vtkGetMacro( MaximumImageSampleDistance, float ); 00146 00148 00151 vtkSetClampMacro( AutoAdjustSampleDistances, int, 0, 1 ); 00152 vtkGetMacro( AutoAdjustSampleDistances, int ); 00153 vtkBooleanMacro( AutoAdjustSampleDistances, int ); 00155 00157 00159 void SetNumberOfThreads( int num ); 00160 vtkGetMacro( NumberOfThreads, int ); 00162 00164 00166 vtkSetClampMacro( IntermixIntersectingGeometry, int, 0, 1 ); 00167 vtkGetMacro( IntermixIntersectingGeometry, int ); 00168 vtkBooleanMacro( IntermixIntersectingGeometry, int ); 00170 00171 //BTX 00174 void Render( vtkRenderer *, vtkVolume * ); 00175 00180 void ReleaseGraphicsResources(vtkWindow *); 00181 00184 float GetZeroOpacityThreshold( vtkVolume *vol ); 00185 00187 00189 virtual float GetGradientMagnitudeScale(); 00190 virtual float GetGradientMagnitudeBias(); 00191 virtual float GetGradientMagnitudeScale(int) 00192 {return this->GetGradientMagnitudeScale();}; 00193 virtual float GetGradientMagnitudeBias(int) 00194 {return this->GetGradientMagnitudeBias();}; 00196 00197 //ETX 00198 00199 protected: 00200 vtkVolumeRayCastMapper(); 00201 ~vtkVolumeRayCastMapper(); 00202 00203 vtkVolumeRayCastFunction *VolumeRayCastFunction; 00204 vtkEncodedGradientEstimator *GradientEstimator; 00205 vtkEncodedGradientShader *GradientShader; 00206 00207 // The distance between sample points along the ray 00208 float SampleDistance; 00209 float ImageSampleDistance; 00210 float MinimumImageSampleDistance; 00211 float MaximumImageSampleDistance; 00212 int AutoAdjustSampleDistances; 00213 00214 float WorldSampleDistance; 00215 int ScalarDataType; 00216 void *ScalarDataPointer; 00217 00218 void UpdateShadingTables( vtkRenderer *ren, 00219 vtkVolume *vol ); 00220 00221 void ComputeMatrices( vtkImageData *data, vtkVolume *vol ); 00222 virtual void RenderTexture( vtkVolume *vol, vtkRenderer *ren)=0; 00223 int ComputeRowBounds( vtkVolume *vol, vtkRenderer *ren ); 00224 00225 friend VTK_THREAD_RETURN_TYPE VolumeRayCastMapper_CastRays( void *arg ); 00226 00227 vtkMultiThreader *Threader; 00228 int NumberOfThreads; 00229 00230 vtkMatrix4x4 *PerspectiveMatrix; 00231 vtkMatrix4x4 *ViewToWorldMatrix; 00232 vtkMatrix4x4 *ViewToVoxelsMatrix; 00233 vtkMatrix4x4 *VoxelsToViewMatrix; 00234 vtkMatrix4x4 *WorldToVoxelsMatrix; 00235 vtkMatrix4x4 *VoxelsToWorldMatrix; 00236 00237 vtkMatrix4x4 *VolumeMatrix; 00238 00239 vtkTransform *PerspectiveTransform; 00240 vtkTransform *VoxelsTransform; 00241 vtkTransform *VoxelsToViewTransform; 00242 00243 // This is how big the image would be if it covered the entire viewport 00244 int ImageViewportSize[2]; 00245 00246 // This is how big the allocated memory for image is. This may be bigger 00247 // or smaller than ImageFullSize - it will be bigger if necessary to 00248 // ensure a power of 2, it will be smaller if the volume only covers a 00249 // small region of the viewport 00250 int ImageMemorySize[2]; 00251 00252 // This is the size of subregion in ImageSize image that we are using for 00253 // the current image. Since ImageSize is a power of 2, there is likely 00254 // wasted space in it. This number will be used for things such as clearing 00255 // the image if necessary. 00256 int ImageInUseSize[2]; 00257 00258 // This is the location in ImageFullSize image where our ImageSize image 00259 // is located. 00260 int ImageOrigin[2]; 00261 00262 // This is the allocated image 00263 unsigned char *Image; 00264 00265 int *RowBounds; 00266 int *OldRowBounds; 00267 00268 float *RenderTimeTable; 00269 vtkVolume **RenderVolumeTable; 00270 vtkRenderer **RenderRendererTable; 00271 int RenderTableSize; 00272 int RenderTableEntries; 00273 00274 void StoreRenderTime( vtkRenderer *ren, vtkVolume *vol, float t ); 00275 float RetrieveRenderTime( vtkRenderer *ren, vtkVolume *vol ); 00276 00277 int IntermixIntersectingGeometry; 00278 00279 float *ZBuffer; 00280 int ZBufferSize[2]; 00281 int ZBufferOrigin[2]; 00282 00283 float MinimumViewDistance; 00284 00285 int ClipRayAgainstVolume( vtkVolumeRayCastDynamicInfo *dynamicInfo, 00286 float bounds[6] ); 00287 00288 void InitializeClippingPlanes( vtkVolumeRayCastStaticInfo *staticInfo, 00289 vtkPlaneCollection *planes ); 00290 00291 int ClipRayAgainstClippingPlanes( vtkVolumeRayCastDynamicInfo *dynamicInfo, 00292 vtkVolumeRayCastStaticInfo *staticInfo); 00293 00294 // Get the ZBuffer value corresponding to location (x,y) where (x,y) 00295 // are indexing into the ImageInUse image. This must be converted to 00296 // the zbuffer image coordinates. Nearest neighbor value is returned. 00297 float GetZBufferValue( int x, int y ); 00298 00299 private: 00300 vtkVolumeRayCastMapper(const vtkVolumeRayCastMapper&); // Not implemented. 00301 void operator=(const vtkVolumeRayCastMapper&); // Not implemented. 00302 }; 00303 00304 #endif 00305