VTK
vtkOpenGLVolumeRGBTable.h
Go to the documentation of this file.
1/*=========================================================================
2
3 Program: Visualization Toolkit
4 Module: vtkOpenGLVolumeRGBTable.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 vtkOpenGLVolumeRGBTable_h
17#define vtkOpenGLVolumeRGBTable_h
18
19#include <vtkObjectFactory.h>
21#include <vtkTextureObject.h>
22#include <vtk_glew.h>
23#include <vtkMath.h>
24
25
26//----------------------------------------------------------------------------
28{
29public:
30
32
33 // Activate texture.
34 //--------------------------------------------------------------------------
35 void Activate()
36 {
37 if (!this->TextureObject)
38 {
39 return;
40 }
41 this->TextureObject->Activate();
42 }
43
44 // Deactivate texture.
45 //--------------------------------------------------------------------------
47 {
48 if (!this->TextureObject)
49 {
50 return;
51 }
53 }
54
55 // Update color transfer function texture.
56 //--------------------------------------------------------------------------
58 double range[2],
59 int filterValue,
61 {
62 bool needUpdate = false;
63
64 if (!this->TextureObject)
65 {
67 }
68
69 this->TextureObject->SetContext(renWin);
70
71 if (range[0] != this->LastRange[0] || range[1] != this->LastRange[1])
72 {
73 this->LastRange[0] = range[0];
74 this->LastRange[1] = range[1];
75 needUpdate = true;
76 }
77
78 if (scalarRGB->GetMTime() > this->BuildTime ||
79 this->TextureObject->GetMTime() > this->BuildTime ||
80 needUpdate || !this->TextureObject->GetHandle())
81 {
82 int const idealW = scalarRGB->EstimateMinNumberOfSamples(this->LastRange[0],
83 this->LastRange[1]);
84 int const newWidth = this->GetMaximumSupportedTextureWidth(renWin, idealW);
85
86 if(this->Table == NULL || this->TextureWidth != newWidth)
87 {
88 this->TextureWidth = newWidth;
89 delete [] this->Table;
90 this->Table = new float[this->TextureWidth *
92 }
93
94 scalarRGB->GetTable(this->LastRange[0], this->LastRange[1],
95 this->TextureWidth, this->Table);
98 this->TextureObject->SetMagnificationFilter(filterValue);
99 this->TextureObject->SetMinificationFilter(filterValue);
102 VTK_FLOAT,
103 this->Table);
104 this->LastInterpolation = filterValue;
105 this->BuildTime.Modified();
106 }
107
108 if (this->LastInterpolation != filterValue)
109 {
110 this->LastInterpolation = filterValue;
111 this->TextureObject->SetMagnificationFilter(filterValue);
112 this->TextureObject->SetMinificationFilter(filterValue);
113 }
114 }
115
116 //--------------------------------------------------------------------------
118 int idealWidth)
119 {
120 if (!this->TextureObject)
121 {
122 vtkErrorMacro("vtkTextureObject not initialized!");
123 return -1;
124 }
125
126 // Try to match the next power of two.
127 idealWidth = vtkMath::NearestPowerOfTwo(idealWidth);
128 int const maxWidth = this->TextureObject->GetMaximumTextureSize(renWin);
129 if (maxWidth < 0)
130 {
131 vtkErrorMacro("Failed to query max texture size! using default 1024.");
132 return 1024;
133 }
134
135 if (maxWidth >= idealWidth)
136 {
137 idealWidth = vtkMath::Max(1024, idealWidth);
138 return idealWidth;
139 }
140
141 vtkWarningMacro("This OpenGL implementation does not support the required "
142 "texture size of " << idealWidth << ", falling back to maximum allowed, "
143 << maxWidth << "." << "This may cause an incorrect color table mapping.");
144
145 return maxWidth;
146 }
147
148 // Get the texture unit
149 //--------------------------------------------------------------------------
151 {
152 if (!this->TextureObject)
153 {
154 return -1;
155 }
156 return this->TextureObject->GetTextureUnit();
157 }
158
159 //--------------------------------------------------------------------------
161 {
162 if (this->TextureObject)
163 {
165 this->TextureObject->Delete();
166 this->TextureObject = 0;
167 }
168 }
169
170protected:
171
172 //--------------------------------------------------------------------------
174 {
175 this->TextureWidth = 1024;
176 this->NumberOfColorComponents = 3;
177 this->TextureObject = NULL;
178 this->LastInterpolation = -1;
179 this->LastRange[0] = this->LastRange[1] = 0;
180 this->Table = NULL;
181 }
182
183 //--------------------------------------------------------------------------
185 {
186 if (this->TextureObject)
187 {
188 this->TextureObject->Delete();
189 this->TextureObject = NULL;
190 }
191
192 delete[] this->Table;
193 }
194
195
198
200
202 double LastRange[2];
203 float* Table;
205
206private:
208 VTK_DELETE_FUNCTION;
210 VTK_DELETE_FUNCTION;
211};
212
214
215
218{
219public:
220 //--------------------------------------------------------------------------
221 vtkOpenGLVolumeRGBTables(unsigned int numberOfTables)
222 {
223 this->Tables.reserve(static_cast<size_t>(numberOfTables));
224
225 for (unsigned int i = 0; i < numberOfTables; i++)
226 {
228 this->Tables.push_back(table);
229 }
230 }
231
232 //--------------------------------------------------------------------------
234 {
235 size_t const size = this->Tables.size();
236 for (size_t i = 0; i < size; i++)
237 {
238 this->Tables[i]->Delete();
239 }
240 }
241
242 // brief Get opacity table at a given index.
243 //--------------------------------------------------------------------------
245 {
246 if (i >= this->Tables.size())
247 {
248 return NULL;
249 }
250 return this->Tables[i];
251 }
252
253 // Get number of opacity tables.
254 //--------------------------------------------------------------------------
256 {
257 return this->Tables.size();
258 }
259
260 //--------------------------------------------------------------------------
262 {
263 size_t const size = this->Tables.size();
264 for (size_t i = 0; i < size; ++i)
265 {
266 this->Tables[i]->ReleaseGraphicsResources(window);
267 }
268 }
269
270private:
271 std::vector<vtkOpenGLVolumeRGBTable*> Tables;
272
273 vtkOpenGLVolumeRGBTables() VTK_DELETE_FUNCTION;
274
275 vtkOpenGLVolumeRGBTables(const vtkOpenGLVolumeRGBTables &other) VTK_DELETE_FUNCTION;
276
277 vtkOpenGLVolumeRGBTables &operator=(const vtkOpenGLVolumeRGBTables &other) VTK_DELETE_FUNCTION;
278};
279
280#endif // vtkOpenGLVolumeRGBTable_h
281// VTK-HeaderTest-Exclude: vtkOpenGLVolumeRGBTable.h
Defines a transfer function for mapping a property to an RGB color value.
void GetTable(double x1, double x2, int n, double *table)
Fills in a table of n colors mapped from values mapped with even spacing between x1 and x2,...
int EstimateMinNumberOfSamples(double const &x1, double const &x2)
Estimates the minimum size of a table such that it would correctly sample this function.
static T Max(const T &a, const T &b)
Returns the maximum of the two arugments provided.
Definition: vtkMath.h:1268
static int NearestPowerOfTwo(int x)
Compute the nearest power of two that is not less than x.
Definition: vtkMath.h:1230
virtual void Delete()
Delete a VTK object.
abstract base class for most VTK objects
Definition: vtkObject.h:60
virtual vtkMTimeType GetMTime()
Return this object's modified time.
OpenGL rendering window.
static vtkOpenGLVolumeRGBTable * New()
void ReleaseGraphicsResources(vtkWindow *window)
void Update(vtkColorTransferFunction *scalarRGB, double range[2], int filterValue, vtkOpenGLRenderWindow *renWin)
int GetMaximumSupportedTextureWidth(vtkOpenGLRenderWindow *renWin, int idealWidth)
void ReleaseGraphicsResources(vtkWindow *window)
vtkOpenGLVolumeRGBTables(unsigned int numberOfTables)
vtkOpenGLVolumeRGBTable * GetTable(unsigned int i)
abstracts an OpenGL texture object.
void Deactivate(unsigned int texUnit)
bool Create2DFromRaw(unsigned int width, unsigned int height, int numComps, int dataType, void *data)
Create a 2D texture from client memory numComps must be in [1-4].
virtual void SetWrapT(int)
void ReleaseGraphicsResources(vtkWindow *win)
Deactivate and UnBind the texture.
virtual void SetMagnificationFilter(int)
int GetTextureUnit()
Return the texture unit used for this texture.
static int GetMaximumTextureSize(vtkOpenGLRenderWindow *context)
Query and return maximum texture size (dimension) supported by the OpenGL driver for a particular con...
void Activate(unsigned int texUnit)
Set the active tex unit and bind (using our bind).
virtual void SetMinificationFilter(int)
static vtkTextureObject * New()
virtual void SetWrapS(int)
void SetContext(vtkRenderWindow *)
Get/Set the context.
record modification and/or execution time
Definition: vtkTimeStamp.h:36
void Modified()
Set this objects time to the current time.
window superclass for vtkRenderWindow
Definition: vtkWindow.h:35
@ range
Definition: vtkX3D.h:238
@ size
Definition: vtkX3D.h:253
vtkStandardNewMacro(vtkOpenGLVolumeRGBTable)
#define VTK_FLOAT
Definition: vtkType.h:58