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);
108  this->TextureObject->SetMagnificationFilter(filterValue);
109  this->TextureObject->SetMinificationFilter(filterValue);
112  VTK_FLOAT,
113  this->Table);
114  this->LastInterpolation = filterValue;
115  this->BuildTime.Modified();
116  }
117 
118  if (this->LastInterpolation != filterValue)
119  {
120  this->LastInterpolation = filterValue;
121  this->TextureObject->SetMagnificationFilter(filterValue);
122  this->TextureObject->SetMinificationFilter(filterValue);
123  }
124  }
125 
126  // Get the texture unit
127  //--------------------------------------------------------------------------
128  int GetTextureUnit(void)
129  {
130  if (!this->TextureObject)
131  {
132  return -1;
133  }
134  return this->TextureObject->GetTextureUnit();
135  }
136 
137  //--------------------------------------------------------------------------
139  {
140  if (this->TextureObject)
141  {
143  this->TextureObject->Delete();
144  this->TextureObject = 0;
145  }
146  }
147 
148 protected:
151 
153 
155  double LastRange[2];
156  float* Table;
158 };
159 
160 //----------------------------------------------------------------------------
162 {
163 public:
164  //--------------------------------------------------------------------------
165  vtkOpenGLVolumeRGBTables(unsigned int numberOfTables)
166  {
167  this->Tables = new vtkOpenGLVolumeRGBTable[numberOfTables];
168  this->NumberOfTables = numberOfTables;
169  }
170 
171  //--------------------------------------------------------------------------
173  {
174  delete [] this->Tables;
175  }
176 
177  // brief Get opacity table at a given index.
178  //--------------------------------------------------------------------------
180  {
181  if (i >= this->NumberOfTables)
182  {
183  return NULL;
184  }
185  return &this->Tables[i];
186  }
187 
188  // Get number of opacity tables.
189  //--------------------------------------------------------------------------
190  unsigned int GetNumberOfTables()
191  {
192  return this->NumberOfTables;
193  }
194 
195  //--------------------------------------------------------------------------
197  {
198  for (unsigned int i = 0; i <this->NumberOfTables; ++i)
199  {
200  this->Tables[i].ReleaseGraphicsResources(window);
201  }
202  }
203 
204 private:
205  unsigned int NumberOfTables;
206  vtkOpenGLVolumeRGBTable* Tables;
207 
208  // vtkOpenGLVolumeRGBTables (Not implemented)
210 
211  // vtkOpenGLVolumeRGBTables (Not implemented)
213 
214  // operator = (Not implemented)
215  vtkOpenGLVolumeRGBTables &operator=(const vtkOpenGLVolumeRGBTables &other);
216 };
217 
218 #endif // vtkOpenGLVolumeRGBTable_h_
219 // 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 Create1DFromRaw(unsigned int width, 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)
vtkOpenGLVolumeRGBTables(unsigned int numberOfTables)
virtual void Delete()
virtual void SetMagnificationFilter(int)