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 
20 #include <vtkTextureObject.h>
21 #include <vtk_glew.h>
22 
23 //----------------------------------------------------------------------------
25 {
26 public:
27  //--------------------------------------------------------------------------
29  {
30  this->TextureWidth = 1024;
31  this->NumberOfColorComponents = 3;
32  this->TextureObject = 0;
33  this->LastInterpolation = -1;
34  this->LastRange[0] = this->LastRange[1] = 0;
35  this->Table = 0;
36  }
37 
38  //--------------------------------------------------------------------------
40  {
41  if (this->TextureObject)
42  {
43  this->TextureObject->Delete();
44  this->TextureObject = 0;
45  }
46  delete[] this->Table;
47  }
48 
49  // Activate texture.
50  //--------------------------------------------------------------------------
51  void Activate()
52  {
53  if (!this->TextureObject)
54  {
55  return;
56  }
57  this->TextureObject->Activate();
58  }
59 
60  // Deactivate texture.
61  //--------------------------------------------------------------------------
62  void Deactivate()
63  {
64  if (!this->TextureObject)
65  {
66  return;
67  }
68  this->TextureObject->Deactivate();
69  }
70 
71  // Update color transfer function texture.
72  //--------------------------------------------------------------------------
74  double range[2],
75  int filterValue,
76  vtkOpenGLRenderWindow* renWin)
77  {
78  bool needUpdate = false;
79 
80  if (!this->TextureObject)
81  {
83  }
84 
85  this->TextureObject->SetContext(renWin);
86 
87  if (range[0] != this->LastRange[0] || range[1] != this->LastRange[1])
88  {
89  this->LastRange[0] = range[0];
90  this->LastRange[1] = range[1];
91  needUpdate = true;
92  }
93 
94  if (scalarRGB->GetMTime() > this->BuildTime ||
95  this->TextureObject->GetMTime() > this->BuildTime ||
96  needUpdate || !this->TextureObject->GetHandle())
97  {
98  // Create table if not created already
99  if(this->Table==0)
100  {
101  this->Table = new float[this->TextureWidth *
103  }
104 
105  scalarRGB->GetTable(this->LastRange[0], this->LastRange[1],
106  this->TextureWidth, this->Table);
109  this->TextureObject->SetMagnificationFilter(filterValue);
110  this->TextureObject->SetMinificationFilter(filterValue);
113  VTK_FLOAT,
114  this->Table);
115  this->LastInterpolation = 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:
152 
154 
156  double LastRange[2];
157  float* Table;
159 };
160 
161 //----------------------------------------------------------------------------
163 {
164 public:
165  //--------------------------------------------------------------------------
166  vtkOpenGLVolumeRGBTables(unsigned int numberOfTables)
167  {
168  this->Tables = new vtkOpenGLVolumeRGBTable[numberOfTables];
169  this->NumberOfTables = numberOfTables;
170  }
171 
172  //--------------------------------------------------------------------------
174  {
175  delete [] this->Tables;
176  }
177 
178  // brief Get opacity table at a given index.
179  //--------------------------------------------------------------------------
181  {
182  if (i >= this->NumberOfTables)
183  {
184  return NULL;
185  }
186  return &this->Tables[i];
187  }
188 
189  // Get number of opacity tables.
190  //--------------------------------------------------------------------------
191  unsigned int GetNumberOfTables()
192  {
193  return this->NumberOfTables;
194  }
195 
196  //--------------------------------------------------------------------------
198  {
199  for (unsigned int i = 0; i <this->NumberOfTables; ++i)
200  {
201  this->Tables[i].ReleaseGraphicsResources(window);
202  }
203  }
204 
205 private:
206  unsigned int NumberOfTables;
207  vtkOpenGLVolumeRGBTable* Tables;
208 
209  // vtkOpenGLVolumeRGBTables (Not implemented)
211 
212  // vtkOpenGLVolumeRGBTables (Not implemented)
214 
215  // operator = (Not implemented)
216  vtkOpenGLVolumeRGBTables &operator=(const vtkOpenGLVolumeRGBTables &other);
217 };
218 
219 #endif // vtkOpenGLVolumeRGBTable_h
220 // VTK-HeaderTest-Exclude: vtkOpenGLVolumeRGBTable.h
OpenGL rendering window.
void GetTable(double x1, double x2, int n, double *table)
void SetContext(vtkRenderWindow *)
void ReleaseGraphicsResources(vtkWindow *window)
record modification and/or execution time
Definition: vtkTimeStamp.h:34
void Modified()
void Deactivate(unsigned int texUnit)
void Update(vtkColorTransferFunction *scalarRGB, double range[2], int filterValue, vtkOpenGLRenderWindow *renWin)
bool Create2DFromRaw(unsigned int width, unsigned int height, int numComps, int dataType, void *data)
window superclass for vtkRenderWindow
Definition: vtkWindow.h:36
#define VTK_FLOAT
Definition: vtkType.h:35
virtual unsigned long GetMTime()
virtual void SetMinificationFilter(int)
virtual unsigned int GetHandle()
void Activate(unsigned int texUnit)
vtkOpenGLVolumeRGBTable * GetTable(unsigned int i)
abstracts an OpenGL texture object.
Defines a transfer function for mapping a property to an RGB color value.
void ReleaseGraphicsResources(vtkWindow *win)
static vtkTextureObject * New()
virtual void SetWrapS(int)
void ReleaseGraphicsResources(vtkWindow *window)
virtual void SetWrapT(int)
vtkOpenGLVolumeRGBTables(unsigned int numberOfTables)
virtual void Delete()
virtual void SetMagnificationFilter(int)