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)
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.
239  vtkVolume *vol);
240 
241  // This method is used during the initialization process to
242  // transform the points to view coordinates
244 
245  // This method is used during the initialization process to
246  // create the list of triangles if the data has changed
248 
249  // This method is used during the initialization process to
250  // update the view dependent information in the triangle list
252 
253  // This method is used during the initialization process to
254  // compute the intersections for each pixel with the boundary
255  // triangles.
257 
258 //ETX
259 
260 private:
262  void operator=(const vtkUnstructuredGridBunykRayCastFunction&); // Not implemented.
263 };
264 
265 #endif
266 
267 
268 
269 
270 
271 
272 
vtkUnstructuredGridBunykRayCastFunction::PrintSelf
virtual void PrintSelf(ostream &os, vtkIndent indent)
vtkUnstructuredGridBunykRayCastFunction::TetraTriangles
Triangle ** TetraTriangles
Definition: vtkUnstructuredGridBunykRayCastFunction.h:207
vtkGetObjectMacro
#define vtkGetObjectMacro(name, type)
Definition: vtkSetGet.h:232
vtkUnstructuredGridBunykRayCastFunction::NewIterator
virtual vtkUnstructuredGridVolumeRayCastIterator * NewIterator()
vtkUnstructuredGridBunykRayCastFunction::NumberOfPoints
int NumberOfPoints
Definition: vtkUnstructuredGridBunykRayCastFunction.h:170
vtkUnstructuredGridBunykRayCastFunction::Initialize
virtual void Initialize(vtkRenderer *ren, vtkVolume *vol)
vtkVolume
represents a volume (data & properties) in a rendered scene
Definition: vtkVolume.h:50
vtkUnstructuredGridBunykRayCastFunction::Intersection::TriPtr
Triangle * TriPtr
Definition: vtkUnstructuredGridBunykRayCastFunction.h:115
vtkIdType
int vtkIdType
Definition: vtkType.h:275
vtkUnstructuredGridBunykRayCastFunction::Valid
int Valid
Definition: vtkUnstructuredGridBunykRayCastFunction.h:167
vtkUnstructuredGridBunykRayCastFunction::Intersection
Definition: vtkUnstructuredGridBunykRayCastFunction.h:113
vtkTimeStamp
record modification and/or execution time
Definition: vtkTimeStamp.h:35
vtkRenderingVolumeModule.h
vtkUnstructuredGridBase
dataset represents arbitrary combinations of all possible cell types. May be mapped onto a non-standa...
Definition: vtkUnstructuredGridBase.h:37
vtkTypeMacro
#define vtkTypeMacro(thisClass, superclass)
Definition: vtkSetGet.h:642
vtkUnstructuredGridBunykRayCastFunction::Renderer
vtkRenderer * Renderer
Definition: vtkUnstructuredGridBunykRayCastFunction.h:160
vtkUnstructuredGridBunykRayCastFunction
a superclass for ray casting functions
Definition: vtkUnstructuredGridBunykRayCastFunction.h:83
vtkgl::x
GLint GLint GLint GLint GLint x
Definition: vtkgl.h:11318
vtkUnstructuredGridBunykRayCastFunction::Image
Intersection ** Image
Definition: vtkUnstructuredGridBunykRayCastFunction.h:179
vtkDataArray
abstract superclass for arrays of numeric data
Definition: vtkDataArray.h:55
vtkGetVectorMacro
#define vtkGetVectorMacro(name, type, count)
Definition: vtkSetGet.h:424
vtkColorTransferFunction
Defines a transfer function for mapping a property to an RGB color value.
Definition: vtkColorTransferFunction.h:58
vtkUnstructuredGridBunykRayCastFunction::Finalize
virtual void Finalize()
vtkUnstructuredGridBunykRayCastFunction::CheckValidity
int CheckValidity(vtkRenderer *ren, vtkVolume *vol)
vtkUnstructuredGridBunykRayCastFunction::ComputeViewDependentInfo
void ComputeViewDependentInfo()
vtkUnstructuredGridVolumeRayCastIterator
Definition: vtkUnstructuredGridVolumeRayCastIterator.h:43
vtkUnstructuredGridBunykRayCastFunction::ClearImage
void ClearImage()
vtkUnstructuredGridBunykRayCastFunction::Triangle::Denominator
double Denominator
Definition: vtkUnstructuredGridBunykRayCastFunction.h:106
vtkUnstructuredGridBunykRayCastFunction::vtkUnstructuredGridBunykRayCastFunction
vtkUnstructuredGridBunykRayCastFunction()
vtkUnstructuredGridBunykRayCastFunction::UpdateTriangleList
void UpdateTriangleList()
vtkUnstructuredGridBunykRayCastFunction::SavedTriangleListMTime
vtkTimeStamp SavedTriangleListMTime
Definition: vtkUnstructuredGridBunykRayCastFunction.h:198
vtkUnstructuredGridBunykRayCastFunction::TransformPoints
void TransformPoints()
vtkUnstructuredGridBunykRayCastFunction::GetIntersectionList
Intersection * GetIntersectionList(int x, int y)
Definition: vtkUnstructuredGridBunykRayCastFunction.h:150
vtkUnstructuredGridBunykRayCastFunction::Mapper
vtkUnstructuredGridVolumeRayCastMapper * Mapper
Definition: vtkUnstructuredGridBunykRayCastFunction.h:162
vtkUnstructuredGridBunykRayCastFunction::Triangle::P1Y
double P1Y
Definition: vtkUnstructuredGridBunykRayCastFunction.h:104
vtkIndent
a simple class to control print indentation
Definition: vtkIndent.h:39
vtkMatrix4x4
represent and manipulate 4x4 transformation matrices
Definition: vtkMatrix4x4.h:39
vtkUnstructuredGridBunykRayCastFunction::Triangle::D
double D
Definition: vtkUnstructuredGridBunykRayCastFunction.h:107
vtkUnstructuredGridBunykRayCastFunction::IsTriangleFrontFacing
int IsTriangleFrontFacing(Triangle *triPtr, vtkIdType tetraIndex)
vtkIdList
list of point or cell ids
Definition: vtkIdList.h:36
vtkUnstructuredGridBunykRayCastFunction::Intersection::Z
double Z
Definition: vtkUnstructuredGridBunykRayCastFunction.h:116
vtkUnstructuredGridBunykRayCastFunction::New
static vtkUnstructuredGridBunykRayCastFunction * New()
vtkUnstructuredGridBunykRayCastFunction::TriangleList
Triangle * TriangleList
Definition: vtkUnstructuredGridBunykRayCastFunction.h:210
vtkUnstructuredGridBunykRayCastFunction::Triangle::Next
Triangle * Next
Definition: vtkUnstructuredGridBunykRayCastFunction.h:108
vtkPiecewiseFunction
Defines a 1D piecewise function.
Definition: vtkPiecewiseFunction.h:51
vtkUnstructuredGridBunykRayCastFunction::GetTetraTriangles
Triangle ** GetTetraTriangles()
Definition: vtkUnstructuredGridBunykRayCastFunction.h:147
vtkUnstructuredGridVolumeRayCastFunction
a superclass for ray casting functions
Definition: vtkUnstructuredGridVolumeRayCastFunction.h:41
vtkUnstructuredGridVolumeRayCastFunction.h
vtkUnstructuredGridVolumeRayCastMapper
A software mapper for unstructured volumes.
Definition: vtkUnstructuredGridVolumeRayCastMapper.h:49
vtkUnstructuredGridBunykRayCastFunction::TetraTrianglesSize
vtkIdType TetraTrianglesSize
Definition: vtkUnstructuredGridBunykRayCastFunction.h:208
VTK_BUNYKRCF_MAX_ARRAYS
#define VTK_BUNYKRCF_MAX_ARRAYS
Definition: vtkUnstructuredGridBunykRayCastFunction.h:79
vtkUnstructuredGridBunykRayCastFunction::ViewToWorldMatrix
vtkMatrix4x4 * ViewToWorldMatrix
Definition: vtkUnstructuredGridBunykRayCastFunction.h:175
vtkgl::y
GLint GLint GLint GLint GLint GLint y
Definition: vtkgl.h:11318
vtkRenderer
abstract specification for renderers
Definition: vtkRenderer.h:64
vtkUnstructuredGridBunykRayCastFunction::Volume
vtkVolume * Volume
Definition: vtkUnstructuredGridBunykRayCastFunction.h:161
vtkUnstructuredGridBunykRayCastFunction::Triangle::P2Y
double P2Y
Definition: vtkUnstructuredGridBunykRayCastFunction.h:105
vtkUnstructuredGridBunykRayCastFunction::~vtkUnstructuredGridBunykRayCastFunction
~vtkUnstructuredGridBunykRayCastFunction()
VTKRENDERINGVOLUME_EXPORT
#define VTKRENDERINGVOLUME_EXPORT
Definition: vtkRenderingVolumeModule.h:15
vtkUnstructuredGridBunykRayCastFunction::Triangle
Definition: vtkUnstructuredGridBunykRayCastFunction.h:100
vtkDoubleArray
dynamic, self-adjusting array of double
Definition: vtkDoubleArray.h:49
vtkUnstructuredGridBunykRayCastFunction::GetPoints
double * GetPoints()
Definition: vtkUnstructuredGridBunykRayCastFunction.h:129
vtkUnstructuredGridBunykRayCastFunction::SavedTriangleListInput
vtkUnstructuredGridBase * SavedTriangleListInput
Definition: vtkUnstructuredGridBunykRayCastFunction.h:197
vtkUnstructuredGridBunykRayCastFunction::Intersection::Next
Intersection * Next
Definition: vtkUnstructuredGridBunykRayCastFunction.h:117
vtkUnstructuredGridBunykRayCastFunction::InTriangle
int InTriangle(double x, double y, Triangle *triPtr)
vtkUnstructuredGridBunykRayCastFunction::Points
double * Points
Definition: vtkUnstructuredGridBunykRayCastFunction.h:171
vtkUnstructuredGridBunykRayCastFunction::ComputePixelIntersections
void ComputePixelIntersections()
vtkUnstructuredGridBunykRayCastFunction::NewIntersection
void * NewIntersection()