33 #ifndef vtkOpenGLContextDevice2DPrivate_h 34 #define vtkOpenGLContextDevice2DPrivate_h 92 return this->first == other.first;
129 typename std::list<CacheElement >::iterator it;
130 for (it = this->
Cache.begin(); it != this->
Cache.end(); ++it)
132 it->second.Texture->ReleaseGraphicsResources(window);
148 this->
Cache.pop_back();
150 this->
Cache.push_front(CacheElement(
key, cacheData));
151 return this->
Cache.begin()->second;
171 typename std::list<CacheElement>::iterator it =
172 std::find(this->Cache.begin(), this->Cache.end(), CacheElement(
key));
173 if (it != this->Cache.end())
180 cacheData.Texture->SetInputData(cacheData.ImageData);
181 return this->AddCacheData(
key, cacheData);
187 template <
class StringType>
204 vtkTypeUInt32 hash = static_cast<vtkTypeUInt32>(
id);
208 assert(
"Hash is really a uint32" && static_cast<size_t>(hash) ==
id);
234 static_cast<unsigned char>(
color[1] * 255),
235 static_cast<unsigned char>(
color[2] * 255),
236 static_cast<unsigned char>(textProperty->
GetOpacity() * 255));
341 float* texCoord =
new float[2*n];
342 float minX = f[0];
float minY = f[1];
343 float maxX = f[0];
float maxY = f[1];
345 for(
int i = 0; i < n; ++i)
347 minX = fptr[0] < minX ? fptr[0] : minX;
348 maxX = fptr[0] > maxX ? fptr[0] : maxX;
349 minY = fptr[1] < minY ? fptr[1] : minY;
350 maxY = fptr[1] > maxY ? fptr[1] : maxY;
357 float rangeX = (textureBounds[1] - textureBounds[0]) ?
358 textureBounds[1] - textureBounds[0] : 1.;
359 float rangeY = (textureBounds[3] - textureBounds[2]) ?
360 textureBounds[3] - textureBounds[2] : 1.;
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;
370 float rangeX = (maxX - minX)? maxX - minX : 1.f;
371 float rangeY = (maxY - minY)? maxY - minY : 1.f;
372 for (
int i = 0; i < n; ++i)
374 texCoord[i*2] = (fptr[0]-minX)/rangeX;
375 texCoord[i*2+1] = (fptr[1]-minY)/rangeY;
385 for (
int i = 0; i < 2; ++i)
387 while (pow2[i] <
size[i])
399 vtkGenericWarningMacro(
"Invalid image format: expected unsigned char.");
402 int bytesPerPixel =
image->GetNumberOfScalarComponents();
407 for (
int i = 0; i < 2; ++i)
409 texCoords[i] =
size[i] /
float(newImg[i]);
412 unsigned char *dataPtr =
413 new unsigned char[newImg[0] * newImg[1] * bytesPerPixel];
414 unsigned char *origPtr =
415 static_cast<unsigned char*>(
image->GetScalarPointer());
417 for (
int i = 0; i < newImg[0]; ++i)
419 for (
int j = 0; j < newImg[1]; ++j)
421 for (
int k = 0; k < bytesPerPixel; ++k)
425 dataPtr[i * bytesPerPixel + j * newImg[0] * bytesPerPixel + k] =
426 origPtr[i * bytesPerPixel + j *
size[0] * bytesPerPixel + k];
430 dataPtr[i * bytesPerPixel + j * newImg[0] * bytesPerPixel + k] =
438 GLint glFormat = bytesPerPixel == 3 ? GL_RGB : GL_RGBA;
439 GLint glInternalFormat = bytesPerPixel == 3 ? GL_RGB8 : GL_RGBA8;
441 glGenTextures(1, &tmpIndex);
442 glBindTexture(GL_TEXTURE_2D, tmpIndex);
444 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
445 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
446 glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S,
448 glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T,
451 glTexImage2D(GL_TEXTURE_2D, 0 , glInternalFormat,
452 newImg[0], newImg[1], 0, glFormat,
453 GL_UNSIGNED_BYTE, static_cast<const GLvoid *>(dataPtr));
462 cout <<
"Error = not an unsigned char..." << endl;
465 int bytesPerPixel =
image->GetNumberOfScalarComponents();
469 unsigned char *dataPtr =
470 static_cast<unsigned char*>(
image->GetScalarPointer());
472 GLint glFormat = bytesPerPixel == 3 ? GL_RGB : GL_RGBA;
473 GLint glInternalFormat = bytesPerPixel == 3 ? GL_RGB8 : GL_RGBA8;
475 glGenTextures(1, &tmpIndex);
476 glBindTexture(GL_TEXTURE_2D, tmpIndex);
478 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
479 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
480 glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S,
482 glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T,
485 glTexImage2D(GL_TEXTURE_2D, 0 , glInternalFormat,
487 GL_UNSIGNED_BYTE, static_cast<const GLvoid *>(dataPtr));
565 this->Colors = colors;
571 this->DrawLines(cellArray, scalarMode, x, y,
scale);
575 this->DrawPolygons(cellArray, scalarMode, x, y,
scale);
587 void MapCurrentCell (
float const posX,
float const posY,
float const scale,
590 this->CellPoints.reserve(this->NumPointsCell * 2);
592 for (
int i = 0; i < this->NumPointsCell; i++)
598 float const x = static_cast<float>(
point[0]) + posX;
599 float const y = static_cast<float>(
point[1]) + posY;
600 this->CellPoints.push_back(x *
scale);
601 this->CellPoints.push_back(y *
scale);
608 mappedColorId = this->PointIds[i];
611 mappedColorId = cellId;
614 std::cerr <<
"Scalar mode not supported!" << std::endl;
618 this->CellColors->
SetTuple(i, mappedColorId, this->Colors);
627 void DrawLines(
vtkCellArray* cellArray,
int scalarMode,
float const x,
628 float const y,
float const scale)
630 if (cellArray->
GetMTime() > this->LinesLoadingTime)
633 this->LineColors->
Reset();
637 this->Lines.reserve(numVertices * 2);
644 this->PointIds); cellId++)
646 this->MapCurrentCell(x, y,
scale, cellId, scalarMode);
649 for (
int i = 0; i < this->NumPointsCell; i++)
651 this->Lines.push_back(this->CellPoints[2 * i]);
652 this->Lines.push_back(this->CellPoints[2 * i + 1]);
654 double* color4 = this->CellColors->
GetTuple(i);
655 this->LineColors->
InsertTuple4(vertOffset + i, color4[0], color4[1], color4[2],
659 vertOffset += this->NumPointsCell;
660 this->CellColors->
Reset();
661 this->CellPoints.clear();
667 this->Device->
DrawLines(&this->Lines[0], this->Lines.size() / 2,
681 this->PointIds); cellId++)
683 numTriVert += 3 * (this->NumPointsCell - 2);
694 void DrawPolygons(
vtkCellArray* cellArray,
int scalarMode,
float const x,
695 float const y,
float const scale)
697 if (cellArray->
GetMTime() > this->PolygonsLoadingTime)
699 this->PolyTri.clear();
700 this->PolyColors->
Reset();
703 vtkIdType const totalTriVert = this->GetCountTriangleVertices(cellArray);
704 this->PolyTri.reserve(totalTriVert * 2);
713 this->PointIds); cellId++)
715 this->MapCurrentCell(x, y,
scale, cellId, scalarMode);
718 for (
int i = 0; i < this->NumPointsCell - 2; i++)
720 this->PolyTri.push_back(this->CellPoints[0]);
721 this->PolyTri.push_back(this->CellPoints[1]);
722 this->PolyTri.push_back(this->CellPoints[i * 2 + 2]);
723 this->PolyTri.push_back(this->CellPoints[i * 2 + 3]);
724 this->PolyTri.push_back(this->CellPoints[i * 2 + 4]);
725 this->PolyTri.push_back(this->CellPoints[i * 2 + 5]);
728 vtkIdType const triangOffset = vertOffset + 3 * i;
729 double* color4 = this->CellColors->
GetTuple(0);
730 this->PolyColors->
InsertTuple4(triangOffset, color4[0], color4[1],
731 color4[2], color4[3]);
733 color4 = this->CellColors->
GetTuple(i + 1);
734 this->PolyColors->
InsertTuple4(triangOffset + 1, color4[0], color4[1],
735 color4[2], color4[3]);
737 color4 = this->CellColors->
GetTuple(i + 2);
738 this->PolyColors->
InsertTuple4(triangOffset + 2, color4[0], color4[1],
739 color4[2], color4[3]);
742 vertOffset += 3 * (this->NumPointsCell - 2);
743 this->CellColors->
Reset();
744 this->CellPoints.clear();
747 this->PolygonsLoadingTime.
Modified();
751 static_cast<unsigned char*>(this->PolyColors->
GetVoidPointer(0)), 4);
765 std::vector<float> CellPoints;
773 std::vector<float> PolyTri;
782 std::vector<float> Lines;
787 #endif // VTKOPENGLCONTEXTDEVICE2DPRIVATE_H
GLuint TextureFromImage(vtkImageData *image)
void InsertTuple4(vtkIdType tupleIdx, double val0, double val1, double val2, double val3)
These methods are included as convenience for the wrappers.
void DrawLines(float *f, int n, unsigned char *colors=nullptr, int nc_comps=0) override
Draw lines using the points - memory layout is as follows: l1p1,l1p2,l2p1,l2p2...
virtual int GetJustification()
Set/Get the horizontal justification to left (default), centered, or right.
bool operator==(const CacheElement &other) const
double * GetBounds()
Return a pointer to the geometry bounding box in the form (xmin,xmax, ymin,ymax, zmin,...
void SetEnumState(unsigned int name, bool value)
vtkTextRenderer::Metrics Metrics
record modification and/or execution time
GLfloat SavedClearColor[4]
Class for drawing 2D primitives using OpenGL 1.1+.
void Modified()
Set this objects time to the current time.
void InitTraversal()
A cell traversal methods that is more efficient than vtkDataSet traversal methods.
void vtkglGetIntegerv(unsigned int pname, int *params)
GLuint TextureFromImage(vtkImageData *image, vtkVector2f &texCoords)
vtkTypeUInt32 TextPropertyId
void SaveGLState(vtkOpenGLState *ostate, bool colorBuffer=false)
TextPropertyKey(vtkTextProperty *textProperty, const StringType &text, int dpi)
Creates a TextPropertyKey.
int GetNumberOfComponents()
Set/Get the dimension (n) of the components.
virtual vtkIdType GetNumberOfCells()
Get the number of cells in the array.
CellArrayHelper(vtkOpenGLContextDevice2D *device)
std::list< CacheElement > Cache
List of a pair of key and cache data.
bool GetEnumState(unsigned int name)
static vtkSmartPointer< T > New()
Create an instance of a VTK object.
CacheElement(const Key &key, const CacheData &cacheData)
void SetNumberOfTuples(vtkIdType number) override
Set the number of tuples (a component group) in the array.
void ReleaseGraphicsResources(vtkWindow *window)
Release all the OpenGL Pixel Buffer Object(PBO) associated with the textures of the cache list.
void SetTuple(vtkIdType tupleIdx, const float *tuple) override
Set the data tuple at tupleIdx.
vtkSmartPointer< vtkTexture > Texture
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.
void vtkglGetFloatv(unsigned int pname, float *params)
#define VTK_SCALAR_MODE_USE_POINT_DATA
vtkTextureImageCache< UTF16TextPropertyKey > TextTextureCache
Cache for text images.
vtkTextureImageCache< UTF8TextPropertyKey > MathTextTextureCache
Cache for text images.
topologically and geometrically regular array of data
vtkImageData * GetInput()
Get the input as a vtkImageData object.
virtual vtkMTimeType GetMTime()
Return this object's modified time.
Some derived classes for the different vectors commonly used.
virtual int GetVerticalJustification()
Set/Get the vertical justification to bottom (default), middle, or top.
vtkTexture * SpriteTexture
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.
double * GetPoint(vtkIdType id)
Return a pointer to a double point x[3] for a specific id.
represent text properties.
void Reset()
Reset to an empty state, without freeing any memory.
dynamic, self-adjusting array of unsigned char
void CoreDrawTriangles(std::vector< float > &tverts, unsigned char *colors=nullptr, int numComp=0)
object to represent cell connectivity
CacheElement(const Key &key)
virtual double * GetColor()
Set the color of the text.
#define VTK_UNSIGNED_CHAR
unsigned int TextureProperties
void RestoreGLState(vtkOpenGLState *ostate, bool colorBuffer=false)
void vtkglClearColor(float red, float green, float blue, float alpha)
int GetNextCell(vtkIdType &npts, vtkIdType *&pts)
A cell traversal methods that is more efficient than vtkDataSet traversal methods.
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.
#define VTK_SCALAR_MODE_USE_CELL_DATA
CacheData & AddCacheData(const Key &key, const CacheData &cacheData)
Add a new cache entry into the cache list.
void GetTuple(vtkIdType tupleIdx, double *tuple) override
Get the data tuple at tupleIdx by filling in a user-provided array, Make sure that your array is larg...
vtkSmartPointer< vtkImageData > ImageData
void SetNumberOfComponents(int num) override
Set/Get the dimension (n) of the components.
void * GetVoidPointer(vtkIdType valueIdx) override
Get the address of a particular data index.
represent and manipulate 3D points
void Draw(int cellType, vtkCellArray *cellArray, vtkPoints *points, float x, float y, float scale, int scalarMode, vtkUnsignedCharArray *colors=nullptr)
Draw primitives as specified by cellType.
virtual void Delete()
Delete a VTK object.