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  delete[] this->Table;
50  }
51 
52  // activate texture.
53  //--------------------------------------------------------------------------
54  void Activate()
55  {
56  if (!this->TextureObject)
57  {
58  return;
59  }
60  this->TextureObject->Activate();
61  }
62 
63  void Deactivate()
64  {
65  if (!this->TextureObject)
66  {
67  return;
68  }
69  this->TextureObject->Deactivate();
70  }
71 
72  // Update opacity tranfer function texture.
73  //--------------------------------------------------------------------------
74  void Update(vtkPiecewiseFunction* gradientOpacity,
75  double sampleDistance,
76  double range[2],
77  double vtkNotUsed(unitDistance),
78  int filterValue,
79  vtkOpenGLRenderWindow* renWin)
80  {
81  bool needUpdate=false;
82 
83  if (!this->TextureObject)
84  {
86  }
87 
88  this->TextureObject->SetContext(renWin);
89 
90  if (this->LastRange[0] != range[0] ||
91  this->LastRange[1] != range[1])
92  {
93  this->LastRange[0] = range[0];
94  this->LastRange[1] = range[1];
95  needUpdate = true;
96  }
97 
98  if(gradientOpacity->GetMTime() > this->BuildTime ||
99  this->TextureObject->GetMTime() > this->BuildTime ||
100  this->LastSampleDistance != sampleDistance ||
101  needUpdate || !this->TextureObject->GetHandle())
102  {
103  if(this->Table == 0)
104  {
105  this->Table = new float[this->TextureWidth];
106  }
107 
108  gradientOpacity->GetTable(0,
109  (this->LastRange[1] - this->LastRange[0]) * 0.25,
110  this->TextureWidth, this->Table);
111 
114  VTK_FLOAT,
115  this->Table);
116 
118  this->TextureObject->SetMagnificationFilter(filterValue);
119  this->TextureObject->SetMinificationFilter(filterValue);
120  this->BuildTime.Modified();
121  }
122 
123  if(this->LastInterpolation != filterValue)
124  {
125  this->LastInterpolation = filterValue;
126  this->TextureObject->SetMagnificationFilter(filterValue);
127  this->TextureObject->SetMinificationFilter(filterValue);
128  }
129  }
130 
131  // Get the texture unit
132  //--------------------------------------------------------------------------
133  int GetTextureUnit(void)
134  {
135  if (!this->TextureObject)
136  {
137  return -1;
138  }
139  return this->TextureObject->GetTextureUnit();
140  }
141 
142  //--------------------------------------------------------------------------
144  {
145  if (this->TextureObject)
146  {
148  this->TextureObject->Delete();
149  this->TextureObject = 0;
150  }
151  }
152 
153 protected:
154 // GLuint TextureId;
157 
160  float* Table;
162  double LastRange[2];
163 private:
166 };
167 
168 //-----------------------------------------------------------------------------
170 {
171 public:
172  //--------------------------------------------------------------------------
173  vtkOpenGLVolumeGradientOpacityTables(unsigned int numberOfTables)
174  {
175  this->Tables = new vtkOpenGLVolumeGradientOpacityTable[numberOfTables];
176  this->NumberOfTables = numberOfTables;
177  }
178 
179  //--------------------------------------------------------------------------
181  {
182  delete [] this->Tables;
183  }
184 
185  // Get opacity table at a given index.
186  //--------------------------------------------------------------------------
188  {
189  if (i >= this->NumberOfTables)
190  {
191  return NULL;
192  }
193  return &this->Tables[i];
194  }
195 
196  // Get number of tables.
197  //--------------------------------------------------------------------------
198  unsigned int GetNumberOfTables()
199  {
200  return this->NumberOfTables;
201  }
202 
203  //--------------------------------------------------------------------------
205  {
206  for (unsigned int i = 0; i < this->NumberOfTables; ++i)
207  {
208  this->Tables[i].ReleaseGraphicsResources(window);
209  }
210  }
211 private:
212  unsigned int NumberOfTables;
214 
215  // vtkOpenGLVolumeGradientOpacityTables (Not implemented)
217 
218  // vtkOpenGLVolumeGradientOpacityTables (Not implemented)
220 
221  // operator = (Not implemented)
223 };
224 
225 #endif // vtkOpenGLVolumeGradientOpacityTable_h_
226 // VTK-HeaderTest-Exclude: vtkOpenGLVolumeGradientOpacityTable.h
OpenGL rendering window.
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 Deactivate(unsigned int texUnit)
void GetTable(double x1, double x2, int size, float *table, int stride=1)
vtkOpenGLVolumeGradientOpacityTables(unsigned int numberOfTables)
window superclass for vtkRenderWindow
Definition: vtkWindow.h:36
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)
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)
virtual void Delete()
virtual void SetMagnificationFilter(int)