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

Rendering/vtkVolumeRayCastMapper.h

Go to the documentation of this file.
00001 /*=========================================================================
00002 
00003   Program:   Visualization Toolkit
00004   Module:    $RCSfile: vtkVolumeRayCastMapper.h,v $
00005   Language:  C++
00006 
00007 
00008 Copyright (c) 1993-2001 Ken Martin, Will Schroeder, Bill Lorensen 
00009 All rights reserved.
00010 
00011 Redistribution and use in source and binary forms, with or without
00012 modification, are permitted provided that the following conditions are met:
00013 
00014  * Redistributions of source code must retain the above copyright notice,
00015    this list of conditions and the following disclaimer.
00016 
00017  * Redistributions in binary form must reproduce the above copyright notice,
00018    this list of conditions and the following disclaimer in the documentation
00019    and/or other materials provided with the distribution.
00020 
00021  * Neither name of Ken Martin, Will Schroeder, or Bill Lorensen nor the names
00022    of any contributors may be used to endorse or promote products derived
00023    from this software without specific prior written permission.
00024 
00025  * Modified source versions must be plainly marked as such, and must not be
00026    misrepresented as being the original software.
00027 
00028 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS''
00029 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00030 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
00031 ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE FOR
00032 ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
00033 DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
00034 SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
00035 CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
00036 OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
00037 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00038 
00039 =========================================================================*/
00040 
00059 #ifndef __vtkVolumeRayCastMapper_h
00060 #define __vtkVolumeRayCastMapper_h
00061 
00062 #include "vtkVolumeMapper.h"
00063 #include "vtkMultiThreader.h"
00064 #include "vtkVolumeRayCastFunction.h"
00065 #include "vtkEncodedGradientShader.h"
00066 #include "vtkEncodedGradientEstimator.h"
00067 
00068 class  vtkRenderer;
00069 class  vtkVolume;
00070 class  vtkVolumeTransform;
00071 class  vtkPlaneCollection;
00072 class  vtkPoints;
00073 class  vtkCellArray;
00074 class  vtkTCoords;
00075 class  vtkPolyData;
00076 class  vtkTexture;
00077 class  vtkActor;
00078 class  vtkPolyDataMapper;
00079 class  vtkMultiThreader;
00080 class  vtkTimerLog;
00081 
00082 // Macro for floor of x
00083 #define vtkFloorFuncMacro(x)   (((x) < 0.0)?((int)((x)-1.0)):((int)(x)))
00084 
00085 // Macro for rounding x
00086 #define vtkRoundFuncMacro(x)   (int)((x)+0.5)
00087 
00088 // Macro for tri-linear interpolation - do four linear interpolations on
00089 // edges, two linear interpolations between pairs of edges, then a final
00090 // interpolation between faces
00091 #define vtkTrilinFuncMacro(v,x,y,z,a,b,c,d,e,f,g,h)         \
00092         t00 =   a + (x)*(b-a);      \
00093         t01 =   c + (x)*(d-c);      \
00094         t10 =   e + (x)*(f-e);      \
00095         t11 =   g + (x)*(h-g);      \
00096         t0  = t00 + (y)*(t01-t00);  \
00097         t1  = t10 + (y)*(t11-t10);  \
00098         v   =  t0 + (z)*(t1-t0);
00099 
00100 class VTK_RENDERING_EXPORT vtkVolumeRayCastMapper : public vtkVolumeMapper
00101 {
00102 public:
00103   static vtkVolumeRayCastMapper *New();
00104   vtkTypeMacro(vtkVolumeRayCastMapper,vtkVolumeMapper);
00105   void PrintSelf( ostream& os, vtkIndent index );
00106 
00108 
00111   vtkSetMacro( SampleDistance, float );
00112   vtkGetMacro( SampleDistance, float );
00114 
00116 
00118   vtkSetObjectMacro( VolumeRayCastFunction, vtkVolumeRayCastFunction );
00119   vtkGetObjectMacro( VolumeRayCastFunction, vtkVolumeRayCastFunction );
00121 
00123 
00124   void SetGradientEstimator( vtkEncodedGradientEstimator *gradest );
00125   vtkGetObjectMacro( GradientEstimator, vtkEncodedGradientEstimator );
00127 
00129 
00130   vtkGetObjectMacro( GradientShader, vtkEncodedGradientShader );
00132 
00134 
00137   vtkSetClampMacro( ImageSampleDistance, float, 0.1, 100.0 );
00138   vtkGetMacro( ImageSampleDistance, float );
00140 
00142 
00144   vtkSetClampMacro( MinimumImageSampleDistance, float, 0.1, 100.0 );
00145   vtkGetMacro( MinimumImageSampleDistance, float );
00147 
00149 
00151   vtkSetClampMacro( MaximumImageSampleDistance, float, 0.1, 100.0 );
00152   vtkGetMacro( MaximumImageSampleDistance, float );
00154 
00156 
00159   vtkSetClampMacro( AutoAdjustSampleDistances, int, 0, 1 );
00160   vtkGetMacro( AutoAdjustSampleDistances, int );
00161   vtkBooleanMacro( AutoAdjustSampleDistances, int );
00163   
00165 
00167   void SetNumberOfThreads( int num );
00168   vtkGetMacro( NumberOfThreads, int );
00170 
00172 
00174   vtkSetClampMacro( IntermixIntersectingGeometry, int, 0, 1 );
00175   vtkGetMacro( IntermixIntersectingGeometry, int );
00176   vtkBooleanMacro( IntermixIntersectingGeometry, int );
00178   
00179 //BTX
00182   void Render( vtkRenderer *, vtkVolume * );
00183 
00188   void ReleaseGraphicsResources(vtkWindow *);
00189 
00192   float GetZeroOpacityThreshold( vtkVolume *vol );
00193 
00195 
00197   virtual float GetGradientMagnitudeScale();
00198   virtual float GetGradientMagnitudeBias();
00200   
00201 //ETX
00202 
00203 protected:
00204   vtkVolumeRayCastMapper();
00205   ~vtkVolumeRayCastMapper();
00206 
00207   vtkVolumeRayCastFunction     *VolumeRayCastFunction;
00208   vtkEncodedGradientEstimator  *GradientEstimator;
00209   vtkEncodedGradientShader     *GradientShader;
00210 
00211   // The distance between sample points along the ray
00212   float                        SampleDistance;
00213   float                        ImageSampleDistance;
00214   float                        MinimumImageSampleDistance;
00215   float                        MaximumImageSampleDistance;
00216   int                          AutoAdjustSampleDistances;
00217   
00218   float                        WorldSampleDistance;
00219   int                          ScalarDataType;
00220   void                         *ScalarDataPointer;
00221 
00222   void                         UpdateShadingTables( vtkRenderer *ren, 
00223                                                     vtkVolume *vol );
00224 
00225   void ComputeMatrices( vtkImageData *data, vtkVolume *vol );
00226   virtual void RenderTexture( vtkVolume *vol, vtkRenderer *ren)=0;
00227   int ComputeRowBounds( vtkVolume *vol, vtkRenderer *ren );
00228   
00229   friend VTK_THREAD_RETURN_TYPE VolumeRayCastMapper_CastRays( void *arg );
00230 
00231   vtkMultiThreader  *Threader;
00232   int               NumberOfThreads;
00233 
00234   vtkMatrix4x4 *PerspectiveMatrix;
00235   vtkMatrix4x4 *ViewToWorldMatrix;
00236   vtkMatrix4x4 *ViewToVoxelsMatrix;
00237   vtkMatrix4x4 *VoxelsToViewMatrix;
00238   vtkMatrix4x4 *WorldToVoxelsMatrix;
00239   vtkMatrix4x4 *VoxelsToWorldMatrix;
00240   
00241   // This is how big the image would be if it covered the entire viewport
00242   int            ImageViewportSize[2];
00243   
00244   // This is how big the allocated memory for image is. This may be bigger
00245   // or smaller than ImageFullSize - it will be bigger if necessary to 
00246   // ensure a power of 2, it will be smaller if the volume only covers a
00247   // small region of the viewport
00248   int            ImageMemorySize[2];
00249   
00250   // This is the size of subregion in ImageSize image that we are using for
00251   // the current image. Since ImageSize is a power of 2, there is likely
00252   // wasted space in it. This number will be used for things such as clearing
00253   // the image if necessary.
00254   int            ImageInUseSize[2];
00255   
00256   // This is the location in ImageFullSize image where our ImageSize image
00257   // is located.
00258   int            ImageOrigin[2];
00259   
00260   // This is the allocated image
00261   unsigned char *Image;
00262   
00263   int  *RowBounds;
00264   int  *OldRowBounds;
00265 
00266   float        *RenderTimeTable;
00267   vtkVolume   **RenderVolumeTable;
00268   vtkRenderer **RenderRendererTable;
00269   int           RenderTableSize;
00270   int           RenderTableEntries;
00271 
00272   void StoreRenderTime( vtkRenderer *ren, vtkVolume *vol, float t );
00273   float RetrieveRenderTime( vtkRenderer *ren, vtkVolume *vol );
00274 
00275   int           IntermixIntersectingGeometry;
00276 
00277   float        *ZBuffer;
00278   int           ZBufferSize[2];
00279   int           ZBufferOrigin[2];
00280 
00281   float         MinimumViewDistance;
00282   
00283   int           ClipRayAgainstVolume( VTKVRCDynamicInfo *dynamicInfo,
00284                                       float bounds[6] );
00285 
00286   void          InitializeClippingPlanes( VTKVRCStaticInfo *staticInfo,
00287                                           vtkPlaneCollection *planes );
00288 
00289   int           ClipRayAgainstClippingPlanes( VTKVRCDynamicInfo *dynamicInfo,
00290                                               VTKVRCStaticInfo *staticInfo);
00291   
00292   // Get the ZBuffer value corresponding to location (x,y) where (x,y)
00293   // are indexing into the ImageInUse image. This must be converted to
00294   // the zbuffer image coordinates. Nearest neighbor value is returned.
00295   float         GetZBufferValue( int x, int y );
00296 
00297 private:
00298   vtkVolumeRayCastMapper(const vtkVolumeRayCastMapper&);  // Not implemented.
00299   void operator=(const vtkVolumeRayCastMapper&);  // Not implemented.
00300 };
00301 
00302 #endif
00303 

Generated on Thu Mar 28 14:19:34 2002 for VTK by doxygen1.2.11.1 written by Dimitri van Heesch, © 1997-2001