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