VTK
|
00001 /*========================================================================= 00002 00003 Program: Visualization Toolkit 00004 Module: vtkOpenGLVolumeGradientOpacityTable.h 00005 00006 Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen 00007 All rights reserved. 00008 See Copyright.txt or http://www.kitware.com/Copyright.htm for details. 00009 00010 This software is distributed WITHOUT ANY WARRANTY; without even 00011 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 00012 PURPOSE. See the above copyright notice for more information. 00013 00014 =========================================================================*/ 00015 00016 #ifndef vtkOpenGLVolumeGradientOpacityTable_h_ 00017 #define vtkOpenGLVolumeGradientOpacityTable_h_ 00018 00019 #include <vtkPiecewiseFunction.h> 00020 #include <vtkTextureObject.h> 00021 #include <vtkVolumeMapper.h> 00022 00023 #include <vtk_glew.h> 00024 00025 //---------------------------------------------------------------------------- 00026 class vtkOpenGLVolumeGradientOpacityTable 00027 { 00028 public: 00029 //-------------------------------------------------------------------------- 00030 vtkOpenGLVolumeGradientOpacityTable(int width = 1024) 00031 { 00032 this->TextureObject = 0; 00033 this->TextureWidth = width; 00034 this->LastSampleDistance = 1.0; 00035 this->Table = 0; 00036 this->LastInterpolation = -1; 00037 this->LastRange[0] = this->LastRange[1] = 0.0; 00038 } 00039 00040 //-------------------------------------------------------------------------- 00041 ~vtkOpenGLVolumeGradientOpacityTable() 00042 { 00043 if (this->TextureObject) 00044 { 00045 this->TextureObject->Delete(); 00046 this->TextureObject = 0; 00047 } 00048 00049 if (this->Table) 00050 { 00051 delete[] this->Table; 00052 this->Table=0; 00053 } 00054 } 00055 00056 // Bind texture. 00057 //-------------------------------------------------------------------------- 00058 void Bind() 00059 { 00060 if (!this->TextureObject) 00061 { 00062 return; 00063 } 00064 this->TextureObject->Activate(); 00065 } 00066 00067 // Update opacity tranfer function texture. 00068 //-------------------------------------------------------------------------- 00069 void Update(vtkPiecewiseFunction* gradientOpacity, 00070 double sampleDistance, 00071 double range[2], 00072 double vtkNotUsed(unitDistance), 00073 int filterValue, 00074 vtkOpenGLRenderWindow* renWin) 00075 { 00076 bool needUpdate=false; 00077 00078 if (!this->TextureObject) 00079 { 00080 this->TextureObject = vtkTextureObject::New(); 00081 } 00082 00083 this->TextureObject->SetContext(renWin); 00084 00085 if (this->LastRange[0] != range[0] || 00086 this->LastRange[1] != range[1]) 00087 { 00088 this->LastRange[0] = range[0]; 00089 this->LastRange[1] = range[1]; 00090 needUpdate = true; 00091 } 00092 00093 if(gradientOpacity->GetMTime() > this->BuildTime || 00094 this->TextureObject->GetMTime() > this->BuildTime || 00095 this->LastSampleDistance != sampleDistance || 00096 needUpdate || !this->TextureObject->GetHandle()) 00097 { 00098 if(this->Table == 0) 00099 { 00100 this->Table = new float[this->TextureWidth]; 00101 } 00102 00103 gradientOpacity->GetTable(0, 00104 (this->LastRange[1] - this->LastRange[0]) * 0.25, 00105 this->TextureWidth, this->Table); 00106 00107 this->TextureObject->CreateAlphaFromRaw(this->TextureWidth, 00108 vtkTextureObject::alpha16, 00109 VTK_FLOAT, 00110 this->Table); 00111 00112 this->TextureObject->Activate(); 00113 this->TextureObject->SetWrapS(vtkTextureObject::ClampToEdge); 00114 this->TextureObject->SetMagnificationFilter(filterValue); 00115 this->TextureObject->SetMinificationFilter(filterValue); 00116 this->BuildTime.Modified(); 00117 } 00118 00119 if(this->LastInterpolation != filterValue) 00120 { 00121 this->LastInterpolation = filterValue; 00122 this->TextureObject->SetMagnificationFilter(filterValue); 00123 this->TextureObject->SetMinificationFilter(filterValue); 00124 } 00125 } 00126 00127 // Get the texture unit 00128 //-------------------------------------------------------------------------- 00129 int GetTextureUnit(void) 00130 { 00131 if (!this->TextureObject) 00132 { 00133 return -1; 00134 } 00135 return this->TextureObject->GetTextureUnit(); 00136 } 00137 00138 //-------------------------------------------------------------------------- 00139 void ReleaseGraphicsResources(vtkWindow *window) 00140 { 00141 if (this->TextureObject) 00142 { 00143 this->TextureObject->ReleaseGraphicsResources(window); 00144 this->TextureObject->Delete(); 00145 this->TextureObject = 0; 00146 } 00147 } 00148 00149 protected: 00150 // GLuint TextureId; 00151 vtkTextureObject* TextureObject; 00152 int TextureWidth; 00153 00154 double LastSampleDistance; 00155 vtkTimeStamp BuildTime; 00156 float* Table; 00157 int LastInterpolation; 00158 double LastRange[2]; 00159 private: 00160 vtkOpenGLVolumeGradientOpacityTable(const vtkOpenGLVolumeGradientOpacityTable&); 00161 vtkOpenGLVolumeGradientOpacityTable& operator=(const vtkOpenGLVolumeGradientOpacityTable&); 00162 }; 00163 00164 //----------------------------------------------------------------------------- 00165 class vtkOpenGLVolumeGradientOpacityTables 00166 { 00167 public: 00168 //-------------------------------------------------------------------------- 00169 vtkOpenGLVolumeGradientOpacityTables(unsigned int numberOfTables) 00170 { 00171 this->Tables = new vtkOpenGLVolumeGradientOpacityTable[numberOfTables]; 00172 this->NumberOfTables = numberOfTables; 00173 } 00174 00175 //-------------------------------------------------------------------------- 00176 ~vtkOpenGLVolumeGradientOpacityTables() 00177 { 00178 delete [] this->Tables; 00179 } 00180 00181 // Get opacity table at a given index. 00182 //-------------------------------------------------------------------------- 00183 vtkOpenGLVolumeGradientOpacityTable* GetTable(unsigned int i) 00184 { 00185 if (i >= this->NumberOfTables) 00186 { 00187 return NULL; 00188 } 00189 return &this->Tables[i]; 00190 } 00191 00192 // Get number of tables. 00193 //-------------------------------------------------------------------------- 00194 unsigned int GetNumberOfTables() 00195 { 00196 return this->NumberOfTables; 00197 } 00198 00199 //-------------------------------------------------------------------------- 00200 void ReleaseGraphicsResources(vtkWindow *window) 00201 { 00202 for (unsigned int i = 0; i < this->NumberOfTables; ++i) 00203 { 00204 this->Tables[i].ReleaseGraphicsResources(window); 00205 } 00206 } 00207 private: 00208 unsigned int NumberOfTables; 00209 vtkOpenGLVolumeGradientOpacityTable* Tables; 00210 00211 // vtkOpenGLVolumeGradientOpacityTables (Not implemented) 00212 vtkOpenGLVolumeGradientOpacityTables(); 00213 00214 // vtkOpenGLVolumeGradientOpacityTables (Not implemented) 00215 vtkOpenGLVolumeGradientOpacityTables(const vtkOpenGLVolumeGradientOpacityTables &other); 00216 00217 // operator = (Not implemented) 00218 vtkOpenGLVolumeGradientOpacityTables &operator=(const vtkOpenGLVolumeGradientOpacityTables &other); 00219 }; 00220 00221 #endif // vtkOpenGLVolumeGradientOpacityTable_h_ 00222 // VTK-HeaderTest-Exclude: vtkOpenGLVolumeGradientOpacityTable.h