32 #ifndef vtkOpenGLContextDevice2DPrivate_h
33 #define vtkOpenGLContextDevice2DPrivate_h
68 struct CacheElement:
public std::pair<Key, CacheData>
80 : std::pair<Key,
CacheData>(key, cacheData){}
87 return this->first == other.first;
121 typename std::list<CacheElement >::iterator it;
122 for (it = this->
Cache.begin(); it != this->
Cache.end(); ++it)
124 it->second.Texture->ReleaseGraphicsResources(window);
138 this->
Cache.pop_back();
140 this->
Cache.push_front(CacheElement(key, cacheData));
141 return this->
Cache.begin()->second;
146 std::list<CacheElement >
Cache;
157 typename std::list<CacheElement>::iterator it =
158 std::find(this->Cache.begin(), this->Cache.end(), CacheElement(key));
159 if (it != this->Cache.end())
166 cacheData.Texture->SetInputData(cacheData.ImageData);
167 cacheData.TextWidth = 0;
168 cacheData.TextHeight = 0;
169 return this->AddCacheData(key, cacheData);
175 template <
class StringType>
185 return static_cast<unsigned int>(id);
198 this->
Color.
Set(static_cast<unsigned char>(color[0] * 255),
199 static_cast<unsigned char>(color[1] * 255),
200 static_cast<unsigned char>(color[2] * 255),
201 static_cast<unsigned char>(textProperty->
GetOpacity() * 255));
301 bool colorDiffer =
false;
302 while(!colorDiffer && i < 4)
320 glEnable(capability);
324 glDisable(capability);
330 float* texCoord =
new float[2*n];
331 float minX = f[0];
float minY = f[1];
332 float maxX = f[0];
float maxY = f[1];
334 for(
int i = 0; i < n; ++i)
336 minX = fptr[0] < minX ? fptr[0] : minX;
337 maxX = fptr[0] > maxX ? fptr[0] : maxX;
338 minY = fptr[1] < minY ? fptr[1] : minY;
339 maxY = fptr[1] > maxY ? fptr[1] : maxY;
346 float rangeX = (textureBounds[1] - textureBounds[0]) ?
347 textureBounds[1] - textureBounds[0] : 1.;
348 float rangeY = (textureBounds[3] - textureBounds[2]) ?
349 textureBounds[3] - textureBounds[2] : 1.;
350 for (
int i = 0; i < n; ++i)
352 texCoord[i*2] = (fptr[0]-minX) / rangeX;
353 texCoord[i*2+1] = (fptr[1]-minY) / rangeY;
359 float rangeX = (maxX - minX)? maxX - minX : 1.f;
360 float rangeY = (maxY - minY)? maxY - minY : 1.f;
361 for (
int i = 0; i < n; ++i)
363 texCoord[i*2] = (fptr[0]-minX)/rangeX;
364 texCoord[i*2+1] = (fptr[1]-minY)/rangeY;
374 for (
int i = 0; i < 2; ++i)
376 while (pow2[i] < size[i])
388 cout <<
"Error = not an unsigned char..." << endl;
396 for (
int i = 0; i < 2; ++i)
398 texCoords[i] = size[i] /
float(newImg[i]);
401 unsigned char *dataPtr =
402 new unsigned char[newImg[0] * newImg[1] * bytesPerPixel];
403 unsigned char *origPtr =
406 for (
int i = 0; i < newImg[0]; ++i)
408 for (
int j = 0; j < newImg[1]; ++j)
410 for (
int k = 0; k < bytesPerPixel; ++k)
412 if (i < size[0] && j < size[1])
414 dataPtr[i * bytesPerPixel + j * newImg[0] * bytesPerPixel + k] =
415 origPtr[i * bytesPerPixel + j * size[0] * bytesPerPixel + k];
419 dataPtr[i * bytesPerPixel + j * newImg[0] * bytesPerPixel + k] =
427 GLint glFormat = bytesPerPixel == 3 ? GL_RGB : GL_RGBA;
428 GLint glInternalFormat = bytesPerPixel == 3 ? GL_RGB8 : GL_RGBA8;
430 glGenTextures(1, &tmpIndex);
431 glBindTexture(GL_TEXTURE_2D, tmpIndex);
433 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
434 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
435 glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S,
437 glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T,
440 glTexImage2D(GL_TEXTURE_2D, 0 , glInternalFormat,
441 newImg[0], newImg[1], 0, glFormat,
442 GL_UNSIGNED_BYTE, static_cast<const GLvoid *>(dataPtr));
451 cout <<
"Error = not an unsigned char..." << endl;
458 unsigned char *dataPtr =
461 GLint glFormat = bytesPerPixel == 3 ? GL_RGB : GL_RGBA;
462 GLint glInternalFormat = bytesPerPixel == 3 ? GL_RGB8 : GL_RGBA8;
464 glGenTextures(1, &tmpIndex);
465 glBindTexture(GL_TEXTURE_2D, tmpIndex);
467 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
468 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
469 glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S,
471 glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T,
474 glTexImage2D(GL_TEXTURE_2D, 0 , glInternalFormat,
475 size[0], size[1], 0, glFormat,
476 GL_UNSIGNED_BYTE, static_cast<const GLvoid *>(dataPtr));
506 #endif // VTKOPENGLCONTEXTDEVICE2DPRIVATE_H
std::list< CacheElement > Cache
GLuint TextureFromImage(vtkImageData *image)
bool operator==(const CacheElement &other) const
void SetGLCapability(GLenum capability, GLboolean state)
static int GetNumberOfScalarComponents(vtkInformation *meta_data)
GLuint TextureFromImage(vtkImageData *image, vtkVector2f &texCoords)
bool IsKeyInCache(const Key &key) const
TextPropertyKey(vtkTextProperty *textProperty, const StringType &text, int dpi)
vtkSmartPointer< vtkTexture > Texture
static vtkSmartPointer< T > New()
CacheElement(const Key &key, const CacheData &cacheData)
void ReleaseGraphicsResources(vtkWindow *window)
vtkSmartPointer< vtkImageData > ImageData
bool operator==(const TextPropertyKey &other) const
float * TexCoords(float *f, int n)
TextPropertyKey< vtkStdString > UTF8TextPropertyKey
window superclass for vtkRenderWindow
virtual int * GetDimensions()
static int GetScalarType(vtkInformation *meta_data)
topologically and geometrically regular array of data
vtkImageData * GetInput()
CacheData & GetCacheData(const Key &key)
void Set(const T &red, const T &green, const T &blue)
handles properties associated with a texture map
virtual double GetOpacity()
represent text properties.
vtkTextureImageCache< UTF16TextPropertyKey > TextTextureCache
static unsigned int GetIdFromTextProperty(vtkTextProperty *textProperty)
CacheElement(const Key &key)
virtual double * GetColor()
GLfloat SavedClearColor[4]
#define VTK_UNSIGNED_CHAR
virtual void * GetScalarPointer(int coordinates[3])
vtkTexture * SpriteTexture
unsigned int TextureProperties
vtkVector2i FindPowerOfTwo(const vtkVector2i &size)
virtual int GetFontSize()
TextPropertyKey< vtkUnicodeString > UTF16TextPropertyKey
CacheData & AddCacheData(const Key &key, const CacheData &cacheData)
unsigned int TextPropertyId
GLboolean SavedStencilTest
void RestoreGLState(bool colorBuffer=false)
void SaveGLState(bool colorBuffer=false)
vtkTextureImageCache< UTF8TextPropertyKey > MathTextTextureCache