VTK
vtkVolumeRayCastMapper.h
Go to the documentation of this file.
1 /*=========================================================================
2 
3  Program: Visualization Toolkit
4  Module: vtkVolumeRayCastMapper.h
5 
6  Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
7  All rights reserved.
8  See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
9 
10  This software is distributed WITHOUT ANY WARRANTY; without even
11  the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
12  PURPOSE. See the above copyright notice for more information.
13 
14 =========================================================================*/
15 
31 #ifndef __vtkVolumeRayCastMapper_h
32 #define __vtkVolumeRayCastMapper_h
33 
34 #include "vtkRenderingVolumeModule.h" // For export macro
35 #include "vtkVolumeMapper.h"
36 #include "vtkVolumeRayCastFunction.h" // For vtkVolumeRayCastStaticInfo
37  // and vtkVolumeRayCastDynamicInfo
38 #include "vtkFastNumericConversion.h" // for fast rounding and floor
39 
42 class vtkMatrix4x4;
43 class vtkMultiThreader;
44 class vtkPlaneCollection;
45 class vtkRenderer;
46 class vtkTimerLog;
47 class vtkVolume;
49 class vtkVolumeTransform;
50 class vtkTransform;
52 
53 //BTX
54 // Macro for floor of x
55 
56 inline int vtkFloorFuncMacro(double x)
57 {
59 }
60 
61 
62 // Macro for rounding x (for x >= 0)
63 inline int vtkRoundFuncMacro(double x)
64 {
66 }
67 //ETX
68 
69 // Macro for tri-linear interpolation - do four linear interpolations on
70 // edges, two linear interpolations between pairs of edges, then a final
71 // interpolation between faces
72 #define vtkTrilinFuncMacro(v,x,y,z,a,b,c,d,e,f,g,h) \
73  t00 = a + (x)*(b-a); \
74  t01 = c + (x)*(d-c); \
75  t10 = e + (x)*(f-e); \
76  t11 = g + (x)*(h-g); \
77  t0 = t00 + (y)*(t01-t00); \
78  t1 = t10 + (y)*(t11-t10); \
79  v = t0 + (z)*(t1-t0);
80 
81 // Forward declaration needed for use by friend declaration below.
83 
84 class VTKRENDERINGVOLUME_EXPORT vtkVolumeRayCastMapper : public vtkVolumeMapper
85 {
86 public:
87  static vtkVolumeRayCastMapper *New();
89  void PrintSelf( ostream& os, vtkIndent indent );
90 
92 
95  vtkSetMacro( SampleDistance, double );
96  vtkGetMacro( SampleDistance, double );
98 
100 
102  virtual void SetVolumeRayCastFunction(vtkVolumeRayCastFunction*);
103  vtkGetObjectMacro( VolumeRayCastFunction, vtkVolumeRayCastFunction );
105 
107 
108  virtual void SetGradientEstimator(vtkEncodedGradientEstimator *gradest);
109  vtkGetObjectMacro( GradientEstimator, vtkEncodedGradientEstimator );
111 
113 
114  vtkGetObjectMacro( GradientShader, vtkEncodedGradientShader );
116 
118 
121  vtkSetClampMacro( ImageSampleDistance, double, 0.1, 100.0 );
122  vtkGetMacro( ImageSampleDistance, double );
124 
126 
128  vtkSetClampMacro( MinimumImageSampleDistance, double, 0.1, 100.0 );
129  vtkGetMacro( MinimumImageSampleDistance, double );
131 
133 
135  vtkSetClampMacro( MaximumImageSampleDistance, double, 0.1, 100.0 );
136  vtkGetMacro( MaximumImageSampleDistance, double );
138 
140 
143  vtkSetClampMacro( AutoAdjustSampleDistances, int, 0, 1 );
144  vtkGetMacro( AutoAdjustSampleDistances, int );
145  vtkBooleanMacro( AutoAdjustSampleDistances, int );
147 
149 
151  void SetNumberOfThreads( int num );
152  int GetNumberOfThreads();
154 
156 
158  vtkSetClampMacro( IntermixIntersectingGeometry, int, 0, 1 );
159  vtkGetMacro( IntermixIntersectingGeometry, int );
160  vtkBooleanMacro( IntermixIntersectingGeometry, int );
162 
163 //BTX
166  void Render( vtkRenderer *, vtkVolume * );
167 
173 
176  float GetZeroOpacityThreshold( vtkVolume *vol );
177 
179 
181  virtual float GetGradientMagnitudeScale();
182  virtual float GetGradientMagnitudeBias();
183  virtual float GetGradientMagnitudeScale(int)
184  {return this->GetGradientMagnitudeScale();};
185  virtual float GetGradientMagnitudeBias(int)
186  {return this->GetGradientMagnitudeBias();};
188 
189 //ETX
190 
191 protected:
194 
199 
200  virtual void ReportReferences(vtkGarbageCollector*);
201 
202  // The distance between sample points along the ray
208 
212 
213  void UpdateShadingTables( vtkRenderer *ren,
214  vtkVolume *vol );
215 
216  void ComputeMatrices( vtkImageData *data, vtkVolume *vol );
217  int ComputeRowBounds( vtkVolume *vol, vtkRenderer *ren );
218 
220 
222 
229 
231 
235 
236  // This is how big the image would be if it covered the entire viewport
237  int ImageViewportSize[2];
238 
239  // This is how big the allocated memory for image is. This may be bigger
240  // or smaller than ImageFullSize - it will be bigger if necessary to
241  // ensure a power of 2, it will be smaller if the volume only covers a
242  // small region of the viewport
243  int ImageMemorySize[2];
244 
245  // This is the size of subregion in ImageSize image that we are using for
246  // the current image. Since ImageSize is a power of 2, there is likely
247  // wasted space in it. This number will be used for things such as clearing
248  // the image if necessary.
249  int ImageInUseSize[2];
250 
251  // This is the location in ImageFullSize image where our ImageSize image
252  // is located.
253  int ImageOrigin[2];
254 
255  // This is the allocated image
256  unsigned char *Image;
257 
258  int *RowBounds;
260 
266 
267  void StoreRenderTime( vtkRenderer *ren, vtkVolume *vol, float t );
268  float RetrieveRenderTime( vtkRenderer *ren, vtkVolume *vol );
269 
271 
272  float *ZBuffer;
273  int ZBufferSize[2];
274  int ZBufferOrigin[2];
275 
277 
278  int ClipRayAgainstVolume( vtkVolumeRayCastDynamicInfo *dynamicInfo,
279  float bounds[6] );
280 
281  void InitializeClippingPlanes( vtkVolumeRayCastStaticInfo *staticInfo,
282  vtkPlaneCollection *planes );
283 
284  int ClipRayAgainstClippingPlanes( vtkVolumeRayCastDynamicInfo *dynamicInfo,
285  vtkVolumeRayCastStaticInfo *staticInfo);
286 
287  // Get the ZBuffer value corresponding to location (x,y) where (x,y)
288  // are indexing into the ImageInUse image. This must be converted to
289  // the zbuffer image coordinates. Nearest neighbor value is returned.
290  double GetZBufferValue( int x, int y );
291 
292 private:
293  vtkVolumeRayCastMapper(const vtkVolumeRayCastMapper&); // Not implemented.
294  void operator=(const vtkVolumeRayCastMapper&); // Not implemented.
295 };
296 
297 #endif
298