VTK
vtkOpenGLVolumeGradientOpacityTable.h
Go to the documentation of this file.
1 /*=========================================================================
2 
3  Program: Visualization Toolkit
4  Module: vtkOpenGLVolumeGradientOpacityTable.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 =========================================================================*/
15 
16 #ifndef vtkOpenGLVolumeGradientOpacityTable_h_
17 #define vtkOpenGLVolumeGradientOpacityTable_h_
18 
19 #include <vtkPiecewiseFunction.h>
20 #include <vtkTextureObject.h>
21 #include <vtkVolumeMapper.h>
22 
23 #include <vtk_glew.h>
24 
25 //----------------------------------------------------------------------------
27 {
28 public:
29  //--------------------------------------------------------------------------
31  {
32  this->TextureObject = 0;
33  this->TextureWidth = width;
34  this->LastSampleDistance = 1.0;
35  this->Table = 0;
36  this->LastInterpolation = -1;
37  this->LastRange[0] = this->LastRange[1] = 0.0;
38  }
39 
40  //--------------------------------------------------------------------------
42  {
43  if (this->TextureObject)
44  {
45  this->TextureObject->Delete();
46  this->TextureObject = 0;
47  }
48 
49  if (this->Table)
50  {
51  delete[] this->Table;
52  this->Table=0;
53  }
54  }
55 
56  // Bind texture.
57  //--------------------------------------------------------------------------
58  void Bind()
59  {
60  if (!this->TextureObject)
61  {
62  return;
63  }
64  this->TextureObject->Activate();
65  }
66 
67  // Update opacity tranfer function texture.
68  //--------------------------------------------------------------------------
69  void Update(vtkPiecewiseFunction* gradientOpacity,
70  double sampleDistance,
71  double range[2],
72  double vtkNotUsed(unitDistance),
73  int filterValue,
74  vtkOpenGLRenderWindow* renWin)
75  {
76  bool needUpdate=false;
77 
78  if (!this->TextureObject)
79  {
81  }
82 
83  this->TextureObject->SetContext(renWin);
84 
85  if (this->LastRange[0] != range[0] ||
86  this->LastRange[1] != range[1])
87  {
88  this->LastRange[0] = range[0];
89  this->LastRange[1] = range[1];
90  needUpdate = true;
91  }
92 
93  if(gradientOpacity->GetMTime() > this->BuildTime ||
94  this->TextureObject->GetMTime() > this->BuildTime ||
95  this->LastSampleDistance != sampleDistance ||
96  needUpdate || !this->TextureObject->GetHandle())
97  {
98  if(this->Table == 0)
99  {
100  this->Table = new float[this->TextureWidth];
101  }
102 
103  gradientOpacity->GetTable(0,
104  (this->LastRange[1] - this->LastRange[0]) * 0.25,
105  this->TextureWidth, this->Table);
106 
109  VTK_FLOAT,
110  this->Table);
111 
112  this->TextureObject->Activate();
114  this->TextureObject->SetMagnificationFilter(filterValue);
115  this->TextureObject->SetMinificationFilter(filterValue);
116  this->BuildTime.Modified();
117  }
118 
119  if(this->LastInterpolation != filterValue)
120  {
121  this->LastInterpolation = filterValue;
122  this->TextureObject->SetMagnificationFilter(filterValue);
123  this->TextureObject->SetMinificationFilter(filterValue);
124  }
125  }
126 
127  // Get the texture unit
128  //--------------------------------------------------------------------------
129  int GetTextureUnit(void)
130  {
131  if (!this->TextureObject)
132  {
133  return -1;
134  }
135  return this->TextureObject->GetTextureUnit();
136  }
137 
138  //--------------------------------------------------------------------------
140  {
141  if (this->TextureObject)
142  {
144  this->TextureObject->Delete();
145  this->TextureObject = 0;
146  }
147  }
148 
149 protected:
150 // GLuint TextureId;
153 
156  float* Table;
158  double LastRange[2];
159 private:
162 };
163 
164 //-----------------------------------------------------------------------------
166 {
167 public:
168  //--------------------------------------------------------------------------
169  vtkOpenGLVolumeGradientOpacityTables(unsigned int numberOfTables)
170  {
171  this->Tables = new vtkOpenGLVolumeGradientOpacityTable[numberOfTables];
172  this->NumberOfTables = numberOfTables;
173  }
174 
175  //--------------------------------------------------------------------------
177  {
178  delete [] this->Tables;
179  }
180 
181  // Get opacity table at a given index.
182  //--------------------------------------------------------------------------
184  {
185  if (i >= this->NumberOfTables)
186  {
187  return NULL;
188  }
189  return &this->Tables[i];
190  }
191 
192  // Get number of tables.
193  //--------------------------------------------------------------------------
194  unsigned int GetNumberOfTables()
195  {
196  return this->NumberOfTables;
197  }
198 
199  //--------------------------------------------------------------------------
201  {
202  for (unsigned int i = 0; i < this->NumberOfTables; ++i)
203  {
204  this->Tables[i].ReleaseGraphicsResources(window);
205  }
206  }
207 private:
208  unsigned int NumberOfTables;
210 
211  // vtkOpenGLVolumeGradientOpacityTables (Not implemented)
213 
214  // vtkOpenGLVolumeGradientOpacityTables (Not implemented)
216 
217  // operator = (Not implemented)
219 };
220 
221 #endif // vtkOpenGLVolumeGradientOpacityTable_h_
222 // VTK-HeaderTest-Exclude: vtkOpenGLVolumeGradientOpacityTable.h
OpenGL rendering window.
#define vtkNotUsed(x)
Definition: vtkSetGet.h:547
void SetContext(vtkRenderWindow *)
Defines a 1D piecewise function.
record modification and/or execution time
Definition: vtkTimeStamp.h:34
unsigned long int GetMTime()
void Modified()
void GetTable(double x1, double x2, int size, float *table, int stride=1)
vtkOpenGLVolumeGradientOpacityTables(unsigned int numberOfTables)
window superclass for vtkRenderWindow
Definition: vtkWindow.h:33
void Update(vtkPiecewiseFunction *gradientOpacity, double sampleDistance, double range[2], double vtkNotUsed(unitDistance), int filterValue, vtkOpenGLRenderWindow *renWin)
#define VTK_FLOAT
Definition: vtkType.h:35
virtual unsigned long GetMTime()
virtual void SetMinificationFilter(int)
GLint GLint GLsizei width
Definition: vtkgl.h:11316
virtual unsigned int GetHandle()
void Activate(unsigned int texUnit)
abstracts an OpenGL texture object.
void ReleaseGraphicsResources(vtkWindow *win)
static vtkTextureObject * New()
virtual void SetWrapS(int)
bool CreateAlphaFromRaw(unsigned int width, int internalFormat, int rawType, void *raw)
vtkOpenGLVolumeGradientOpacityTable * GetTable(unsigned int i)
GLenum GLint * range
Definition: vtkgl.h:14180
virtual void Delete()
virtual void SetMagnificationFilter(int)