VTK  9.0.1
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 =========================================================================*/
39 #ifndef vtkGPUVolumeRayCastMapper_h
40 #define vtkGPUVolumeRayCastMapper_h
41 #include <unordered_map> // For std::unordered_map
42 #include <vector> // For std::vector
43 
44 #include "vtkVolumeMapper.h"
45 #include <vtkRenderingVolumeModule.h> // For export macro
46 
47 class vtkContourValues;
48 class vtkRenderWindow;
49 class vtkVolumeProperty;
50 
51 class VTKRENDERINGVOLUME_EXPORT vtkGPUVolumeRayCastMapper : public vtkVolumeMapper
52 {
53 public:
56  void PrintSelf(ostream& os, vtkIndent indent) override;
57 
59 
65  vtkSetClampMacro(AutoAdjustSampleDistances, vtkTypeBool, 0, 1);
66  vtkGetMacro(AutoAdjustSampleDistances, vtkTypeBool);
67  vtkBooleanMacro(AutoAdjustSampleDistances, vtkTypeBool);
69 
71 
76  vtkSetClampMacro(LockSampleDistanceToInputSpacing, vtkTypeBool, 0, 1);
77  vtkGetMacro(LockSampleDistanceToInputSpacing, vtkTypeBool);
78  vtkBooleanMacro(LockSampleDistanceToInputSpacing, vtkTypeBool);
80 
82 
87  vtkSetClampMacro(UseJittering, vtkTypeBool, 0, 1);
88  vtkGetMacro(UseJittering, vtkTypeBool);
89  vtkBooleanMacro(UseJittering, vtkTypeBool);
91 
93 
101  vtkSetClampMacro(UseDepthPass, vtkTypeBool, 0, 1);
102  vtkGetMacro(UseDepthPass, vtkTypeBool);
103  vtkBooleanMacro(UseDepthPass, vtkTypeBool);
105 
111  vtkContourValues* GetDepthPassContourValues();
112 
114 
120  vtkSetMacro(SampleDistance, float);
121  vtkGetMacro(SampleDistance, float);
123 
125 
132  vtkSetClampMacro(ImageSampleDistance, float, 0.1f, 100.0f);
133  vtkGetMacro(ImageSampleDistance, float);
135 
137 
141  vtkSetClampMacro(MinimumImageSampleDistance, float, 0.1f, 100.0f);
142  vtkGetMacro(MinimumImageSampleDistance, float);
144 
146 
150  vtkSetClampMacro(MaximumImageSampleDistance, float, 0.1f, 100.0f);
151  vtkGetMacro(MaximumImageSampleDistance, float);
153 
155 
168  vtkSetMacro(FinalColorWindow, float);
169  vtkGetMacro(FinalColorWindow, float);
170  vtkSetMacro(FinalColorLevel, float);
171  vtkGetMacro(FinalColorLevel, float);
173 
175 
180  vtkSetMacro(MaxMemoryInBytes, vtkIdType);
181  vtkGetMacro(MaxMemoryInBytes, vtkIdType);
183 
185 
190  vtkSetClampMacro(MaxMemoryFraction, float, 0.1f, 1.0f);
191  vtkGetMacro(MaxMemoryFraction, float);
193 
195 
203  vtkSetMacro(ReportProgress, bool);
204  vtkGetMacro(ReportProgress, bool);
206 
213  virtual int IsRenderSupported(
214  vtkRenderWindow* vtkNotUsed(window), vtkVolumeProperty* vtkNotUsed(property))
215  {
216  return 0;
217  }
218 
219  void CreateCanonicalView(vtkRenderer* ren, vtkVolume* volume, vtkImageData* image, int blend_mode,
220  double viewDirection[3], double viewUp[3]);
221 
223 
243  void SetMaskInput(vtkImageData* mask);
244  vtkGetObjectMacro(MaskInput, vtkImageData);
246 
247  enum
248  {
249  BinaryMaskType = 0,
250  LabelMapMaskType
251  };
252 
254 
258  vtkSetMacro(MaskType, int);
259  vtkGetMacro(MaskType, int);
260  void SetMaskTypeToBinary();
261  void SetMaskTypeToLabelMap();
263 
265 
273  vtkSetClampMacro(MaskBlendFactor, float, 0.0f, 1.0f);
274  vtkGetMacro(MaskBlendFactor, float);
276 
278 
292  vtkSetMacro(RenderToImage, vtkTypeBool);
293  vtkGetMacro(RenderToImage, vtkTypeBool);
294  vtkBooleanMacro(RenderToImage, vtkTypeBool);
296 
298 
303  vtkSetMacro(DepthImageScalarType, int);
304  vtkGetMacro(DepthImageScalarType, int);
305  void SetDepthImageScalarTypeToUnsignedChar();
306  void SetDepthImageScalarTypeToUnsignedShort();
307  void SetDepthImageScalarTypeToFloat();
309 
311 
322  vtkSetMacro(ClampDepthToBackface, vtkTypeBool);
323  vtkGetMacro(ClampDepthToBackface, vtkTypeBool);
324  vtkBooleanMacro(ClampDepthToBackface, vtkTypeBool);
326 
333  virtual void GetDepthImage(vtkImageData*) {}
334 
341  virtual void GetColorImage(vtkImageData*) {}
342 
347  void Render(vtkRenderer*, vtkVolume*) override;
348 
353  virtual void GPURender(vtkRenderer*, vtkVolume*) {}
354 
362 
375  virtual void GetReductionRatio(double ratio[3]) = 0;
376 
378  {
379  SCALAR = 0, // default
380  NATIVE
381  };
382 
384 
400  vtkSetMacro(ColorRangeType, int);
401  vtkGetMacro(ColorRangeType, int);
402  vtkSetMacro(ScalarOpacityRangeType, int);
403  vtkGetMacro(ScalarOpacityRangeType, int);
404  vtkSetMacro(GradientOpacityRangeType, int);
405  vtkGetMacro(GradientOpacityRangeType, int);
407 
408  vtkImageData* GetInput() override { return this->GetInput(0); };
409 
411 
415  void RemoveInputConnection(int port, vtkAlgorithmOutput* input) override;
416  void RemoveInputConnection(int port, int idx) override;
417  void SetInputConnection(int port, vtkAlgorithmOutput* input) override;
419  {
420  this->SetInputConnection(0, input);
421  }
423 
427  int GetInputCount();
428 
429  vtkImageData* GetTransformedInput(const int port = 0);
430 
431  double* GetBoundsFromPort(const int port) VTK_SIZEHINT(6);
432 
433 protected:
435  ~vtkGPUVolumeRayCastMapper() override;
436 
445  int FillInputPortInformation(int port, vtkInformation* info) override;
446 
458  void TransformInput(const int port);
459 
461 
470  int ValidateRender(vtkRenderer*, vtkVolume*);
471  int ValidateInputs();
472  int ValidateInput(vtkVolumeProperty* property, const int port);
474 
476 
480  void CloneInputs();
481  void CloneInput(vtkImageData* input, const int port);
483 
484  // Special version of render called during the creation
485  // of a canonical view.
486  void CanonicalViewRender(vtkRenderer*, vtkVolume*);
487 
488  // Methods called by the AMR Volume Mapper.
489  virtual void PreRender(vtkRenderer* ren, vtkVolume* vol, double datasetBounds[6],
490  double scalarRange[2], int numberOfScalarComponents, unsigned int numberOfLevels) = 0;
491 
492  // \pre input is up-to-date
493  virtual void RenderBlock(vtkRenderer* ren, vtkVolume* vol, unsigned int level) = 0;
494 
495  virtual void PostRender(vtkRenderer* ren, int numberOfScalarComponents) = 0;
496  vtkImageData* GetInput(const int port) override;
497 
503  void SetCellFlag(int cellFlag);
504  void RemovePortInternal(const int port);
505 
511 
512  // Render to texture mode flag
514 
515  // Depth image scalar type
517 
518  // Clamp depth values to the depth of the face at which the ray
519  // exits the volume
521 
522  // Enable / disable stochastic jittering
524 
525  // Enable / disable two pass rendering
528 
529  // The distance between sample points along the ray
531 
535 
538 
539  // 1 if we are generating the canonical image, 0 otherwise
542 
544 
548  vtkSetClampMacro(AMRMode, vtkTypeBool, 0, 1);
549  vtkGetMacro(AMRMode, vtkTypeBool);
550  vtkBooleanMacro(AMRMode, vtkTypeBool);
552 
555  int MaskType;
556 
558 
559  // Transfer function range type
563 
564  // Point data or cell data (or field data, not handled) ?
565  int CellFlag;
566 
579  virtual void ClipCroppingRegionPlanes();
580 
581  using DataMap = std::unordered_map<int, vtkImageData*>;
582  void SetTransformedInput(vtkImageData*);
583  vtkImageData* FindData(int port, DataMap& container);
584 
585  double ClippedCroppingRegionPlanes[6];
586 
589 
591  std::vector<int> Ports;
592  std::vector<int> RemovedPorts;
594 
600 
601 private:
603  void operator=(const vtkGPUVolumeRayCastMapper&) = delete;
604 };
605 
606 #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
vtkImageData * GetInput() override
Set/Get the input data.
represents a volume (data & properties) in a rendered scene
Definition: vtkVolume.h:44
std::unordered_map< int, vtkImageData * > DataMap
Abstract class for a volume mapper.
Store vtkAlgorithm input/output information.
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:67
int vtkIdType
Definition: vtkType.h:338
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:37
a simple class to control print indentation
Definition: vtkIndent.h:33
int FillInputPortInformation(int, vtkInformation *) override
Fill the input port information objects for this algorithm.
topologically and geometrically regular array of data
Definition: vtkImageData.h:41
virtual void SetInputConnection(int port, vtkAlgorithmOutput *input)
Set the connection for the given input port index.
virtual vtkImageData * GetInput()
Set/Get the input data.
#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()
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.
virtual void RemoveInputConnection(int port, vtkAlgorithmOutput *input)
Remove a connection from the given input port index.