VTK: Rendering/Volume/vtkUnstructuredGridBunykRayCastFunction.h Source File

| 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
52 #include "vtkUnstructuredGridVolumeRayCastFunction.h"
53
54 VTK_ABI_NAMESPACE_BEGIN
55 class vtkRenderer;
56 class vtkVolume;
57 class vtkUnstructuredGridVolumeRayCastMapper;
58 class vtkMatrix4x4;
59 class vtkPiecewiseFunction;
60 class vtkColorTransferFunction;
61 class vtkUnstructuredGridBase;
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
73 : public vtkUnstructuredGridVolumeRayCastFunction
74 {
75 public:
76 static vtkUnstructuredGridBunykRayCastFunction* New();
77 vtkTypeMacro(vtkUnstructuredGridBunykRayCastFunction, vtkUnstructuredGridVolumeRayCastFunction);
78 void PrintSelf(ostream& os, vtkIndent indent) override;
79
83 void Initialize(vtkRenderer* ren, vtkVolume* vol) override;
84
88 void Finalize() override;
89
90 VTK_NEWINSTANCE
91 vtkUnstructuredGridVolumeRayCastIterator* NewIterator() override;
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;
104 Triangle* Next;
105 };
106
107 // Used to store each intersection for the pixel rays - made
108 // public because of the templated function
109 class Intersection
110 {
111 public:
112 Triangle* TriPtr;
113 double Z;
114 Intersection* Next;
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
157 Intersection* GetIntersectionList(int x, int y)
158 {
159 return this->Image[y * this->ImageSize[0] + x];
160 }
161
162 protected:
163 vtkUnstructuredGridBunykRayCastFunction();
164 ~vtkUnstructuredGridBunykRayCastFunction() override;
165
166 // These are cached during the initialize method so that they do not
167 // need to be passed into subsequent CastRay calls.
168 vtkRenderer* Renderer;
169 vtkVolume* Volume;
170 vtkUnstructuredGridVolumeRayCastMapper* Mapper;
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
178 int NumberOfPoints;
179 double* Points;
180
181 // This is the matrix that will take a transformed point back
182 // to world coordinates
183 vtkMatrix4x4* ViewToWorldMatrix;
184
185 // This is the intersection list per pixel in the image
186 Intersection** 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.
204 vtkUnstructuredGridBase* SavedTriangleListInput;
205 vtkTimeStamp SavedTriangleListMTime;
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.
213 Triangle** TetraTriangles;
214 vtkIdType TetraTrianglesSize;
215
216 Triangle* TriangleList;
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:
264 vtkUnstructuredGridBunykRayCastFunction(const vtkUnstructuredGridBunykRayCastFunction&) = delete;
265 void operator=(const vtkUnstructuredGridBunykRayCastFunction&) = delete;
266 };
267
268 VTK_ABI_NAMESPACE_END
269 #endif
vtkColorTransferFunction
Defines a transfer function for mapping a property to an RGB color value.
Definition: vtkColorTransferFunction.h:60
vtkDataArray
abstract superclass for arrays of numeric data
Definition: vtkDataArray.h:54
vtkDoubleArray
dynamic, self-adjusting array of double
Definition: vtkDoubleArray.h:40
vtkIdList
list of point or cell ids
Definition: vtkIdList.h:32
vtkIndent
a simple class to control print indentation
Definition: vtkIndent.h:38
vtkMatrix4x4
represent and manipulate 4x4 transformation matrices
Definition: vtkMatrix4x4.h:40
vtkPiecewiseFunction
Defines a 1D piecewise function.
Definition: vtkPiecewiseFunction.h:50
vtkRenderer
abstract specification for renderers
Definition: vtkRenderer.h:71
vtkTimeStamp
record modification and/or execution time
Definition: vtkTimeStamp.h:34
vtkUnstructuredGridBase
dataset represents arbitrary combinations of all possible cell types.
Definition: vtkUnstructuredGridBase.h:27
vtkUnstructuredGridBunykRayCastFunction::Intersection
Definition: vtkUnstructuredGridBunykRayCastFunction.h:110
vtkUnstructuredGridBunykRayCastFunction::Intersection::Next
Intersection * Next
Definition: vtkUnstructuredGridBunykRayCastFunction.h:114
vtkUnstructuredGridBunykRayCastFunction::Intersection::Z
double Z
Definition: vtkUnstructuredGridBunykRayCastFunction.h:113
vtkUnstructuredGridBunykRayCastFunction::Intersection::TriPtr
Triangle * TriPtr
Definition: vtkUnstructuredGridBunykRayCastFunction.h:112
vtkUnstructuredGridBunykRayCastFunction::Triangle
Definition: vtkUnstructuredGridBunykRayCastFunction.h:96
vtkUnstructuredGridBunykRayCastFunction::Triangle::Denominator
double Denominator
Definition: vtkUnstructuredGridBunykRayCastFunction.h:102
vtkUnstructuredGridBunykRayCastFunction::Triangle::P1X
double P1X
Definition: vtkUnstructuredGridBunykRayCastFunction.h:100
vtkUnstructuredGridBunykRayCastFunction::Triangle::P2X
double P2X
Definition: vtkUnstructuredGridBunykRayCastFunction.h:101
vtkUnstructuredGridBunykRayCastFunction::Triangle::Next
Triangle * Next
Definition: vtkUnstructuredGridBunykRayCastFunction.h:104
vtkUnstructuredGridBunykRayCastFunction::Triangle::A
double A
Definition: vtkUnstructuredGridBunykRayCastFunction.h:103
vtkUnstructuredGridBunykRayCastFunction
a superclass for ray casting functions
Definition: vtkUnstructuredGridBunykRayCastFunction.h:74
vtkUnstructuredGridBunykRayCastFunction::Points
double * Points
Definition: vtkUnstructuredGridBunykRayCastFunction.h:179
vtkUnstructuredGridBunykRayCastFunction::TransformPoints
void TransformPoints()
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::CheckValidity
int CheckValidity(vtkRenderer *ren, vtkVolume *vol)
vtkUnstructuredGridBunykRayCastFunction::ComputeViewDependentInfo
void ComputeViewDependentInfo()
vtkUnstructuredGridBunykRayCastFunction::GetTetraTriangles
Triangle ** GetTetraTriangles()
Access to an internal structure for the templated method.
Definition: vtkUnstructuredGridBunykRayCastFunction.h:152
vtkUnstructuredGridBunykRayCastFunction::~vtkUnstructuredGridBunykRayCastFunction
~vtkUnstructuredGridBunykRayCastFunction() override
vtkUnstructuredGridBunykRayCastFunction::NewIntersection
void * NewIntersection()
vtkUnstructuredGridBunykRayCastFunction::PrintSelf
void PrintSelf(ostream &os, vtkIndent indent) override
Methods invoked by print to print information about the object including superclasses.
vtkUnstructuredGridBunykRayCastFunction::ComputePixelIntersections
void ComputePixelIntersections()
vtkUnstructuredGridBunykRayCastFunction::New
static vtkUnstructuredGridBunykRayCastFunction * New()
vtkUnstructuredGridBunykRayCastFunction::Finalize
void Finalize() override
Called by the ray cast mapper at the end of rendering.
vtkUnstructuredGridBunykRayCastFunction::IsTriangleFrontFacing
int IsTriangleFrontFacing(Triangle *triPtr, vtkIdType tetraIndex)
vtkUnstructuredGridBunykRayCastFunction::GetPoints
double * GetPoints()
Access to an internal structure for the templated method.
Definition: vtkUnstructuredGridBunykRayCastFunction.h:126
vtkUnstructuredGridBunykRayCastFunction::Initialize
void Initialize(vtkRenderer *ren, vtkVolume *vol) override
Called by the ray cast mapper at the start of rendering.
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::Valid
int Valid
Definition: vtkUnstructuredGridBunykRayCastFunction.h:175
vtkUnstructuredGridBunykRayCastFunction::SavedTriangleListMTime
vtkTimeStamp SavedTriangleListMTime
Definition: vtkUnstructuredGridBunykRayCastFunction.h:205
vtkUnstructuredGridBunykRayCastFunction::Mapper
vtkUnstructuredGridVolumeRayCastMapper * Mapper
Definition: vtkUnstructuredGridBunykRayCastFunction.h:170
vtkUnstructuredGridBunykRayCastFunction::ClearImage
void ClearImage()
vtkUnstructuredGridBunykRayCastFunction::TetraTriangles
Triangle ** TetraTriangles
Definition: vtkUnstructuredGridBunykRayCastFunction.h:213
vtkUnstructuredGridBunykRayCastFunction::Image
Intersection ** Image
Definition: vtkUnstructuredGridBunykRayCastFunction.h:186
vtkUnstructuredGridBunykRayCastFunction::SavedTriangleListInput
vtkUnstructuredGridBase * SavedTriangleListInput
Definition: vtkUnstructuredGridBunykRayCastFunction.h:204
vtkUnstructuredGridBunykRayCastFunction::TetraTrianglesSize
vtkIdType TetraTrianglesSize
Definition: vtkUnstructuredGridBunykRayCastFunction.h:214
vtkUnstructuredGridBunykRayCastFunction::Renderer
vtkRenderer * Renderer
Definition: vtkUnstructuredGridBunykRayCastFunction.h:168
vtkUnstructuredGridBunykRayCastFunction::UpdateTriangleList
void UpdateTriangleList()
vtkUnstructuredGridBunykRayCastFunction::ViewToWorldMatrix
vtkMatrix4x4 * ViewToWorldMatrix
Definition: vtkUnstructuredGridBunykRayCastFunction.h:183
vtkUnstructuredGridBunykRayCastFunction::GetIntersectionList
Intersection * GetIntersectionList(int x, int y)
Access to an internal structure for the templated method.
Definition: vtkUnstructuredGridBunykRayCastFunction.h:157
vtkUnstructuredGridBunykRayCastFunction::TriangleList
Triangle * TriangleList
Definition: vtkUnstructuredGridBunykRayCastFunction.h:216
vtkUnstructuredGridBunykRayCastFunction::Volume
vtkVolume * Volume
Definition: vtkUnstructuredGridBunykRayCastFunction.h:169
vtkUnstructuredGridBunykRayCastFunction::vtkUnstructuredGridBunykRayCastFunction
vtkUnstructuredGridBunykRayCastFunction()
vtkUnstructuredGridBunykRayCastFunction::NumberOfPoints
int NumberOfPoints
Definition: vtkUnstructuredGridBunykRayCastFunction.h:178
vtkUnstructuredGridVolumeRayCastFunction
a superclass for ray casting functions
Definition: vtkUnstructuredGridVolumeRayCastFunction.h:28
vtkUnstructuredGridVolumeRayCastIterator
vtkUnstructuredGridVolumeRayCastIterator is a superclass for iterating over the intersections of a vi...
Definition: vtkUnstructuredGridVolumeRayCastIterator.h:31
vtkUnstructuredGridVolumeRayCastMapper
A software mapper for unstructured volumes.
Definition: vtkUnstructuredGridVolumeRayCastMapper.h:46
vtkVolume
represents a volume (data & properties) in a rendered scene
Definition: vtkVolume.h:49
vtkIdType
int vtkIdType
Definition: vtkType.h:315
VTK_BUNYKRCF_MAX_ARRAYS
#define VTK_BUNYKRCF_MAX_ARRAYS
Definition: vtkUnstructuredGridBunykRayCastFunction.h:69
vtkUnstructuredGridVolumeRayCastFunction.h
VTK_NEWINSTANCE
#define VTK_NEWINSTANCE
Definition: vtkWrappingHints.h:32