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  if(this->Table)
47  {
48  delete[] this->Table;
49  this->Table=0;
50  }
51  }
52 
53  // Bind texture.
54  //--------------------------------------------------------------------------
55  void Bind(void)
56  {
57  if (!this->TextureObject)
58  {
59  return;
60  }
61  this->TextureObject->Activate();
62  }
63 
64  // Update color transfer function texture.
65  //--------------------------------------------------------------------------
67  double range[2],
68  int filterValue,
69  vtkOpenGLRenderWindow* renWin)
70  {
71  bool needUpdate = false;
72 
73  if (!this->TextureObject)
74  {
76  }
77 
78  this->TextureObject->SetContext(renWin);
79 
80  if (range[0] != this->LastRange[0] || range[1] != this->LastRange[1])
81  {
82  this->LastRange[0] = range[0];
83  this->LastRange[1] = range[1];
84  needUpdate = true;
85  }
86 
87  if (scalarRGB->GetMTime() > this->BuildTime ||
88  this->TextureObject->GetMTime() > this->BuildTime ||
89  needUpdate || !this->TextureObject->GetHandle())
90  {
91  // Create table if not created already
92  if(this->Table==0)
93  {
94  this->Table = new float[this->TextureWidth *
96  }
97 
98  scalarRGB->GetTable(this->LastRange[0], this->LastRange[1],
99  this->TextureWidth, this->Table);
101  this->TextureObject->SetMagnificationFilter(filterValue);
102  this->TextureObject->SetMinificationFilter(filterValue);
105  VTK_FLOAT,
106  this->Table);
107  this->LastInterpolation = filterValue;
108  this->TextureObject->Activate();
109  this->BuildTime.Modified();
110  }
111 
112  if (this->LastInterpolation != filterValue)
113  {
114  this->LastInterpolation = filterValue;
115  this->TextureObject->SetMagnificationFilter(filterValue);
116  this->TextureObject->SetMinificationFilter(filterValue);
117  }
118  }
119 
120  // Get the texture unit
121  //--------------------------------------------------------------------------
122  int GetTextureUnit(void)
123  {
124  if (!this->TextureObject)
125  {
126  return -1;
127  }
128  return this->TextureObject->GetTextureUnit();
129  }
130 
131  //--------------------------------------------------------------------------
133  {
134  if (this->TextureObject)
135  {
137  this->TextureObject->Delete();
138  this->TextureObject = 0;
139  }
140  }
141 
142 protected:
145 
147 
149  double LastRange[2];
150  float* Table;
152 };
153 
154 //----------------------------------------------------------------------------
156 {
157 public:
158  //--------------------------------------------------------------------------
159  vtkOpenGLVolumeRGBTables(unsigned int numberOfTables)
160  {
161  this->Tables = new vtkOpenGLVolumeRGBTable[numberOfTables];
162  this->NumberOfTables = numberOfTables;
163  }
164 
165  //--------------------------------------------------------------------------
167  {
168  delete [] this->Tables;
169  }
170 
171  // brief Get opacity table at a given index.
172  //--------------------------------------------------------------------------
174  {
175  if (i >= this->NumberOfTables)
176  {
177  return NULL;
178  }
179  return &this->Tables[i];
180  }
181 
182  // Get number of opacity tables.
183  //--------------------------------------------------------------------------
184  unsigned int GetNumberOfTables()
185  {
186  return this->NumberOfTables;
187  }
188 
189  //--------------------------------------------------------------------------
191  {
192  for (unsigned int i = 0; i <this->NumberOfTables; ++i)
193  {
194  this->Tables[i].ReleaseGraphicsResources(window);
195  }
196  }
197 
198 private:
199  unsigned int NumberOfTables;
200  vtkOpenGLVolumeRGBTable* Tables;
201 
202  // vtkOpenGLVolumeRGBTables (Not implemented)
204 
205  // vtkOpenGLVolumeRGBTables (Not implemented)
207 
208  // operator = (Not implemented)
209  vtkOpenGLVolumeRGBTables &operator=(const vtkOpenGLVolumeRGBTables &other);
210 };
211 
212 #endif // vtkOpenGLVolumeRGBTable_h_
213 // 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 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:33
#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)
GLenum GLint * range
Definition: vtkgl.h:14180
vtkOpenGLVolumeRGBTables(unsigned int numberOfTables)
virtual void Delete()
virtual void SetMagnificationFilter(int)