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 "vtkRenderingVolumeModule.h" // For export macro 00035 #include "vtkVolumeMapper.h" 00036 #include "vtkVolumeRayCastFunction.h" // For vtkVolumeRayCastStaticInfo 00037 // and vtkVolumeRayCastDynamicInfo 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 // Macro for tri-linear interpolation - do four linear interpolations on 00053 // edges, two linear interpolations between pairs of edges, then a final 00054 // interpolation between faces 00055 #define vtkTrilinFuncMacro(v,x,y,z,a,b,c,d,e,f,g,h) \ 00056 t00 = a + (x)*(b-a); \ 00057 t01 = c + (x)*(d-c); \ 00058 t10 = e + (x)*(f-e); \ 00059 t11 = g + (x)*(h-g); \ 00060 t0 = t00 + (y)*(t01-t00); \ 00061 t1 = t10 + (y)*(t11-t10); \ 00062 v = t0 + (z)*(t1-t0); 00063 00064 // Forward declaration needed for use by friend declaration below. 00065 VTK_THREAD_RETURN_TYPE VolumeRayCastMapper_CastRays( void *arg ); 00066 00067 class VTKRENDERINGVOLUME_EXPORT vtkVolumeRayCastMapper : public vtkVolumeMapper 00068 { 00069 public: 00070 static vtkVolumeRayCastMapper *New(); 00071 vtkTypeMacro(vtkVolumeRayCastMapper,vtkVolumeMapper); 00072 void PrintSelf( ostream& os, vtkIndent indent ); 00073 00075 00078 vtkSetMacro( SampleDistance, double ); 00079 vtkGetMacro( SampleDistance, double ); 00081 00083 00085 virtual void SetVolumeRayCastFunction(vtkVolumeRayCastFunction*); 00086 vtkGetObjectMacro( VolumeRayCastFunction, vtkVolumeRayCastFunction ); 00088 00090 00091 virtual void SetGradientEstimator(vtkEncodedGradientEstimator *gradest); 00092 vtkGetObjectMacro( GradientEstimator, vtkEncodedGradientEstimator ); 00094 00096 00097 vtkGetObjectMacro( GradientShader, vtkEncodedGradientShader ); 00099 00101 00104 vtkSetClampMacro( ImageSampleDistance, double, 0.1, 100.0 ); 00105 vtkGetMacro( ImageSampleDistance, double ); 00107 00109 00111 vtkSetClampMacro( MinimumImageSampleDistance, double, 0.1, 100.0 ); 00112 vtkGetMacro( MinimumImageSampleDistance, double ); 00114 00116 00118 vtkSetClampMacro( MaximumImageSampleDistance, double, 0.1, 100.0 ); 00119 vtkGetMacro( MaximumImageSampleDistance, double ); 00121 00123 00126 vtkSetClampMacro( AutoAdjustSampleDistances, int, 0, 1 ); 00127 vtkGetMacro( AutoAdjustSampleDistances, int ); 00128 vtkBooleanMacro( AutoAdjustSampleDistances, int ); 00130 00132 00134 void SetNumberOfThreads( int num ); 00135 int GetNumberOfThreads(); 00137 00139 00141 vtkSetClampMacro( IntermixIntersectingGeometry, int, 0, 1 ); 00142 vtkGetMacro( IntermixIntersectingGeometry, int ); 00143 vtkBooleanMacro( IntermixIntersectingGeometry, int ); 00145 00146 //BTX 00149 void Render( vtkRenderer *, vtkVolume * ); 00150 00155 void ReleaseGraphicsResources(vtkWindow *); 00156 00159 float GetZeroOpacityThreshold( vtkVolume *vol ); 00160 00162 00164 virtual float GetGradientMagnitudeScale(); 00165 virtual float GetGradientMagnitudeBias(); 00166 virtual float GetGradientMagnitudeScale(int) 00167 {return this->GetGradientMagnitudeScale();}; 00168 virtual float GetGradientMagnitudeBias(int) 00169 {return this->GetGradientMagnitudeBias();}; 00171 00172 //ETX 00173 00174 protected: 00175 vtkVolumeRayCastMapper(); 00176 ~vtkVolumeRayCastMapper(); 00177 00178 vtkVolumeRayCastFunction *VolumeRayCastFunction; 00179 vtkEncodedGradientEstimator *GradientEstimator; 00180 vtkEncodedGradientShader *GradientShader; 00181 vtkRayCastImageDisplayHelper *ImageDisplayHelper; 00182 00183 virtual void ReportReferences(vtkGarbageCollector*); 00184 00185 // The distance between sample points along the ray 00186 double SampleDistance; 00187 double ImageSampleDistance; 00188 double MinimumImageSampleDistance; 00189 double MaximumImageSampleDistance; 00190 int AutoAdjustSampleDistances; 00191 00192 double WorldSampleDistance; 00193 int ScalarDataType; 00194 void *ScalarDataPointer; 00195 00196 void UpdateShadingTables( vtkRenderer *ren, 00197 vtkVolume *vol ); 00198 00199 void ComputeMatrices( vtkImageData *data, vtkVolume *vol ); 00200 int ComputeRowBounds( vtkVolume *vol, vtkRenderer *ren ); 00201 00202 friend VTK_THREAD_RETURN_TYPE VolumeRayCastMapper_CastRays( void *arg ); 00203 00204 vtkMultiThreader *Threader; 00205 00206 vtkMatrix4x4 *PerspectiveMatrix; 00207 vtkMatrix4x4 *ViewToWorldMatrix; 00208 vtkMatrix4x4 *ViewToVoxelsMatrix; 00209 vtkMatrix4x4 *VoxelsToViewMatrix; 00210 vtkMatrix4x4 *WorldToVoxelsMatrix; 00211 vtkMatrix4x4 *VoxelsToWorldMatrix; 00212 00213 vtkMatrix4x4 *VolumeMatrix; 00214 00215 vtkTransform *PerspectiveTransform; 00216 vtkTransform *VoxelsTransform; 00217 vtkTransform *VoxelsToViewTransform; 00218 00219 // This is how big the image would be if it covered the entire viewport 00220 int ImageViewportSize[2]; 00221 00222 // This is how big the allocated memory for image is. This may be bigger 00223 // or smaller than ImageFullSize - it will be bigger if necessary to 00224 // ensure a power of 2, it will be smaller if the volume only covers a 00225 // small region of the viewport 00226 int ImageMemorySize[2]; 00227 00228 // This is the size of subregion in ImageSize image that we are using for 00229 // the current image. Since ImageSize is a power of 2, there is likely 00230 // wasted space in it. This number will be used for things such as clearing 00231 // the image if necessary. 00232 int ImageInUseSize[2]; 00233 00234 // This is the location in ImageFullSize image where our ImageSize image 00235 // is located. 00236 int ImageOrigin[2]; 00237 00238 // This is the allocated image 00239 unsigned char *Image; 00240 00241 int *RowBounds; 00242 int *OldRowBounds; 00243 00244 float *RenderTimeTable; 00245 vtkVolume **RenderVolumeTable; 00246 vtkRenderer **RenderRendererTable; 00247 int RenderTableSize; 00248 int RenderTableEntries; 00249 00250 void StoreRenderTime( vtkRenderer *ren, vtkVolume *vol, float t ); 00251 float RetrieveRenderTime( vtkRenderer *ren, vtkVolume *vol ); 00252 00253 int IntermixIntersectingGeometry; 00254 00255 float *ZBuffer; 00256 int ZBufferSize[2]; 00257 int ZBufferOrigin[2]; 00258 00259 float MinimumViewDistance; 00260 00261 int ClipRayAgainstVolume( vtkVolumeRayCastDynamicInfo *dynamicInfo, 00262 float bounds[6] ); 00263 00264 void InitializeClippingPlanes( vtkVolumeRayCastStaticInfo *staticInfo, 00265 vtkPlaneCollection *planes ); 00266 00267 int ClipRayAgainstClippingPlanes( vtkVolumeRayCastDynamicInfo *dynamicInfo, 00268 vtkVolumeRayCastStaticInfo *staticInfo); 00269 00270 // Get the ZBuffer value corresponding to location (x,y) where (x,y) 00271 // are indexing into the ImageInUse image. This must be converted to 00272 // the zbuffer image coordinates. Nearest neighbor value is returned. 00273 double GetZBufferValue( int x, int y ); 00274 00275 private: 00276 vtkVolumeRayCastMapper(const vtkVolumeRayCastMapper&); // Not implemented. 00277 void operator=(const vtkVolumeRayCastMapper&); // Not implemented. 00278 }; 00279 00280 #endif 00281