VTK
|
00001 /*========================================================================= 00002 00003 Program: Visualization Toolkit 00004 Module: vtkVolumeRayCastMapper.h 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 #include "vtkFastNumericConversion.h" // for fast rounding and floor 00038 00039 class vtkEncodedGradientEstimator; 00040 class vtkEncodedGradientShader; 00041 class vtkMatrix4x4; 00042 class vtkMultiThreader; 00043 class vtkPlaneCollection; 00044 class vtkRenderer; 00045 class vtkTimerLog; 00046 class vtkVolume; 00047 class vtkVolumeRayCastFunction; 00048 class vtkVolumeTransform; 00049 class vtkTransform; 00050 class vtkRayCastImageDisplayHelper; 00051 00052 //BTX 00053 // Macro for floor of x 00054 00055 inline int vtkFloorFuncMacro(double x) 00056 { 00057 return vtkFastNumericConversion::QuickFloor(x); 00058 } 00059 00060 00061 // Macro for rounding x (for x >= 0) 00062 inline int vtkRoundFuncMacro(double x) 00063 { 00064 return vtkFastNumericConversion::Round(x); 00065 } 00066 //ETX 00067 00068 // Macro for tri-linear interpolation - do four linear interpolations on 00069 // edges, two linear interpolations between pairs of edges, then a final 00070 // interpolation between faces 00071 #define vtkTrilinFuncMacro(v,x,y,z,a,b,c,d,e,f,g,h) \ 00072 t00 = a + (x)*(b-a); \ 00073 t01 = c + (x)*(d-c); \ 00074 t10 = e + (x)*(f-e); \ 00075 t11 = g + (x)*(h-g); \ 00076 t0 = t00 + (y)*(t01-t00); \ 00077 t1 = t10 + (y)*(t11-t10); \ 00078 v = t0 + (z)*(t1-t0); 00079 00080 // Forward declaration needed for use by friend declaration below. 00081 VTK_THREAD_RETURN_TYPE VolumeRayCastMapper_CastRays( void *arg ); 00082 00083 class VTK_VOLUMERENDERING_EXPORT vtkVolumeRayCastMapper : public vtkVolumeMapper 00084 { 00085 public: 00086 static vtkVolumeRayCastMapper *New(); 00087 vtkTypeMacro(vtkVolumeRayCastMapper,vtkVolumeMapper); 00088 void PrintSelf( ostream& os, vtkIndent indent ); 00089 00091 00094 vtkSetMacro( SampleDistance, double ); 00095 vtkGetMacro( SampleDistance, double ); 00097 00099 00101 virtual void SetVolumeRayCastFunction(vtkVolumeRayCastFunction*); 00102 vtkGetObjectMacro( VolumeRayCastFunction, vtkVolumeRayCastFunction ); 00104 00106 00107 virtual void SetGradientEstimator(vtkEncodedGradientEstimator *gradest); 00108 vtkGetObjectMacro( GradientEstimator, vtkEncodedGradientEstimator ); 00110 00112 00113 vtkGetObjectMacro( GradientShader, vtkEncodedGradientShader ); 00115 00117 00120 vtkSetClampMacro( ImageSampleDistance, double, 0.1, 100.0 ); 00121 vtkGetMacro( ImageSampleDistance, double ); 00123 00125 00127 vtkSetClampMacro( MinimumImageSampleDistance, double, 0.1, 100.0 ); 00128 vtkGetMacro( MinimumImageSampleDistance, double ); 00130 00132 00134 vtkSetClampMacro( MaximumImageSampleDistance, double, 0.1, 100.0 ); 00135 vtkGetMacro( MaximumImageSampleDistance, double ); 00137 00139 00142 vtkSetClampMacro( AutoAdjustSampleDistances, int, 0, 1 ); 00143 vtkGetMacro( AutoAdjustSampleDistances, int ); 00144 vtkBooleanMacro( AutoAdjustSampleDistances, int ); 00146 00148 00150 void SetNumberOfThreads( int num ); 00151 int GetNumberOfThreads(); 00153 00155 00157 vtkSetClampMacro( IntermixIntersectingGeometry, int, 0, 1 ); 00158 vtkGetMacro( IntermixIntersectingGeometry, int ); 00159 vtkBooleanMacro( IntermixIntersectingGeometry, int ); 00161 00162 //BTX 00165 void Render( vtkRenderer *, vtkVolume * ); 00166 00171 void ReleaseGraphicsResources(vtkWindow *); 00172 00175 float GetZeroOpacityThreshold( vtkVolume *vol ); 00176 00178 00180 virtual float GetGradientMagnitudeScale(); 00181 virtual float GetGradientMagnitudeBias(); 00182 virtual float GetGradientMagnitudeScale(int) 00183 {return this->GetGradientMagnitudeScale();}; 00184 virtual float GetGradientMagnitudeBias(int) 00185 {return this->GetGradientMagnitudeBias();}; 00187 00188 //ETX 00189 00190 protected: 00191 vtkVolumeRayCastMapper(); 00192 ~vtkVolumeRayCastMapper(); 00193 00194 vtkVolumeRayCastFunction *VolumeRayCastFunction; 00195 vtkEncodedGradientEstimator *GradientEstimator; 00196 vtkEncodedGradientShader *GradientShader; 00197 vtkRayCastImageDisplayHelper *ImageDisplayHelper; 00198 00199 virtual void ReportReferences(vtkGarbageCollector*); 00200 00201 // The distance between sample points along the ray 00202 double SampleDistance; 00203 double ImageSampleDistance; 00204 double MinimumImageSampleDistance; 00205 double MaximumImageSampleDistance; 00206 int AutoAdjustSampleDistances; 00207 00208 double WorldSampleDistance; 00209 int ScalarDataType; 00210 void *ScalarDataPointer; 00211 00212 void UpdateShadingTables( vtkRenderer *ren, 00213 vtkVolume *vol ); 00214 00215 void ComputeMatrices( vtkImageData *data, vtkVolume *vol ); 00216 int ComputeRowBounds( vtkVolume *vol, vtkRenderer *ren ); 00217 00218 friend VTK_THREAD_RETURN_TYPE VolumeRayCastMapper_CastRays( void *arg ); 00219 00220 vtkMultiThreader *Threader; 00221 00222 vtkMatrix4x4 *PerspectiveMatrix; 00223 vtkMatrix4x4 *ViewToWorldMatrix; 00224 vtkMatrix4x4 *ViewToVoxelsMatrix; 00225 vtkMatrix4x4 *VoxelsToViewMatrix; 00226 vtkMatrix4x4 *WorldToVoxelsMatrix; 00227 vtkMatrix4x4 *VoxelsToWorldMatrix; 00228 00229 vtkMatrix4x4 *VolumeMatrix; 00230 00231 vtkTransform *PerspectiveTransform; 00232 vtkTransform *VoxelsTransform; 00233 vtkTransform *VoxelsToViewTransform; 00234 00235 // This is how big the image would be if it covered the entire viewport 00236 int ImageViewportSize[2]; 00237 00238 // This is how big the allocated memory for image is. This may be bigger 00239 // or smaller than ImageFullSize - it will be bigger if necessary to 00240 // ensure a power of 2, it will be smaller if the volume only covers a 00241 // small region of the viewport 00242 int ImageMemorySize[2]; 00243 00244 // This is the size of subregion in ImageSize image that we are using for 00245 // the current image. Since ImageSize is a power of 2, there is likely 00246 // wasted space in it. This number will be used for things such as clearing 00247 // the image if necessary. 00248 int ImageInUseSize[2]; 00249 00250 // This is the location in ImageFullSize image where our ImageSize image 00251 // is located. 00252 int ImageOrigin[2]; 00253 00254 // This is the allocated image 00255 unsigned char *Image; 00256 00257 int *RowBounds; 00258 int *OldRowBounds; 00259 00260 float *RenderTimeTable; 00261 vtkVolume **RenderVolumeTable; 00262 vtkRenderer **RenderRendererTable; 00263 int RenderTableSize; 00264 int RenderTableEntries; 00265 00266 void StoreRenderTime( vtkRenderer *ren, vtkVolume *vol, float t ); 00267 float RetrieveRenderTime( vtkRenderer *ren, vtkVolume *vol ); 00268 00269 int IntermixIntersectingGeometry; 00270 00271 float *ZBuffer; 00272 int ZBufferSize[2]; 00273 int ZBufferOrigin[2]; 00274 00275 float MinimumViewDistance; 00276 00277 int ClipRayAgainstVolume( vtkVolumeRayCastDynamicInfo *dynamicInfo, 00278 float bounds[6] ); 00279 00280 void InitializeClippingPlanes( vtkVolumeRayCastStaticInfo *staticInfo, 00281 vtkPlaneCollection *planes ); 00282 00283 int ClipRayAgainstClippingPlanes( vtkVolumeRayCastDynamicInfo *dynamicInfo, 00284 vtkVolumeRayCastStaticInfo *staticInfo); 00285 00286 // Get the ZBuffer value corresponding to location (x,y) where (x,y) 00287 // are indexing into the ImageInUse image. This must be converted to 00288 // the zbuffer image coordinates. Nearest neighbor value is returned. 00289 double GetZBufferValue( int x, int y ); 00290 00291 private: 00292 vtkVolumeRayCastMapper(const vtkVolumeRayCastMapper&); // Not implemented. 00293 void operator=(const vtkVolumeRayCastMapper&); // Not implemented. 00294 }; 00295 00296 #endif 00297