vtkUnstructuredGridPreIntegration.h 7.35 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
/*=========================================================================

  Program:   Visualization Toolkit
  Module:    vtkUnstructuredGridPreIntegration.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.

=========================================================================*/

/*
 * Copyright 2004 Sandia Corporation.
 * Under the terms of Contract DE-AC04-94AL85000, there is a non-exclusive
 * license for use of this work by or on behalf of the
 * U.S. Government. Redistribution and use in source and binary forms, with
 * or without modification, are permitted provided that this Notice and any
 * statement of authorship are reproduced on all copies.
 */

25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41
/**
 * @class   vtkUnstructuredGridPreIntegration
 * @brief   performs ray integration with pre-integration tables.
 *
 *
 *
 * vtkUnstructuredGridPreIntegration performs ray integration by looking
 * into a precomputed table.  The result should be equivalent to that
 * computed by vtkUnstructuredGridLinearRayIntegrator and
 * vtkUnstructuredGridPartialPreIntegration, but faster than either one.
 * The pre-integration algorithm was first introduced by Roettger, Kraus,
 * and Ertl in "Hardware-Accelerated Volume And Isosurface Rendering Based
 * On Cell-Projection."
 *
 * Due to table size limitations, a table can only be indexed by
 * independent scalars.  Thus, dependent scalars are not supported.
 *
42
 */
43

44 45
#ifndef vtkUnstructuredGridPreIntegration_h
#define vtkUnstructuredGridPreIntegration_h
46

47
#include "vtkRenderingVolumeModule.h" // For export macro
48 49 50 51
#include "vtkUnstructuredGridVolumeRayIntegrator.h"

class vtkVolumeProperty;

52 53
class VTKRENDERINGVOLUME_EXPORT vtkUnstructuredGridPreIntegration
  : public vtkUnstructuredGridVolumeRayIntegrator
54 55
{
public:
56 57 58
  vtkTypeMacro(vtkUnstructuredGridPreIntegration, vtkUnstructuredGridVolumeRayIntegrator);
  static vtkUnstructuredGridPreIntegration* New();
  void PrintSelf(ostream& os, vtkIndent indent) override;
59

60
  void Initialize(vtkVolume* volume, vtkDataArray* scalars) override;
61

62 63
  void Integrate(vtkDoubleArray* intersectionLengths, vtkDataArray* nearIntersections,
    vtkDataArray* farIntersections, float color[4]) override;
64

65 66 67 68 69
  //@{
  /**
   * The class used to fill the pre integration table.  By default, a
   * vtkUnstructuredGridPartialPreIntegration is built.
   */
70
  vtkGetObjectMacro(Integrator, vtkUnstructuredGridVolumeRayIntegrator);
71
  virtual void SetIntegrator(vtkUnstructuredGridVolumeRayIntegrator*);
72
  //@}
73

74 75 76 77
  //@{
  /**
   * Set/Get the size of the integration table built.
   */
78 79 80 81
  vtkSetMacro(IntegrationTableScalarResolution, int);
  vtkGetMacro(IntegrationTableScalarResolution, int);
  vtkSetMacro(IntegrationTableLengthResolution, int);
  vtkGetMacro(IntegrationTableLengthResolution, int);
82
  //@}
83

84 85 86 87
  //@{
  /**
   * Get how an integration table is indexed.
   */
88 89 90
  virtual double GetIntegrationTableScalarShift(int component = 0);
  virtual double GetIntegrationTableScalarScale(int component = 0);
  virtual double GetIntegrationTableLengthScale();
91 92 93 94 95 96 97 98 99
  //@}

  //@{
  /**
   * Get/set whether to use incremental pre-integration (by default it's
   * on).  Incremental pre-integration is much faster but can introduce
   * error due to numerical imprecision.  Under most circumstances, the
   * error is not noticeable.
   */
100 101 102
  vtkGetMacro(IncrementalPreIntegration, vtkTypeBool);
  vtkSetMacro(IncrementalPreIntegration, vtkTypeBool);
  vtkBooleanMacro(IncrementalPreIntegration, vtkTypeBool);
103 104 105 106 107 108 109 110 111 112 113 114 115
  //@}

  /**
   * Get the partial pre-integration table for the given scalar component.
   * The tables are built when Initialize is called.  A segment of length d
   * with a front scalar of sf and a back scalar of sb is referenced in the
   * resulting table as 4 * ((l * \c IntegrationTableLengthScale) * \c
   * IntegrationTableScalarResolution * \c IntegrationTableScalarResolution
   * + (sb * \c IntegrationTableScalarScale + \c
   * IntegrationTableScalarShift) * \c IntegrationTableScalarResolution
   * + (sf * \c IntegrationTableScalarScale + \c
   * IntegrationTableScalarShift)).
   */
116
  virtual float* GetPreIntegrationTable(int component = 0);
117

118 119
  /**
   * Get an entry (RGBA) in one of the pre-integration tables.  The tables
Kunda's avatar
Kunda committed
120
   * are built when Initialize is called.
121
   */
122
  float* GetTableEntry(double scalar_front, double scalar_back, double length, int component = 0);
123

124 125 126 127 128
  /**
   * Like GetTableEntry, except the inputs are scaled indices into the table
   * rather than than the actual scalar and length values.  Use GetTableEntry
   * unless you are really sure you know what you are doing.
   */
129 130
  float* GetIndexedTableEntry(
    int scalar_front_index, int scalar_back_index, int length_index, int component = 0);
131 132 133

protected:
  vtkUnstructuredGridPreIntegration();
134
  ~vtkUnstructuredGridPreIntegration() override;
135

136
  vtkUnstructuredGridVolumeRayIntegrator* Integrator;
137

138 139
  vtkVolume* Volume;
  vtkVolumeProperty* Property;
140 141
  double MaxLength;

142 143 144 145 146
  int NumComponents;
  float** IntegrationTable;
  double* IntegrationTableScalarShift;
  double* IntegrationTableScalarScale;
  double IntegrationTableLengthScale;
147 148 149 150 151
  vtkTimeStamp IntegrationTableBuilt;

  int IntegrationTableScalarResolution;
  int IntegrationTableLengthResolution;

152
  vtkTypeBool IncrementalPreIntegration;
153

154
  virtual void BuildPreIntegrationTables(vtkDataArray* scalars);
155 156

private:
157 158
  vtkUnstructuredGridPreIntegration(const vtkUnstructuredGridPreIntegration&) = delete;
  void operator=(const vtkUnstructuredGridPreIntegration&) = delete;
159 160
};

161 162
inline float* vtkUnstructuredGridPreIntegration::GetIndexedTableEntry(
  int scalar_front_index, int scalar_back_index, int length_index, int component)
163 164 165 166
{
  // Snap entries to bounds.  I don't really want to spend cycles doing
  // this, but I've had the ray caster give me values that are noticeably
  // out of bounds.
167 168
  if (scalar_front_index < 0)
    scalar_front_index = 0;
169 170
  if (scalar_front_index >= this->IntegrationTableScalarResolution)
    scalar_front_index = this->IntegrationTableScalarResolution - 1;
171 172
  if (scalar_back_index < 0)
    scalar_back_index = 0;
173 174
  if (scalar_back_index >= this->IntegrationTableScalarResolution)
    scalar_back_index = this->IntegrationTableScalarResolution - 1;
175 176
  if (length_index < 0)
    length_index = 0;
177 178 179
  if (length_index >= this->IntegrationTableLengthResolution)
    length_index = this->IntegrationTableLengthResolution - 1;

180 181 182 183 184
  return (this->IntegrationTable[component] +
    4 *
      (((length_index * this->IntegrationTableScalarResolution + scalar_back_index) *
         this->IntegrationTableScalarResolution) +
        scalar_front_index));
185 186
}

187
inline float* vtkUnstructuredGridPreIntegration::GetTableEntry(
188 189
  double scalar_front, double scalar_back, double length, int component)
{
190 191 192 193 194
  int sfi = static_cast<int>(scalar_front * this->IntegrationTableScalarScale[component] +
    this->IntegrationTableScalarShift[component] + 0.5);
  int sbi = static_cast<int>(scalar_back * this->IntegrationTableScalarScale[component] +
    this->IntegrationTableScalarShift[component] + 0.5);
  int li = static_cast<int>(length * this->IntegrationTableLengthScale + 0.5);
195 196 197
  return this->GetIndexedTableEntry(sfi, sbi, li, component);
}

198
#endif // vtkUnstructuredGridPreIntegration_h