Main Page | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Class Members | File Members | Related Pages

vtkUnstructuredGridBunykRayCastFunction.h

Go to the documentation of this file.
00001 /*=========================================================================
00002 
00003   Program:   Visualization Toolkit
00004   Module:    $RCSfile: vtkUnstructuredGridBunykRayCastFunction.h,v $
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   vtkTypeRevisionMacro(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   Triangle  *TriangleList;
00208 
00209   // Compute whether a boundary triangle is front facing by
00210   // looking at the fourth point in the tetra to see if it is
00211   // in front (triangle is backfacing) or behind (triangle is
00212   // front facing) the plane containing the triangle.
00213   int  IsTriangleFrontFacing( Triangle *triPtr, vtkIdType tetraIndex );
00214   
00215   // The image contains lists of intersections per pixel - we
00216   // need to clear this during the initialization phase for each
00217   // render.
00218   void ClearImage();
00219   
00220   // This is the memory buffer used to build the intersection
00221   // lists. We do our own memory management here because allocating
00222   // a bunch of small elements during rendering is too slow.
00223   Intersection *IntersectionBuffer[VTK_BUNYKRCF_MAX_ARRAYS];
00224   int           IntersectionBufferCount[VTK_BUNYKRCF_MAX_ARRAYS];
00225   
00226   // This method replaces new for creating a new element - it
00227   // returns one from the big block already allocated (it 
00228   // allocates another big block if necessary)
00229   void         *NewIntersection();  
00230 
00231   // This method is used during the initialization process to
00232   // check the validity of the objects - missing information
00233   // such as the volume, renderer, mapper, etc. will be flagged
00234   // and reported.
00235   int          CheckValidity(vtkRenderer *ren,
00236                              vtkVolume   *vol);
00237   
00238   // This method is used during the initialization process to
00239   // transform the points to view coordinates
00240   void          TransformPoints();
00241 
00242   // This method is used during the initialization process to 
00243   // create the list of triangles if the data has changed
00244   void          UpdateTriangleList();
00245   
00246   // This method is used during the initialization process to
00247   // update the view dependent information in the triangle list
00248   void          ComputeViewDependentInfo();
00249   
00250   // This method is used during the initialization process to
00251   // compute the intersections for each pixel with the boundary
00252   // triangles.
00253   void          ComputePixelIntersections();
00254   
00255 //ETX
00256   
00257 private:
00258   vtkUnstructuredGridBunykRayCastFunction(const vtkUnstructuredGridBunykRayCastFunction&);  // Not implemented.
00259   void operator=(const vtkUnstructuredGridBunykRayCastFunction&);  // Not implemented.
00260 };
00261 
00262 #endif
00263 
00264 
00265 
00266 
00267 
00268 
00269 

Generated on Mon Jan 21 23:07:37 2008 for VTK by  doxygen 1.4.3-20050530