VTK  9.3.1
vtkUnstructuredGridBunykRayCastFunction.h
Go to the documentation of this file.
1 // SPDX-FileCopyrightText: Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
2 // SPDX-License-Identifier: BSD-3-Clause
3 
48 #ifndef vtkUnstructuredGridBunykRayCastFunction_h
49 #define vtkUnstructuredGridBunykRayCastFunction_h
50 
51 #include "vtkRenderingVolumeModule.h" // For export macro
53 
54 VTK_ABI_NAMESPACE_BEGIN
55 class vtkRenderer;
56 class vtkVolume;
58 class vtkMatrix4x4;
62 class vtkIdList;
63 class vtkDoubleArray;
64 class vtkDataArray;
65 
66 // We manage the memory for the list of intersections ourself - this is the
67 // storage used. We keep 10,000 elements in each array, and we can have up to
68 // 1,000 arrays.
69 #define VTK_BUNYKRCF_MAX_ARRAYS 10000
70 #define VTK_BUNYKRCF_ARRAY_SIZE 10000
71 
72 class VTKRENDERINGVOLUME_EXPORT vtkUnstructuredGridBunykRayCastFunction
74 {
75 public:
78  void PrintSelf(ostream& os, vtkIndent indent) override;
79 
83  void Initialize(vtkRenderer* ren, vtkVolume* vol) override;
84 
88  void Finalize() override;
89 
92 
93  // Used to store each triangle - made public because of the
94  // templated function
95  class Triangle
96  {
97  public:
98  vtkIdType PointIndex[3];
99  vtkIdType ReferredByTetra[2];
100  double P1X, P1Y;
101  double P2X, P2Y;
102  double Denominator;
103  double A, B, C, D;
105  };
106 
107  // Used to store each intersection for the pixel rays - made
108  // public because of the templated function
110  {
111  public:
113  double Z;
115  };
116 
121  int InTriangle(double x, double y, Triangle* triPtr);
122 
126  double* GetPoints() { return this->Points; }
127 
129 
132  vtkGetObjectMacro(ViewToWorldMatrix, vtkMatrix4x4);
134 
136 
139  vtkGetVectorMacro(ImageOrigin, int, 2);
141 
143 
146  vtkGetVectorMacro(ImageViewportSize, int, 2);
148 
152  Triangle** GetTetraTriangles() { return this->TetraTriangles; }
153 
158  {
159  return this->Image[y * this->ImageSize[0] + x];
160  }
161 
162 protected:
165 
166  // These are cached during the initialize method so that they do not
167  // need to be passed into subsequent CastRay calls.
171 
172  // Computed during the initialize method - if something is
173  // wrong (no mapper, no volume, no input, etc.) then no rendering
174  // will actually be performed.
175  int Valid;
176 
177  // These are the transformed points
179  double* Points;
180 
181  // This is the matrix that will take a transformed point back
182  // to world coordinates
184 
185  // This is the intersection list per pixel in the image
187 
188  // This is the size of the image we are computing (which does
189  // not need to match the screen size)
190  int ImageSize[2];
191 
192  // Since we may only be computing a subregion of the "full" image,
193  // this is the origin of the region we are computing. We must
194  // subtract this origin from any pixel (x,y) locations before
195  // accessing the pixel in this->Image (which represents only the
196  // subregion)
197  int ImageOrigin[2];
198 
199  // This is the full size of the image
200  int ImageViewportSize[2];
201 
202  // These are values saved for the building of the TriangleList. Basically
203  // we need to check if the data has changed in some way.
206 
207  // This is a memory intensive algorithm! For each tetra in the
208  // input data we create up to 4 triangles (we don't create duplicates)
209  // This is the TriangleList. Then, for each tetra we keep track of
210  // the pointer to each of its four triangles - this is the
211  // TetraTriangles. We also keep a duplicate list of points
212  // (transformed into view space) - these are the Points.
215 
217 
218  // Compute whether a boundary triangle is front facing by
219  // looking at the fourth point in the tetra to see if it is
220  // in front (triangle is backfacing) or behind (triangle is
221  // front facing) the plane containing the triangle.
222  int IsTriangleFrontFacing(Triangle* triPtr, vtkIdType tetraIndex);
223 
224  // The image contains lists of intersections per pixel - we
225  // need to clear this during the initialization phase for each
226  // render.
227  void ClearImage();
228 
229  // This is the memory buffer used to build the intersection
230  // lists. We do our own memory management here because allocating
231  // a bunch of small elements during rendering is too slow.
232  Intersection* IntersectionBuffer[VTK_BUNYKRCF_MAX_ARRAYS];
233  int IntersectionBufferCount[VTK_BUNYKRCF_MAX_ARRAYS];
234 
235  // This method replaces new for creating a new element - it
236  // returns one from the big block already allocated (it
237  // allocates another big block if necessary)
238  void* NewIntersection();
239 
240  // This method is used during the initialization process to
241  // check the validity of the objects - missing information
242  // such as the volume, renderer, mapper, etc. will be flagged
243  // and reported.
244  int CheckValidity(vtkRenderer* ren, vtkVolume* vol);
245 
246  // This method is used during the initialization process to
247  // transform the points to view coordinates
248  void TransformPoints();
249 
250  // This method is used during the initialization process to
251  // create the list of triangles if the data has changed
252  void UpdateTriangleList();
253 
254  // This method is used during the initialization process to
255  // update the view dependent information in the triangle list
256  void ComputeViewDependentInfo();
257 
258  // This method is used during the initialization process to
259  // compute the intersections for each pixel with the boundary
260  // triangles.
261  void ComputePixelIntersections();
262 
263 private:
265  void operator=(const vtkUnstructuredGridBunykRayCastFunction&) = delete;
266 };
267 
268 VTK_ABI_NAMESPACE_END
269 #endif
represents a volume (data & properties) in a rendered scene
Definition: vtkVolume.h:39
represent and manipulate 4x4 transformation matrices
Definition: vtkMatrix4x4.h:30
Defines a 1D piecewise function.
Triangle ** GetTetraTriangles()
Access to an internal structure for the templated method.
record modification and/or execution time
Definition: vtkTimeStamp.h:24
Intersection * GetIntersectionList(int x, int y)
Access to an internal structure for the templated method.
A software mapper for unstructured volumes.
abstract specification for renderers
Definition: vtkRenderer.h:61
int vtkIdType
Definition: vtkType.h:315
dynamic, self-adjusting array of double
a simple class to control print indentation
Definition: vtkIndent.h:28
list of point or cell ids
Definition: vtkIdList.h:22
abstract superclass for arrays of numeric data
Definition: vtkDataArray.h:44
void PrintSelf(ostream &os, vtkIndent indent) override
Methods invoked by print to print information about the object including superclasses.
#define VTK_NEWINSTANCE
double * GetPoints()
Access to an internal structure for the templated method.
Defines a transfer function for mapping a property to an RGB color value.
vtkUnstructuredGridVolumeRayCastIterator is a superclass for iterating over the intersections of a vi...
virtual vtkUnstructuredGridVolumeRayCastIterator * NewIterator()=0
Returns a new object that will iterate over all the intersections of a ray with the cells of the inpu...
static vtkObject * New()
Create an object with Debug turned off, modified time initialized to zero, and reference counting on...
virtual void Initialize(vtkRenderer *ren, vtkVolume *vol)=0
dataset represents arbitrary combinations of all possible cell types.