VTK
|
00001 /*========================================================================= 00002 00003 Program: Visualization Toolkit 00004 Module: vtkUnstructuredGridBunykRayCastFunction.h 00005 00006 Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen 00007 All rights reserved. 00008 See Copyright.txt or http://www.kitware.com/Copyright.htm for details. 00009 00010 This software is distributed WITHOUT ANY WARRANTY; without even 00011 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 00012 PURPOSE. See the above copyright notice for more information. 00013 00014 =========================================================================*/ 00015 00059 #ifndef __vtkUnstructuredGridBunykRayCastFunction_h 00060 #define __vtkUnstructuredGridBunykRayCastFunction_h 00061 00062 #include "vtkUnstructuredGridVolumeRayCastFunction.h" 00063 00064 class vtkRenderer; 00065 class vtkVolume; 00066 class vtkUnstructuredGridVolumeRayCastMapper; 00067 class vtkMatrix4x4; 00068 class vtkPiecewiseFunction; 00069 class vtkColorTransferFunction; 00070 class vtkUnstructuredGrid; 00071 class vtkIdList; 00072 class vtkDoubleArray; 00073 class vtkDataArray; 00074 00075 // We manage the memory for the list of intersections ourself - this is the 00076 // storage used. We keep 10,000 elements in each array, and we can have up to 00077 // 1,000 arrays. 00078 #define VTK_BUNYKRCF_MAX_ARRAYS 10000 00079 #define VTK_BUNYKRCF_ARRAY_SIZE 10000 00080 00081 class VTK_VOLUMERENDERING_EXPORT vtkUnstructuredGridBunykRayCastFunction : public vtkUnstructuredGridVolumeRayCastFunction 00082 { 00083 public: 00084 static vtkUnstructuredGridBunykRayCastFunction *New(); 00085 vtkTypeMacro(vtkUnstructuredGridBunykRayCastFunction,vtkUnstructuredGridVolumeRayCastFunction); 00086 virtual void PrintSelf(ostream& os, vtkIndent indent); 00087 00088 //BTX 00090 virtual void Initialize( vtkRenderer *ren, vtkVolume *vol ); 00091 00093 virtual void Finalize(); 00094 00095 virtual vtkUnstructuredGridVolumeRayCastIterator *NewIterator(); 00096 00097 // Used to store each triangle - made public because of the 00098 // templated function 00099 class Triangle { 00100 public: 00101 vtkIdType PointIndex[3]; 00102 vtkIdType ReferredByTetra[2]; 00103 double P1X, P1Y; 00104 double P2X, P2Y; 00105 double Denominator; 00106 double A, B, C, D; 00107 Triangle *Next; 00108 }; 00109 00110 // Used to store each intersection for the pixel rays - made 00111 // public because of the templated function 00112 class Intersection { 00113 public: 00114 Triangle *TriPtr; 00115 double Z; 00116 Intersection *Next; 00117 }; 00118 00120 00122 int InTriangle( double x, double y, 00123 Triangle *triPtr ); 00125 00126 00128 double *GetPoints() {return this->Points;} 00129 00131 00132 vtkGetObjectMacro( ViewToWorldMatrix, vtkMatrix4x4 ); 00134 00136 00137 vtkGetVectorMacro( ImageOrigin, int, 2 ); 00139 00141 00142 vtkGetVectorMacro( ImageViewportSize, int, 2 ); 00144 00146 Triangle **GetTetraTriangles () {return this->TetraTriangles;} 00147 00149 Intersection *GetIntersectionList( int x, int y ) { return this->Image[y*this->ImageSize[0] + x]; } 00150 00151 //ETX 00152 00153 protected: 00154 vtkUnstructuredGridBunykRayCastFunction(); 00155 ~vtkUnstructuredGridBunykRayCastFunction(); 00156 00157 // These are cached during the initialize method so that they do not 00158 // need to be passed into subsequent CastRay calls. 00159 vtkRenderer *Renderer; 00160 vtkVolume *Volume; 00161 vtkUnstructuredGridVolumeRayCastMapper *Mapper; 00162 00163 // Computed during the initialize method - if something is 00164 // wrong (no mapper, no volume, no input, etc.) then no rendering 00165 // will actually be performed. 00166 int Valid; 00167 00168 // These are the transformed points 00169 int NumberOfPoints; 00170 double *Points; 00171 00172 // This is the matrix that will take a transformed point back 00173 // to world coordinates 00174 vtkMatrix4x4 *ViewToWorldMatrix; 00175 00176 00177 // This is the intersection list per pixel in the image 00178 Intersection **Image; 00179 00180 // This is the size of the image we are computing (which does 00181 // not need to match the screen size) 00182 int ImageSize[2]; 00183 00184 // Since we may only be computing a subregion of the "full" image, 00185 // this is the origin of the region we are computing. We must 00186 // subtract this origin from any pixel (x,y) locations before 00187 // accessing the pixel in this->Image (which represents only the 00188 // subregion) 00189 int ImageOrigin[2]; 00190 00191 // This is the full size of the image 00192 int ImageViewportSize[2]; 00193 00194 // These are values saved for the building of the TriangleList. Basically 00195 // we need to check if the data has changed in some way. 00196 vtkUnstructuredGrid *SavedTriangleListInput; 00197 vtkTimeStamp SavedTriangleListMTime; 00198 00199 //BTX 00200 // This is a memory intensive algorithm! For each tetra in the 00201 // input data we create up to 4 triangles (we don't create duplicates) 00202 // This is the TriangleList. Then, for each tetra we keep track of 00203 // the pointer to each of its four triangles - this is the 00204 // TetraTriangles. We also keep a duplicate list of points 00205 // (transformed into view space) - these are the Points. 00206 Triangle **TetraTriangles; 00207 vtkIdType TetraTrianglesSize; 00208 00209 Triangle *TriangleList; 00210 00211 // Compute whether a boundary triangle is front facing by 00212 // looking at the fourth point in the tetra to see if it is 00213 // in front (triangle is backfacing) or behind (triangle is 00214 // front facing) the plane containing the triangle. 00215 int IsTriangleFrontFacing( Triangle *triPtr, vtkIdType tetraIndex ); 00216 00217 // The image contains lists of intersections per pixel - we 00218 // need to clear this during the initialization phase for each 00219 // render. 00220 void ClearImage(); 00221 00222 // This is the memory buffer used to build the intersection 00223 // lists. We do our own memory management here because allocating 00224 // a bunch of small elements during rendering is too slow. 00225 Intersection *IntersectionBuffer[VTK_BUNYKRCF_MAX_ARRAYS]; 00226 int IntersectionBufferCount[VTK_BUNYKRCF_MAX_ARRAYS]; 00227 00228 // This method replaces new for creating a new element - it 00229 // returns one from the big block already allocated (it 00230 // allocates another big block if necessary) 00231 void *NewIntersection(); 00232 00233 // This method is used during the initialization process to 00234 // check the validity of the objects - missing information 00235 // such as the volume, renderer, mapper, etc. will be flagged 00236 // and reported. 00237 int CheckValidity(vtkRenderer *ren, 00238 vtkVolume *vol); 00239 00240 // This method is used during the initialization process to 00241 // transform the points to view coordinates 00242 void TransformPoints(); 00243 00244 // This method is used during the initialization process to 00245 // create the list of triangles if the data has changed 00246 void UpdateTriangleList(); 00247 00248 // This method is used during the initialization process to 00249 // update the view dependent information in the triangle list 00250 void ComputeViewDependentInfo(); 00251 00252 // This method is used during the initialization process to 00253 // compute the intersections for each pixel with the boundary 00254 // triangles. 00255 void ComputePixelIntersections(); 00256 00257 //ETX 00258 00259 private: 00260 vtkUnstructuredGridBunykRayCastFunction(const vtkUnstructuredGridBunykRayCastFunction&); // Not implemented. 00261 void operator=(const vtkUnstructuredGridBunykRayCastFunction&); // Not implemented. 00262 }; 00263 00264 #endif 00265 00266 00267 00268 00269 00270 00271