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 
112  this->TextureObject->Create2DFromRaw(this->TextureWidth,1,1,
113  VTK_FLOAT,
114  this->Table);
115 
117  this->TextureObject->SetMagnificationFilter(filterValue);
118  this->TextureObject->SetMinificationFilter(filterValue);
119  this->BuildTime.Modified();
120  }
121 
122  if(this->LastInterpolation != filterValue)
123  {
124  this->LastInterpolation = filterValue;
125  this->TextureObject->SetMagnificationFilter(filterValue);
126  this->TextureObject->SetMinificationFilter(filterValue);
127  }
128  }
129 
130  // Get the texture unit
131  //--------------------------------------------------------------------------
132  int GetTextureUnit(void)
133  {
134  if (!this->TextureObject)
135  {
136  return -1;
137  }
138  return this->TextureObject->GetTextureUnit();
139  }
140 
141  //--------------------------------------------------------------------------
143  {
144  if (this->TextureObject)
145  {
147  this->TextureObject->Delete();
148  this->TextureObject = 0;
149  }
150  }
151 
152 protected:
153 // GLuint TextureId;
156 
159  float* Table;
161  double LastRange[2];
162 private:
165 };
166 
167 //-----------------------------------------------------------------------------
169 {
170 public:
171  //--------------------------------------------------------------------------
172  vtkOpenGLVolumeGradientOpacityTables(unsigned int numberOfTables)
173  {
174  this->Tables = new vtkOpenGLVolumeGradientOpacityTable[numberOfTables];
175  this->NumberOfTables = numberOfTables;
176  }
177 
178  //--------------------------------------------------------------------------
180  {
181  delete [] this->Tables;
182  }
183 
184  // Get opacity table at a given index.
185  //--------------------------------------------------------------------------
187  {
188  if (i >= this->NumberOfTables)
189  {
190  return NULL;
191  }
192  return &this->Tables[i];
193  }
194 
195  // Get number of tables.
196  //--------------------------------------------------------------------------
197  unsigned int GetNumberOfTables()
198  {
199  return this->NumberOfTables;
200  }
201 
202  //--------------------------------------------------------------------------
204  {
205  for (unsigned int i = 0; i < this->NumberOfTables; ++i)
206  {
207  this->Tables[i].ReleaseGraphicsResources(window);
208  }
209  }
210 private:
211  unsigned int NumberOfTables;
213 
214  // vtkOpenGLVolumeGradientOpacityTables (Not implemented)
216 
217  // vtkOpenGLVolumeGradientOpacityTables (Not implemented)
219 
220  // operator = (Not implemented)
222 };
223 
224 #endif // vtkOpenGLVolumeGradientOpacityTable_h
225 // 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)
bool Create2DFromRaw(unsigned int width, unsigned int height, int numComps, int dataType, void *data)
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)
vtkOpenGLVolumeGradientOpacityTable * GetTable(unsigned int i)
virtual void Delete()
virtual void SetMagnificationFilter(int)