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 
108  vtkContourValues* GetDepthPassContourValues();
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 
240  void SetMaskInput(vtkImageData* mask);
241  vtkGetObjectMacro(MaskInput, vtkImageData);
243 
244  enum
245  {
246  BinaryMaskType = 0,
247  LabelMapMaskType
248  };
249 
251 
255  vtkSetMacro(MaskType, int);
256  vtkGetMacro(MaskType, int);
257  void SetMaskTypeToBinary();
258  void SetMaskTypeToLabelMap();
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);
330  void SetDepthImageScalarTypeToUnsignedChar();
331  void SetDepthImageScalarTypeToUnsignedShort();
332  void SetDepthImageScalarTypeToFloat();
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 
452  int GetInputCount();
453 
454  vtkDataSet* GetTransformedInput(const int port = 0);
455 
456  double* GetBoundsFromPort(const int port) VTK_SIZEHINT(6);
457 
459 
462  vtkSetStringMacro(Transfer2DYAxisArray);
463  vtkGetStringMacro(Transfer2DYAxisArray);
465 
466 protected:
468  ~vtkGPUVolumeRayCastMapper() override;
469 
478  int FillInputPortInformation(int port, vtkInformation* info) override;
479 
491  void TransformInput(const int port);
492 
494 
503  int ValidateRender(vtkRenderer*, vtkVolume*);
504  int ValidateInputs();
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.
519  void CanonicalViewRender(vtkRenderer*, vtkVolume*);
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*>;
620  void SetTransformedInput(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
virtual void GPURender(vtkRenderer *, vtkVolume *)
Handled in the subclass - the actual render method.
void ReleaseGraphicsResources(vtkWindow *) override
Release any graphics resources that are being consumed by this mapper.
helper object to manage setting and generating contour values
represents a volume (data & properties) in a rendered scene
Definition: vtkVolume.h:50
Abstract class for a volume mapper.
Store vtkAlgorithm input/output information.
abstract class to specify dataset behavior
Definition: vtkDataSet.h:62
virtual void GetDepthImage(vtkImageData *)
Low level API to export the depth texture as vtkImageData in RenderToImage mode.
virtual void GetColorImage(vtkImageData *)
Low level API to export the color texture as vtkImageData in RenderToImage mode.
abstract specification for renderers
Definition: vtkRenderer.h:72
int vtkIdType
Definition: vtkType.h:332
std::unordered_map< int, vtkDataSet * > DataMap
void Render(vtkRenderer *ren, vtkVolume *vol) override=0
WARNING: INTERNAL METHOD - NOT INTENDED FOR GENERAL USE DO NOT USE THIS METHOD OUTSIDE OF THE RENDERI...
Proxy object to connect input/output ports.
int vtkTypeBool
Definition: vtkABI.h:69
window superclass for vtkRenderWindow
Definition: vtkWindow.h:38
virtual vtkDataSet * GetInput()
Set/Get the input data.
a simple class to control print indentation
Definition: vtkIndent.h:39
int FillInputPortInformation(int, vtkInformation *) override
Fill the input port information objects for this algorithm.
topologically and geometrically regular array of data
Definition: vtkImageData.h:53
virtual void SetInputConnection(int port, vtkAlgorithmOutput *input)
Set the connection for the given input port index.
#define VTK_SIZEHINT(...)
represents the common properties for rendering a volume.
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...
create a window for renderers to draw into
DataMap LastInputs
This is needed only to check if the input data has been changed since the last Render() call...
static vtkAlgorithm * New()
char * Transfer2DYAxisArray
Define the array used for the Y axis of transfer 2D.
Ray casting performed on the GPU.
void PrintSelf(ostream &os, vtkIndent indent) override
Methods invoked by print to print information about the object including superclasses.
void SetInputConnection(vtkAlgorithmOutput *input) override
Add/Remove input connections.
vtkDataSet * GetInput() override
Set/Get the input data.
virtual void RemoveInputConnection(int port, vtkAlgorithmOutput *input)
Remove a connection from the given input port index.