vtkFixedPointRayCastImage.h 7.76 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
/*=========================================================================

  Program:   Visualization Toolkit
  Module:    vtkFixedPointRayCastImage.h

  Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
  All rights reserved.
  See Copyright.txt or http://www.kitware.com/Copyright.htm for details.

     This software is distributed WITHOUT ANY WARRANTY; without even
     the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
     PURPOSE.  See the above copyright notice for more information.

=========================================================================*/

// .NAME vtkFixedPointRayCastImage - helper class for a ray cast image
// .SECTION Description
// This is a helper class for storing the ray cast image including the
// underlying data and the size of the image. This class is not intended
20
// to be used directly - just as an internal class in the
21
// vtkFixedPointVolumeRayCastMapper so that multiple mappers can share
22 23
// the same image. This class also stored the ZBuffer (if necessary due
// to intermixed geometry). Perhaps this class could be generalized
24 25 26 27 28 29
// in the future to be used for other ray cast methods other than the
// fixed point method.

// .SECTION see also
// vtkFixedPointVolumeRayCastMapper

30 31
#ifndef vtkFixedPointRayCastImage_h
#define vtkFixedPointRayCastImage_h
32

33
#include "vtkRenderingVolumeModule.h" // For export macro
34 35
#include "vtkObject.h"

36
class VTKRENDERINGVOLUME_EXPORT vtkFixedPointRayCastImage : public vtkObject
37 38 39
{
public:
  static vtkFixedPointRayCastImage *New();
40
  vtkTypeMacro(vtkFixedPointRayCastImage,vtkObject);
41 42 43 44 45 46 47
  virtual void PrintSelf(ostream& os, vtkIndent indent);

  // Description:
  // Get the internal storage for the image. It is a pointer to
  // unsigned short with four components (RGBA) per pixel. This
  // memory is allocated when the AllocateImage method is called.
  unsigned short *GetImage() {return this->Image;}
48

49 50 51 52 53 54 55 56 57 58 59 60 61
  // Description:
  // Set / Get the ImageViewportSize. This is the size of the
  // whole viewport in pixels.
  vtkSetVector2Macro( ImageViewportSize, int );
  vtkGetVectorMacro(  ImageViewportSize, int, 2 );

  // Description:
  // Set / Get the ImageMemorySize. This is the size in pixels
  // of the Image ivar. This will be a power of two in order
  // to ensure that the texture can be rendered by graphics
  // hardware that requires power of two textures.
  vtkSetVector2Macro( ImageMemorySize, int );
  vtkGetVectorMacro(  ImageMemorySize, int, 2 );
62

63 64 65
  // Description:
  // Set / Get the size of the image we are actually using. As
  // long as the memory size is big enough, but not too big,
66
  // we won't bother deleting and re-allocated, we'll just
67 68 69 70
  // continue to use the memory size we have. This size will
  // always be equal to or less than the ImageMemorySize.
  vtkSetVector2Macro( ImageInUseSize, int );
  vtkGetVectorMacro(  ImageInUseSize, int, 2 );
71

72
  // Description:
73
  // Set / Get the origin of the image. This is the starting
74 75
  // pixel within the whole viewport that our Image starts on.
  // That is, we could be generating just a subregion of the
76
  // whole viewport due to the fact that our volume occupies
77 78 79 80 81
  // only a portion of the viewport. The Image pixels will
  // start from this location.
  vtkSetVector2Macro( ImageOrigin, int );
  vtkGetVectorMacro(  ImageOrigin, int, 2 );

82
  // Description:
83
  // Set / Get the ImageSampleDistance that will be used for
84 85 86 87 88
  // rendering. This is a copy of the value stored in the
  // mapper. It is stored here for sharing between all mappers
  // that are participating in the creation of this image.
  vtkSetMacro( ImageSampleDistance, float );
  vtkGetMacro( ImageSampleDistance, float );
89

90 91 92 93 94
  // Description:
  // Call this method once the ImageMemorySize has been set
  // the allocate the image. If an image already exists,
  // it will be deleted first.
  void AllocateImage();
95

96 97 98
  // Description:
  // Clear the image to (0,0,0,0) for each pixel.
  void ClearImage();
99

100 101 102 103 104 105 106 107
  // Description:
  // Set / Get the size of the ZBuffer in pixels. The zbuffer will
  // be captured for the region of the screen covered by the
  // ImageInUseSize image. However, due to subsampling, the size
  // of the ImageInUseSize image may be smaller than this ZBuffer
  // image which will be captured at screen resolution.
  vtkSetVector2Macro( ZBufferSize, int );
  vtkGetVectorMacro(  ZBufferSize, int, 2 );
108

109 110 111 112 113
  // Description:
  // Set / Get the origin of the ZBuffer. This is the distance
  // from the lower left corner of the viewport where the ZBuffer
  // started (multiply the ImageOrigin by the ImageSampleDistance)
  // This is the pixel location on the full resolution viewport
114 115
  // where the ZBuffer capture will start. These values are used
  // to convert the (x,y) pixel location within the ImageInUseSize
116 117 118 119 120 121 122 123
  // image into a ZBuffer location.
  vtkSetVector2Macro( ZBufferOrigin, int );
  vtkGetVectorMacro(  ZBufferOrigin, int, 2 );

  // Description:
  // The UseZBuffer flag indicates whether the ZBuffer is in use.
  // The ZBuffer is captured and used when IntermixIntersectingGeometry
  // is on in the mapper, and when there are props that have been
124
  // rendered before the current volume.
125 126 127
  vtkSetClampMacro( UseZBuffer, int, 0, 1 );
  vtkGetMacro( UseZBuffer, int );
  vtkBooleanMacro( UseZBuffer, int );
128

129 130 131 132 133
  // Description:
  // Get the ZBuffer value corresponding to location (x,y) where (x,y)
  // are indexing into the ImageInUse image. This must be converted to
  // the zbuffer image coordinates. Nearest neighbor value is returned.
  // If UseZBuffer is off, then 1.0 is always returned.
134 135
  float         GetZBufferValue( int x, int y );

136 137 138 139 140
  // Description:
  // Get the ZBuffer. The size of the ZBuffer should be specific
  // with SetZBufferSize, and AllocateZBuffer method should be called
  // before getting the ZBuffer.
  float *GetZBuffer() {return this->ZBuffer;}
141

142 143 144
  // Descipriotn:
  // Allocate the space for the ZBuffer according to the size.
  void AllocateZBuffer();
145

146 147 148
protected:
  vtkFixedPointRayCastImage();
  ~vtkFixedPointRayCastImage();
149

150 151
  // This is how big the image would be if it covered the entire viewport
  int             ImageViewportSize[2];
152

153
  // This is how big the allocated memory for image is. This may be bigger
154
  // or smaller than ImageFullSize - it will be bigger if necessary to
155 156 157
  // ensure a power of 2, it will be smaller if the volume only covers a
  // small region of the viewport
  int             ImageMemorySize[2];
158

159 160 161 162 163
  // This is the size of subregion in ImageSize image that we are using for
  // the current image. Since ImageSize is a power of 2, there is likely
  // wasted space in it. This number will be used for things such as clearing
  // the image if necessary.
  int             ImageInUseSize[2];
164

165 166 167
  // This is the location in ImageFullSize image where our ImageSize image
  // is located.
  int             ImageOrigin[2];
168 169 170 171

  // This is a copy of the ImageSampleDistance from the mapper - copied here
  // in order to share among all mappers contributing to this image
  float           ImageSampleDistance;
172

173
  // This is the allocated image
174
  unsigned short *Image;
175

176 177
  // This is the size of the zbuffer in pixels
  int             ZBufferSize[2];
178

179
  // This is the size of the memory for the zbuffer - this can be
180
  // bigger than the size of the zbuffer since we will allocate enough
181 182
  // space for the whole viewport to avoid re-allocating over and over
  int             ZBufferMemorySize;
183

184 185 186 187 188 189
  // This is the distance from the lower left corner of the viewport
  // where the ZBuffer starts
  int             ZBufferOrigin[2];

  // This is the flag that indicate whether the ZBuffer is in use
  int             UseZBuffer;
190

191 192
  // This is the actual ZBuffer data in floats
  float          *ZBuffer;
193 194


195 196 197 198 199 200 201 202
private:
  vtkFixedPointRayCastImage(const vtkFixedPointRayCastImage&);  // Not implemented.
  void operator=(const vtkFixedPointRayCastImage&);  // Not implemented.
};

#endif


203 204 205