VTK
vtkVolumeTexture.h
Go to the documentation of this file.
1 /*=========================================================================
2 
3  Program: Visualization Toolkit
4  Module: vtkVolumeTexture.h
5 
6  Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
7  All rights reserved.
8  See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
9 
10  This software is distributed WITHOUT ANY WARRANTY; without even
11  the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
12  PURPOSE. See the above copyright notice for more information.
13 
14 =========================================================================*/
15 
66 #ifndef vtkVolumeTexture_h
67 #define vtkVolumeTexture_h
68 #include <map> // For ImageDataBlockMap
69 #include <vector> // For ImageDataBlocks
70 
71 #include "vtkMatrix4x4.h" // For vtkMatrix4
72 #include "vtkNew.h" // For vtkNew
73 #include "vtkObject.h"
74 #include "vtkRenderingVolumeOpenGL2Module.h" // For export macro
75 #include "vtkSmartPointer.h" // For SmartPointer
76 #include "vtkTimeStamp.h" // For UploadTime
77 #include "vtkTuple.h" // For Size6 and Size3
78 
79 
80 class vtkDataArray;
81 class vtkImageData;
82 class vtkVolumeProperty;
83 class vtkRenderer;
84 class vtkTextureObject;
85 class vtkWindow;
86 
87 class VTKRENDERINGVOLUMEOPENGL2_EXPORT vtkVolumeTexture : public vtkObject
88 {
89  typedef vtkTuple<int, 6> Size6;
90  typedef vtkTuple<int, 3> Size3;
91 
92 public:
93  static vtkVolumeTexture* New();
94 
95  struct VolumeBlock
96  {
97  VolumeBlock(vtkImageData* imData, vtkTextureObject* tex, Size3 const& texSize)
98  {
99  // Block extent is stored in vtkImageData
100  ImageData = imData;
101  TextureObject = tex;
102  TextureSize = texSize;
103  TupleIndex = 0;
104 
105  this->Extents[0] = VTK_INT_MAX;
106  this->Extents[1] = VTK_INT_MIN;
107  this->Extents[2] = VTK_INT_MAX;
108  this->Extents[3] = VTK_INT_MIN;
109  this->Extents[4] = VTK_INT_MAX;
110  this->Extents[5] = VTK_INT_MIN;
111  }
112 
119 
120  double CellScale[3];
121  float CellStep[3];
122  double DatasetStepSize[3];
123 
128  double LoadedBounds[6];
129  int Extents[6];
130  };
131 
132  vtkTypeMacro(vtkVolumeTexture, vtkObject);
133  void PrintSelf( ostream& os, vtkIndent indent ) override;
134 
138  void SetPartitions(int const x, int const y, int const z);
140 
148  int const isCell, int const interpolation);
149 
155 
161 
171 
176 
183  static void GetScaleAndBias(const int scalarType, float* scalarRange,
184  float& scale, float& bias);
186 
188  float Scale[4];
189  float Bias[4];
190  float ScalarRange[4][2];
191  float CellSpacing[3];
194 
195  int IsCellData = 0;
197  float AdjustedTexMin[4];
198  float AdjustedTexMax[4];
199 
200 protected:
202  ~vtkVolumeTexture() override;
203 
204 private:
205  vtkVolumeTexture(const vtkVolumeTexture&) = delete;
206  void operator=(const vtkVolumeTexture&) = delete;
207 
212  bool LoadTexture(int const interpolation, VolumeBlock* volBlock);
213 
217  void SplitVolume(vtkImageData* imageData, Size3 const & part);
218 
219  void CreateBlocks(unsigned int const format, unsigned int const internalFormat,
220  int const type);
221 
222  void AdjustExtentForCell(Size6& extent);
223  Size3 ComputeBlockSize(int* extent);
224 
229  void SelectTextureFormat(unsigned int& format, unsigned int& internalFormat,
230  int& type, int const scalarType, int const noOfComponents);
231 
235  void ClearBlocks();
236 
240  void ComputeBounds(VolumeBlock* block);
241  void UpdateTextureToDataMatrix(VolumeBlock* block);
242 
261  void ComputeCellToPointMatrix(int extents[6]);
262 
264 
272  bool AreDimensionsValid(vtkTextureObject* texture, int const width,
273  int const height, int const depth);
274 
275  bool SafeLoadTexture(vtkTextureObject* texture, int const width,
276  int const height, int const depth, int numComps, int dataType, void* dataPtr);
278 
279  void UpdateInterpolationType(int const interpolation);
280  void SetInterpolation(int const interpolation);
281 
282 
283  //----------------------------------------------------------------------------
284  vtkTimeStamp UpdateTime;
285 
287  std::vector<vtkImageData*> ImageDataBlocks;
288  std::map<vtkImageData*, VolumeBlock*> ImageDataBlockMap;
289  std::vector<VolumeBlock*> SortedVolumeBlocks;
290  size_t CurrentBlockIdx;
291  bool StreamBlocks;
292 
293  std::vector<Size3> TextureSizes;
294  Size6 FullExtent;
295  Size3 FullSize;
296  Size3 Partitions;
297 
298  vtkDataArray* Scalars;
299 };
300 
301 #endif //vtkVolumeTexture_h
vtkVolumeTexture::SortBlocksBackToFront
void SortBlocksBackToFront(vtkRenderer *ren, vtkMatrix4x4 *volumeMat)
If streaming the data array as separate blocks, sort them back to front.
vtkVolumeTexture::GetPartitions
const Size3 & GetPartitions()
VTK_INT_MIN
#define VTK_INT_MIN
Definition: vtkType.h:158
VTK_INT_MAX
#define VTK_INT_MAX
Definition: vtkType.h:159
vtkX3D::scale
@ scale
Definition: vtkX3D.h:229
vtkTimeStamp.h
vtkVolumeTexture::GetScaleAndBias
static void GetScaleAndBias(const int scalarType, float *scalarRange, float &scale, float &bias)
Get the scale and bias values given a VTK scalar type and a finite range.
vtkX3D::type
@ type
Definition: vtkX3D.h:516
vtkIdType
int vtkIdType
Definition: vtkType.h:347
vtkVolumeTexture::VolumeBlock::TextureToDataset
vtkNew< vtkMatrix4x4 > TextureToDataset
Definition: vtkVolumeTexture.h:117
vtkX3D::data
@ data
Definition: vtkX3D.h:315
vtkTimeStamp
record modification and/or execution time
Definition: vtkTimeStamp.h:36
vtkVolumeTexture::VolumeBlock::TextureToDatasetInv
vtkNew< vtkMatrix4x4 > TextureToDatasetInv
Definition: vtkVolumeTexture.h:118
vtkVolumeTexture::GetNextBlock
VolumeBlock * GetNextBlock()
Return the next volume block to be rendered and load its data.
vtkVolumeTexture::UpdateVolume
void UpdateVolume(vtkVolumeProperty *property)
It currently only calls SetInterpolation internally.
vtkVolumeTexture::SetPartitions
void SetPartitions(int const x, int const y, int const z)
Set a number of blocks per axis.
vtkSmartPointer< vtkTextureObject >
vtkObject
abstract base class for most VTK objects
Definition: vtkObject.h:60
vtkDataArray
abstract superclass for arrays of numeric data
Definition: vtkDataArray.h:55
vtkVolumeTexture::VolumeBlock
Definition: vtkVolumeTexture.h:96
vtkVolumeTexture::vtkVolumeTexture
vtkVolumeTexture()
vtkVolumeTexture::~vtkVolumeTexture
~vtkVolumeTexture() override
vtkWindow
window superclass for vtkRenderWindow
Definition: vtkWindow.h:38
vtkVolumeTexture::HandleLargeDataTypes
bool HandleLargeDataTypes
Definition: vtkVolumeTexture.h:187
vtkX3D::height
@ height
Definition: vtkX3D.h:254
vtkVolumeTexture::VolumeBlock::TextureObject
vtkTextureObject * TextureObject
Definition: vtkVolumeTexture.h:114
vtkVolumeTexture::VolumeBlock::VolumeBlock
VolumeBlock(vtkImageData *imData, vtkTextureObject *tex, Size3 const &texSize)
Definition: vtkVolumeTexture.h:97
vtkMatrix4x4.h
vtkVolumeTexture::New
static vtkVolumeTexture * New()
vtkImageData
topologically and geometrically regular array of data
Definition: vtkImageData.h:46
vtkIndent
a simple class to control print indentation
Definition: vtkIndent.h:40
vtkTextureObject
abstracts an OpenGL texture object.
Definition: vtkTextureObject.h:45
vtkMatrix4x4
represent and manipulate 4x4 transformation matrices
Definition: vtkMatrix4x4.h:42
vtkVolumeTexture::LoadVolume
bool LoadVolume(vtkRenderer *ren, vtkImageData *data, vtkDataArray *scalars, int const isCell, int const interpolation)
Loads the data array into the texture in the case only a single block is is defined.
vtkVolumeTexture::VolumeBlock::TupleIndex
vtkIdType TupleIndex
Definition: vtkVolumeTexture.h:116
vtkVolumeTexture::ReleaseGraphicsResources
void ReleaseGraphicsResources(vtkWindow *win)
Clean-up acquired graphics resources.
vtkVolumeTexture::CellToPointMatrix
vtkNew< vtkMatrix4x4 > CellToPointMatrix
Definition: vtkVolumeTexture.h:196
vtkSmartPointer.h
vtkNew< vtkMatrix4x4 >
vtkObject.h
vtkVolumeTexture::VolumeBlock::TextureSize
Size3 TextureSize
Definition: vtkVolumeTexture.h:115
vtkVolumeTexture
Creates and manages the volume texture rendered by vtkOpenGLGPUVolumeRayCastMapper.
Definition: vtkVolumeTexture.h:88
vtkVolumeTexture::GetLoadedScalars
vtkDataArray * GetLoadedScalars()
vtkVolumeTexture::UploadTime
vtkTimeStamp UploadTime
Definition: vtkVolumeTexture.h:193
vtkVolumeTexture::PrintSelf
void PrintSelf(ostream &os, vtkIndent indent) override
Methods invoked by print to print information about the object including superclasses.
vtkTuple.h
vtkNew.h
vtkVolumeTexture::GetCurrentBlock
VolumeBlock * GetCurrentBlock()
Return the currently loaded block.
vtkVolumeTexture::VolumeBlock::ImageData
vtkImageData * ImageData
Definition: vtkVolumeTexture.h:113
vtkRenderer
abstract specification for renderers
Definition: vtkRenderer.h:64
vtkX3D::extent
@ extent
Definition: vtkX3D.h:345
vtkTuple< int, 6 >
vtkVolumeTexture::InterpolationType
int InterpolationType
Definition: vtkVolumeTexture.h:192
vtkVolumeProperty
represents the common properties for rendering a volume.
Definition: vtkVolumeProperty.h:69