VTK  9.2.6
vtkGPUVolumeRayCastMapper.h
Go to the documentation of this file.
1 /*=========================================================================
2 
3  Program: Visualization Toolkit
4  Module: vtkGPUVolumeRayCastMapper.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 =========================================================================*/
36 #ifndef vtkGPUVolumeRayCastMapper_h
37 #define vtkGPUVolumeRayCastMapper_h
38 #include <unordered_map> // For std::unordered_map
39 #include <vector> // For std::vector
40 
41 #include "vtkRenderingVolumeModule.h" // For export macro
42 #include "vtkVolumeMapper.h"
43 
44 class vtkContourValues;
45 class vtkRenderWindow;
46 class vtkVolumeProperty;
47 
48 class VTKRENDERINGVOLUME_EXPORT vtkGPUVolumeRayCastMapper : public vtkVolumeMapper
49 {
50 public:
53  void PrintSelf(ostream& os, vtkIndent indent) override;
54 
56 
62  vtkSetClampMacro(AutoAdjustSampleDistances, vtkTypeBool, 0, 1);
63  vtkGetMacro(AutoAdjustSampleDistances, vtkTypeBool);
64  vtkBooleanMacro(AutoAdjustSampleDistances, vtkTypeBool);
66 
68 
73  vtkSetClampMacro(LockSampleDistanceToInputSpacing, vtkTypeBool, 0, 1);
74  vtkGetMacro(LockSampleDistanceToInputSpacing, vtkTypeBool);
75  vtkBooleanMacro(LockSampleDistanceToInputSpacing, vtkTypeBool);
77 
79 
84  vtkSetClampMacro(UseJittering, vtkTypeBool, 0, 1);
85  vtkGetMacro(UseJittering, vtkTypeBool);
86  vtkBooleanMacro(UseJittering, vtkTypeBool);
88 
90 
98  vtkSetClampMacro(UseDepthPass, vtkTypeBool, 0, 1);
99  vtkGetMacro(UseDepthPass, vtkTypeBool);
100  vtkBooleanMacro(UseDepthPass, vtkTypeBool);
102 
109 
111 
117  vtkSetMacro(SampleDistance, float);
118  vtkGetMacro(SampleDistance, float);
120 
122 
129  vtkSetClampMacro(ImageSampleDistance, float, 0.1f, 100.0f);
130  vtkGetMacro(ImageSampleDistance, float);
132 
134 
138  vtkSetClampMacro(MinimumImageSampleDistance, float, 0.1f, 100.0f);
139  vtkGetMacro(MinimumImageSampleDistance, float);
141 
143 
147  vtkSetClampMacro(MaximumImageSampleDistance, float, 0.1f, 100.0f);
148  vtkGetMacro(MaximumImageSampleDistance, float);
150 
152 
165  vtkSetMacro(FinalColorWindow, float);
166  vtkGetMacro(FinalColorWindow, float);
167  vtkSetMacro(FinalColorLevel, float);
168  vtkGetMacro(FinalColorLevel, float);
170 
172 
177  vtkSetMacro(MaxMemoryInBytes, vtkIdType);
178  vtkGetMacro(MaxMemoryInBytes, vtkIdType);
180 
182 
187  vtkSetClampMacro(MaxMemoryFraction, float, 0.1f, 1.0f);
188  vtkGetMacro(MaxMemoryFraction, float);
190 
192 
200  vtkSetMacro(ReportProgress, bool);
201  vtkGetMacro(ReportProgress, bool);
203 
210  virtual int IsRenderSupported(
211  vtkRenderWindow* vtkNotUsed(window), vtkVolumeProperty* vtkNotUsed(property))
212  {
213  return 0;
214  }
215 
216  void CreateCanonicalView(vtkRenderer* ren, vtkVolume* volume, vtkImageData* image, int blend_mode,
217  double viewDirection[3], double viewUp[3]);
218 
220 
241  vtkGetObjectMacro(MaskInput, vtkImageData);
243 
244  enum
245  {
246  BinaryMaskType = 0,
247  LabelMapMaskType
248  };
249 
251 
255  vtkSetMacro(MaskType, int);
256  vtkGetMacro(MaskType, int);
260 
262 
270  vtkSetClampMacro(MaskBlendFactor, float, 0.0f, 1.0f);
271  vtkGetMacro(MaskBlendFactor, float);
273 
275 
282  vtkSetClampMacro(GlobalIlluminationReach, float, 0.0f, 1.0f);
283  vtkGetMacro(GlobalIlluminationReach, float);
285 
287 
298  vtkSetClampMacro(VolumetricScatteringBlending, float, 0.0f, 2.0f);
299  vtkGetMacro(VolumetricScatteringBlending, float);
301 
303 
317  vtkSetMacro(RenderToImage, vtkTypeBool);
318  vtkGetMacro(RenderToImage, vtkTypeBool);
319  vtkBooleanMacro(RenderToImage, vtkTypeBool);
321 
323 
328  vtkSetMacro(DepthImageScalarType, int);
329  vtkGetMacro(DepthImageScalarType, int);
334 
336 
347  vtkSetMacro(ClampDepthToBackface, vtkTypeBool);
348  vtkGetMacro(ClampDepthToBackface, vtkTypeBool);
349  vtkBooleanMacro(ClampDepthToBackface, vtkTypeBool);
351 
358  virtual void GetDepthImage(vtkImageData*) {}
359 
366  virtual void GetColorImage(vtkImageData*) {}
367 
372  void Render(vtkRenderer*, vtkVolume*) override;
373 
378  virtual void GPURender(vtkRenderer*, vtkVolume*) {}
379 
387 
400  virtual void GetReductionRatio(double ratio[3]) = 0;
401 
403  {
404  SCALAR = 0, // default
405  NATIVE
406  };
407 
409 
425  vtkSetMacro(ColorRangeType, int);
426  vtkGetMacro(ColorRangeType, int);
427  vtkSetMacro(ScalarOpacityRangeType, int);
428  vtkGetMacro(ScalarOpacityRangeType, int);
429  vtkSetMacro(GradientOpacityRangeType, int);
430  vtkGetMacro(GradientOpacityRangeType, int);
432 
433  vtkDataSet* GetInput() override { return this->GetInput(0); };
434 
436 
440  void RemoveInputConnection(int port, vtkAlgorithmOutput* input) override;
441  void RemoveInputConnection(int port, int idx) override;
442  void SetInputConnection(int port, vtkAlgorithmOutput* input) override;
444  {
445  this->SetInputConnection(0, input);
446  }
448 
453 
455 
456  double* GetBoundsFromPort(const int port) VTK_SIZEHINT(6);
457 
459 
462  vtkSetStringMacro(Transfer2DYAxisArray);
463  vtkGetStringMacro(Transfer2DYAxisArray);
465 
466 protected:
469 
479 
491  void TransformInput(const int port);
492 
494 
505  int ValidateInput(vtkVolumeProperty* property, const int port);
507 
509 
513  void CloneInputs();
514  void CloneInput(vtkDataSet* input, const int port);
516 
517  // Special version of render called during the creation
518  // of a canonical view.
520 
521  // Methods called by the AMR Volume Mapper.
522  virtual void PreRender(vtkRenderer* ren, vtkVolume* vol, double datasetBounds[6],
523  double scalarRange[2], int numberOfScalarComponents, unsigned int numberOfLevels) = 0;
524 
525  // \pre input is up-to-date
526  virtual void RenderBlock(vtkRenderer* ren, vtkVolume* vol, unsigned int level) = 0;
527 
528  virtual void PostRender(vtkRenderer* ren, int numberOfScalarComponents) = 0;
529  vtkDataSet* GetInput(const int port) override;
530 
536  void SetCellFlag(int cellFlag);
537  void RemovePortInternal(const int port);
538 
544 
545  // Render to texture mode flag
547 
548  // Depth image scalar type
550 
551  // Clamp depth values to the depth of the face at which the ray
552  // exits the volume
554 
555  // Enable / disable stochastic jittering
557 
558  // Secondary rays ambient/global adjustment coefficient
559  float GlobalIlluminationReach = 0.0;
560 
561  float VolumetricScatteringBlending = 0.0;
562 
563  // Enable / disable two pass rendering
566 
567  // The distance between sample points along the ray
569 
573 
576 
577  // 1 if we are generating the canonical image, 0 otherwise
580 
582 
586  vtkSetClampMacro(AMRMode, vtkTypeBool, 0, 1);
587  vtkGetMacro(AMRMode, vtkTypeBool);
588  vtkBooleanMacro(AMRMode, vtkTypeBool);
590 
593  int MaskType;
594 
596 
597  // Transfer function range type
601 
602  // Point data or cell data (or field data, not handled) ?
603  int CellFlag;
604 
617  virtual void ClipCroppingRegionPlanes();
618 
619  using DataMap = std::unordered_map<int, vtkDataSet*>;
621  vtkDataSet* FindData(int port, DataMap& container);
622 
623  double ClippedCroppingRegionPlanes[6];
624 
627 
629  std::vector<int> Ports;
630  std::vector<int> RemovedPorts;
632 
638 
645 
646 private:
648  void operator=(const vtkGPUVolumeRayCastMapper&) = delete;
649 };
650 
651 #endif
Proxy object to connect input/output ports.
virtual void SetInputConnection(int port, vtkAlgorithmOutput *input)
Set the connection for the given input port index.
helper object to manage setting and generating contour values
abstract class to specify dataset behavior
Definition: vtkDataSet.h:172
Ray casting performed on the GPU.
virtual void GetDepthImage(vtkImageData *)
Low level API to export the depth texture as vtkImageData in RenderToImage mode.
virtual int IsRenderSupported(vtkRenderWindow *vtkNotUsed(window), vtkVolumeProperty *vtkNotUsed(property))
Based on hardware and properties, we may or may not be able to render using 3D texture mapping.
void CloneInputs()
Shallow-copy the inputs into a transform-adjusted clone.
void SetMaskTypeToLabelMap()
Set the mask type, if mask is to be used.
void RemoveInputConnection(int port, int idx) override
Add/Remove input connections.
void SetTransformedInput(vtkDataSet *)
void SetDepthImageScalarTypeToFloat()
Set/Get the scalar type of the depth texture in RenderToImage mode.
virtual void GPURender(vtkRenderer *, vtkVolume *)
Handled in the subclass - the actual render method.
char * Transfer2DYAxisArray
Define the array used for the Y axis of transfer 2D.
int ValidateRender(vtkRenderer *, vtkVolume *)
This method is used by the Render() method to validate everything before attempting to render.
virtual void GetColorImage(vtkImageData *)
Low level API to export the color texture as vtkImageData in RenderToImage mode.
double * GetBoundsFromPort(const int port)
void SetInputConnection(vtkAlgorithmOutput *input) override
Add/Remove input connections.
void SetDepthImageScalarTypeToUnsignedShort()
Set/Get the scalar type of the depth texture in RenderToImage mode.
void SetMaskInput(vtkImageData *mask)
Optionally, set a mask input.
~vtkGPUVolumeRayCastMapper() override
virtual void GetReductionRatio(double ratio[3])=0
Return how much the dataset has to be reduced in each dimension to fit on the GPU.
void RemovePortInternal(const int port)
DataMap LastInputs
This is needed only to check if the input data has been changed since the last Render() call.
void CreateCanonicalView(vtkRenderer *ren, vtkVolume *volume, vtkImageData *image, int blend_mode, double viewDirection[3], double viewUp[3])
void SetDepthImageScalarTypeToUnsignedChar()
Set/Get the scalar type of the depth texture in RenderToImage mode.
int ValidateInputs()
This method is used by the Render() method to validate everything before attempting to render.
vtkContourValues * GetDepthPassContourValues()
Return handle to contour values container so that values can be set by the application.
std::unordered_map< int, vtkDataSet * > DataMap
int ValidateInput(vtkVolumeProperty *property, const int port)
This method is used by the Render() method to validate everything before attempting to render.
void ReleaseGraphicsResources(vtkWindow *) override
Release any graphics resources that are being consumed by this mapper.
void Render(vtkRenderer *, vtkVolume *) override
Initialize rendering for this volume.
void TransformInput(const int port)
A transformation is applied (translation) to the input.
void PrintSelf(ostream &os, vtkIndent indent) override
Methods invoked by print to print information about the object including superclasses.
void RemoveInputConnection(int port, vtkAlgorithmOutput *input) override
Add/Remove input connections.
virtual void PreRender(vtkRenderer *ren, vtkVolume *vol, double datasetBounds[6], double scalarRange[2], int numberOfScalarComponents, unsigned int numberOfLevels)=0
vtkDataSet * FindData(int port, DataMap &container)
static vtkGPUVolumeRayCastMapper * New()
vtkDataSet * GetTransformedInput(const int port=0)
virtual void RenderBlock(vtkRenderer *ren, vtkVolume *vol, unsigned int level)=0
void SetInputConnection(int port, vtkAlgorithmOutput *input) override
Add/Remove input connections.
int GetInputCount()
Number of currently active ports.
vtkDataSet * GetInput() override
Set/Get the input data.
virtual void ClipCroppingRegionPlanes()
Compute the cropping planes clipped by the bounds of the volume.
int FillInputPortInformation(int port, vtkInformation *info) override
Handle inputs.
void SetMaskTypeToBinary()
Set the mask type, if mask is to be used.
vtkDataSet * GetInput(const int port) override
Set/Get the input data.
void CloneInput(vtkDataSet *input, const int port)
Shallow-copy the inputs into a transform-adjusted clone.
virtual void PostRender(vtkRenderer *ren, int numberOfScalarComponents)=0
void SetCellFlag(int cellFlag)
Called by the AMR Volume Mapper.
void CanonicalViewRender(vtkRenderer *, vtkVolume *)
topologically and geometrically regular array of data
Definition: vtkImageData.h:163
a simple class to control print indentation
Definition: vtkIndent.h:119
Store vtkAlgorithm input/output information.
create a window for renderers to draw into
abstract specification for renderers
Definition: vtkRenderer.h:182
Abstract class for a volume mapper.
represents the common properties for rendering a volume.
represents a volume (data & properties) in a rendered scene
Definition: vtkVolume.h:140
window superclass for vtkRenderWindow
Definition: vtkWindow.h:39
@ info
Definition: vtkX3D.h:382
@ level
Definition: vtkX3D.h:401
@ port
Definition: vtkX3D.h:453
@ image
Definition: vtkX3D.h:380
int vtkTypeBool
Definition: vtkABI.h:69
int vtkIdType
Definition: vtkType.h:332
#define VTK_SIZEHINT(...)