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
vtkOpenGLVolumeRGBTable::Activate
void Activate()
Definition: vtkOpenGLVolumeRGBTable.h:51
vtkTextureObject::ReleaseGraphicsResources
void ReleaseGraphicsResources(vtkWindow *win)
vtkOpenGLVolumeRGBTable::NumberOfColorComponents
int NumberOfColorComponents
Definition: vtkOpenGLVolumeRGBTable.h:150
vtkOpenGLVolumeRGBTables::~vtkOpenGLVolumeRGBTables
~vtkOpenGLVolumeRGBTables()
Definition: vtkOpenGLVolumeRGBTable.h:172
vtkOpenGLVolumeRGBTables
Definition: vtkOpenGLVolumeRGBTable.h:162
vtkTextureObject::SetMinificationFilter
virtual void SetMinificationFilter(int)
vtkTextureObject::SetWrapS
virtual void SetWrapS(int)
vtkOpenGLVolumeRGBTable::Table
float * Table
Definition: vtkOpenGLVolumeRGBTable.h:156
vtkTimeStamp
record modification and/or execution time
Definition: vtkTimeStamp.h:35
vtkOpenGLVolumeRGBTable::LastRange
double LastRange[2]
Definition: vtkOpenGLVolumeRGBTable.h:155
vtkColorTransferFunction::GetTable
void GetTable(double x1, double x2, int n, double *table)
vtkObject::GetMTime
virtual unsigned long GetMTime()
vtkObjectBase::Delete
virtual void Delete()
vtkOpenGLVolumeRGBTable::ReleaseGraphicsResources
void ReleaseGraphicsResources(vtkWindow *window)
Definition: vtkOpenGLVolumeRGBTable.h:138
vtkgl::range
GLenum GLint * range
Definition: vtkgl.h:14180
vtkColorTransferFunction
Defines a transfer function for mapping a property to an RGB color value.
Definition: vtkColorTransferFunction.h:58
vtkTextureObject::Activate
void Activate(unsigned int texUnit)
vtkTextureObject::GetTextureUnit
int GetTextureUnit()
vtkWindow
window superclass for vtkRenderWindow
Definition: vtkWindow.h:34
vtkColorTransferFunction.h
vtkOpenGLVolumeRGBTable::~vtkOpenGLVolumeRGBTable
~vtkOpenGLVolumeRGBTable()
Definition: vtkOpenGLVolumeRGBTable.h:39
vtkOpenGLVolumeRGBTables::GetNumberOfTables
unsigned int GetNumberOfTables()
Definition: vtkOpenGLVolumeRGBTable.h:190
vtkTimeStamp::Modified
void Modified()
vtkTextureObject::SetContext
void SetContext(vtkRenderWindow *)
vtkOpenGLVolumeRGBTable::BuildTime
vtkTimeStamp BuildTime
Definition: vtkOpenGLVolumeRGBTable.h:157
vtkOpenGLVolumeRGBTable::GetTextureUnit
int GetTextureUnit(void)
Definition: vtkOpenGLVolumeRGBTable.h:128
vtkTextureObject
abstracts an OpenGL texture object.
Definition: vtkTextureObject.h:40
vtkOpenGLVolumeRGBTable::Update
void Update(vtkColorTransferFunction *scalarRGB, double range[2], int filterValue, vtkOpenGLRenderWindow *renWin)
Definition: vtkOpenGLVolumeRGBTable.h:73
vtkTextureObject::New
static vtkTextureObject * New()
VTK_FLOAT
#define VTK_FLOAT
Definition: vtkType.h:35
vtkOpenGLVolumeRGBTable::Deactivate
void Deactivate()
Definition: vtkOpenGLVolumeRGBTable.h:62
vtkTextureObject::Deactivate
void Deactivate(unsigned int texUnit)
vtkTextureObject::SetMagnificationFilter
virtual void SetMagnificationFilter(int)
vtkOpenGLVolumeRGBTable::TextureObject
vtkTextureObject * TextureObject
Definition: vtkOpenGLVolumeRGBTable.h:152
vtkOpenGLVolumeRGBTable
Definition: vtkOpenGLVolumeRGBTable.h:25
vtkOpenGLVolumeRGBTable::vtkOpenGLVolumeRGBTable
vtkOpenGLVolumeRGBTable()
Definition: vtkOpenGLVolumeRGBTable.h:28
vtkTextureObject::Create1DFromRaw
bool Create1DFromRaw(unsigned int width, int numComps, int dataType, void *data)
vtkTextureObject::ClampToEdge
@ ClampToEdge
Definition: vtkTextureObject.h:71
vtkOpenGLVolumeRGBTables::vtkOpenGLVolumeRGBTables
vtkOpenGLVolumeRGBTables(unsigned int numberOfTables)
Definition: vtkOpenGLVolumeRGBTable.h:165
vtkOpenGLVolumeRGBTable::LastInterpolation
int LastInterpolation
Definition: vtkOpenGLVolumeRGBTable.h:154
vtkOpenGLRenderWindow
OpenGL rendering window.
Definition: vtkOpenGLRenderWindow.h:41
vtkOpenGLVolumeRGBTables::GetTable
vtkOpenGLVolumeRGBTable * GetTable(unsigned int i)
Definition: vtkOpenGLVolumeRGBTable.h:179
vtkOpenGLVolumeRGBTables::ReleaseGraphicsResources
void ReleaseGraphicsResources(vtkWindow *window)
Definition: vtkOpenGLVolumeRGBTable.h:196
vtkOpenGLVolumeRGBTable::TextureWidth
int TextureWidth
Definition: vtkOpenGLVolumeRGBTable.h:149