VTK
vtkUnstructuredGridBunykRayCastFunction.h
Go to the documentation of this file.
1 /*=========================================================================
2 
3  Program: Visualization Toolkit
4  Module: vtkUnstructuredGridBunykRayCastFunction.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 
59 #ifndef vtkUnstructuredGridBunykRayCastFunction_h
60 #define vtkUnstructuredGridBunykRayCastFunction_h
61 
62 #include "vtkRenderingVolumeModule.h" // For export macro
64 
65 class vtkRenderer;
66 class vtkVolume;
68 class vtkMatrix4x4;
72 class vtkIdList;
73 class vtkDoubleArray;
74 class vtkDataArray;
75 
76 // We manage the memory for the list of intersections ourself - this is the
77 // storage used. We keep 10,000 elements in each array, and we can have up to
78 // 1,000 arrays.
79 #define VTK_BUNYKRCF_MAX_ARRAYS 10000
80 #define VTK_BUNYKRCF_ARRAY_SIZE 10000
81 
83 {
84 public:
87  virtual void PrintSelf(ostream& os, vtkIndent indent);
88 
89 //BTX
91  virtual void Initialize( vtkRenderer *ren, vtkVolume *vol );
92 
94  virtual void Finalize();
95 
97 
98  // Used to store each triangle - made public because of the
99  // templated function
100  class Triangle {
101  public:
102  vtkIdType PointIndex[3];
103  vtkIdType ReferredByTetra[2];
104  double P1X, P1Y;
105  double P2X, P2Y;
106  double Denominator;
107  double A, B, C, D;
109  };
110 
111  // Used to store each intersection for the pixel rays - made
112  // public because of the templated function
113  class Intersection {
114  public:
116  double Z;
118  };
119 
121 
123  int InTriangle( double x, double y,
124  Triangle *triPtr );
126 
127 
129  double *GetPoints() {return this->Points;}
130 
132 
133  vtkGetObjectMacro( ViewToWorldMatrix, vtkMatrix4x4 );
135 
137 
138  vtkGetVectorMacro( ImageOrigin, int, 2 );
140 
142 
143  vtkGetVectorMacro( ImageViewportSize, int, 2 );
145 
147  Triangle **GetTetraTriangles () {return this->TetraTriangles;}
148 
150  Intersection *GetIntersectionList( int x, int y ) { return this->Image[y*this->ImageSize[0] + x]; }
151 
152 //ETX
153 
154 protected:
157 
158  // These are cached during the initialize method so that they do not
159  // need to be passed into subsequent CastRay calls.
163 
164  // Computed during the initialize method - if something is
165  // wrong (no mapper, no volume, no input, etc.) then no rendering
166  // will actually be performed.
167  int Valid;
168 
169  // These are the transformed points
171  double *Points;
172 
173  // This is the matrix that will take a transformed point back
174  // to world coordinates
176 
177 
178  // This is the intersection list per pixel in the image
180 
181  // This is the size of the image we are computing (which does
182  // not need to match the screen size)
183  int ImageSize[2];
184 
185  // Since we may only be computing a subregion of the "full" image,
186  // this is the origin of the region we are computing. We must
187  // subtract this origin from any pixel (x,y) locations before
188  // accessing the pixel in this->Image (which represents only the
189  // subregion)
190  int ImageOrigin[2];
191 
192  // This is the full size of the image
193  int ImageViewportSize[2];
194 
195  // These are values saved for the building of the TriangleList. Basically
196  // we need to check if the data has changed in some way.
199 
200 //BTX
201  // This is a memory intensive algorithm! For each tetra in the
202  // input data we create up to 4 triangles (we don't create duplicates)
203  // This is the TriangleList. Then, for each tetra we keep track of
204  // the pointer to each of its four triangles - this is the
205  // TetraTriangles. We also keep a duplicate list of points
206  // (transformed into view space) - these are the Points.
209 
211 
212  // Compute whether a boundary triangle is front facing by
213  // looking at the fourth point in the tetra to see if it is
214  // in front (triangle is backfacing) or behind (triangle is
215  // front facing) the plane containing the triangle.
216  int IsTriangleFrontFacing( Triangle *triPtr, vtkIdType tetraIndex );
217 
218  // The image contains lists of intersections per pixel - we
219  // need to clear this during the initialization phase for each
220  // render.
221  void ClearImage();
222 
223  // This is the memory buffer used to build the intersection
224  // lists. We do our own memory management here because allocating
225  // a bunch of small elements during rendering is too slow.
226  Intersection *IntersectionBuffer[VTK_BUNYKRCF_MAX_ARRAYS];
227  int IntersectionBufferCount[VTK_BUNYKRCF_MAX_ARRAYS];
228 
229  // This method replaces new for creating a new element - it
230  // returns one from the big block already allocated (it
231  // allocates another big block if necessary)
232  void *NewIntersection();
233 
234  // This method is used during the initialization process to
235  // check the validity of the objects - missing information
236  // such as the volume, renderer, mapper, etc. will be flagged
237  // and reported.
238  int CheckValidity(vtkRenderer *ren,
239  vtkVolume *vol);
240 
241  // This method is used during the initialization process to
242  // transform the points to view coordinates
243  void TransformPoints();
244 
245  // This method is used during the initialization process to
246  // create the list of triangles if the data has changed
247  void UpdateTriangleList();
248 
249  // This method is used during the initialization process to
250  // update the view dependent information in the triangle list
251  void ComputeViewDependentInfo();
252 
253  // This method is used during the initialization process to
254  // compute the intersections for each pixel with the boundary
255  // triangles.
256  void ComputePixelIntersections();
257 
258 //ETX
259 
260 private:
262  void operator=(const vtkUnstructuredGridBunykRayCastFunction&); // Not implemented.
263 };
264 
265 #endif
266 
267 
268 
269 
270 
271 
272 
virtual void PrintSelf(ostream &os, vtkIndent indent)
represents a volume (data & properties) in a rendered scene
Definition: vtkVolume.h:49
represent and manipulate 4x4 transformation matrices
Definition: vtkMatrix4x4.h:38
Defines a 1D piecewise function.
#define VTKRENDERINGVOLUME_EXPORT
record modification and/or execution time
Definition: vtkTimeStamp.h:34
A software mapper for unstructured volumes.
abstract specification for renderers
Definition: vtkRenderer.h:63
int vtkIdType
Definition: vtkType.h:275
dynamic, self-adjusting array of double
a simple class to control print indentation
Definition: vtkIndent.h:38
list of point or cell ids
Definition: vtkIdList.h:35
abstract superclass for arrays of numeric data
Definition: vtkDataArray.h:54
Defines a transfer function for mapping a property to an RGB color value.
virtual vtkUnstructuredGridVolumeRayCastIterator * NewIterator()=0
static vtkObject * New()
virtual void Initialize(vtkRenderer *ren, vtkVolume *vol)=0
dataset represents arbitrary combinations of all possible cell types. May be mapped onto a non-standa...