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->SavedAlphaTest = GL_TRUE;
280  this->SavedStencilTest = GL_TRUE;
281  this->SavedBlend = GL_TRUE;
282  this->SavedDrawBuffer = 0;
283  this->SavedClearColor[0] = this->SavedClearColor[1] =
284  this->SavedClearColor[2] =
285  this->SavedClearColor[3] = 0.0f;
286  this->TextCounter = 0;
287  this->GLExtensionsLoaded = true;
288  this->GLSL = true;
289  this->PowerOfTwoTextures = false;
290  }
291 
293  {
294  if (this->Texture)
295  {
296  this->Texture->Delete();
297  this->Texture = nullptr;
298  }
299  if (this->SpriteTexture)
300  {
301  this->SpriteTexture->Delete();
302  this->SpriteTexture = nullptr;
303  }
304  }
305 
306  void SaveGLState(bool colorBuffer = false)
307  {
308  this->SavedDepthTest = glIsEnabled(GL_DEPTH_TEST);
309 
310  if (colorBuffer)
311  {
312  this->SavedAlphaTest = glIsEnabled(GL_ALPHA_TEST);
313  this->SavedStencilTest = glIsEnabled(GL_STENCIL_TEST);
314  this->SavedBlend = glIsEnabled(GL_BLEND);
315  glGetFloatv(GL_COLOR_CLEAR_VALUE, this->SavedClearColor);
316  glGetIntegerv(GL_DRAW_BUFFER, &this->SavedDrawBuffer);
317  }
318  }
319 
320  void RestoreGLState(bool colorBuffer = false)
321  {
322  this->SetGLCapability(GL_DEPTH_TEST, this->SavedDepthTest);
323 
324  if (colorBuffer)
325  {
326  this->SetGLCapability(GL_ALPHA_TEST, this->SavedAlphaTest);
327  this->SetGLCapability(GL_STENCIL_TEST, this->SavedStencilTest);
328  this->SetGLCapability(GL_BLEND, this->SavedBlend);
329 
330  if(this->SavedDrawBuffer != GL_BACK_LEFT)
331  {
332  glDrawBuffer(this->SavedDrawBuffer);
333  }
334 
335  int i = 0;
336  bool colorDiffer = false;
337  while(!colorDiffer && i < 4)
338  {
339  colorDiffer=this->SavedClearColor[i++] != 0.0;
340  }
341  if(colorDiffer)
342  {
343  glClearColor(this->SavedClearColor[0],
344  this->SavedClearColor[1],
345  this->SavedClearColor[2],
346  this->SavedClearColor[3]);
347  }
348  }
349  }
350 
351  void SetGLCapability(GLenum capability, GLboolean state)
352  {
353  if (state)
354  {
355  glEnable(capability);
356  }
357  else
358  {
359  glDisable(capability);
360  }
361  }
362 
363  float* TexCoords(float* f, int n)
364  {
365  float* texCoord = new float[2*n];
366  float minX = f[0]; float minY = f[1];
367  float maxX = f[0]; float maxY = f[1];
368  float* fptr = f;
369  for(int i = 0; i < n; ++i)
370  {
371  minX = fptr[0] < minX ? fptr[0] : minX;
372  maxX = fptr[0] > maxX ? fptr[0] : maxX;
373  minY = fptr[1] < minY ? fptr[1] : minY;
374  maxY = fptr[1] > maxY ? fptr[1] : maxY;
375  fptr+=2;
376  }
377  fptr = f;
379  {
380  const double* textureBounds = this->Texture->GetInput()->GetBounds();
381  float rangeX = (textureBounds[1] - textureBounds[0]) ?
382  textureBounds[1] - textureBounds[0] : 1.;
383  float rangeY = (textureBounds[3] - textureBounds[2]) ?
384  textureBounds[3] - textureBounds[2] : 1.;
385  for (int i = 0; i < n; ++i)
386  {
387  texCoord[i*2] = (fptr[0]-minX) / rangeX;
388  texCoord[i*2+1] = (fptr[1]-minY) / rangeY;
389  fptr+=2;
390  }
391  }
392  else // this->TextureProperties & vtkContextDevice2D::Stretch
393  {
394  float rangeX = (maxX - minX)? maxX - minX : 1.f;
395  float rangeY = (maxY - minY)? maxY - minY : 1.f;
396  for (int i = 0; i < n; ++i)
397  {
398  texCoord[i*2] = (fptr[0]-minX)/rangeX;
399  texCoord[i*2+1] = (fptr[1]-minY)/rangeY;
400  fptr+=2;
401  }
402  }
403  return texCoord;
404  }
405 
407  {
408  vtkVector2i pow2(1, 1);
409  for (int i = 0; i < 2; ++i)
410  {
411  while (pow2[i] < size[i])
412  {
413  pow2[i] *= 2;
414  }
415  }
416  return pow2;
417  }
418 
420  {
421  if (image->GetScalarType() != VTK_UNSIGNED_CHAR)
422  {
423  vtkGenericWarningMacro("Invalid image format: expected unsigned char.");
424  return 0;
425  }
426  int bytesPerPixel = image->GetNumberOfScalarComponents();
427  int size[3];
428  image->GetDimensions(size);
429  vtkVector2i newImg = this->FindPowerOfTwo(vtkVector2i(size[0], size[1]));
430 
431  for (int i = 0; i < 2; ++i)
432  {
433  texCoords[i] = size[i] / float(newImg[i]);
434  }
435 
436  unsigned char *dataPtr =
437  new unsigned char[newImg[0] * newImg[1] * bytesPerPixel];
438  unsigned char *origPtr =
439  static_cast<unsigned char*>(image->GetScalarPointer());
440 
441  for (int i = 0; i < newImg[0]; ++i)
442  {
443  for (int j = 0; j < newImg[1]; ++j)
444  {
445  for (int k = 0; k < bytesPerPixel; ++k)
446  {
447  if (i < size[0] && j < size[1])
448  {
449  dataPtr[i * bytesPerPixel + j * newImg[0] * bytesPerPixel + k] =
450  origPtr[i * bytesPerPixel + j * size[0] * bytesPerPixel + k];
451  }
452  else
453  {
454  dataPtr[i * bytesPerPixel + j * newImg[0] * bytesPerPixel + k] =
455  k == 3 ? 0 : 255;
456  }
457  }
458  }
459  }
460 
461  GLuint tmpIndex(0);
462  GLint glFormat = bytesPerPixel == 3 ? GL_RGB : GL_RGBA;
463  GLint glInternalFormat = bytesPerPixel == 3 ? GL_RGB8 : GL_RGBA8;
464 
465  glGenTextures(1, &tmpIndex);
466  glBindTexture(GL_TEXTURE_2D, tmpIndex);
467 
468  glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
469  glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
470  glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S,
471  GL_CLAMP_TO_EDGE );
472  glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T,
473  GL_CLAMP_TO_EDGE );
474 
475  glTexImage2D(GL_TEXTURE_2D, 0 , glInternalFormat,
476  newImg[0], newImg[1], 0, glFormat,
477  GL_UNSIGNED_BYTE, static_cast<const GLvoid *>(dataPtr));
478  delete [] dataPtr;
479  return tmpIndex;
480  }
481 
483  {
484  if (image->GetScalarType() != VTK_UNSIGNED_CHAR)
485  {
486  cout << "Error = not an unsigned char..." << endl;
487  return 0;
488  }
489  int bytesPerPixel = image->GetNumberOfScalarComponents();
490  int size[3];
491  image->GetDimensions(size);
492 
493  unsigned char *dataPtr =
494  static_cast<unsigned char*>(image->GetScalarPointer());
495  GLuint tmpIndex(0);
496  GLint glFormat = bytesPerPixel == 3 ? GL_RGB : GL_RGBA;
497  GLint glInternalFormat = bytesPerPixel == 3 ? GL_RGB8 : GL_RGBA8;
498 
499  glGenTextures(1, &tmpIndex);
500  glBindTexture(GL_TEXTURE_2D, tmpIndex);
501 
502  glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
503  glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
504  glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S,
505  GL_CLAMP_TO_EDGE );
506  glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T,
507  GL_CLAMP_TO_EDGE );
508 
509  glTexImage2D(GL_TEXTURE_2D, 0 , glInternalFormat,
510  size[0], size[1], 0, glFormat,
511  GL_UNSIGNED_BYTE, static_cast<const GLvoid *>(dataPtr));
512  return tmpIndex;
513  }
514 
516  unsigned int TextureProperties;
518  // Store the previous GL state so that we can restore it when complete
519  GLboolean SavedDepthTest;
520  GLboolean SavedAlphaTest;
521  GLboolean SavedStencilTest;
522  GLboolean SavedBlend;
524  GLfloat SavedClearColor[4];
525 
530  bool GLSL;
532 
534 
540 };
542 
544 
564 {
565 
566 public:
567  enum CellType
568  {
569  LINE = 1,
571  //TRIANGLE_STRIPS
572  };
573 
575  : Device(device)
576  , Points(nullptr)
577  , PointIds(nullptr)
578  , Colors(nullptr)
579  , NumPointsCell(0)
580  {
581  };
582 
586  void Draw (int cellType, vtkCellArray* cellArray, vtkPoints* points, float x,
587  float y, float scale, int scalarMode, vtkUnsignedCharArray* colors = nullptr)
588  {
589  this->Points = points;
590  this->Colors = colors;
591  this->CellColors->SetNumberOfComponents(colors->GetNumberOfComponents());
592 
593  switch (cellType)
594  {
595  case LINE:
596  this->DrawLines(cellArray, scalarMode, x, y, scale);
597  break;
598 
599  case POLYGON:
600  this->DrawPolygons(cellArray, scalarMode, x, y, scale);
601  break;
602  }
603  };
604 
605 private:
606  CellArrayHelper(const CellArrayHelper&) = delete;
607  void operator=(const CellArrayHelper&) = delete;
608 
612  void MapCurrentCell (float const posX, float const posY, float const scale,
613  vtkIdType cellId, int scalarMode)
614  {
615  this->CellPoints.reserve(this->NumPointsCell * 2); /* 2 components */
616  this->CellColors->SetNumberOfTuples(this->NumPointsCell); /* RGBA */
617  for (int i = 0; i < this->NumPointsCell; i++)
618  {
619  double point[3];
620  this->Points->GetPoint(this->PointIds[i], point);
621 
622  // Only 2D meshes are supported
623  float const x = static_cast<float>(point[0]) + posX;
624  float const y = static_cast<float>(point[1]) + posY;
625  this->CellPoints.push_back(x * scale);
626  this->CellPoints.push_back(y * scale);
627 
628  // Grab specific point / cell colors
630  switch (scalarMode)
631  {
633  mappedColorId = this->PointIds[i];
634  break;
636  mappedColorId = cellId;
637  break;
638  default:
639  std::cerr << "Scalar mode not supported!" << std::endl;
640  break;
641  }
642 
643  this->CellColors->SetTuple(i, mappedColorId, this->Colors);
644  }
645  };
646 
652  void DrawLines(vtkCellArray* cellArray, int scalarMode, float const x,
653  float const y, float const scale)
654  {
655  if (cellArray->GetMTime() > this->LinesLoadingTime)
656  {
657  this->Lines.clear();
658  this->LineColors->Reset();
659 
660  // Pre-allocate batched array
661  vtkIdType const numVertices = cellArray->GetNumberOfCells() * 2;// points/line
662  this->Lines.reserve(numVertices * 2); // components
663  this->LineColors->SetNumberOfComponents(this->Colors->GetNumberOfComponents());
664  this->LineColors->SetNumberOfTuples(numVertices);
665 
666  vtkIdType cellId = 0;
667  vtkIdType vertOffset = 0;
668  for (cellArray->InitTraversal(); cellArray->GetNextCell(this->NumPointsCell,
669  this->PointIds); cellId++)
670  {
671  this->MapCurrentCell(x, y, scale, cellId, scalarMode);
672 
673  // Accumulate the current cell in the batched array
674  for (int i = 0; i < this->NumPointsCell; i++)
675  {
676  this->Lines.push_back(this->CellPoints[2 * i]);
677  this->Lines.push_back(this->CellPoints[2 * i + 1]);
678 
679  double* color4 = this->CellColors->GetTuple(i);
680  this->LineColors->InsertTuple4(vertOffset + i, color4[0], color4[1], color4[2],
681  color4[3]);
682  }
683 
684  vertOffset += this->NumPointsCell;
685  this->CellColors->Reset();
686  this->CellPoints.clear();
687  }
688 
689  this->LinesLoadingTime.Modified();
690  }
691 
692  this->Device->DrawLines(&this->Lines[0], this->Lines.size() / 2,
693  static_cast<unsigned char*>(this->LineColors->GetVoidPointer(0)),
694  this->LineColors->GetNumberOfComponents());
695  };
696 
701  vtkIdType GetCountTriangleVertices(vtkCellArray* cellArray)
702  {
703  vtkIdType cellId = 0;
704  vtkIdType numTriVert = 0;
705  for (cellArray->InitTraversal(); cellArray->GetNextCell(this->NumPointsCell,
706  this->PointIds); cellId++)
707  {
708  numTriVert += 3 * (this->NumPointsCell - 2);
709  };
710 
711  return numTriVert;
712  };
713 
719  void DrawPolygons(vtkCellArray* cellArray, int scalarMode, float const x,
720  float const y, float const scale)
721  {
722  if (cellArray->GetMTime() > this->PolygonsLoadingTime)
723  {
724  this->PolyTri.clear();
725  this->PolyColors->Reset();
726 
727  // Pre-allocate batched array
728  vtkIdType const totalTriVert = this->GetCountTriangleVertices(cellArray);
729  this->PolyTri.reserve(totalTriVert * 2); // components
730  this->PolyColors->SetNumberOfComponents(this->Colors->GetNumberOfComponents());
731  this->PolyColors->SetNumberOfTuples(totalTriVert);
732 
733  // Traverse polygons and convert to triangles
734  vtkIdType cellId = 0;
735  vtkIdType vertOffset = 0;
736  this->PolyColors->SetNumberOfComponents(this->Colors->GetNumberOfComponents());
737  for (cellArray->InitTraversal(); cellArray->GetNextCell(this->NumPointsCell,
738  this->PointIds); cellId++)
739  {
740  this->MapCurrentCell(x, y, scale, cellId, scalarMode);
741 
742  // Convert current cell (polygon) to triangles
743  for (int i = 0; i < this->NumPointsCell - 2; i++)
744  {
745  this->PolyTri.push_back(this->CellPoints[0]);
746  this->PolyTri.push_back(this->CellPoints[1]);
747  this->PolyTri.push_back(this->CellPoints[i * 2 + 2]);
748  this->PolyTri.push_back(this->CellPoints[i * 2 + 3]);
749  this->PolyTri.push_back(this->CellPoints[i * 2 + 4]);
750  this->PolyTri.push_back(this->CellPoints[i * 2 + 5]);
751 
752  // Insert triangle vertex color
753  vtkIdType const triangOffset = vertOffset + 3 * i;
754  double* color4 = this->CellColors->GetTuple(0);
755  this->PolyColors->InsertTuple4(triangOffset, color4[0], color4[1],
756  color4[2], color4[3]);
757 
758  color4 = this->CellColors->GetTuple(i + 1);
759  this->PolyColors->InsertTuple4(triangOffset + 1, color4[0], color4[1],
760  color4[2], color4[3]);
761 
762  color4 = this->CellColors->GetTuple(i + 2);
763  this->PolyColors->InsertTuple4(triangOffset + 2, color4[0], color4[1],
764  color4[2], color4[3]);
765  }
766 
767  vertOffset += 3 * (this->NumPointsCell - 2); // Triangle verts current cell
768  this->CellColors->Reset();
769  this->CellPoints.clear();
770  }
771 
772  this->PolygonsLoadingTime.Modified();
773  }
774 
775  this->Device->CoreDrawTriangles(this->PolyTri,
776  static_cast<unsigned char*>(this->PolyColors->GetVoidPointer(0)), 4);
777  };
778 
779  vtkOpenGLContextDevice2D* Device;
780 
781  vtkPoints* Points;
782  vtkIdType* PointIds;
783  vtkUnsignedCharArray* Colors;
784 
786 
789  vtkIdType NumPointsCell;
790  std::vector<float> CellPoints;
791  vtkNew<vtkUnsignedCharArray> CellColors;
793 
795 
798  std::vector<float> PolyTri;
799  vtkNew<vtkUnsignedCharArray> PolyColors;
800  vtkTimeStamp PolygonsLoadingTime;
802 
804 
807  std::vector<float> Lines;
808  vtkNew<vtkUnsignedCharArray> LineColors;
809  vtkTimeStamp LinesLoadingTime;
811 };
812 #endif // VTKOPENGLCONTEXTDEVICE2DPRIVATE_H
813 // VTK-HeaderTest-Exclude: vtkOpenGLContextDevice2DPrivate.h
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 void * GetVoidPointer(vtkIdType valueIdx)=0
Return a void pointer.
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,zmax).
virtual double * GetTuple(vtkIdType tupleIdx)=0
Get the data tuple at tupleIdx.
record modification and/or execution time
Definition: vtkTimeStamp.h:32
Class for drawing 2D primitives using OpenGL 1.1+.
void SetTuple(vtkIdType dstTupleIdx, vtkIdType srcTupleIdx, vtkAbstractArray *source) override
Set the tuple at dstTupleIdx in this array to the tuple at srcTupleIdx in the source array...
void Modified()
Set this objects time to the current time.
void InitTraversal()
A cell traversal methods that is more efficient than vtkDataSet traversal methods.
Definition: vtkCellArray.h:96
GLuint TextureFromImage(vtkImageData *image, vtkVector2f &texCoords)
int vtkIdType
Definition: vtkType.h:345
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.
std::list< CacheElement > Cache
List of a pair of key and cache data.
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...
TextPropertyKey< vtkStdString > UTF8TextPropertyKey
window superclass for vtkRenderWindow
Definition: vtkWindow.h:34
size_t MaxSize
Maximum size the cache list can be.
bool operator==(const TextPropertyKey &other) const
Compares two TextPropertyKeys with each other.
#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
Definition: vtkImageData.h:39
vtkImageData * GetInput()
Get the input as a vtkImageData object.
virtual vtkMTimeType GetMTime()
Return this object&#39;s modified time.
Some derived classes for the different vectors commonly used.
Definition: vtkVector.h:405
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.
Definition: vtkColor.h:129
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
Definition: vtkTexture.h:65
vtkTextureImageCache()
Construct a texture image cache with a maximum number of texture of 50.
virtual double GetOpacity()
Set/Get the text&#39;s opacity.
double * GetPoint(vtkIdType id)
Return a pointer to a double point x[3] for a specific id.
Definition: vtkPoints.h:134
represent text properties.
static vtkFreeTypeTools * GetInstance()
Return the singleton instance with no reference counting.
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)
virtual void SetNumberOfComponents(int)
Set/Get the dimension (n) of the components.
object to represent cell connectivity
Definition: vtkCellArray.h:44
virtual double * GetColor()
Set the color of the text.
#define VTK_UNSIGNED_CHAR
Definition: vtkType.h:51
void MapTextPropertyToId(vtkTextProperty *tprop, size_t *tprop_cache_id)
Given a text property &#39;tprop&#39;, get its unique ID in our cache framework.
int GetNextCell(vtkIdType &npts, vtkIdType *&pts)
A cell traversal methods that is more efficient than vtkDataSet traversal methods.
Definition: vtkCellArray.h:359
CacheElement associates a unique key to some cache.
vtkVector2i FindPowerOfTwo(const vtkVector2i &size)
virtual int GetFontSize()
Set/Get the font size (in points).
virtual void SetNumberOfTuples(vtkIdType numTuples)=0
Set the number of tuples (a component group) in the array.
TextPropertyKey< vtkUnicodeString > UTF16TextPropertyKey
static vtkTypeUInt32 GetIdFromTextProperty(vtkTextProperty *tprop)
Transform a text property into an unsigned long.
static vtkTypeUInt32 HashBuffer(const void *str, size_t n, vtkTypeUInt32 hash=0)
Hash a string of a given length.
#define VTK_SCALAR_MODE_USE_CELL_DATA
FreeType library support.
CacheData & AddCacheData(const Key &key, const CacheData &cacheData)
Add a new cache entry into the cache list.
vtkSmartPointer< vtkImageData > ImageData
represent and manipulate 3D points
Definition: vtkPoints.h:33
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.