33 #ifndef vtkOpenGLContextDevice2DPrivate_h
34 #define vtkOpenGLContextDevice2DPrivate_h
71 struct CacheElement:
public std::pair<Key, CacheData>
83 : std::pair<Key,
CacheData>(key, cacheData){}
90 return this->first == other.first;
127 typename std::list<CacheElement >::iterator it;
128 for (it = this->
Cache.begin(); it != this->
Cache.end(); ++it)
130 it->second.Texture->ReleaseGraphicsResources(window);
146 this->
Cache.pop_back();
148 this->
Cache.push_front(CacheElement(key, cacheData));
149 return this->
Cache.begin()->second;
156 std::list<CacheElement >
Cache;
169 typename std::list<CacheElement>::iterator it =
170 std::find(this->Cache.begin(), this->Cache.end(), CacheElement(key));
171 if (it != this->Cache.end())
178 cacheData.Texture->SetInputData(cacheData.ImageData);
179 cacheData.TextWidth = 0;
180 cacheData.TextHeight = 0;
181 return this->AddCacheData(key, cacheData);
187 template <
class StringType>
199 return static_cast<unsigned int>(id);
214 this->
Color.
Set(static_cast<unsigned char>(color[0] * 255),
215 static_cast<unsigned char>(color[1] * 255),
216 static_cast<unsigned char>(color[2] * 255),
217 static_cast<unsigned char>(textProperty->
GetOpacity() * 255));
317 bool colorDiffer =
false;
318 while(!colorDiffer && i < 4)
336 glEnable(capability);
340 glDisable(capability);
346 float* texCoord =
new float[2*n];
347 float minX = f[0];
float minY = f[1];
348 float maxX = f[0];
float maxY = f[1];
350 for(
int i = 0; i < n; ++i)
352 minX = fptr[0] < minX ? fptr[0] : minX;
353 maxX = fptr[0] > maxX ? fptr[0] : maxX;
354 minY = fptr[1] < minY ? fptr[1] : minY;
355 maxY = fptr[1] > maxY ? fptr[1] : maxY;
362 float rangeX = (textureBounds[1] - textureBounds[0]) ?
363 textureBounds[1] - textureBounds[0] : 1.;
364 float rangeY = (textureBounds[3] - textureBounds[2]) ?
365 textureBounds[3] - textureBounds[2] : 1.;
366 for (
int i = 0; i < n; ++i)
368 texCoord[i*2] = (fptr[0]-minX) / rangeX;
369 texCoord[i*2+1] = (fptr[1]-minY) / rangeY;
375 float rangeX = (maxX - minX)? maxX - minX : 1.f;
376 float rangeY = (maxY - minY)? maxY - minY : 1.f;
377 for (
int i = 0; i < n; ++i)
379 texCoord[i*2] = (fptr[0]-minX)/rangeX;
380 texCoord[i*2+1] = (fptr[1]-minY)/rangeY;
390 for (
int i = 0; i < 2; ++i)
392 while (pow2[i] < size[i])
404 vtkGenericWarningMacro(
"Invalid image format: expected unsigned char.");
412 for (
int i = 0; i < 2; ++i)
414 texCoords[i] = size[i] /
float(newImg[i]);
417 unsigned char *dataPtr =
418 new unsigned char[newImg[0] * newImg[1] * bytesPerPixel];
419 unsigned char *origPtr =
422 for (
int i = 0; i < newImg[0]; ++i)
424 for (
int j = 0; j < newImg[1]; ++j)
426 for (
int k = 0; k < bytesPerPixel; ++k)
428 if (i < size[0] && j < size[1])
430 dataPtr[i * bytesPerPixel + j * newImg[0] * bytesPerPixel + k] =
431 origPtr[i * bytesPerPixel + j * size[0] * bytesPerPixel + k];
435 dataPtr[i * bytesPerPixel + j * newImg[0] * bytesPerPixel + k] =
443 GLint glFormat = bytesPerPixel == 3 ? GL_RGB : GL_RGBA;
444 GLint glInternalFormat = bytesPerPixel == 3 ? GL_RGB8 : GL_RGBA8;
446 glGenTextures(1, &tmpIndex);
447 glBindTexture(GL_TEXTURE_2D, tmpIndex);
449 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
450 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
451 glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S,
453 glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T,
456 glTexImage2D(GL_TEXTURE_2D, 0 , glInternalFormat,
457 newImg[0], newImg[1], 0, glFormat,
458 GL_UNSIGNED_BYTE, static_cast<const GLvoid *>(dataPtr));
467 cout <<
"Error = not an unsigned char..." << endl;
474 unsigned char *dataPtr =
477 GLint glFormat = bytesPerPixel == 3 ? GL_RGB : GL_RGBA;
478 GLint glInternalFormat = bytesPerPixel == 3 ? GL_RGB8 : GL_RGBA8;
480 glGenTextures(1, &tmpIndex);
481 glBindTexture(GL_TEXTURE_2D, tmpIndex);
483 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
484 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
485 glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S,
487 glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T,
490 glTexImage2D(GL_TEXTURE_2D, 0 , glInternalFormat,
491 size[0], size[1], 0, glFormat,
492 GL_UNSIGNED_BYTE, static_cast<const GLvoid *>(dataPtr));
524 #endif // VTKOPENGLCONTEXTDEVICE2DPRIVATE_H
std::list< CacheElement > Cache
List of a pair of key and cache data.
GLuint TextureFromImage(vtkImageData *image)
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,zmax).
static int GetNumberOfScalarComponents(vtkInformation *meta_data)
Set/Get the number of scalar components for points.
GLuint TextureFromImage(vtkImageData *image, vtkVector2f &texCoords)
bool IsKeyInCache(const Key &key) const
Search the cache list to see if a given key already exists.
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
bool operator==(const TextPropertyKey &other) const
Compares two TextPropertyKeys with each other.
float * TexCoords(float *f, int n)
TextPropertyKey< vtkStdString > UTF8TextPropertyKey
window superclass for vtkRenderWindow
size_t MaxSize
Maximum size the cache list can be.
virtual int * GetDimensions()
Get dimensions of this structured points dataset.
static int GetScalarType(vtkInformation *meta_data)
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.
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.
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.
static unsigned int GetIdFromTextProperty(vtkTextProperty *textProperty)
Transform a text property into an unsigned long.
CacheElement(const Key &key)
virtual double * GetColor()
Set the color of the text.
GLfloat SavedClearColor[4]
#define VTK_UNSIGNED_CHAR
virtual void * GetScalarPointer(int coordinates[3])
Access the native pointer for the scalar data.
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
CacheData & AddCacheData(const Key &key, const CacheData &cacheData)
Add a new cache entry into the cache list.
unsigned int TextPropertyId
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.