33 #ifndef vtkOpenGLContextDevice2DPrivate_h 34 #define vtkOpenGLContextDevice2DPrivate_h 91 return this->first == other.first;
128 typename std::list<CacheElement >::iterator it;
129 for (it = this->
Cache.begin(); it != this->
Cache.end(); ++it)
131 it->second.Texture->ReleaseGraphicsResources(window);
147 this->
Cache.pop_back();
149 this->
Cache.push_front(CacheElement(
key, cacheData));
150 return this->
Cache.begin()->second;
170 typename std::list<CacheElement>::iterator it =
171 std::find(this->Cache.begin(), this->Cache.end(), CacheElement(
key));
172 if (it != this->Cache.end())
179 cacheData.Texture->SetInputData(cacheData.ImageData);
180 return this->AddCacheData(
key, cacheData);
186 template <
class StringType>
203 vtkTypeUInt32 hash = static_cast<vtkTypeUInt32>(
id);
207 assert(
"Hash is really a uint32" && static_cast<size_t>(hash) ==
id);
233 static_cast<unsigned char>(
color[1] * 255),
234 static_cast<unsigned char>(
color[2] * 255),
235 static_cast<unsigned char>(textProperty->
GetOpacity() * 255));
340 bool colorDiffer =
false;
341 while(!colorDiffer && i < 4)
359 glEnable(capability);
363 glDisable(capability);
369 float* texCoord =
new float[2*n];
370 float minX = f[0];
float minY = f[1];
371 float maxX = f[0];
float maxY = f[1];
373 for(
int i = 0; i < n; ++i)
375 minX = fptr[0] < minX ? fptr[0] : minX;
376 maxX = fptr[0] > maxX ? fptr[0] : maxX;
377 minY = fptr[1] < minY ? fptr[1] : minY;
378 maxY = fptr[1] > maxY ? fptr[1] : maxY;
385 float rangeX = (textureBounds[1] - textureBounds[0]) ?
386 textureBounds[1] - textureBounds[0] : 1.;
387 float rangeY = (textureBounds[3] - textureBounds[2]) ?
388 textureBounds[3] - textureBounds[2] : 1.;
389 for (
int i = 0; i < n; ++i)
391 texCoord[i*2] = (fptr[0]-minX) / rangeX;
392 texCoord[i*2+1] = (fptr[1]-minY) / rangeY;
398 float rangeX = (maxX - minX)? maxX - minX : 1.f;
399 float rangeY = (maxY - minY)? maxY - minY : 1.f;
400 for (
int i = 0; i < n; ++i)
402 texCoord[i*2] = (fptr[0]-minX)/rangeX;
403 texCoord[i*2+1] = (fptr[1]-minY)/rangeY;
413 for (
int i = 0; i < 2; ++i)
415 while (pow2[i] <
size[i])
427 cout <<
"Error = not an unsigned char..." << endl;
430 int bytesPerPixel =
image->GetNumberOfScalarComponents();
435 for (
int i = 0; i < 2; ++i)
437 texCoords[i] =
size[i] /
float(newImg[i]);
440 unsigned char *dataPtr =
441 new unsigned char[newImg[0] * newImg[1] * bytesPerPixel];
442 unsigned char *origPtr =
443 static_cast<unsigned char*>(
image->GetScalarPointer());
445 for (
int i = 0; i < newImg[0]; ++i)
447 for (
int j = 0; j < newImg[1]; ++j)
449 for (
int k = 0; k < bytesPerPixel; ++k)
453 dataPtr[i * bytesPerPixel + j * newImg[0] * bytesPerPixel + k] =
454 origPtr[i * bytesPerPixel + j *
size[0] * bytesPerPixel + k];
458 dataPtr[i * bytesPerPixel + j * newImg[0] * bytesPerPixel + k] =
466 GLint glFormat = bytesPerPixel == 3 ? GL_RGB : GL_RGBA;
467 GLint glInternalFormat = bytesPerPixel == 3 ? GL_RGB8 : GL_RGBA8;
469 glGenTextures(1, &tmpIndex);
470 glBindTexture(GL_TEXTURE_2D, tmpIndex);
472 glTexEnvf(GL_TEXTURE_ENV, vtkgl::COMBINE_RGB, GL_REPLACE);
473 glTexEnvf(GL_TEXTURE_ENV, vtkgl::COMBINE_ALPHA, GL_REPLACE);
475 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
476 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
477 glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S,
478 vtkgl::CLAMP_TO_EDGE );
479 glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T,
480 vtkgl::CLAMP_TO_EDGE );
482 glTexImage2D(GL_TEXTURE_2D, 0 , glInternalFormat,
483 newImg[0], newImg[1], 0, glFormat,
484 GL_UNSIGNED_BYTE, static_cast<const GLvoid *>(dataPtr));
485 glAlphaFunc(GL_GREATER, static_cast<GLclampf>(0));
486 glEnable(GL_ALPHA_TEST);
487 glMatrixMode(GL_TEXTURE);
489 glMatrixMode(GL_MODELVIEW);
490 glEnable(GL_TEXTURE_2D);
499 cout <<
"Error = not an unsigned char..." << endl;
502 int bytesPerPixel =
image->GetNumberOfScalarComponents();
506 unsigned char *dataPtr =
507 static_cast<unsigned char*>(
image->GetScalarPointer());
509 GLint glFormat = bytesPerPixel == 3 ? GL_RGB : GL_RGBA;
510 GLint glInternalFormat = bytesPerPixel == 3 ? GL_RGB8 : GL_RGBA8;
512 glGenTextures(1, &tmpIndex);
513 glBindTexture(GL_TEXTURE_2D, tmpIndex);
515 glTexEnvf(GL_TEXTURE_ENV, vtkgl::COMBINE_RGB, GL_REPLACE);
516 glTexEnvf(GL_TEXTURE_ENV, vtkgl::COMBINE_ALPHA, GL_REPLACE);
518 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
519 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
520 glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S,
521 vtkgl::CLAMP_TO_EDGE );
522 glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T,
523 vtkgl::CLAMP_TO_EDGE );
525 glTexImage2D(GL_TEXTURE_2D, 0 , glInternalFormat,
527 GL_UNSIGNED_BYTE, static_cast<const GLvoid *>(dataPtr));
528 glAlphaFunc(GL_GREATER, static_cast<GLclampf>(0));
529 glEnable(GL_ALPHA_TEST);
530 glMatrixMode(GL_TEXTURE);
532 glMatrixMode(GL_MODELVIEW);
533 glEnable(GL_TEXTURE_2D);
568 #endif // VTKOPENGLCONTEXTDEVICE2DPRIVATE_H
std::list< CacheElement > Cache
List of a pair of key and cache data.
GLuint TextureFromImage(vtkImageData *image)
virtual int GetJustification()
Set/Get the horizontal justification to left (default), centered, or right.
bool operator==(const CacheElement &other) const
void SetGLCapability(GLenum capability, GLboolean state)
double * GetBounds()
Return a pointer to the geometry bounding box in the form (xmin,xmax, ymin,ymax, zmin,...
vtkTextRenderer::Metrics Metrics
GLuint TextureFromImage(vtkImageData *image, vtkVector2f &texCoords)
vtkTypeUInt32 TextPropertyId
TextPropertyKey(vtkTextProperty *textProperty, const StringType &text, int dpi)
Creates a TextPropertyKey.
vtkSmartPointer< vtkTexture > Texture
static vtkSmartPointer< T > New()
Create an instance of a VTK object.
CacheElement(const Key &key, const CacheData &cacheData)
void ReleaseGraphicsResources(vtkWindow *window)
Release all the OpenGL Pixel Buffer Object(PBO) associated with the textures of the cache list.
vtkSmartPointer< vtkImageData > ImageData
float * TexCoords(float *f, int n)
TextPropertyKey< vtkStdString > UTF8TextPropertyKey
window superclass for vtkRenderWindow
size_t MaxSize
Maximum size the cache list can be.
bool operator==(const TextPropertyKey &other) const
Compares two TextPropertyKeys with each other.
topologically and geometrically regular array of data
vtkImageData * GetInput()
Get the input as a vtkImageData object.
Some derived classes for the different vectors commonly used.
virtual int GetVerticalJustification()
Set/Get the vertical justification to bottom (default), middle, or top.
CacheData & GetCacheData(const Key &key)
Return the cache associated to a key.
void Set(const T &red, const T &green, const T &blue)
Set the red, green and blue components of the color.
bool IsKeyInCache(const Key &key) const
Search the cache list to see if a given key already exists.
handles properties associated with a texture map
vtkTextureImageCache()
Construct a texture image cache with a maximum number of texture of 50.
virtual double GetOpacity()
Set/Get the text's opacity.
represent text properties.
vtkTextureImageCache< UTF16TextPropertyKey > TextTextureCache
Cache for text images.
CacheElement(const Key &key)
virtual double * GetColor()
Set the color of the text.
GLfloat SavedClearColor[4]
#define VTK_UNSIGNED_CHAR
vtkTexture * SpriteTexture
unsigned int TextureProperties
CacheElement associates a unique key to some cache.
vtkVector2i FindPowerOfTwo(const vtkVector2i &size)
virtual int GetFontSize()
Set/Get the font size (in points).
TextPropertyKey< vtkUnicodeString > UTF16TextPropertyKey
static vtkTypeUInt32 GetIdFromTextProperty(vtkTextProperty *tprop)
Transform a text property into an unsigned long.
CacheData & AddCacheData(const Key &key, const CacheData &cacheData)
Add a new cache entry into the cache list.
GLboolean SavedStencilTest
void RestoreGLState(bool colorBuffer=false)
void SaveGLState(bool colorBuffer=false)
virtual void Delete()
Delete a VTK object.
vtkTextureImageCache< UTF8TextPropertyKey > MathTextTextureCache
Cache for text images.