VTK
vtkOpenGLContextDevice2D.h
Go to the documentation of this file.
1 /*=========================================================================
2 
3  Program: Visualization Toolkit
4  Module: vtkOpenGLContextDevice2D.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 
30 #ifndef vtkOpenGLContextDevice2D_h
31 #define vtkOpenGLContextDevice2D_h
32 
33 #include "vtkRenderingContextOpenGL2Module.h" // For export macro
34 #include "vtkContextDevice2D.h"
35 
36 #include <vector> // STL Header
37 #include <list> // for std::list
38 
39 class vtkMatrix4x4;
41 class vtkOpenGLHelper;
43 class vtkPath;
44 class vtkRenderer;
45 class vtkShaderProgram;
46 class vtkStringToImage;
47 class vtkTransform;
48 class vtkViewport;
49 class vtkWindow;
50 
51 class VTKRENDERINGCONTEXTOPENGL2_EXPORT vtkOpenGLContextDevice2D : public vtkContextDevice2D
52 {
53 public:
55  void PrintSelf(ostream &os, vtkIndent indent) VTK_OVERRIDE;
56 
60  static vtkOpenGLContextDevice2D *New();
61 
67  void DrawPoly(float *f, int n, unsigned char *colors = 0,
68  int nc_comps = 0) VTK_OVERRIDE;
69 
76  void DrawLines(float *f, int n, unsigned char *colors = 0,
77  int nc_comps = 0) VTK_OVERRIDE;
78 
84  void DrawPoints(float *points, int n, unsigned char* colors = 0,
85  int nc_comps = 0) VTK_OVERRIDE;
86 
93  void DrawPointSprites(vtkImageData *sprite, float *points, int n,
94  unsigned char* colors = 0, int nc_comps = 0) VTK_OVERRIDE;
95 
107  void DrawMarkers(int shape, bool highlight, float *points, int n,
108  unsigned char *colors = 0, int nc_comps = 0) VTK_OVERRIDE;
109 
111 
116  vtkSetMacro(MaximumMarkerCacheSize, int)
117  vtkGetMacro(MaximumMarkerCacheSize, int)
119 
123  void DrawQuad(float *points, int n) VTK_OVERRIDE;
124 
128  void DrawQuadStrip(float *points, int n) VTK_OVERRIDE;
129 
133  void DrawPolygon(float *, int) VTK_OVERRIDE;
134 
146  void DrawEllipseWedge(float x, float y, float outRx, float outRy,
147  float inRx, float inRy, float startAngle,
148  float stopAngle) VTK_OVERRIDE;
149 
156  void DrawEllipticArc(float x, float y, float rX, float rY,
157  float startAngle, float stopAngle) VTK_OVERRIDE;
158 
159 
163  void DrawString(float *point, const vtkStdString &string) VTK_OVERRIDE;
164 
173  void ComputeStringBounds(const vtkStdString &string,
174  float bounds[4]) VTK_OVERRIDE;
175 
179  void DrawString(float *point, const vtkUnicodeString &string) VTK_OVERRIDE;
180 
189  void ComputeStringBounds(const vtkUnicodeString &string,
190  float bounds[4]) VTK_OVERRIDE;
191 
197  void ComputeJustifiedStringBounds(const char* string, float bounds[4]) VTK_OVERRIDE;
198 
203  void DrawMathTextString(float point[2], const vtkStdString &string) VTK_OVERRIDE;
204 
209  void DrawImage(float p[2], float scale, vtkImageData *image) VTK_OVERRIDE;
210 
216  void DrawImage(const vtkRectf& pos, vtkImageData *image) VTK_OVERRIDE;
217 
222  void DrawPolyData(float p[2], float scale, vtkPolyData* polyData,
223  vtkUnsignedCharArray* colors, int scalarMode) VTK_OVERRIDE;
224 
228  void SetColor4(unsigned char color[4]) VTK_OVERRIDE;
229 
233  virtual void SetColor(unsigned char color[3]);
234 
238  void SetTexture(vtkImageData* image, int properties = 0) VTK_OVERRIDE;
239 
243  void SetPointSize(float size) VTK_OVERRIDE;
244 
248  void SetLineWidth(float width) VTK_OVERRIDE;
249 
253  void SetLineType(int type) VTK_OVERRIDE;
254 
258  void MultiplyMatrix(vtkMatrix3x3 *m) VTK_OVERRIDE;
259 
263  void SetMatrix(vtkMatrix3x3 *m) VTK_OVERRIDE;
264 
268  void GetMatrix(vtkMatrix3x3 *m) VTK_OVERRIDE;
269 
273  void PushMatrix() VTK_OVERRIDE;
274 
278  void PopMatrix() VTK_OVERRIDE;
279 
284  void SetClipping(int *x) VTK_OVERRIDE;
285 
289  void EnableClipping(bool enable) VTK_OVERRIDE;
290 
294  void Begin(vtkViewport* viewport) VTK_OVERRIDE;
295 
299  void End() VTK_OVERRIDE;
300 
308  void BufferIdModeBegin(vtkAbstractContextBufferId *bufferId) VTK_OVERRIDE;
309 
317  void BufferIdModeEnd() VTK_OVERRIDE;
318 
324  bool SetStringRendererToFreeType();
325 
330  bool SetStringRendererToQt();
331 
335  bool HasGLSL();
336 
338 
341  vtkGetObjectMacro(RenderWindow, vtkOpenGLRenderWindow);
343 
349  virtual void ReleaseGraphicsResources(vtkWindow *window);
350 
352 
355  vtkMatrix4x4 *GetProjectionMatrix();
356  vtkMatrix4x4 *GetModelMatrix();
358 
359 protected:
361  ~vtkOpenGLContextDevice2D() VTK_OVERRIDE;
362 
370  int GetNumberOfArcIterations(float rX,
371  float rY,
372  float startAngle,
373  float stopAngle);
374 
378  int Geometry[2];
379 
383  vtkRenderer *Renderer;
384 
388  bool InRender;
389 
391 
394  class Private;
395  Private *Storage;
396 
398  CellArrayHelper* PolyDataImpl;
400 
404  vtkOpenGLRenderWindow* RenderWindow;
405 
406  vtkOpenGLHelper *LinesCBO; // vertex + color
407  void ReadyLinesCBOProgram();
408  vtkOpenGLHelper *LinesBO; // vertex
409  void ReadyLinesBOProgram();
410  vtkOpenGLHelper *VCBO; // vertex + color
411  void ReadyVCBOProgram();
412  vtkOpenGLHelper *VBO; // vertex
413  void ReadyVBOProgram();
414  vtkOpenGLHelper *VTBO; // vertex + tcoord
415  void ReadyVTBOProgram();
416  vtkOpenGLHelper *SCBO; // sprite + color
417  void ReadySCBOProgram();
418  vtkOpenGLHelper *SBO; // sprite
419  void ReadySBOProgram();
420 
421  void SetMatrices(vtkShaderProgram *prog);
422  void BuildVBO(vtkOpenGLHelper *cbo,
423  float *v, int nv,
424  unsigned char *coolors, int nc,
425  float *tcoords);
426  void CoreDrawTriangles(std::vector<float> &tverts, unsigned char* colors = NULL,
427  int numComp = 0);
428  // used for stipples
429  unsigned short LinePattern;
430 
432 
436  void DrawMarkersGL2PS(int shape, bool highlight, float *points, int n,
437  unsigned char *colors, int nc_comps);
438  void DrawCrossMarkersGL2PS(bool highlight, float *points, int n,
439  unsigned char *colors, int nc_comps);
440  void DrawPlusMarkersGL2PS(bool highlight, float *points, int n,
441  unsigned char *colors, int nc_comps);
442  void DrawSquareMarkersGL2PS(bool highlight, float *points, int n,
443  unsigned char *colors, int nc_comps);
444  void DrawCircleMarkersGL2PS(bool highlight, float *points, int n,
445  unsigned char *colors, int nc_comps);
446  void DrawDiamondMarkersGL2PS(bool highlight, float *points, int n,
447  unsigned char *colors, int nc_comps);
449 
451 
454  void DrawImageGL2PS(float p[2], vtkImageData *image);
455  void DrawImageGL2PS(float p[2], float scale, vtkImageData *image);
456  void DrawImageGL2PS(const vtkRectf &rect, vtkImageData *image);
458 
460 
463  void DrawCircleGL2PS(float x, float y, float rX, float rY);
464  void DrawWedgeGL2PS(float x, float y, float outRx, float outRy,
465  float inRx, float inRy);
467 
471  void AddEllipseToPath(vtkPath *path, float x, float y, float rx, float ry,
472  bool reverse);
473 
477  void TransformPath(vtkPath *path) const;
478 
482  void TransformPoint(float &x, float &y) const;
483 
487  void TransformSize(float &dx, float &dy) const;
488 
489 private:
490  vtkOpenGLContextDevice2D(const vtkOpenGLContextDevice2D &) VTK_DELETE_FUNCTION;
491  void operator=(const vtkOpenGLContextDevice2D &) VTK_DELETE_FUNCTION;
492 
499  vtkImageData *GetMarker(int shape, int size, bool highlight);
500 
501  class vtkMarkerCacheObject
502  {
503  public:
504  vtkTypeUInt64 Key;
505  vtkImageData *Value;
506  bool operator==(vtkTypeUInt64 key)
507  {
508  return this->Key == key;
509  }
510  };
511 
512  void ComputeStringBoundsInternal(const vtkUnicodeString &string,
513  float bounds[4]);
514 
515  vtkTransform *ProjectionMatrix;
516  vtkTransform *ModelMatrix;
517 
518  std::list<vtkMarkerCacheObject> MarkerCache;
519  int MaximumMarkerCacheSize;
520 
525  vtkImageData * GenerateMarker(int shape, int size, bool highlight);
526 
527 };
528 
529 #endif //vtkOpenGLContextDevice2D_h
OpenGL rendering window.
Wrapper around std::string to keep symbols short.
Definition: vtkStdString.h:47
represent and manipulate 4x4 transformation matrices
Definition: vtkMatrix4x4.h:41
concrete dataset representing a path defined by Bezier curves.
Definition: vtkPath.h:35
abstract specification for Viewports
Definition: vtkViewport.h:47
Class for drawing 2D primitives using OpenGL 1.1+.
abstract specification for renderers
Definition: vtkRenderer.h:63
static vtkContextDevice2D * New()
describes linear transformations via a 4x4 matrix
Definition: vtkTransform.h:60
concrete dataset represents vertices, lines, polygons, and triangle strips
Definition: vtkPolyData.h:85
base class for classes that render supplied text to an image.
window superclass for vtkRenderWindow
Definition: vtkWindow.h:37
virtual void DrawPoly(float *points, int n, unsigned char *colors=0, int nc_comps=0)=0
Draw a poly line using the points - fastest code path due to memory layout of the coordinates...
a simple class to control print indentation
Definition: vtkIndent.h:39
topologically and geometrically regular array of data
Definition: vtkImageData.h:45
Abstract class for drawing 2D primitives.
Interface class for querying and using OpenGL extensions.
dynamic, self-adjusting array of unsigned char
vtkSetMacro(IgnoreDriverBugs, bool)
When set known driver bugs are ignored during driver feature detection.
2D array of ids, used for picking.
VTKCOMMONCORE_EXPORT bool operator==(const vtkUnicodeString &lhs, const vtkUnicodeString &rhs)
represent and manipulate 3x3 transformation matrices
Definition: vtkMatrix3x3.h:36
void PrintSelf(ostream &os, vtkIndent indent) override
Methods invoked by print to print information about the object including superclasses.
String class that stores Unicode text.
The ShaderProgram uses one or more Shader objects.