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

Rendering/vtkUnstructuredGridBunykRayCastFunction.h

Go to the documentation of this file.
00001 /*=========================================================================
00002 
00003   Program:   Visualization Toolkit
00004   Module:    $RCSfile: vtkUnstructuredGridBunykRayCastFunction.h,v $
00005   Language:  C++
00006 
00007   Copyright (c) 1993-2002 Ken Martin, Will Schroeder, Bill Lorensen 
00008   All rights reserved.
00009   See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
00010 
00011      This software is distributed WITHOUT ANY WARRANTY; without even 
00012      the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 
00013      PURPOSE.  See the above copyright notice for more information.
00014 
00015 =========================================================================*/
00016 
00063 #ifndef __vtkUnstructuredGridBunykRayCastFunction_h
00064 #define __vtkUnstructuredGridBunykRayCastFunction_h
00065 
00066 #include "vtkUnstructuredGridVolumeRayCastFunction.h"
00067 
00068 class vtkRenderer;
00069 class vtkVolume;
00070 class vtkUnstructuredGridVolumeRayCastMapper;
00071 class vtkMatrix4x4;
00072 class vtkPiecewiseFunction;
00073 class vtkColorTransferFunction;
00074 class vtkUnstructuredGrid;
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 1000
00080 #define VTK_BUNYKRCF_ARRAY_SIZE 10000
00081 
00082 class VTK_RENDERING_EXPORT vtkUnstructuredGridBunykRayCastFunction : public vtkUnstructuredGridVolumeRayCastFunction
00083 { 
00084 public:
00085   static vtkUnstructuredGridBunykRayCastFunction *New();
00086   vtkTypeRevisionMacro(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   
00097   virtual void CastRay( int x, int y, double bounds[2], float color[4] );
00098 
00099   // Used to store each triangle - made public because of the 
00100   // templated function
00101   class Triangle {
00102   public:
00103     int       PointIndex[3];
00104     int       ReferredByTetra[2];
00105     double    P1X, P1Y;
00106     double    P2X, P2Y;
00107     double    Denominator;
00108     double    A, B, C, D;
00109     Triangle *Next; 
00110   };
00111   
00112   // Used to store each intersection for the pixel rays - made
00113   // public because of the templated function
00114   class Intersection {
00115   public:
00116     Triangle     *TriPtr;
00117     double        Z;
00118     Intersection *Next;
00119   };
00120   
00122 
00124   int  InTriangle( double x, double y,
00125                    Triangle *triPtr );
00127   
00128 
00130   double *GetPoints() {return this->Points;}
00131   
00133 
00134   vtkGetObjectMacro( ViewToWorldMatrix, vtkMatrix4x4 );
00136   
00138 
00139   vtkGetVectorMacro( ImageOrigin, int, 2 );
00141 
00143 
00144   vtkGetVectorMacro( ImageViewportSize, int, 2 );
00146 
00148   Triangle **GetTetraTriangles () {return this->TetraTriangles;}
00149   
00151   Intersection *GetIntersectionList( int x, int y ) { return this->Image[y*this->ImageSize[0] + x]; }
00152 
00153   double **GetColorTable() {return this->ColorTable;}
00154   double *GetColorTableShift() {return this->ColorTableShift;}
00155   double *GetColorTableScale() {return this->ColorTableScale;}
00156   
00157 //ETX
00158   
00159 protected:
00160   vtkUnstructuredGridBunykRayCastFunction();
00161   ~vtkUnstructuredGridBunykRayCastFunction();
00162 
00163   // These are cached during the initialize method so that they do not
00164   // need to be passed into subsequent CastRay calls.
00165   vtkRenderer                             *Renderer;
00166   vtkVolume                               *Volume;
00167   vtkUnstructuredGridVolumeRayCastMapper  *Mapper;
00168   void                                    *Scalars;
00169   int                                      ScalarType;
00170   int                                      NumberOfComponents;
00171   
00172   // Computed during the initialize method - if something is
00173   // wrong (no mapper, no volume, no input, etc.) then no rendering
00174   // will actually be performed.
00175   int                                      Valid;
00176 
00177   // These are the transformed points
00178   int      NumberOfPoints;
00179   double  *Points;
00180 
00181   // This is the matrix that will take a transformed point back
00182   // to world coordinates
00183   vtkMatrix4x4 *ViewToWorldMatrix;
00184 
00185 
00186   // This is the intersection list per pixel in the image
00187   Intersection    **Image;
00188   
00189   // This is the size of the image we are computing (which does
00190   // not need to match the screen size)
00191   int               ImageSize[2];
00192   
00193   // Since we may only be computing a subregion of the "full" image,
00194   // this is the origin of the region we are computing. We must
00195   // subtract this origin from any pixel (x,y) locations before 
00196   // accessing the pixel in this->Image (which represents only the
00197   // subregion)
00198   int               ImageOrigin[2];
00199   
00200   // This is the full size of the image
00201   int               ImageViewportSize[2];
00202 
00203   // This table holds the mapping from scalar value to color/opacity.
00204   // There is one table per component.
00205   double         **ColorTable;
00206   int             *ColorTableSize;
00207   
00208   // This is the shift/scale that needs to be applied to the scalar value
00209   // to map it into the (integer) range of the color table. There is one
00210   // shift/scale value per component.
00211   double           *ColorTableShift;
00212   double           *ColorTableScale;
00213   
00214   // These are some values saved during the computation of the ColorTable.
00215   // These saved values help us determine if anything changed since the
00216   // last time the functions were updated - if so we need to recreate them,
00217   // otherwise we can just keep using the current ones.
00218   vtkColorTransferFunction **SavedRGBFunction;
00219   vtkPiecewiseFunction     **SavedGrayFunction;
00220   vtkPiecewiseFunction     **SavedScalarOpacityFunction;
00221   int                       *SavedColorChannels;
00222   double                    *SavedScalarOpacityDistance;
00223   double                     SavedSampleDistance;
00224   int                        SavedBlendMode;
00225   int                        SavedNumberOfComponents;
00226   vtkUnstructuredGrid       *SavedParametersInput;
00227   vtkTimeStamp               SavedParametersMTime;
00228 
00229   // These are values saved for the building of the TriangleList. Basically
00230   // we need to check if the data has changed in some way.
00231   vtkUnstructuredGrid       *SavedTriangleListInput;
00232   vtkTimeStamp               SavedTriangleListMTime;
00233   
00234   // The sample distance is computed when building the triangle
00235   // structure as the average length of a side of a triangle
00236   double                     SampleDistance;
00237   
00238 //BTX  
00239   // This is a memory intensive algorithm! For each tetra in the 
00240   // input data we create up to 4 triangles (we don't create duplicates)
00241   // This is the TriangleList. Then, for each tetra we keep track of
00242   // the pointer to each of its four triangles - this is the 
00243   // TetraTriangles. We also keep a duplicate list of points 
00244   // (transformed into view space) - these are the Points. 
00245   Triangle **TetraTriangles;
00246   Triangle  *TriangleList;
00247   
00248   // Compute whether a boundary triangle is front facing by
00249   // looking at the fourth point in the tetra to see if it is
00250   // in front (triangle is backfacing) or behind (triangle is
00251   // front facing) the plane containing the triangle.
00252   int  IsTriangleFrontFacing( Triangle *triPtr, int tetraIndex );
00253   
00254   // The image contains lists of intersections per pixel - we
00255   // need to clear this during the initialization phase for each
00256   // render.
00257   void ClearImage();
00258   
00259   // This is the memory buffer used to build the intersection
00260   // lists. We do our own memory management here because allocating
00261   // a bunch of small elements during rendering is too slow.
00262   Intersection *IntersectionBuffer[VTK_BUNYKRCF_MAX_ARRAYS];
00263   int           IntersectionBufferCount[VTK_BUNYKRCF_MAX_ARRAYS];
00264   
00265   // This method replaces new for creating a new element - it
00266   // returns one from the big block already allocated (it 
00267   // allocates another big block if necessary)
00268   void         *NewIntersection();  
00269 
00270   // This method is used during the initialization process to
00271   // check the validity of the objects - missing information
00272   // such as the volume, renderer, mapper, etc. will be flagged
00273   // and reported.
00274   int          CheckValidity(vtkRenderer *ren,
00275                              vtkVolume   *vol);
00276   
00277   // This method is used during the initialization process to
00278   // transform the points to view coordinates
00279   void          TransformPoints();
00280 
00281   // This method is used during the initialization process to 
00282   // create the list of triangles if the data has changed
00283   void          UpdateTriangleList();
00284   
00285   // This method is used during the initialization process to
00286   // update the view dependent information in the triangle list
00287   void          ComputeViewDependentInfo();
00288   
00289   // This method is used during the initialization process to
00290   // compute the intersections for each pixel with the boundary
00291   // triangles.
00292   void          ComputePixelIntersections();
00293 
00294   // This method is used during the initialization process to
00295   // update the arrays holding the mapping from scalar value
00296   // to color/opacity
00297   void          UpdateColorTable();
00298 
00299   // This method is used to change the number of components
00300   // for which information is being cached. This will delete
00301   // the color table and all saved arrays for computing it, 
00302   // and will reconstruct them with the right size.
00303   void          SetNumberOfComponents( int num );
00304   
00305 //ETX
00306   
00307 private:
00308   vtkUnstructuredGridBunykRayCastFunction(const vtkUnstructuredGridBunykRayCastFunction&);  // Not implemented.
00309   void operator=(const vtkUnstructuredGridBunykRayCastFunction&);  // Not implemented.
00310 };
00311 
00312 #endif
00313 
00314 
00315 
00316 
00317 
00318 
00319