VTK  9.2.6
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 
52 #ifndef vtkOpenGLContextDevice2D_h
53 #define vtkOpenGLContextDevice2D_h
54 
55 #include "vtkContextDevice2D.h"
56 #include "vtkRenderingContextOpenGL2Module.h" // For export macro
57 
58 #include <list> // for std::list
59 #include <vector> // STL Header
60 
61 class vtkMatrix4x4;
62 class vtkOpenGLExtensionManager;
63 class vtkOpenGLHelper;
65 class vtkPath;
66 class vtkRenderer;
67 class vtkShaderProgram;
68 class vtkStringToImage;
69 class vtkTransform;
70 class vtkViewport;
71 class vtkWindow;
72 
73 class VTKRENDERINGCONTEXTOPENGL2_EXPORT vtkOpenGLContextDevice2D : public vtkContextDevice2D
74 {
75 public:
77  void PrintSelf(ostream& os, vtkIndent indent) override;
78 
83 
89  void DrawPoly(float* f, int n, unsigned char* colors = nullptr, int nc_comps = 0) override;
90 
97  void DrawLines(float* f, int n, unsigned char* colors = nullptr, int nc_comps = 0) override;
98 
104  void DrawPoints(float* points, int n, unsigned char* colors = nullptr, int nc_comps = 0) override;
105 
112  void DrawPointSprites(vtkImageData* sprite, float* points, int n, unsigned char* colors = nullptr,
113  int nc_comps = 0) override;
114 
130  void DrawMarkers(int shape, bool highlight, float* points, int n, unsigned char* colors = nullptr,
131  int nc_comps = 0) override;
132 
134 
139  vtkSetMacro(MaximumMarkerCacheSize, int);
140  vtkGetMacro(MaximumMarkerCacheSize, int);
142 
146  void DrawQuad(float* points, int n) override;
147 
151  void DrawQuadStrip(float* points, int n) override;
152 
156  void DrawPolygon(float*, int) override;
158  float* points, int numPoints, unsigned char* colors = nullptr, int nc_comps = 0) override;
159 
171  void DrawEllipseWedge(float x, float y, float outRx, float outRy, float inRx, float inRy,
172  float startAngle, float stopAngle) override;
173 
181  float x, float y, float rX, float rY, float startAngle, float stopAngle) override;
182 
186  void DrawString(float* point, const vtkStdString& string) override;
187 
196  void ComputeStringBounds(const vtkStdString& string, float bounds[4]) override;
197 
203  void ComputeJustifiedStringBounds(const char* string, float bounds[4]) override;
204 
209  void DrawMathTextString(float point[2], const vtkStdString& string) override;
210 
215  void DrawImage(float p[2], float scale, vtkImageData* image) override;
216 
222  void DrawImage(const vtkRectf& pos, vtkImageData* image) override;
223 
228  void DrawPolyData(float p[2], float scale, vtkPolyData* polyData, vtkUnsignedCharArray* colors,
229  int scalarMode) override;
230 
234  void SetColor4(unsigned char color[4]) override;
235 
239  virtual void SetColor(unsigned char color[3]);
240 
244  void SetTexture(vtkImageData* image, int properties = 0) override;
245 
249  void SetPointSize(float size) override;
250 
254  void SetLineWidth(float width) override;
255 
259  void SetLineType(int type) override;
260 
264  void MultiplyMatrix(vtkMatrix3x3* m) override;
265 
269  void SetMatrix(vtkMatrix3x3* m) override;
270 
274  void GetMatrix(vtkMatrix3x3* m) override;
275 
279  void PushMatrix() override;
280 
284  void PopMatrix() override;
285 
286  /*
287  * Supply an int array of length 4 with x1, y1, width, height specifying
288  * clipping region for the device in pixels.
289  */
290  void SetClipping(int* x) override;
291 
295  void EnableClipping(bool enable) override;
296 
300  void Begin(vtkViewport* viewport) override;
301 
305  void End() override;
306 
315 
323  void BufferIdModeEnd() override;
324 
331 
337 
341  bool HasGLSL();
342 
344 
347  vtkGetObjectMacro(RenderWindow, vtkOpenGLRenderWindow);
349 
355  virtual void ReleaseGraphicsResources(vtkWindow* window);
356 
358 
364 
365 protected:
368 
376  int GetNumberOfArcIterations(float rX, float rY, float startAngle, float stopAngle);
377 
382 
386  bool InRender;
387 
389 
392  class Private;
394 
395  class CellArrayHelper;
398 
403 
404  vtkOpenGLHelper* LinesCBO; // vertex + color
408  vtkOpenGLHelper* VCBO; // vertex + color
410  vtkOpenGLHelper* VBO; // vertex
412  vtkOpenGLHelper* VTBO; // vertex + tcoord
414  vtkOpenGLHelper* SCBO; // sprite + color
416  vtkOpenGLHelper* SBO; // sprite
418 
420  void BuildVBO(
421  vtkOpenGLHelper* cbo, float* v, int nv, unsigned char* coolors, int nc, float* tcoords);
423  std::vector<float>& tverts, unsigned char* colors = nullptr, int numComp = 0);
424  // used for stipples
425  unsigned short LinePattern;
426 
428 
433  int shape, bool highlight, float* points, int n, unsigned char* colors, int nc_comps);
435  bool highlight, float* points, int n, unsigned char* colors, int nc_comps);
437  bool highlight, float* points, int n, unsigned char* colors, int nc_comps);
439  bool highlight, float* points, int n, unsigned char* colors, int nc_comps);
441  bool highlight, float* points, int n, unsigned char* colors, int nc_comps);
443  bool highlight, float* points, int n, unsigned char* colors, int nc_comps);
445 
447 
450  void DrawImageGL2PS(float p[2], vtkImageData* image);
451  void DrawImageGL2PS(float p[2], float scale, vtkImageData* image);
454 
456 
459  void DrawCircleGL2PS(float x, float y, float rX, float rY);
460  void DrawWedgeGL2PS(float x, float y, float outRx, float outRy, float inRx, float inRy);
462 
466  void AddEllipseToPath(vtkPath* path, float x, float y, float rx, float ry, bool reverse);
467 
471  void TransformPath(vtkPath* path) const;
472 
476  void TransformPoint(float& x, float& y) const;
477 
481  void TransformSize(float& dx, float& dy) const;
482 
483 private:
485  void operator=(const vtkOpenGLContextDevice2D&) = delete;
486 
493  vtkImageData* GetMarker(int shape, int size, bool highlight);
494 
495  class vtkMarkerCacheObject
496  {
497  public:
498  vtkTypeUInt64 Key;
499  vtkImageData* Value;
500  bool operator==(vtkTypeUInt64 key) { return this->Key == key; }
501  };
502 
503  void ComputeStringBoundsInternal(const std::string& string, float bounds[4]);
504 
505  vtkTransform* ProjectionMatrix;
506  vtkTransform* ModelMatrix;
507 
508  std::list<vtkMarkerCacheObject> MarkerCache;
509  int MaximumMarkerCacheSize;
510 
515  vtkImageData* GenerateMarker(int shape, int size, bool highlight);
516 };
517 
518 #endif // vtkOpenGLContextDevice2D_h
2D array of ids, used for picking.
Abstract class for drawing 2D primitives.
topologically and geometrically regular array of data
Definition: vtkImageData.h:163
a simple class to control print indentation
Definition: vtkIndent.h:119
represent and manipulate 3x3 transformation matrices
Definition: vtkMatrix3x3.h:66
represent and manipulate 4x4 transformation matrices
Definition: vtkMatrix4x4.h:151
Class for drawing 2D primitives using OpenGL 1.1+.
void DrawEllipseWedge(float x, float y, float outRx, float outRy, float inRx, float inRy, float startAngle, float stopAngle) override
Draw an elliptic wedge with center at x, y, outer radii outRx, outRy, inner radii inRx,...
void DrawCircleMarkersGL2PS(bool highlight, float *points, int n, unsigned char *colors, int nc_comps)
Draw the markers as paths/polydata instead of sprites for detailed GL2PS capture.
~vtkOpenGLContextDevice2D() override
void PopMatrix() override
Pop the current matrix off of the stack.
bool HasGLSL()
Check whether the current context device has support for GLSL.
void SetLineType(int type) override
Set the line type type (using anonymous enum in vtkPen).
void DrawPoly(float *f, int n, unsigned char *colors=nullptr, int nc_comps=0) override
Draw a poly line using the points - fastest code path due to memory layout of the coordinates.
void PushMatrix() override
Push the current matrix onto the stack.
int GetNumberOfArcIterations(float rX, float rY, float startAngle, float stopAngle)
Factorized code called by DrawEllipseWedge() and DrawEllipticArc() to figure out the number of iterat...
void CoreDrawTriangles(std::vector< float > &tverts, unsigned char *colors=nullptr, int numComp=0)
void BufferIdModeBegin(vtkAbstractContextBufferId *bufferId) override
Start BufferId creation Mode.
void SetMatrices(vtkShaderProgram *prog)
void DrawImageGL2PS(const vtkRectf &rect, vtkImageData *image)
Embed an RGBA image in the GL2PS output at the supplied point.
void DrawImage(const vtkRectf &pos, vtkImageData *image) override
Draw the supplied image at the given position.
void SetLineWidth(float width) override
Set the line width for glyphs/sprites.
void SetPointSize(float size) override
Set the point size for glyphs/sprites.
virtual void SetColor(unsigned char color[3])
Set the color for the device using unsigned char of length 3, RGB.
void EnableClipping(bool enable) override
Disable clipping of the display.
static vtkOpenGLContextDevice2D * New()
Creates a 2D Painter object.
void DrawCrossMarkersGL2PS(bool highlight, float *points, int n, unsigned char *colors, int nc_comps)
Draw the markers as paths/polydata instead of sprites for detailed GL2PS capture.
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...
void DrawPointSprites(vtkImageData *sprite, float *points, int n, unsigned char *colors=nullptr, int nc_comps=0) override
Draw a series of point sprites, images centred at the points supplied.
void GetMatrix(vtkMatrix3x3 *m) override
Set the model view matrix for the display.
void SetTexture(vtkImageData *image, int properties=0) override
Set the texture for the device, it is used to fill the polygons.
void DrawColoredPolygon(float *points, int numPoints, unsigned char *colors=nullptr, int nc_comps=0) override
Draw a polygon using the specified number of points.
void PrintSelf(ostream &os, vtkIndent indent) override
Methods invoked by print to print information about the object including superclasses.
vtkMatrix4x4 * GetProjectionMatrix()
Get the projection matrix this is needed.
void End() override
End drawing, clean up the view.
vtkRenderer * Renderer
We need to store a pointer to the renderer for the text rendering.
void DrawMathTextString(float point[2], const vtkStdString &string) override
Draw text using MathText markup for mathematical equations.
void DrawImageGL2PS(float p[2], float scale, vtkImageData *image)
Embed an RGBA image in the GL2PS output at the supplied point.
vtkOpenGLRenderWindow * RenderWindow
The OpenGL render window being used by the device.
void DrawEllipticArc(float x, float y, float rX, float rY, float startAngle, float stopAngle) override
Draw an elliptic arc with center at x,y with radii rX and rY between angles startAngle and stopAngle ...
void DrawPolygon(float *, int) override
Draw a polygon using the specified number of points.
void BuildVBO(vtkOpenGLHelper *cbo, float *v, int nv, unsigned char *coolors, int nc, float *tcoords)
void TransformSize(float &dx, float &dy) const
Transform the width and height from pixels to data units.
void DrawCircleGL2PS(float x, float y, float rX, float rY)
Inject smooth primitives into the GL2PS stream.
void DrawPoints(float *points, int n, unsigned char *colors=nullptr, int nc_comps=0) override
Draw a series of points - fastest code path due to memory layout of the coordinates.
void ComputeStringBounds(const vtkStdString &string, float bounds[4]) override
Compute the bounds of the supplied string.
virtual void ReleaseGraphicsResources(vtkWindow *window)
Release any graphics resources that are being consumed by this device.
void SetMatrix(vtkMatrix3x3 *m) override
Set the model view matrix for the display.
void DrawSquareMarkersGL2PS(bool highlight, float *points, int n, unsigned char *colors, int nc_comps)
Draw the markers as paths/polydata instead of sprites for detailed GL2PS capture.
void DrawQuadStrip(float *points, int n) override
Draws a rectangle.
void DrawImage(float p[2], float scale, vtkImageData *image) override
Draw the supplied image at the given x, y (p[0], p[1]) (bottom corner), scaled by scale (1....
void DrawString(float *point, const vtkStdString &string) override
Draw some text to the screen!
void TransformPath(vtkPath *path) const
Transform the path using the current modelview matrix.
bool SetStringRendererToQt()
Force the use of the Qt based string render strategy.
vtkMatrix4x4 * GetModelMatrix()
Get the projection matrix this is needed.
void BufferIdModeEnd() override
Finalize BufferId creation Mode.
void SetClipping(int *x) override
Supply an int array of length 4 with x1, y1, width, height specifying clipping region for the device ...
void DrawMarkers(int shape, bool highlight, float *points, int n, unsigned char *colors=nullptr, int nc_comps=0) override
Draw a series of markers centered at the points supplied.
void DrawWedgeGL2PS(float x, float y, float outRx, float outRy, float inRx, float inRy)
Inject smooth primitives into the GL2PS stream.
void SetColor4(unsigned char color[4]) override
Set the color for the device using unsigned char of length 4, RGBA.
bool SetStringRendererToFreeType()
Force the use of the freetype based render strategy.
void Begin(vtkViewport *viewport) override
Begin drawing, pass in the viewport to set up the view.
void DrawImageGL2PS(float p[2], vtkImageData *image)
Embed an RGBA image in the GL2PS output at the supplied point.
void ComputeJustifiedStringBounds(const char *string, float bounds[4]) override
Compute the bounds of the supplied string while taking into account the justification of the currentl...
void DrawPolyData(float p[2], float scale, vtkPolyData *polyData, vtkUnsignedCharArray *colors, int scalarMode) override
Draw the supplied PolyData at the given x, y (p[0], p[1]) (bottom corner), scaled by scale (1....
void AddEllipseToPath(vtkPath *path, float x, float y, float rx, float ry, bool reverse)
Add an ellipse to a vtkPath.
void DrawPlusMarkersGL2PS(bool highlight, float *points, int n, unsigned char *colors, int nc_comps)
Draw the markers as paths/polydata instead of sprites for detailed GL2PS capture.
void TransformPoint(float &x, float &y) const
Transform the 2D point using the current modelview matrix.
void DrawDiamondMarkersGL2PS(bool highlight, float *points, int n, unsigned char *colors, int nc_comps)
Draw the markers as paths/polydata instead of sprites for detailed GL2PS capture.
void DrawMarkersGL2PS(int shape, bool highlight, float *points, int n, unsigned char *colors, int nc_comps)
Draw the markers as paths/polydata instead of sprites for detailed GL2PS capture.
void DrawQuad(float *points, int n) override
Draws a rectangle.
bool InRender
Is the device currently rendering? Prevent multiple End() calls.
void MultiplyMatrix(vtkMatrix3x3 *m) override
Multiply the current model view matrix by the supplied one.
OpenGL rendering window.
concrete dataset representing a path defined by Bezier curves.
Definition: vtkPath.h:36
concrete dataset represents vertices, lines, polygons, and triangle strips
Definition: vtkPolyData.h:200
abstract specification for renderers
Definition: vtkRenderer.h:182
The ShaderProgram uses one or more Shader objects.
Wrapper around std::string to keep symbols short.
Definition: vtkStdString.h:108
base class for classes that render supplied text to an image.
describes linear transformations via a 4x4 matrix
Definition: vtkTransform.h:170
dynamic, self-adjusting array of unsigned char
abstract specification for Viewports
Definition: vtkViewport.h:56
window superclass for vtkRenderWindow
Definition: vtkWindow.h:39
@ point
Definition: vtkX3D.h:242
@ key
Definition: vtkX3D.h:263
@ points
Definition: vtkX3D.h:452
@ startAngle
Definition: vtkX3D.h:492
@ scale
Definition: vtkX3D.h:235
@ type
Definition: vtkX3D.h:522
@ color
Definition: vtkX3D.h:227
@ image
Definition: vtkX3D.h:380
@ size
Definition: vtkX3D.h:259
@ string
Definition: vtkX3D.h:496
bool VTKCOMMONDATAMODEL_EXPORT operator==(vtkEdgeBase e1, vtkEdgeBase e2)