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