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
vtkUnstructuredGridBunykRayCastFunction::TetraTriangles
Triangle ** TetraTriangles
Definition: vtkUnstructuredGridBunykRayCastFunction.h:224
vtkUnstructuredGridBunykRayCastFunction::~vtkUnstructuredGridBunykRayCastFunction
~vtkUnstructuredGridBunykRayCastFunction() override
vtkUnstructuredGridBunykRayCastFunction::NumberOfPoints
int NumberOfPoints
Definition: vtkUnstructuredGridBunykRayCastFunction.h:189
vtkVolume
represents a volume (data & properties) in a rendered scene
Definition: vtkVolume.h:45
vtkUnstructuredGridBunykRayCastFunction::Intersection::TriPtr
Triangle * TriPtr
Definition: vtkUnstructuredGridBunykRayCastFunction.h:123
vtkIdType
int vtkIdType
Definition: vtkType.h:338
vtkUnstructuredGridBunykRayCastFunction::Valid
int Valid
Definition: vtkUnstructuredGridBunykRayCastFunction.h:186
vtkUnstructuredGridBunykRayCastFunction::Intersection
Definition: vtkUnstructuredGridBunykRayCastFunction.h:121
vtkTimeStamp
record modification and/or execution time
Definition: vtkTimeStamp.h:33
vtkUnstructuredGridBase
dataset represents arbitrary combinations of all possible cell types.
Definition: vtkUnstructuredGridBase.h:35
vtkUnstructuredGridBunykRayCastFunction::PrintSelf
void PrintSelf(ostream &os, vtkIndent indent) override
Methods invoked by print to print information about the object including superclasses.
vtkUnstructuredGridBunykRayCastFunction::Renderer
vtkRenderer * Renderer
Definition: vtkUnstructuredGridBunykRayCastFunction.h:179
vtkUnstructuredGridBunykRayCastFunction
a superclass for ray casting functions
Definition: vtkUnstructuredGridBunykRayCastFunction.h:85
vtkUnstructuredGridBunykRayCastFunction::Finalize
void Finalize() override
Called by the ray cast mapper at the end of rendering.
vtkUnstructuredGridBunykRayCastFunction::Image
Intersection ** Image
Definition: vtkUnstructuredGridBunykRayCastFunction.h:197
vtkDataArray
abstract superclass for arrays of numeric data
Definition: vtkDataArray.h:50
vtkColorTransferFunction
Defines a transfer function for mapping a property to an RGB color value.
Definition: vtkColorTransferFunction.h:55
vtkUnstructuredGridBunykRayCastFunction::CheckValidity
int CheckValidity(vtkRenderer *ren, vtkVolume *vol)
vtkUnstructuredGridBunykRayCastFunction::ComputeViewDependentInfo
void ComputeViewDependentInfo()
vtkUnstructuredGridVolumeRayCastIterator
vtkUnstructuredGridVolumeRayCastIterator is a superclass for iterating over the intersections of a vi...
Definition: vtkUnstructuredGridVolumeRayCastIterator.h:44
vtkUnstructuredGridBunykRayCastFunction::ClearImage
void ClearImage()
vtkUnstructuredGridBunykRayCastFunction::Initialize
void Initialize(vtkRenderer *ren, vtkVolume *vol) override
Called by the ray cast mapper at the start of rendering.
vtkUnstructuredGridBunykRayCastFunction::Triangle::Denominator
double Denominator
Definition: vtkUnstructuredGridBunykRayCastFunction.h:113
vtkUnstructuredGridBunykRayCastFunction::vtkUnstructuredGridBunykRayCastFunction
vtkUnstructuredGridBunykRayCastFunction()
vtkUnstructuredGridBunykRayCastFunction::UpdateTriangleList
void UpdateTriangleList()
vtkUnstructuredGridBunykRayCastFunction::SavedTriangleListMTime
vtkTimeStamp SavedTriangleListMTime
Definition: vtkUnstructuredGridBunykRayCastFunction.h:216
vtkUnstructuredGridBunykRayCastFunction::TransformPoints
void TransformPoints()
vtkUnstructuredGridBunykRayCastFunction::GetIntersectionList
Intersection * GetIntersectionList(int x, int y)
Access to an internal structure for the templated method.
Definition: vtkUnstructuredGridBunykRayCastFunction.h:168
vtkUnstructuredGridBunykRayCastFunction::Mapper
vtkUnstructuredGridVolumeRayCastMapper * Mapper
Definition: vtkUnstructuredGridBunykRayCastFunction.h:181
vtkUnstructuredGridBunykRayCastFunction::Triangle::P1Y
double P1Y
Definition: vtkUnstructuredGridBunykRayCastFunction.h:111
vtkIndent
a simple class to control print indentation
Definition: vtkIndent.h:34
vtkMatrix4x4
represent and manipulate 4x4 transformation matrices
Definition: vtkMatrix4x4.h:36
vtkUnstructuredGridBunykRayCastFunction::Triangle::D
double D
Definition: vtkUnstructuredGridBunykRayCastFunction.h:114
vtkUnstructuredGridBunykRayCastFunction::IsTriangleFrontFacing
int IsTriangleFrontFacing(Triangle *triPtr, vtkIdType tetraIndex)
vtkIdList
list of point or cell ids
Definition: vtkIdList.h:31
vtkUnstructuredGridBunykRayCastFunction::Intersection::Z
double Z
Definition: vtkUnstructuredGridBunykRayCastFunction.h:124
vtkUnstructuredGridBunykRayCastFunction::New
static vtkUnstructuredGridBunykRayCastFunction * New()
vtkUnstructuredGridBunykRayCastFunction::TriangleList
Triangle * TriangleList
Definition: vtkUnstructuredGridBunykRayCastFunction.h:227
vtkUnstructuredGridBunykRayCastFunction::Triangle::Next
Triangle * Next
Definition: vtkUnstructuredGridBunykRayCastFunction.h:115
vtkPiecewiseFunction
Defines a 1D piecewise function.
Definition: vtkPiecewiseFunction.h:46
vtkUnstructuredGridBunykRayCastFunction::GetTetraTriangles
Triangle ** GetTetraTriangles()
Access to an internal structure for the templated method.
Definition: vtkUnstructuredGridBunykRayCastFunction.h:163
vtkUnstructuredGridVolumeRayCastFunction
a superclass for ray casting functions
Definition: vtkUnstructuredGridVolumeRayCastFunction.h:39
vtkUnstructuredGridVolumeRayCastFunction.h
vtkUnstructuredGridVolumeRayCastMapper
A software mapper for unstructured volumes.
Definition: vtkUnstructuredGridVolumeRayCastMapper.h:45
vtkUnstructuredGridBunykRayCastFunction::TetraTrianglesSize
vtkIdType TetraTrianglesSize
Definition: vtkUnstructuredGridBunykRayCastFunction.h:225
VTK_BUNYKRCF_MAX_ARRAYS
#define VTK_BUNYKRCF_MAX_ARRAYS
Definition: vtkUnstructuredGridBunykRayCastFunction.h:80
vtkUnstructuredGridBunykRayCastFunction::ViewToWorldMatrix
vtkMatrix4x4 * ViewToWorldMatrix
Definition: vtkUnstructuredGridBunykRayCastFunction.h:194
vtkRenderer
abstract specification for renderers
Definition: vtkRenderer.h:59
vtkUnstructuredGridBunykRayCastFunction::Volume
vtkVolume * Volume
Definition: vtkUnstructuredGridBunykRayCastFunction.h:180
vtkUnstructuredGridBunykRayCastFunction::Triangle::P2Y
double P2Y
Definition: vtkUnstructuredGridBunykRayCastFunction.h:112
vtkUnstructuredGridBunykRayCastFunction::Triangle
Definition: vtkUnstructuredGridBunykRayCastFunction.h:107
vtkDoubleArray
dynamic, self-adjusting array of double
Definition: vtkDoubleArray.h:36
vtkUnstructuredGridBunykRayCastFunction::GetPoints
double * GetPoints()
Access to an internal structure for the templated method.
Definition: vtkUnstructuredGridBunykRayCastFunction.h:137
VTK_NEWINSTANCE
#define VTK_NEWINSTANCE
Definition: vtkWrappingHints.h:42
vtkUnstructuredGridBunykRayCastFunction::SavedTriangleListInput
vtkUnstructuredGridBase * SavedTriangleListInput
Definition: vtkUnstructuredGridBunykRayCastFunction.h:215
vtkUnstructuredGridBunykRayCastFunction::Intersection::Next
Intersection * Next
Definition: vtkUnstructuredGridBunykRayCastFunction.h:125
vtkUnstructuredGridBunykRayCastFunction::InTriangle
int InTriangle(double x, double y, Triangle *triPtr)
Is the point x, y, in the given triangle? Public for access from the templated function.
vtkUnstructuredGridBunykRayCastFunction::Points
double * Points
Definition: vtkUnstructuredGridBunykRayCastFunction.h:190
vtkUnstructuredGridBunykRayCastFunction::ComputePixelIntersections
void ComputePixelIntersections()
vtkUnstructuredGridBunykRayCastFunction::NewIterator
vtkUnstructuredGridVolumeRayCastIterator * NewIterator() override
Returns a new object that will iterate over all the intersections of a ray with the cells of the inpu...
vtkUnstructuredGridBunykRayCastFunction::NewIntersection
void * NewIntersection()