VTK  9.0.1
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 
60 #ifndef vtkUnstructuredGridBunykRayCastFunction_h
61 #define vtkUnstructuredGridBunykRayCastFunction_h
62 
63 #include "vtkRenderingVolumeModule.h" // For export macro
65 
66 class vtkRenderer;
67 class vtkVolume;
69 class vtkMatrix4x4;
73 class vtkIdList;
74 class vtkDoubleArray;
75 class vtkDataArray;
76 
77 // We manage the memory for the list of intersections ourself - this is the
78 // storage used. We keep 10,000 elements in each array, and we can have up to
79 // 1,000 arrays.
80 #define VTK_BUNYKRCF_MAX_ARRAYS 10000
81 #define VTK_BUNYKRCF_ARRAY_SIZE 10000
82 
83 class VTKRENDERINGVOLUME_EXPORT vtkUnstructuredGridBunykRayCastFunction
85 {
86 public:
89  void PrintSelf(ostream& os, vtkIndent indent) override;
90 
94  void Initialize(vtkRenderer* ren, vtkVolume* vol) override;
95 
99  void Finalize() override;
100 
103 
104  // Used to store each triangle - made public because of the
105  // templated function
106  class Triangle
107  {
108  public:
109  vtkIdType PointIndex[3];
110  vtkIdType ReferredByTetra[2];
111  double P1X, P1Y;
112  double P2X, P2Y;
113  double Denominator;
114  double A, B, C, D;
116  };
117 
118  // Used to store each intersection for the pixel rays - made
119  // public because of the templated function
121  {
122  public:
124  double Z;
126  };
127 
132  int InTriangle(double x, double y, Triangle* triPtr);
133 
137  double* GetPoints() { return this->Points; }
138 
140 
143  vtkGetObjectMacro(ViewToWorldMatrix, vtkMatrix4x4);
145 
147 
150  vtkGetVectorMacro(ImageOrigin, int, 2);
152 
154 
157  vtkGetVectorMacro(ImageViewportSize, int, 2);
159 
163  Triangle** GetTetraTriangles() { return this->TetraTriangles; }
164 
169  {
170  return this->Image[y * this->ImageSize[0] + x];
171  }
172 
173 protected:
176 
177  // These are cached during the initialize method so that they do not
178  // need to be passed into subsequent CastRay calls.
182 
183  // Computed during the initialize method - if something is
184  // wrong (no mapper, no volume, no input, etc.) then no rendering
185  // will actually be performed.
186  int Valid;
187 
188  // These are the transformed points
190  double* Points;
191 
192  // This is the matrix that will take a transformed point back
193  // to world coordinates
195 
196  // This is the intersection list per pixel in the image
198 
199  // This is the size of the image we are computing (which does
200  // not need to match the screen size)
201  int ImageSize[2];
202 
203  // Since we may only be computing a subregion of the "full" image,
204  // this is the origin of the region we are computing. We must
205  // subtract this origin from any pixel (x,y) locations before
206  // accessing the pixel in this->Image (which represents only the
207  // subregion)
208  int ImageOrigin[2];
209 
210  // This is the full size of the image
211  int ImageViewportSize[2];
212 
213  // These are values saved for the building of the TriangleList. Basically
214  // we need to check if the data has changed in some way.
217 
218  // This is a memory intensive algorithm! For each tetra in the
219  // input data we create up to 4 triangles (we don't create duplicates)
220  // This is the TriangleList. Then, for each tetra we keep track of
221  // the pointer to each of its four triangles - this is the
222  // TetraTriangles. We also keep a duplicate list of points
223  // (transformed into view space) - these are the Points.
226 
228 
229  // Compute whether a boundary triangle is front facing by
230  // looking at the fourth point in the tetra to see if it is
231  // in front (triangle is backfacing) or behind (triangle is
232  // front facing) the plane containing the triangle.
233  int IsTriangleFrontFacing(Triangle* triPtr, vtkIdType tetraIndex);
234 
235  // The image contains lists of intersections per pixel - we
236  // need to clear this during the initialization phase for each
237  // render.
238  void ClearImage();
239 
240  // This is the memory buffer used to build the intersection
241  // lists. We do our own memory management here because allocating
242  // a bunch of small elements during rendering is too slow.
243  Intersection* IntersectionBuffer[VTK_BUNYKRCF_MAX_ARRAYS];
244  int IntersectionBufferCount[VTK_BUNYKRCF_MAX_ARRAYS];
245 
246  // This method replaces new for creating a new element - it
247  // returns one from the big block already allocated (it
248  // allocates another big block if necessary)
250 
251  // This method is used during the initialization process to
252  // check the validity of the objects - missing information
253  // such as the volume, renderer, mapper, etc. will be flagged
254  // and reported.
256 
257  // This method is used during the initialization process to
258  // transform the points to view coordinates
260 
261  // This method is used during the initialization process to
262  // create the list of triangles if the data has changed
264 
265  // This method is used during the initialization process to
266  // update the view dependent information in the triangle list
268 
269  // This method is used during the initialization process to
270  // compute the intersections for each pixel with the boundary
271  // triangles.
273 
274 private:
276  void operator=(const vtkUnstructuredGridBunykRayCastFunction&) = delete;
277 };
278 
279 #endif
Defines a transfer function for mapping a property to an RGB color value.
abstract superclass for arrays of numeric data
Definition: vtkDataArray.h:50
dynamic, self-adjusting array of double
list of point or cell ids
Definition: vtkIdList.h:31
a simple class to control print indentation
Definition: vtkIndent.h:34
represent and manipulate 4x4 transformation matrices
Definition: vtkMatrix4x4.h:36
Defines a 1D piecewise function.
abstract specification for renderers
Definition: vtkRenderer.h:59
record modification and/or execution time
Definition: vtkTimeStamp.h:33
dataset represents arbitrary combinations of all possible cell types.
vtkUnstructuredGridVolumeRayCastIterator * NewIterator() override
Returns a new object that will iterate over all the intersections of a ray with the cells of the inpu...
int CheckValidity(vtkRenderer *ren, vtkVolume *vol)
Triangle ** GetTetraTriangles()
Access to an internal structure for the templated method.
void PrintSelf(ostream &os, vtkIndent indent) override
Methods invoked by print to print information about the object including superclasses.
static vtkUnstructuredGridBunykRayCastFunction * New()
void Finalize() override
Called by the ray cast mapper at the end of rendering.
int IsTriangleFrontFacing(Triangle *triPtr, vtkIdType tetraIndex)
double * GetPoints()
Access to an internal structure for the templated method.
void Initialize(vtkRenderer *ren, vtkVolume *vol) override
Called by the ray cast mapper at the start of rendering.
int InTriangle(double x, double y, Triangle *triPtr)
Is the point x, y, in the given triangle? Public for access from the templated function.
Intersection * GetIntersectionList(int x, int y)
Access to an internal structure for the templated method.
vtkUnstructuredGridVolumeRayCastIterator is a superclass for iterating over the intersections of a vi...
A software mapper for unstructured volumes.
represents a volume (data & properties) in a rendered scene
Definition: vtkVolume.h:45
int vtkIdType
Definition: vtkType.h:338
#define VTK_NEWINSTANCE