VTK
vtkOpenGLRGBTable.h
Go to the documentation of this file.
1 /*=========================================================================
2 
3  Program: Visualization Toolkit
4  Module: vtkOpenGLRGBTable.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 vtkOpenGLRGBTable_h_
17 #define vtkOpenGLRGBTable_h_
18 
20 #include <vtk_glew.h>
21 
22 //----------------------------------------------------------------------------
24 {
25 public:
26  //--------------------------------------------------------------------------
28  {
29  this->Loaded = false;
30  this->LastLinearInterpolation = false;
31  this->TexutureWidth = 1024;
32  this->NumberOfColorComponents = 3;
33  this->TextureId = 0;
34  this->LastRange[0] = this->LastRange[1] = 0;
35  this->Table = 0;
36  }
37 
38  //--------------------------------------------------------------------------
40  {
41  if(this->TextureId!=0)
42  {
43  glDeleteTextures(1,&this->TextureId);
44  this->TextureId=0;
45  }
46  if(this->Table!=0)
47  {
48  delete[] this->Table;
49  this->Table=0;
50  }
51  }
52 
53  // Check if color transfer function texture is loaded.
54  //--------------------------------------------------------------------------
55  bool IsLoaded()
56  {
57  return this->Loaded;
58  }
59 
60  // Bind texture.
61  //--------------------------------------------------------------------------
62  void Bind(int textureUnit = 1)
63  {
64  // Activate texture 1
65  glActiveTexture(GL_TEXTURE0 + textureUnit);
66  glBindTexture(GL_TEXTURE_1D, this->TextureId);
67  }
68 
69  // Update color transfer function texture.
70  //--------------------------------------------------------------------------
72  double range[2],
73  bool linearInterpolation, int textureUnit = 1)
74  {
75  // Activate texture 1
76  glActiveTexture(GL_TEXTURE0 + textureUnit);
77 
78  bool needUpdate = false;
79 
80  if(this->TextureId == 0)
81  {
82  glGenTextures(1, &this->TextureId);
83  needUpdate = true;
84  }
85 
86  if (range[0] != this->LastRange[0] || range[1] != this->LastRange[1])
87  {
88  needUpdate=true;
89  }
90 
91  glBindTexture(GL_TEXTURE_1D, this->TextureId);
92  if(needUpdate)
93  {
94  glTexParameteri(GL_TEXTURE_1D, GL_TEXTURE_WRAP_S,
95  GL_CLAMP_TO_EDGE);
96  }
97  if(scalarRGB->GetMTime() > this->BuildTime || needUpdate || !this->Loaded)
98  {
99  this->Loaded = false;
100 
101  // Create table if not created already
102  if(this->Table==0)
103  {
104  this->Table = new float[this->TexutureWidth *
106  }
107 
108  scalarRGB->GetTable(range[0],range[1], this->TexutureWidth, this->Table);
109  glTexImage1D(GL_TEXTURE_1D, 0, GL_RGB16, this->TexutureWidth, 0,
110  GL_RGB, GL_FLOAT, this->Table);
111 
112  this->Loaded = true;
113  this->BuildTime.Modified();
114 
115  this->LastRange[0] = range[0];
116  this->LastRange[1] = range[1];
117  }
118 
119  needUpdate = needUpdate ||
120  this->LastLinearInterpolation!=linearInterpolation;
121  if (needUpdate)
122  {
123  this->LastLinearInterpolation = linearInterpolation;
124  GLint value;
125  if (linearInterpolation)
126  {
127  value = GL_LINEAR;
128  }
129  else
130  {
131  value = GL_NEAREST;
132  }
133  glTexParameteri(GL_TEXTURE_1D, GL_TEXTURE_MIN_FILTER, value);
134  glTexParameteri(GL_TEXTURE_1D, GL_TEXTURE_MAG_FILTER, value);
135  }
136 
137  glActiveTexture(GL_TEXTURE0);
138  }
139 
140 protected:
141 
142  bool Loaded;
144 
147 
149 
150  double LastRange[2];
151  float* Table;
153 };
154 
155 #endif // vtkOpenGLRGBTable_h_
156 // VTK-HeaderTest-Exclude: vtkOpenGLRGBTable.h
void GetTable(double x1, double x2, int n, double *table)
vtkTimeStamp BuildTime
void Update(vtkColorTransferFunction *scalarRGB, double range[2], bool linearInterpolation, int textureUnit=1)
typedef GLuint(APIENTRYP PFNGLCREATEPROGRAMPROC)(void)
record modification and/or execution time
Definition: vtkTimeStamp.h:34
void Modified()
GLsizei const GLfloat * value
Definition: vtkgl.h:12021
virtual unsigned long GetMTime()
typedef GLint(APIENTRYP PFNGLGETATTRIBLOCATIONPROC)(GLuint program
Defines a transfer function for mapping a property to an RGB color value.
GLenum GLint * range
Definition: vtkgl.h:14180
void Bind(int textureUnit=1)