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

  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.

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

16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
/**
 * @class   vtkFixedPointRayCastImage
 * @brief   helper class for a ray cast image
 *
 * 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
 * to be used directly - just as an internal class in the
 * vtkFixedPointVolumeRayCastMapper so that multiple mappers can share
 * the same image. This class also stored the ZBuffer (if necessary due
 * to intermixed geometry). Perhaps this class could be generalized
 * in the future to be used for other ray cast methods other than the
 * fixed point method.
 *
 * @sa
 * vtkFixedPointVolumeRayCastMapper
31
 */
32

33 34
#ifndef vtkFixedPointRayCastImage_h
#define vtkFixedPointRayCastImage_h
35 36

#include "vtkObject.h"
37
#include "vtkRenderingVolumeModule.h" // For export macro
38

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

46 47 48 49 50
  /**
   * 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.
   */
51
  unsigned short* GetImage() { return this->Image; }
52

53 54 55 56 57
  //@{
  /**
   * Set / Get the ImageViewportSize. This is the size of the
   * whole viewport in pixels.
   */
58 59
  vtkSetVector2Macro(ImageViewportSize, int);
  vtkGetVectorMacro(ImageViewportSize, int, 2);
60 61 62 63 64 65 66 67 68
  //@}

  //@{
  /**
   * 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.
   */
69 70
  vtkSetVector2Macro(ImageMemorySize, int);
  vtkGetVectorMacro(ImageMemorySize, int, 2);
71 72 73 74 75 76 77 78 79 80
  //@}

  //@{
  /**
   * Set / Get the size of the image we are actually using. As
   * long as the memory size is big enough, but not too big,
   * we won't bother deleting and re-allocated, we'll just
   * continue to use the memory size we have. This size will
   * always be equal to or less than the ImageMemorySize.
   */
81 82
  vtkSetVector2Macro(ImageInUseSize, int);
  vtkGetVectorMacro(ImageInUseSize, int, 2);
83 84 85 86 87 88 89 90 91 92 93
  //@}

  //@{
  /**
   * Set / Get the origin of the image. This is the starting
   * pixel within the whole viewport that our Image starts on.
   * That is, we could be generating just a subregion of the
   * whole viewport due to the fact that our volume occupies
   * only a portion of the viewport. The Image pixels will
   * start from this location.
   */
94 95
  vtkSetVector2Macro(ImageOrigin, int);
  vtkGetVectorMacro(ImageOrigin, int, 2);
96 97 98 99 100 101 102 103 104
  //@}

  //@{
  /**
   * Set / Get the ImageSampleDistance that will be used for
   * 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.
   */
105 106
  vtkSetMacro(ImageSampleDistance, float);
  vtkGetMacro(ImageSampleDistance, float);
107
  //@}
108

109 110 111 112 113
  /**
   * Call this method once the ImageMemorySize has been set
   * the allocate the image. If an image already exists,
   * it will be deleted first.
   */
114
  void AllocateImage();
115

116 117 118
  /**
   * Clear the image to (0,0,0,0) for each pixel.
   */
119
  void ClearImage();
120

121 122 123 124 125 126 127 128
  //@{
  /**
   * 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.
   */
129 130
  vtkSetVector2Macro(ZBufferSize, int);
  vtkGetVectorMacro(ZBufferSize, int, 2);
131 132 133 134 135 136 137 138 139 140 141 142
  //@}

  //@{
  /**
   * 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
   * where the ZBuffer capture will start. These values are used
   * to convert the (x,y) pixel location within the ImageInUseSize
   * image into a ZBuffer location.
   */
143 144
  vtkSetVector2Macro(ZBufferOrigin, int);
  vtkGetVectorMacro(ZBufferOrigin, int, 2);
145 146 147 148 149 150 151 152 153
  //@}

  //@{
  /**
   * 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
   * rendered before the current volume.
   */
154 155 156
  vtkSetClampMacro(UseZBuffer, vtkTypeBool, 0, 1);
  vtkGetMacro(UseZBuffer, vtkTypeBool);
  vtkBooleanMacro(UseZBuffer, vtkTypeBool);
157 158 159 160 161 162 163 164
  //@}

  /**
   * 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.
   */
165
  float GetZBufferValue(int x, int y);
166

167 168 169 170 171
  /**
   * Get the ZBuffer. The size of the ZBuffer should be specific
   * with SetZBufferSize, and AllocateZBuffer method should be called
   * before getting the ZBuffer.
   */
172
  float* GetZBuffer() { return this->ZBuffer; }
173

174 175 176
  // Descipriotn:
  // Allocate the space for the ZBuffer according to the size.
  void AllocateZBuffer();
177

178 179
protected:
  vtkFixedPointRayCastImage();
180
  ~vtkFixedPointRayCastImage() override;
181

182
  // This is how big the image would be if it covered the entire viewport
183
  int ImageViewportSize[2];
184

185
  // This is how big the allocated memory for image is. This may be bigger
186
  // or smaller than ImageFullSize - it will be bigger if necessary to
187 188
  // ensure a power of 2, it will be smaller if the volume only covers a
  // small region of the viewport
189
  int ImageMemorySize[2];
190

191 192 193 194
  // 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.
195
  int ImageInUseSize[2];
196

197 198
  // This is the location in ImageFullSize image where our ImageSize image
  // is located.
199
  int ImageOrigin[2];
200 201 202

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

205
  // This is the allocated image
206
  unsigned short* Image;
207

208
  // This is the size of the zbuffer in pixels
209
  int ZBufferSize[2];
210

211
  // This is the size of the memory for the zbuffer - this can be
212
  // bigger than the size of the zbuffer since we will allocate enough
213
  // space for the whole viewport to avoid re-allocating over and over
214
  int ZBufferMemorySize;
215

216 217
  // This is the distance from the lower left corner of the viewport
  // where the ZBuffer starts
218
  int ZBufferOrigin[2];
219 220

  // This is the flag that indicate whether the ZBuffer is in use
221
  vtkTypeBool UseZBuffer;
222

223
  // This is the actual ZBuffer data in floats
224
  float* ZBuffer;
225

226
private:
227 228
  vtkFixedPointRayCastImage(const vtkFixedPointRayCastImage&) = delete;
  void operator=(const vtkFixedPointRayCastImage&) = delete;
229 230 231
};

#endif