VTK  9.3.0
vtkVolumeTexture.h
Go to the documentation of this file.
1 // SPDX-FileCopyrightText: Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
2 // SPDX-License-Identifier: BSD-3-Clause
3 
53 #ifndef vtkVolumeTexture_h
54 #define vtkVolumeTexture_h
55 #include <map> // For ImageDataBlockMap
56 #include <vector> // For ImageDataBlocks
57 
58 #include "vtkMatrix4x4.h" // For vtkMatrix4
59 #include "vtkNew.h" // For vtkNew
60 #include "vtkObject.h"
61 #include "vtkRenderingVolumeOpenGL2Module.h" // For export macro
62 #include "vtkSmartPointer.h" // For SmartPointer
63 #include "vtkTimeStamp.h" // For UploadTime
64 #include "vtkTuple.h" // For Size6 and Size3
65 
66 VTK_ABI_NAMESPACE_BEGIN
67 class vtkDataArray;
68 class vtkDataSet;
69 class vtkImageData;
70 class vtkRenderer;
71 class vtkTextureObject;
72 class vtkVolumeProperty;
73 class vtkWindow;
74 
75 class VTKRENDERINGVOLUMEOPENGL2_EXPORT vtkVolumeTexture : public vtkObject
76 {
77  typedef vtkTuple<int, 6> Size6;
78  typedef vtkTuple<int, 3> Size3;
79 
80 public:
81  static vtkVolumeTexture* New();
82 
83  struct VolumeBlock
84  {
85  VolumeBlock(vtkDataSet* dataset, vtkTextureObject* tex, Size3 const& texSize)
86  {
87  // Block extent is stored in vtkDataSet
88  DataSet = dataset;
89  TextureObject = tex;
90  TextureSize = texSize;
91  TupleIndex = 0;
92 
93  this->Extents[0] = VTK_INT_MAX;
94  this->Extents[1] = VTK_INT_MIN;
95  this->Extents[2] = VTK_INT_MAX;
96  this->Extents[3] = VTK_INT_MIN;
97  this->Extents[4] = VTK_INT_MAX;
98  this->Extents[5] = VTK_INT_MIN;
99  }
100 
107 
108  float CellStep[3];
109  double DatasetStepSize[3];
110 
115  double LoadedBounds[6];
116  double LoadedBoundsAA[6];
117  double VolumeGeometry[24];
118  int Extents[6];
119  };
120 
121  vtkTypeMacro(vtkVolumeTexture, vtkObject);
122  void PrintSelf(ostream& os, vtkIndent indent) override;
123 
127  void SetPartitions(int x, int y, int z);
129 
137  vtkRenderer* ren, vtkDataSet* data, vtkDataArray* scalars, int isCell, int interpolation);
138 
144 
150 
160 
165 
172  static void GetScaleAndBias(int scalarType, float* scalarRange, float& scale, float& bias);
174 
176  float Scale[4];
177  float Bias[4];
178  float ScalarRange[4][2];
179  float CellSpacing[3];
182 
183  int IsCellData = 0;
185  float AdjustedTexMin[4];
186  float AdjustedTexMax[4];
187 
189 
190  int CoordsTexSizes[3];
191  float CoordsScale[3];
192  float CoordsBias[3];
193 
195 
196 protected:
198  ~vtkVolumeTexture() override;
199 
200 private:
201  vtkVolumeTexture(const vtkVolumeTexture&) = delete;
202  void operator=(const vtkVolumeTexture&) = delete;
203 
208  bool LoadTexture(int interpolation, VolumeBlock* volBlock);
209 
213  void SplitVolume(vtkImageData* imageData, Size3 const& part);
214 
215  void CreateBlocks(unsigned int format, unsigned int internalFormat, int type);
216 
217  void AdjustExtentForCell(Size6& extent);
218  Size3 ComputeBlockSize(int* extent);
219 
224  void SelectTextureFormat(unsigned int& format, unsigned int& internalFormat, int& type,
225  int scalarType, int noOfComponents);
226 
230  void ClearBlocks();
231 
235  // can be combined into one call
236  void ComputeBounds(VolumeBlock* block);
237  void UpdateTextureToDataMatrix(VolumeBlock* block);
238 
257  void ComputeCellToPointMatrix(int extents[6]);
258 
260 
268  bool AreDimensionsValid(vtkTextureObject* texture, int width, int height, int depth);
269 
270  bool SafeLoadTexture(vtkTextureObject* texture, int width, int height, int depth, int numComps,
271  int dataType, void* dataPtr);
273 
274  void UpdateInterpolationType(int interpolation);
275  void SetInterpolation(int interpolation);
276 
277  //----------------------------------------------------------------------------
278  vtkTimeStamp UpdateTime;
279 
281  std::vector<vtkDataSet*> ImageDataBlocks;
282  std::map<vtkDataSet*, VolumeBlock*> ImageDataBlockMap;
283  std::vector<VolumeBlock*> SortedVolumeBlocks;
284  size_t CurrentBlockIdx;
285  bool StreamBlocks;
286 
287  std::vector<Size3> TextureSizes;
288  Size6 FullExtent;
289  Size3 FullSize;
290  Size3 Partitions;
291 
292  vtkDataArray* Scalars;
293 };
294 
295 VTK_ABI_NAMESPACE_END
296 #endif // vtkVolumeTexture_h
abstract superclass for arrays of numeric data
Definition: vtkDataArray.h:54
abstract class to specify dataset behavior
Definition: vtkDataSet.h:62
topologically and geometrically regular array of data
Definition: vtkImageData.h:52
a simple class to control print indentation
Definition: vtkIndent.h:38
represent and manipulate 4x4 transformation matrices
Definition: vtkMatrix4x4.h:40
abstract base class for most VTK objects
Definition: vtkObject.h:61
abstract specification for renderers
Definition: vtkRenderer.h:71
abstracts an OpenGL texture object.
record modification and/or execution time
Definition: vtkTimeStamp.h:34
represents the common properties for rendering a volume.
Creates and manages the volume texture rendered by vtkOpenGLGPUVolumeRayCastMapper.
static vtkVolumeTexture * New()
VolumeBlock * GetNextBlock()
Return the next volume block to be rendered and load its data.
bool LoadVolume(vtkRenderer *ren, vtkDataSet *data, vtkDataArray *scalars, int isCell, int interpolation)
Loads the data array into the texture in the case only a single block is is defined.
vtkSmartPointer< vtkTextureObject > BlankingTex
vtkTimeStamp UploadTime
vtkNew< vtkMatrix4x4 > CellToPointMatrix
void SetPartitions(int x, int y, int z)
Set a number of blocks per axis.
vtkDataArray * GetLoadedScalars()
void PrintSelf(ostream &os, vtkIndent indent) override
Methods invoked by print to print information about the object including superclasses.
const Size3 & GetPartitions()
void UpdateVolume(vtkVolumeProperty *property)
It currently only calls SetInterpolation internally.
void ReleaseGraphicsResources(vtkWindow *win)
Clean-up acquired graphics resources.
vtkSmartPointer< vtkTextureObject > CoordsTex
~vtkVolumeTexture() override
static void GetScaleAndBias(int scalarType, float *scalarRange, float &scale, float &bias)
Get the scale and bias values given a VTK scalar type and a finite range.
void SortBlocksBackToFront(vtkRenderer *ren, vtkMatrix4x4 *volumeMat)
If streaming the data array as separate blocks, sort them back to front.
VolumeBlock * GetCurrentBlock()
Return the currently loaded block.
window superclass for vtkRenderWindow
Definition: vtkWindow.h:37
@ scale
Definition: vtkX3D.h:229
@ extent
Definition: vtkX3D.h:345
@ type
Definition: vtkX3D.h:516
@ height
Definition: vtkX3D.h:254
@ data
Definition: vtkX3D.h:315
std::map< std::string, DataArray > DataSet
key: variable name, value: DataArray
Definition: VTXTypes.h:28
VolumeBlock(vtkDataSet *dataset, vtkTextureObject *tex, Size3 const &texSize)
vtkNew< vtkMatrix4x4 > TextureToDataset
vtkNew< vtkMatrix4x4 > TextureToDatasetInv
vtkTextureObject * TextureObject
int vtkIdType
Definition: vtkType.h:315
#define VTK_INT_MIN
Definition: vtkType.h:143
#define VTK_INT_MAX
Definition: vtkType.h:144