VTK
vtkOpenGLContextDevice2DPrivate.h
Go to the documentation of this file.
1 /*=========================================================================
2 
3  Program: Visualization Toolkit
4  Module: vtkOpenGLContextDevice2DPrivate.h
5 
6  Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
7  All rights reserved.
8  See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
9 
10  This software is distributed WITHOUT ANY WARRANTY; without even
11  the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
12  PURPOSE. See the above copyright notice for more information.
13 
14 =========================================================================*/
15 
33 #ifndef vtkOpenGLContextDevice2DPrivate_h
34 #define vtkOpenGLContextDevice2DPrivate_h
35 
37 
38 #include "vtkAbstractMapper.h"
39 #include "vtkColor.h"
40 #include "vtkFreeTypeTools.h"
41 #include "vtkTextProperty.h"
42 #include "vtkTextRenderer.h"
43 #include "vtkTexture.h"
44 #include "vtkStdString.h"
45 #include "vtkUnicodeString.h"
46 
47 #include <algorithm>
48 #include <list>
49 #include <utility>
50 
51 // .NAME vtkTextureImageCache - store vtkTexture and vtkImageData identified by
52 // a unique key.
53 // .SECTION Description
54 // Creating and initializing a texture can be time consuming,
55 // vtkTextureImageCache offers the ability to reuse them as much as possible.
56 template <class Key>
58 {
59 public:
60  struct CacheData
61  {
64  // Use to generate texture coordinates. Computing this is as expensive as
65  // rendering the texture, so we cache it.
67  };
68 
70 
73  struct CacheElement: public std::pair<Key, CacheData>
74  {
75  // Default constructor
77  : std::pair<Key, CacheData>(Key(), CacheData()){}
78  // Construct a partial CacheElement with no CacheData
79  // This can be used for temporary CacheElement used to search a given
80  // key into the cache list.
81  CacheElement(const Key& key)
82  : std::pair<Key, CacheData>(key, CacheData()){}
83  // Standard constructor of CacheElement
84  CacheElement(const Key& key, const CacheData& cacheData)
85  : std::pair<Key, CacheData>(key, cacheData){}
86  // Operator tuned to be used when searching into the cache list using
87  // std::find()
88  bool operator==(const CacheElement& other)const
89  {
90  // Here we cheat and make the comparison only on the key, this allows
91  // us to use std::find() to search for a given key.
92  return this->first == other.first;
93  }
94  };
96 
101  {
102  this->MaxSize = 50;
103  }
104 
109  bool IsKeyInCache(const Key& key)const
110  {
111  return std::find(this->Cache.begin(), this->Cache.end(), key) != this->Cache.end();
112  }
113 
120  CacheData& GetCacheData(const Key& key);
121 
123 
128  {
129  typename std::list<CacheElement >::iterator it;
130  for (it = this->Cache.begin(); it != this->Cache.end(); ++it)
131  {
132  it->second.Texture->ReleaseGraphicsResources(window);
133  }
134  }
136 
137 protected:
139 
143  CacheData& AddCacheData(const Key& key, const CacheData& cacheData)
144  {
145  assert(!this->IsKeyInCache(key));
146  if (this->Cache.size() >= this->MaxSize)
147  {
148  this->Cache.pop_back();
149  }
150  this->Cache.push_front(CacheElement(key, cacheData));
151  return this->Cache.begin()->second;
152  }
154 
158  std::list<CacheElement > Cache;
160 
163  size_t MaxSize;
164 };
166 
167 template<class Key>
169 ::GetCacheData(const Key& key)
170 {
171  typename std::list<CacheElement>::iterator it =
172  std::find(this->Cache.begin(), this->Cache.end(), CacheElement(key));
173  if (it != this->Cache.end())
174  {
175  return it->second;
176  }
177  CacheData cacheData;
179  cacheData.Texture = vtkSmartPointer<vtkTexture>::New();
180  cacheData.Texture->SetInputData(cacheData.ImageData);
181  return this->AddCacheData(key, cacheData);
182 }
183 
184 // .NAME TextPropertyKey - unique key for a vtkTextProperty and text
185 // .SECTION Description
186 // Uniquely describe a pair of vtkTextProperty and text.
187 template <class StringType>
189 {
191 
194  static vtkTypeUInt32 GetIdFromTextProperty(vtkTextProperty* tprop)
195  {
196  size_t id;
197 
199  ftt->MapTextPropertyToId(tprop, &id);
200 
201  // The hash is really a uint32 that gets cast to a size_t in
202  // MapTextPropertyToId, so this possible truncation is safe.
203  // Yay legacy APIs.
204  vtkTypeUInt32 hash = static_cast<vtkTypeUInt32>(id);
205 
206  // Ensure that the above implementation assumption still holds. If it
207  // doesn't we'll need to rework this cache class a bit.
208  assert("Hash is really a uint32" && static_cast<size_t>(hash) == id);
209 
210  // Since we cache the text metrics (which includes orientation and alignment
211  // info), we'll need to store the alignment options, since
212  // MapTextPropertyToId intentionally ignores these:
213  int tmp = tprop->GetJustification();
214  hash = vtkFreeTypeTools::HashBuffer(&tmp, sizeof(int), hash);
215  tmp = tprop->GetVerticalJustification();
216  hash = vtkFreeTypeTools::HashBuffer(&tmp, sizeof(int), hash);
217 
218  return hash;
219  }
221 
223 
226  TextPropertyKey(vtkTextProperty* textProperty, const StringType& text,
227  int dpi)
228  {
229  this->TextPropertyId = GetIdFromTextProperty(textProperty);
230  this->FontSize = textProperty->GetFontSize();
231  double color[3];
232  textProperty->GetColor(color);
233  this->Color.Set(static_cast<unsigned char>(color[0] * 255),
234  static_cast<unsigned char>(color[1] * 255),
235  static_cast<unsigned char>(color[2] * 255),
236  static_cast<unsigned char>(textProperty->GetOpacity() * 255));
237  this->Text = text;
238  this->DPI = dpi;
239  }
241 
246  bool operator==(const TextPropertyKey& other)const
247  {
248  return this->TextPropertyId == other.TextPropertyId &&
249  this->FontSize == other.FontSize &&
250  this->Text == other.Text &&
251  this->Color[0] == other.Color[0] &&
252  this->Color[1] == other.Color[1] &&
253  this->Color[2] == other.Color[2] &&
254  this->Color[3] == other.Color[3] &&
255  this->DPI == other.DPI;
256  }
257 
258  unsigned short FontSize;
260  // States in the function not to use more than 32 bits - int works fine here.
261  vtkTypeUInt32 TextPropertyId;
262  StringType Text;
263  int DPI;
264 };
265 
268 
270 {
271 public:
273  {
274  this->Texture = nullptr;
277  this->SpriteTexture = nullptr;
278  this->SavedDepthTest = GL_TRUE;
279  this->SavedStencilTest = GL_TRUE;
280  this->SavedBlend = GL_TRUE;
281  this->SavedDrawBuffer = 0;
282  this->SavedClearColor[0] = this->SavedClearColor[1] =
283  this->SavedClearColor[2] =
284  this->SavedClearColor[3] = 0.0f;
285  this->TextCounter = 0;
286  this->GLExtensionsLoaded = true;
287  this->GLSL = true;
288  this->PowerOfTwoTextures = false;
289  }
290 
292  {
293  if (this->Texture)
294  {
295  this->Texture->Delete();
296  this->Texture = nullptr;
297  }
298  if (this->SpriteTexture)
299  {
300  this->SpriteTexture->Delete();
301  this->SpriteTexture = nullptr;
302  }
303  }
304 
305  void SaveGLState(vtkOpenGLState *ostate, bool colorBuffer = false)
306  {
307  this->SavedDepthTest = ostate->GetEnumState(GL_DEPTH_TEST);
308 
309  if (colorBuffer)
310  {
311  this->SavedStencilTest = ostate->GetEnumState(GL_STENCIL_TEST);
312  this->SavedBlend = ostate->GetEnumState(GL_BLEND);
313  ostate->vtkglGetFloatv(GL_COLOR_CLEAR_VALUE, this->SavedClearColor);
314  ostate->vtkglGetIntegerv(GL_DRAW_BUFFER, &this->SavedDrawBuffer);
315  }
316  }
317 
318  void RestoreGLState(vtkOpenGLState *ostate, bool colorBuffer = false)
319  {
320  ostate->SetEnumState(GL_DEPTH_TEST, this->SavedDepthTest);
321 
322  if (colorBuffer)
323  {
324  ostate->SetEnumState(GL_STENCIL_TEST, this->SavedStencilTest);
325  ostate->SetEnumState(GL_BLEND, this->SavedBlend);
326 
327  if(this->SavedDrawBuffer != GL_BACK_LEFT)
328  {
329  glDrawBuffer(this->SavedDrawBuffer);
330  }
331 
332  ostate->vtkglClearColor(this->SavedClearColor[0],
333  this->SavedClearColor[1],
334  this->SavedClearColor[2],
335  this->SavedClearColor[3]);
336  }
337  }
338 
339  float* TexCoords(float* f, int n)
340  {
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];
344  float* fptr = f;
345  for(int i = 0; i < n; ++i)
346  {
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;
351  fptr+=2;
352  }
353  fptr = f;
355  {
356  const double* textureBounds = this->Texture->GetInput()->GetBounds();
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)
362  {
363  texCoord[i*2] = (fptr[0]-minX) / rangeX;
364  texCoord[i*2+1] = (fptr[1]-minY) / rangeY;
365  fptr+=2;
366  }
367  }
368  else // this->TextureProperties & vtkContextDevice2D::Stretch
369  {
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)
373  {
374  texCoord[i*2] = (fptr[0]-minX)/rangeX;
375  texCoord[i*2+1] = (fptr[1]-minY)/rangeY;
376  fptr+=2;
377  }
378  }
379  return texCoord;
380  }
381 
383  {
384  vtkVector2i pow2(1, 1);
385  for (int i = 0; i < 2; ++i)
386  {
387  while (pow2[i] < size[i])
388  {
389  pow2[i] *= 2;
390  }
391  }
392  return pow2;
393  }
394 
396  {
397  if (image->GetScalarType() != VTK_UNSIGNED_CHAR)
398  {
399  vtkGenericWarningMacro("Invalid image format: expected unsigned char.");
400  return 0;
401  }
402  int bytesPerPixel = image->GetNumberOfScalarComponents();
403  int size[3];
404  image->GetDimensions(size);
405  vtkVector2i newImg = this->FindPowerOfTwo(vtkVector2i(size[0], size[1]));
406 
407  for (int i = 0; i < 2; ++i)
408  {
409  texCoords[i] = size[i] / float(newImg[i]);
410  }
411 
412  unsigned char *dataPtr =
413  new unsigned char[newImg[0] * newImg[1] * bytesPerPixel];
414  unsigned char *origPtr =
415  static_cast<unsigned char*>(image->GetScalarPointer());
416 
417  for (int i = 0; i < newImg[0]; ++i)
418  {
419  for (int j = 0; j < newImg[1]; ++j)
420  {
421  for (int k = 0; k < bytesPerPixel; ++k)
422  {
423  if (i < size[0] && j < size[1])
424  {
425  dataPtr[i * bytesPerPixel + j * newImg[0] * bytesPerPixel + k] =
426  origPtr[i * bytesPerPixel + j * size[0] * bytesPerPixel + k];
427  }
428  else
429  {
430  dataPtr[i * bytesPerPixel + j * newImg[0] * bytesPerPixel + k] =
431  k == 3 ? 0 : 255;
432  }
433  }
434  }
435  }
436 
437  GLuint tmpIndex(0);
438  GLint glFormat = bytesPerPixel == 3 ? GL_RGB : GL_RGBA;
439  GLint glInternalFormat = bytesPerPixel == 3 ? GL_RGB8 : GL_RGBA8;
440 
441  glGenTextures(1, &tmpIndex);
442  glBindTexture(GL_TEXTURE_2D, tmpIndex);
443 
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,
447  GL_CLAMP_TO_EDGE );
448  glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T,
449  GL_CLAMP_TO_EDGE );
450 
451  glTexImage2D(GL_TEXTURE_2D, 0 , glInternalFormat,
452  newImg[0], newImg[1], 0, glFormat,
453  GL_UNSIGNED_BYTE, static_cast<const GLvoid *>(dataPtr));
454  delete [] dataPtr;
455  return tmpIndex;
456  }
457 
459  {
460  if (image->GetScalarType() != VTK_UNSIGNED_CHAR)
461  {
462  cout << "Error = not an unsigned char..." << endl;
463  return 0;
464  }
465  int bytesPerPixel = image->GetNumberOfScalarComponents();
466  int size[3];
467  image->GetDimensions(size);
468 
469  unsigned char *dataPtr =
470  static_cast<unsigned char*>(image->GetScalarPointer());
471  GLuint tmpIndex(0);
472  GLint glFormat = bytesPerPixel == 3 ? GL_RGB : GL_RGBA;
473  GLint glInternalFormat = bytesPerPixel == 3 ? GL_RGB8 : GL_RGBA8;
474 
475  glGenTextures(1, &tmpIndex);
476  glBindTexture(GL_TEXTURE_2D, tmpIndex);
477 
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,
481  GL_CLAMP_TO_EDGE );
482  glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T,
483  GL_CLAMP_TO_EDGE );
484 
485  glTexImage2D(GL_TEXTURE_2D, 0 , glInternalFormat,
486  size[0], size[1], 0, glFormat,
487  GL_UNSIGNED_BYTE, static_cast<const GLvoid *>(dataPtr));
488  return tmpIndex;
489  }
490 
492  unsigned int TextureProperties;
494  // Store the previous GL state so that we can restore it when complete
499  GLfloat SavedClearColor[4];
500 
505  bool GLSL;
507 
509 
515 };
517 
519 
539 {
540 
541 public:
542  enum CellType
543  {
544  LINE = 1,
546  //TRIANGLE_STRIPS
547  };
548 
550  : Device(device)
551  , Points(nullptr)
552  , PointIds(nullptr)
553  , Colors(nullptr)
554  , NumPointsCell(0)
555  {
556  };
557 
561  void Draw (int cellType, vtkCellArray* cellArray, vtkPoints* points, float x,
562  float y, float scale, int scalarMode, vtkUnsignedCharArray* colors = nullptr)
563  {
564  this->Points = points;
565  this->Colors = colors;
566  this->CellColors->SetNumberOfComponents(colors->GetNumberOfComponents());
567 
568  switch (cellType)
569  {
570  case LINE:
571  this->DrawLines(cellArray, scalarMode, x, y, scale);
572  break;
573 
574  case POLYGON:
575  this->DrawPolygons(cellArray, scalarMode, x, y, scale);
576  break;
577  }
578  };
579 
580 private:
581  CellArrayHelper(const CellArrayHelper&) = delete;
582  void operator=(const CellArrayHelper&) = delete;
583 
587  void MapCurrentCell (float const posX, float const posY, float const scale,
588  vtkIdType cellId, int scalarMode)
589  {
590  this->CellPoints.reserve(this->NumPointsCell * 2); /* 2 components */
591  this->CellColors->SetNumberOfTuples(this->NumPointsCell); /* RGBA */
592  for (int i = 0; i < this->NumPointsCell; i++)
593  {
594  double point[3];
595  this->Points->GetPoint(this->PointIds[i], point);
596 
597  // Only 2D meshes are supported
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);
602 
603  // Grab specific point / cell colors
605  switch (scalarMode)
606  {
608  mappedColorId = this->PointIds[i];
609  break;
611  mappedColorId = cellId;
612  break;
613  default:
614  std::cerr << "Scalar mode not supported!" << std::endl;
615  break;
616  }
617 
618  this->CellColors->SetTuple(i, mappedColorId, this->Colors);
619  }
620  };
621 
627  void DrawLines(vtkCellArray* cellArray, int scalarMode, float const x,
628  float const y, float const scale)
629  {
630  if (cellArray->GetMTime() > this->LinesLoadingTime)
631  {
632  this->Lines.clear();
633  this->LineColors->Reset();
634 
635  // Pre-allocate batched array
636  vtkIdType const numVertices = cellArray->GetNumberOfCells() * 2;// points/line
637  this->Lines.reserve(numVertices * 2); // components
638  this->LineColors->SetNumberOfComponents(this->Colors->GetNumberOfComponents());
639  this->LineColors->SetNumberOfTuples(numVertices);
640 
641  vtkIdType cellId = 0;
642  vtkIdType vertOffset = 0;
643  for (cellArray->InitTraversal(); cellArray->GetNextCell(this->NumPointsCell,
644  this->PointIds); cellId++)
645  {
646  this->MapCurrentCell(x, y, scale, cellId, scalarMode);
647 
648  // Accumulate the current cell in the batched array
649  for (int i = 0; i < this->NumPointsCell; i++)
650  {
651  this->Lines.push_back(this->CellPoints[2 * i]);
652  this->Lines.push_back(this->CellPoints[2 * i + 1]);
653 
654  double* color4 = this->CellColors->GetTuple(i);
655  this->LineColors->InsertTuple4(vertOffset + i, color4[0], color4[1], color4[2],
656  color4[3]);
657  }
658 
659  vertOffset += this->NumPointsCell;
660  this->CellColors->Reset();
661  this->CellPoints.clear();
662  }
663 
664  this->LinesLoadingTime.Modified();
665  }
666 
667  this->Device->DrawLines(&this->Lines[0], this->Lines.size() / 2,
668  static_cast<unsigned char*>(this->LineColors->GetVoidPointer(0)),
669  this->LineColors->GetNumberOfComponents());
670  };
671 
676  vtkIdType GetCountTriangleVertices(vtkCellArray* cellArray)
677  {
678  vtkIdType cellId = 0;
679  vtkIdType numTriVert = 0;
680  for (cellArray->InitTraversal(); cellArray->GetNextCell(this->NumPointsCell,
681  this->PointIds); cellId++)
682  {
683  numTriVert += 3 * (this->NumPointsCell - 2);
684  };
685 
686  return numTriVert;
687  };
688 
694  void DrawPolygons(vtkCellArray* cellArray, int scalarMode, float const x,
695  float const y, float const scale)
696  {
697  if (cellArray->GetMTime() > this->PolygonsLoadingTime)
698  {
699  this->PolyTri.clear();
700  this->PolyColors->Reset();
701 
702  // Pre-allocate batched array
703  vtkIdType const totalTriVert = this->GetCountTriangleVertices(cellArray);
704  this->PolyTri.reserve(totalTriVert * 2); // components
705  this->PolyColors->SetNumberOfComponents(this->Colors->GetNumberOfComponents());
706  this->PolyColors->SetNumberOfTuples(totalTriVert);
707 
708  // Traverse polygons and convert to triangles
709  vtkIdType cellId = 0;
710  vtkIdType vertOffset = 0;
711  this->PolyColors->SetNumberOfComponents(this->Colors->GetNumberOfComponents());
712  for (cellArray->InitTraversal(); cellArray->GetNextCell(this->NumPointsCell,
713  this->PointIds); cellId++)
714  {
715  this->MapCurrentCell(x, y, scale, cellId, scalarMode);
716 
717  // Convert current cell (polygon) to triangles
718  for (int i = 0; i < this->NumPointsCell - 2; i++)
719  {
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]);
726 
727  // Insert triangle vertex color
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]);
732 
733  color4 = this->CellColors->GetTuple(i + 1);
734  this->PolyColors->InsertTuple4(triangOffset + 1, color4[0], color4[1],
735  color4[2], color4[3]);
736 
737  color4 = this->CellColors->GetTuple(i + 2);
738  this->PolyColors->InsertTuple4(triangOffset + 2, color4[0], color4[1],
739  color4[2], color4[3]);
740  }
741 
742  vertOffset += 3 * (this->NumPointsCell - 2); // Triangle verts current cell
743  this->CellColors->Reset();
744  this->CellPoints.clear();
745  }
746 
747  this->PolygonsLoadingTime.Modified();
748  }
749 
750  this->Device->CoreDrawTriangles(this->PolyTri,
751  static_cast<unsigned char*>(this->PolyColors->GetVoidPointer(0)), 4);
752  };
753 
754  vtkOpenGLContextDevice2D* Device;
755 
756  vtkPoints* Points;
757  vtkIdType* PointIds;
758  vtkUnsignedCharArray* Colors;
759 
761 
764  vtkIdType NumPointsCell;
765  std::vector<float> CellPoints;
766  vtkNew<vtkUnsignedCharArray> CellColors;
768 
770 
773  std::vector<float> PolyTri;
774  vtkNew<vtkUnsignedCharArray> PolyColors;
775  vtkTimeStamp PolygonsLoadingTime;
777 
779 
782  std::vector<float> Lines;
783  vtkNew<vtkUnsignedCharArray> LineColors;
784  vtkTimeStamp LinesLoadingTime;
786 };
787 #endif // VTKOPENGLCONTEXTDEVICE2DPRIVATE_H
788 // VTK-HeaderTest-Exclude: vtkOpenGLContextDevice2DPrivate.h
vtkPoints
represent and manipulate 3D points
Definition: vtkPoints.h:33
vtkOpenGLContextDevice2D::Private
Definition: vtkOpenGLContextDevice2DPrivate.h:269
vtkAOSDataArrayTemplate::GetTuple
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...
vtkStdString.h
vtkOpenGLContextDevice2D::Private::SaveGLState
void SaveGLState(vtkOpenGLState *ostate, bool colorBuffer=false)
Definition: vtkOpenGLContextDevice2DPrivate.h:305
vtkOpenGLContextDevice2D::Private::TexCoords
float * TexCoords(float *f, int n)
Definition: vtkOpenGLContextDevice2DPrivate.h:339
VTK_SCALAR_MODE_USE_POINT_DATA
#define VTK_SCALAR_MODE_USE_POINT_DATA
Definition: vtkAbstractMapper.h:35
vtkOpenGLContextDevice2D::Private::SavedStencilTest
bool SavedStencilTest
Definition: vtkOpenGLContextDevice2DPrivate.h:496
vtkAbstractArray::GetNumberOfComponents
int GetNumberOfComponents()
Definition: vtkAbstractArray.h:127
vtkOpenGLState::vtkglGetIntegerv
void vtkglGetIntegerv(unsigned int pname, int *params)
vtkOpenGLContextDevice2D::Private::Dim
vtkVector2i Dim
Definition: vtkOpenGLContextDevice2DPrivate.h:502
vtkContextDevice2D::Repeat
Definition: vtkContextDevice2D.h:289
vtkOpenGLContextDevice2D::Private::GLSL
bool GLSL
Definition: vtkOpenGLContextDevice2DPrivate.h:505
vtkX3D::scale
Definition: vtkX3D.h:229
vtkIdType
int vtkIdType
Definition: vtkType.h:347
vtkOpenGLContextDevice2D::Private::TextTextureCache
vtkTextureImageCache< UTF16TextPropertyKey > TextTextureCache
Cache for text images.
Definition: vtkOpenGLContextDevice2DPrivate.h:513
vtkOpenGLContextDevice2D::Private::MathTextTextureCache
vtkTextureImageCache< UTF8TextPropertyKey > MathTextTextureCache
Definition: vtkOpenGLContextDevice2DPrivate.h:514
vtkX3D::key
Definition: vtkX3D.h:257
vtkTimeStamp
record modification and/or execution time
Definition: vtkTimeStamp.h:32
vtkOpenGLContextDevice2D::DrawLines
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...
vtkX3D::image
Definition: vtkX3D.h:374
vtkUnicodeString.h
vtkOpenGLContextDevice2D::Private::Texture
vtkTexture * Texture
Definition: vtkOpenGLContextDevice2DPrivate.h:491
vtkOpenGLContextDevice2D::Private::SpriteTexture
vtkTexture * SpriteTexture
Definition: vtkOpenGLContextDevice2DPrivate.h:493
vtkUnsignedCharArray
dynamic, self-adjusting array of unsigned char
Definition: vtkUnsignedCharArray.h:35
vtkOpenGLContextDevice2D::CoreDrawTriangles
void CoreDrawTriangles(std::vector< float > &tverts, unsigned char *colors=nullptr, int numComp=0)
vtkTextureImageCache::CacheElement::CacheElement
CacheElement(const Key &key)
Definition: vtkOpenGLContextDevice2DPrivate.h:81
vtkOpenGLContextDevice2D::Private::TextCounter
int TextCounter
Definition: vtkOpenGLContextDevice2DPrivate.h:501
vtkTextureImageCache::ReleaseGraphicsResources
void ReleaseGraphicsResources(vtkWindow *window)
Release all the OpenGL Pixel Buffer Object(PBO) associated with the textures of the cache list.
Definition: vtkOpenGLContextDevice2DPrivate.h:127
vtkTextureImageCache::CacheData::ImageData
vtkSmartPointer< vtkImageData > ImageData
Definition: vtkOpenGLContextDevice2DPrivate.h:62
vtkSmartPointer< vtkImageData >
vtkTextureImageCache::CacheData::Texture
vtkSmartPointer< vtkTexture > Texture
Definition: vtkOpenGLContextDevice2DPrivate.h:63
vtkTextureImageCache::CacheElement::CacheElement
CacheElement(const Key &key, const CacheData &cacheData)
Definition: vtkOpenGLContextDevice2DPrivate.h:84
vtkTextProperty::GetColor
virtual double * GetColor()
TextPropertyKey::Text
StringType Text
Definition: vtkOpenGLContextDevice2DPrivate.h:262
vtkOpenGLContextDevice2D::Private::PowerOfTwoTextures
bool PowerOfTwoTextures
Definition: vtkOpenGLContextDevice2DPrivate.h:506
vtkObjectBase::Delete
virtual void Delete()
Delete a VTK object.
vtkOpenGLContextDevice2D::Private::Offset
vtkVector2i Offset
Definition: vtkOpenGLContextDevice2DPrivate.h:503
vtkAOSDataArrayTemplate::SetTuple
void SetTuple(vtkIdType tupleIdx, const float *tuple) override
Set the data tuple at tupleIdx.
vtkTextRenderer.h
vtkTextureImageCache::CacheElement
CacheElement associates a unique key to some cache.
Definition: vtkOpenGLContextDevice2DPrivate.h:73
vtkOpenGLContextDevice2D::Private::TextureFromImage
GLuint TextureFromImage(vtkImageData *image, vtkVector2f &texCoords)
Definition: vtkOpenGLContextDevice2DPrivate.h:395
vtkTextProperty.h
UTF8TextPropertyKey
TextPropertyKey< vtkStdString > UTF8TextPropertyKey
Definition: vtkOpenGLContextDevice2DPrivate.h:266
vtkWindow
window superclass for vtkRenderWindow
Definition: vtkWindow.h:34
vtkOpenGLContextDevice2D::Private::SavedClearColor
GLfloat SavedClearColor[4]
Definition: vtkOpenGLContextDevice2DPrivate.h:499
vtkTextureImageCache::CacheElement::CacheElement
CacheElement()
Definition: vtkOpenGLContextDevice2DPrivate.h:76
vtkOpenGLContextDevice2D::CellArrayHelper::CellArrayHelper
CellArrayHelper(vtkOpenGLContextDevice2D *device)
Definition: vtkOpenGLContextDevice2DPrivate.h:549
vtkCellArray::GetNextCell
int GetNextCell(vtkIdType &npts, vtkIdType *&pts)
A cell traversal methods that is more efficient than vtkDataSet traversal methods.
Definition: vtkCellArray.h:359
TextPropertyKey::GetIdFromTextProperty
static vtkTypeUInt32 GetIdFromTextProperty(vtkTextProperty *tprop)
Transform a text property into an unsigned long.
Definition: vtkOpenGLContextDevice2DPrivate.h:194
vtkTextProperty::GetFontSize
virtual int GetFontSize()
vtkTextureImageCache::CacheElement::operator==
bool operator==(const CacheElement &other) const
Definition: vtkOpenGLContextDevice2DPrivate.h:88
float
float
Definition: vtkVectorOperators.h:162
vtkX3D::color
Definition: vtkX3D.h:221
vtkOpenGLContextDevice2D.h
vtkOpenGLContextDevice2D::CellArrayHelper::LINE
Definition: vtkOpenGLContextDevice2DPrivate.h:544
vtkX3D::points
Definition: vtkX3D.h:446
vtkX3D::point
Definition: vtkX3D.h:236
vtkTexture
handles properties associated with a texture map
Definition: vtkTexture.h:65
vtkGenericDataArray::SetNumberOfTuples
void SetNumberOfTuples(vtkIdType number) override
Set the number of tuples (a component group) in the array.
vtkFreeTypeTools::MapTextPropertyToId
void MapTextPropertyToId(vtkTextProperty *tprop, size_t *tprop_cache_id)
Given a text property 'tprop', get its unique ID in our cache framework.
vtkTextureImageCache::Cache
std::list< CacheElement > Cache
List of a pair of key and cache data.
Definition: vtkOpenGLContextDevice2DPrivate.h:158
VTK_SCALAR_MODE_USE_CELL_DATA
#define VTK_SCALAR_MODE_USE_CELL_DATA
Definition: vtkAbstractMapper.h:36
vtkTimeStamp::Modified
void Modified()
Set this objects time to the current time.
vtkTextureImageCache::CacheData
Definition: vtkOpenGLContextDevice2DPrivate.h:60
vtkAbstractArray::Reset
void Reset()
Reset to an empty state, without freeing any memory.
Definition: vtkAbstractArray.h:311
vtkOpenGLContextDevice2D
Class for drawing 2D primitives using OpenGL 1.1+.
Definition: vtkOpenGLContextDevice2D.h:51
TextPropertyKey::Color
vtkColor4ub Color
Definition: vtkOpenGLContextDevice2DPrivate.h:259
vtkPoints::GetPoint
double * GetPoint(vtkIdType id)
Return a pointer to a double point x[3] for a specific id.
Definition: vtkPoints.h:134
vtkObject::GetMTime
virtual vtkMTimeType GetMTime()
Return this object's modified time.
TextPropertyKey::FontSize
unsigned short FontSize
Definition: vtkOpenGLContextDevice2DPrivate.h:258
vtkOpenGLContextDevice2D::CellArrayHelper
Definition: vtkOpenGLContextDevice2DPrivate.h:538
vtkColor.h
vtkOpenGLContextDevice2D::CellArrayHelper::POLYGON
Definition: vtkOpenGLContextDevice2DPrivate.h:545
vtkTextureImageCache::vtkTextureImageCache
vtkTextureImageCache()
Construct a texture image cache with a maximum number of texture of 50.
Definition: vtkOpenGLContextDevice2DPrivate.h:100
vtkImageData
topologically and geometrically regular array of data
Definition: vtkImageData.h:39
vtkCellArray
object to represent cell connectivity
Definition: vtkCellArray.h:44
vtkOpenGLContextDevice2D::Private::SavedDrawBuffer
GLint SavedDrawBuffer
Definition: vtkOpenGLContextDevice2DPrivate.h:498
vtkOpenGLState::SetEnumState
void SetEnumState(unsigned int name, bool value)
vtkTextProperty::GetJustification
virtual int GetJustification()
vtkSmartPointer::New
static vtkSmartPointer< T > New()
Create an instance of a VTK object.
Definition: vtkSmartPointer.h:153
VTK_UNSIGNED_CHAR
#define VTK_UNSIGNED_CHAR
Definition: vtkType.h:51
vtkX3D::size
Definition: vtkX3D.h:253
vtkNew< vtkUnsignedCharArray >
vtkOpenGLContextDevice2D::Private::SavedBlend
bool SavedBlend
Definition: vtkOpenGLContextDevice2DPrivate.h:497
vtkColor4::Set
void Set(const T &red, const T &green, const T &blue)
Set the red, green and blue components of the color.
Definition: vtkColor.h:129
vtkTexture.h
vtkOpenGLState::vtkglClearColor
void vtkglClearColor(float red, float green, float blue, float alpha)
vtkTextureImageCache::MaxSize
size_t MaxSize
Maximum size the cache list can be.
Definition: vtkOpenGLContextDevice2DPrivate.h:163
vtkTextureImageCache::CacheData::Metrics
vtkTextRenderer::Metrics Metrics
Definition: vtkOpenGLContextDevice2DPrivate.h:66
vtkOpenGLContextDevice2D::CellArrayHelper::CellType
CellType
Definition: vtkOpenGLContextDevice2DPrivate.h:542
vtkOpenGLContextDevice2D::Private::Private
Private()
Definition: vtkOpenGLContextDevice2DPrivate.h:272
vtkTextProperty
represent text properties.
Definition: vtkTextProperty.h:33
vtkOpenGLContextDevice2D::Private::GLExtensionsLoaded
bool GLExtensionsLoaded
Definition: vtkOpenGLContextDevice2DPrivate.h:504
vtkOpenGLContextDevice2D::Private::~Private
~Private()
Definition: vtkOpenGLContextDevice2DPrivate.h:291
vtkAbstractMapper.h
vtkTexture::GetInput
vtkImageData * GetInput()
Get the input as a vtkImageData object.
vtkContextDevice2D::Linear
Definition: vtkContextDevice2D.h:287
vtkFreeTypeTools.h
vtkOpenGLState::GetEnumState
bool GetEnumState(unsigned int name)
TextPropertyKey::TextPropertyId
vtkTypeUInt32 TextPropertyId
Definition: vtkOpenGLContextDevice2DPrivate.h:261
vtkFreeTypeTools::HashBuffer
static vtkTypeUInt32 HashBuffer(const void *str, size_t n, vtkTypeUInt32 hash=0)
Hash a string of a given length.
vtkOpenGLContextDevice2D::Private::TextureProperties
unsigned int TextureProperties
Definition: vtkOpenGLContextDevice2DPrivate.h:492
TextPropertyKey::DPI
int DPI
Definition: vtkOpenGLContextDevice2DPrivate.h:263
vtkCellArray::InitTraversal
void InitTraversal()
A cell traversal methods that is more efficient than vtkDataSet traversal methods.
Definition: vtkCellArray.h:96
vtkOpenGLState::vtkglGetFloatv
void vtkglGetFloatv(unsigned int pname, float *params)
vtkTextureImageCache::GetCacheData
CacheData & GetCacheData(const Key &key)
Return the cache associated to a key.
Definition: vtkOpenGLContextDevice2DPrivate.h:169
vtkColor4ub
Definition: vtkColor.h:240
vtkOpenGLContextDevice2D::CellArrayHelper::Draw
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.
Definition: vtkOpenGLContextDevice2DPrivate.h:561
vtkTextureImageCache::IsKeyInCache
bool IsKeyInCache(const Key &key) const
Search the cache list to see if a given key already exists.
Definition: vtkOpenGLContextDevice2DPrivate.h:109
vtkDataSet::GetBounds
double * GetBounds()
Return a pointer to the geometry bounding box in the form (xmin,xmax, ymin,ymax, zmin,...
vtkCellArray::GetNumberOfCells
virtual vtkIdType GetNumberOfCells()
Get the number of cells in the array.
vtkTextureImageCache
Definition: vtkOpenGLContextDevice2DPrivate.h:57
TextPropertyKey::TextPropertyKey
TextPropertyKey(vtkTextProperty *textProperty, const StringType &text, int dpi)
Creates a TextPropertyKey.
Definition: vtkOpenGLContextDevice2DPrivate.h:226
vtkVector2i
Some derived classes for the different vectors commonly used.
Definition: vtkVector.h:405
vtkAOSDataArrayTemplate::GetVoidPointer
void * GetVoidPointer(vtkIdType valueIdx) override
Return a void pointer.
vtkOpenGLContextDevice2D::Private::SavedDepthTest
bool SavedDepthTest
Definition: vtkOpenGLContextDevice2DPrivate.h:495
vtkTextProperty::GetVerticalJustification
virtual int GetVerticalJustification()
vtkOpenGLContextDevice2D::Private::TextureFromImage
GLuint TextureFromImage(vtkImageData *image)
Definition: vtkOpenGLContextDevice2DPrivate.h:458
UTF16TextPropertyKey
TextPropertyKey< vtkUnicodeString > UTF16TextPropertyKey
Definition: vtkOpenGLContextDevice2DPrivate.h:267
vtkDataArray::InsertTuple4
void InsertTuple4(vtkIdType tupleIdx, double val0, double val1, double val2, double val3)
vtkFreeTypeTools::GetInstance
static vtkFreeTypeTools * GetInstance()
Return the singleton instance with no reference counting.
vtkTextRenderer::Metrics
Definition: vtkTextRenderer.h:75
vtkTextProperty::GetOpacity
virtual double GetOpacity()
vtkOpenGLState
OpenGL state storage.
Definition: vtkOpenGLState.h:67
vtkVector2f
Definition: vtkVector.h:415
vtkOpenGLContextDevice2D::Private::RestoreGLState
void RestoreGLState(vtkOpenGLState *ostate, bool colorBuffer=false)
Definition: vtkOpenGLContextDevice2DPrivate.h:318
TextPropertyKey
Definition: vtkOpenGLContextDevice2DPrivate.h:188
vtkGenericDataArray::SetNumberOfComponents
void SetNumberOfComponents(int num) override
Set/Get the dimension (n) of the components.
vtkContextDevice2D::Stretch
Definition: vtkContextDevice2D.h:288
vtkFreeTypeTools
FreeType library support.
Definition: vtkFreeTypeTools.h:67
TextPropertyKey::operator==
bool operator==(const TextPropertyKey &other) const
Compares two TextPropertyKeys with each other.
Definition: vtkOpenGLContextDevice2DPrivate.h:246
vtkOpenGLContextDevice2D::Private::FindPowerOfTwo
vtkVector2i FindPowerOfTwo(const vtkVector2i &size)
Definition: vtkOpenGLContextDevice2DPrivate.h:382
vtkTextureImageCache::AddCacheData
CacheData & AddCacheData(const Key &key, const CacheData &cacheData)
Add a new cache entry into the cache list.
Definition: vtkOpenGLContextDevice2DPrivate.h:143