VTK
dox/VolumeRendering/vtkUnstructuredGridVolumeZSweepMapper.h
Go to the documentation of this file.
00001 /*=========================================================================
00002 
00003   Program:   Visualization Toolkit
00004   Module:    vtkUnstructuredGridVolumeZSweepMapper.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 =========================================================================*/
00037 #ifndef __vtkUnstructuredGridVolumeZSweepMapper_h
00038 #define __vtkUnstructuredGridVolumeZSweepMapper_h
00039 
00040 #include "vtkUnstructuredGridVolumeMapper.h"
00041 
00042 class vtkRenderer;
00043 class vtkVolume;
00044 class vtkRayCastImageDisplayHelper;
00045 class vtkCell;
00046 class vtkGenericCell;
00047 class vtkIdList;
00048 class vtkPriorityQueue;
00049 class vtkTransform;
00050 class vtkMatrix4x4;
00051 class vtkVolumeProperty;
00052 class vtkDoubleArray;
00053 class vtkUnstructuredGridVolumeRayIntegrator;
00054 class vtkRenderWindow;
00055 
00056 //BTX
00057 // Internal classes
00058 namespace vtkUnstructuredGridVolumeZSweepMapperNamespace
00059 {
00060   class vtkScreenEdge;
00061   class vtkSpan;
00062   class vtkPixelListFrame;
00063   class vtkUseSet;
00064   class vtkVertices;
00065   class vtkSimpleScreenEdge;
00066   class vtkDoubleScreenEdge;
00067   class vtkVertexEntry;
00068   class vtkPixelListEntryMemory;
00069 };
00070 //ETX
00071 
00072 class VTK_VOLUMERENDERING_EXPORT vtkUnstructuredGridVolumeZSweepMapper : public vtkUnstructuredGridVolumeMapper
00073 {
00074 public:
00075   vtkTypeMacro(vtkUnstructuredGridVolumeZSweepMapper,vtkUnstructuredGridVolumeMapper);
00076   void PrintSelf( ostream& os, vtkIndent indent );
00077   
00079   static vtkUnstructuredGridVolumeZSweepMapper *New();
00080   
00082 
00085   vtkSetClampMacro( ImageSampleDistance, float, 0.1f, 100.0f );
00086   vtkGetMacro( ImageSampleDistance, float );
00088 
00090 
00092   vtkSetClampMacro( MinimumImageSampleDistance, float, 0.1f, 100.0f );
00093   vtkGetMacro( MinimumImageSampleDistance, float );
00095 
00097 
00099   vtkSetClampMacro( MaximumImageSampleDistance, float, 0.1f, 100.0f );
00100   vtkGetMacro( MaximumImageSampleDistance, float );
00102 
00104 
00107   vtkSetClampMacro( AutoAdjustSampleDistances, int, 0, 1 );
00108   vtkGetMacro( AutoAdjustSampleDistances, int );
00109   vtkBooleanMacro( AutoAdjustSampleDistances, int );
00111   
00113 
00115   vtkSetClampMacro( IntermixIntersectingGeometry, int, 0, 1 );
00116   vtkGetMacro( IntermixIntersectingGeometry, int );
00117   vtkBooleanMacro( IntermixIntersectingGeometry, int );
00119 
00124   int GetMaxPixelListSize();
00125   
00128   void SetMaxPixelListSize(int size);
00129   
00131 
00133   virtual void SetRayIntegrator(vtkUnstructuredGridVolumeRayIntegrator *ri);
00134   vtkGetObjectMacro(RayIntegrator, vtkUnstructuredGridVolumeRayIntegrator);
00136   
00137 //BTX
00139 
00141   void Render(vtkRenderer *ren,
00142               vtkVolume *vol);
00144   
00145   vtkGetVectorMacro( ImageInUseSize, int, 2 );
00146   vtkGetVectorMacro( ImageOrigin, int, 2 );
00147   vtkGetVectorMacro( ImageViewportSize, int , 2 );
00148 //ETX
00149   
00150 protected:
00151   vtkUnstructuredGridVolumeZSweepMapper();
00152   ~vtkUnstructuredGridVolumeZSweepMapper();
00153   
00155   void BuildUseSets();
00156   
00158 
00160   int ReorderTriangle(vtkIdType v[3],
00161                       vtkIdType w[3]);
00163 
00165 
00168   void ProjectAndSortVertices(vtkRenderer *ren,
00169                               vtkVolume *vol);
00171   
00173   void CreateAndCleanPixelList();
00174   
00177   void MainLoop(vtkRenderWindow *renWin);
00178   
00181   void CompositeFunction(double zTarget);
00182   
00184   unsigned char ColorComponentRealToByte(float color);
00185   
00187   void RasterizeFace(vtkIdType faceIds[3], int externalSide);
00188 
00189 //BTX
00191 
00193   void RasterizeTriangle(
00194             vtkUnstructuredGridVolumeZSweepMapperNamespace::vtkVertexEntry *ve0,
00195             vtkUnstructuredGridVolumeZSweepMapperNamespace::vtkVertexEntry *ve1,
00196             vtkUnstructuredGridVolumeZSweepMapperNamespace::vtkVertexEntry *ve2,
00197             bool exitFace);
00199   
00201 
00203   void RasterizeSpan(int y,
00204            vtkUnstructuredGridVolumeZSweepMapperNamespace::vtkScreenEdge *left,
00205            vtkUnstructuredGridVolumeZSweepMapperNamespace::vtkScreenEdge *right,
00206            bool exitFace);
00208   
00210 
00213   void RasterizeLine(
00214              vtkUnstructuredGridVolumeZSweepMapperNamespace::vtkVertexEntry *v0,
00215              vtkUnstructuredGridVolumeZSweepMapperNamespace::vtkVertexEntry *v1,
00216              bool exitFace);
00217 //ETX
00219   
00220   void StoreRenderTime(vtkRenderer *ren,
00221                        vtkVolume *vol,
00222                        float t);
00223   
00224   float RetrieveRenderTime(vtkRenderer *ren,
00225                            vtkVolume *vol);
00226   
00228 
00229   double GetZBufferValue(int x,
00230                          int y);
00232   
00233   double GetMinimumBoundsDepth(vtkRenderer *ren,
00234                                vtkVolume *vol);
00235   
00238   void AllocateUseSet(vtkIdType size);
00239   
00242   void AllocateVertices(vtkIdType size);
00243   
00245   void SavePixelListFrame();
00246   
00247   int MaxPixelListSize;
00248   
00249   float ImageSampleDistance;
00250   float MinimumImageSampleDistance;
00251   float MaximumImageSampleDistance;
00252   int AutoAdjustSampleDistances;
00253   
00254   vtkRayCastImageDisplayHelper *ImageDisplayHelper;
00255   
00256   // This is how big the image would be if it covered the entire viewport
00257   int ImageViewportSize[2];
00258   
00259   // This is how big the allocated memory for image is. This may be bigger
00260   // or smaller than ImageFullSize - it will be bigger if necessary to 
00261   // ensure a power of 2, it will be smaller if the volume only covers a
00262   // small region of the viewport
00263   int ImageMemorySize[2];
00264   
00265   // This is the size of subregion in ImageSize image that we are using for
00266   // the current image. Since ImageSize is a power of 2, there is likely
00267   // wasted space in it. This number will be used for things such as clearing
00268   // the image if necessary.
00269   int ImageInUseSize[2];
00270   
00271   // This is the location in ImageFullSize image where our ImageSize image
00272   // is located.
00273   int ImageOrigin[2];
00274   
00275   // This is the allocated image
00276   unsigned char *Image;
00277   
00278   // This is the accumulating double RGBA image
00279   float *RealRGBAImage;
00280   
00281   float *RenderTimeTable;
00282   vtkVolume **RenderVolumeTable;
00283   vtkRenderer **RenderRendererTable;
00284   int RenderTableSize;
00285   int RenderTableEntries;
00286   
00287   int IntermixIntersectingGeometry;
00288 
00289   float *ZBuffer;
00290   int ZBufferSize[2];
00291   int ZBufferOrigin[2];
00292   
00293   vtkDataArray *Scalars;
00294   int CellScalars;
00295   
00296   // if use CellScalars, we need to keep track of the
00297   // values on each side of the face and figure out
00298   // if the face is used by two cells (twosided) or one cell.
00299   double FaceScalars[2];
00300   int FaceSide;
00301 
00302 //BTX
00303   vtkUnstructuredGridVolumeZSweepMapperNamespace::vtkSpan *Span;
00304   vtkUnstructuredGridVolumeZSweepMapperNamespace::vtkPixelListFrame *PixelListFrame;
00305   
00306   // Used by BuildUseSets().
00307   vtkGenericCell *Cell;
00308   
00309   vtkUnstructuredGridVolumeZSweepMapperNamespace::vtkUseSet *UseSet;
00310   
00311   vtkPriorityQueue *EventList;
00312   vtkUnstructuredGridVolumeZSweepMapperNamespace::vtkVertices *Vertices;
00313   
00314   vtkTransform *PerspectiveTransform;
00315   vtkMatrix4x4 *PerspectiveMatrix;
00316   
00317   // Used by the main loop
00318   int MaxPixelListSizeReached;
00319   int XBounds[2];
00320   int YBounds[2];
00321   
00322   vtkUnstructuredGridVolumeZSweepMapperNamespace::vtkSimpleScreenEdge *SimpleEdge;
00323   vtkUnstructuredGridVolumeZSweepMapperNamespace::vtkDoubleScreenEdge *DoubleEdge;
00324   
00325   vtkUnstructuredGridVolumeRayIntegrator *RayIntegrator;
00326   vtkUnstructuredGridVolumeRayIntegrator *RealRayIntegrator;
00327   
00328   vtkTimeStamp SavedTriangleListMTime;
00329   
00330   // Used during compositing
00331   vtkDoubleArray *IntersectionLengths;
00332   vtkDoubleArray *NearIntersections;
00333   vtkDoubleArray *FarIntersections;
00334   
00335   // Benchmark
00336   vtkIdType MaxRecordedPixelListSize;
00337 
00338   
00339   vtkUnstructuredGridVolumeZSweepMapperNamespace::vtkPixelListEntryMemory *MemoryManager;
00340 //ETX
00341 private:
00342   vtkUnstructuredGridVolumeZSweepMapper(const vtkUnstructuredGridVolumeZSweepMapper&);  // Not implemented.
00343   void operator=(const vtkUnstructuredGridVolumeZSweepMapper&);  // Not implemented.
00344 };
00345 
00346 #endif