vtkMultiVolume.h 5.84 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
/*=========================================================================

  Program:   Visualization Toolkit
  Module:    vtkMultiVolume.h

  Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
  All rights reserved.
  See Copyright.txt or http://www.kitware.com/Copyright.htm for details.

     This software is distributed WITHOUT ANY WARRANTY; without even
     the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
     PURPOSE.  See the above copyright notice for more information.

=========================================================================*/
/**
 * @class vtkMultiVolume
 * @brief Represents a world axis-aligned bounding-box containing a set of
 * volumes in a rendered scene.
 *
 * vtkVolume instances registered in this class can be overlapping. They are
 * intended to be all rendered simultaneously by a vtkGPUVolumeRayCastMapper
 * (inputs should be set directly in the mapper).
 *
 * This class holds the full transformation of a bounding-box containing
 * all of the registered volumes.
 *
 *      + TexToBBox : Texture-to-Data (scaling)
 *      + Matrix : Data-to-World (translation)
 *
 * @note This class is intended to be used only by mappers supporting multiple
 * inputs.
 *
 * @sa vtkVolume vtkAbstractVolumeMapper vtkGPUVolumeRayCastMapper
34
 */
35 36
#ifndef vtkMultiVolume_h
#define vtkMultiVolume_h
37 38
#include <array>         // for std::array
#include <unordered_map> // For std::unordered_map
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66

#include "vtkMatrix4x4.h"             // For Matrix
#include "vtkRenderingVolumeModule.h" // For export macro
#include "vtkSmartPointer.h"          // For vtkSmartPointer
#include "vtkVolume.h"

class vtkAbstractVolumeMapper;
class vtkBoundingBox;
class vtkMatrix4x4;
class vtkRenderer;
class vtkVolumeProperty;
class vtkWindow;
class vtkVolumeProperty;
class vtkAbstractVolumeMapper;

class VTKRENDERINGVOLUME_EXPORT vtkMultiVolume : public vtkVolume
{
public:
  static vtkMultiVolume* New();
  vtkTypeMacro(vtkMultiVolume, vtkVolume);
  void PrintSelf(ostream& os, vtkIndent indent) override;

  //@{
  /**
   * Add / Remove a vtkVolume instance.
   */
  void SetVolume(vtkVolume* volume, int port = 0);
  vtkVolume* GetVolume(int port = 0);
67
  void RemoveVolume(int port) { this->SetVolume(nullptr, port); }
68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99
  //@}

  //@{
  /**
   * Given that this class represents a bounding-box only there is no property
   * directly associated with it (a cannot be set directly).
   * This instance will return the property of the volume registered in the 0th
   * port (or nullptr if no volume has been set).
   * \sa vtkVolume
   */
  void SetProperty(vtkVolumeProperty* property) override;
  vtkVolumeProperty* GetProperty() override;
  //@}

  /**
   * Computes the bounds of the box containing all of the vtkVolume instances.
   * Returns the bounds (vtkVolume::Bounds) in world coordinates [xmin, xmax,
   * ymin, ymax, zmin, zmax] but also keeps cached the bounds in data coordinates
   * (vtkMultiVolume::DataBounds).
   */
  double* GetBounds() override;

  /**
   * \sa vtkVolume
   */
  vtkMTimeType GetMTime() override;

  /**
   * Checks whether the vtkProp passed is another vtkMultiVolume and tries to
   * copy accordingly. Otherwise it falls back to vtkVolume::ShallowCopy.
   * \sa vtkVolume
   */
100
  void ShallowCopy(vtkProp* prop) override;
101 102 103 104 105 106 107 108 109 110

  /**
   * As with other vtkProp3D, Matrix holds the transformation from data
   * coordinates to world coordinates.  Since this class represents an
   * axis-aligned bounding-box, this transformation only contains a translation
   * vector. Each registered vtkVolume contains its own transformation with
   * respect to the world coordinate system.
   * \sa vtkProp3D vtkVolume
   */
  using vtkVolume::GetMatrix;
111
  vtkMatrix4x4* GetMatrix() override { return this->Matrix; }
112 113 114 115 116 117

  /**
   * Returns the transformation from texture coordinates to data cooridinates
   * of the bounding-box. Since this class represents an axis-aligned bounding
   * -boxThis, this transformation only contains a scaling diagonal.
   */
118
  vtkMatrix4x4* GetTextureMatrix() { return this->TexToBBox.GetPointer(); }
119 120 121 122

  /**
   * Total bounds in data coordinates.
   */
123
  double* GetDataBounds() { return this->DataBounds.data(); }
124

125
  vtkMTimeType GetBoundsTime() { return this->BoundsComputeTime.GetMTime(); }
126 127 128 129 130 131 132 133 134

  /**
   * Since vtkMultiVolume acts like a proxy volume to compute the bounding box
   * for its internal vtkVolume instances, there are no properties to be set directly
   * in this instance. For that reason, this override ignores the vtkVolumeProperty
   * check.
   */
  int RenderVolumetricGeometry(vtkViewport* vp) override;

135 136 137
  /**
   * Return the eight corners of the volume
   */
138
  double* GetDataGeometry() { return this->DataGeometry.data(); }
139

140 141 142 143 144 145 146 147 148 149
protected:
  vtkMultiVolume();
  ~vtkMultiVolume() override;

  /**
   * The transformation matrix of this vtkProp3D is not user-definable,
   * (only the registered vtkVolume instances define the total bounding-box).
   * For that reason this method does nothing.
   * \sa vtkProp3D
   */
150
  void ComputeMatrix() override {}
151 152 153 154 155 156 157 158 159 160

  /**
   * Returns the vtkVolume registered in port.
   */
  vtkVolume* FindVolume(int port);

  /**
   * Checks for changes in the registered vtkVolume instances which could
   * required the bounding-box to be recomputed.
   */
161
  bool VolumesChanged();
162 163 164 165 166 167 168

  /**
   * For a box defined by bounds in coordinate system X, compute its
   * axis-aligned bounds in coordinate system Y. T defines the transformation
   * from X to Y and bounds ([x_min, x_max, y_min, y_max, z_min, z_max])
   * the box in X.
   */
169
  std::array<double, 6> ComputeAABounds(double bounds[6], vtkMatrix4x4* T) const;
170 171

  std::array<double, 6> DataBounds;
172
  std::array<double, 24> DataGeometry;
173 174 175 176 177 178 179 180 181
  std::unordered_map<int, vtkVolume*> Volumes;
  vtkTimeStamp BoundsComputeTime;
  vtkSmartPointer<vtkMatrix4x4> TexToBBox;

private:
  vtkMultiVolume(const vtkMultiVolume&) = delete;
  void operator=(const vtkMultiVolume&) = delete;
};
#endif